Skip to content

fix(interp): box a ref local only while its register is loaded - #204

Merged
siyul-park merged 2 commits into
mainfrom
fix/jit-selfcall-trace-entry
Aug 16, 2026
Merged

siyul-park merged 2 commits into
mainfrom
fix/jit-selfcall-trace-entry

Conversation

@siyul-park

@siyul-park siyul-park commented Aug 16, 2026 •

Copy link
Copy Markdown
Owner

Fixes the SIGSEGV left open by #201/#203, and unblocks a kernel that had never compiled.

Root cause

A native call invalidates the caller's cached local registers — the callee owns every allocatable register, so the call sites clear(activation.state) on return, and the committing flush before the call leaves the VM stack slot authoritative.

activation.locals still names the register each value was last materialized into. guardFrame, which reads every ref local for the frame teardown, decided purely on that register being set:

v := f.locals[i]
if v.reg.Width() != asm.WidthUndefined {
    ref, ok = l.box(ctx, v)     // stale across the call
} else {
    ...load from the slot...
}

So the teardown boxed whatever the callee had left in that register and released it. Reading i.rc at that address faults inside the Go runtime rather than diverging quietly.

The rule now has one owner: activation.isLoadedAt answers whether the cached register is still good, and guardFrame and loadLocal both ask it instead of testing the state flag inline. guardFrame's separate register-width check goes away with it — a loaded slot always names a register. guardFrame was the only reader that consulted locals without the state; the others go through loadLocal or gate on localDirty.

How it was found

Black-box probing eliminated seven hypotheses (spill frame/X26, i.rc growth, hot-exit folding, carried legs, buffer overwrite, reinstall over a live entry, fallback capture) before dumping the callable and disassembling it. The fault PC is a stable offset 0x39c:

036c  and  x3, x5, #0xffffffff     ; boxed result (dead)
0374  and  x3, x2, #0xffffffff     ; ref address extracted from X2
...
039c  ldr  x7, [x4, x3, lsl #3]    ; rc[x3]  <- fault

X2 is written at 0x0064/0x0068 as the boxed ref constant, then lives across two BL ctx.head self-calls that clobber it.

Effect beyond the crash

The stale box could also fail, rejecting the whole plan — so a shape that never compiled now does:

Call_IndirectRecursiveFib ns/op
default, main 489 µs
default, this PR 69 µs
threaded (unchanged) 553 µs

7.1x, confirmed over four interleaved rounds (488–491 µs vs 68.7–69.0 µs), and it passes the threaded tier for the first time. Every other kernel is unchanged: median +0.1% across 18 kernels, 3 interleaved rounds. docs/benchmarks.md carries the updated row.

Test

TestARM64_SelfCallFrameLocals — self-recursion with a ref local read before it is written (which is what gives it a cached register live across the call), depth 8, WithTick(1), 16 rounds against a WithThreshold(-1) twin asserting value and rc parity, plus that native code was actually installed. Without the fix it faults.

Verification

go test -race ./..., make lint, make check-generated, make fuzz, and a GOOS=linux GOARCH=amd64 build all pass. docs/jit-internals.md records the invalidation contract next to the X26 one.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@siyul-park, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: abba82e4-9db6-4a87-9611-b5c0f9b29178

📥 Commits

Reviewing files that changed from the base of the PR and between feef1e1 and ecc05b8.

📒 Files selected for processing (5)
  • docs/benchmarks.md
  • docs/jit-internals.md
  • interp/jit.go
  • interp/jit_arm64.go
  • interp/jit_arm64_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.92%. Comparing base (feef1e1) to head (2301f41).

Files with missing lines Patch % Lines
interp/jit.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
- Coverage   22.92%   22.92%   -0.01%     
==========================================
  Files          87       87              
  Lines       70125    70127       +2     
==========================================
  Hits        16077    16077              
- Misses      52802    52804       +2     
  Partials     1246     1246              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A native call invalidates the caller's cached local registers, because
the callee owns every allocatable register: the call sites clear
activation.state on return, and the committing flush before the call
leaves the VM stack slot authoritative. activation.locals still names
the register each value was last materialized into, so guardFrame - which
reads every ref local for the frame teardown - boxed whatever the callee
had left there and released it. Reading i.rc at that address faults
inside the Go runtime rather than diverging quietly.

Give the rule one owner. activation.isLoadedAt answers whether the cached
register is still good; guardFrame and loadLocal both ask it instead of
testing the state flag inline, and guardFrame's separate register-width
check goes away because a loaded slot always names a register.

Baseline Call_IndirectRecursiveFib default 489 us, result 69 us,
conclusion the stale box could also fail and reject the whole plan, so a
shape that never compiled now does - 7.1x over four interleaved rounds,
and it passes the threaded tier (553 us) for the first time. Every other
kernel is unchanged: median +0.1% across 18 kernels, 3 rounds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@siyul-park
siyul-park force-pushed the fix/jit-selfcall-trace-entry branch from 452765d to 2301f41 Compare August 16, 2026 11:03
@siyul-park siyul-park changed the title fix(interp): read ref locals from their slot when a call clears the cache fix(interp): box a ref local only while its register is loaded Aug 16, 2026
Two symbols sat outside their group. elemShape, a private type, was
declared between the constant and variable groups, and isLoadedAt, a
private method, between two private types. Both are moves only.

elemShape joins the private types and gains the doc comment its fields
were missing; isLoadedAt follows newActivation, the constructor of the
type it answers for.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@siyul-park
siyul-park merged commit 4a463e6 into main Aug 16, 2026
3 checks passed
@siyul-park
siyul-park deleted the fix/jit-selfcall-trace-entry branch August 16, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant