Integrated: 8369944: Notification can be lost due to interrupt in Object.wait
Patricio Chilano Mateo
pchilanomate at openjdk.org
Thu Oct 23 15:49:45 UTC 2025
On Thu, 16 Oct 2025 22:03:51 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
This pull request has now been integrated.
Changeset: 6e898e21
Author: Patricio Chilano Mateo <pchilanomate at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/6e898e21130259839e8060245c70182f70d8ee12
Stats: 14 lines in 2 files changed: 0 ins; 7 del; 7 mod
8369944: Notification can be lost due to interrupt in Object.wait
Reviewed-by: dholmes, fbredberg
-------------
PR: https://git.openjdk.org/jdk/pull/27856
More information about the hotspot-runtime-dev
mailing list