-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8330681: Explicit hashCode and equals for java.lang.runtime.SwitchBootstraps$TypePairs #18865
Conversation
👋 Welcome back redestad! A progress list of the required criteria for merging this PR into |
@cl4es 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:
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 13 new commits pushed to the
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
|
||
public boolean equals(Object other) { | ||
if (other instanceof TypePairs otherPair) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match the behaviour of the equals
method body generated by java.lang.runtime.ObjectMethods::bootstrap
, this should include a fast path check for this == other
:
if (other instanceof TypePairs otherPair) { | |
if (this == other) { | |
return true; | |
} | |
if (other instanceof TypePairs otherPair) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, see https://www.youtube.com/watch?v=kuzjX_efuDs; this fast path is faster for == matching case but significantly slows down all other branches.
@@ -684,13 +681,27 @@ else if (selectorType.equals(targetType) || | |||
|
|||
// TypePairs should be in sync with the corresponding record in Lower | |||
record TypePairs(Class<?> from, Class<?> to) { | |||
|
|||
private static final Map<TypePairs, String> typePairToName = initialize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If TypePairs.typePairToName
is never modified after initialisation, then it should probably be made immutable:
private static final Map<TypePairs, String> typePairToName = initialize(); | |
private static final Map<TypePairs, String> typePairToName = Map.copyOf(initialize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you really think about it, the initialize
method itself is somewhat problematic, as it's initializing with byte/short/char on the left, all of which are already converted to int in the of() factory. This should be done in a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the "redirected" mappings can simply be removed in the current implementation.
Using Map.copyOf
should be ok to nail down the read-only intent.
/integrate |
Going to push as commit 3d62bbf.
Your commit was automatically rebased without conflicts. |
We can reduce overhead of first use of a switch bootstrap by moving
typePairToName
intoTypePairs
and by explicitly overridinghashCode
andequals
. The first change avoids loading and initializing theTypePairs
class in actual cases, the second remove some excess code generation from happening on first use.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18865/head:pull/18865
$ git checkout pull/18865
Update a local copy of the PR:
$ git checkout pull/18865
$ git pull https://git.openjdk.org/jdk.git pull/18865/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18865
View PR using the GUI difftool:
$ git pr show -t 18865
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18865.diff
Webrev
Link to Webrev Comment