Skip to content

Truly independent web browser

LibJS: Cache missing properties in `length` and `super` reads

Tim Ledbetterbe61de38b42c
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
index a75ced9a255..684512dd461 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/aarch64.S
@@ -5633,6 +5633,9 @@ asm_handler_GetLength:
ldp x4, x3, [x0, #24]
cmp x4, x2
b.ne .Lasm_GetLength.ssa_block_1
+ ldr w4, [x0]
+ cmp w4, #6
+ b.eq .Lasm_GetLength.ssa_block_1
cbnz x3, .Lasm_GetLength.ssa_block_1
ldp w3, w0, [x0, #4]
ldr w9, [x2, #52]
diff --git a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
index 98ecd869f50..9055d09394e 100644
--- a/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
+++ b/Libraries/LibJS/Flap/tests/interpreter-assembly/x86_64.S
@@ -5715,6 +5715,9 @@ asm_handler_GetLength:
mov rax, QWORD PTR [rcx + 32]
cmp rdi, rsi
jne .Lasm_GetLength.ssa_block_1
+ mov edi, DWORD PTR [rcx]
+ cmp edi, 6
+ je .Lasm_GetLength.ssa_block_1
test rax, rax
jnz .Lasm_GetLength.ssa_block_1
mov eax, DWORD PTR [rcx + 8]
diff --git a/Libraries/LibJS/Interpreter/interpreter.flap b/Libraries/LibJS/Interpreter/interpreter.flap
index c048061101c..138ae0c737f 100644
--- a/Libraries/LibJS/Interpreter/interpreter.flap
+++ b/Libraries/LibJS/Interpreter/interpreter.flap
@@ -3693,6 +3693,7 @@ handler GetLength(
let shape = object.shape;
guard let property_cache = load_property_lookup_cache(cache) else slow;
guard property_cache.shape == shape else slow;
+ guard property_cache.entry_type != PROPERTY_LOOKUP_CACHE_ENTRY_TYPE_GET_MISSING_PROPERTY else slow;
guard property_cache.prototype == 0 else slow;
guard property_cache.shape_dictionary_generation == shape.dictionary_generation else slow;
let value = object.named_properties[property_cache.property_offset];
diff --git a/Libraries/LibJS/Rust/src/bytecode/property_access.rs b/Libraries/LibJS/Rust/src/bytecode/property_access.rs
index d36b713dcf3..71c91338d04 100644
--- a/Libraries/LibJS/Rust/src/bytecode/property_access.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/property_access.rs
@@ -35,12 +35,6 @@ pub enum GetByIdMode {
Length,
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum CachePropertyAbsence {
- No,
- Yes,
-}
-
/// Whether the code doing a property access is strict mode code.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Strict {
@@ -305,7 +299,6 @@ pub fn base_object_for_get(
throw_null_or_undefined_property_get(vm, base_value, get_base_identifier, property_name)
}
-#[allow(clippy::too_many_arguments)]
pub fn get_by_id(
vm: &Vm,
mode: GetByIdMode,
@@ -314,7 +307,6 @@ pub fn get_by_id(
base_value: Value,
this_value: Value,
cache: &PropertyLookupCache,
- cache_property_absence: CachePropertyAbsence,
) -> ThrowCompletionOr<Value> {
if mode == GetByIdMode::Length && base_value.is_string() {
return Ok(Value::from_f64(
@@ -338,15 +330,7 @@ pub fn get_by_id(
return Ok(Value::from_f64(f64::from(base_obj.indexed_array_like_size())));
}
- get_with_property_lookup_cache(
- vm,
- base_obj,
- property_name,
- this_value,
- cache,
- cache_property_absence,
- 0,
- )
+ get_with_property_lookup_cache(vm, base_obj, property_name, this_value, cache, 0)
}
/// Gets the property from `base_obj` through `cache`, filling the cache on a miss. `cache_key` is the key the cache's
@@ -358,7 +342,6 @@ pub fn get_with_property_lookup_cache(
property_name: &PropertyKey,
this_value: Value,
cache: &PropertyLookupCache,
- cache_property_absence: CachePropertyAbsence,
cache_key: u64,
) -> ThrowCompletionOr<Value> {
let shape = base_obj.shape();
@@ -373,9 +356,6 @@ pub fn get_with_property_lookup_cache(
}
let entry_type = cache_entry.entry_type.get();
if entry_type == PropertyLookupCacheEntryType::GetMissingProperty {
- if cache_property_absence == CachePropertyAbsence::No {
- continue;
- }
if !base_obj.is_cacheable_for_property_absence() {
continue;
}
@@ -476,9 +456,7 @@ pub fn get_with_property_lookup_cache(
entry.shape_dictionary_generation = shape.dictionary_generation();
});
}
- CacheableGetPropertyMetadataType::GetMissingProperty
- if cache_property_absence == CachePropertyAbsence::Yes =>
- {
+ CacheableGetPropertyMetadataType::GetMissingProperty => {
cache.update(PropertyLookupCacheEntryType::GetMissingProperty, |entry| {
entry.key = cache_key;
entry.shape = Some(shape);
diff --git a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
index aecacba30c6..8956496a1f0 100644
--- a/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
+++ b/Libraries/LibJS/Rust/src/interpreter/slow_paths/property_access.rs
@@ -20,9 +20,9 @@ use crate::bytecode::executable::{
};
use crate::bytecode::op;
use crate::bytecode::property_access::{
- self, CachePropertyAbsence, GetByIdMode, Strict, base_object_for_get, get_by_value_with_keyed_cache,
- get_cached_property_value, get_with_property_lookup_cache, object_can_cache_property_additions,
- property_addition_is_cacheable, put_by_property_key,
+ self, GetByIdMode, Strict, base_object_for_get, get_by_value_with_keyed_cache, get_cached_property_value,
+ get_with_property_lookup_cache, object_can_cache_property_additions, property_addition_is_cacheable,
+ put_by_property_key,
};
use crate::gc::class::GcCell;
use crate::gc::class::class_of;
@@ -144,7 +144,6 @@ pub fn get_by_id(vm: &Vm, pc: u32, instruction: &op::GetById, values: &mut op::G
base_value,
base_value,
cache,
- CachePropertyAbsence::Yes,
)
);
values.dst = value;
@@ -208,7 +207,6 @@ pub fn get_by_id_with_this(
base_value,
this_value,
cache,
- CachePropertyAbsence::No,
)
);
values.dst = value;
@@ -300,15 +298,7 @@ fn get_by_value_with_site_cache(
cache_key: u64,
) -> ThrowCompletionOr<Value> {
if property_key.is_symbol() {
- return get_with_property_lookup_cache(
- vm,
- object,
- property_key,
- base,
- cache,
- CachePropertyAbsence::Yes,
- cache_key,
- );
+ return get_with_property_lookup_cache(vm, object, property_key, base, cache, cache_key);
}
get_by_value_with_keyed_cache(vm, object, base, property_key, Some((cache, cache_key)))
}
@@ -419,7 +409,6 @@ pub fn get_length(vm: &Vm, pc: u32, instruction: &op::GetLength, values: &mut op
base_value,
base_value,
cache,
- CachePropertyAbsence::No,
)
);
values.dst = value;
@@ -447,7 +436,6 @@ pub fn get_length_with_this(
base_value,
this_value,
cache,
- CachePropertyAbsence::No,
)
);
values.dst = value;
diff --git a/Libraries/LibJS/Rust/src/runtime/value.rs b/Libraries/LibJS/Rust/src/runtime/value.rs
index a6a9021afd5..21d7bad8dc1 100644
--- a/Libraries/LibJS/Rust/src/runtime/value.rs
+++ b/Libraries/LibJS/Rust/src/runtime/value.rs
@@ -13,7 +13,7 @@ use num_traits::Zero;
use crate::build_configuration::HEAP_REGION_OFFSET_MASK;
use crate::bytecode::executable::{PropertyLookupCache, StaticPropertyLookupCacheSite};
-use crate::bytecode::property_access::{CachePropertyAbsence, GetByIdMode, get_by_id};
+use crate::bytecode::property_access::{GetByIdMode, get_by_id};
use crate::gc::capi::js_heap_region_base;
use crate::gc::class_id::ClassId;
use crate::interpreter::vm::Vm;
@@ -989,16 +989,7 @@ impl Value {
if self.is_nullish() {
return vm.throw_completion(ErrorKind::TypeError, ErrorType::ToObjectNullOrUndefined, &[]);
}
- get_by_id(
- vm,
- GetByIdMode::Normal,
- || None,
- property_key,
- self,
- self,
- cache,
- CachePropertyAbsence::Yes,
- )
+ get_by_id(vm, GetByIdMode::Normal, || None, property_key, self, self, cache)
}
// 7.3.11 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod