Skip to content

Conversation

teshull
Copy link
Contributor

@teshull teshull commented May 28, 2025

Currently from ResolvedJavaType one can retrieve all declared methods, static methods, and constructors of the given type. However, internally in HotSpot there are also VM-internal methods, such as overpass methods, associated with a given type which we cannot access via the API.

To correct this, we should add a new method which enables VM-internal methods, such as overpass methods, to be accessed.


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-8357987: [JVMCI] Add support for retrieving all methods of a ResolvedJavaType (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25498/head:pull/25498
$ git checkout pull/25498

Update a local copy of the PR:
$ git checkout pull/25498
$ git pull https://git.openjdk.org/jdk.git pull/25498/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25498

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25498.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label May 28, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented May 28, 2025

Hi @teshull, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user teshull" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk
Copy link

openjdk bot commented May 28, 2025

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

8357987: [JVMCI] Add support for retrieving all methods of a ResolvedJavaType

Reviewed-by: dnsimon, yzheng, never

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 5 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dougxc, @mur47x111, @tkrodriguez) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented May 28, 2025

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

  • graal
  • hotspot-compiler

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.

@teshull
Copy link
Contributor Author

teshull commented May 28, 2025

/covered

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label May 28, 2025
@bridgekeeper
Copy link

bridgekeeper bot commented May 28, 2025

Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@teshull teshull changed the title 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType. 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType May 28, 2025
@openjdk openjdk bot changed the title 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType. May 28, 2025
if (isConstructor() || isStatic()) {
return false;
}
return !compilerToVM().isOverpass(this);
Copy link
Member

Choose a reason for hiding this comment

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

I think you can do this with a direct flag check:

boolean isOverpass = (getConstMethodFlags() & config().constMethodIsOverpass) != 0;
return isOverpass;

See #20256 as an example of the other changes needed for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call. changed

}

/**
* Returns a list containing all the non-static methods present within this type.
Copy link
Member

Choose a reason for hiding this comment

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

Point out that the returned list is unmodifiable (like the API for Stream.toList() does).

native ResolvedJavaMethod[] getDeclaredMethods(HotSpotResolvedObjectTypeImpl klass, long klassPointer);

/**
* Gets the {@link ResolvedJavaMethod}s for all instance methods of {@code klass}.
Copy link
Member

Choose a reason for hiding this comment

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

instance -> non-static
Instance -> NonStatic

Copy link
Contributor Author

@teshull teshull May 28, 2025

Choose a reason for hiding this comment

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

I realized NonStatic is not accurate - we return everything except <init>s and <clinit> - so I switched to NonInitializerMethods everywhere. Does that seem fair?

Copy link
Contributor Author

@teshull teshull May 29, 2025

Choose a reason for hiding this comment

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

thinking about it more, it's probably better if we do no filtering and return all methods in InstanceKlass->_methods. How about something like getAllMethods:

 /**
     * Returns a list containing all methods present within this type. This list can include
     * methods implicitly created and used by the VM.
     * The returned List is unmodifiable; calls to any mutator method
     * will always cause {@code UnsupportedOperationException} to be thrown.
     *
     * @param forceLink if {@code true}, forces this type to be {@link #link linked}
     */
    List<ResolvedJavaMethod> getAllMethods(boolean forceLink);

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's a good idea - it's more future proof and lets the caller do the filtering.

This list can include methods implicitly created and used by the VM that are not present in {@link #getDeclaredMethods}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it now to be getAllMethods

@teshull teshull changed the title 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType. 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType May 28, 2025
@openjdk openjdk bot changed the title 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType. May 28, 2025

private native boolean isCompilable(HotSpotResolvedJavaMethodImpl method, long methodPointer);

/**
Copy link
Member

@dougxc dougxc May 29, 2025

Choose a reason for hiding this comment

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

Delete this method - it's no longer used.

return !method->is_not_compilable(CompLevel_full_optimization);
C2V_END

C2V_VMENTRY_0(jboolean, isOverpass,(JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
Copy link
Member

Choose a reason for hiding this comment

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

Delete this method - it's no longer used.

{CC "methodIsIgnoredBySecurityStackWalk", CC "(" HS_METHOD2 ")Z", FN_PTR(methodIsIgnoredBySecurityStackWalk)},
{CC "setNotInlinableOrCompilable", CC "(" HS_METHOD2 ")V", FN_PTR(setNotInlinableOrCompilable)},
{CC "isCompilable", CC "(" HS_METHOD2 ")Z", FN_PTR(isCompilable)},
{CC "isOverpass", CC "(" HS_METHOD2 ")Z", FN_PTR(isOverpass)},
Copy link
Member

Choose a reason for hiding this comment

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

delete

for (Class<?> c : classes) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
Set<ResolvedJavaMethod> allMethods = new HashSet<>(type.getAllMethods(true));
boolean included = Arrays.stream(type.getDeclaredMethods()).allMatch(m -> allMethods.contains(m));
Copy link
Member

Choose a reason for hiding this comment

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

You can produce a more helpful error message by collecting the entries from getDeclaredMethods, getDeclaredConstructors and the class initialized that are not in allMethods.

@dougxc
Copy link
Member

dougxc commented May 30, 2025

I also updated the title of https://bugs.openjdk.org/browse/JDK-8357987 to Not Be All Capitalized so you'll need to fix the title of this PR.

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels May 30, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label May 30, 2025
@mlbridge
Copy link

mlbridge bot commented May 30, 2025

Webrevs

@teshull teshull changed the title 8357987: [JVMCI] Add Support for Retrieving All Non-Static Methods of a ResolvedJavaType. 8357987: [JVMCI] Add support for retrieving al methods of a ResolvedJavaType Jun 2, 2025
@teshull teshull changed the title 8357987: [JVMCI] Add support for retrieving al methods of a ResolvedJavaType 8357987: [JVMCI] Add support for retrieving all methods of a ResolvedJavaType Jun 2, 2025
Copy link
Member

@dougxc dougxc 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 to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 2, 2025
if (instanceMethods.length == 0) {
return List.of();
}
return Collections.unmodifiableList(Arrays.asList(instanceMethods));
Copy link
Contributor

Choose a reason for hiding this comment

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

return List.of(instanceMethods); should work. We can then replace the above with return List.of(runtime().compilerToVm.getAllMethods(this));

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 2, 2025
Copy link
Member

@dougxc dougxc left a comment

Choose a reason for hiding this comment

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

Still looks good to me.

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

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

@teshull
Copy link
Contributor Author

teshull commented Jun 3, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 3, 2025
@openjdk
Copy link

openjdk bot commented Jun 3, 2025

@teshull
Your change (at version 606f361) is now ready to be sponsored by a Committer.

@dougxc
Copy link
Member

dougxc commented Jun 3, 2025

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 3, 2025

Going to push as commit e235b61.
Since your change was applied there have been 5 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 Jun 3, 2025
@openjdk openjdk bot closed this Jun 3, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jun 3, 2025
@openjdk
Copy link

openjdk bot commented Jun 3, 2025

@dougxc @teshull Pushed as commit e235b61.

💡 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.

4 participants