-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8366584: Add an InstanceKlass::super() method that returns InstanceKlass* #27037
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
8366584: Add an InstanceKlass::super() method that returns InstanceKlass* #27037
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 58 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
|
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! Great to see all those java_super()
calls disappear. A couple of nits/comments.
Thanks
Klass* super = ((InstanceKlass*)cie->klass())->java_super(); | ||
InstanceKlass* super = InstanceKlass::cast(cie->klass())->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.
Pre-existing, but if this cast is safe then KlassInfoEntry::_klass
should be declared InstanceKlass
. Otherwise this cast is not safe! Separate RFE for that.
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 looked at the KlassHierarchy
code and it looks at only instance klasses.
jdk/src/hotspot/share/memory/heapInspection.cpp
Lines 318 to 319 in 80fb708
if (cie->klass()->is_instance_klass()) { | |
_elements->append(cie); |
I added an assert to make this more apparent.
The KlassInfoEntry
is used by other code that could sometimes store a non-instance klass. I'll leave it as is for now.
// This shadows Klass::super(). The _super of an InstanceKlass is | ||
// always an InstanceKlass (or nullptr) | ||
InstanceKlass* super() const { | ||
return (Klass::super() == nullptr) ? nullptr : InstanceKlass::cast(Klass::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.
Is it better/simpler/cleaner to just do:
return static_cast<InstanceKlass*>(Klass::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 think the term is "hides" not "shadows". InstanceKlass::cast() is better - one additional check that super is always another InstanceKlass.
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.
Do we still need 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.
There are a few places that use it. Maybe we should look at these again in the future.
compiler dependencies:
./share/code/dependencies.cpp: for (InstanceKlass* super = k->java_super(); super != nullptr; super = super->java_super()) {
./share/code/dependencies.cpp: _klass = _klass->java_super();
subklass and sibling:
./share/oops/instanceKlass.cpp: _current = _current->java_super(); // backtrack; no more sibling subclasses left
./share/oops/klass.cpp: InstanceKlass* super = java_super();
./share/oops/klass.cpp: && (super->java_super() == nullptr || !is_interface())),
Some general cases where you have a Klass but wants same super as in java.lang.Class::getSuperClass
./share/oops/klassVtable.cpp: InstanceKlass* super = _klass->java_super();
./share/prims/jni.cpp: // Rules of Class.getSuperClass as implemented by KLass::java_super:
./share/prims/jni.cpp: Klass* super = k->java_super();
./share/prims/jni.cpp: "java_super computation depends on interface, array, other super");
./share/services/heapDumper.cpp: InstanceKlass* java_super = k->java_super();
./share/services/heapDumper.cpp: assert(java_super != nullptr, "checking");
./share/services/heapDumper.cpp: writer->write_classID(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 changed to hides
. There are mentions of both shadows
and hides
in our comments.
@@ -1571,7 +1571,7 @@ void klassVtable::verify(outputStream* st, bool forced) { | |||
// verify consistency with superKlass vtable | |||
Klass* super = _klass->super(); | |||
if (super != nullptr) { | |||
InstanceKlass* sk = InstanceKlass::cast(super); | |||
InstanceKlass* sk = InstanceKlass::cast(super); // why are we sure this is InstanceKlass?? |
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 don't think it is guaranteed to be an IK. But AFAICS we don't actually need an IK here anyway, we should be able to use super
directly.
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.
Fixed.
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. This will help with InstanceKlass casting.
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.
Updates look good. Thanks
Thanks @coleenp @dholmes-ora for the review |
Going to push as commit f4d73d2.
Your commit was automatically rebased without conflicts. |
By adding an
InstanceKlass* InstanceKlass::super()
method to shadowKlass* Klass:super()
, this PR makes it possible to simplify the following codeto
So you no longer need to do casting or need to understand what
java_super()
is.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27037/head:pull/27037
$ git checkout pull/27037
Update a local copy of the PR:
$ git checkout pull/27037
$ git pull https://git.openjdk.org/jdk.git pull/27037/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27037
View PR using the GUI difftool:
$ git pr show -t 27037
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27037.diff
Using Webrev
Link to Webrev Comment