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

incorrect implementation of JVM TI GetObjectMonitorUsage

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 23
    • hotspot
    • None
    • behavioral
    • medium
    • Hide
      The fix is correcting the behavior existed for a long time (from the original release of the JVMTI). The function is used in the implementation of the JDWP `ObjectReference.MonitorInfo` command but the fix updates the JDWP to keep the command's original behavior. This JVMTI function is intended for debugging and we don't know about the JVMTI agents except the JDWP agent that are using it. However, such JVMTI agent(s) may exist. Also, this can potentially impact the IBM J9 implementation. There are several JVMTI JCK and vmTestbase tests which depend on this incorrect behavior and need to be fixed.
      Show
      The fix is correcting the behavior existed for a long time (from the original release of the JVMTI). The function is used in the implementation of the JDWP `ObjectReference.MonitorInfo` command but the fix updates the JDWP to keep the command's original behavior. This JVMTI function is intended for debugging and we don't know about the JVMTI agents except the JDWP agent that are using it. However, such JVMTI agent(s) may exist. Also, this can potentially impact the IBM J9 implementation. There are several JVMTI JCK and vmTestbase tests which depend on this incorrect behavior and need to be fixed.
    • Other
    • Implementation

      Summary

      The JVMTI GetObjectMonitorUsage implementation gives incorrect information about threads waiting to enter or re-enter the ObjectMonitor which does not match the function spec. The dependent JDWP ObjectReference.MonitorInfo command spec also need an update to make it clear what threads are returned as waiting for the monitor.

      Problem

      The JVMTI GetObjectMonitorUsage returns the following data structure:

          typedef struct {
              jthread owner;
              jint entry_count;
              jint waiter_count;
              jthread* waiters;
              jint notify_waiter_count;
              jthread* notify_waiters;
          } jvmtiMonitorUsage;

      The following two fields in this structure are specified as:

      waiter_count  [jint] The number of threads waiting to own this monitor
      waiters       [jthread*] The waiter_count waiting threads

      The waiters field has to include all threads waiting to enter the monitor or to re-enter it in Object.wait(). The implementation also includes the threads waiting to be notified in Object.wait() which is wrong.

      The JDWP ObjectReference.MonitorInfo command spec has the following description of the waiters field:

        waiters "The number of threads that are waiting for the monitor "
                "0 if there is no current owner"

      It is not clear what threads are waiting for the monitor: entering, re-entering, waiting to be notified, or all of the above.

      Solution

      The solution on JVMTI side is to align the implementation with the JVMTI GetObjectMonitorUsage spec, so that the waiters field only contains the threads waiting to enter/re-enter the monitor

      Also, update the JDWP ObjectReference.MonitorInfo command spec to clarify what are the waiters threads as below:

        waiters "The total number of threads that are waiting to enter or re-enter "
                "the monitor, or waiting to be notified by the monitor."

      The implementation of the JDWP command ObjectReference.MonitorInfo has to be adjusted to keep the original behavior.

      The bug has a Release Note.

      The following JVMTI vmTestbase tests have to be fixed to adopt the modified behavior:

      vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage001/TestDescription.java
      vmTestbase/nsk/jvmti/GetObjectMonitorUsage/objmonusage003/TestDescription.java

      The following JVMTI JCK tests have to be fixed to adopt the modified behavior:

      vm/jvmti/GetObjectMonitorUsage/gomu001/gomu00101/gomu00101.html
      vm/jvmti/GetObjectMonitorUsage/gomu001/gomu00101/gomu00101a.html
      vm/jvmti/GetObjectMonitorUsage/gomu001/gomu00102/gomu00102.html
      vm/jvmti/GetObjectMonitorUsage/gomu001/gomu00102/gomu00102a.html

      Specification

      The JVMTI GetObjectMonitorUsage spec is not being changed and can be found here:

      https://docs.oracle.com/en/java/javase/21/docs/specs/jvmti.html#GetObjectMonitorUsage

      The JDWP ObjectReference.MonitorInfo command spec can be found here:

      https://docs.oracle.com/en/java/javase/21/docs/specs/jdwp/jdwp-protocol.html#JDWP_ObjectReference_MonitorInfo

            sspitsyn Serguei Spitsyn
            dholmes David Holmes
            Alan Bateman, Daniel Daugherty, David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: