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

ObjectStreamClass does not provide a mechanism to clear the cache

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE REQUEST :
      It is not possible (without using reflection) to clear the references held in ObjectStreamClass$Caches. Such a use of reflection is strongly discouraged in Java 9 onwards.

      A method is requested that removes all classes from the caches that have been loaded by the given class loader or a descendant.

      JUSTIFICATION :
      One of the features of Apache Tomcat is detection of memory leaks in web applications. For this detection to work, it is necessary that all valid/expected references to a web application class loader can be removed. A combination of a WeakReference to the web application class loader and an explicit GC call then enables Tomcat to determine if any unexpected references have been retained to the web application class loader which would indicate a memory leak.

      The references retained in ObjectStreamClass$Caches trigger a false positive in Tomcat's memory leak detection. It is necessary to clear those references for the detection to work correctly. An API to do this is requested.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Something along the lines of this API:

      ObjectStreamClass.clearCaches(ClassLoader classLoader)

      that then did the equivalent of cleanUpLeakingObjects() in https://github.com/markt-asf/memory-
      leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java

      ACTUAL -
      The clean-up has to be performed via reflection.

      ---------- BEGIN SOURCE ----------
      This class demonstrates the leak:

      https://github.com/markt-asf/memory-
      leaks/blob/master/src/org/apache/markt/leaks/io/ObjectStreamClassLeak.java

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      See the code in cleanUpLeakingObjects()

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: