Compiled blocks tail-jump straight to their successor's compiled code
(canary-style indirection dispatch) instead of returning to the Rust
superblock loop between blocks, checking the lockstep yield guards
INLINE. Gated behind XENIA_JIT_CHAIN (default off) — the shipping JIT
path (Phase A) is byte-for-byte unchanged.
Mechanism:
- JitEnv gains chain_{enabled,stop,deadline,mmio_ptr,mmio_before,cache}.
- Chaining epilogue (non-sync blocks only, when chain_active): flush cache
to ctx, then inline guards — budget (ctx.cycle_count >= start+budget,
== interp total_executed>=budget), mmio (per-block prologue snapshot vs
live counter), chain_enabled gate — then jit_chain_next(env, next_pc)
(pure JIT-cache freshness lookup, returns host entry or null). On a hit:
restore env->rdi, unwind THIS frame (pop to entry rsp), tail-jmp to the
successor (no stack growth; the return addr rides through to the final
block's ret). On null: set chain_stop=Miss, return to Rust.
- run_jit_chain drives it; run_superblock_jit_chained (used when chaining
compiled in + budget>1 + no probe/mem-watch armed) re-enters on a Miss to
build+compile the chainable next block. sync blocks keep the plain
epilogue (end the superblock like interp). GuestMemory::
mmio_access_count_ptr exposes the counter for the inline check.
BYTE-IDENTICAL golden n200m across: interp, JIT, JIT+REGCACHE, JIT+CHAIN,
JIT+CHAIN+REGCACHE, and JIT+CHAIN+budget=1 == interp+budget=1. 19 jit
tests green. (Fixed: prologue mmio snapshot must be chain_enabled-guarded
— a chaining-compiled block is also run via run_jit_block with a null
mmio_ptr on the Phase A / budget==1 / probes-armed paths.)
THROUGHPUT: NEUTRAL on the boot bench (JIT vs JIT+CHAIN statistically
equal, within noise). As the canary study predicted: block-granularity
chaining keeps the per-block prologue/epilogue (unwind+rewind per
boundary) and jit_chain_next ~= the run_fresh it replaces, so the
reclaimed Rust-loop overhead is Amdahl-swamped. The determinism-critical
machinery (inline yield guards, tail-jmp discipline, dispatch ABI) is now
PROVEN byte-identical — the foundation for region/function-granularity
compilation (increment 2), which is where the real dispatch win lives.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>