Skip to content

8365799: AArch64: Remove trailing DMB from cmpxchgptr for LSE #26845

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

spchee
Copy link
Contributor

@spchee spchee commented Aug 19, 2025

According to the Java SE 24 API, CompareAndExchange has the memory semantics as given by VarHandle.compareAndExchange, which has the following effects [1]:

Atomically sets the value of a variable to the newValue with the
memory semantics of setVolatile if the variable's current value,
referred to as the witness value, == the expectedValue, as accessed
with the memory semantics of getVolatile.

Thus, the store-release due to setVolatile only occurs if the compare is successful. Since CASAL already satisfies these requirements, the DMB does not need to occur to ensure memory ordering in case the compare fails and a store-release does not happen.

Therefore, we can remove the DMB from cmpxchgptr when LSE is enabled. We also rename it to cmpxchgptr_barrier to indicate that this method provides trailing barrier semantics (via either LSE CASAL or a DMB).

The unused cmpxchgw is removed.

[1] https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/invoke/VarHandle.html#compareAndExchange(java.lang.Object...)


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-8365799: AArch64: Remove trailing DMB from cmpxchgptr for LSE (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26845

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 19, 2025

👋 Welcome back spchee! 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.

According to the Java SE 24 API, CompareAndExchange has the
memory semantics as given by VarHandle.compareAndExchange, which has
the following effects [1]:

> Atomically sets the value of a variable to the newValue with the
> memory semantics of setVolatile if the variable's current value,
> referred to as the witness value, == the expectedValue, as accessed
> with the memory semantics of getVolatile.

Thus, the store-release due to setVolatile only occurs if
the compare is successful. Since CASAL already satisfies these
requirements, the DMB does not need to occur to ensure memory ordering
in case the compare fails and a store-release does not happen.

Therefore, we can remove the DMB from cmpxchgptr when LSE
is enabled. We also rename it to cmpxchgptr_barrier to indicate that
this method provides trailing barrier semantics (via either LSE
CASAL or a DMB).

The unused cmpxchgw is removed.

[1] https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/invoke/VarHandle.html#compareAndExchange(java.lang.Object...)

Change-Id: I45b26bdd75f931ecdb436d34f24ed91de0ac31c2
@openjdk
Copy link

openjdk bot commented Aug 19, 2025

@spchee This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8365799: AArch64: Remove trailing DMB from cmpxchgptr for LSE

Reviewed-by: aph

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 21 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@theRealAph) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Aug 19, 2025

@spchee Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@openjdk
Copy link

openjdk bot commented Aug 19, 2025

@spchee this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout cmpxchgw_dmb
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@spchee
Copy link
Contributor Author

spchee commented Aug 19, 2025

Tested and passes jcstress.

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Aug 19, 2025
@openjdk
Copy link

openjdk bot commented Aug 19, 2025

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

  • hotspot

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.

@openjdk openjdk bot added rfr Pull request is ready for review and removed merge-conflict Pull request has merge conflict with target branch labels Aug 19, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 19, 2025

Webrevs

@spchee
Copy link
Contributor Author

spchee commented Aug 19, 2025

Ok looks like there are some very recent changes to the relevant files since I last touched it. Need to fix my merge-conflict and have a look at whats changed.

Change-Id: I74d44f711de208395bce47595fecd801564bcb54
@spchee
Copy link
Contributor Author

spchee commented Aug 19, 2025

Have fixed :)

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 20, 2025
@dholmes-ora
Copy link
Member

Not sure why you are using the specification for the Java API cmpxchg function to determine what the MacroAssembler function does?? Is this the intrinsic for the Java code?

@spchee
Copy link
Contributor Author

spchee commented Aug 20, 2025

You're right, it is a little inaccurate to use the Java API to determine what cmpxchgptr does. Although the original intent to remove the membar is still functionality correct.

Although looking into it more, it seems that cmpxchgptr can now be removed completely. The recent PR #26594 removed two of its call sites, and the only other existing one is within MacroAssembler::cmpxchg_obj_header - a method which never gets called to.

So I propose:

  • We close this pr
  • Open new one which removes the methods MacroAssembler::cmpxchg_obj_header, MacroAssembler::cmpxchgptr and MacroAssembler::cmpxchgw completely since they are no longer called to from anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants