Optimization of a.getClass() == b.getClass() to a.klass == b.klass needs to take shenandoah's acmp pattern into account

Roland Westrelin rwestrel at redhat.com
Mon Jun 27 08:08:09 UTC 2016


http://cr.openjdk.java.net/~roland/shenandoah-acmp-getclass/webrev.00/

acmp is compiled as:
if (a != b) {
  a = read_barrier(a);
  b = read_barrier(b);
}
if (a == b) {
  ..
} else {
  ..
}

and C2 optimizes:

if (a.getClass() == b.getClass()) {

as

if (a.klass == b.klass) {

So the acmp pattern above in that case becomes:

c = a.getClass();
d = b.getClass();
if (a.klass != b.klass) {
  c = read_barrier(c);
  d = read_barrier(d);
}
if (c == d) {

Which is inefficient (because the acmp should be optimized to a single
comparison in that case) and wrong because if a.klass == b.klass the
second test is executed with no barriers.

Roland.


More information about the shenandoah-dev mailing list