Skip to content

Truly independent web browser

LibJS: Pass a DeferGc to the JIT code that relies on its caller's

Shannon Booth0afbfe110240
diff --git a/Libraries/LibJS/Rust/src/gc/defer_gc.rs b/Libraries/LibJS/Rust/src/gc/defer_gc.rs
index 2afbcaa7258..df8dc864f6e 100644
--- a/Libraries/LibJS/Rust/src/gc/defer_gc.rs
+++ b/Libraries/LibJS/Rust/src/gc/defer_gc.rs
@@ -4,6 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+use core::marker::PhantomData;
+use core::ops::{Deref, DerefMut};
+
use super::capi;
use super::heap::Heap;
use crate::interpreter::vm::Vm;
@@ -20,6 +23,14 @@ impl<'heap> DeferGc<'heap> {
capi::gc_heap_defer_gc(heap.handle());
Self(heap)
}
+
+ /// Ties `value`, whose cells only this deferral keeps alive, to the deferral.
+ pub fn cover<T>(&self, value: T) -> Deferred<'_, T> {
+ Deferred {
+ value,
+ _defer_gc: PhantomData,
+ }
+ }
}
impl Drop for DeferGc<'_> {
@@ -27,3 +38,31 @@ impl Drop for DeferGc<'_> {
capi::gc_heap_undefer_gc(self.0.handle());
}
}
+
+/// A value whose cells nothing keeps alive but a deferral, such as cells in a Vec that nothing traces yet. It cannot
+/// outlive the deferral.
+pub struct Deferred<'d, T> {
+ value: T,
+ _defer_gc: PhantomData<&'d ()>,
+}
+
+impl<T> Deferred<'_, T> {
+ /// Gives up the value, for moving it where the collector finds its cells.
+ pub fn into_inner(self) -> T {
+ self.value
+ }
+}
+
+impl<T> Deref for Deferred<'_, T> {
+ type Target = T;
+
+ fn deref(&self) -> &T {
+ &self.value
+ }
+}
+
+impl<T> DerefMut for Deferred<'_, T> {
+ fn deref_mut(&mut self) -> &mut T {
+ &mut self.value
+ }
+}
diff --git a/Libraries/LibJS/Rust/src/jit/allocation.rs b/Libraries/LibJS/Rust/src/jit/allocation.rs
index 9b93bd83862..8cad0552db6 100644
--- a/Libraries/LibJS/Rust/src/jit/allocation.rs
+++ b/Libraries/LibJS/Rust/src/jit/allocation.rs
@@ -22,6 +22,7 @@ use libjs_jit::snapshot::{
use super::offset;
use crate::bytecode::executable::Executable;
use crate::gc::class::{Extends, GcCell, class_of};
+use crate::gc::defer_gc::{DeferGc, Deferred};
use crate::interpreter::slow_paths::bindings::create_lexical_environment;
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
@@ -79,7 +80,7 @@ pub struct AllocationInfos {
pub cells: Vec<Gc<CellHeader>>,
}
-pub fn allocation_infos(vm: &Vm, realm: Gc<Realm>) -> AllocationInfos {
+pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>) -> Deferred<'d, AllocationInfos> {
let heap = vm.heap();
let inline = heap.inline_allocation_info();
let heap_address = heap.raw() as u64;
@@ -172,13 +173,13 @@ pub fn allocation_infos(vm: &Vm, realm: Gc<Realm>) -> AllocationInfos {
slow_path: libjs_jit_clone_function as *const () as u64,
};
- AllocationInfos {
+ defer_gc.cover(AllocationInfos {
object,
array,
rope,
function,
cells: vec![header_of(array_shape)],
- }
+ })
}
fn header_of<T: Extends<CellHeader>>(cell: Gc<T>) -> Gc<CellHeader> {
@@ -437,20 +438,25 @@ pub extern "C" fn libjs_jit_create_lexical_environment(
.as_ptr()
}
+/// The sample of each closure template with its words, by shared function data index.
+pub type ClosureTemplates = Vec<Option<(Gc<EcmascriptFunctionObject>, Vec<u64>)>>;
+
/// The closures JIT code of `executable`, whose frames run `function`, creates with each `NewFunction` (by shared
-/// function data index) by copying a sample (see `FunctionAllocationInfo`), or None for those it cannot. This
-/// allocates the samples, so it may collect garbage.
-pub fn closure_templates(
+/// function data index) by copying a sample (see `FunctionAllocationInfo`), or None for those it cannot.
+pub fn closure_templates<'d>(
vm: &Vm,
executable: Gc<Executable>,
function: Gc<EcmascriptFunctionObject>,
-) -> Vec<Option<(Gc<EcmascriptFunctionObject>, Vec<u64>)>> {
- (0..executable.shared_function_data_count())
- .map(|index| {
- let shared_data = executable.shared_function_data(u32::try_from(index).ok()?);
- closure_template(vm, function, shared_data)
- })
- .collect()
+ defer_gc: &'d DeferGc<'_>,
+) -> Deferred<'d, ClosureTemplates> {
+ defer_gc.cover(
+ (0..executable.shared_function_data_count())
+ .map(|index| {
+ let shared_data = executable.shared_function_data(u32::try_from(index).ok()?);
+ closure_template(vm, function, shared_data)
+ })
+ .collect(),
+ )
}
fn closure_template(
@@ -487,8 +493,9 @@ fn closure_template(
/// The closure templates as the snapshot carries them, with their samples as cells the code embeds.
pub fn closure_template_snapshots(
- templates: Vec<Option<(Gc<EcmascriptFunctionObject>, Vec<u64>)>>,
+ templates: ClosureTemplates,
mut cell: impl FnMut(Gc<EcmascriptFunctionObject>) -> CellId,
+ _defer_gc: &DeferGc<'_>,
) -> Vec<Option<ClosureTemplateSnapshot>> {
templates
.into_iter()
diff --git a/Libraries/LibJS/Rust/src/jit/disabled.rs b/Libraries/LibJS/Rust/src/jit/disabled.rs
index e8981b10f2e..8f838627dff 100644
--- a/Libraries/LibJS/Rust/src/jit/disabled.rs
+++ b/Libraries/LibJS/Rust/src/jit/disabled.rs
@@ -192,13 +192,14 @@ pub mod translate {
Vec::new()
}
- pub fn call_site_frame_arguments(
+ pub fn call_site_frame_arguments<'d>(
_vm: &Vm,
_frame: &ExecutionContext,
_index: u32,
_frame_pointer: u64,
_frame_state: usize,
- ) -> Vec<Value> {
+ _defer_gc: &'d crate::gc::defer_gc::DeferGc<'_>,
+ ) -> crate::gc::defer_gc::Deferred<'d, Vec<Value>> {
unreachable!("no frame runs JIT code");
}
diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
index b780a2d0b45..78ab9c57c8a 100644
--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs
+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
@@ -28,6 +28,7 @@ use crate::bytecode::executable::{
MEGAMORPHIC_PRIMARY_ENTRIES_OFFSET, MEGAMORPHIC_SECONDARY_ENTRIES_OFFSET,
};
use crate::gc::class::{Class, GcCell};
+use crate::gc::defer_gc::DeferGc;
use crate::interpreter::runtime_functions::runtime_function_addresses;
use crate::interpreter::vm::{
FLY_STRING_CACHE_SIZE, LARGE_NUMERIC_STRING_CACHE_SIZE, NUMERIC_STRING_CACHE_SIZE, NumericStringCacheEntry, Vm,
@@ -445,7 +446,7 @@ const _: () = assert!(size_of::<core::cell::Cell<Option<Gc<PrimitiveString>>>>()
/// The runtime info of a compile job for code of `realm`, with what JIT code needs to allocate cells itself (which
/// refers to the cells in `allocation.cells`).
-pub fn runtime_info(vm: &Vm, realm: Gc<Realm>, allocation: AllocationInfos) -> RuntimeInfo {
+pub fn runtime_info(vm: &Vm, realm: Gc<Realm>, allocation: AllocationInfos, _defer_gc: &DeferGc<'_>) -> RuntimeInfo {
let addresses = vm.jit.runtime_function_addresses();
let mut layout = runtime_layout();
layout.try_get_by_id_cache = addresses.try_get_by_id_cache;
diff --git a/Libraries/LibJS/Rust/src/jit/snapshot.rs b/Libraries/LibJS/Rust/src/jit/snapshot.rs
index 7f89a2dd8ea..35187d22d1d 100644
--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs
+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs
@@ -33,6 +33,7 @@ use crate::bytecode::executable::{Executable, PropertyLookupCacheEntryData, Prop
use crate::bytecode::feedback::{CallFeedback, CallFeedbackForwarding, call_feedback_flags};
use crate::bytecode::instruction::instruction_length_from_bytes;
use crate::gc::class::Extends;
+use crate::gc::defer_gc::{DeferGc, Deferred};
use crate::interpreter::vm::Vm;
use crate::layout::cell::{CellHeader, Gc};
use crate::layout::environment::DeclarativeEnvironment;
@@ -77,10 +78,10 @@ const MAX_INLINED_CONSTRUCT_INSTRUCTION_COUNT: u32 = 50;
/// A snapshot with the cells it refers to, which must stay alive (and in place) until the job's code is installed or
/// the job is abandoned.
-pub struct CapturedSnapshot {
+pub struct CapturedSnapshot<'d> {
pub snapshot: Box<Snapshot>,
- pub cells: Vec<Gc<CellHeader>>,
- pub snapshot_executables: Vec<SnapshotExecutable>,
+ pub cells: Deferred<'d, Vec<Gc<CellHeader>>>,
+ pub snapshot_executables: Deferred<'d, Vec<SnapshotExecutable>>,
}
/// An executable of the snapshot.
@@ -1253,13 +1254,14 @@ fn captured_binding_accesses(executable: &Executable) -> CapturedBindingAccesses
/// Captures the snapshot of a compile job for `executable`, whose frames run `function` in `realm`, or the top-level
/// code of a script or of a module without one, in the running frame. `osr_pc` is the loop back edge whose tier-up
/// budget ran out, if a loop triggered the compile.
-pub fn capture_snapshot(
+pub fn capture_snapshot<'d>(
vm: &Vm,
executable: Gc<Executable>,
function: Option<Gc<EcmascriptFunctionObject>>,
realm: Gc<Realm>,
osr_pc: Option<u32>,
-) -> CapturedSnapshot {
+ defer_gc: &'d DeferGc<'_>,
+) -> CapturedSnapshot<'d> {
let compiled_function_fields = match function {
Some(function) => function_frame_fields(function),
None => FunctionFrameFields {
@@ -1268,11 +1270,11 @@ pub fn capture_snapshot(
},
};
// NB: These allocate (and so may collect garbage), which they do before anything is captured.
- let allocation = allocation_infos(vm, realm);
+ let allocation = allocation_infos(vm, realm, defer_gc);
// NB: Closures that top-level code creates have its environments, which the code does not know.
let closure_templates = match function {
- Some(function) => closure_templates(vm, executable, function),
- None => (0..executable.shared_function_data_count()).map(|_| None).collect(),
+ Some(function) => closure_templates(vm, executable, function, defer_gc),
+ None => defer_gc.cover((0..executable.shared_function_data_count()).map(|_| None).collect()),
};
let closure_samples = closure_templates
.iter()
@@ -1296,7 +1298,8 @@ pub fn capture_snapshot(
lexical_environment_templates: Vec::new(),
construct_this_shapes: HashMap::new(),
};
- builder.closure_templates = closure_template_snapshots(closure_templates, |sample| builder.cell(sample));
+ builder.closure_templates =
+ closure_template_snapshots(closure_templates.into_inner(), |sample| builder.cell(sample), defer_gc);
builder.lexical_environment_templates =
lexical_environment_templates(vm, executable, realm, |cell| builder.cell(cell));
// NB: executable_snapshot() appends the inlining candidates it finds.
@@ -1325,7 +1328,7 @@ pub fn capture_snapshot(
executables.push(builder.executable_snapshot(&entry));
index += 1;
}
- let mut runtime = super::runtime_info::runtime_info(vm, realm, allocation);
+ let mut runtime = super::runtime_info::runtime_info(vm, realm, allocation.into_inner(), defer_gc);
// NB: Code that embeds the prototypes of the runtime info lists them as embedded cells.
builder.cell(realm.array_prototype());
builder.cell(realm.object_prototype());
@@ -1369,22 +1372,24 @@ pub fn capture_snapshot(
};
CapturedSnapshot {
snapshot: Box::new(snapshot),
- cells: builder.cells,
- snapshot_executables: builder
- .entries
- .iter()
- .map(|entry| SnapshotExecutable {
- executable: entry.executable,
- function: entry.function,
- known_exit_sites: entry.executable.jit_exit_site_count(),
- known_builtin_exit_sites: entry.executable.jit_builtin_exit_site_count(),
- property_cache_sizes: entry
- .executable
- .property_lookup_caches()
- .iter()
- .map(speculated_cache_size)
- .collect(),
- })
- .collect(),
+ cells: defer_gc.cover(builder.cells),
+ snapshot_executables: defer_gc.cover(
+ builder
+ .entries
+ .iter()
+ .map(|entry| SnapshotExecutable {
+ executable: entry.executable,
+ function: entry.function,
+ known_exit_sites: entry.executable.jit_exit_site_count(),
+ known_builtin_exit_sites: entry.executable.jit_builtin_exit_site_count(),
+ property_cache_sizes: entry
+ .executable
+ .property_lookup_caches()
+ .iter()
+ .map(speculated_cache_size)
+ .collect(),
+ })
+ .collect(),
+ ),
}
}
diff --git a/Libraries/LibJS/Rust/src/jit/tier_up.rs b/Libraries/LibJS/Rust/src/jit/tier_up.rs
index 1f92b985973..e3533721595 100644
--- a/Libraries/LibJS/Rust/src/jit/tier_up.rs
+++ b/Libraries/LibJS/Rust/src/jit/tier_up.rs
@@ -13,7 +13,7 @@ use libjs_jit::code::CompiledCode;
use super::code::{CompileState, JitCode, SnapshotExecutable};
use super::compile_queue::CompileResult;
use super::executable_memory::ExecutableMemory;
-use super::snapshot::capture_snapshot;
+use super::snapshot::{CapturedSnapshot, capture_snapshot};
use super::{CompileJob, JitState};
use crate::bytecode::executable::Executable;
use crate::bytecode::feedback::tier_up_costs;
@@ -447,10 +447,14 @@ fn compile(
// NB: Nothing may collect the cells the snapshot captured before something keeps them alive.
let defer_gc = DeferGc::new(vm);
- let captured = capture_snapshot(vm, executable, function, realm, osr_pc);
+ let CapturedSnapshot {
+ snapshot,
+ cells,
+ snapshot_executables,
+ } = capture_snapshot(vm, executable, function, realm, osr_pc, &defer_gc);
if sync {
// NB: Nothing collects garbage while compiling on this thread, so the snapshot's cells stay alive.
- let result = libjs_jit::compile(&captured.snapshot);
+ let result = libjs_jit::compile(&snapshot);
let memory = should_install(vm, &result).then(|| {
let code = &result.as_ref().expect("the compile succeeded").code;
let name = super::describe_executable(&executable);
@@ -463,18 +467,18 @@ fn compile(
.pop()
.expect("one code was allocated")
});
- finish_compile(vm, executable, result, memory, captured.snapshot_executables);
+ finish_compile(vm, executable, result, memory, snapshot_executables.into_inner());
drop(defer_gc);
return;
}
let job_id = vm.jit.add_job(CompileJob {
executable,
- cells: captured.cells,
- snapshot_executables: captured.snapshot_executables,
+ cells: cells.into_inner(),
+ snapshot_executables: snapshot_executables.into_inner(),
});
drop(defer_gc);
- vm.jit.compile_queue().submit(job_id, captured.snapshot);
+ vm.jit.compile_queue().submit(job_id, snapshot);
}
/// Compiles the executable of `function` right away, from the feedback it has, unless it has code, is being compiled or
diff --git a/Libraries/LibJS/Rust/src/jit/translate.rs b/Libraries/LibJS/Rust/src/jit/translate.rs
index 2e034c35308..5187d458be4 100644
--- a/Libraries/LibJS/Rust/src/jit/translate.rs
+++ b/Libraries/LibJS/Rust/src/jit/translate.rs
@@ -32,7 +32,7 @@ use crate::bytecode::executable::Executable;
use crate::bytecode::instruction::{OpCode, instruction_length_from_bytes};
use crate::bytecode::instruction_at;
use crate::bytecode::op;
-use crate::gc::defer_gc::DeferGc;
+use crate::gc::defer_gc::{DeferGc, Deferred};
use crate::interpreter::vm::Vm;
use crate::layout::cell::Gc;
use crate::layout::execution_context::ExecutionContext;
@@ -140,7 +140,7 @@ struct SiteValues<'a> {
root: *const ExecutionContext,
site: &'a Site,
dump: &'a RegisterDump,
- created: HashMap<u32, Gc<Object>>,
+ created: Deferred<'a, HashMap<u32, Gc<Object>>>,
/// Whether the objects created are remembered for the frame, for a frame that continues in compiled code until it
/// leaves it, where the objects must be the same.
remember: bool,
@@ -156,6 +156,7 @@ impl<'a> SiteValues<'a> {
root: NonNull<ExecutionContext>,
site: &'a Site,
dump: &'a RegisterDump,
+ defer_gc: &'a DeferGc<'_>,
) -> Self {
Self {
vm,
@@ -163,7 +164,7 @@ impl<'a> SiteValues<'a> {
root: root.as_ptr(),
site,
dump,
- created: HashMap::new(),
+ created: defer_gc.cover(HashMap::new()),
remember: false,
deferred_arguments: None,
}
@@ -605,8 +606,8 @@ pub(super) fn exit(vm: &Vm, root: NonNull<ExecutionContext>, code: &JitCode, ind
));
// NB: Nothing may collect the objects created here before the frames hold them.
- let _defer_gc = DeferGc::new(vm);
- let mut values = SiteValues::new(vm, code, root, site, dump);
+ let defer_gc = DeferGc::new(vm);
+ let mut values = SiteValues::new(vm, code, root, site, dump, &defer_gc);
let innermost = push_site_frames(
vm,
code,
@@ -704,8 +705,8 @@ pub(super) fn leave(vm: &Vm, root: NonNull<ExecutionContext>, code: &JitCode, in
let pushed = frames.len().min(frame_states.len() - 1);
// NB: Nothing may collect the objects created here before the frames hold them.
- let _defer_gc = DeferGc::new(vm);
- let mut values = SiteValues::new(vm, code, root, site, dump);
+ let defer_gc = DeferGc::new(vm);
+ let mut values = SiteValues::new(vm, code, root, site, dump, &defer_gc);
let mut write = |frame: &ExecutionContext, frame_state: &FrameState| {
let expected = code.snapshot_executable(frame_state.executable).executable;
assert!(executable_of(frame) == expected);
@@ -747,8 +748,8 @@ pub(super) fn publish(vm: &Vm, root: NonNull<ExecutionContext>, code: &JitCode,
let frame_states = &site.frames;
assert!(frame_states.len() >= 2);
// NB: Nothing may collect the objects created here before the frames hold them.
- let _defer_gc = DeferGc::new(vm);
- let mut values = SiteValues::new(vm, code, root, site, dump);
+ let defer_gc = DeferGc::new(vm);
+ let mut values = SiteValues::new(vm, code, root, site, dump, &defer_gc);
// NB: The values of the site stay in the register dump of the JIT frame while the slow path runs.
values.deferred_arguments = Some(dump.gprs[RegisterDump::FRAME_POINTER]);
// NB: The compiled function's frame is at the call of the outermost inlined call, which stack walks show.
@@ -814,9 +815,9 @@ pub(super) fn materialize_call_site_frames(
vm.head.running_execution_context.set(root.as_ptr());
// NB: Nothing may collect the objects created here before the frames hold them.
- let _defer_gc = DeferGc::new(vm);
+ let defer_gc = DeferGc::new(vm);
let dump = RegisterDump::of_stack_slots(frame_pointer);
- let mut values = SiteValues::new(vm, code, root, site, &dump);
+ let mut values = SiteValues::new(vm, code, root, site, &dump, &defer_gc);
// NB: Compiled code keeps running once the call returns, and the call may read the frames' legacy arguments, which
// find their values through the site (see `resolve_deferred_arguments()`).
values.deferred_arguments = Some(frame_pointer);
@@ -920,13 +921,14 @@ pub fn call_site_frames(vm: &Vm, frame: &ExecutionContext, index: u32, frame_poi
/// code running `frame` is in, the one with the frame state at `frame_state` of the site, while it runs without it,
/// with the JIT frame at `frame_pointer`, for code reading the legacy `arguments` of the frame's function. Objects
/// among them that the code never allocated are created for the frame (see `note_legacy_arguments_read()`).
-pub fn call_site_frame_arguments(
+pub fn call_site_frame_arguments<'d>(
vm: &Vm,
frame: &ExecutionContext,
index: u32,
frame_pointer: u64,
frame_state: usize,
-) -> Vec<Value> {
+ defer_gc: &'d DeferGc<'_>,
+) -> Deferred<'d, Vec<Value>> {
let compiled_executable = executable_of(frame);
let code = compiled_executable
.jit_code(vm)
@@ -939,16 +941,18 @@ pub fn call_site_frame_arguments(
let executable = code.snapshot_executable(frame_state.executable).executable;
// NB: The caller keeps collections deferred while it holds the objects created here.
let dump = RegisterDump::of_stack_slots(frame_pointer);
- let mut values = SiteValues::new(vm, code, NonNull::from(frame), site, &dump);
+ let mut values = SiteValues::new(vm, code, NonNull::from(frame), site, &dump, defer_gc);
values.remember = true;
let mut reads_objects = false;
- let arguments = (0..passed_argument_count)
- .map(|argument| {
- let location = argument_location(frame_state, &executable, argument);
- reads_objects |= matches!(location, Some(ValueLocation::VirtualObject(_)));
- location.map_or(Value::UNDEFINED, |location| values.value(location))
- })
- .collect();
+ let arguments = defer_gc.cover(
+ (0..passed_argument_count)
+ .map(|argument| {
+ let location = argument_location(frame_state, &executable, argument);
+ reads_objects |= matches!(location, Some(ValueLocation::VirtualObject(_)));
+ location.map_or(Value::UNDEFINED, |location| values.value(location))
+ })
+ .collect(),
+ );
if reads_objects {
note_legacy_arguments_read(vm, frame, code, frame_state);
}
@@ -1001,14 +1005,14 @@ fn deferred_argument(vm: &Vm, frame: &ExecutionContext, argument: u32, frame_poi
argument_location(frame_state, &executable, argument).expect("the frame state lists arguments with markers");
assert!(matches!(location, ValueLocation::VirtualObject(_)));
// NB: The objects created here are remembered for the frame, which keeps them alive.
- let _defer_gc = DeferGc::new(vm);
+ let defer_gc = DeferGc::new(vm);
// NB: The values of a publication are in the JIT frame's register dump while its slow path runs; those of a call
// site, in stack slots.
let dump = match site.kind {
SiteKind::Publish => RegisterDump::in_jit_frame(code, frame_pointer),
_ => RegisterDump::of_stack_slots(frame_pointer),
};
- let mut values = SiteValues::new(vm, code, root, site, &dump);
+ let mut values = SiteValues::new(vm, code, root, site, &dump, &defer_gc);
values.remember = true;
let object = values.value(location);
note_legacy_arguments_read(vm, frame_of(root), code, frame_state);
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index 0ef6a9f9b48..442655b8988 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -14,7 +14,7 @@ use libjs_runtime_macros::Trace;
use crate::bytecode::executable::Executable;
use crate::gc::class::{Extends, GcCell, cast_ref, define_cell};
-use crate::gc::defer_gc::DeferGc;
+use crate::gc::defer_gc::{DeferGc, Deferred};
use crate::gc::gc_ref_cell::GcRefCell;
use crate::gc::root::MarkedVec;
use crate::gc::visitor::{Trace, Visitor};
@@ -990,8 +990,8 @@ impl EcmascriptFunctionObject {
let this_function = self.as_function_object_gc();
// NB: The arguments of a frame of an inlined call may be objects JIT code never created, which only the
// arguments object holds once it exists.
- let _defer_gc = DeferGc::new(vm);
- let mut passed_arguments: Option<Vec<Cell<Value>>> = None;
+ let defer_gc = DeferGc::new(vm);
+ let mut passed_arguments: Option<Deferred<'_, Vec<Cell<Value>>>> = None;
vm.for_each_stack_frame_top_to_bottom(|frame| {
if frame.function != Some(this_function) {
@@ -999,28 +999,32 @@ impl EcmascriptFunctionObject {
}
// NB: The frame of a call that JIT code inlined has its arguments in the JIT frame.
- passed_arguments = Some(match frame.inlined_call {
- Some(inlined_call) => crate::jit::translate::call_site_frame_arguments(
- vm,
- frame.execution_context,
- inlined_call.site,
- inlined_call.frame_pointer,
- inlined_call.frame_state,
- )
- .into_iter()
- .map(Cell::new)
- .collect(),
- None => {
- let context = frame.execution_context;
- // NB: The frame of an inlined call that JIT code published or materialized for a call it made has
- // markers for the objects among its arguments that the code never allocated.
- crate::jit::translate::resolve_deferred_arguments(vm, context);
- context.arguments()[..context.passed_argument_count.get() as usize]
- .iter()
- .map(|argument| Cell::new(argument.get()))
- .collect()
- }
- });
+ passed_arguments = Some(
+ defer_gc.cover(match frame.inlined_call {
+ Some(inlined_call) => crate::jit::translate::call_site_frame_arguments(
+ vm,
+ frame.execution_context,
+ inlined_call.site,
+ inlined_call.frame_pointer,
+ inlined_call.frame_state,
+ &defer_gc,
+ )
+ .into_inner()
+ .into_iter()
+ .map(Cell::new)
+ .collect(),
+ None => {
+ let context = frame.execution_context;
+ // NB: The frame of an inlined call that JIT code published or materialized for a call it made has
+ // markers for the objects among its arguments that the code never allocated.
+ crate::jit::translate::resolve_deferred_arguments(vm, context);
+ context.arguments()[..context.passed_argument_count.get() as usize]
+ .iter()
+ .map(|argument| Cell::new(argument.get()))
+ .collect()
+ }
+ }),
+ );
ControlFlow::Break(())
});