JDK-8130920 : C1 trouble in VarHandle.get tests
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-07-10
  • Updated: 2015-07-16
  • Resolved: 2015-07-16
Related Reports
Relates :  
Description
For some reason, VarHandles are significantly slower than either the plain calls or unsafe calls when compiled with C1.
This is not specific to int tests, but reproduces on all primitive tests like this:
http://cr.openjdk.java.net/~shade/8130920/IntTest.java

o.o.v.get.acc.IntTest.plain                           avgt   15   16.380 �� 0.008  ns/op
o.o.v.get.acc.IntTest.unsafe                          avgt   15   18.903 �� 0.007  ns/op
o.o.v.get.acc.IntTest.varHandle                       avgt   15   44.113 �� 0.026  ns/op

Disassembly points fingers at non-inlined MH::linkToStatic: 
 http://cr.openjdk.java.net/~shade/8130920/c1.perfasm
 http://cr.openjdk.java.net/~shade/8130920/c2.perfasm

   2029  239             java.lang.invoke.VarHandleGuards::guard_L_I (38 bytes)
                            @ 13   java.lang.invoke.VarHandleGuards::checkExactType (12 bytes)   force inline by annotation
                              @ 7   java.lang.invoke.Invokers::newWrongMethodTypeException (36 bytes)   callee is too large
                            @ 31   java.lang.invoke.VarHandleGuards::checkMemberName (12 bytes)   force inline by annotation
                              @ 6   java.lang.invoke.VarHandle::unsupported (8 bytes)
                                @ 4  java/lang/UnsupportedOperationException::<init> (not loaded)   not inlineable
                            @ 34   java.lang.invoke.MethodHandle::linkToStatic(LLL)I (0 bytes)   MemberName not constant
Comments
C1 is not able to see through @Stable final arrays. Therefore, we probably need to explode them: http://cr.openjdk.java.net/~shade/8130920/8130920.patch
15-07-2015