Request for review (S): C2 should recognize "obj.getClass() == A.class" code pattern

Krystal Mok rednaxelafx at
Tue Apr 24 09:16:07 PDT 2012

Hi all,

Could I get some reviews for this patch, please? Any comments and
suggestions are welcomed.
I'm still pretty new to C2, and I'm taking this as an exercise to get more
familiar with the implementation details.

The idea is to optimize this code pattern:

  x.getClass() == A.class


  x._klass == klassof(A)

which shortens the original pattern by 1 load.

A scenario where this might be useful is the following code pattern:

  if (x.getClass() == A.class) {
    A a = (A) x; // checkcast
    a.m();       // ... use a ...

Before this change, there would be redundant exact type check in the
generated code, as mentioned in an earlier thread [1].
After this change, the redundant check gets optimized away, because the new
pattern is the same as the one used in the fast path of

It's probably rare to see this pattern in normal Java code, where normal
virtual dispatch should be favored instead. But it might be a common
pattern in dynamic language runtime implementations.
I'll leave it to Remi to explain the original motivation for optimizing
this code pattern :-)

Tested with CTW -XX:+VerifyIterativeGVN, and SPECjvm2008.
The composite result in SPECjvm2008 seems to have dropped a little bit, I'm
not sure if that's caused by this change or by some variance on my test



SPECjvm2008 results:

JDK8-b35/HS24-b07 without change:
compiler                      668.38
compress                      339.67
crypto                        342.78
derby                         679
mpegaudio                     214.92
scimark.large                 63.42
scimark.small                 388.48
serial                        262.37
startup                       26.89
sunflow                       129.93
xml                           785.47
Composite result: 246.2 SPECjvm2008 Base ops/m

JDK8-b35/HS24-b07 with change:
compiler                      629.35
compress                      337.61
crypto                        342.02
derby                         689.93
mpegaudio                     216.66
scimark.large                 60.33
scimark.small                 387.42
serial                        233.34
startup                       26.41
sunflow                       131.64
xml                           780.32
Composite result: 241.2 SPECjvm2008 Base ops/m
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the hotspot-compiler-dev mailing list