Skip to content

Truly independent web browser

LibJS: Compress the realm and prototype of shapes and accessor functions

Andreas Klingb1e4231fa5db
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
index 07a9f8b7f4c..6a327fbd043 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
@@ -5197,7 +5197,7 @@ asm_handler_PutByValue:
b.ne .Lasm_PutByValue.ssa_block_3
cbnz x3, .Lasm_PutByValue.ssa_block_3
ldp w3, w4, [x0, #4]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w4
b.ne .Lasm_PutByValue.ssa_block_3
ldrb w9, [x0, #12]
@@ -5251,7 +5251,7 @@ asm_handler_GetById:
mov x1, x3
.Lasm_GetById.ssa_block_16:
ldp w4, w5, [x2, #4]
- ldr w9, [x0, #52]
+ ldr w9, [x0, #40]
cmp w9, w5
b.ne .Lasm_GetById.ssa_block_1
ldr x0, [x1, #24]
@@ -5294,7 +5294,7 @@ asm_handler_GetById:
cmp w2, #6
b.eq .Lasm_GetById.ssa_block_1
ldr w2, [x1, #8]
- ldr w9, [x0, #52]
+ ldr w9, [x0, #40]
cmp w9, w2
b.ne .Lasm_GetById.ssa_block_1
ldr x0, [x1, #32]
@@ -5343,7 +5343,7 @@ asm_handler_PutById:
b.ne .Lasm_PutById.ssa_block_2
cbnz x3, .Lasm_PutById.ssa_block_2
ldp w3, w4, [x0, #4]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w4
b.ne .Lasm_PutById.ssa_block_2
ldrb w9, [x0, #12]
@@ -5649,7 +5649,7 @@ asm_handler_GetByValue:
cmp w4, #6
b.eq .Lasm_GetByValue.ssa_block_3
ldr w4, [x0, #8]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w4
b.ne .Lasm_GetByValue.ssa_block_3
cbnz x3, .Lasm_GetByValue.ssa_block_3
@@ -5713,7 +5713,7 @@ asm_handler_GetLength:
b.eq .Lasm_GetLength.ssa_block_1
cbnz x3, .Lasm_GetLength.ssa_block_1
ldp w3, w0, [x0, #4]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w0
b.ne .Lasm_GetLength.ssa_block_1
ldr x0, [x2, #24]
@@ -5772,7 +5772,7 @@ asm_handler_GetGlobal:
cmp x9, x1
b.ne .Lasm_GetGlobal.ssa_block_2
ldp w4, w5, [x0, #4]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w5
b.ne .Lasm_GetGlobal.ssa_block_2
ldr x0, [x3, #24]
@@ -5830,7 +5830,7 @@ asm_handler_ResolveGlobalBinding:
cmp x9, x1
b.ne .Lasm_ResolveGlobalBinding.ssa_block_2
ldr w2, [x0, #8]
- ldr w9, [x1, #52]
+ ldr w9, [x1, #40]
cmp w9, w2
b.ne .Lasm_ResolveGlobalBinding.ssa_block_2
ldr w9, [x21, #4]
@@ -5878,7 +5878,7 @@ asm_handler_SetGlobal:
cmp x9, x2
b.ne .Lasm_SetGlobal.ssa_block_2
ldp w4, w5, [x0, #4]
- ldr w9, [x2, #52]
+ ldr w9, [x2, #40]
cmp w9, w5
b.ne .Lasm_SetGlobal.ssa_block_2
ldr x1, [x3, #24]
@@ -5986,8 +5986,9 @@ asm_handler_Call:
ldr w3, [x1, #20]
cbz x3, .Lasm_Call.assert_failure_1
add x3, x24, w3, uxtw #3
- ldr x3, [x3, #16]
+ ldr w3, [x3, #12]
cbz x3, .Lasm_Call.assert_failure_2
+ add x3, x24, w3, uxtw #3
ldr x3, [x3, #32]
cbz x3, .Lasm_Call.assert_failure_3
ldr x6, [x3, #32]
@@ -6035,8 +6036,9 @@ asm_handler_Call:
ldr w5, [x1, #20]
cbz x5, .Lasm_Call.assert_failure_6
add x5, x24, w5, uxtw #3
- ldr x5, [x5, #16]
+ ldr w5, [x5, #12]
cbz x5, .Lasm_Call.assert_failure_7
+ add x5, x24, w5, uxtw #3
stp x1, x5, [x0, #0]
ldr w5, [x1, #72]
add x9, x24, w5, uxtw #3
@@ -6151,8 +6153,9 @@ asm_handler_Call:
ldr w2, [x1, #20]
cbz x2, .Lasm_Call.assert_failure_12
add x2, x24, w2, uxtw #3
- ldr x2, [x2, #16]
+ ldr w2, [x2, #12]
cbz x2, .Lasm_Call.assert_failure_13
+ add x2, x24, w2, uxtw #3
stp x1, x2, [x0, #0]
ldp x2, x4, [x28, #32]
cbz x2, .Lasm_Call.assert_predicate_failure_68
@@ -6350,7 +6353,7 @@ asm_handler_ObjectPropertyIteratorNext:
b.ne .Lasm_ObjectPropertyIteratorNext.ssa_block_1
ldrb w9, [x0, #11]
cbz w9, .Lasm_ObjectPropertyIteratorNext.ssa_block_4
- ldr w1, [x1, #52]
+ ldr w1, [x1, #40]
ldr w9, [x0, #20]
cmp w9, w1
b.ne .Lasm_ObjectPropertyIteratorNext.ssa_block_1
@@ -14125,8 +14128,9 @@ asm_handler_GetById_cold:
ldr w2, [x1, #20]
cbz x2, .Lasm_GetById.assert_failure_8
add x2, x24, w2, uxtw #3
- ldr x2, [x2, #16]
+ ldr w2, [x2, #12]
cbz x2, .Lasm_GetById.assert_failure_9
+ add x2, x24, w2, uxtw #3
stp x1, x2, [x0, #0]
ldp x1, x2, [x28, #32]
cbz x1, .Lasm_GetById.assert_predicate_failure_202
@@ -14245,7 +14249,10 @@ asm_handler_GetById_cold:
.Lasm_GetById.ssa_block_17:
and x0, x0, #0x7ffffffff
add x0, x0, x24
- ldr x1, [x0, #16]
+ ldr w1, [x0, #16]
+ add x9, x24, w1, uxtw #3
+ cmp w1, #0
+ csel x1, x9, xzr, ne
cbz x1, .Lasm_GetById.ssa_block_5
ldrh w0, [x1, #12]
tbnz x0, #1, 1f
@@ -14616,7 +14623,7 @@ asm_handler_GetByValue_cold:
cmp w3, #3
b.ne .Lasm_GetByValue.ssa_block_2
ldr w3, [x1, #8]
- ldr w9, [x0, #52]
+ ldr w9, [x0, #40]
cmp w9, w3
b.ne .Lasm_GetByValue.ssa_block_2
ldr x0, [x2, #24]
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
index ee2279abf98..41ec7f32b0d 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
@@ -5236,7 +5236,7 @@ asm_handler_PutByValue:
jnz .Lasm_PutByValue.ssa_block_3
mov edx, DWORD PTR [rax + 4]
mov edi, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], edi
+ cmp DWORD PTR [rcx + 40], edi
jne .Lasm_PutByValue.ssa_block_3
cmp BYTE PTR [rax + 12], 0
jz .Lasm_PutByValue.ssa_block_3
@@ -5296,7 +5296,7 @@ asm_handler_GetById:
.Lasm_GetById.ssa_block_16:
mov edi, DWORD PTR [rdx + 4]
mov r8d, DWORD PTR [rdx + 8]
- cmp DWORD PTR [rax + 52], r8d
+ cmp DWORD PTR [rax + 40], r8d
jne .Lasm_GetById.ssa_block_1
mov rax, QWORD PTR [rcx + 24]
test rax, rax
@@ -5336,7 +5336,7 @@ asm_handler_GetById:
cmp edx, 6
je .Lasm_GetById.ssa_block_1
mov edx, DWORD PTR [rcx + 8]
- cmp DWORD PTR [rax + 52], edx
+ cmp DWORD PTR [rax + 40], edx
jne .Lasm_GetById.ssa_block_1
mov rax, QWORD PTR [rcx + 32]
test rax, rax
@@ -5394,7 +5394,7 @@ asm_handler_PutById:
jnz .Lasm_PutById.ssa_block_2
mov esi, DWORD PTR [rax + 4]
mov edi, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], edi
+ cmp DWORD PTR [rcx + 40], edi
jne .Lasm_PutById.ssa_block_2
cmp BYTE PTR [rax + 12], 0
jz .Lasm_PutById.ssa_block_2
@@ -5722,7 +5722,7 @@ asm_handler_GetByValue:
cmp edi, 6
je .Lasm_GetByValue.ssa_block_3
mov edi, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], edi
+ cmp DWORD PTR [rcx + 40], edi
jne .Lasm_GetByValue.ssa_block_3
test rsi, rsi
jnz .Lasm_GetByValue.ssa_block_3
@@ -5795,7 +5795,7 @@ asm_handler_GetLength:
jnz .Lasm_GetLength.ssa_block_1
mov esi, DWORD PTR [rax + 4]
mov eax, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], eax
+ cmp DWORD PTR [rcx + 40], eax
jne .Lasm_GetLength.ssa_block_1
mov rax, QWORD PTR [rdx + 24]
test rax, rax
@@ -5855,7 +5855,7 @@ asm_handler_GetGlobal:
jne .Lasm_GetGlobal.ssa_block_2
mov edi, DWORD PTR [rax + 4]
mov r8d, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], r8d
+ cmp DWORD PTR [rcx + 40], r8d
jne .Lasm_GetGlobal.ssa_block_2
mov rax, QWORD PTR [rsi + 24]
test rax, rax
@@ -5915,7 +5915,7 @@ asm_handler_ResolveGlobalBinding:
cmp QWORD PTR [rax + 24], rcx
jne .Lasm_ResolveGlobalBinding.ssa_block_2
mov edx, DWORD PTR [rax + 8]
- cmp DWORD PTR [rcx + 52], edx
+ cmp DWORD PTR [rcx + 40], edx
jne .Lasm_ResolveGlobalBinding.ssa_block_2
movabs r11, 9221401712017801217
mov eax, DWORD PTR [r14 + r13 + 4]
@@ -5961,7 +5961,7 @@ asm_handler_SetGlobal:
jne .Lasm_SetGlobal.ssa_block_2
mov edi, DWORD PTR [rax + 4]
mov r8d, DWORD PTR [rax + 8]
- cmp DWORD PTR [rdx + 52], r8d
+ cmp DWORD PTR [rdx + 40], r8d
jne .Lasm_SetGlobal.ssa_block_2
mov rcx, QWORD PTR [rsi + 24]
test rcx, rcx
@@ -6077,9 +6077,10 @@ asm_handler_Call:
test rsi, rsi
jz .Lasm_Call.assert_failure_1
lea rsi, [r15 + rsi * 8]
- mov rsi, QWORD PTR [rsi + 16]
+ mov esi, DWORD PTR [rsi + 12]
test rsi, rsi
jz .Lasm_Call.assert_failure_2
+ lea rsi, [r15 + rsi * 8]
mov rsi, QWORD PTR [rsi + 32]
test rsi, rsi
jz .Lasm_Call.assert_failure_3
@@ -6136,9 +6137,10 @@ asm_handler_Call:
test r8, r8
jz .Lasm_Call.assert_failure_6
lea r8, [r15 + r8 * 8]
- mov r8, QWORD PTR [r8 + 16]
+ mov r8d, DWORD PTR [r8 + 12]
test r8, r8
jz .Lasm_Call.assert_failure_7
+ lea r8, [r15 + r8 * 8]
mov QWORD PTR [rax], rcx
mov QWORD PTR [rax + 8], r8
mov r8d, DWORD PTR [rcx + 72]
@@ -6268,9 +6270,10 @@ asm_handler_Call:
test rdx, rdx
jz .Lasm_Call.assert_failure_12
lea rdx, [r15 + rdx * 8]
- mov rdx, QWORD PTR [rdx + 16]
+ mov edx, DWORD PTR [rdx + 12]
test rdx, rdx
jz .Lasm_Call.assert_failure_13
+ lea rdx, [r15 + rdx * 8]
mov QWORD PTR [rax], rcx
mov QWORD PTR [rax + 8], rdx
mov rdx, QWORD PTR [rbx - 96]
@@ -6489,7 +6492,7 @@ asm_handler_ObjectPropertyIteratorNext:
jne .Lasm_ObjectPropertyIteratorNext.ssa_block_1
cmp BYTE PTR [rax + 11], 0
jz .Lasm_ObjectPropertyIteratorNext.ssa_block_4
- mov ecx, DWORD PTR [rcx + 52]
+ mov ecx, DWORD PTR [rcx + 40]
cmp DWORD PTR [rax + 20], ecx
jne .Lasm_ObjectPropertyIteratorNext.ssa_block_1
.Lasm_ObjectPropertyIteratorNext.ssa_block_4:
@@ -13784,9 +13787,10 @@ asm_handler_GetById_cold:
test rdx, rdx
jz .Lasm_GetById.assert_failure_8
lea rdx, [r15 + rdx * 8]
- mov rdx, QWORD PTR [rdx + 16]
+ mov edx, DWORD PTR [rdx + 12]
test rdx, rdx
jz .Lasm_GetById.assert_failure_9
+ lea rdx, [r15 + rdx * 8]
mov QWORD PTR [rax], rcx
mov QWORD PTR [rax + 8], rdx
mov rcx, QWORD PTR [rbx - 96]
@@ -13911,7 +13915,10 @@ asm_handler_GetById_cold:
movabs r11, 34359738367
and rax, r11
add rax, r15
- mov rcx, QWORD PTR [rax + 16]
+ mov ecx, DWORD PTR [rax + 16]
+ lea r11, [r15 + rcx * 8]
+ test ecx, ecx
+ cmovnz rcx, r11
test rcx, rcx
jz .Lasm_GetById.ssa_block_5
movzx eax, WORD PTR [rcx + 12]
@@ -14283,7 +14290,7 @@ asm_handler_GetByValue_cold:
cmp esi, 3
jne .Lasm_GetByValue.ssa_block_2
mov esi, DWORD PTR [rcx + 8]
- cmp DWORD PTR [rax + 52], esi
+ cmp DWORD PTR [rax + 40], esi
jne .Lasm_GetByValue.ssa_block_2
mov rax, QWORD PTR [rdx + 24]
test rax, rax
diff --git a/Libraries/LibJS/Flap/tests/interpreter-layout.conf b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
index 0de42725eab..caba04e3c12 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-layout.conf
+++ b/Libraries/LibJS/Flap/tests/interpreter-layout.conf
@@ -15,7 +15,7 @@ const OBJECT_SIZE = 64
# Accessor layout
const ACCESSOR_GETTER = 16
-field Accessor.getter FunctionObject ACCESSOR_GETTER nullable cell
+field Accessor.getter FunctionObject ACCESSOR_GETTER nullable compressed
# Object flags
const OBJECT_FLAGS = 12
@@ -32,12 +32,12 @@ const OBJECT_FLAG_IS_GLOBAL_OBJECT = 2048
const OBJECT_FLAG_IS_HTMLDDA = 8192
# Shape layout
-const SHAPE_REALM = 16
-field Shape.realm Realm SHAPE_REALM nonnull cell
-const SHAPE_PROTOTYPE = 24
-const SHAPE_DICTIONARY_GENERATION = 52
+const SHAPE_REALM = 12
+field Shape.realm Realm SHAPE_REALM nonnull compressed
+const SHAPE_PROTOTYPE = 16
+const SHAPE_DICTIONARY_GENERATION = 40
field Shape.dictionary_generation u32 SHAPE_DICTIONARY_GENERATION nullable scalar
-const SHAPE_SIZE = 56
+const SHAPE_SIZE = 44
# PropertyLookupCache layout
const PROPERTY_LOOKUP_CACHE_DATA = 0
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/arrays.rs b/Libraries/LibJS/JIT/Rust/src/codegen/arrays.rs
index b9041de0fdc..02f4914adf5 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/arrays.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/arrays.rs
@@ -16,6 +16,7 @@ use crate::asm::Label;
use crate::asm::PortableMacroAssembler;
use crate::asm::Scale;
use crate::ir::NodeId;
+use crate::snapshot::CellId;
impl<M: PortableMacroAssembler> Codegen<'_, M> {
/// Calls the splice helper with the inserted values on the native
@@ -161,12 +162,10 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
fail,
);
self.emit_load_compressed_cell(shape, &Address::new(object, offsets.object_shape as i32));
- self.masm
- .load64(scratch, &Address::new(shape, layout.shape_prototype as i32));
- self.masm.branch64_imm(
+ self.masm.branch32_memory_imm(
Condition::NotEqual,
- scratch,
- self.runtime.array_prototype.0 as i64,
+ &Address::new(shape, layout.shape_prototype as i32),
+ self.runtime.array_prototype.compressed() as i32,
fail,
);
self.masm
@@ -225,10 +224,13 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
let offsets = self.runtime.offsets;
let layout = self.runtime.layout;
self.emit_load_compressed_cell(scratch, &Address::new(object, offsets.object_shape as i32));
- self.masm
- .load64(scratch, &Address::new(scratch, layout.shape_prototype as i32));
+ self.masm.branch32_memory_imm(
+ Condition::NotEqual,
+ &Address::new(scratch, layout.shape_prototype as i32),
+ CellId(expected).compressed() as i32,
+ fail,
+ );
self.masm.move_imm64(dst, expected);
- self.masm.branch64(Condition::NotEqual, scratch, dst, fail);
self.masm.load32(
scratch,
&Address::new(dst, layout.object_indexed_array_like_size as i32),
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
index d1274842aca..16406588aba 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/call_stub.rs
@@ -506,8 +506,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
.store64(&field(offsets.execution_context_variable_environment), scratch);
self.masm.bind(prepared_environment);
self.emit_load_compressed_cell(scratch, &Address::new(function_register, offsets.object_shape as i32));
- self.masm
- .load64(scratch, &Address::new(scratch, layout.shape_realm as i32));
+ self.emit_load_compressed_cell(scratch, &Address::new(scratch, layout.shape_realm as i32));
self.masm.store64(&field(offsets.execution_context_realm), scratch);
self.masm
.store64(&field(offsets.execution_context_executable), executable_register);
@@ -792,7 +791,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
self.masm
.store64(&field(offsets.execution_context_function), function_register);
self.emit_load_compressed_cell(temp, &Address::new(function_register, offsets.object_shape as i32));
- self.masm.load64(temp, &Address::new(temp, layout.shape_realm as i32));
+ self.emit_load_compressed_cell(temp, &Address::new(temp, layout.shape_realm as i32));
self.masm.store64(&field(offsets.execution_context_realm), temp);
self.masm.store32(&field(offsets.execution_context_slot_count), count);
self.masm
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
index 20a9bc1c00d..d6aa66edcfd 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/mod.rs
@@ -1645,17 +1645,15 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
let exit = self.exit_site(node_id);
let output = self.output(node_id);
let field = self.emit_load_accessor(node_id, output, *offset, *part, exit)?;
- self.masm.load64(output, &field);
- self.masm.branch_test64(Condition::Zero, output, u64::MAX, exit);
+ self.emit_load_compressed_cell_or_branch(output, &field, exit);
self.box_object(output);
}
Op::CheckAccessorFunction { offset, part, function } => {
let exit = self.exit_site(node_id);
let accessor = Gpr(self.allocation.node(node_id).temps[0]);
let field = self.emit_load_accessor(node_id, accessor, *offset, *part, exit)?;
- let scratch = self.pinned.scratch;
- self.masm.move_imm64(scratch, function.0);
- self.masm.branch64_memory(Condition::NotEqual, &field, scratch, exit);
+ self.masm
+ .branch32_memory_imm(Condition::NotEqual, &field, function.compressed() as i32, exit);
}
Op::LoadNamed { offset, holds_data } => {
let exit = (!holds_data).then(|| self.exit_site(node_id));
@@ -1885,9 +1883,11 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
exit,
);
self.emit_load_compressed_cell(object, &Address::new(object, offsets.object_shape as i32));
- self.masm
- .load64(object, &Address::new(object, layout.shape_prototype as i32));
- self.masm.branch_test64(Condition::Zero, object, u64::MAX, not_found);
+ self.emit_load_compressed_cell_or_branch(
+ object,
+ &Address::new(object, layout.shape_prototype as i32),
+ not_found,
+ );
self.emit_unbox_cell(output, prototype);
self.masm.branch64(Condition::Equal, object, output, found);
self.masm.jump(walk);
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs
index f3dbe8770d6..bdcfe100370 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs
@@ -281,7 +281,7 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {
// Entries without a prototype chain validity are for shapes without
// a prototype.
self.emit_load_compressed_cell(shape, &Address::new(object, offsets.object_shape as i32));
- self.masm.branch64_memory_imm(
+ self.masm.branch32_memory_imm(
Condition::NotEqual,
&Address::new(shape, layout.shape_prototype as i32),
0,
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
index 8279d9d05f6..cf8fa3c224d 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs
@@ -2491,7 +2491,7 @@ mod property_access {
/// `Array.prototype.push` against fake arrays: `[shape, flags, named
/// property storage, elements, storage kind (byte 0) and size (bytes
/// 4-7), length writable (byte 0) and proxy target (byte 1)]`, with
- /// shapes `[dictionary generation, prototype]`.
+ /// shapes `[dictionary generation, compressed prototype]`.
mod array_push {
use super::*;
use crate::snapshot::Intrinsic;
@@ -2509,11 +2509,11 @@ mod property_access {
value::int32(99)
}
- struct FakeObject(Box<[u64; 6]>);
+ struct FakeObject(&'static mut [u64]);
impl FakeObject {
fn new(shape: &Cell, flags: u64, elements: &[u64], size: u32) -> Self {
- Self(Box::new([
+ Self(fake_heap::low_cell(&[
fake_heap::low_compressed(shape.address()),
flags,
0,
@@ -2547,9 +2547,9 @@ mod property_access {
fn new() -> Self {
let object_prototype_shape = Cell::new([0, 0, 0]);
let object_prototype = FakeObject::new(&object_prototype_shape, EXTENSIBLE, &[], 0);
- let array_prototype_shape = Cell::new([0, object_prototype.address(), 0]);
- let mut array_prototype = FakeObject::new(&array_prototype_shape, EXTENSIBLE, &[], 0);
- let array_shape = Cell::new([0, array_prototype.address(), 0]);
+ let array_prototype_shape = Cell::new([0, fake_heap::low_compressed(object_prototype.address()), 0]);
+ let array_prototype = FakeObject::new(&array_prototype_shape, EXTENSIBLE, &[], 0);
+ let array_shape = Cell::new([0, fake_heap::low_compressed(array_prototype.address()), 0]);
let push = Cell::new([0; 3]);
let methods = vec![(u64::from(value::OBJECT_TAG) << 48) | push.address()].into_boxed_slice();
array_prototype.0[2] = methods.as_ptr() as u64;
@@ -2644,7 +2644,7 @@ mod property_access {
assert_eq!(grown.0[4] >> 32, 2);
// Arrays without indexed properties yet.
- let mut empty = array(&world, &buffer(0, 0), 0);
+ let empty = array(&world, &buffer(0, 0), 0);
empty.0[3] = 0;
empty.0[4] = 0;
assert_eq!(world.push(&empty), (returned(value::int32(99)), vec![]));
@@ -2653,7 +2653,7 @@ mod property_access {
#[test]
fn pushes_exit_for_arrays_they_cannot_append_to_unobservably() {
- let mut world = World::new();
+ let world = World::new();
let elements = buffer(1, 4);
let exits = |world: &World, change: &dyn Fn(&mut FakeObject)| {
let mut pushed = array(world, &elements, 1);
@@ -3723,6 +3723,8 @@ mod direct_calls {
callee: Callee,
function: &'static mut [u64],
shape: &'static mut [u64],
+ /// The realm of the shape, a cell in the region.
+ realm: u64,
shared_data: &'static mut [u64],
}
@@ -3740,7 +3742,8 @@ mod direct_calls {
fn new(formal_parameter_count: u64, flags: u64) -> Self {
let callee = Callee::new();
callee.executable[EXECUTABLE_ARGUMENTS_BASE_WORD] = 9;
- let shape = fake_heap::cell(&[REALM]);
+ let realm = fake_heap::cell(&[0]).as_ptr() as u64;
+ let shape = fake_heap::cell(&[fake_heap::compressed(realm)]);
let shared_data = fake_heap::cell(&[
fake_heap::compressed(callee.executable.as_ptr() as u64),
formal_parameter_count | flags,
@@ -3757,6 +3760,7 @@ mod direct_calls {
callee,
function,
shape,
+ realm,
shared_data,
}
}
@@ -3842,7 +3846,7 @@ mod direct_calls {
let half = |offset: usize| (frame[offset / 8] >> (8 * (offset % 8))) as u32;
let byte = |offset: usize| (frame[offset / 8] >> (8 * (offset % 8))) as u8;
assert_eq!(word(64), callee.function.as_ptr() as u64, "function");
- assert_eq!(word(72), REALM);
+ assert_eq!(word(72), callee.realm);
assert_eq!((word(80), word(88)), (FUNCTION_WORDS[2], FUNCTION_WORDS[3]));
assert_eq!(
(word(8), word(96), word(16)),
@@ -4211,7 +4215,8 @@ mod direct_calls {
const RAW_NATIVE_FLAG: u16 = 1 << 7;
for through_call in [false, true] {
let mut callee = DynamicCallee::new(0, 0);
- let shape = fake_heap::cell(&[REALM]);
+ let realm = fake_heap::cell(&[0]).as_ptr() as u64;
+ let shape = fake_heap::cell(&[fake_heap::compressed(realm)]);
// Native function index 1, with a bit above the table's index mask that the call stub drops.
let native = fake_heap::cell(&[
fake_heap::compressed(shape.as_ptr() as u64),
@@ -4258,7 +4263,7 @@ mod direct_calls {
assert_eq!(state.generic_calls, 0);
let frame = &state.direct.callee_frames[0];
assert_eq!(frame[64 / 8], native.as_ptr() as u64, "function");
- assert_eq!(frame[72 / 8], REALM);
+ assert_eq!(frame[72 / 8], realm);
assert_eq!(frame[32 / 8], 0, "no executable");
assert_eq!(machine.vm[0], machine.frame.as_ptr() as u64);
assert_eq!(machine.vm[3], stack);
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
index f5aba6c16d6..3306ee39f14 100644
--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs
@@ -1373,16 +1373,15 @@ impl FakeArray {
}
}
-/// A fake shape with `words`, in the low fake heap so that objects can have
-/// it as their compressed shape.
-fn fake_shape(words: &[u64]) -> &'static mut [u64] {
+/// A fake cell with `words`, in the low fake heap so that other cells can
+/// point to it compressed (see `fake_heap::low_cell()`).
+fn low_cell(words: &[u64]) -> &'static mut [u64] {
super::fake_heap::low_cell(words)
}
-/// The shape word of an object with the fake shape `shape`: its compressed
-/// pointer.
-fn shape_word(shape: &[u64]) -> u64 {
- super::fake_heap::low_compressed(shape.as_ptr() as u64)
+/// The compressed pointer to the low fake cell `cell`.
+fn compressed(cell: &[u64]) -> u64 {
+ super::fake_heap::low_compressed(cell.as_ptr() as u64)
}
/// A typed array of `kind` over `data`.
@@ -1785,9 +1784,9 @@ fn property_iterator_next(receiver: u64, keys: u64, cursor: u64) -> (u64, u64, u
#[test]
fn property_iterator_next_reads_key_snapshots() {
- let shape = fake_shape(&[0; 12]);
+ let shape = low_cell(&[0; 12]);
let mut object = FakeArray::new(0, PACKED, 2, &[], 2);
- object.object[6] = shape_word(shape);
+ object.object[6] = compressed(shape);
let keys = [value::int32(100), value::int32(101)];
let named = FakeKeySnapshot::new(1, &shape, &keys);
let empty = value::EMPTY;
@@ -1806,7 +1805,7 @@ fn property_iterator_next_reads_key_snapshots() {
(empty, value::TRUE, value::int32(2), 0)
);
// Other shapes, cursors and receivers are slow.
- let other_shape = fake_shape(&[0; 12]);
+ let other_shape = low_cell(&[0; 12]);
let other = FakeKeySnapshot::new(1, other_shape, &keys);
assert_eq!(
property_iterator_next(object.value(), other.value(), value::int32(0)).3,
@@ -2182,7 +2181,7 @@ impl FakeGlobals {
realm: vec![0; 8],
object: vec![0; 8],
named_properties: vec![value::int32(10), u64::from(0xFFFC_u16) << 48 | 0x1000, value::int32(12)],
- shape: fake_shape(&[0; 12]),
+ shape: low_cell(&[0; 12]),
environment: FakeEnvironment::new(
&[value::int32(20), value::EMPTY, value::int32(22)],
&[BINDING_MUTABLE, BINDING_MUTABLE, 0],
@@ -2192,7 +2191,7 @@ impl FakeGlobals {
executable: vec![0; 4],
caches: vec![0; 16],
});
- globals.object[6] = shape_word(globals.shape);
+ globals.object[6] = compressed(globals.shape);
globals.object[7] = globals.named_properties.as_ptr() as u64;
globals.shape[10] = 7 << 32;
globals.environment.words[8] = 99;
@@ -2456,21 +2455,21 @@ fn instance_of_global_functions_walks_prototype_chains() {
let (ordinary_methods, exotic_methods) = (vec![0u64], vec![0x1234u64]);
let ordinary_class = vec![0, ordinary_methods.as_ptr() as u64];
let exotic_class = vec![0, exotic_methods.as_ptr() as u64];
- // Objects of the class whose shape has the prototype (at
+ // Objects of the class whose shape has the compressed prototype (at
// `shape_prototype`, 0), with named properties.
struct Fake {
- object: Vec<u64>,
+ object: &'static mut [u64],
shape: &'static mut [u64],
properties: Vec<u64>,
}
let fake = |class: &[u64], prototype: Option<&Fake>, properties: Vec<u64>| {
- let mut fake = Box::new(Fake {
- object: vec![0; 8],
- shape: fake_shape(&[prototype.map_or(0, |prototype| prototype.object.as_ptr() as u64)]),
+ let fake = Box::new(Fake {
+ object: low_cell(&[0; 8]),
+ shape: low_cell(&[prototype.map_or(0, |prototype| compressed(prototype.object))]),
properties,
});
fake.object[0] = class.as_ptr() as u64;
- fake.object[6] = shape_word(fake.shape);
+ fake.object[6] = compressed(fake.shape);
fake.object[7] = fake.properties.as_ptr() as u64;
fake
};
@@ -2863,7 +2862,7 @@ impl FakeCachedObject {
.into_iter()
.chain(properties.iter().copied())
.collect(),
- shape: fake_shape(&[0; 12]),
+ shape: low_cell(&[0; 12]),
entry: vec![0; 6],
caches: vec![0; 2],
executable: vec![0; 4],
@@ -2872,7 +2871,7 @@ impl FakeCachedObject {
keyed_store_cache: std::cell::Cell::new(0),
});
fake.object[5] = 2;
- fake.object[6] = shape_word(fake.shape);
+ fake.object[6] = compressed(fake.shape);
fake.object[7] = fake.properties[1..].as_ptr() as u64;
fake.shape[10] = 5 << 32;
fake.caches[1] = fake.entry.as_ptr() as u64 | 1;
@@ -3055,9 +3054,9 @@ fn get_by_id_reads_direct_getter_wrappers_inline() {
// property 1 whose getter reads the implementation's word 2, and the
// main world wrapper of that through the implementation's word 1 and
// the weak reference's word 1.
- let function = vec![0u64; 4];
+ let function = low_cell(&[0; 4]);
let mut accessor = vec![0u64; 3];
- accessor[1] = function.as_ptr() as u64;
+ accessor[1] = compressed(function);
let accessor_value = u64::from(0xFFFC_u16) << 48 | accessor.as_ptr() as u64;
let mut fake = FakeCachedObject::new(&[value::int32(10), accessor_value]);
let mut result = vec![0u64; 2];
@@ -3157,9 +3156,9 @@ fn put_by_id_calls_native_setters_of_prototypes() {
use crate::builder::tests::property_access::{cache, own};
use crate::snapshot::{AccessorFunctionSnapshot, CellId, NativeCallTarget, PropertyCacheEntryType};
// A prototype whose property 0 is an accessor with a native setter.
- let function = vec![0u64; 4];
+ let function = low_cell(&[0; 4]);
let mut accessor = vec![0u64; 3];
- accessor[2] = function.as_ptr() as u64;
+ accessor[2] = compressed(function);
let accessor_value = u64::from(0xFFFC_u16) << 48 | accessor.as_ptr() as u64;
let prototype = FakeCachedObject::new(&[accessor_value]);
let validity = vec![1u64];
@@ -3218,11 +3217,11 @@ fn put_by_id_calls_native_setters_of_prototypes() {
#[test]
fn put_by_id_adds_properties_through_property_caches() {
let mut fake = FakeCachedObject::new(&[value::int32(10), value::int32(11), value::EMPTY]);
- let old_shape = shape_word(fake.shape);
+ let old_shape = compressed(fake.shape);
// A shape with three properties, and dictionary generation 5.
- let new_shape = fake_shape(&[0; 12]);
+ let new_shape = low_cell(&[0; 12]);
new_shape[10] = 3 | 5 << 32;
- let new_shape_word = shape_word(new_shape);
+ let new_shape_word = compressed(new_shape);
fake.set_add_entry(new_shape, 2);
let add = |fake: &mut FakeCachedObject, flags: u16| {
fake.object[1] = u64::from(flags);
@@ -4347,22 +4346,22 @@ fn keyed_accesses_of_missing_and_added_properties_through_property_caches() {
assert_eq!(fake.properties[2], value::NULL);
// Additions, from the shape the entry adds a property to.
- let new_shape = fake_shape(&[0; 12]);
+ let new_shape = low_cell(&[0; 12]);
new_shape[10] = 3 | 5 << 32;
let new_shape_address = new_shape.as_ptr() as u64;
set_entry(&mut data, 1, 2, new_shape_address, shape);
assert_eq!(put(&fake, other_key, value::TRUE), 1);
assert_eq!(put(&fake, key, value::TRUE), 0);
- assert_eq!(fake.object[6], shape_word(new_shape));
+ assert_eq!(fake.object[6], compressed(new_shape));
assert_eq!(fake.properties[3], value::TRUE);
// Objects that already have the new shape take the slow path.
assert_eq!(put(&fake, key, value::FALSE), 1);
assert_eq!(fake.properties[3], value::TRUE);
// So do objects that may not cache additions.
- fake.object[6] = shape_word(fake.shape);
+ fake.object[6] = compressed(fake.shape);
fake.object[1] = u64::from(FLAG_IS_EXTENSIBLE | FLAG_HAS_MAGICAL_LENGTH);
assert_eq!(put(&fake, key, value::FALSE), 1);
- assert_eq!(fake.object[6], shape_word(fake.shape));
+ assert_eq!(fake.object[6], compressed(fake.shape));
std::hint::black_box(&data);
}
diff --git a/Libraries/LibJS/Runtime/Shape.h b/Libraries/LibJS/Runtime/Shape.h
index 4e43062a130..9c0e79b3e3f 100644
--- a/Libraries/LibJS/Runtime/Shape.h
+++ b/Libraries/LibJS/Runtime/Shape.h
@@ -13,6 +13,7 @@
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <AK/kmalloc.h>
+#include <LibGC/CompressedPointer.h>
#include <LibGC/Weak.h>
#include <LibGC/WeakInlines.h>
#include <LibJS/Embedding/Layout.h>
@@ -30,14 +31,14 @@ namespace JS {
// are fields of the runtime's shape.
class JS_API Shape final : public EngineCell {
public:
- Realm& realm() const { return *field_at<Realm*>(JS_LAYOUT_SHAPE_REALM_OFFSET); }
+ Realm& realm() const { return *reinterpret_cast<Realm*>(GC::decompress_nonnull(field_at<u32>(JS_LAYOUT_SHAPE_REALM_OFFSET))); }
- Object* prototype() { return field_at<Object*>(JS_LAYOUT_SHAPE_PROTOTYPE_OFFSET); }
- Object const* prototype() const { return field_at<Object*>(JS_LAYOUT_SHAPE_PROTOTYPE_OFFSET); }
+ Object* prototype() { return reinterpret_cast<Object*>(GC::decompress(field_at<u32>(JS_LAYOUT_SHAPE_PROTOTYPE_OFFSET))); }
+ Object const* prototype() const { return reinterpret_cast<Object const*>(GC::decompress(field_at<u32>(JS_LAYOUT_SHAPE_PROTOTYPE_OFFSET))); }
private:
- static_assert(JS_LAYOUT_SHAPE_REALM_SIZE == sizeof(void*));
- static_assert(JS_LAYOUT_SHAPE_PROTOTYPE_SIZE == sizeof(void*));
+ static_assert(JS_LAYOUT_SHAPE_REALM_SIZE == sizeof(u32));
+ static_assert(JS_LAYOUT_SHAPE_PROTOTYPE_SIZE == sizeof(u32));
template<typename Field>
Field field_at(size_t offset) const
diff --git a/Libraries/LibJS/Rust/generate/layout_table.rs b/Libraries/LibJS/Rust/generate/layout_table.rs
index ae393b613ce..e1415559ffa 100644
--- a/Libraries/LibJS/Rust/generate/layout_table.rs
+++ b/Libraries/LibJS/Rust/generate/layout_table.rs
@@ -182,7 +182,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
size!(w, "OBJECT_SIZE", Object);
w.section("Accessor layout");
- field!(w, "ACCESSOR_GETTER", "Accessor.getter", "FunctionObject", Accessor, getter, 8, "nullable", "cell");
+ field!(w, "ACCESSOR_GETTER", "Accessor.getter", "FunctionObject", Accessor, getter, 4, "nullable", "compressed");
w.section("Object flags");
field!(w, "OBJECT_FLAGS", "Object.flags", "u16", Object, flags, 2, "nullable", "scalar");
@@ -198,7 +198,7 @@ pub fn generate(configuration: &LayoutConfiguration) -> LayoutWriter {
w.constant("OBJECT_FLAG_IS_HTMLDDA", object_flag::IS_HTMLDDA);
w.section("Shape layout");
- field!(w, "SHAPE_REALM", "Shape.realm", "Realm", Shape, realm, 8, "nonnull", "cell");
+ field!(w, "SHAPE_REALM", "Shape.realm", "Realm", Shape, realm, 4, "nonnull", "compressed");
offset!(w, "SHAPE_PROTOTYPE", Shape, prototype);
field!(w, "SHAPE_DICTIONARY_GENERATION", "Shape.dictionary_generation", "u32", Shape, dictionary_generation, 4, "nullable", "scalar");
w.constant("SHAPE_SIZE", size_of::<Shape>());
diff --git a/Libraries/LibJS/Rust/src/layout/accessor.rs b/Libraries/LibJS/Rust/src/layout/accessor.rs
index da143e41186..3ead811dd13 100644
--- a/Libraries/LibJS/Rust/src/layout/accessor.rs
+++ b/Libraries/LibJS/Rust/src/layout/accessor.rs
@@ -6,7 +6,7 @@
use core::cell::Cell;
-use super::cell::{CellHeader, Gc};
+use super::cell::CellHeader;
use super::function_object::FunctionObject;
use super::member::NullableMember;
use crate::layout_forward::Symbol;
@@ -17,8 +17,8 @@ pub struct Accessor {
/// NB: The fields the interpreter does not read come first, in the bytes after the header.
pub cache_on_receiver: Cell<bool>,
pub cached_value_key: NullableMember<Symbol>,
- pub getter: Cell<Option<Gc<FunctionObject>>>,
- pub setter: Cell<Option<Gc<FunctionObject>>>,
+ pub getter: NullableMember<FunctionObject>,
+ pub setter: NullableMember<FunctionObject>,
}
-const _: () = assert!(size_of::<Accessor>() == 32);
+const _: () = assert!(size_of::<Accessor>() == 24);
diff --git a/Libraries/LibJS/Rust/src/layout/shape.rs b/Libraries/LibJS/Rust/src/layout/shape.rs
index 4eb117cc735..72c22022ede 100644
--- a/Libraries/LibJS/Rust/src/layout/shape.rs
+++ b/Libraries/LibJS/Rust/src/layout/shape.rs
@@ -6,8 +6,8 @@
use core::cell::Cell;
-use super::cell::{CellHeader, Gc};
-use super::member::NullableMember;
+use super::cell::CellHeader;
+use super::member::{Member, NullableMember};
use super::object::Object;
use super::property_lookup_cache::ObjectPropertyIteratorCacheData;
use super::realm::Realm;
@@ -17,9 +17,8 @@ use crate::layout_forward::{ShapeStorage, SpecialPropertyCache, WatchpointSetSto
pub struct Shape {
pub header: CellHeader,
pub flags: Cell<u8>,
- pub realm: Cell<Gc<Realm>>,
- pub prototype: Cell<Option<Gc<Object>>>,
- // NB: The interpreter does not read these four, which fill the word pair before the fields it reads after them.
+ pub realm: Member<Realm>,
+ pub prototype: NullableMember<Object>,
pub prototype_chain_validity: NullableMember<WatchpointSet>,
pub property_iterator_cache: NullableMember<ObjectPropertyIteratorCacheData>,
/// The shape this one transitioned from, unless it changed the prototype. Transition caches only hold their
diff --git a/Libraries/LibJS/Rust/src/runtime/accessor.rs b/Libraries/LibJS/Rust/src/runtime/accessor.rs
index 9d298040078..ad489129bdb 100644
--- a/Libraries/LibJS/Rust/src/runtime/accessor.rs
+++ b/Libraries/LibJS/Rust/src/runtime/accessor.rs
@@ -36,8 +36,8 @@ impl Accessor {
assert!(cached_value_key.is_none_or(|cached_value_key| cached_value_key.is_private()));
vm.heap().allocate(|_| Accessor {
header: CellHeader::for_class(Self::CLASS),
- getter: Cell::new(getter),
- setter: Cell::new(setter),
+ getter: NullableMember::new(getter),
+ setter: NullableMember::new(setter),
cache_on_receiver: Cell::new(false),
cached_value_key: NullableMember::new(cached_value_key),
})
diff --git a/Libraries/LibJS/Rust/src/runtime/shape.rs b/Libraries/LibJS/Rust/src/runtime/shape.rs
index f9d83d55763..3313d8a7549 100644
--- a/Libraries/LibJS/Rust/src/runtime/shape.rs
+++ b/Libraries/LibJS/Rust/src/runtime/shape.rs
@@ -20,7 +20,7 @@ use crate::gc::weak::GcWeak;
use crate::interpreter::vm::Vm;
use crate::jit::dependencies::{CellId, Dependency};
use crate::layout::cell::{CellHeader, Gc};
-use crate::layout::member::NullableMember;
+use crate::layout::member::{Member, NullableMember};
use crate::layout::object::Object;
use crate::layout::property_lookup_cache::ObjectPropertyIteratorCacheData;
pub use crate::layout::shape::Shape;
@@ -149,7 +149,7 @@ pub struct ShapeStorage {
}
// NB: Every shape has these bytes.
-const _: () = assert!(size_of::<Shape>() == 128);
+const _: () = assert!(size_of::<Shape>() == 120);
impl ShapeStorage {
fn new(_: &DeferGc<'_>) -> Self {
@@ -324,8 +324,8 @@ impl Shape {
Self {
header: CellHeader::for_class(Self::CLASS),
flags: Cell::new(0),
- realm: Cell::new(realm),
- prototype: Cell::new(None),
+ realm: Member::new(realm),
+ prototype: NullableMember::null(),
prototype_chain_validity: NullableMember::null(),
property_iterator_cache: NullableMember::null(),
previous: NullableMember::null(),