RFR: 8369019: Improve timed-park mechanism in ObjectMonitor for virtual thread support [v3]
Alan Bateman
alanb at openjdk.org
Mon Oct 6 16:51:24 UTC 2025
On Fri, 3 Oct 2025 19:55:20 GMT, Patricio Chilano Mateo <pchilanomate at openjdk.org> wrote:
>> Please review the following fix. When blocking in `ObjectMonitor::enter_internal` we currently use timed-park for pinned virtual threads. This is done to alleviate some potential deadlocks cases where the successor is an unmounted virtual thread that cannot run. In particular this could happen during class loading/initialization if all other carriers are blocked waiting for the same class to be loaded/initialized.
>> This mechanism should be extended to cover `ObjectMonitor::reenter_internal` used in `Object.wait` (notification case). Also, the criteria to decide whether to do a timed-park should be based on whether there are unmounted vthreads already in the `_entry_list`, and not just if this is a pinned virtual thread. This covers mixed usages of the same ObjectMonitor between virtual threads and platform threads. This will become more relevant once we bring the changes currently in the fibers branch to preempt virtual threads during klass initialization.
>>
>> These changes have been running in the loom pipeline for a couple of months already. I also added a new test case to test/jdk/java/lang/Thread/virtual/MonitorWaitNotify.java which deadlocks without these changes.
>>
>> Thanks,
>> Patricio
>
> Patricio Chilano Mateo has updated the pull request incrementally with one additional commit since the last revision:
>
> make MAX_RECHECK_INTERVAL global static
test/jdk/java/lang/Thread/virtual/MonitorWaitNotify.java line 645:
> 643: /**
> 644: * Test no deadlock happens when Object.wait is called from a mix of pinned and non-pinned
> 645: * paths and notification is done using notifyAll.
At some point then maybe we should combine this with RetryMonitorEnterWhenPinned. I'm not suggesting we do this now but some of the expanded description might be useful to include here as a passing reader might not immediately know what this test is doing.
test/jdk/java/lang/Thread/virtual/MonitorWaitNotify.java line 648:
> 646: */
> 647: @Test
> 648: void testMixedPinnedUnmounted() throws Exception {
What would you think of testing timed-wait too? Some of the other tests are paramerized with a value source and some time values to test both untimed and timed waits.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27597#discussion_r2407415045
PR Review Comment: https://git.openjdk.org/jdk/pull/27597#discussion_r2407408631
More information about the hotspot-runtime-dev
mailing list