summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-12 20:36:39 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-15 22:06:33 +0430
commite73b142a97db5844d24ab881a5d23acf725ca572 (patch)
tree08fe166efa6c4dde22365c52b9705ba224a08c57 /Userland/Libraries
parentf7f88adc78ba708ff8e76cf09549383657074330 (diff)
downloadserenity-e73b142a97db5844d24ab881a5d23acf725ca572.zip
LibJS: Make basic block size customizable
And keep the default 4 KiB for the code generator.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp8
-rw-r--r--Userland/Libraries/LibJS/Bytecode/BasicBlock.h5
2 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp b/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp
index b4901da98f..0182d4412f 100644
--- a/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/BasicBlock.cpp
@@ -11,18 +11,18 @@
namespace JS::Bytecode {
-NonnullOwnPtr<BasicBlock> BasicBlock::create(String name)
+NonnullOwnPtr<BasicBlock> BasicBlock::create(String name, size_t size)
{
- return adopt_own(*new BasicBlock(move(name)));
+ return adopt_own(*new BasicBlock(move(name), max(size, static_cast<size_t>(4 * KiB))));
}
-BasicBlock::BasicBlock(String name)
+BasicBlock::BasicBlock(String name, size_t size)
: m_name(move(name))
{
// FIXME: This is not the smartest solution ever. Find something cleverer!
// The main issue we're working around here is that we don't want pointers into the bytecode stream to become invalidated
// during code generation due to dynamic buffer resizing. Otherwise we could just use a Vector.
- m_buffer_capacity = 4 * KiB;
+ m_buffer_capacity = size;
m_buffer = (u8*)mmap(nullptr, m_buffer_capacity, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
VERIFY(m_buffer != MAP_FAILED);
}
diff --git a/Userland/Libraries/LibJS/Bytecode/BasicBlock.h b/Userland/Libraries/LibJS/Bytecode/BasicBlock.h
index 08912e1a6d..b3720c2a15 100644
--- a/Userland/Libraries/LibJS/Bytecode/BasicBlock.h
+++ b/Userland/Libraries/LibJS/Bytecode/BasicBlock.h
@@ -47,13 +47,14 @@ class BasicBlock {
AK_MAKE_NONCOPYABLE(BasicBlock);
public:
- static NonnullOwnPtr<BasicBlock> create(String name);
+ static NonnullOwnPtr<BasicBlock> create(String name, size_t size = 4 * KiB);
~BasicBlock();
void seal();
void dump(Executable const&) const;
ReadonlyBytes instruction_stream() const { return ReadonlyBytes { m_buffer, m_buffer_size }; }
+ size_t size() const { return m_buffer_size; }
void* next_slot() { return m_buffer + m_buffer_size; }
bool can_grow(size_t additional_size) const { return m_buffer_size + additional_size <= m_buffer_capacity; }
@@ -65,7 +66,7 @@ public:
String const& name() const { return m_name; }
private:
- BasicBlock(String name);
+ BasicBlock(String name, size_t size);
u8* m_buffer { nullptr };
size_t m_buffer_capacity { 0 };