Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8059913

Deadlock finder is unable to find deadlocks caused by <clinit>

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 12
    • Component/s: hotspot
    • Labels:

      Description

      Ctrl-\ prints out the thread dump, which includes an analysis for deadlocks. Here's a good example:

          public class DeadLock {

            static Object a = new Object();
            static Object b = new Object();

            public static void main(String args[]) {
              (new Thread() {
                  public void run() {
                    synchronized(a) {
                      try {Thread.sleep(1000);} catch (Throwable t) {}
                      synchronized(b) {
                      }
                    }
                  }
                }).start();

              synchronized(b) {
                try {Thread.sleep(1000);} catch (Throwable t) {}
                synchronized(a) {
                }
              }
            }
          }

          Ctrl-\
          ...
          Found one Java-level deadlock:
          =============================
          "Thread-0":
            waiting to lock monitor 0x00007f97980062c8 (object 0x00000006b0ccc5f8, a java.lang.Object),
            which is held by "main"
          "main":
            waiting to lock monitor 0x00007f9798004cc8 (object 0x00000006b0ccc5e8, a java.lang.Object),
            which is held by "Thread-0"

          Java stack information for the threads listed above:
          ===================================================
          "Thread-0":
              at DeadLock$1.run(DeadLock.java:12)
              - waiting to lock <0x00000006b0ccc5f8> (a java.lang.Object)
              - locked <0x00000006b0ccc5e8> (a java.lang.Object)
          "main":
              at DeadLock.main(DeadLock.java:20)
              - waiting to lock <0x00000006b0ccc5e8> (a java.lang.Object)
              - locked <0x00000006b0ccc5f8> (a java.lang.Object)

          Found 1 deadlock.

      However, there seems to be a bug with deadlock detection, if the deadlocks are caused by intertwined <clinit>

          public class DeadLockClinit {
            static Object a = new Object();
            static Object b = new Object();

            static class A {
              static Object x;
              static {
                System.out.println("A started");
                try {Thread.sleep(1000);} catch (Throwable t) {}
                System.out.println("A waited");
                x = new B();
              }
            }

            static class B {
              static Object x;
              static {
                System.out.println("B started");
                try {Thread.sleep(1000);} catch (Throwable t) {}
                System.out.println("B waited");
                x = new A();
              }
            }

            public static void main(String args[]) {
              (new Thread() {
                  public void run() {
                    A x = new A();
                  }
                }).start();
              B x = new B();
            }
          }

          Ctrl-\
          ...
          "main" prio=10 tid=0x00007f02d800a000 nid=0x5e78 in Object.wait() [0x00007f02deb93000]
             java.lang.Thread.State: RUNNABLE
              at DeadLockClinit$B.<clinit>(DeadLockClinit.java:25)
              at DeadLockClinit.main(DeadLockClinit.java:37)
          "Thread-0" prio=10 tid=0x00007f02d810b000 nid=0x5e98 in Object.wait() [0x00007f024c4ca000]
             java.lang.Thread.State: RUNNABLE
              at DeadLockClinit$A.<clinit>(DeadLockClinit.java:14)
              at DeadLockClinit$1.run(DeadLockClinit.java:33)
          ...
          (no deadlocks found.)


      This issue is causing customers (see comments) problems in diagnosing program lock ups.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              iklam Ioi Lam
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: