Skip to content

Truly independent web browser

LibJS: Tie what the JIT keeps cells in to the deferral that keeps them

Shannon Boothdcb467aa0f89
diff --git a/Libraries/LibJS/Rust/src/jit/allocation.rs b/Libraries/LibJS/Rust/src/jit/allocation.rs
index 8cad0552db6..5b14adc9673 100644
--- a/Libraries/LibJS/Rust/src/jit/allocation.rs
+++ b/Libraries/LibJS/Rust/src/jit/allocation.rs
@@ -71,16 +71,16 @@ fn cell_words<T>(cell: Gc<T>, size: usize) -> Vec<u64> {
/// What JIT code needs to allocate cells itself, for code of `realm`. The templates come from cells allocated here,
/// so this may collect garbage.
-pub struct AllocationInfos {
+pub struct AllocationInfos<'d> {
pub object: ObjectAllocationInfo,
pub array: ArrayAllocationInfo,
pub rope: RopeAllocationInfo,
pub function: FunctionAllocationInfo,
/// The cells the templates refer to that code embeds (the shape of new arrays).
- pub cells: Vec<Gc<CellHeader>>,
+ pub cells: Deferred<'d, Vec<Gc<CellHeader>>>,
}
-pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>) -> Deferred<'d, AllocationInfos> {
+pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>) -> AllocationInfos<'d> {
let heap = vm.heap();
let inline = heap.inline_allocation_info();
let heap_address = heap.raw() as u64;
@@ -173,13 +173,13 @@ pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>
slow_path: libjs_jit_clone_function as *const () as u64,
};
- defer_gc.cover(AllocationInfos {
+ AllocationInfos {
object,
array,
rope,
function,
- cells: vec![header_of(array_shape)],
- })
+ cells: defer_gc.cover(vec![header_of(array_shape)]),
+ }
}
fn header_of<T: Extends<CellHeader>>(cell: Gc<T>) -> Gc<CellHeader> {
diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
index 78ab9c57c8a..4c9c4d292ee 100644
--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs
+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs
@@ -446,7 +446,12 @@ 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, _defer_gc: &DeferGc<'_>) -> 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 11bc3797f54..73b85e40ea8 100644
--- a/Libraries/LibJS/Rust/src/jit/snapshot.rs
+++ b/Libraries/LibJS/Rust/src/jit/snapshot.rs
@@ -96,6 +96,7 @@ struct Entry {
struct SnapshotBuilder<'vm> {
vm: &'vm Vm,
+ _defer_gc: &'vm DeferGc<'vm>,
cells: Vec<Gc<CellHeader>>,
entries: Vec<Entry>,
indices: HashMap<InlinedFunction, u32>,
@@ -1282,7 +1283,8 @@ pub fn capture_snapshot<'d>(
.collect::<Vec<_>>();
let mut builder = SnapshotBuilder {
vm,
- cells: allocation.cells.clone(),
+ _defer_gc: defer_gc,
+ cells: (*allocation.cells).clone(),
entries: vec![Entry {
executable,
function: None,
@@ -1328,7 +1330,7 @@ pub fn capture_snapshot<'d>(
executables.push(builder.executable_snapshot(&entry));
index += 1;
}
- let mut runtime = super::runtime_info::runtime_info(vm, realm, allocation.into_inner(), defer_gc);
+ let mut runtime = super::runtime_info::runtime_info(vm, realm, allocation, 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());