Skip to content

series: keep guest loads whose value is unused - #8

Merged
utkarshdalal merged 1 commit into
gamenativefrom
fexcore-keep-faulting-loads
Oct 29, 2026
Merged

utkarshdalal merged 1 commit into
gamenativefrom
fexcore-keep-faulting-loads

Conversation

@utkarshdalal

Copy link
Copy Markdown

Adds series patch 0007 and bumps SERIES_VERSION to 5.

What

The dead-flag pass (RedundantFlagCalculationElimination::EliminateDeadCode) removes any IR node with no uses and no declared side effects. LoadMem and LoadMemTSO declare none, so a guest load whose only consumer was a flag write that a later instruction overwrites is removed together with the compare. A load that faults on x86 then does not fault under FEX.

0007 sets HasSideEffects on the guest load ops in IR.json: LoadMem, LoadMemTSO, VLoadVectorMasked, VLoadVectorGatherMasked, VLoadVectorGatherMaskedQPS, VLoadVectorElement, VLoadNonTemporal. LoadMemPair already had it. The flag is read only by that dead-code check, so the only behaviour change is that unused loads stay in the block.

Why

HotSpot's C1 emits its explicit null check as cmp rax,[reg] with the flags dead (MacroAssembler::null_check), and turns the access violation at that PC into a NullPointerException. Under FEX the compare and its load were gone, so a null receiver reached the next field load, whose PC is not in the nmethod's null-check table, and the VM aborted.

Necesse (Temurin 17.0.19 x86-64 JRE) died this way 13 s after start on the Odin 3 on every FEX build and preset: EXCEPTION_ACCESS_VIOLATION reading 0xc at mov esi,[rdx+0xc] in necesse.engine.save.LoadData.getInt/getBoolean (8 bytes, tier 3), right after a passed cmp rax,[rdx]. The code between the two is the profile counter update:

cmp rax,[rdx]              ; null check for the inlined invokevirtual, flags dead
mov r8,rdx
movabs rsi,MDO
add qword [rsi+0x128],1    ; overwrites every flag -> compare removed -> load removed
...
mov esi,[rdx+0xc]          ; faults with rdx = 0, no handler for this PC

All five distinct hs_err dumps show the normal path (rsi holds the live counter, no stub taken) and the event log has Implicit null exception at <pc> to 0x0000000000000000: the JVM looked up a continuation for the faulting PC and found none. -XX:TieredStopAtLevel=1 and -XX:-TieredCompilation survive because that code folds the null check into a used load.

Evidence

Odin 3, Proton 11.0-2-arm64ec-9, Necesse container, stock Necesse.json.

Stand-alone repro (C1NullProbe: a static method calling a virtual on its argument, null every 5000th call, 5 M iterations, -XX:CompileCommand=dontinline):

Build -XX:TieredStopAtLevel=3 default tiering -XX:TieredStopAtLevel=1
2610-gn-4 (stock) abort: J 159 c1 C1NullProbe.getBool (8 bytes) @ +0x4e, AV reading 0xc, rdx=0, Implicit null exception ... to 0x0 same abort DONE n=4999000 npe=1000
2610-gn5-f83cf58-0 (this PR) , exit 0 , exit 0 , exit 0

Necesse on stock settings:

Build Result
2610-gn-4 hs_err at 13 s, every run (5 runs, also with -XX:-ImplicitNullChecks)
2610-gn5-f83cf58-0 at +26 s, menu reached (world-select dialog, 59.6 fps), javaw still alive after a further 60 s, no hs_err

Not covered: upstream InstructionCountCI expectations will change where a test compares against memory with dead flags; the series CI only builds the DLLs. Upstream main (fb48e2d) has the same code; this is not sent upstream here.

HotSpot C1 null checks are cmp rax,[reg] with dead flags; the dead-flag
pass removed the load with the compare and Necesse aborted on the next
field load. Patch 0007 declares the guest load IR ops as side-effecting.
Series version 5.
@utkarshdalal
utkarshdalal merged commit 31a43f5 into gamenative Oct 29, 2026
8 checks passed
utkarshdalal added a commit to utkarshdalal/GameNative that referenced this pull request Oct 29, 2026
Series 5 keeps guest loads whose value is unused (GameNative/FEX#8): the
dead-flag pass deleted HotSpot's cmp rax,[rdx] null probe, which aborted the
JVM in Necesse 13 s after start on every earlier FEX build. Replaces the gn-4
entry as #2211 did for gn3; overlays with a 2610-gn floor resolve to it.

Co-authored-by: Utkarsh Dalal <utkarsh.dalal@toptal.com>
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