LibJS: Move source range cache from ExecutionContext to Executable

CachedSourceRange was a GC-allocated cell stored on the
ExecutionContext, only needed because ExecutionContext must be
trivially destructible.

Move the source range cache to a HashMap<u32, SourceRange> on the
Executable (keyed by program counter), where it belongs. This
eliminates the GC::Cell subclass entirely and removes the
cached_source_range field from ExecutionContext.

StackTraceElement and TracebackFrame now store Optional<SourceRange>
directly instead of GC::Ptr<CachedSourceRange>.

Shrinks ExecutionContext from 144 to 136 bytes.
This commit is contained in:
Andreas Kling 2026-03-08 11:56:31 +01:00 committed by Andreas Kling
parent f02b67a700
commit 75e7bc1e2a
Notes: github-actions[bot] 2026-03-11 12:35:21 +00:00
10 changed files with 31 additions and 68 deletions

View file

@ -246,6 +246,17 @@ UnrealizedSourceRange Executable::source_range_at(size_t offset) const
};
}
SourceRange const& Executable::get_source_range(u32 program_counter)
{
return m_source_range_cache.ensure(program_counter, [&] {
auto unrealized = source_range_at(program_counter);
if (unrealized.source_code)
return unrealized.realize();
static SourceRange dummy { SourceCode::create({}, {}), {}, {} };
return dummy;
});
}
Operand Executable::original_operand_from_raw(u32 raw) const
{
// NB: Layout is [registers | locals | constants | arguments]