Skip to content

jitv2: tell an empty code page by a flag, not by the stub's address - #941

Merged
jamesbraid merged 1 commit into
mainfrom
jb/jit-fnptr
Nov 30, 2026
Merged

jamesbraid merged 1 commit into
mainfrom
jb/jit-fnptr

Conversation

@jamesbraid

@jamesbraid jamesbraid commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

In a build with many codegen units and no LTO, a physical code page with no compiled code looks like it has some. The CPU then skips compiling pages it should compile, and publishing treats the page as holding live code. Nine tests fail that way with --features jitv2,rex-jit,gputrace. They include the sync-compile tests in mips_exec_test and exception_mid_run_counts_like_the_interpreter.

Cause

An empty page points its code pointer (func) at a stub, jit_no_code. has_code() and publish_from() decided "empty" by comparing func with the address of jit_no_code. Rust does not promise one address per function, and a small function like this can be instantiated once per codegen unit. With 256 units and no LTO, one run printed the stored stub at 0x555b2a7497b8 and the constant at the comparison site at 0x555b2a81dbf8. The comparison never matched. Dev and the ship profile (fat LTO, one unit) keep a single copy, so they passed.

Fix

Add a holds_code flag next to func, written under publish_lock, and have has_code() read it. publish() treats a null func as "publish no code" and stores the stub. func is still never null when empty: a CPU that passed is_runnable can load it just as retire_code swaps the code out, so it must stay callable. Dispatch is unchanged. The two tests that compared func with the stub now call it and check it returns EXEC_FALLBACK.

Cost

On the ship profile with --features jitv2, the 6248 indirect calls in the MipsCpu functions are identical before and after. The inline-compile check on CPU arrival goes from load, lea, cmp, je to movzbl, test, je. perf stat instructions:u for iris-bench run --quick --cpu r10000, six interleaved runs each, is 182.9G mean (sd 5.8G) on base 2adb78f8a and 184.6G (sd 4.4G) here. The difference is inside the run-to-run spread. has_code() is on no per-instruction path.

Verified

The nine tests pass in a build with 256 codegen units and no LTO. nextest passes in dev with default features and with jitv2,rex-jit,gputrace, and iris-checks passes after the release-features build.

Production lines: +15 -6. Test lines: +9 -3.

In a build with many codegen units and no LTO, a physical code page
with no compiled code looks like it has some. The CPU then skips
compiling pages it should compile, and publishing treats the page as
holding live code. Nine tests fail that way with --features
jitv2,rex-jit,gputrace. They include the sync-compile tests in
mips_exec_test and exception_mid_run_counts_like_the_interpreter.

An empty page points its code pointer (func) at a stub, jit_no_code.
has_code() and publish_from() decided "empty" by comparing func with
the address of jit_no_code. Rust does not promise one address per
function, and a small function like this can be instantiated once per
codegen unit. With 256 units and no LTO, one run printed the stored
stub at 0x555b2a7497b8 and the constant at the comparison site at
0x555b2a81dbf8. The comparison never matched. Dev and the ship profile
(fat LTO, one unit) keep a single copy, so they passed.

Add a holds_code flag next to func, written under publish_lock, and
have has_code() read it. publish() treats a null func as "publish no
code" and stores the stub. func is still never null when empty: a CPU
that passed is_runnable can load it just as retire_code swaps the code
out, so it must stay callable. Dispatch is unchanged. The two tests
that compared func with the stub now call it and check it returns
EXEC_FALLBACK.

Cost, on the ship profile with --features jitv2: the 6248 indirect
calls in the MipsCpu functions are identical before and after, and the
inline-compile check on CPU arrival goes from load, lea, cmp, je to
movzbl, test, je. perf stat instructions:u for iris-bench run --quick
--cpu r10000, six interleaved runs each, is 182.9G mean (sd 5.8G) on
base 2adb78f and 184.6G (sd 4.4G) here. The difference is inside
the run-to-run spread. has_code() is on no per-instruction path.

Verified: the nine tests pass in a build with 256 codegen units and no
LTO. nextest passes in dev with default features and with
jitv2,rex-jit,gputrace, and iris-checks passes after the
release-features build.

Production lines: +15 -6
Test lines: +9 -3
@jamesbraid
jamesbraid marked this pull request as ready for review November 30, 2026 05:46
@jamesbraid jamesbraid changed the title jitv2: stop comparing function addresses to tell if a page has code jitv2: tell an empty code page by a flag, not by the stub's address Nov 30, 2026
@jamesbraid
jamesbraid merged commit 51cf2c7 into main Nov 30, 2026
15 checks passed
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