LibJS: Shrink two u64 fields in ExecutionContext to u32

To shrink ExecutionContext, these two fields are made 32-bit:

- skip_when_determining_incumbent_counter
- program_counter
This commit is contained in:
Andreas Kling 2025-10-29 08:42:30 +01:00 committed by Andreas Kling
parent 4c7ffc0552
commit 59ce6c9b41
4 changed files with 12 additions and 10 deletions

View File

@ -305,7 +305,7 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
return js_undefined(); return js_undefined();
} }
NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception(size_t& program_counter, Value exception) NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception(u32& program_counter, Value exception)
{ {
reg(Register::exception()) = exception; reg(Register::exception()) = exception;
m_scheduled_jump = {}; m_scheduled_jump = {};
@ -349,7 +349,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
auto& executable = current_executable(); auto& executable = current_executable();
auto const* bytecode = executable.bytecode.data(); auto const* bytecode = executable.bytecode.data();
size_t& program_counter = running_execution_context.program_counter; u32& program_counter = running_execution_context.program_counter;
program_counter = entry_point; program_counter = entry_point;
// Declare a lookup table for computed goto with each of the `handle_*` labels // Declare a lookup table for computed goto with each of the `handle_*` labels

View File

@ -95,7 +95,7 @@ private:
ExitFromExecutable, ExitFromExecutable,
ContinueInThisExecutable, ContinueInThisExecutable,
}; };
[[nodiscard]] HandleExceptionResponse handle_exception(size_t& program_counter, Value exception); [[nodiscard]] HandleExceptionResponse handle_exception(u32& program_counter, Value exception);
VM& m_vm; VM& m_vm;
Optional<size_t> m_scheduled_jump; Optional<size_t> m_scheduled_jump;

View File

@ -58,7 +58,11 @@ public:
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC. // Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
GC::Ptr<Cell> context_owner; GC::Ptr<Cell> context_owner;
size_t program_counter { 0 }; u32 program_counter { 0 };
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
u32 skip_when_determining_incumbent_counter { 0 };
mutable RefPtr<CachedSourceRange> cached_source_range; mutable RefPtr<CachedSourceRange> cached_source_range;
@ -66,10 +70,6 @@ public:
GC::Ptr<Bytecode::Executable> executable; GC::Ptr<Bytecode::Executable> executable;
// https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
// FIXME: Move this out of LibJS (e.g. by using the CustomData concept), as it's used exclusively by LibWeb.
size_t skip_when_determining_incumbent_counter { 0 };
Span<Value> registers_and_constants_and_locals_and_arguments_span() Span<Value> registers_and_constants_and_locals_and_arguments_span()
{ {
return { registers_and_constants_and_locals_and_arguments(), registers_and_constants_and_locals_and_arguments_count }; return { registers_and_constants_and_locals_and_arguments(), registers_and_constants_and_locals_and_arguments_count };

View File

@ -207,9 +207,10 @@ void prepare_to_run_callback(JS::Realm& realm)
auto* context = top_most_script_having_execution_context(vm); auto* context = top_most_script_having_execution_context(vm);
// 3. If context is not null, increment context's skip-when-determining-incumbent counter. // 3. If context is not null, increment context's skip-when-determining-incumbent counter.
if (context) if (context) {
context->skip_when_determining_incumbent_counter++; context->skip_when_determining_incumbent_counter++;
} }
}
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#parse-a-url
Optional<URL::URL> EnvironmentSettingsObject::parse_url(StringView url) Optional<URL::URL> EnvironmentSettingsObject::parse_url(StringView url)
@ -265,8 +266,9 @@ void clean_up_after_running_callback(JS::Realm const& realm)
auto* context = top_most_script_having_execution_context(vm); auto* context = top_most_script_having_execution_context(vm);
// 2. If context is not null, decrement context's skip-when-determining-incumbent counter. // 2. If context is not null, decrement context's skip-when-determining-incumbent counter.
if (context) if (context) {
context->skip_when_determining_incumbent_counter--; context->skip_when_determining_incumbent_counter--;
}
// 3. Assert: the topmost entry of the backup incumbent realm stack is realm. // 3. Assert: the topmost entry of the backup incumbent realm stack is realm.
auto& event_loop = HTML::main_thread_event_loop(); auto& event_loop = HTML::main_thread_event_loop();