JDK-8370416 : C2: Optimizing away arraycopy leads to wrong execution
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11
  • Priority: P2
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2025-10-22
  • Updated: 2025-11-21
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 26
26Unresolved
Related Reports
Relates :  
Relates :  
Description
Found by Olivier Mattmann <olivier.mattmann@bluewin.ch> during work on this Master thesis where he is working on a fuzzer for C2.

The attached test case (Test.java) leads C2 to optimize away the array copy which in turn leads to a wrong execution. The test case was derived from compiler/arraycopy/TestLoadBypassACWithWrongMem.java introduced in JDK-8181742. The symptoms look similar, but the setup is now more contrived.

java -XX:-TieredCompilation -Xbatch Test.java
Exception in thread "main" java.lang.RuntimeException: Wrong result from compiled method test1: 16. Expected: 0
	at Test.main(Test.java:34)

Possible workarounds: -XX:-DoEscapeAnalysis, -XX:-UseSwitchProfiling, -XX:-UseProfiledLoopPredicate
Comments
Looks like the 'dst' array is scalar replaced but the debug info about the contents of the array is incorrect. Workarounds: -XX:DisableIntrinsic=_arraycopy or -XX:-EliminateAllocations ILW = Wrong result of C2 compiled code, easy to reproduce but edge case and old issue, -XX:DisableIntrinsic=_arraycopy or -XX:-EliminateAllocations = HMM = P2
23-10-2025

[~roland] Since this is similar to JDK-8181742, maybe you want to take a look.
23-10-2025