Skip to content
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

8282322: AArch64: Provide a means to eliminate all STREX family of instructions #8779

Closed
wants to merge 11 commits into from

Conversation

dchuyko
Copy link
Member

@dchuyko dchuyko commented May 18, 2022

On AArch64 it is sometimes convenient to have LSE atomics right from the start. Currently they are enabled after feature detection and RR reverse debugger works incorrectly.

New build configuration feature 'hardlse' is added. If it is enabled for aarch64 type of build, then statically compiled stubs replace the initial pessimistic implementation and dynamically generated replacements (when LSE support is detected). The feature works for builds of all debug levels.

New file atomic_linux_aarch64_lse.S is derived from atomic_linux_aarch64.S and inherits its copyright. This alternative static implementation corresponds to the dynamically generated code.

Note, this configuration part is necessary but not sufficient to fully avoid strex instructions for practical purposes. Other parts are:

  • Run on the OS built without strex family instructions. E.g. Amazon Linux 2022.
  • Compile with outline atomics enabled and the configuration flag enabled. E.g. configure with
    --with-extra-cflags='-march=armv8.3-a+crc+crypto -moutline-atomics' --with-extra-cxxflags='-march=armv8.3-a+crc+crypto -moutline-atomics' --with-extra-ldflags='-Wl,--allow-multiple-definition' --with-jvm-features=hardlse

Testing: tier1, tier2 on linux-aarch64 release builds with feature off and feature on.


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-8282322: AArch64: Provide a means to eliminate all STREX family of instructions

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8779

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 18, 2022

👋 Welcome back dchuyko! 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 openjdk bot changed the title JDK-8282322 8282322: AArch64: Provide a means to eliminate all STREX family of instructions May 18, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label May 18, 2022
@openjdk
Copy link

openjdk bot commented May 18, 2022

@dchuyko The following labels will be automatically applied to this pull request:

  • build
  • hotspot

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

@openjdk openjdk bot added build build-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels May 18, 2022
@mlbridge
Copy link

mlbridge bot commented May 18, 2022

@theRealAph
Copy link
Contributor

This looks reasonable enough, but I take it that this would create an OpenJDK build that would not run on AArch64 systems without LSE instructions. Might it not be a better idea to build with outline-atomics, and use them in OpenJDK? That would also solve your problem, and we wouldn't have AArch64 Linux OpenJDK binaries which don't work on all systems.

Note that atomic_bsd_aarch64.hpp already does this.

I'm also concerned about code rot with options like this one. atomic_linux_aarch64_lse.S would not be tested in any standard configuration.

@theRealAph
Copy link
Contributor

This looks reasonable enough, but I take it that this would create an OpenJDK build that would not run on AArch64 systems without LSE instructions.

Forget that, we already do so with extra-cflags.

@nick-arm
Copy link
Contributor

What's the advantage of defining the new hardlse VM feature over using the existing __ARM_FEATURE_ATOMICS preprocessor symbol? Both GCC and Clang will define that with an appropriate -march value, which you're passing to configure anyway. You could then conditionally emit the LSE instructions in atomic_linux_aarch64.S based on that.

@theRealAph
Copy link
Contributor

There is another way to achieve what you want, which is less disruptive and I believe more useful.

I just did this:

cp src/hotspot/os_cpu/bsd_aarch64/atomic_bsd_aarch64.hpp src/hotspot/os_cpu/linux_aarch64/atomic_linux_aarch64.hpp

and built OpenJDK with your configury, and it achieves exactly what you want: a HotSpot that uses LSE throughout. If you, therefore, add an option to build with host compiler's atomics, just like BSD does, you'll get what you need with almost no code changes.

@theRealAph
Copy link
Contributor

What's the advantage of defining the new hardlse VM feature over using the existing __ARM_FEATURE_ATOMICS preprocessor symbol? Both GCC and Clang will define that with an appropriate -march value, which you're passing to configure anyway. You could then conditionally emit the LSE instructions in atomic_linux_aarch64.S based on that.

That's not a bad idea either. In fact, maybe I prefer it to my own suggestion.

@dchuyko
Copy link
Member Author

dchuyko commented May 19, 2022

Thanks a lot for the great comments. Both suggestions make sense to me. The resulting code can be driven by the compiler flags in the configuration.

As I see it:

  1. To have a single compile time implementation based on __atomic_add_fetch intrinsics (no .S file at all).
  2. In generated part wrap put 'if (UseLSE)' blocks under '#ifdef __ARM_FEATURE_ATOMICS'.

Some concerns:

  1. It should work at least for Clang and GCC but still will require checking all os-cpu/compiler variants.
  2. Windows-aarch64 is the most worrisome.
  3. The way of configuration is different for different compilers, not a problem though if we need an optimized build or to make rr work.

@theRealAph
Copy link
Contributor

theRealAph commented May 19, 2022

I literally just tried this:


        .text

#ifdef __ARM_FEATURE_ATOMICS

        .globl aarch64_atomic_fetch_add_8_default_impl
        .align 5
aarch64_atomic_fetch_add_8_default_impl:
        prfm    pstl1strm, [x0]
0:      ldaddal x1, x2, [x0]
        dmb     ish
        mov     x0, x2

with the obvious #else and #endif around the non-LSE part

and

$ objdump -d /home/aph/theRealAph-jdk/build/linux-aarch64-server-slowdebug/hotspot/variant-server/libjvm/objs/atomic_linux_aarch64.o | head -40

/home/aph/theRealAph-jdk/build/linux-aarch64-server-slowdebug/hotspot/variant-server/libjvm/objs/atomic_linux_aarch64.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <aarch64_atomic_fetch_add_8_default_impl>:
   0:	f9800011 	prfm	pstl1strm, [x0]
   4:	f8e10002 	ldaddal	x1, x2, [x0]
   8:	d5033bbf 	dmb	ish
   c:	aa0203e0 	mov	x0, x2
  10:	d65f03c0 	ret

@theRealAph

This comment was marked as outdated.

@theRealAph
Copy link
Contributor

Some concerns:

1. It should work at least for Clang and GCC but still will require checking all os-cpu/compiler variants.

Non-Linux systems don't use this stuff at all, so don't worry about it.

Copy link
Member

@magicus magicus left a comment

Choose a reason for hiding this comment

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

Configure files need a bit more work.

make/autoconf/jvm-features.m4 Outdated Show resolved Hide resolved
make/autoconf/jvm-features.m4 Outdated Show resolved Hide resolved
@dchuyko
Copy link
Member Author

dchuyko commented May 23, 2022

New variant turns on using LSE atomics statically when __ARM_FEATURE_ATOMICS compiler feature is on. Prefetch is left only to non-LSE case, the kernel seems to do the same.

@magicus
Copy link
Member

magicus commented May 23, 2022

/label -build

@openjdk openjdk bot removed the build build-dev@openjdk.org label May 23, 2022
@openjdk
Copy link

openjdk bot commented May 23, 2022

@magicus
The build label was successfully removed.

Copy link
Contributor

@nick-arm nick-arm left a comment

Choose a reason for hiding this comment

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

Looks OK to me.

@openjdk
Copy link

openjdk bot commented Jun 9, 2022

@dchuyko 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:

8282322: AArch64: Provide a means to eliminate all STREX family of instructions

Reviewed-by: ngasson, 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 261 new commits pushed to the master branch:

  • 1fec62f: 8289710: Move Suspend/Resume classes out of os.hpp
  • 01b9f95: Merge
  • 3212dc9: 8289486: Improve XSLT XPath operators count efficiency
  • a8eb728: 8289779: Map::replaceAll javadoc has redundant @throws clauses
  • 889150b: 8289558: Need spec clarification of j.l.foreign.*Layout
  • 8dd94a2: 8289196: Pattern domination not working properly for record patterns
  • 8f24d25: 6509045: {@inheritdoc} only copies one instance of the specified exception
  • 9a0fa82: 8288949: serviceability/jvmti/vthread/ContStackDepthTest/ContStackDepthTest.java failing
  • 55fa19b: 8289857: ProblemList jdk/jfr/event/runtime/TestActiveSettingEvent.java
  • 32b650c: 8289840: ProblemList vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java when run with vthread wrapper
  • ... and 251 more: https://git.openjdk.org/jdk/compare/47b86690b6672301aa46d4a7b9ced58d17047cc7...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 9, 2022
@theRealAph
Copy link
Contributor

Is this dead, or... ?

@phohensee
Copy link
Member

Andrew, looks like Dima will be good to go once you re-review it.

@dchuyko
Copy link
Member Author

dchuyko commented Jul 7, 2022

@theRealAph I have made the latest edits as per your comments and they are pending review.

@theRealAph
Copy link
Contributor

Andrew, looks like Dima will be good to go once you re-review it.

Fine by me, but note where we are in rampdown.

@dchuyko
Copy link
Member Author

dchuyko commented Jul 8, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Jul 8, 2022

Going to push as commit a13af65.
Since your change was applied there have been 264 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 8, 2022
@openjdk openjdk bot closed this Jul 8, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 8, 2022
@openjdk
Copy link

openjdk bot commented Jul 8, 2022

@dchuyko Pushed as commit a13af65.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@dchuyko
Copy link
Member Author

dchuyko commented Jul 8, 2022

Andrew, thanks for taking a look. This change is now for the master, later we can also consider update releases.

@theRealAph
Copy link
Contributor

Andrew, thanks for taking a look. This change is now for the master, later we can also consider update releases.

You'll have to take your chances with that. I'm not sure that it qualifies for a backport under any of the usual criteria, but we can discuss that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants