1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibJS: Keep cached this value in a call frame register

Just moving more things to call frame registers..
This commit is contained in:
Andreas Kling 2023-09-26 14:42:30 +02:00
parent 3887b840a3
commit c833885fb5
5 changed files with 13 additions and 9 deletions

View file

@ -252,7 +252,7 @@ private:
NonnullOwnPtr<IdentifierTable> m_identifier_table;
NonnullOwnPtr<RegexTable> m_regex_table;
u32 m_next_register { 3 };
u32 m_next_register { Register::reserved_register_count };
u32 m_next_block { 1 };
u32 m_next_property_lookup_cache { 0 };
u32 m_next_global_variable_cache { 0 };

View file

@ -179,8 +179,6 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa
else
push_call_frame(make<CallFrame>(), executable.number_of_registers);
TemporaryChange restore_this_value { m_this_value, {} };
for (;;) {
auto pc = InstructionStreamIterator { m_current_block->instruction_stream(), m_current_executable };
TemporaryChange temp_change { m_pc, Optional<InstructionStreamIterator&>(pc) };

View file

@ -90,8 +90,6 @@ public:
auto& instruction_stream_iterator() const { return m_pc; }
DeprecatedString debug_position() const;
Optional<Value>& this_value() { return m_this_value; }
void visit_edges(Cell::Visitor&);
private:
@ -116,7 +114,6 @@ private:
Span<Value> m_current_call_frame;
Optional<BasicBlock const*> m_pending_jump;
BasicBlock const* m_scheduled_jump { nullptr };
Optional<Value> m_this_value;
Optional<Value> m_return_value;
Executable* m_current_executable { nullptr };
BasicBlock const* m_current_block { nullptr };

View file

@ -767,13 +767,14 @@ ThrowCompletionOr<void> Jump::execute_impl(Bytecode::Interpreter& interpreter) c
ThrowCompletionOr<void> ResolveThisBinding::execute_impl(Bytecode::Interpreter& interpreter) const
{
if (!interpreter.this_value().has_value()) {
auto& cached_this_value = interpreter.reg(Register::this_value());
if (cached_this_value.is_empty()) {
// OPTIMIZATION: Because the value of 'this' cannot be reassigned during a function execution, it's
// resolved once and then saved for subsequent use.
auto& vm = interpreter.vm();
interpreter.this_value() = TRY(vm.resolve_this_binding());
cached_this_value = TRY(vm.resolve_this_binding());
}
interpreter.accumulator() = interpreter.this_value().value();
interpreter.accumulator() = cached_this_value;
return {};
}

View file

@ -33,6 +33,14 @@ public:
return Register(exception_index);
}
static constexpr Register this_value()
{
constexpr u32 this_value_index = 3;
return Register(this_value_index);
}
static constexpr u32 reserved_register_count = 4;
constexpr explicit Register(u32 index)
: m_index(index)
{