mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
re-add deprecated cppgc api (#1611)
This commit is contained in:
parent
bca14ac66d
commit
8a5f484c71
5 changed files with 84 additions and 41 deletions
2
.gn
2
.gn
|
@ -40,6 +40,8 @@ default_args = {
|
||||||
|
|
||||||
v8_enable_pointer_compression = false
|
v8_enable_pointer_compression = false
|
||||||
|
|
||||||
|
v8_imminent_deprecation_warnings = false
|
||||||
|
|
||||||
# This flag speeds up the performance of fork/execve on Linux systems for
|
# This flag speeds up the performance of fork/execve on Linux systems for
|
||||||
# embedders which use it (like Node.js). It works by marking the pages that
|
# embedders which use it (like Node.js). It works by marking the pages that
|
||||||
# V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel
|
# V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel
|
||||||
|
|
|
@ -3888,13 +3888,25 @@ void v8__Object__Wrap(v8::Isolate* isolate, const v8::Object& wrapper,
|
||||||
tag);
|
tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::CppHeap* v8__Isolate__GetCppHeap(v8::Isolate* isolate) {
|
||||||
|
return isolate->GetCppHeap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void v8__Isolate__AttachCppHeap(v8::Isolate* isolate, v8::CppHeap* cpp_heap) {
|
||||||
|
isolate->AttachCppHeap(cpp_heap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void v8__Isolate__DetachCppHeap(v8::Isolate* isolate) {
|
||||||
|
isolate->DetachCppHeap();
|
||||||
|
}
|
||||||
|
|
||||||
void cppgc__initialize_process(v8::Platform* platform) {
|
void cppgc__initialize_process(v8::Platform* platform) {
|
||||||
cppgc::InitializeProcess(platform->GetPageAllocator());
|
cppgc::InitializeProcess(platform->GetPageAllocator());
|
||||||
}
|
}
|
||||||
|
|
||||||
void cppgc__shutdown_process() { cppgc::ShutdownProcess(); }
|
void cppgc__shutdown_process() { cppgc::ShutdownProcess(); }
|
||||||
|
|
||||||
v8::CppHeap* cppgc__heap__create(v8::Platform* platform,
|
v8::CppHeap* v8__CppHeap__Create(v8::Platform* platform,
|
||||||
cppgc::Heap::MarkingType marking_support,
|
cppgc::Heap::MarkingType marking_support,
|
||||||
cppgc::Heap::SweepingType sweeping_support) {
|
cppgc::Heap::SweepingType sweeping_support) {
|
||||||
v8::CppHeapCreateParams params{{}};
|
v8::CppHeapCreateParams params{{}};
|
||||||
|
@ -3904,11 +3916,9 @@ v8::CppHeap* cppgc__heap__create(v8::Platform* platform,
|
||||||
return heap.release();
|
return heap.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::CppHeap* v8__Isolate__GetCppHeap(v8::Isolate* isolate) {
|
void v8__CppHeap__Terminate(v8::CppHeap* cpp_heap) { cpp_heap->Terminate(); }
|
||||||
return isolate->GetCppHeap();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cppgc__heap__DELETE(v8::CppHeap* self) { delete self; }
|
void v8__CppHeap__DELETE(v8::CppHeap* self) { delete self; }
|
||||||
|
|
||||||
void cppgc__heap__enable_detached_garbage_collections_for_testing(
|
void cppgc__heap__enable_detached_garbage_collections_for_testing(
|
||||||
v8::CppHeap* heap) {
|
v8::CppHeap* heap) {
|
||||||
|
|
17
src/cppgc.rs
17
src/cppgc.rs
|
@ -14,12 +14,13 @@ extern "C" {
|
||||||
fn cppgc__initialize_process(platform: *mut Platform);
|
fn cppgc__initialize_process(platform: *mut Platform);
|
||||||
fn cppgc__shutdown_process();
|
fn cppgc__shutdown_process();
|
||||||
|
|
||||||
fn cppgc__heap__create(
|
fn v8__CppHeap__Create(
|
||||||
platform: *mut Platform,
|
platform: *mut Platform,
|
||||||
marking_support: MarkingType,
|
marking_support: MarkingType,
|
||||||
sweeping_support: SweepingType,
|
sweeping_support: SweepingType,
|
||||||
) -> *mut Heap;
|
) -> *mut Heap;
|
||||||
fn cppgc__heap__DELETE(heap: *mut Heap);
|
fn v8__CppHeap__Terminate(heap: *mut Heap);
|
||||||
|
fn v8__CppHeap__DELETE(heap: *mut Heap);
|
||||||
fn cppgc__make_garbage_collectable(
|
fn cppgc__make_garbage_collectable(
|
||||||
heap: *mut Heap,
|
heap: *mut Heap,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
@ -226,7 +227,9 @@ pub struct Heap(Opaque);
|
||||||
|
|
||||||
impl Drop for Heap {
|
impl Drop for Heap {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { cppgc__heap__DELETE(self) }
|
unsafe {
|
||||||
|
v8__CppHeap__DELETE(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +239,7 @@ impl Heap {
|
||||||
params: HeapCreateParams,
|
params: HeapCreateParams,
|
||||||
) -> UniqueRef<Heap> {
|
) -> UniqueRef<Heap> {
|
||||||
unsafe {
|
unsafe {
|
||||||
UniqueRef::from_raw(cppgc__heap__create(
|
UniqueRef::from_raw(v8__CppHeap__Create(
|
||||||
&*platform as *const Platform as *mut _,
|
&*platform as *const Platform as *mut _,
|
||||||
params.marking_support,
|
params.marking_support,
|
||||||
params.sweeping_support,
|
params.sweeping_support,
|
||||||
|
@ -263,6 +266,12 @@ impl Heap {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn terminate(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
v8__CppHeap__Terminate(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Base trait for managed objects.
|
/// Base trait for managed objects.
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::support::MapFnFrom;
|
||||||
use crate::support::MapFnTo;
|
use crate::support::MapFnTo;
|
||||||
use crate::support::Opaque;
|
use crate::support::Opaque;
|
||||||
use crate::support::ToCFn;
|
use crate::support::ToCFn;
|
||||||
|
use crate::support::UniqueRef;
|
||||||
use crate::support::UnitType;
|
use crate::support::UnitType;
|
||||||
use crate::wasm::trampoline;
|
use crate::wasm::trampoline;
|
||||||
use crate::wasm::WasmStreaming;
|
use crate::wasm::WasmStreaming;
|
||||||
|
@ -467,6 +468,8 @@ extern "C" {
|
||||||
change_in_bytes: i64,
|
change_in_bytes: i64,
|
||||||
) -> i64;
|
) -> i64;
|
||||||
fn v8__Isolate__GetCppHeap(isolate: *mut Isolate) -> *mut Heap;
|
fn v8__Isolate__GetCppHeap(isolate: *mut Isolate) -> *mut Heap;
|
||||||
|
fn v8__Isolate__AttachCppHeap(isolate: *mut Isolate, cpp_heap: *mut Heap);
|
||||||
|
fn v8__Isolate__DetachCppHeap(isolate: *mut Isolate);
|
||||||
fn v8__Isolate__SetPrepareStackTraceCallback(
|
fn v8__Isolate__SetPrepareStackTraceCallback(
|
||||||
isolate: *mut Isolate,
|
isolate: *mut Isolate,
|
||||||
callback: PrepareStackTraceCallback,
|
callback: PrepareStackTraceCallback,
|
||||||
|
@ -1219,10 +1222,21 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_cpp_heap(&mut self) -> Option<&Heap> {
|
pub fn get_cpp_heap(&mut self) -> Option<&Heap> {
|
||||||
unsafe { v8__Isolate__GetCppHeap(self).as_ref() }
|
unsafe { v8__Isolate__GetCppHeap(self).as_ref() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn attach_cpp_heap(&mut self, cpp_heap: &mut UniqueRef<Heap>) {
|
||||||
|
unsafe { v8__Isolate__AttachCppHeap(self, cpp_heap.deref_mut()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn detach_cpp_heap(&mut self) {
|
||||||
|
unsafe { v8__Isolate__DetachCppHeap(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_oom_error_handler(&mut self, callback: OomErrorCallback) {
|
pub fn set_oom_error_handler(&mut self, callback: OomErrorCallback) {
|
||||||
unsafe { v8__Isolate__SetOOMErrorHandler(self, callback) };
|
unsafe { v8__Isolate__SetOOMErrorHandler(self, callback) };
|
||||||
|
|
|
@ -94,13 +94,14 @@ fn cppgc_object_wrap() {
|
||||||
|
|
||||||
{
|
{
|
||||||
// Create a managed heap.
|
// Create a managed heap.
|
||||||
let heap = v8::cppgc::Heap::create(
|
let mut heap = v8::cppgc::Heap::create(
|
||||||
guard.platform.clone(),
|
guard.platform.clone(),
|
||||||
v8::cppgc::HeapCreateParams::default(),
|
v8::cppgc::HeapCreateParams::default(),
|
||||||
);
|
);
|
||||||
let isolate =
|
let isolate = &mut v8::Isolate::new(v8::CreateParams::default());
|
||||||
&mut v8::Isolate::new(v8::CreateParams::default().cpp_heap(heap));
|
isolate.attach_cpp_heap(&mut heap);
|
||||||
|
|
||||||
|
{
|
||||||
let handle_scope = &mut v8::HandleScope::new(isolate);
|
let handle_scope = &mut v8::HandleScope::new(isolate);
|
||||||
let context = v8::Context::new(handle_scope, Default::default());
|
let context = v8::Context::new(handle_scope, Default::default());
|
||||||
let scope = &mut v8::ContextScope::new(handle_scope, context);
|
let scope = &mut v8::ContextScope::new(handle_scope, context);
|
||||||
|
@ -133,8 +134,9 @@ fn cppgc_object_wrap() {
|
||||||
|
|
||||||
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 0);
|
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 0);
|
||||||
|
|
||||||
scope
|
scope.request_garbage_collection_for_testing(
|
||||||
.request_garbage_collection_for_testing(v8::GarbageCollectionType::Full);
|
v8::GarbageCollectionType::Full,
|
||||||
|
);
|
||||||
|
|
||||||
assert!(TRACE_COUNT.load(Ordering::SeqCst) > 0);
|
assert!(TRACE_COUNT.load(Ordering::SeqCst) > 0);
|
||||||
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 1);
|
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 1);
|
||||||
|
@ -146,11 +148,17 @@ fn cppgc_object_wrap() {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
scope
|
scope.request_garbage_collection_for_testing(
|
||||||
.request_garbage_collection_for_testing(v8::GarbageCollectionType::Full);
|
v8::GarbageCollectionType::Full,
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 3);
|
assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isolate.detach_cpp_heap();
|
||||||
|
heap.terminate();
|
||||||
|
drop(heap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_script(
|
fn execute_script(
|
||||||
|
|
Loading…
Reference in a new issue