-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8369219: JNI::RegisterNatives causes a memory leak in CodeCache #27742
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back fandreuzzi! A progress list of the required criteria for merging this PR into |
|
@fandreuz This change is no longer ready for integration - check the PR body for details. |
Webrevs
|
test/hotspot/jtreg/gc/NativeWrapperCollection/NativeWrapperCollection.java
Show resolved
Hide resolved
|
/label add hotspot-compiler |
|
@dholmes-ora |
src/hotspot/share/code/nmethod.cpp
Outdated
| // nmethods that don't seem to be all that relevant any longer. | ||
| bool nmethod::is_cold() { | ||
| if (!MethodFlushing || is_native_method() || is_not_installed()) { | ||
| if (!MethodFlushing || (is_native_method() && is_in_use()) || is_not_installed()) { |
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.
So I guess we need to decide what to do about native wrappers that are still "in use", but are "cold" because they haven't been called in a while. The above change would keep them around forever. We could instead allow them to be cleaned up like regular nmethods.
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.
We could instead allow them to be cleaned up like regular nmethods.
That sounds reasonable to me, native methods seem to be tracked like all other nmethods.
Removing is_native_method() altogether from the condition was the first implementation I had, and as far as I remember there was no failure in tier1 or tier2. Should I propose this alternative implementation as part of this PR?
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 am tempted to say yes, for consistency, but it probably won't make much of a difference either way. But now I am wondering, if these cold native wrappers continue to be immortal, then do they really need to give them nmethod entry barriers? Removing the barrier could remove some overhead. Whatever direction we decide to go, it would be good to add a comment here explaining the decision and/or trade-offs.
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 actually possible to remove entry barriers for any garbage collectable nmethod? How can we know an nmethod is not used anymore, even when it is made not entrant? is_cold() bails out when an nmethod does not support entry barriers:
// On platforms that don't support nmethod entry barriers, we can't
// trust the temporal aspect of the gc epochs. So we can't detect
// cold nmethods on such platforms.
So, the decision of removing entry barriers for native nmethods would make the memory leak I'm trying to fix here effectively unfixable? Let me know if I'm missing something.
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.
If we mark them as not-entrant, then the is_not_entrant() check below will still catch them, right?
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 see, I assumed an nmethod couldn't be marked as on-stack without entry barriers, but that doesn't seem to be the case.
But on second thought, do you agree with the fix I'm proposing in this PR? I think the following two work items could be implemented and reviewed in separate changesets:
- Allow not-entrant nmethod to be collected during GC (I removed
is_static_method()from L2599, so native nmethods are treated just like normal nmethods) - Evaluate the implications of removing entry barriers for native nmethods, thus letting GC reclaim them whenever
!is_maybe_on_stack() && is_not_entrant(), but without the overhead of entry barriers.
I'm proposing this because I guess the latter will need more discussion and is technically not needed to fix the memory leak I address in this PR. Do you agree @dean-long ? I could create another ticket to handle the second item.
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, I'm fine with it being a separate issue.
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 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 reasonable, but the test needs a bit more work.
/reviewers 2
|
|
||
| WB.enqueueMethodForCompilation(method, 1 /* compLevel */); | ||
| while (WB.isMethodQueuedForCompilation(method)) { | ||
| Thread.onSpinWait(); |
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.
We are just waiting for compilation here. It is counter-productive to wait with a busy-loop. Insert a sleep for ~10...100ms instead. Same thing for the loop below.
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, that sounds reasonable. I got this pattern from another test, but it looks counterproductive here indeed.
I propose to amend
nmethod::is_coldto let GC collect not-entrant nativenmethodinstances.Passes tier1 and tier2 (fastdebug).
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27742/head:pull/27742$ git checkout pull/27742Update a local copy of the PR:
$ git checkout pull/27742$ git pull https://git.openjdk.org/jdk.git pull/27742/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27742View PR using the GUI difftool:
$ git pr show -t 27742Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27742.diff
Using Webrev
Link to Webrev Comment