Skip to main content

Module osr_compiler

Module osr_compiler 

Source
Expand description

OSR (On-Stack Replacement) Loop Compilation

Compiles hot loop bodies to native code via Cranelift IR for mid-execution transfer from the bytecode interpreter to JIT-compiled code.

§OSR ABI

extern "C" fn(ctx_ptr: *mut u8, _unused: *const u8) -> u64

  • Returns 0 on normal loop exit (locals written back to ctx).
  • Returns u64::MAX on deoptimization (locals partially written back).

§Escape Analysis / Scalar Replacement

The escape analysis pass (Phase 5) identifies small non-escaping arrays for scalar replacement in the whole-function JIT compiler. OSR compilation does NOT support NewArray/GetProp/SetLocalIndex opcodes (they fail the preflight check in is_osr_supported_opcode), so scalar replacement does not apply to OSR-compiled loop bodies. If OSR support for array opcodes is added in the future, deopt materialization must reconstruct scalar-replaced arrays from their SSA variable elements before writing locals back to ctx.

Structs§

OsrCompilationResult
Result of compiling a loop body for OSR entry.

Functions§

compile_osr_loop
Compile a loop body for OSR (On-Stack Replacement) entry.