JDK-8131782 : C1 Class.cast optimization breaks when Class is loaded from static final
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-07-17
  • Updated: 2016-04-27
  • Resolved: 2015-07-25
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 8 JDK 9
8u101Fixed 9 b77Fixed
Related Reports
Blocks :  
Relates :  
Description
This is observed in VarHandles work for JDK-8130923.

The reason is that C1 canonicalizer seems to assume a particular constant shape (InstanceConstant), while the Class instances coming through @Stable/static-final seem to be ObjectConstants. Accepting ObjectConstants as well fixes it:
  http://cr.openjdk.java.net/~shade/8131782/webrev.01/

Simple benchmark articulates it clearly:
  http://cr.openjdk.java.net/~shade/8131782/ClassCastConstants.java

(Runnable JAR: http://cr.openjdk.java.net/~shade/8131782/benchmarks.jar)

Baseline result calls into Runtime::isInstance in "static final" case, experiencing the 2x hit:
  http://cr.openjdk.java.net/~shade/8131782/baseline.perfasm

Patched VM behaves perfectly well in both cases:
  http://cr.openjdk.java.net/~shade/8131782/patched.perfasm