ClassLoader leak in MethodHandle.asType()

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Fri Apr 24 21:41:39 UTC 2015


Thanks for the report, Peter.

Filed JDK-8078641 [1] to track the problem.

The fix you propose looks reasonable.

Best regards,
Vladimir Ivanov

[1] https://bugs.openjdk.java.net/browse/JDK-8078641

On 4/24/15 7:14 PM, Peter Levart wrote:
> Hi,
>
> I think there is a Class(Loader) leak in MethodHandle.asType()
> implementation. If for example some MH (say mhX) is long lived (because
> it is a system cached MH) and a client "generates" variants from it by
> invoking mhX.asType(newType) and the newType contains a type (either
> return type or parameter type) that is loaded by some child ClassLoader,
> then such derived MH is retained strongly from mhX via the
> MethodHandle.asTypeCache field. Until this field is overwriten by some
> other MH, child ClassLoader can not be GCed.
>
> In case this one-element cache is needed to speed things up, it should
> be a WeakReference, like the following:
>
> http://cr.openjdk.java.net/~plevart/jdk9-dev/MethodHandle.asTypeCacheLeak/webrev.01/
>
>
>
> Regards, Peter
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev


More information about the mlvm-dev mailing list