-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8367142: Avoid InstanceKlass::cast when converting java mirror to InstanceKlass #27158
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
8367142: Avoid InstanceKlass::cast when converting java mirror to InstanceKlass #27158
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 79 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.
Sorry but I think this PR is trying to do too many things at once.
It is pushing JNI resolving inside internal JVM methods, which I think is a bad thing - we resolve JNI references at the boundary to get the oop that the VM wants to work with. Internal APIs should be oblivious to jobject and friends IMO. Also there may be times that the JNI/JVM method needs get the oop itself before extracting the klass.
You are converting klass to instanceKlass where it has to be instanceKlass e.g. with redefinition. This is a good thing, but it is a very distinct thing that deserves its own cleanup (as per previous changes in that area).
You are defining a helper java_lang_Class::as_InstanceKlass to internalize the cast - this is fine but again a simple cleanup that would be better standalone IMO.
It is also not clear that JVM/JNI API's are properly checking that the incoming jobject is in fact a class of the right kind (ie not an array class object).
There are 92 header files that have the word There are 54 cases where we call
I can move the considering_redefinition changes in a follow-up PR.
I am just converting to The code already assumes that it has an InstanceKlass, and I am not changing that. |
I think it is more that there are many bits of code that actually form the "boundary" (prims, services, some runtime, jvmci, interpreter-related). But I guess it is hard to argue this makes it markedly worse.
Okay. |
|
@iklam this pull request can not be integrated into git checkout 8367142-simplify-java-mirror-handling-in-jni-methods
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
…on() changes, to be done in separate PR
Arguably the translation of Java mirrors to Klasses is also a boundary (from Java representation to VM representation) :-) In reality I think because jobjects are easy to use and are just another kind of handle (like Handle and OopHandle), the leakage from JNI code to other parts of VM just happened naturally.
BTW I removed the JVMTI changes from this PR. |
The mirror is an oop, both oop and klass are internal VM representations. |
I think you should deal with that by adding a helper function inside jni.cpp instead of extending the *Klass functions to take a jobject. |
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. A couple of minor nits.
Thanks
src/hotspot/share/prims/jvm.cpp
Outdated
| const char * from_name = java_lang_Class::as_Klass(from)->external_name(); | ||
| const char * to_name = java_lang_Class::as_Klass(result)->external_name(); |
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.
| const char * from_name = java_lang_Class::as_Klass(from)->external_name(); | |
| const char * to_name = java_lang_Class::as_Klass(result)->external_name(); | |
| const char* from_name = java_lang_Class::as_Klass(from)->external_name(); | |
| const char* to_name = java_lang_Class::as_Klass(result)->external_name(); |
pre-existing nit
src/hotspot/share/prims/jvm.cpp
Outdated
| THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Lookup class is null"); | ||
| THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Lookup class is primitive"); |
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 is a behavioural change.
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 reverted the change to the error message.
I don't know how we will ever get a primitive class in there and who would be reading the error message. I added a comment saying the error message is wrong, so people reading this code will not get confused.
I agree with this. I don't think you should move any more jobjects into the runtime code. The jobjects should stop at jni/jvm. They don't everywhere but that's something that over time we should fix. For instance, the ci creates jobjects but it should use OopHandles instead, except per-thread OopStorage isn't implemented yet. |
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.
jfr also is a boundary between Java -> Native code. That can have jobjects too, but resolve them before calling javaClasses.
|
|
||
|
|
||
| Klass* klass() const { return vmClasses::klass_at(klass_id); } | ||
| InstanceKlass* klass() const { return vmClasses::klass_at(klass_id); } |
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.
Can you fix the indentation?
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 removed all indentation alignments from this class, as they no longer seem warranted.
|
I didn't realize that my attempt to remove the I updated the JBS issue text as this PR is now only for reducing the number of InstanceKlass::cast() calls. |
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.
Reduced set of changes still looks good.
I was prepared to be accommodating on the broader change, but seems others agreed with my initial position. :)
Removing boilerplate wasn't controversial. Spreading the j* types can be seen as controversial give that we have various efforts to push those types out to the boundaries of the JVM. Adding new convenience functions that accept j* goes in the opposite direction.
But almost all are in jni.cpp and jvm.cpp and you can get rid of most of the boilerplate code by adding local helpers there. The handfulish of other places could keep their explicit usage of JNIHandles::resolve* calls. |
Maybe in a different PR. I want to keep the current PR simple. |
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 great. Thanks!
|
Thanks @dholmes-ora @coleenp for the review |
|
Going to push as commit 2425584.
Your commit was automatically rebased without conflicts. |
The purpose of this PR is to simplify JNI code and also to avoid unnecessary
InstanceKlass::cast()calls by adding a new function:This PR is intended to be a strict clean-up that preserves existing behaviors.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27158/head:pull/27158$ git checkout pull/27158Update a local copy of the PR:
$ git checkout pull/27158$ git pull https://git.openjdk.org/jdk.git pull/27158/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27158View PR using the GUI difftool:
$ git pr show -t 27158Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27158.diff
Using Webrev
Link to Webrev Comment