RFR: 8362239: Reconcile enter_internal and reenter_internal in the ObjectMonitor code

Anton Artemov duke at openjdk.org
Thu Aug 21 12:26:17 UTC 2025


Please consider the following changes:

The two methods of the `ObjectMonitor` class, namely `enter_internal()` and `reenter_internal()`, are reconciled. As a result, `reenter_internal()` is removed, whereas `enter_internal()` is modified. 

The modification affects the range of the code, where the thread is in the blocked state. Now, it is only a small part in the innermost loop of the method. However, suspension of the "contender" thread is not allowed on the initial entrance, as this can potentially lead to a deadlock: if the "contender" thread is suspended in the innermost loop, and the "resumer" thread is parked, no one will be making progress as the "resumer" thread cannot be woken up, as the "contender" thread has not yet exited the monitor to unpark the "resumer". 

In this sense, the initial entrance to the monitor is considered to be **atomic**, i.e. it is either completed, or not done at all. This means it should not be interrupted by a suspension request. The re-entrance to the monitor, however, allows suspension, as the monitor has been already owned by a "contender" thread.

Tested in tiers 1-5.

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

Commit messages:
 - 8362239: Reconciled enter_internal vs reenter_internal in the ObjectMonitor code

Changes: https://git.openjdk.org/jdk/pull/26858/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=26858&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8362239
  Stats: 164 lines in 2 files changed: 43 ins; 79 del; 42 mod
  Patch: https://git.openjdk.org/jdk/pull/26858.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26858/head:pull/26858

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


More information about the hotspot-runtime-dev mailing list