See discussion and complete test case at http://cs.oswego.edu/pipermail/concurrency-interest/2012-November/010184.html It reproduces perfectly on server VMs tested: all existing 7u*, many 6u* tested. The test passes with -XX:-Inline. The assembly shows that this loop: public void think() { while (true) { if (checkInterruptedStatus()) break; } System.out.println("We're done thinking"); } private boolean checkInterruptedStatus() { return Thread.currentThread().isInterrupted(); } ...is being reduced to: # {method} 'think' '()V' in 'InterruptedVisibilityTest' ... 0x00007f31890601a3: mov 0x14(%r10),%r11d // read $interrupted 0x00007f31890601a7: test %r11d,%r11d // test $interrupted 0x00007f31890601aa: jne 0x00007f31890601c9 // exit branch 0x00007f31890601ac: mov %rbp,%r10 // LOOP START 0x00007f31890601af: test %eax,0xb15ee4b(%rip) // safepoint 0x00007f31890601b5: jmp 0x00007f31890601ac // LOOP END ...effectively to non-terminating busy loop, which ignores interrupts. The interesting part is that this loop is working just fine: public void think() { while (true) { if (Thread.currentThread().isInterrupted()) break; } System.out.println("We're done thinking"); } ...which means there is either a weird interaction with inlining, which either loses barriers, or intrinsics inlining which gets isInterrupted() inlined into the leaf callee, and then being treated as usual read with final inlining into think().
|