You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/05/20 19:13:09 UTC

svn commit: r1744786 - /tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java

Author: markt
Date: Fri May 20 19:13:09 2016
New Revision: 1744786

URL: http://svn.apache.org/viewvc?rev=1744786&view=rev
Log:
Remove the ResourceBundle memory leak protection since I am as sure as I can be that the original report was a false positive. The reasons I think this are:
- The GC roots related to ResourceBundle were all weak references.
- I can no longer produce the leak with the same (newer version) test application and Java the original 1.8. If it was a GC bug it is fixed in any version of Java that Tomcat 9 will use.
- We have a better understanding of JVM bugs that make some GC roots not visible in profilers like YourKit.

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1744786&r1=1744785&r2=1744786&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Fri May 20 19:13:09 2016
@@ -23,7 +23,6 @@ import java.io.InputStream;
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.IllegalClassFormatException;
 import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URI;
@@ -52,8 +51,6 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -77,7 +74,6 @@ import org.apache.tomcat.InstrumentableC
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.compat.JreCompat;
-import org.apache.tomcat.util.compat.JreVendor;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -1526,13 +1522,6 @@ public abstract class WebappClassLoaderB
             org.apache.juli.logging.LogFactory.release(this);
         }
 
-        // Clear the resource bundle cache
-        // This shouldn't be necessary, the cache uses weak references but
-        // it has caused leaks. Oddly, using the leak detection code in
-        // standard host allows the class loader to be GC'd. This has been seen
-        // on Sun but not IBM JREs. Maybe a bug in Sun's GC impl?
-        clearReferencesResourceBundles();
-
         // Clear the classloader reference in the VM's bean introspector
         java.beans.Introspector.flushCaches();
 
@@ -2143,94 +2132,6 @@ public abstract class WebappClassLoaderB
         }
     }
 
-
-    /**
-     * Clear the {@link ResourceBundle} cache of any bundles loaded by this
-     * class loader or any class loader where this loader is a parent class
-     * loader. Whilst {@link ResourceBundle#clearCache()} could be used there
-     * are complications around the
-     * {@link org.apache.jasper.servlet.JasperLoader} that mean a reflection
-     * based approach is more likely to be complete.
-     *
-     * The ResourceBundle is using WeakReferences so it shouldn't be pinning the
-     * class loader in memory. However, it is. Therefore clear out the
-     * references.
-     */
-    private void clearReferencesResourceBundles() {
-        // Get a reference to the cache
-        try {
-            Field cacheListField =
-                ResourceBundle.class.getDeclaredField("cacheList");
-            cacheListField.setAccessible(true);
-
-            // Java 6 uses ConcurrentMap
-            // Java 5 uses SoftCache extends Abstract Map
-            // So use Map and it *should* work with both
-            Map<?,?> cacheList = (Map<?,?>) cacheListField.get(null);
-
-            // Get the keys (loader references are in the key)
-            Set<?> keys = cacheList.keySet();
-
-            Field loaderRefField = null;
-
-            // Iterate over the keys looking at the loader instances
-            Iterator<?> keysIter = keys.iterator();
-
-            int countRemoved = 0;
-
-            while (keysIter.hasNext()) {
-                Object key = keysIter.next();
-
-                if (loaderRefField == null) {
-                    loaderRefField =
-                        key.getClass().getDeclaredField("loaderRef");
-                    loaderRefField.setAccessible(true);
-                }
-                WeakReference<?> loaderRef =
-                    (WeakReference<?>) loaderRefField.get(key);
-
-                ClassLoader loader = (ClassLoader) loaderRef.get();
-
-                while (loader != null && loader != this) {
-                    loader = loader.getParent();
-                }
-
-                if (loader != null) {
-                    keysIter.remove();
-                    countRemoved++;
-                }
-            }
-
-            if (countRemoved > 0 && log.isDebugEnabled()) {
-                log.debug(sm.getString(
-                        "webappClassLoader.clearReferencesResourceBundlesCount",
-                        Integer.valueOf(countRemoved), getContextName()));
-            }
-        } catch (SecurityException e) {
-            log.warn(sm.getString(
-                    "webappClassLoader.clearReferencesResourceBundlesFail",
-                    getContextName()), e);
-        } catch (NoSuchFieldException e) {
-            if (JreVendor.IS_ORACLE_JVM) {
-                log.warn(sm.getString(
-                        "webappClassLoader.clearReferencesResourceBundlesFail",
-                        getContextName()), e);
-            } else {
-                log.debug(sm.getString(
-                        "webappClassLoader.clearReferencesResourceBundlesFail",
-                        getContextName()), e);
-            }
-        } catch (IllegalArgumentException e) {
-            log.warn(sm.getString(
-                    "webappClassLoader.clearReferencesResourceBundlesFail",
-                    getContextName()), e);
-        } catch (IllegalAccessException e) {
-            log.warn(sm.getString(
-                    "webappClassLoader.clearReferencesResourceBundlesFail",
-                    getContextName()), e);
-        }
-    }
-
 
     /**
      * Find specified class in local repositories.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org