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.
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.
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:
- Allocation never collects. Allocating only sets a flag when memory is low. The flag is polled at loop back-edges and function entries.
- 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.
no per-safepoint tables
only when a collection actually runs
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:
| Boundary | Before | Contract |
|---|---|---|
| Entry | a chain of validity checks, about 1,100 instructions | one cell, the pointer is the validity |
| Exit | three recovery implementations, 25 refusal reasons | one descriptor per site, one reader, five kinds |
| Collection | no written rule | spill 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.