-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8366024: Remove unnecessary InstanceKlass::cast() #26908
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
8366024: Remove unnecessary InstanceKlass::cast() #26908
Conversation
|
👋 Welcome back iklam! A progress list of the required criteria for merging this PR into |
|
@iklam 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 95 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 |
Webrevs
|
|
Not necessarily for this PR, but I nominate |
|
I found two more occurrences of casting super() to InstanceKlass: The first one ought perhaps to be using InstanceKlass::superklass()? |
| // Gets the fields of `klass` that are eliminated by escape analysis and need to be reassigned | ||
| static GrowableArray<ReassignedField>* get_reassigned_fields(InstanceKlass* klass, GrowableArray<ReassignedField>* fields, bool is_jvmci) { | ||
| InstanceKlass* super = klass->superklass(); | ||
| InstanceKlass* super = klass->java_super(); |
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.
What is wrong with using superklass() here? We already know that klass is an InstanceKlass* so we don't need to make a virtual call to java_super().
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.
I got rid of superklass() because it was yet another way of looking for a "super" that has no documentation.
In this particular case, the cost of a virtual code will be negligible compared to what happens in the following loop.
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.
This looks good. We've had several passes of narrowing the Klass types to InstanceKlass so thank you for doing this one. super() is tricky because of array covariance in subtype checking. I don't see that this affects that code.
Thank @adinn for finding more.
I fixed this one with
Here we have the same logic as in the (removed) |
|
FWIW |
I have filed JDK-8366417 - jfieldIDWorkaround should use InstanceKlass* instead of Klass* |
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.
This seems fine though I will also comment that java_super seems completely mis-named in relation to super as there is nothing more Java about it. The implementation of java_super for arrays is quite odd - I'm not sure when we don't care about the actual superclass and want to go straight to object.
Thanks
|
Thanks @adinn @dholmes-ora @coleenp for the review |
|
Going to push as commit 2427c90.
Your commit was automatically rebased without conflicts. |
As we discussed offline, I will try to add a new |
We have a lot of
InstanceKlass::cast(k)calls wherekis statically known to be anInstanceKlass. I fixed many instances of this pattern:The
super()method has a very confusing API. It has the return type ofKlass*because for for anObjArrayKlasslike[Ljava/lang/String;:super()returns[Ljava/lang/Object;java_super()returnsLjava/lang/Object;However, for
[Ljava/lang/Object;, allTypeArrayKlassesand allInstanceKlasses,super()andjava_super()return an identical value of that always have the actual type ofInstanceKlass*.See here about the difference between
super()andjava_super():jdk/src/hotspot/share/oops/klass.hpp
Lines 218 to 221 in 7b9969d
Unfortunately, we have a lot of code that incorrectly uses
super()instead ofjava_super(), which leads toInstanceKlass::cast()calls. I tried to fixed a bunch of easy ones in this PR, although there are a few more to go.I also fixed some calls to
local_interafaces()->at()that widens the return type forInstanceKlass*toKlass*, which may lead to unnecessaryInstanceKlass::cast()calls.I also removed the
Klass::superklass()API. This was used only in a few places and all of them can be safely replaced withKlass::java_super().To avoid confusion, I think we should rename
super()to something more obvious, but let's do that in a future PR.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26908/head:pull/26908$ git checkout pull/26908Update a local copy of the PR:
$ git checkout pull/26908$ git pull https://git.openjdk.org/jdk.git pull/26908/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26908View PR using the GUI difftool:
$ git pr show -t 26908Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26908.diff
Using Webrev
Link to Webrev Comment