RFR: 8346120: VirtualThreadPinned event recorded for Object.wait may have wrong duration or may record second event

Patricio Chilano Mateo pchilanomate at openjdk.org
Fri Dec 13 16:30:35 UTC 2024


On Thu, 12 Dec 2024 17:09:09 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> A jdk.VirtualPinnedEvent JFR event is recorded by Object::wait when a virtual thread waits in Object.wait while pinned. The posting of the event in ObjectMonitor::wait is done after waiting but it can block again in enter/ReenterI before it re-acquires. If that happens then the event duration won't be accurate, and for the off-list case, the enter may be contended and a jdk.VirtualPinnedEvent event will be recorded for contended monitor enter. The changes to fix this are small: move the post of the event for Object.wait to end of the wait function, and only post an event for contended monitor enter when not waiting.
> 
> I've added a test to check the pinned event that is recored for several contended monitor enter and Object.wait cases. It checks the event duration and that only one event is recorded for each case.

Looks good to me.

test/jdk/java/lang/Thread/virtual/MonitorPinnedEvents.java line 345:

> 343:                         vthread.interrupt();
> 344:                     } else {
> 345:                         synchronized (lock) {

Not sure if this was intentional but we already own the monitor.

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

Marked as reviewed by pchilanomate (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/22718#pullrequestreview-2502675830
PR Review Comment: https://git.openjdk.org/jdk/pull/22718#discussion_r1884181502


More information about the core-libs-dev mailing list