Commit Graph

6 Commits

Author SHA1 Message Date
Andreas Kling
949ceedaed LibJS: Remove the seal/unseal of Bytecode::Block again
This partially reverts c6ce7c9326.
The munmap part of that change was good, but we can't seal the blocks
since that breaks NewString and other ops that have String members.
2021-06-08 21:39:50 +02:00
Leon Albrecht
c6ce7c9326
LibJS: Seal Bytecode Blocks and munmap them (#7919) 2021-06-08 17:21:48 +02:00
Andreas Kling
4776c50d5f LibJS: Remove unused Bytecode::Block::m_buffer_end 2021-06-07 18:30:39 +02:00
Andreas Kling
312297ac38 LibJS: Add placeholder bytecode block sealing mechanism
After compiling bytecode, we should mark the memory read-only.
This currently does not work because it breaks instruction destruction.

I'm adding this anyway with a FIXME so we don't forget about it. :^)
2021-06-07 18:11:59 +02:00
Andreas Kling
e7d69c5d3c 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.
2021-06-07 18:11:59 +02:00
Andreas Kling
69dddd4ef5 LibJS: Start fleshing out a bytecode for the JavaScript engine :^)
This patch begins the work of implementing JavaScript execution in a
bytecode VM instead of an AST tree-walk interpreter.

It's probably quite naive, but we have to start somewhere.

The basic idea is that you call Bytecode::Generator::generate() on an
AST node and it hands you back a Bytecode::Block filled with
instructions that can then be interpreted by a Bytecode::Interpreter.

This first version only implements two instructions: Load and Add. :^)

Each bytecode block has infinity registers, and the interpreter resizes
its register file to fit the block being executed.

Two new `js` options are added in this patch as well:

`-d` will dump the generated bytecode
`-b` will execute the generated bytecode

Note that unless `-d` and/or `-b` are specified, none of the bytecode
related stuff in LibJS runs at all. This is implemented in parallel
with the existing AST interpreter. :^)
2021-06-07 18:11:59 +02:00