Locks, monitors, and deadlocks (LOCKS)
An example of the LOCKS component part of a Java™ dump taken during a deadlock.
A lock typically prevents more than one entity from accessing a shared resource. Each object in the Java language has an associated lock, also referred to as a monitor, which a thread obtains by using a synchronized method or block of code. In the case of the JVM, threads compete for various resources in the JVM and locks on Java objects.
When you take a Java dump,
the JVM attempts to detect deadlock cycles. The JVM can detect cycles
that consist of locks that are obtained through synchronization, locks that extend the java.util.concurrent.locks.AbstractOwnableSynchronizer class, or
a mix of both lock types.
The following example is from a deadlock test
program where two threads, DeadLockThread 0 and DeadLockThread 1,
unsuccessfully attempt to synchronize on a java/lang/String object,
and lock an instance of the java.util.concurrent.locks.ReentrantLock class.
The
Locks section in the example (highlighted) shows that thread DeadLockThread
1 locked the object instance java/lang/String@0x00007F5E5E18E3D8.
The monitor was created as a result of a Java code
fragment such as synchronize(aString), and this monitor
has DeadLockThread 0 waiting to get a lock on this same object instance
(aString). The deadlock section also shows an instance
of the java.util.concurrentlocks.ReentrantLock$NonfairSync class,
that is locked by DeadLockThread 0, and has Deadlock Thread 1 waiting.
This classic deadlock situation is caused by an error in application design; Javadump is a major tool in the detection of such events.
Blocked thread information is also available in the Threads section of the Java dump, in lines that begin with 3XMTHREADBLOCK, for threads
that are blocked, waiting or parked. For more information, see Blocked thread information.
NULL ------------------------------------------------------------------------
0SECTION LOCKS subcomponent dump routine
NULL ===============================
NULL
1LKPOOLINFO Monitor pool info:
2LKPOOLTOTAL Current total number of monitors: 2
NULL
1LKMONPOOLDUMP Monitor Pool Dump (flat & inflated object-monitors):
2LKMONINUSE sys_mon_t:0x00007F5E24013F10 infl_mon_t: 0x00007F5E24013F88:
3LKMONOBJECT java/lang/String@0x00007F5E5E18E3D8: Flat locked by "Deadlock Thread 1" (0x00007F5E84362100), entry count 1
3LKWAITERQ Waiting to enter:
3LKWAITER "Deadlock Thread 0" (0x00007F5E8435BD00)
NULL
1LKREGMONDUMP JVM System Monitor Dump (registered monitors):
2LKREGMON Thread global lock (0x00007F5E84004F58): <unowned>
2LKREGMON &(PPG_mem_mem32_subAllocHeapMem32.monitor) lock (0x00007F5E84005000): <unowned>
2LKREGMON NLS hash table lock (0x00007F5E840050A8): <unowned>
< lines removed for brevity >
1LKDEADLOCK Deadlock detected !!!
NULL ---------------------
NULL
2LKDEADLOCKTHR Thread "Deadlock Thread 0" (0x00007F5E8435BD00)
3LKDEADLOCKWTR is waiting for:
4LKDEADLOCKMON sys_mon_t:0x00007F5E24013F10 infl_mon_t: 0x00007F5E24013F88:
4LKDEADLOCKOBJ java/lang/String@0x00007F5E5E18E3D8
3LKDEADLOCKOWN which is owned by:
2LKDEADLOCKTHR Thread "Deadlock Thread 1" (0x00007F5E84362100)
3LKDEADLOCKWTR which is waiting for:
4LKDEADLOCKOBJ java/util/concurrent/locks/ReentrantLock$NonfairSync@0x00007F5E7E1464F0
3LKDEADLOCKOWN which is owned by:
2LKDEADLOCKTHR Thread "Deadlock Thread 0" (0x00007F5E8435BD00)