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:
- csr of
-
JDK-8247972 incorrect implementation of JVM TI GetObjectMonitorUsage
-
- Resolved
-
- relates to
-
JDK-8325314 Release Note: The Implementation of JVMTI `GetObjectMonitorUsage` Has Been Corrected
-
- Resolved
-