Preface
Executing bytecode is one of the core parts of the JavaScriptCore engine, and it is also where most JavaScript-engine optimizations concentrate.
Interpreting and executing JS bytecode is a complex system. After OSR and multiple tiers of JIT were introduced, bytecode execution became increasingly efficient, striking a good balance between low latency and high throughput. Low-latency LLInt interprets bytecode first. When repeated calls, recursion, loops, or other trigger conditions appear, execution can switch through OSR into JIT-based execution. Different JIT tiers may be entered depending on the specific trigger conditions, which improves performance.
CLoopRegister simulates real CPU registers. It defines
the following strategies:
- How to pack integers smaller than
intptr_tinto pseudo-registers. - How to hide differences between big-endian and little-endian platforms.
1 | struct UnlinkedInstruction |
1 | struct ProtoCallFrame { |
1 | JSValue execute(ProgramExecutable*, CallFrame*, JSObject* thisObj); |
1 | // Elements needed by interpreter execution: executable program, execution stack, and global object. |
ProgramExecutable
ProgramExecutable can be understood as the manager of
the script currently being executed. Its name already tells us that it
represents an executable program.
First, it initializes global properties.
The processing results are recorded in callFrame. The
main work is done through the JSGlobalObject methods
addFunction and addVar, which record the
global properties parsed from let, const, and
class declarations, as well as global variables declared
with var, let, and const.
1 | // Initialize global properties. |
1 | JSObject* ScriptExecutable::prepareForExecutionImpl( |