mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
LibJS: Devirtualize and pack the bytecode stream :^)
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.
This commit is contained in:
parent
845f2826aa
commit
e7d69c5d3c
11 changed files with 284 additions and 110 deletions
|
@ -9,14 +9,51 @@
|
|||
#include <AK/Forward.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
||||
#define ENUMERATE_BYTECODE_OPS(O) \
|
||||
O(Load) \
|
||||
O(Add) \
|
||||
O(Sub) \
|
||||
O(LessThan) \
|
||||
O(AbstractInequals) \
|
||||
O(AbstractEquals) \
|
||||
O(NewString) \
|
||||
O(NewObject) \
|
||||
O(GetVariable) \
|
||||
O(SetVariable) \
|
||||
O(PutById) \
|
||||
O(GetById) \
|
||||
O(Jump) \
|
||||
O(JumpIfFalse) \
|
||||
O(JumpIfTrue) \
|
||||
O(Call) \
|
||||
O(EnterScope) \
|
||||
O(Return)
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
class Instruction {
|
||||
public:
|
||||
virtual ~Instruction();
|
||||
enum class Type {
|
||||
#define __BYTECODE_OP(op) \
|
||||
op,
|
||||
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
||||
#undef __BYTECODE_OP
|
||||
};
|
||||
|
||||
virtual String to_string() const = 0;
|
||||
virtual void execute(Bytecode::Interpreter&) const = 0;
|
||||
Type type() const { return m_type; }
|
||||
size_t length() const;
|
||||
String to_string() const;
|
||||
void execute(Bytecode::Interpreter&) const;
|
||||
static void destroy(Instruction&);
|
||||
|
||||
protected:
|
||||
explicit Instruction(Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Type m_type {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue