Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8078641

MethodHandle.asTypeCache can retain classes from unloading

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 18
    • 9, 11, 17, 18
    • core-libs

      http://mail.openjdk.java.net/pipermail/mlvm-dev/2015-April/006436.html
      Peter Levart wrote:

      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/

            vlivanov Vladimir Ivanov
            vlivanov Vladimir Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: