Skip to content

8362239: Reconcile enter_internal and reenter_internal in the ObjectMonitor code #26858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

toxaart
Copy link
Contributor

@toxaart toxaart commented Aug 20, 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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8362239: Reconcile enter_internal and reenter_internal in the ObjectMonitor code (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26858/head:pull/26858
$ git checkout pull/26858

Update a local copy of the PR:
$ git checkout pull/26858
$ git pull https://git.openjdk.org/jdk.git pull/26858/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26858

View PR using the GUI difftool:
$ git pr show -t 26858

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26858.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 20, 2025

👋 Welcome back toxaart! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 20, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Aug 20, 2025

@toxaart The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@toxaart toxaart force-pushed the JDK-object-monitor-experiments-reconcile-enter-reenter-attempt5 branch 6 times, most recently from 54f64a0 to 8a0d56b Compare August 20, 2025 11:48
@toxaart toxaart force-pushed the JDK-object-monitor-experiments-reconcile-enter-reenter-attempt5 branch from 8a0d56b to bcea486 Compare August 20, 2025 14:10
@@ -1935,7 +1900,7 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
enter(current);
} else {
guarantee(v == ObjectWaiter::TS_ENTER, "invariant");
reenter_internal(current, &node);
enter_internal(current, &node, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enter_internal(current, &node, true);
enter_internal(current, &node, true /* do_reenter */);

Comment on lines +977 to +981
// As an aside, if were to ever rewrite the synchronization code mostly
// in Java, WaitNodes, ObjectMonitors, and Events would become 1st-class
// Java objects. This would avoid awkward lifecycle and liveness issues,
// as well as eliminate a subset of ABA issues.
// TODO: eliminate ObjectWaiter and enqueue either Threads or Events.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side issue: I think this commentary can be removed now.

@toxaart toxaart marked this pull request as ready for review August 21, 2025 12:20
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 21, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 21, 2025

Webrevs

@toxaart toxaart marked this pull request as draft August 21, 2025 12:29
@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants