Integrated: 8078641: MethodHandle.asTypeCache can retain classes from unloading
Vladimir Ivanov
vlivanov at openjdk.java.net
Wed Sep 8 11:31:10 UTC 2021
On Wed, 25 Aug 2021 09:31:51 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
> `MethodHandle.asTypeCache` keeps a strong reference to adapted `MethodHandle` and it can introduce a class loader leak through its `MethodType`.
>
> Proposed fix introduces a 2-level cache (1 element each) where 1st level can only contain `MethodHandle`s which are guaranteed to not introduce any dependencies on new class loaders compared to the original `MethodHandle`. 2nd level is backed by a `SoftReference` and is used as a backup when the result of `MethodHandle.asType()` conversion can't populate the higher level cache.
>
> The fix is based on [the work](http://cr.openjdk.java.net/~plevart/jdk9-dev/MethodHandle.asTypeCacheLeak/) made by Peter Levart @plevart back in 2015.
>
> Testing: tier1 - tier6
This pull request has now been integrated.
Changeset: 21012f2b
Author: Vladimir Ivanov <vlivanov at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/21012f2bbe214955d05f8bc583dcdceb0949b601
Stats: 109 lines in 2 files changed: 88 ins; 3 del; 18 mod
8078641: MethodHandle.asTypeCache can retain classes from unloading
Co-authored-by: Peter Levart <plevart at openjdk.org>
Co-authored-by: Vladimir Ivanov <vlivanov at openjdk.org>
Reviewed-by: psandoz, mchung, plevart
-------------
PR: https://git.openjdk.java.net/jdk/pull/5246
More information about the core-libs-dev
mailing list