1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +00:00

LibJS/JIT: Resolve the GetCalleeAndThisFromEnvironment cache at JIT time

This commit is contained in:
Andreas Kling 2023-11-10 13:00:36 +01:00
parent 8f4966fc5c
commit 2520c46224
4 changed files with 17 additions and 15 deletions

View file

@ -345,22 +345,21 @@ ThrowCompletionOr<Value> get_variable(Bytecode::Interpreter& interpreter, Deprec
return TRY(reference.get_value(vm));
}
ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, u32 cache_index)
ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, EnvironmentVariableCache& cache)
{
auto& vm = interpreter.vm();
Value callee = js_undefined();
Value this_value = js_undefined();
auto& cached_environment_coordinate = interpreter.current_executable().environment_variable_caches[cache_index];
if (cached_environment_coordinate.has_value()) {
if (cache.has_value()) {
auto environment = vm.running_execution_context().lexical_environment;
for (size_t i = 0; i < cached_environment_coordinate->hops; ++i)
for (size_t i = 0; i < cache->hops; ++i)
environment = environment->outer_environment();
VERIFY(environment);
VERIFY(environment->is_declarative_environment());
if (!environment->is_permanently_screwed_by_eval()) {
callee = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cached_environment_coordinate.value().index, vm.in_strict_mode()));
callee = TRY(verify_cast<DeclarativeEnvironment>(*environment).get_binding_value_direct(vm, cache.value().index, vm.in_strict_mode()));
this_value = js_undefined();
if (auto base_object = environment->with_base_object())
this_value = base_object;
@ -369,12 +368,12 @@ ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::
.this_value = this_value,
};
}
cached_environment_coordinate = {};
cache = {};
}
auto reference = TRY(vm.resolve_binding(name));
if (reference.environment_coordinate().has_value())
cached_environment_coordinate = reference.environment_coordinate();
cache = reference.environment_coordinate();
callee = TRY(reference.get_value(vm));

View file

@ -29,7 +29,7 @@ struct CalleeAndThis {
Value callee;
Value this_value;
};
ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter&, DeprecatedFlyString const& name, u32 cache_index);
ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter&, DeprecatedFlyString const& name, EnvironmentVariableCache&);
Value new_regexp(VM&, ParsedRegex const&, DeprecatedString const& pattern, DeprecatedString const& flags);
MarkedVector<Value> argument_list_evaluation(VM&, Value arguments);
ThrowCompletionOr<void> create_variable(VM&, DeprecatedFlyString const& name, Op::EnvironmentMode, bool is_global, bool is_immutable, bool is_strict);

View file

@ -692,7 +692,10 @@ ThrowCompletionOr<void> GetVariable::execute_impl(Bytecode::Interpreter& interpr
ThrowCompletionOr<void> GetCalleeAndThisFromEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto callee_and_this = TRY(get_callee_and_this_from_environment(interpreter, interpreter.current_executable().get_identifier(m_identifier), m_cache_index));
auto callee_and_this = TRY(get_callee_and_this_from_environment(
interpreter,
interpreter.current_executable().get_identifier(m_identifier),
interpreter.current_executable().environment_variable_caches[m_cache_index]));
interpreter.reg(m_callee_reg) = callee_and_this.callee;
interpreter.reg(m_this_reg) = callee_and_this.this_value;
return {};

View file

@ -1544,13 +1544,13 @@ void Compiler::compile_get_variable(Bytecode::Op::GetVariable const& op)
end.link(m_assembler);
}
static Value cxx_get_callee_and_this_from_environment(VM& vm, DeprecatedFlyString const& name, u32 cache_index, Bytecode::Register callee_reg, Bytecode::Register this_reg)
static Value cxx_get_callee_and_this_from_environment(VM& vm, DeprecatedFlyString const& name, Bytecode::Register callee_reg, Bytecode::Register this_reg, Bytecode::EnvironmentVariableCache& cache)
{
auto& bytecode_interpreter = vm.bytecode_interpreter();
auto callee_and_this = TRY_OR_SET_EXCEPTION(Bytecode::get_callee_and_this_from_environment(
bytecode_interpreter,
name,
cache_index));
cache));
bytecode_interpreter.reg(callee_reg) = callee_and_this.callee;
bytecode_interpreter.reg(this_reg) = callee_and_this.this_value;
@ -1564,13 +1564,13 @@ void Compiler::compile_get_callee_and_this_from_environment(Bytecode::Op::GetCal
Assembler::Operand::Imm(bit_cast<u64>(&m_bytecode_executable.get_identifier(op.identifier()))));
m_assembler.mov(
Assembler::Operand::Register(ARG2),
Assembler::Operand::Imm(op.cache_index()));
m_assembler.mov(
Assembler::Operand::Register(ARG3),
Assembler::Operand::Imm(op.callee().index()));
m_assembler.mov(
Assembler::Operand::Register(ARG4),
Assembler::Operand::Register(ARG3),
Assembler::Operand::Imm(op.this_().index()));
m_assembler.mov(
Assembler::Operand::Register(ARG4),
Assembler::Operand::Imm(bit_cast<u64>(&m_bytecode_executable.environment_variable_caches[op.cache_index()])));
native_call((void*)cxx_get_callee_and_this_from_environment);
check_exception();
}