Skip to content

Conversation

@iwanowww
Copy link
Contributor

@iwanowww iwanowww commented Sep 12, 2025

As part of JDK-8353786, C2 support for operations backed by the vector math library was completely removed. On JDK side, there is a special dispatching logic added to avoid intrinsic calls in jdk.internal.vm.vector.VectorSupport. But it's still possible to observe such paradoxical situations (intrinsic calls with obsolete operation IDs) when processing effectively dead code.

Consider FloatVector::lanewiseTemplate:

    FloatVector lanewiseTemplate(VectorOperators.Unary op) {
        if (opKind(op, VO_SPECIAL)) {
            ...                             
            else if (opKind(op, VO_MATHLIB)) {
                return unaryMathOp(op);
            }
        }
        int opc = opCode(op);
        return VectorSupport.unaryOp(opc, ...);
    }

At runtime, unaryMathOp is unconditionally invoked, but during compilation it's possible to end up with an intrinsification attempt of VectorSupport.unaryOp() before opKind(op, VO_SPECIAL) is inlined.

It can be reliably reproduced -XX:+StressIncrementalInlining flag.

The fix is to fail-fast intrinsification rather than crashing the VM.

Testing: tier1 - tier4


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-8367333: C2: Vector math operation intrinsification failure (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27263

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 12, 2025

👋 Welcome back vlivanov! 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 Sep 12, 2025

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

8367333: C2: Vector math operation intrinsification failure

Reviewed-by: epeter, shade, jbhateja

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 42 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.

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

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Sep 12, 2025
@openjdk
Copy link

openjdk bot commented Sep 12, 2025

@iwanowww
The hotspot-compiler label was successfully added.

@iwanowww iwanowww marked this pull request as ready for review September 12, 2025 20:49
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 12, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 12, 2025

Webrevs

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks reasonable! Thanks.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 15, 2025
Copy link
Member

@jatin-bhateja jatin-bhateja left a comment

Choose a reason for hiding this comment

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

LGTM

Best Regards

Comment on lines 39 to 40
* -XX:+StressIncrementalInlining
* compiler.vectorapi.TestVectorMathLib
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
* -XX:+StressIncrementalInlining
* compiler.vectorapi.TestVectorMathLib
* -XX:+StressIncrementalInlining compiler.vectorapi.TestVectorMathLib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fixed. I prefer to keep test class name on a separate line.

/*
* @test
* @bug 8367333
* @requires vm.compiler2.enabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need this @requires? It might be nice to be able to run this with other compilers too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's intended as C2-specific regression test and it relies on C2-specific VM flags. Vector API unit tests (under test/jdk/jdk/incubator/vector/) exercise the very same functionality, but don't specify flags required to trigger the bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

I leave it up to you. You can always ignore unrecognized flags. And tests tend to diverge over time, so maybe a little duplication would not hurt. But up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

And if it is a duplication, you should probably leave a comment linking it to the other one.
Also: why not just add the extra run over at the original test?

Copy link
Contributor Author

@iwanowww iwanowww Sep 17, 2025

Choose a reason for hiding this comment

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

Also: why not just add the extra run over at the original test?

test/jdk/jdk/incubator/vector/*VectorTests.java are huge and already override default timeout setting. But running them with -XX:+StressIncrementalInlining does make some sense. (Maybe not by default, but as part of some stress testing configuration we have.)

Comment on lines 37 to 40
* @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=quiet
* -XX:CompileCommand=compileonly,compiler.vectorapi.TestVectorMathLib::test*
* -XX:+StressIncrementalInlining
* compiler.vectorapi.TestVectorMathLib
Copy link
Contributor

Choose a reason for hiding this comment

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

Like @jatin-bhateja mentioned: alignment is off.
I'd also like to see a run without flags, maybe with only -XX:CompileCommand=compileonly,compiler.vectorapi.TestVectorMathLib::test*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, IMO it doesn't make sense to run the regression test without stressing incremental inlining. Otherwise, it duplicates existing tests.

Copy link
Contributor Author

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

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

Thanks for the reviews.

/*
* @test
* @bug 8367333
* @requires vm.compiler2.enabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's intended as C2-specific regression test and it relies on C2-specific VM flags. Vector API unit tests (under test/jdk/jdk/incubator/vector/) exercise the very same functionality, but don't specify flags required to trigger the bug.

Comment on lines 37 to 40
* @run main/othervm -Xbatch -XX:-TieredCompilation -XX:CompileCommand=quiet
* -XX:CompileCommand=compileonly,compiler.vectorapi.TestVectorMathLib::test*
* -XX:+StressIncrementalInlining
* compiler.vectorapi.TestVectorMathLib
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, IMO it doesn't make sense to run the regression test without stressing incremental inlining. Otherwise, it duplicates existing tests.

Comment on lines 39 to 40
* -XX:+StressIncrementalInlining
* compiler.vectorapi.TestVectorMathLib
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fixed. I prefer to keep test class name on a separate line.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 16, 2025
Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

I leave it up to you with the @requires. I was wondering why not just add the extra run with special flags to the original test? But I don't want to hold up the PR, so up to you ;)

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 17, 2025
@iwanowww
Copy link
Contributor Author

Thanks for the reviews, Aleksey, Jatin, and Emanuel.

/integrate

@openjdk
Copy link

openjdk bot commented Sep 17, 2025

Going to push as commit aa36799.
Since your change was applied there have been 65 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 Sep 17, 2025
@openjdk openjdk bot closed this Sep 17, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 17, 2025
@openjdk
Copy link

openjdk bot commented Sep 17, 2025

@iwanowww Pushed as commit aa36799.

💡 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.

4 participants