Skip to content

Commit

Permalink
Don't run GC on isolate disposal (#1181)
Browse files Browse the repository at this point in the history
Removing this garbage collection trigger removes the guarantee that
"regular" FinalizerCallbacks will be called before the isolate goes away.
It is fine as both spec and V8 do not provide this guarantee and we were
overly strict in this case.
  • Loading branch information
bartlomieju authored Feb 2, 2023
1 parent 1269ad6 commit d3fff51
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 44 deletions.
4 changes: 0 additions & 4 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,10 +954,6 @@ impl FinalizerMap {
id
}

pub(crate) fn is_empty(&self) -> bool {
self.map.is_empty()
}

pub(crate) fn drain(
&mut self,
) -> impl Iterator<Item = FinalizerCallback> + '_ {
Expand Down
9 changes: 0 additions & 9 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,15 +1182,6 @@ impl Isolate {
// Drop the scope stack.
ScopeData::drop_root(self);

// If there are finalizers left to call, we trigger GC to try and call as
// many of them as possible.
if !self.get_annex().finalizer_map.is_empty() {
// A low memory notification triggers a synchronous GC, which means
// finalizers will be called during the course of the call, rather than at
// some later point.
self.low_memory_notification();
}

// Set the `isolate` pointer inside the annex struct to null, so any
// IsolateHandle that outlives the isolate will know that it can't call
// methods on the isolate.
Expand Down
31 changes: 0 additions & 31 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7943,37 +7943,6 @@ fn drop_weak_from_raw_in_finalizer() {
assert!(finalized.get());
}

#[test]
fn finalizer_on_global_object() {
use std::cell::Cell;
use std::rc::Rc;

let _setup_guard = setup::parallel_test();

let weak;
let finalized = Rc::new(Cell::new(false));

{
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);

let global_object = context.global(scope);
weak = v8::Weak::with_finalizer(
scope,
global_object,
Box::new({
let finalized = finalized.clone();
move |_| finalized.set(true)
}),
);
}

assert!(finalized.get());
drop(weak);
}

#[test]
fn finalizer_on_kept_global() {
// If a global is kept alive after an isolate is dropped, regular finalizers
Expand Down

0 comments on commit d3fff51

Please sign in to comment.