JDK-8347718 : Unexpected NullPointerException in C2 compiled code due to ReduceAllocationMerges
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23,24,25
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-01-14
  • Updated: 2025-04-22
  • Resolved: 2025-01-28
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 24 JDK 25
24.0.2Fixed 25 b08Fixed
Related Reports
Duplicate :  
Relates :  
Description
The attached test file TestC2Miscompile.java prints:

$ java TestC2Miscompile.java
true
true
false
false
true
true
false
true
true
true
false
true
false
true
false
true
NullPointerException: Cannot invoke "TestC2Miscompile$Class0.Class0_method1()"
true
false
false

Examination of the code shows that the receiver can never be null here. Goes away with either of -Xint or -XX:TieredStopAtLevel=3, so I think this must be a C2 bug.

Reproduced today with OracleJDK 25+5, but goes back at least half a year.
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk24u/pull/65 Date: 2025-02-10 08:07:01 +0000
10-02-2025

Fix Request (JDK 24u) The issue leads to an incorrect result with C2 compiled code (unexpected NPE, regression in JDK 23). The fix is low risk and was thoroughly tested in JDK 25 (integrated two weeks ago). The backport applies cleanly.
10-02-2025

Changeset: 9f4d3de4 Branch: master Author: Cesar Soares Lucas <cslucas@openjdk.org> Committer: Vladimir Kozlov <kvn@openjdk.org> Date: 2025-01-28 19:17:15 +0000 URL: https://git.openjdk.org/jdk/commit/9f4d3de442a846c503dac52de4a757e5b5638e73
28-01-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/23312 Date: 2025-01-27 03:36:24 +0000
27-01-2025

I attached a simpler version of the test (Simple.java): java -XX:-TieredCompilation -Xbatch Simple.java Exception in thread "main" java.lang.RuntimeException: Unexpected null at Simple.test(Simple.java:37) at Simple.main(Simple.java:45)
15-01-2025

ILW = Incorrect result with C2 compiled code (unexpected NPE), edge case with generated test but easy to reproduce, -XX:-ReduceAllocationMerges = HLM = P3
15-01-2025

This is a regression from JDK-8316991 in JDK 23 b18.
14-01-2025

Thanks for the report, [~gbarany]! I'll take a look.
14-01-2025