RFR: 8369019: Improve timed-park mechanism in ObjectMonitor for virtual thread support

David Holmes dholmes at openjdk.org
Thu Oct 2 05:38:48 UTC 2025


On Wed, 1 Oct 2025 22:13:58 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

src/hotspot/share/runtime/objectMonitor.cpp line 988:

> 986: 
> 987:   // If there are unmounted virtual threads ahead in the _entry_list we want
> 988:   // to do a timed-park instead to alleviate some deadlocks cases where one

Suggestion:

  // to do a timed-park instead to alleviate some deadlock cases where one

src/hotspot/share/runtime/objectMonitor.cpp line 997:

> 995:   // prevents this load from floating up previous store.
> 996:   // Note that we can have false positives where timed-park is not necessary.
> 997:   bool do_timed_parked = has_unmounted_vthreads();

Don't we still only need the timed-park if the current thread is a pinned vthread?

src/hotspot/share/runtime/objectMonitor.cpp line 1095:

> 1093: 
> 1094:   // If there are unmounted virtual threads ahead in the _entry_list we want
> 1095:   // to do a timed-park instead to alleviate some deadlocks cases where one

Suggestion:

  // to do a timed-park instead to alleviate some deadlock cases where one

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27597#discussion_r2396996314
PR Review Comment: https://git.openjdk.org/jdk/pull/27597#discussion_r2397010146
PR Review Comment: https://git.openjdk.org/jdk/pull/27597#discussion_r2397000418


More information about the hotspot-runtime-dev mailing list