RFR: 8369944: Notification can be lost due to interrupt in Object.wait

Patricio Chilano Mateo pchilanomate at openjdk.org
Thu Oct 16 22:48:29 UTC 2025


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

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

Commit messages:
 - v1

Changes: https://git.openjdk.org/jdk/pull/27856/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27856&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8369944
  Stats: 12 lines in 2 files changed: 0 ins; 7 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/27856.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27856/head:pull/27856

PR: https://git.openjdk.org/jdk/pull/27856


More information about the hotspot-runtime-dev mailing list