Skip to main content

Module vm

Module vm 

Source
Expand description

The register machine: the register file and frame table, the main loop, its slow paths, exception unwinding and the leaf-native ABI.

A frame owns a window of the register file: register 0 is this, then the parameters, the locals and the operand temporaries of its code unit. A call’s window starts inside the caller’s, on the callee’s operands, so no argument is copied. Both tables live inside the Heap as fixed roots: a safepoint marks registers[..top] and every frame’s function.

Modules§

compile
Code compiled at run time: eval, the Function constructors, $262.evalScript and Function.prototype.toString’s source text, through the compile host the embedder installs.
frame_flags
ic
Inline caches: one 16-byte entry per cache site, in a store beside the code store.
module
ECMAScript modules.
native
The native ABI: host functions that read their receiver and arguments from the register file by index and call back into JavaScript through the re-entrant call and construct as straight-line Rust. A native roots what it holds across an allocation or a call on the root stack, which is cut back when it returns. The natives themselves are the realm’s builtins (crate::builtins).
regexp
Regular-expression objects: the program store and the RegExp object kind. A literal allocates a new object on every evaluation, as the specification requires, over one compiled program per distinct (source, flags), compiled on first use; new RegExp(source, flags) shares the store, so a program built in a loop does not grow it without bound. The store lives in the heap: a RegExp object’s payload names its program, a collection marks the programs of the live objects (and their two atoms), and sweeps the rest.

Structs§

Services
Runtime state the natives reach beside the heap: output, the random stream, the symbol registry, and the embedder’s Host.
Throw
A thrown JavaScript value. It is not rooted: whoever receives it stores it in a register, a root or a handle before the next allocation.
VmStack
The register file and the frame table.

Enums§

ErrorKind
Output
Where print writes.

Constants§

DEFAULT_STACK_LIMIT
Registers the file may hold before a call fails with InternalError: stack overflow: 8 MiB of values.
INTERRUPT_INTERVAL
Back-edges and calls between two interrupt polls. QuickJS’s JS_INTERRUPT_COUNTER_INIT is 10,000; a tenth of it costs the loop nothing measurable (the poll is cold), and stops a script ten times sooner.
NATIVE_STACK_BUDGET
Native stack bytes nested re-entries may use (debug builds have large loop frames; the default thread stack of a test is 2 MiB).