Potential memory leak in Method::ensure_jmethod_ids

Jiangli Zhou jianglizhou at google.com
Mon Jan 25 01:46:53 UTC 2021


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) {

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?



More information about the hotspot-runtime-dev mailing list