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

Roman Kennke rkennke at redhat.com
Mon Jun 27 10:46:38 UTC 2016


Great work! It does indeed fix some failures, and patch looks good too!

Please go ahead and push!

Cheers,
Roman

Am Montag, den 27.06.2016, 10:08 +0200 schrieb Roland Westrelin:
> 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