1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 16:35:08 +00:00

LibJS/JIT: Support alternative entry point blocks

If Interpreter::run_and_return_frame is called with a specific entry
point we now map that to a native instruction address, which the JIT
code jumps to after the function prologue.
This commit is contained in:
Simon Wanner 2023-11-02 21:52:20 +01:00 committed by Andreas Kling
parent 38f3b78a1d
commit e400682fb1
4 changed files with 46 additions and 5 deletions

View file

@ -19,6 +19,15 @@ NativeExecutable::NativeExecutable(void* code, size_t size, Vector<BytecodeMappi
, m_size(size)
, m_mapping(move(mapping))
{
// Translate block index to instruction address, so the native code can just jump to it.
for (auto const& entry : m_mapping) {
if (entry.block_index == BytecodeMapping::EXECUTABLE)
continue;
if (entry.bytecode_offset == 0) {
VERIFY(entry.block_index == m_block_entry_points.size());
m_block_entry_points.append(bit_cast<FlatPtr>(m_code) + entry.native_offset);
}
}
}
NativeExecutable::~NativeExecutable()
@ -26,12 +35,19 @@ NativeExecutable::~NativeExecutable()
munmap(m_code, m_size);
}
void NativeExecutable::run(VM& vm) const
void NativeExecutable::run(VM& vm, size_t entry_point) const
{
typedef void (*JITCode)(VM&, Value* registers, Value* locals);
FlatPtr entry_point_address = 0;
if (entry_point != 0) {
entry_point_address = m_block_entry_points[entry_point];
VERIFY(entry_point_address != 0);
}
typedef void (*JITCode)(VM&, Value* registers, Value* locals, FlatPtr entry_point_address);
((JITCode)m_code)(vm,
vm.bytecode_interpreter().registers().data(),
vm.running_execution_context().local_variables.data());
vm.running_execution_context().local_variables.data(),
entry_point_address);
}
#if ARCH(X86_64)