[External] : Potential memory leak in Method::ensure_jmethod_ids

Jiangli Zhou jianglizhou at google.com
Mon Jan 25 20:37:45 UTC 2021


Hi Coleen,

Thanks a lot for digging up the information! That's reassuring. I'm
going to work on a fix for the memory leak and then upstream it (also
log a bug in JBS) after testing it internally with the application in
production.

Thanks!

Jiangli

On Mon, Jan 25, 2021 at 6:28 AM Coleen Phillimore
<coleen.phillimore at oracle.com> wrote:
>
>
> Hi Jiangli,
>
> The jmethodID leak is intentional for backward compatibility. Looking back through the source code history, I don't find a bug that made leaking jmethodID objects required.  It seems like a useful change to clean them up under a product option.  When I measured the code we had, there weren't many jmethodID objects, but applications can differ.
>
> Thanks,
> Coleen
>
>
> On 1/24/21 8:46 PM, Jiangli Zhou wrote:
>
> Hi,
>
> Developers reported a potential memory leak in Method::ensure_jmethod_ids for a longer running application on JDK 11 (most likely the memory leak exists in newer JDK versions as well). The allocated JNIMethodBlockNodes are never freed, which is the case even for user defined class loaders after unloading. The daily leak is ~20MiB - ~70MiB. Although the memory leak is not very large, it's still good to eliminate it.
>
> The following comment in ClassLoaderData::~ClassLoaderData() indicates it's intentional:
>
> // Clear all the JNI handles for methods
> // These aren't deallocated and are going to look like a leak, but that's
> // needed because we can't really get rid of jmethodIDs because we don't
> // know when native code is going to stop using them. The spec says that
> // they're "invalid" but existing programs likely rely on their being
> // NULL after class unloading.
> if (_jmethod_ids != NULL) {
>   Method::clear_jmethod_ids(this);
> }
>
>
> The change was introduced as part of the large permgen removal effort. It's not too clear what are the side-effects (related to JVMTI agent?) of deallocating the JNIMethodBlockNodes after unloading. Does anyone know if there was a specific bug related?
>
> Thanks!
>
> Best,
> Jiangli
>
>


More information about the hotspot-runtime-dev mailing list