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

worker has a deadlock bug in jconsole

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • None
    • tools
    • None
    • generic
    • generic

    Description

      The code in Worker.java acquires synchronization objects in different order (once acquires jobs and then this, another time acquires this and then jobs).

      Acquiring synchronization objects in different order can cause circular wait (deadlock).

      Here is the first order: (1) first acquire 'jobs' and then 'this':
       enter public method run() at line 40
       acquire synchronization on jobs at line 43
       call isStopped() at line 44
       acquire synchronization on this at entry to isStopped() because isStopped() is
       a synchronized method --- see line 59

      Here is the second order: (2) first acquire 'this' and then 'jobs':
       enter public method stopWorker() at line 63
       acquire synchronization on this at entry to stopWorker() because
       stopWorker() is a synchronized method --- see line 63
       acquire synchronization on jobs at line 65

      one possible bugfix is to makes code always acquire synchronization in only 1 order: first acquire jobs and then this.

      public void stopWorker() { <<<<<<<<<<<<<<<< moved synchronized from
      here to below as "synchronized(this)"
          synchronized(jobs) {
              synchronized(this) { <<<<<<<<<<<<<<<<<<<<<<<<<< added this
                  stopped = true;
                  jobs.notify();
              }
          }
      }

      Reference:
      https://hg.openjdk.java.net/jdk/jdk/file/b997e5b9479b/src/jdk.jconsole/share/classes/sun/tools/jconsole/Worker.java#l63

      Attachments

        Issue Links

          Activity

            People

              dtitov Daniil Titov (Inactive)
              xliu Xin Liu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: