RFR: 8369219: JNI::RegisterNatives causes a memory leak in CodeCache [v4]
    Dean Long 
    dlong at openjdk.org
       
    Thu Oct 16 23:43:02 UTC 2025
    
    
  
On Thu, 16 Oct 2025 14:36:06 GMT, Francesco Andreuzzi <fandreuzzi at openjdk.org> wrote:
>> src/hotspot/share/code/nmethod.cpp line 2599:
>> 
>>> 2597: // nmethods that don't seem to be all that relevant any longer.
>>> 2598: bool nmethod::is_cold() {
>>> 2599:   if (!MethodFlushing || (is_native_method() && is_in_use()) || is_not_installed()) {
>> 
>> 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.
>
>> 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?
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27742#discussion_r2437762613
    
    
More information about the hotspot-compiler-dev
mailing list