RFR: 8366659: ObjectMonitor::wait() liveness problem with a suspension request [v26]

Daniel D. Daugherty dcubed at openjdk.org
Tue Jan 20 19:03:17 UTC 2026


On Tue, 20 Jan 2026 09:56:09 GMT, Anton Artemov <aartemov at openjdk.org> wrote:

>> Hi, please consider the following changes:
>> 
>> If suspension is allowed when a thread is re-entering an object monitor (OM), then a following liveness issues can happen in the `ObjectMonitor::wait()` method.
>> 
>> The waiting thread is made to be a successor and is unparked. Upon a suspension request, the thread will suspend itself whilst clearing the successor. The OM will be left unlocked (not grabbed by any thread), while the other threads are parked until a thread grabs the OM and the exits it. The suspended thread is on the entry-list and can be selected as a successor again. None of other threads can be woken up to grab the OM until the suspended thread has been resumed and successfully releases the OM.
>> 
>> This can happen in three places where the successor could be suspended: 
>> 
>> 1:
>> https://github.com/openjdk/jdk/blob/6322aaba63b235cb6c73d23a932210af318404ec/src/hotspot/share/runtime/objectMonitor.cpp#L1897
>> 
>> 2:
>> https://github.com/openjdk/jdk/blob/6322aaba63b235cb6c73d23a932210af318404ec/src/hotspot/share/runtime/objectMonitor.cpp#L1149
>> 
>> 3:
>> https://github.com/openjdk/jdk/blob/6322aaba63b235cb6c73d23a932210af318404ec/src/hotspot/share/runtime/objectMonitor.cpp#L1951
>> 
>> The issues are addressed by not allowing suspension in case 1, and by handling the suspension request at a later stage, after the thread has grabbed the OM in `reenter_internal()` in case 2. In case of a suspension request, the thread exits the OM and enters it again once resumed. 
>> 
>> Case 3 is handled by not transferring a thread to the `entry_list` in `notify_internal()` in case the corresponding JVMTI event is allowed. Instead, a tread is unparked and let run. Since it is not on the `entry_list`, it will not be chosen as a successor and it is no harm to suspend it if needed when posting the event. 
>> 
>> Possible issue of posting a `waited` event while still be suspended is addressed by adding a suspension check just before the posting of event.
>> 
>> Tests are added.
>> 
>> Tested in tiers 1 - 7.
>
> Anton Artemov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8366659: Fixed whitespace.

I last reviewed v19 and I've re-reviewed all the changes since then as one diff between v19 and v25. This looks good to me and I've posted just a couple of comments.

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

> 1867: 
> 1868:   int ret = OS_OK;
> 1869:   bool was_notified = true;

L2021: // Monitor notify has precedence over thread interrupt.

With this change to `was_notified` default value, I don't think we can say
that monitor notify has precedence over thread interrupt anymore.

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

> 1931:     // Post monitor waited event. Note that this is past-tense, we are done waiting.
> 1932:     // A thread which should post monitor_waited event is never in TS_ENTER state.
> 1933:     if (JvmtiExport::should_post_monitor_waited()) {

Is it worth asserting that `node.TState != ObjectWaiter::TS_ENTER` inside the if-statement?

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

Marked as reviewed by dcubed (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27040#pullrequestreview-3683757507
PR Review Comment: https://git.openjdk.org/jdk/pull/27040#discussion_r2709683636
PR Review Comment: https://git.openjdk.org/jdk/pull/27040#discussion_r2709638312


More information about the hotspot-runtime-dev mailing list