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

JVM TI GetCurrentContendedMonitor is implemented incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 6, 7, 8, 11, 15, 16
    • hotspot
    • b14

      The spec for GetCurrentContendedMonitor states:

      "Get the object, if any, whose monitor the specified thread is waiting to enter or waiting to regain through java.lang.Object.wait. "

      but the implementation does:

       ObjectMonitor *mon = java_thread->current_waiting_monitor();
        if (mon == NULL) {
          // thread is not doing an Object.wait() call
          mon = java_thread->current_pending_monitor();
          if (mon != NULL) {
            // The thread is trying to enter() an ObjectMonitor.
            obj = mon->object();
            assert(obj != NULL, "ObjectMonitor should have a valid object!");
          }
          // implied else: no contended ObjectMonitor
        } else {
          // thread is doing an Object.wait() call
          obj = mon->object();
          assert(obj != NULL, "Object.wait() should have an object");
        }

      which detects either contended monitor enter or a call to Object.wait (or the internal variant used by class initialization). It does not check if the thread is trying to reenter the monitor as part of Object.wait, but simply checks if the thread is somewhere within the Object.wait call. That is wrong.

      This is a long standing bug as far as I can see.

            sspitsyn Serguei Spitsyn
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: