mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:05:07 +00:00
LibJS: Use a Vector<u8> for BasicBlock instruction storage
This reduces the minimum size of a basic block from 4 KiB to 0 bytes. With this change, memory usage at the end of Speedometer is 1.2 GiB, down from 1.8 GiB.
This commit is contained in:
parent
89a86798a2
commit
d24e07579f
4 changed files with 20 additions and 67 deletions
|
@ -10,19 +10,14 @@
|
|||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
NonnullOwnPtr<BasicBlock> BasicBlock::create(DeprecatedString name, size_t size)
|
||||
NonnullOwnPtr<BasicBlock> BasicBlock::create(DeprecatedString name)
|
||||
{
|
||||
return adopt_own(*new BasicBlock(move(name), max(size, static_cast<size_t>(4 * KiB))));
|
||||
return adopt_own(*new BasicBlock(move(name)));
|
||||
}
|
||||
|
||||
BasicBlock::BasicBlock(DeprecatedString name, size_t size)
|
||||
BasicBlock::BasicBlock(DeprecatedString name)
|
||||
: 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 = size;
|
||||
m_buffer = new u8[m_buffer_capacity];
|
||||
}
|
||||
|
||||
BasicBlock::~BasicBlock()
|
||||
|
@ -33,16 +28,6 @@ BasicBlock::~BasicBlock()
|
|||
++it;
|
||||
Instruction::destroy(const_cast<Instruction&>(to_destroy));
|
||||
}
|
||||
|
||||
delete[] m_buffer;
|
||||
}
|
||||
|
||||
void BasicBlock::seal()
|
||||
{
|
||||
// FIXME: mprotect the instruction stream as PROT_READ
|
||||
// This is currently not possible because instructions can have destructors (that clean up strings)
|
||||
// Instructions should instead be destructor-less and refer to strings in a string table on the Bytecode::Block.
|
||||
// It also doesn't work because instructions that have String members use RefPtr internally which must be in writable memory.
|
||||
}
|
||||
|
||||
void BasicBlock::dump(Bytecode::Executable const& executable) const
|
||||
|
@ -58,8 +43,7 @@ void BasicBlock::dump(Bytecode::Executable const& executable) const
|
|||
|
||||
void BasicBlock::grow(size_t additional_size)
|
||||
{
|
||||
m_buffer_size += additional_size;
|
||||
VERIFY(m_buffer_size <= m_buffer_capacity);
|
||||
m_buffer.resize(m_buffer.size() + additional_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue