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

8328938: C2 SuperWord: disable vectorization for large stride and scale #18485

Closed
wants to merge 5 commits into from

Conversation

eme64
Copy link
Contributor

@eme64 eme64 commented Mar 26, 2024

Problem
In JDK-8310190 / https://git.openjdk.org/jdk/pull/14785 I fixed the alignment with AlignVector. For that, I had to compute abs(scale) and abs(stride), as well as scale * stride. The issue is that all of these values can overflow the int range (e.g. abs(min_int) = min_int).

We hit asserts like:

# assert(is_power_of_2(value)) failed: value must be a power of 2: 0xffffffff80000000
Happens because we take abs(min_int), which is min_int = 0x80000000, and assuming this was a positive (unsigned) number is a power of 2 2^31. We then expand it to long, get 0xffffffff80000000, which is not a power of 2 anymore. This violates the implicit assumptions, and we hit the assert.

# assert(q >= 1) failed: modulo value must be large enough
We have scale = 2^30 and stride = 4 = 2^2. For the alignment calculation we compute scale * stride = 2^32, which overflows the int range and becomes zero.

Before JDK-8310190 we could get similar issues with the (old) code in SuperWord::ref_is_alignable, if AlignVector is enabled:

int span = preloop_stride * p.scale_in_bytes();
...
if (vw % span == 0) {

if span == 0 because of overflow, then the idiv from the modulo gets a division by zero -> SIGFPE.

But it seems the bug is possibly a regression from JDK20 b2 JDK-8286197. Here we enabled certaint Unsafe memory access address patterns, and it is such patterns that the reproducer requires.

Solution
I could either patch up all the code that works with scale and stride, and make sure no overflows ever happen. But that is quite involved and error prone.

I now just disable vectorization for large scale and stride. This should not have any performance impact, because such large scale and stride would lead to highly inefficient memory accesses, since they are spaced very far apart.


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-8328938: C2 SuperWord: disable vectorization for large stride and scale (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18485

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 26, 2024

👋 Welcome back epeter! 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 Mar 26, 2024

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

8328938: C2 SuperWord: disable vectorization for large stride and scale

Reviewed-by: chagedorn, kvn

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 33 new commits pushed to the master branch:

  • 8020183: 8329470: Remove obsolete CDS SharedStrings tests
  • 8267d65: 8329564: [JVMCI] TranslatedException::debugPrintStackTrace does not work in the libjvmci compiler.
  • 16576b8: 8328957: Update PKCS11Test.java to not use hardcoded path
  • 375bfac: 8327474: Review use of java.io.tmpdir in jdk tests
  • 233619b: 8329557: Fix statement around MathContext.DECIMAL128 rounding
  • 023f7f1: 8320799: Bump minimum boot jdk to JDK 22
  • 8dc43aa: 8325217: MethodSymbol.getModifiers() returns SEALED for restricted methods
  • 1c69193: 8328383: Method is not used: com.sun.tools.javac.comp.Attr::thisSym
  • ee09801: 8328352: Serial: Inline SerialBlockOffsetSharedArray
  • bea493b: 8236736: Change notproduct JVM flags to develop flags
  • ... and 23 more: https://git.openjdk.org/jdk/compare/5cddc2de493d9d8712e4bee3aed4f1a0d4c228c3...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 changed the title 8328938 8328938: C2 SuperWord: disable vectorization for large stride and scale Mar 26, 2024
@openjdk
Copy link

openjdk bot commented Mar 26, 2024

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

  • hotspot-compiler

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 the hotspot-compiler hotspot-compiler-dev@openjdk.org label Mar 26, 2024
@eme64 eme64 marked this pull request as ready for review March 27, 2024 06:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 27, 2024
@mlbridge
Copy link

mlbridge bot commented Mar 27, 2024

Webrevs

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

I agree with that. That's a reasonable, safe and easy solution.

src/hotspot/share/opto/vectorization.cpp Outdated Show resolved Hide resolved
src/hotspot/share/opto/vectorization.cpp Outdated Show resolved Hide resolved
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 28, 2024
Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
@openjdk
Copy link

openjdk bot commented Apr 2, 2024

⚠️ @eme64 This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

if (abs(long_scale) >= max_val ||
abs(long_stride) >= max_val ||
abs(long_scale * long_stride) >= max_val) {
assert(!valid(), "adr stride*scale is too large");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you need assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you look a few lines up, you can see that all other "bailouts" also check that the VPointer is invalid. I am simply matching the surrounding code. And it also makes it explicit, that the VPointer will be invalid, which is what I want.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay

@eme64
Copy link
Contributor Author

eme64 commented Apr 4, 2024

@chhagedorn @vnkozlov thanks for the reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Apr 4, 2024

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

  • 4196688: 8329494: Serial: Merge GenMarkSweep into MarkSweep
  • 8020183: 8329470: Remove obsolete CDS SharedStrings tests
  • 8267d65: 8329564: [JVMCI] TranslatedException::debugPrintStackTrace does not work in the libjvmci compiler.
  • 16576b8: 8328957: Update PKCS11Test.java to not use hardcoded path
  • 375bfac: 8327474: Review use of java.io.tmpdir in jdk tests
  • 233619b: 8329557: Fix statement around MathContext.DECIMAL128 rounding
  • 023f7f1: 8320799: Bump minimum boot jdk to JDK 22
  • 8dc43aa: 8325217: MethodSymbol.getModifiers() returns SEALED for restricted methods
  • 1c69193: 8328383: Method is not used: com.sun.tools.javac.comp.Attr::thisSym
  • ee09801: 8328352: Serial: Inline SerialBlockOffsetSharedArray
  • ... and 24 more: https://git.openjdk.org/jdk/compare/5cddc2de493d9d8712e4bee3aed4f1a0d4c228c3...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Apr 4, 2024

@eme64 Pushed as commit 2931458.

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

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

Successfully merging this pull request may close these issues.

3 participants