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

8276217: Harmonize StrictMath intrinsics handling #6184

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented Nov 1, 2021

This blocks JDK-8276215: StrictMath intrinsics are handled peculiarly by giving failing intrinsics a second chance to match against the similar Math intrinsics. This has interesting consequence for matchers: we can match the native StrictMath.sqrt to non-native intrinsic for Math.sqrt. Interpreter would then have to disambiguate the two. It could be made simpler and more consistent.

For min/max methods, StrictMath already delegates to Math methods, so we can just drop the intrinsics for them. sqrt is harder to delegate, because it is native and a part of public API, so we can instead do the proper special intrinsic for it.

There seem to be no performance regressions with this patch at least on Linux x86_64:

$ CONF=linux-x86_64-server-release make test TEST="micro:StrictMathBench" 

Benchmark                   Mode  Cnt       Score     Error   Units

### Before

StrictMathBench.minDouble  thrpt    4  230921.558 ± 234.238  ops/ms
StrictMathBench.minFloat   thrpt    4  230932.303 ± 126.721  ops/ms
StrictMathBench.minInt     thrpt    4  230917.256 ±  73.008  ops/ms
StrictMathBench.minLong    thrpt    4  194460.828 ± 178.079  ops/ms


StrictMathBench.maxDouble  thrpt    4  230983.180 ± 161.211  ops/ms
StrictMathBench.maxFloat   thrpt    4  230969.290 ± 277.500  ops/ms
StrictMathBench.maxInt     thrpt    4  231033.581 ± 200.015  ops/ms
StrictMathBench.maxLong    thrpt    4  194590.744 ± 114.295  ops/ms


StrictMathBench.sqrtDouble  thrpt    4  230722.037 ± 2222.080  ops/ms

### After

StrictMathBench.minDouble  thrpt    4  230976.625 ±  67.338  ops/ms
StrictMathBench.minFloat   thrpt    4  230896.021 ± 270.434  ops/ms
StrictMathBench.minInt     thrpt    4  230859.741 ± 403.147  ops/ms
StrictMathBench.minLong    thrpt    4  194456.673 ± 111.557  ops/ms

StrictMathBench.maxDouble  thrpt    4  230890.776 ±  89.924  ops/ms
StrictMathBench.maxFloat   thrpt    4  230918.334 ±  63.160  ops/ms
StrictMathBench.maxInt     thrpt    4  231059.128 ±  51.224  ops/ms
StrictMathBench.maxLong    thrpt    4  194488.210 ± 495.224  ops/ms

StrictMathBench.sqrtDouble  thrpt    4  231023.703 ± 247.330  ops/ms

Additional testing:

  • StrictMath benchmarks
  • Linux x86_64 fastdebug java/lang/StrictMath, java/lang/Math
  • Linux x86_64 fastdebug tier1

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8276217: Harmonize StrictMath intrinsics handling

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6184/head:pull/6184
$ git checkout pull/6184

Update a local copy of the PR:
$ git checkout pull/6184
$ git pull https://git.openjdk.java.net/jdk pull/6184/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6184

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6184.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 1, 2021

👋 Welcome back shade! 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 Nov 1, 2021

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

  • core-libs
  • 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 hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Nov 1, 2021
@shipilev shipilev marked this pull request as ready for review Nov 1, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 1, 2021
@mlbridge
Copy link

mlbridge bot commented Nov 1, 2021

Webrevs

Copy link
Contributor

@theRealAph theRealAph left a comment

So we have _dsqrt and_dsqrt_strict, which must be functionally identical, but we provide both names because they're part of a public API. I think this deserves an explanatory comment in the code.

@shipilev
Copy link
Member Author

shipilev commented Nov 1, 2021

So we have _dsqrt and_dsqrt_strict, which must be functionally identical, but we provide both names because they're part of a public API. I think this deserves an explanatory comment in the code.

Yes, no problem, added comment near intrinsic definition.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Removing intrinsics for StrictMatch min/max methods may prevent them from inlining if they are not hot when caller is compiled.

@shipilev
Copy link
Member Author

shipilev commented Nov 1, 2021

Removing intrinsics for StrictMatch min/max methods may prevent them from inlining if they are not hot when caller is compiled.

Would you like me to leave them instead? That would mean we introduce these new intrinsic definitions:

  /* StrictMath intrinsics, similar to what we have in Math. */                                                         \
  do_intrinsic(_min_strict,               java_lang_StrictMath,   min_name,           int2_int_signature,        F_S)   \
  do_intrinsic(_max_strict,               java_lang_StrictMath,   max_name,           int2_int_signature,        F_S)   \
  do_intrinsic(_minF_strict,              java_lang_StrictMath,   min_name,           float2_float_signature,    F_S)   \
  do_intrinsic(_maxF_strict,              java_lang_StrictMath,   max_name,           float2_float_signature,    F_S)   \
  do_intrinsic(_minD_strict,              java_lang_StrictMath,   min_name,           double2_double_signature,  F_S)   \
  do_intrinsic(_maxD_strict,              java_lang_StrictMath,   max_name,           double2_double_signature,  F_S)   \
  /* Special flavor of dsqrt intrinsic to handle the "native" method in StrictMath. Otherwise the same as in Math. */   \
  do_intrinsic(_dsqrt_strict,             java_lang_StrictMath,   sqrt_name,          double_double_signature,   F_SN)  \

@vnkozlov
Copy link
Contributor

vnkozlov commented Nov 1, 2021

Yes, I am fine with new intrinsics for them.

@shipilev
Copy link
Member Author

shipilev commented Nov 2, 2021

Yes, I am fine with new intrinsics for them.

All right, see new commit then.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Good. Thank you for fixing it.

@openjdk
Copy link

openjdk bot commented Nov 2, 2021

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

8276217: Harmonize StrictMath intrinsics handling

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

  • 465d350: 8276157: C2: Compiler stack overflow during escape analysis on Linux x86_32
  • 7439b59: 8276044: ciReplay: C1 does not dump a replay file when using DumpReplay as compile command option
  • 87b926e: 8275086: compiler/c2/irTests/TestPostParseCallDevirtualization.java fails when compiler1 is disabled
  • 2b02b6f: 8274942: AssertionError at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
  • bb92fb0: 8274930: sun/tools/jps/TestJps.java can fail with long VM arguments string
  • 6a04899: 8275840: Add test to java/nio/channels/Channels/TransferTo.java to test transfer sizes > 2GB
  • 01105d6: 8276367: ProblemList vmTestbase/nsk/jvmti/RedefineClasses/StressRedefineWithoutBytecodeCorruption/TestDescription.java
  • 8fc16f1: 8275729: Qualified method names in CodeHeap Analytics
  • fa4ce82: 8276260: (se) Remove java/nio/channels/Selector/Wakeup.java from ProblemList (win)
  • 495c828: 8276188: Clarify "default charset" descriptions in String class
  • ... and 20 more: https://git.openjdk.java.net/jdk/compare/5bb1992b8408a0d196b1afa308bc00d007458dbd...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 Nov 2, 2021
@shipilev
Copy link
Member Author

shipilev commented Nov 3, 2021

Thanks! I re-ran the tests, they seem to be fine. I need a second (R)eviewer for this.

@shipilev
Copy link
Member Author

shipilev commented Nov 3, 2021

Thanks! I am going to push this tomorrow morning, if no other comments show up.

@shipilev
Copy link
Member Author

shipilev commented Nov 4, 2021

/integrate

@openjdk
Copy link

openjdk bot commented Nov 4, 2021

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

  • fb0be81: 8276096: Simplify Unsafe.{load|store}Fence fallbacks by delegating to fullFence
  • 558ee40: 8276615: Update CR number of some tests in ProblemList-zgc.txt
  • 603bba2: 8271420: Extend CDS custom loader support to Windows platform
  • ce8c767: 8276220: Reduce excessive allocations in DateTimeFormatter
  • 0ab910d: 8276066: Reset LoopPercentProfileLimit for x86 due to suboptimal performance
  • f3320d2: 8276588: Change "ccc" to "CSR" in HotSpot sources
  • 32895ac: 8275650: Problemlist java/io/File/createTempFile/SpecialTempFile.java for Windows 11
  • c7f070f: 8276208: vmTestbase/nsk/jdb/repeat/repeat001/repeat001.java fails with "AssertionError: Unexpected output"
  • 684edbb: 8273922: (fs) UserDefinedFileAttributeView doesn't handle file names that are just under the MAX_PATH limit (win)
  • 7115892: 8276401: Use blessed modifier order in java.net.http
  • ... and 37 more: https://git.openjdk.java.net/jdk/compare/5bb1992b8408a0d196b1afa308bc00d007458dbd...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Nov 4, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 4, 2021
@openjdk
Copy link

openjdk bot commented Nov 4, 2021

@shipilev Pushed as commit 9eadcbb.

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

@shipilev shipilev deleted the JDK-8276217-strictmath-handling branch Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
3 participants