1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

LibJS: Add bytecode instruction handles

This change removes the mmap inside of Block in favor of a growing
vector of bytes. This is favorable for two reasons:
  - We don't take more space than we need
  - There is no limit to the growth of the vector (previously, if
    the Block overstepped its 64kb boundary, it would just crash)

However, if that vector happens to resize, any pointer pointing into
that vector would become invalid. To avoid this, this commit adds an
InstructionHandle<Op> class which just stores a block and an offset
into that block.
This commit is contained in:
Matthew Olsson 2021-06-08 14:46:46 -07:00 committed by Andreas Kling
parent 83be39c91a
commit a01bd35c67
8 changed files with 81 additions and 79 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Badge.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibJS/Bytecode/Register.h>
#include <LibJS/Forward.h>
namespace JS::Bytecode {
@ -42,25 +43,20 @@ public:
static NonnullOwnPtr<Block> create();
~Block();
void seal();
void dump() const;
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }
ReadonlyBytes instruction_stream() const { return m_buffer.span(); }
size_t register_count() const { return m_register_count; }
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);
Vector<u8>& buffer() { return m_buffer; }
private:
Block();
Block() = default;
size_t m_register_count { 0 };
u8* m_buffer { nullptr };
size_t m_buffer_capacity { 0 };
size_t m_buffer_size { 0 };
Vector<u8> m_buffer;
};
}