Truly independent web browser
LibJS/JIT: Use cached missing properties of DOM objects in JIT code
Andreas Klinga013050fa9cc
diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rsindex fc6d4493f0a..a6ded4d8de0 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/probes/property.rs@@ -210,11 +210,12 @@ 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, 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+ /// `get_with_property_lookup_cache()`: only objects whose class keeps the+ /// default `ObjectMethods::is_cacheable_for_property_absence` have no+ /// other properties than those of their shape (for the names their+ /// entries can be for), and the property must also be missing from an+ /// unchanged prototype chain. Plain objects, ECMAScript functions, arrays+ /// and String objects are told apart without loading the hook. Clobbers/// `shape`.pub(super) fn branch_unless_property_absence_applies(&mut self, object: Gpr, shape: Gpr, entry: Gpr, miss: Label) {let scratch = self.pinned.scratch;@@ -237,13 +238,27 @@ impl<M: PortableMacroAssembler> Codegen<'_, M> {}let flags =self.runtime.dynamic_calls.object_flag_is_ecmascript_function | layout.object_flag_has_magical_length;- if flags == 0 {+ if flags != 0 {+ self.masm+ .load16(scratch, &Address::new(object, offsets.object_flags as i32));+ self.masm+ .branch_test32(Condition::NonZero, scratch, u32::from(flags), cacheable);+ }+ if layout.default_is_cacheable_for_property_absence == 0 || layout.class_object_methods == 0 {self.masm.jump(miss);} else {+ // NB: Objects start with their class.+ self.masm.load64(shape, &Address::new(object, 0));self.masm- .load16(scratch, &Address::new(object, offsets.object_flags as i32));+ .load64(shape, &Address::new(shape, layout.class_object_methods as i32));self.masm- .branch_test32(Condition::Zero, scratch, u32::from(flags), miss);+ .move_imm64(scratch, layout.default_is_cacheable_for_property_absence);+ self.masm.branch64_memory(+ Condition::NotEqual,+ &Address::new(shape, layout.object_methods_is_cacheable_for_property_absence as i32),+ scratch,+ 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 b4dbe3f8021..fcb7f279752 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests/lowerings.rs@@ -1308,6 +1308,8 @@ fn fake_object_layout() -> RuntimeLayout {property_lookup_cache_entry_type_change_own_property: 2,class_object_methods: 8,object_methods_get_prototype_of: 0,+ object_methods_is_cacheable_for_property_absence: 0,+ default_is_cacheable_for_property_absence: 0,// NB: Tests that look in the VM's keyed lookup cache set its entries.keyed_lookup_cache_entries: 0,keyed_store_cache_entries: 0,diff --git a/Libraries/LibJS/JIT/Rust/src/snapshot.rs b/Libraries/LibJS/JIT/Rust/src/snapshot.rsindex 50e30ad4043..d8f87ac0813 100644--- a/Libraries/LibJS/JIT/Rust/src/snapshot.rs+++ b/Libraries/LibJS/JIT/Rust/src/snapshot.rs@@ -1842,6 +1842,11 @@ pub struct RuntimeLayout {/// `ObjectMethods::internal_get_prototype_of`, which is null for objects/// whose prototype is the prototype of their shape.pub object_methods_get_prototype_of: u32,+ /// `ObjectMethods::is_cacheable_for_property_absence`, and the hook that+ /// classes whose objects have no other properties than those of their+ /// shape keep there, or 0 if JIT code does not check it.+ pub object_methods_is_cacheable_for_property_absence: u32,+ pub default_is_cacheable_for_property_absence: u64,/// The entries of the VM's keyed property lookup cache, which remembers/// lookups of names on shapes for keyed accesses whose own caches do not/// have them, or 0 if JIT code does not look in it. The entry for a namediff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex e70da3e1094..55e3c58cd73 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -66,7 +66,7 @@ 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::object::{ORDINARY_OBJECT_METHODS, ObjectMethods, PropertyKind};use crate::runtime::string_object::StringObject;use crate::runtime::string_prototype::StringPrototype;@@ -339,6 +339,12 @@ fn runtime_layout() -> RuntimeLayout {property_lookup_cache_entry_type_change_own_property: PropertyLookupCacheEntryType::ChangeOwnProperty as u32,class_object_methods: offset(offset_of!(Class, object_methods)),object_methods_get_prototype_of: offset(offset_of!(ObjectMethods, internal_get_prototype_of)),+ object_methods_is_cacheable_for_property_absence: offset(offset_of!(+ ObjectMethods,+ is_cacheable_for_property_absence+ )),+ default_is_cacheable_for_property_absence: ORDINARY_OBJECT_METHODS.is_cacheable_for_property_absence as usize+ as u64,property_lookup_cache_polymorphic_tag: PROPERTY_LOOKUP_CACHE_POLYMORPHIC_DATA_TAG as u64,property_lookup_cache_polymorphic_entry_count: MAX_NUMBER_OF_SHAPES_TO_REMEMBER as u32,property_lookup_cache_entry_size: offset(size_of::<PropertyLookupCacheEntry>()),