mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-31 21:59:21 +00:00
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. :^)
48 lines
1004 B
C++
48 lines
1004 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Format.h>
|
|
#include <LibJS/Bytecode/BasicBlock.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
class Label {
|
|
public:
|
|
explicit Label(BasicBlock const& block)
|
|
: m_block(&block)
|
|
{
|
|
}
|
|
|
|
// Used while compiling.
|
|
BasicBlock const& block() const { return *m_block; }
|
|
|
|
// Used after compiling.
|
|
size_t address() const { return m_address; }
|
|
|
|
void set_address(size_t address) { m_address = address; }
|
|
|
|
private:
|
|
union {
|
|
// Relevant while compiling.
|
|
BasicBlock const* m_block { nullptr };
|
|
|
|
// Relevant after compiling.
|
|
size_t m_address;
|
|
};
|
|
};
|
|
|
|
}
|
|
|
|
template<>
|
|
struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
|
|
ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Label const& label)
|
|
{
|
|
return AK::Formatter<FormatString>::format(builder, "@{:x}"sv, label.address());
|
|
}
|
|
};
|