[External] : Potential memory leak in Method::ensure_jmethod_ids
Coleen Phillimore
coleen.phillimore at oracle.com
Mon Jan 25 14:28:12 UTC 2021
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()
> <https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/764111ff831096729eb1bcc69a54d92fde67b044/src/hotspot/share/classfile/classLoaderData.cpp*L705__;Iw!!GqivPVa7Brio!JFfqo4Dc12kzqeunN7e-UxlXKAKyj4OCzahIumZpuTrEhq3HOx82KsIu8nrrG6e4rqUN7w$>
> 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