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.
8u101Fixed 9 b77Fixed
Related Reports
Blocks :  
Relates :  
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:

Simple benchmark articulates it clearly:

(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:

Patched VM behaves perfectly well in both cases: