Truly independent web browser
LibJS: Use cached missing properties of arrays and strings in JIT code
Tim Ledbetter788b4b08b70a
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rsindex 79f9c81a6f6..fc6d4493f0a 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs@@ -210,9 +210,9 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {/// Branches to `miss` unless the `GetMissingProperty` entry in `entry`/// for the shape of `object` applies to it, like- /// `get_with_property_lookup_cache()`: only plain objects and ECMAScript- /// functions (for the names their entries can be for) have no other- /// properties than those of their shape (see+ /// `get_with_property_lookup_cache()`: only plain objects, ECMAScript+ /// functions, arrays and String objects (for the names their entries can+ /// be for) have no other properties than those of their shape (see/// `Object::is_cacheable_for_property_absence()`), and the property/// must also be missing from an unchanged prototype chain. Clobbers/// `shape`.@@ -230,14 +230,20 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {self.masm.move_imm64(scratch, plain_object_vtable);self.masm.branch64_memory(Condition::Equal, &Address::new(object, 0), scratch, cacheable);- let function_flag = self.runtime.dynamic_calls.object_flag_is_ecmascript_function;- if function_flag == 0 {+ for class in [layout.string_object_class, layout.string_prototype_class] {+ self.masm.move_imm64(scratch, class);+ self.masm+ .branch64_memory(Condition::Equal, &Address::new(object, 0), scratch, cacheable);+ }+ let flags =+ self.runtime.dynamic_calls.object_flag_is_ecmascript_function | layout.object_flag_has_magical_length;+ if flags == 0 {self.masm.jump(miss);} else {self.masm.load16(scratch, &Address::new(object, offsets.object_flags as i32));self.masm- .branch_test32(Condition::Zero, scratch, u32::from(function_flag), miss);+ .branch_test32(Condition::Zero, scratch, u32::from(flags), miss);}self.masm.bind(cacheable);let (has_chain, done) = (self.masm.new_label(), self.masm.new_label());diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rsindex 1e56ff605f0..a7b204a593d 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs@@ -132,6 +132,11 @@ static NO_PROPERTY_CACHES: [u64; 16] = [0; 16];/// ones.const PLAIN_OBJECT_VTABLE: u64 = 0x7000;+/// Word 0 of fake String objects and of the fake `%String.prototype%`, like+/// the classes of real ones.+const STRING_OBJECT_CLASS: u64 = 0x7200;+const STRING_PROTOTYPE_CLASS: u64 = 0x7300;+/// What the fake cache probes find: objects whose word 0 is 1 have the/// property 42 in every cache, and accept every store into their word 1.extern "C" fn fake_try_get_by_id_cache(base: u64, _cache: *const u64) -> u64 {@@ -1179,6 +1184,8 @@ fn fake_object_layout() -> RuntimeLayout {indexed_storage_kind_holey: HOLEY,object_flag_is_extensible: FLAG_IS_EXTENSIBLE,object_flag_has_magical_length: FLAG_HAS_MAGICAL_LENGTH,+ string_object_class: STRING_OBJECT_CLASS,+ string_prototype_class: STRING_PROTOTYPE_CLASS,object_flag_may_interfere: FLAG_MAY_INTERFERE,array_length_writable: 0,array_is_proxy_target: 0,@@ -3961,13 +3968,19 @@ fn get_by_id_of_missing_properties_through_property_caches() {fake.object[0] = PLAIN_OBJECT_VTABLE;assert_eq!(fake.get(fake.value()), value::UNDEFINED);// Objects of other classes may have properties their shapes do not- // describe: the probe, then the slow path. ECMAScript functions only- // do for names whose absence is never cached.+ // describe: the probe, then the slow path. ECMAScript functions, arrays+ // and String objects only do for names whose absence is never cached.fake.object[0] = 0;assert_eq!(fake.get(fake.value()), MARKER);- fake.object[1] = u64::from(FLAG_IS_ECMASCRIPT_FUNCTION);- assert_eq!(fake.get(fake.value()), value::UNDEFINED);+ for flag in [FLAG_IS_ECMASCRIPT_FUNCTION, FLAG_HAS_MAGICAL_LENGTH] {+ fake.object[1] = u64::from(flag);+ assert_eq!(fake.get(fake.value()), value::UNDEFINED);+ }fake.object[1] = 0;+ for class in [STRING_OBJECT_CLASS, STRING_PROTOTYPE_CLASS] {+ fake.object[0] = class;+ assert_eq!(fake.get(fake.value()), value::UNDEFINED);+ }// Shapes with a prototype need a valid prototype chain.fake.object[0] = PLAIN_OBJECT_VTABLE;fake.shape[0] = 0x8000;diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex dea27deb9ed..b48cb7599e6 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -1570,6 +1570,10 @@ pub struct RuntimeLayout {pub object_flag_is_extensible: u16,/// `Object::Flag::HasMagicalLengthProperty`, which only arrays have.pub object_flag_has_magical_length: u16,+ /// The classes (pointers) of `StringObject`s and of `%String.prototype%`,+ /// which start their cells.+ pub string_object_class: u64,+ pub string_prototype_class: u64,/// `Object::Flag::MayInterfereWithIndexedPropertyAccess`.pub object_flag_may_interfere: u16,/// `Array::length_writable` and `Array::is_proxy_target` (bools).diff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex c7db5a49a59..b756dc1ca75 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -67,6 +67,8 @@ use crate::runtime::function_environment::{use crate::runtime::generator_object::GeneratorObject;use crate::runtime::module_environment::ModuleEnvironment;use crate::runtime::object::{ObjectMethods, PropertyKind};+use crate::runtime::string_object::StringObject;+use crate::runtime::string_prototype::StringPrototype;/// The addresses of the runtime functions JIT code calls, which every compile job's runtime info has.pub struct RuntimeFunctionAddresses {@@ -175,6 +177,8 @@ fn runtime_layout() -> RuntimeLayout {indexed_storage_kind_holey: IndexedStorageKind::Holey as u8,object_flag_is_extensible: object_flag::IS_EXTENSIBLE,object_flag_has_magical_length: object_flag::HAS_MAGICAL_LENGTH_PROPERTY,+ string_object_class: core::ptr::from_ref(StringObject::CLASS) as u64,+ string_prototype_class: core::ptr::from_ref(StringPrototype::CLASS) as u64,object_flag_may_interfere: object_flag::MAY_INTERFERE_WITH_INDEXED_PROPERTY_ACCESS,array_length_writable: offset(ARRAY_LENGTH_WRITABLE_OFFSET),array_is_proxy_target: offset(ARRAY_IS_PROXY_TARGET_OFFSET),