mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 18:17:23 +00:00
LibJS/Bytecode: Flatten bytecode to a contiguous representation
Instead of keeping bytecode as a set of disjoint basic blocks on the malloc heap, bytecode is now a contiguous sequence of bytes(!) The transformation happens at the end of Bytecode::Generator::generate() and the only really hairy part is rerouting jump labels. This required solving a few problems: - The interpreter execution loop had to change quite a bit, since we were storing BasicBlock pointers all over the place, and control transfer was done by redirecting the interpreter's current block. - Exception handlers & finalizers are now stored per-bytecode-range in a side table in Executable. - The interpreter now has a plain program counter instead of a stream iterator. This actually makes error stack generation a bit nicer since we just have to deal with a number instead of reaching into the iterator. This yields a 25% performance improvement on this microbenchmark: for (let i = 0; i < 1_000_000; ++i) { } But basically everything gets faster. :^)
This commit is contained in:
parent
c2d3d9d1d4
commit
f6aee2b9e8
Notes:
sideshowbarker
2024-07-17 02:22:23 +09:00
Author: https://github.com/awesomekling
Commit: f6aee2b9e8
Pull-request: https://github.com/SerenityOS/serenity/pull/24240
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/trflynn89 ✅
21 changed files with 392 additions and 172 deletions
|
@ -11,7 +11,6 @@
|
|||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibJS/Bytecode/BasicBlock.h>
|
||||
#include <LibJS/Bytecode/Instruction.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Module.h>
|
||||
#include <LibJS/Runtime/PrivateEnvironment.h>
|
||||
|
@ -51,7 +50,7 @@ public:
|
|||
// Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC.
|
||||
GCPtr<Cell> context_owner;
|
||||
|
||||
Optional<Bytecode::InstructionStreamIterator> instruction_stream_iterator;
|
||||
Optional<size_t> program_counter;
|
||||
GCPtr<PrimitiveString> function_name;
|
||||
Value this_value;
|
||||
bool is_strict_mode { false };
|
||||
|
@ -78,7 +77,7 @@ public:
|
|||
Vector<Value> locals;
|
||||
Vector<Value> registers;
|
||||
Vector<Bytecode::UnwindInfo> unwind_contexts;
|
||||
Vector<Bytecode::BasicBlock const*> previously_scheduled_jumps;
|
||||
Vector<Optional<size_t>> previously_scheduled_jumps;
|
||||
Vector<GCPtr<Environment>> saved_lexical_environments;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue