RFR: 8369944: Notification can be lost due to interrupt in Object.wait [v2]
Fredrik Bredberg
fbredberg at openjdk.org
Thu Oct 23 14:37:38 UTC 2025
On Fri, 17 Oct 2025 15:24:48 GMT, Patricio Chilano Mateo <pchilanomate at openjdk.org> wrote:
>> If a thread waiting in `Object.wait` is interrupted at the same time it is being notified, it could wake up, read `node.TState` as `TS_ENTER` but then read `node._notified` as false. There is no ordering in `notify_internal()` between setting `iterator->_notified` to true and setting `node.TState` to `TS_ENTER`.
>> This means that `WasNotified` will be false and the thread will throw IE. But we will then miss a notification as per the JLS 17.2.4 specs:
>>
>> `Note that if a thread is both interrupted and woken via notify, and that thread returns from wait by throwing an InterruptedException, then some other thread in the wait set must be notified.`
>>
>> There is no need for `_notified`, since the value of `node.TState` can be used to tell if the thread was notified or not.
>> Testing in mach5 tiers1-5.
>>
>> Related note: besides checking for `!WasNotified`, I think we should also check for `ret == OS_OK` before throwing IE. This could have been a timed-wait that timed-out, and only after that, the thread was interrupted while trying to reenter the monitor (the thread can be observed in the reenter part either with JVMTI events enabled or by reading the j.l.Thread.State).
>>
>> Thanks,
>> Patricio
>
> Patricio Chilano Mateo has updated the pull request incrementally with one additional commit since the last revision:
>
> rename to was_notified
Nice cleanup! Having two variables that should always be in sync is never a good idea, so thank you for dropping the unnecessary `_notified`.
-------------
Marked as reviewed by fbredberg (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/27856#pullrequestreview-3370288391
More information about the hotspot-runtime-dev
mailing list