JDK-6478991 : C1 NullCheckEliminator yields incorrect exceptions
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-10-05
  • Updated: 2013-04-24
  • Resolved: 2011-09-30
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 7 JDK 8 Other
7u2Fixed 8Fixed hs22Fixed
Description
Bug report from Christian Wimmer of the C1 collaborative research project:

While analyzing the NullCheckEliminator for the object inlining work, I
found a possible problem where necessary explicit null checks are
eliminated. The attached java class illustrates the problem: An explicit
null check is folded into a later field load, but between the two
instructions there is a class cast that fails. Therefore, the class cast
exception is thrown before the null check is performed. I think that the
order of the exceptions must be preserved, so this behavior is not allowed.

The null check eliminator contains a NEEDS_CLEANUP-comment that states
exactly this, so you possibly already know about this.


Example: If you run the attached class in the interpreter using

  java -Xint NullCheckTest
  
a NullPointerException is thrown. When the method is compiled using

  java -Xcomp -XX:CompileOnly=NullCheckTest.test NullCheckTest
  
a ClassCastException is thrown.

Comments
EVALUATION http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/15559220ce79
08-07-2011

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-main/hotspot/rev/15559220ce79
07-07-2011

EVALUATION 6478991: C1 NullCheckEliminator yields incorrect exceptions Reviewed-by: twisti, iveresov checkcast can trap so don't allow explicit null checks to be folded into instructions that follow it. Tested with new test case.
07-07-2011

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/15559220ce79
06-07-2011

EVALUATION 6478991: C1 NullCheckEliminator yields incorrect exceptions Reviewed-by: iveresov checkcast can trap so don't allow explicit null checks to be folded into instructions that follow it. Tested with new test case.
28-03-2011