-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8268406: Deallocate jmethodID native memory #25267
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
Conversation
|
👋 Welcome back coleenp! A progress list of the required criteria for merging this PR into |
|
@coleenp 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 203 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 |
334bdb9 to
8aa69f5
Compare
Webrevs
|
|
Also, this was @fisk 's idea. |
s/concerned about performance/concerned about JNI performance/ |
Hmmm... I'm rusty with redefinition, but I think there are legitimate scenarios where is "okay" |
|
There is a way to create a jmethodID from an obsolete method and I thought we had tests that did this. I'm not finding them right now. The old and obsolete methods can still be running after a redefinition if they were running during the redefinition. The JIT deoptimizes them but they will be run in the interpreter. New invocations of the method will choose the new version of the method always. Always unless there's a bug that we don't know about. We have fixed a few old method invocations in the past coming from various places in the JVM but we fixed the "last" one fairly recently. |
|
Dan, thank you for your first pass. I've tried to address the things you pointed out. I think I've used 'null' correctly in comments and strings though. |
dcubed-ojdk
left a comment
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.
Thumbs up with the latest version!
Thanks for fixing all the nits.
dholmes-ora
left a comment
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. I'm still digesting it.
Thanks
| int new_jmeths = 0; | ||
| void InstanceKlass::make_methods_jmethod_ids() { | ||
| MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag); | ||
| jmethodID* jmeths = methods_jmethod_ids_acquire(); |
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.
Technically you don't need acquire semantics here as this value is not used to then access other data. But I see this is the only getter API available.
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.
Yes, this does need an acquire getter outside the lock. It's better to not have a non-acquire version to be possibly used by accident.
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.
Acquire is only ever needed outside the lock. I don't like there only being acquire/release available generally speaking because it just confuses what memory operations are being synchronized.
sspitsyn
left a comment
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 really great optimization and refactoring!
Looks pretty good to me but I'd like to make one more pass through the changes.
xmas92
left a comment
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. Thanks.
Feels like JmethodIdCreation_lock might not be needed now but it is also easier to reason about things when we serialize the modifications.
Not passing in the cls parameter, would be a clear user error though, right? And one that would have crashed before, because if you racingly execute bytecodes of a class that is being unloaded, things would blow up one way or another. To me it seems like the user should just pass in the class as intended and then all is good. |
|
Thank you for reviewing from the GC and class unloading perspective, Axel and Erik. |
|
Thank you Serguei and Dan for reviewing. |
The point is to try and make things more robust when the user does the unexpected. As Coleen stated we are trying to handle cases where JNI code looks up a jMethodID in one place, stashes it away and then uses it elsewhere with no guarantee the class is being kept alive. I agree you would think they would have, and pass in, the original jclass reference, but the fact we don't actually use that value is not hard to determine and JNI code can take advantage of that - treating the |
That's fine. I (per my response to Thomas) thought the new approach also closed the door on unsafe usage of the |
dcubed-ojdk
left a comment
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've made another pass through this PR. Just a few more nits.
|
Another way to look at the safety of the new mechanism is to The |
|
Ping @jbachorik for discussions about the safety of jmethodIDs... |
dcubed-ojdk
left a comment
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.
Thanks for making the wording tweaks.
I do not see any code that creates jmethodIDs for all the methods in a ClassLoad JVMTI event. ACGCT does call so it won't create jmethodIDs from a signal handler. Keeping them live for the frames depends on when the native caller of ASGCT uses the trace that is returned. If the frames are still on the call stack, the methods cannot be unloaded because they're still on the call stack. If the frames returned by ASGCT are stored somewhere else, and accessed later, they could be null. I don't see any code that makes this work tbh. Most methods do not have jmethodIDs. |
dholmes-ora
left a comment
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.
Still fine
|
Thank you for the reviews, Serguei, David, Dan, Axel and Erik. And all the discussion, and the idea itself. |
|
Going to push as commit d8f9b18.
Your commit was automatically rebased without conflicts. |
This change uses a ConcurrentHashTable to associate Method* with jmethodID, instead of an indirection. JNI is deprecated in favor of using Panama to call methods, so I don't think we're concerned about JNI performance going forward. JVMTI uses a lot of jmethodIDs but there aren't any performance tests for JVMTI, but running vmTestbase/nsk/jvmti with in product build with and without this change had no difference in time.
The purpose of this change is to remove the memory leak when you unload classes: we were leaving the jmethodID memory just in case JVMTI code still had references to that jmethodID and instead of crashing, should get nullptr. With this change, if JVMTI looks up a jmethodID, we've removed it from the table and will return nullptr. Redefinition and the InstanceKlass::_jmethod_method_ids is somewhat complicated. When a method becomes "obsolete" in redefinition, which means that the code in the method is changed, afterward creating a jmethodID from an "obsolete" method will create a new entry in the InstanceKlass table. This mechanism increases the method_idnum to do this. In the future maybe we could throw NoSuchMethodError if you try to create a jmethodID out of an obsolete method and remove all this code. But that's not in this change.
Tested with tier1-4, 5-7.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25267/head:pull/25267$ git checkout pull/25267Update a local copy of the PR:
$ git checkout pull/25267$ git pull https://git.openjdk.org/jdk.git pull/25267/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25267View PR using the GUI difftool:
$ git pr show -t 25267Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25267.diff
Using Webrev
Link to Webrev Comment