On Thu, 26 Nov 2026 16:07:46 GMT, Fredrik Bredberg <[email protected]> 
wrote:

>> src/hotspot/share/prims/jvmtiRawMonitor.cpp line 317:
>> 
>>> 315:     // into random stack space. So we have to ensure we extract (and
>>> 316:     // retain the usage of) the ParkEvent before we set the TS_RUN
>>> 317:     // state, and then don't access 'w', only the retained 'ev'.
>> 
>> This copy of the comment is not quite accurate. The `simple_wait` is not 
>> really affected by the change to TS_RUN. The waiting thread can proceed as 
>> soon as we drop the `RawMonitor_lock` below as that allows `dequeue_waiter` 
>> to proceed, which in turn allows the thread to  return from `simple_wait` 
>> leaving `w` as a dangling pointer. Suggestion:
>> 
>> // The RawMonitor_lock will prevent `w` from being removed, but as soon as 
>> we drop it, `w` could
>> // be pointing into random stack space. So we have to ensure we extract (and 
>> retain the usage of)
>> // the ParkEvent before doing that, and then don't access `w`, only the 
>> retained `ev`.
>> 
>> Though we could simply move the unlock to after the final unpark - after all 
>> for notifyAll we do all but the last unpark with the lock held.
>
> The problem is that `dequeue_waiter() `can exit without grabbing the 
> `RawMonitor_lock`, if the state of `w` is already `TS_RUN` when 
> `dequeue_waiter()` is called. Which can happen if `simple_wait()` calls a 
> timed `park()`, that times out, and `simple_notify() `is called by some 
> thread and sets the state of `w` to `TS_RUN`. Hence, why I believe the 
> `simple_wait()` is affected by change to `TS_RUN`.

Totally missed that aspect. <sigh>

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33770#discussion_r4715076408

Reply via email to