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

8276215: Intrinsics matchers should handle native method flags better #6187

Conversation

shipilev
Copy link
Contributor

@shipilev shipilev commented Nov 1, 2021

Found this while working on JDK-8276096. It seems when the actual method is native, F_R (regular) intrinsic definition still matches. I believe that happens because flag matchers check for native flags only optionally. It would be better to implement this more consistently. This requires a few simple adjustments to current intrinsics definitions. #6184 handled a larger StrictMath oddity.

Additional testing:

  • Linux x86_64 fastdebug tier1
  • Linux x86_64 fastdebug tier2
  • Linux x86_64 fastdebug applications/ctw/modules (which has a nice side-effect of touching a lot of JDK methods)

Progress

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

Issue

  • JDK-8276215: Intrinsics matchers should handle native method flags better

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6187

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper 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.

@shipilev shipilev changed the title 8276215: VmIntrinsics matchers mishandle the native method flags 8276215: VmIntrinsics matchers should handle native method flags better Nov 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Nov 1, 2021

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

  • hotspot-runtime

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-runtime label Nov 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Nov 4, 2021

@shipilev 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 JDK-8276215-intrinsic-matchers-native
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict label Nov 4, 2021
@shipilev shipilev changed the title 8276215: VmIntrinsics matchers should handle native method flags better 8276215: Intrinsics matchers should handle native method flags better Nov 4, 2021
@shipilev shipilev force-pushed the JDK-8276215-intrinsic-matchers-native branch from e207924 to 878c7e0 Compare Nov 4, 2021
@openjdk openjdk bot removed the merge-conflict label Nov 4, 2021
@shipilev shipilev marked this pull request as ready for review Nov 4, 2021
@openjdk openjdk bot added the rfr label Nov 4, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Nov 4, 2021

Webrevs

@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Nov 9, 2021

No takers? :)

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Nov 9, 2021

I find it very hard to evaluate this without understanding why ?native was used in the first place. It seems to indicate "could be native, don't care either way" and now we want a firm is_native or is_not_native. The implications of this are unclear to me.

David

@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Nov 9, 2021

I find it very hard to evaluate this without understanding why ?native was used in the first place. It seems to indicate "could be native, don't care either way" and now we want a firm is_native or is_not_native. The implications of this are unclear to me.

As far as I can see, this predates OpenJDK history. I suspect ?native was a matter of "convenience". I'd further suspect the JDK/VM split we had a long time ago does not help with coordinated JDK+VM changes when intrinsified method nativeness changed.

But that convenience came with at least two problems: a) you would have to remember this is optional during the reviews, otherwise it leads to questions; b) you would sometimes care whether the method is native or not, for example when cobbling together intrinsics against native and non-native methods, for example in StrictMath.

Tracking the native-ness more strictly makes it safer too: if we ever change a intrinsified method native-ness, CheckIntrinsics would now barf, prompting us to re-evaluate the handling of those intrinsics in interpreter/C1/C2, looking whether such change would be safe. In other words, stronger enforcement of native-ness for intrinsics methods means safer coding.

@vnkozlov
Copy link
Contributor

@vnkozlov vnkozlov commented Nov 9, 2021

I am for more strict checks proposed here.

?native comment was added by Tom for JDK-6892658
https://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/rev/7c57aead6d3e#l8.72

Originally runtime code looked for intrinsic per method and it did not check for native because we did not have many intrinsics at that timeI think:

    // Special case the sqrt function because the Math and StrictMath versions are identical for all cases
    // This allows the hardware to be used for all sqrt implementations
 } else if ((klass_name == vmSymbols::java_lang_Math() || klass_name == vmSymbols::java_lang_StrictMath()) &&
             name() == vmSymbols::java_lang_Math_sqrt_name() && is_static() && !is_synchronized()) {
    if (signature() == vmSymbols::java_lang_Math_sqrt_signature()) return vmIntrinsics::_dsqrt;

@rose00 re-wrote it into current macro form but kept not checking native:

^Ac 6525802, 6428387 Add intrinsics for reflections, data motion, etc.
^Ac Refactor intrinsic specifications for maintainability and verifiability.
^Ac Intrinsic identification is now the job of class vmIntrinsics, not methodOop.
^Ac Remove x_obj32 variants of sun.misc.Unsafe intrinsics (obsolete since 1.4.1).
^Ac Add query accessors symbol_at, find_sid, name_at, find_id, etc.
^Ac StressReflectiveCode supports stress testing.

inline bool match_F_S(jshort flags) {
  const int req = JVM_ACC_STATIC;
  const int neg = JVM_ACC_SYNCHRONIZED;
  return (flags & (req | neg)) == req;
}

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Okay - if @vnkozlov is okay with this then I am okay with it.

Thanks,
David

@openjdk
Copy link

@openjdk openjdk bot commented Nov 10, 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:

8276215: Intrinsics matchers should handle native method flags better

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

  • e91e9d8: 8276721: G1: Refine G1EvacFailureObjectsSet::iterate
  • 8822d41: 8274736: Concurrent read/close of SSLSockets causes SSLSessions to be invalidated unnecessarily
  • c1e41fe: 8276842: G1: Only calculate size in bytes from words when needed
  • c8b0ee6: 8276833: G1: Make G1EvacFailureRegions::par_iterate const
  • 0699220: 8268882: C2: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
  • d7012fb: 8276880: Remove java/lang/RuntimeTests/exec/ExecWithDir as unnecessary
  • f9024d0: 8230130: javadoc search result dialog shows cut off headers for long results
  • 055de6f: 8223358: Incorrect HTML structure in annotation pages
  • a60e912: 8198626: java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html fails on mac
  • dde959d: 8276808: java/nio/channels/Channels/TransferTo.java timed out
  • ... and 76 more: https://git.openjdk.java.net/jdk/compare/9eadcbb47e902f42d933ba68e24f2bfb0ee20915...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 label Nov 10, 2021
@shipilev
Copy link
Contributor Author

@shipilev shipilev commented Nov 10, 2021

I have merged from recent master locally to check that no conflicting intrinsics have appeared meanwhile. Looks clean. I shall be integrating this change then.

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Nov 10, 2021

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

  • 0f463a7: 8276845: (fs) java/nio/file/spi/SetDefaultProvider.java fails on x86_32
  • e01d6d0: 8276679: Malformed Javadoc inline tags in JDK source in javax/swing
  • fd0a25e: 8276805: java/awt/print/PrinterJob/CheckPrivilege.java fails due to disabled SecurityManager
  • 403f318: 8276854: Windows GHA builds fail due to broken Cygwin
  • e91e9d8: 8276721: G1: Refine G1EvacFailureObjectsSet::iterate
  • 8822d41: 8274736: Concurrent read/close of SSLSockets causes SSLSessions to be invalidated unnecessarily
  • c1e41fe: 8276842: G1: Only calculate size in bytes from words when needed
  • c8b0ee6: 8276833: G1: Make G1EvacFailureRegions::par_iterate const
  • 0699220: 8268882: C2: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
  • d7012fb: 8276880: Remove java/lang/RuntimeTests/exec/ExecWithDir as unnecessary
  • ... and 80 more: https://git.openjdk.java.net/jdk/compare/9eadcbb47e902f42d933ba68e24f2bfb0ee20915...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Nov 10, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Nov 10, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Nov 10, 2021

@shipilev Pushed as commit a3f710e.

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

@shipilev shipilev deleted the JDK-8276215-intrinsic-matchers-native branch Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime integrated
3 participants