mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:07:43 +00:00
LibJS: Devirtualize and pack the bytecode stream :^)
This patch changes the LibJS bytecode to be a stream of instructions packed one-after-the-other in contiguous memory, instead of a vector of OwnPtr<Instruction>. This should be a lot more cache-friendly. :^) Instructions are also devirtualized and instead have a type field using a new Instruction::Type enum. To iterate over a bytecode stream, one must now use Bytecode::InstructionStreamIterator.
This commit is contained in:
parent
845f2826aa
commit
e7d69c5d3c
11 changed files with 284 additions and 110 deletions
|
@ -12,24 +12,55 @@
|
|||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
class InstructionStreamIterator {
|
||||
public:
|
||||
explicit InstructionStreamIterator(ReadonlyBytes bytes)
|
||||
: m_bytes(bytes)
|
||||
{
|
||||
}
|
||||
|
||||
size_t offset() const { return m_offset; }
|
||||
bool at_end() const { return m_offset >= m_bytes.size(); }
|
||||
void jump(size_t offset)
|
||||
{
|
||||
VERIFY(offset <= m_bytes.size());
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
Instruction const& operator*() const { return dereference(); }
|
||||
void operator++();
|
||||
|
||||
private:
|
||||
Instruction const& dereference() const { return *reinterpret_cast<Instruction const*>(m_bytes.data() + offset()); }
|
||||
|
||||
ReadonlyBytes m_bytes;
|
||||
size_t m_offset { 0 };
|
||||
};
|
||||
|
||||
class Block {
|
||||
public:
|
||||
static NonnullOwnPtr<Block> create();
|
||||
~Block();
|
||||
|
||||
NonnullOwnPtrVector<Instruction> const& instructions() const { return m_instructions; }
|
||||
void dump() const;
|
||||
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }
|
||||
|
||||
size_t register_count() const { return m_register_count; }
|
||||
|
||||
void append(Badge<Bytecode::Generator>, NonnullOwnPtr<Instruction>);
|
||||
void set_register_count(Badge<Bytecode::Generator>, size_t count) { m_register_count = count; }
|
||||
|
||||
void* next_slot() { return m_buffer + m_buffer_size; }
|
||||
void grow(size_t additional_size);
|
||||
|
||||
private:
|
||||
Block();
|
||||
|
||||
size_t m_register_count { 0 };
|
||||
NonnullOwnPtrVector<Instruction> m_instructions;
|
||||
u8* m_buffer { nullptr };
|
||||
size_t m_buffer_capacity { 0 };
|
||||
size_t m_buffer_size { 0 };
|
||||
|
||||
u8 const* m_buffer_end { nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue