series: keep guest loads whose value is unused

Merged
UT
23d ago
+99-1

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=3default 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 0x0same abortDONE n=4999000 npe=1000
2610-gn5-f83cf58-0 (this PR), exit 0, exit 0, exit 0

Necesse on stock settings:

BuildResult
2610-gn-4hs_err at 13 s, every run (5 runs, also with -XX:-ImplicitNullChecks)
2610-gn5-f83cf58-0at +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 (fb48e2d19) has the same code; this is not sent upstream here.