mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-03-09 13:38:51 -04:00
feat: Isolate::memory_pressure_notification() (#1139)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
e57c3ec90f
commit
3783a5c725
4 changed files with 37 additions and 0 deletions
|
@ -142,6 +142,11 @@ void v8__Isolate__Enter(v8::Isolate* isolate) { isolate->Enter(); }
|
||||||
|
|
||||||
void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); }
|
void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); }
|
||||||
|
|
||||||
|
void v8__Isolate__MemoryPressureNotification(v8::Isolate* isolate,
|
||||||
|
v8::MemoryPressureLevel level) {
|
||||||
|
isolate->MemoryPressureNotification(level);
|
||||||
|
}
|
||||||
|
|
||||||
void v8__Isolate__ClearKeptObjects(v8::Isolate* isolate) {
|
void v8__Isolate__ClearKeptObjects(v8::Isolate* isolate) {
|
||||||
isolate->ClearKeptObjects();
|
isolate->ClearKeptObjects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,18 @@ pub enum MicrotasksPolicy {
|
||||||
Auto = 2,
|
Auto = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Memory pressure level for the MemoryPressureNotification.
|
||||||
|
/// None hints V8 that there is no memory pressure.
|
||||||
|
/// Moderate hints V8 to speed up incremental garbage collection at the cost
|
||||||
|
/// of higher latency due to garbage collection pauses.
|
||||||
|
/// Critical hints V8 to free memory as soon as possible. Garbage collection
|
||||||
|
/// pauses at this level will be large.
|
||||||
|
pub enum MemoryPressureLevel {
|
||||||
|
None = 0,
|
||||||
|
Moderate = 1,
|
||||||
|
Critical = 2,
|
||||||
|
}
|
||||||
|
|
||||||
/// PromiseHook with type Init is called when a new promise is
|
/// PromiseHook with type Init is called when a new promise is
|
||||||
/// created. When a new promise is created as part of the chain in the
|
/// created. When a new promise is created as part of the chain in the
|
||||||
/// case of Promise.then or in the intermediate promises created by
|
/// case of Promise.then or in the intermediate promises created by
|
||||||
|
@ -348,6 +360,7 @@ extern "C" {
|
||||||
fn v8__Isolate__GetNumberOfDataSlots(this: *const Isolate) -> u32;
|
fn v8__Isolate__GetNumberOfDataSlots(this: *const Isolate) -> u32;
|
||||||
fn v8__Isolate__Enter(this: *mut Isolate);
|
fn v8__Isolate__Enter(this: *mut Isolate);
|
||||||
fn v8__Isolate__Exit(this: *mut Isolate);
|
fn v8__Isolate__Exit(this: *mut Isolate);
|
||||||
|
fn v8__Isolate__MemoryPressureNotification(this: *mut Isolate, level: u8);
|
||||||
fn v8__Isolate__ClearKeptObjects(isolate: *mut Isolate);
|
fn v8__Isolate__ClearKeptObjects(isolate: *mut Isolate);
|
||||||
fn v8__Isolate__LowMemoryNotification(isolate: *mut Isolate);
|
fn v8__Isolate__LowMemoryNotification(isolate: *mut Isolate);
|
||||||
fn v8__Isolate__GetHeapStatistics(this: *mut Isolate, s: *mut HeapStatistics);
|
fn v8__Isolate__GetHeapStatistics(this: *mut Isolate, s: *mut HeapStatistics);
|
||||||
|
@ -772,6 +785,15 @@ impl Isolate {
|
||||||
v8__Isolate__Exit(self)
|
v8__Isolate__Exit(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Optional notification that the system is running low on memory.
|
||||||
|
/// V8 uses these notifications to guide heuristics.
|
||||||
|
/// It is allowed to call this function from another thread while
|
||||||
|
/// the isolate is executing long running JavaScript code.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn memory_pressure_notification(&mut self, level: MemoryPressureLevel) {
|
||||||
|
unsafe { v8__Isolate__MemoryPressureNotification(self, level as u8) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Clears the set of objects held strongly by the heap. This set of
|
/// Clears the set of objects held strongly by the heap. This set of
|
||||||
/// objects are originally built when a WeakRef is created or
|
/// objects are originally built when a WeakRef is created or
|
||||||
/// successfully dereferenced.
|
/// successfully dereferenced.
|
||||||
|
|
|
@ -101,6 +101,7 @@ pub use isolate::HostImportModuleDynamicallyCallback;
|
||||||
pub use isolate::HostInitializeImportMetaObjectCallback;
|
pub use isolate::HostInitializeImportMetaObjectCallback;
|
||||||
pub use isolate::Isolate;
|
pub use isolate::Isolate;
|
||||||
pub use isolate::IsolateHandle;
|
pub use isolate::IsolateHandle;
|
||||||
|
pub use isolate::MemoryPressureLevel;
|
||||||
pub use isolate::MessageCallback;
|
pub use isolate::MessageCallback;
|
||||||
pub use isolate::MicrotasksPolicy;
|
pub use isolate::MicrotasksPolicy;
|
||||||
pub use isolate::NearHeapLimitCallback;
|
pub use isolate::NearHeapLimitCallback;
|
||||||
|
|
|
@ -6355,6 +6355,15 @@ fn value_serializer_not_implemented() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn memory_pressure_notification() {
|
||||||
|
let _setup_guard = setup();
|
||||||
|
let isolate = &mut v8::Isolate::new(Default::default());
|
||||||
|
isolate.memory_pressure_notification(v8::MemoryPressureLevel::Moderate);
|
||||||
|
isolate.memory_pressure_notification(v8::MemoryPressureLevel::Critical);
|
||||||
|
isolate.memory_pressure_notification(v8::MemoryPressureLevel::None);
|
||||||
|
}
|
||||||
|
|
||||||
// Flaky on aarch64-qemu (Stack corruption).
|
// Flaky on aarch64-qemu (Stack corruption).
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Reference in a new issue