Multiple Java threads seem to have locked the same object monitor from the thread dumps

Krystal Mok rednaxelafx at
Thu Jul 12 03:55:50 PDT 2012


Someone sent me a couple of thread dumps, and what's strange in them is
that there are multiple threads claiming to have locked the same object
There's at most only one of them actually in the
(java.lang.Thread.State-level) RUNNABLE state, which is correct. The ones
that claim to have locked but are in BLOCKED state apparent haven't really
acquired the lock yet.
Excerpts of the dumps are available here: [1]

There are two other discussion threads on this topic [2][3].

Reading through the related code [4], the only scenario that could result
in such thread dump seems to be:
1. The VM is going into a safepoint caused by the VM_PrintThreads VM
2. A thread is (re-)entering a synchronized block with
  It has already set the correct thread state at Java-level and
OSThread-level, and then it gets blocked in the safepoint callback before
setting the current pending monitor;
3. VM_PrintThreads eventually calls javaVFrame::print_lock_info_on(), where
it checks if it's the first frame and the monitor matches the thread's
current pending one.
  Because the current pending monitor wasn't set yet, this check fails, and
the lock state message defaults to "locked".

I wonder if such behavior implies we should set the pending monitor before
the safepoint callback.

And, could there be other scenarios that would produce such thread dumps?


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the hotspot-runtime-dev mailing list