Skip to content

Conversation

iklam
Copy link
Member

@iklam iklam commented Sep 2, 2025

By adding an InstanceKlass* InstanceKlass::super() method to shadow Klass* Klass:super(), this PR makes it possible to simplify the following code

InstanceKlass* ik;
InstanceKlass* s;
s = InstanceKlass::cast(ik->super()); // before JDK-8366024 
s = ik->java_super(); // after JDK-8366024 

to

s = k->super();

So you no longer need to do casting or need to understand what java_super() is.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8366584: Add an InstanceKlass::super() method that returns InstanceKlass* (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 2, 2025

👋 Welcome back iklam! 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 Sep 2, 2025

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

8366584: Add an InstanceKlass::super() method that returns InstanceKlass*

Reviewed-by: dholmes, coleenp

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 master branch:

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
Copy link

openjdk bot commented Sep 2, 2025

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

  • hotspot
  • serviceability

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.

@mlbridge
Copy link

mlbridge bot commented Sep 2, 2025

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a 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();
Copy link
Member

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.

Copy link
Member Author

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.

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());
Copy link
Member

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());

?

Copy link
Contributor

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.

Copy link
Contributor

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 ?

Copy link
Member Author

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);

Copy link
Member Author

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??
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@coleenp coleenp left a 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 3, 2025
Copy link
Member

@dholmes-ora dholmes-ora left a 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

@iklam
Copy link
Member Author

iklam commented Sep 4, 2025

Thanks @coleenp @dholmes-ora for the review
/integrate

@openjdk
Copy link

openjdk bot commented Sep 4, 2025

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 4, 2025
@openjdk openjdk bot closed this Sep 4, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 4, 2025
@openjdk
Copy link

openjdk bot commented Sep 4, 2025

@iklam Pushed as commit f4d73d2.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants