RFR: 8256314: JVM TI GetCurrentContendedMonitor is implemented incorrectly

Alan Bateman alanb at openjdk.org
Wed Feb 21 19:15:56 UTC 2024


On Wed, 21 Feb 2024 10:28:49 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:

> The implementation of the JVM TI `GetCurrentContendedMonitor` does not match the spec. It can sometimes return an incorrect information about the contended monitor. Such a behavior does not match the function spec. 
> With this update the `GetCurrentContendedMonitor` is returning the monitor only when the specified thread is waiting to enter or re-enter the monitor, and the monitor is not returned when the specified thread is waiting in the `java.lang.Object.wait` to be notified.
> 
> The implementation of the JDWP `ThreadReference.CurrentContendedMonitor` command is based and depends on this JVMTI function. The command was both specified incorrectly and had an incorrect behavior. The fix slightly corrects the JDWP spec to make it right (the JDWP implementation has been fixed by the JVM TI update). Please, see and review the related CSR and Release-Note.
> 
> CSR: [8326024](https://bugs.openjdk.org/browse/JDK-8326024): JVM TI GetCurrentContendedMonitor is implemented incorrectly
> RN:   [8326038](https://bugs.openjdk.org/browse/JDK-8326038): Release Note: JVM TI GetCurrentContendedMonitor is implemented incorrectly
> 
> Testing:
>  - tested with the mach5 tiers 1-6

src/java.se/share/data/jdwp/jdwp.spec line 1985:

> 1983:         "thread may be waiting to enter a monitor, or it may be waiting, via "
> 1984:         "the java.lang.Object.wait method, to re-enter a monitor after being "
> 1985:         "notified by another thread. "

Interrupted or timeout in Object.wait are other reasons to be waiting to reenter. I'm wondering if this should be spelled out here. I see the JVMTI spec uses the phrase "regain" to cover the scenarios where a thread is waiting to reenter.

In any case, I think the wording could be a smoother as reenter case isn't very clear. Here's an attempt as smoothing out the wording but it may be more than you want to include:

"The thread may be waiting to enter the object's monitor, in the monitor's wait set and waiting in Object.wait, or in Object.wait waiting to reenter the monitor after being notified, interrupted, or timeout."

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17944#discussion_r1498160800


More information about the serviceability-dev mailing list