Repository navigation
jitv2: tell an empty code page by a flag, not by the stub's address - #941
Merged
Merged
Conversation
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
force-pushed
the
jb/jit-fnptr
branch
from
November 30, 2026 05:46
134b2b6 to
4fc920a
Compare
jamesbraid
marked this pull request as ready for review
November 30, 2026 05:46
jamesbraid
force-pushed
the
jb/jit-fnptr
branch
from
November 30, 2026 07:54
4fc920a to
6a6f24e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inmips_exec_testandexception_mid_run_counts_like_the_interpreter.Cause
An empty page points its code pointer (
func) at a stub,jit_no_code.has_code()andpublish_from()decided "empty" by comparingfuncwith the address ofjit_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 at0x555b2a7497b8and the constant at the comparison site at0x555b2a81dbf8. The comparison never matched. Dev and the ship profile (fat LTO, one unit) keep a single copy, so they passed.Fix
Add a
holds_codeflag next tofunc, written underpublish_lock, and havehas_code()read it.publish()treats a nullfuncas "publish no code" and stores the stub.funcis still never null when empty: a CPU that passedis_runnablecan load it just asretire_codeswaps the code out, so it must stay callable. Dispatch is unchanged. The two tests that comparedfuncwith the stub now call it and check it returnsEXEC_FALLBACK.Cost
On the ship profile with
--features jitv2, the 6248 indirect calls in theMipsCpufunctions 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:uforiris-bench run --quick --cpu r10000, six interleaved runs each, is 182.9G mean (sd 5.8G) on base2adb78f8aand 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, andiris-checkspasses after the release-features build.Production lines: +15 -6. Test lines: +9 -3.