0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-27 01:29:19 -05:00

feat: add binding for ResourceConstraints::ConfigureDefaults (#1651)

* add binding for `ResourceConstraints::ConfigureDefaults`

* fmt

* fix types
This commit is contained in:
Nathan Whitaker 2024-10-29 10:56:35 -07:00 committed by GitHub
parent b0364c0c5e
commit 2509b0ba62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 0 deletions

View file

@ -385,6 +385,12 @@ void v8__ResourceConstraints__ConfigureDefaultsFromHeapSize(
maximum_heap_size_in_bytes);
}
void v8__ResourceConstraints__ConfigureDefaults(
v8::ResourceConstraints* constraints, uint64_t physical_memory,
uint64_t virtual_memory_limit) {
constraints->ConfigureDefaults(physical_memory, virtual_memory_limit);
}
void v8__HandleScope__CONSTRUCT(uninit_t<v8::HandleScope>* buf,
v8::Isolate* isolate) {
construct_in_place<v8::HandleScope>(buf, isolate);

View file

@ -160,6 +160,37 @@ impl CreateParams {
self
}
/// Configures the constraints with reasonable default values based on the capabilities
/// of the current device the VM is running on.
///
/// By default V8 starts with a small heap and dynamically grows it to match
/// the set of live objects. This may lead to ineffective garbage collections
/// at startup if the live set is large. Setting the initial heap size avoids
/// such garbage collections. Note that this does not affect young generation
/// garbage collections.
///
/// When the heap size approaches its maximum, V8 will perform series of
/// garbage collections and invoke the
/// [NearHeapLimitCallback](struct.Isolate.html#method.add_near_heap_limit_callback).
/// If the garbage collections do not help and the callback does not
/// increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory.
///
/// # Arguments
///
/// * `physical_memory` - The total amount of physical memory on the current device, in bytes.
/// * `virtual_memory_limit` - The amount of virtual memory on the current device, in bytes, or zero, if there is no limit.
pub fn heap_limits_from_system_memory(
mut self,
physical_memory: u64,
virtual_memory_limit: u64,
) -> Self {
self
.raw
.constraints
.configure_defaults(physical_memory, virtual_memory_limit);
self
}
/// A CppHeap used to construct the Isolate. V8 takes ownership of the
/// CppHeap passed this way.
pub fn cpp_heap(mut self, heap: UniqueRef<Heap>) -> Self {
@ -269,6 +300,11 @@ pub(crate) mod raw {
initial_heap_size_in_bytes: usize,
maximum_heap_size_in_bytes: usize,
);
fn v8__ResourceConstraints__ConfigureDefaults(
constraints: *mut ResourceConstraints,
physical_memory: u64,
virtual_memory_limit: u64,
);
}
impl ResourceConstraints {
@ -285,5 +321,19 @@ pub(crate) mod raw {
)
};
}
pub fn configure_defaults(
&mut self,
physical_memory: u64,
virtual_memory_limit: u64,
) {
unsafe {
v8__ResourceConstraints__ConfigureDefaults(
self,
physical_memory,
virtual_memory_limit,
)
}
}
}
}