Invalid code generated by C2 compiler in OpenJDK 21

Andrew Haley aph-open at littlepinkcloud.com
Mon Dec 18 09:42:10 UTC 2023


On 12/18/23 08:26, Antoine DESSAIGNE wrote:
> In my code storedValueVT always has a value, it's tested in the first
> if, but in the second if somehow it throws an NPE. The variable is not
> set to null and it's not reassigned, it only happens with C2 compiled
> code in the second "if" statement, the first one always works.

I wonder if there's a data race here. Is it possible that the storedValue
is changing while this executes?

What would happen if you changed the code to do this?

private void resolveArrhythmicUpdate() {
     // extracting a value non-null value
     if (conditionA && !conditionB) {
         // then call storedValue.getValidTime();.getStartMillis() and it's working
     }
     // some code not altering storedValueVT
     // same if as previouly but with one more condition
     if (conditionA && !conditionB && !conditionC) {
         // then call storedValue.getValidTime();.getStartMillis() and it throws an NPE
     }
}

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the hotspot-compiler-dev mailing list