Broken thread scheduling in indexed loop (missing safepoint?)

Vladimir Kozlov Vladimir.Kozlov at oracle.com
Fri Nov 30 15:01:13 PST 2012


Alexey,

Flag -XX:+TraceSafepoint (with debug VM) shows that a safepoint is 
initiated at that time:

Running: 1354316016260
Running: 1354316017270
Running: 1354316018280
Safepoint synchronization initiated. (8)
Waiting for 1 thread(s) to block
Entering safepoint region: EnableBiasedLocking
Leaving safepoint region
Running: 1354316065524

And because counted loops does not have safepoint instruction it waits 
until worker thread is finished. We have RFE to keep safepoint in 
counted loops for such cases but I can't say when it will be done:

6869327: Add new C2 flag to keep safepoints in counted loops.


The workaround for your case is to switch off biased locking:

-XX:-UseBiasedLocking

But it will not help in case of GC safepoint (heap collection event).

Regards,
Vladimir

On 11/30/12 05:05, Alexey Goncharuk wrote:
> Hi,
>
> We faced some weird issue with thread scheduling. At a first glance it
> looked like it relates to
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7160161 but not exactly.
>
> This is the code we ran:
>
> public static void main(String[] args) throws Exception { Thread worker
> = new Thread() { @Override public void run() { double d = 0; for (int j
> = 1; j < 2000000000; j++) d += Math.log(Math.E * j);
> System.out.println(d); } }; Thread reporter = new Thread() { @Override
> public void run() { try { while (true) { Thread.sleep(1000);
> System.out.println("Running: " + System.currentTimeMillis()); } } catch
> (InterruptedException ignored) { Thread.currentThread().interrupt(); } }
> }; reporter.start(); worker.start(); worker.join(); reporter.interrupt(); }
>
> One can expect that printing thread would output messages during all the
> calculation time, however it hangs after 3-4 iterations. Setting
> -XX:FreqInlineSize=0 as described in original bug report does not help
> in this case, but if I extract loop body into a separate method, setting
> this option works. Example passes with -Xint option as well. (Tested
> with 1.6.0_33, 1.6.0_37, 1.7.0_07 on Windows and 1.6.0_33 on Linux)
>
> I saw #7160161 marked as resolved, so I just wanted to confirm if
> behavior we see really relates to this issue and it was fixed (bug
> report covers non-Counted loop only).
>
> Also, is there any other workarounds rather then extracting the method
> and specifying FreqInlineSize=0?
>
> Thanks,
> Alexey Goncharuk
>


More information about the hotspot-compiler-dev mailing list