JDK-8223923 : C2: Missing interference with mismatched unsafe accesses
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,13,17,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-05-14
  • Updated: 2021-10-04
  • Resolved: 2021-08-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 18
11.0.14-oracleFixed 17.0.2Fixed 18 b12Fixed
Related Reports
Relates :  
Relates :  
Description
When run with -Xcomp:

1) org.graalvm.compiler.core.test.UnsafeVirtualizationTest#testUnsafePEA01
java.lang.AssertionError: java.lang.AssertionError: expected:<0> but was:<1072693248>
	at org.graalvm.compiler.core.test.UnsafeVirtualizationTest.testPartialEscapeReadElimination(UnsafeVirtualizationTest.java:161)
	at org.graalvm.compiler.core.test.UnsafeVirtualizationTest.testUnsafePEA01(UnsafeVirtualizationTest.java:116)

Comments
Fix Request (11u) Fixes a corner case in C2. Applies cleanly. Testing passes.
01-10-2021

Fix request (17u): The bug leads to incorrect C2 compiled code. The fix is low risk and has been tested in the JDK 18 for a while and with tier1-3 in JDK 17u. The patch applies cleanly.
28-09-2021

Update ILW = Incorrect result of C2 compiled code, with mismatched unsafe accesses, no workaround (but disable compilation or don't use Unsafe) = HLM = P3
28-09-2021

Changeset: 86add21a Author: Vladimir Ivanov <vlivanov@openjdk.org> Date: 2021-08-20 12:41:20 +0000 URL: https://git.openjdk.java.net/jdk/commit/86add21a85ec57de00aecb0a18bc99567a91d0d8
20-08-2021

It turns out MemBarCPUOrder does not competely isolate mismatched unsafe accesses. In particular, MemNode::can_see_stored_value() can skip through MemBarCPUOrder nodes.
10-08-2021

thank you, Tom, I'll re-categorize it as a c2 bug then and remove you as an assignee.
09-08-2021

Just as an FYI, the UnsafeVirtualizationTest#testUnsafePEA01failure actually indicates a bug in the folding of these Unsafe operations by C2. These tests compare the results of executing the method using HotSpot and compiling with Graal, and assume the HotSpot result is the correct one. In this particular test, 1072693248 is actually the correct (expected) answer so it appears HotSpot is miscompiling unsafeSnippet1. I've attached a stripped down version of that test that shows the failure. $ java -showversion -Xcomp -XX:CompileOnly=UnsafeFoldingTest.unsafeSnippet1 UnsafeFoldingTest java version "11.0.5" 2019-10-15 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, compiled mode) 1072693248 0 $ java -showversion UnsafeFoldingTest java version "11.0.5" 2019-10-15 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode) 1072693248 1072693248
09-08-2021

in view of JEP 410 (JDK-8263327), should we close this one as NAI?
05-08-2021

[~never] or [~dnsimon] I don't really understand what this test is trying to do . Can you take a look at this please?
03-10-2020

testUnsafePEA21 is also failing with -Xcomp: org.graalvm.compiler.core.test.UnsafeVirtualizationTest#testUnsafePEA21 java.lang.AssertionError: PEA did not escape reads. before: 1, after 1 at org.graalvm.compiler.core.test.UnsafeVirtualizationTest.testPartialEscapeReadElimination(UnsafeVirtualizationTest.java:507) at org.graalvm.compiler.core.test.UnsafeVirtualizationTest.performTest(UnsafeVirtualizationTest.java:472) at org.graalvm.compiler.core.test.UnsafeVirtualizationTest.testUnsafePEA21(UnsafeVirtualizationTest.java:454)
02-10-2020

I think these tests weren't written to take -Xcomp into account. Nevertheless, this is still reproducible in jdk16. In fact I got 3 different failures running compiler/graalunit/Core02Test.java with -Xcomp. The unit test also fails with graal-jvmci-8 when run from the Graal repo with -Xcomp.
08-08-2020