Quench.
THREECONTRACTS

blog / · 4 min read · internals

Entry cells, exit descriptors and a collector without stack maps

Three small contracts decide how compiled JavaScript is called, how it gives up, and how the garbage collector finds its roots. Quench's versions are unusual, and this is the reasoning behind each.

Most of what makes a JIT hard is not generating code. It is the three boundaries around the code: how you get in, how you get out when an assumption fails, and how the garbage collector sees what you are holding. This post describes the contracts Quench settled on in mid-November 2026. Parts of this are implemented and parts are the agreed design the code is moving to; each section says which.

Getting in: one 64-byte cell per function

Calling a JavaScript function means answering several questions. Is there compiled code? Is it still valid? Does it accept this many arguments? Before this contract, answering them took a chain of about 1,100 instructions when the interpreter called into native code.

The design replaces that chain with one cache line per function.

Entry cell, 64 bytes, one per functionentry cellentrycode or stubbodyrecovery infoarity + flagsone compareepochvaliditycounterstiering statistics
Byte offsets 0, 8, 16, 24 and 32 to 64. The cell is aligned to a cache line and indexed by function id.

The trick is in the first word. entry always points at something callable. If the function has compiled code, it points there. If not, it points at a stub that reports "not entered" and lets the caller fall back. There is no separate "is it compiled" flag to test, because the pointer is the answer.

A native call is then one compare of the callee's identity, one load, one call. The interpreter's call path through the cell is budgeted at about 150 instructions in place of 1,100. The gate for calling this done is a non-inlined fib(34) call at 20 nanoseconds or less. It stood at 79 when the contract was written.

Getting out: one descriptor per exit

Compiled code is built on assumptions: this value is an integer, this object has that shape. When one fails, execution has to continue in the interpreter at exactly the right bytecode position with exactly the right values in the right registers. That is deoptimization, and it is the most bug-prone part of any JIT.

We had three different implementations of recovering inlined frames, which is two too many. The contract replaces them with one data structure and one reader.

Leaving compiled codenative codeguard failsleave wordexit site iddescriptorframes, values, pcrecover()writes frames in placeinterpreterresumes at exact pc
The descriptor is emitted at compile time, once per exit site. It records, for every live value, whether it is in a register, a stack slot, a constant, or must be rebuilt.

Every exit site gets a descriptor when the code is compiled. It lists the frames that were inlined at that point, outermost first, and for each live value says where it is: in a machine register, in a slot, a known constant, or something that was optimized away and must be rebuilt. One function reads a descriptor plus the machine state and writes interpreter frames.

Exceptions use the same path. A descriptor can name a handler position, so a throw inside compiled code resumes at the right catch through the same reader. That removes a class of bail-outs that sat behind three known test failures.

The contract also closes the set of reasons code can leave. There are five: a guard missed, an exception, a return, a safepoint, or a suspension (await or yield). Twenty-five ad hoc refusal reasons are being folded into those five.

Being collected: spill on poll

A garbage collector must find every object reference compiled code is holding, including ones in machine registers. The standard answer is stack maps: for every point where a collection can happen, the compiler emits a table saying which registers and stack slots hold references. They are precise and they are a great deal of machinery.

Quench does not use them, because of two properties of its heap:

  1. Allocation never collects. Allocating only sets a flag when memory is low. The flag is polled at loop back-edges and function entries.
  2. The heap does not move objects. It is mark and sweep. A reference stays valid across a collection.

Together those mean a collection can only start at a poll, and nothing needs to be updated afterwards. So the contract is this: at each poll, the rarely taken branch stores live references into their normal frame slots, calls the collector, and continues. The collector scans frames, which it already knows how to do.

0
stack maps

no per-safepoint tables

1 store
per live reference

only when a collection actually runs

3%
the gate

spill stores above this reopen the question

No reload is needed after the collection, because nothing moved. The cost is paid once per collection, not once per allocation or per call.

This is a deliberate deviation from how Cranelift expects to be used, and it has a tripwire. If spill stores ever exceed 3% of executed instructions, the decision is reopened.

What the three have in common

Each contract replaces several mechanisms with one, and each makes the common case cost nothing extra:

BoundaryBeforeContract
Entrya chain of validity checks, about 1,100 instructionsone cell, the pointer is the validity
Exitthree recovery implementations, 25 refusal reasonsone descriptor per site, one reader, five kinds
Collectionno written rulespill on poll, no maps, a 3% tripwire

None of this makes arithmetic faster. It makes calls, exceptions and allocation, which are most of what real programs do, cost what they should.

Try it

Quench builds from source with Cargo and runs TypeScript, JavaScript and WebAssembly.

Build and run

Work on it

Interpreter, JIT, AOT, GC, Node APIs. Every claim on this blog has a measurement you can rerun.

Where to start

Follow it

New posts land here as the engine moves. Star the repository or subscribe to the feed.

Star on GitHub Feed