RFR: 8365556: ObjectMonitor::try_lock_or_add_to_entry_list() returns true with the wrong state of the node

Axel Boldt-Christmas aboldtch at openjdk.org
Mon Aug 18 06:49:14 UTC 2025


On Fri, 15 Aug 2025 07:22:02 GMT, Anton Artemov <duke at openjdk.org> wrote:

> Hi, please consider the following change:
> 
> `ObjectMonitor::try_lock_or_add_to_entry_list() `does not change the node state to `TS_RUN `in case of a successful acquisition of the object monitor. In certain cases this can break the guarantee statement in the `ObjectMonitor::wait()` method and lead to a crash. The missing statement is added.
> 
> Tested in tiers 1 - 5.

Just a side note: 
_I am wondering if `try_lock_or_add_to_entry_list` should just be `add_to_entry_list` and just simply add a waiter to the list. Unclear if it is worth retrying the lock at this point. Given that the head only changes either when there are more threads trying to add themselves to the list or a thread has just acquired the lock and is removing themself. In either case unsure if we are more likely than at any other point to get the lock._

_And if we want to keep the behaviour of `try_lock_or_add_to_entry_list` it should probably try_lock first and then CAS the head. The window where we fail the CAS seems at least as significant as the window we spend allocating and initialising the ObjectWaiter between our previous lock attempt and calling `try_lock_or_add_to_entry_list`. Which would also be more inline with its name placing "lock" before "add to entry list"._

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

PR Comment: https://git.openjdk.org/jdk/pull/26794#issuecomment-3195340986


More information about the hotspot-runtime-dev mailing list