
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.
44 lines
927 B
C++
44 lines
927 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Bytecode/Instruction.h>
|
|
#include <LibJS/Bytecode/Op.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
void Instruction::destroy(Instruction& instruction)
|
|
{
|
|
#define __BYTECODE_OP(op) \
|
|
case Type::op: \
|
|
static_cast<Op::op&>(instruction).~op(); \
|
|
return;
|
|
|
|
switch (instruction.type()) {
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
default:
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
#undef __BYTECODE_OP
|
|
}
|
|
|
|
size_t Instruction::length() const
|
|
{
|
|
if (type() == Type::Call)
|
|
return static_cast<Op::Call const&>(*this).length();
|
|
|
|
#define __BYTECODE_OP(op) \
|
|
case Type::op: \
|
|
return sizeof(Op::op);
|
|
|
|
switch (type()) {
|
|
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
|
default:
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
}
|
|
|
|
}
|