[jmm-dev] easily observable examples of non-sc behaviours in Java

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Jan 15 19:22:03 UTC 2015

On 01/15/2015 10:07 PM, Hans Boehm wrote:
> A similar, though somewhat simpler and more standard, example seems to be
> while (!flag) {}
> getting optimized to tmp = flag; while(!tmp) {}
> I have no idea which JVMs currently do that, but it seems to me that they
> should.

Hotspot does this routinely. This opens up an interesting class of bugs:
busy-waiting on some condition may stuck indefinitely. This is
especially "fun" in intrinsics, e.g. these two interesting bugs:

 a) busy-waiting on Reference.get(): Hotspot intrinsifies the call, but
forgets the barrier, loop optimizations then move out the predicate out
of the loop, boom: https://bugs.openjdk.java.net/browse/JDK-7190310

 b) busy-waiting on Thread.currentThread().isInterrupted(): same thing,
but amusingly only in OSR stub, boom:

I think both are observable on 7u4 or lower.


More information about the jmm-dev mailing list