ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r465073 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/IntrospectionHelper.java
Date Tue, 17 Oct 2006 21:56:18 GMT
Author: peterreilly
Date: Tue Oct 17 14:56:16 2006
New Revision: 465073

URL: http://svn.apache.org/viewvc?view=rev&rev=465073
Log:
Fix for OOME with <*ant*> and <typedef>
Bugzilla report 28283 and 33061

IH had a map of class->IH objects. The
class is the typedefed class and IH is the
attributes, elements etc of that class.
This works fine, except that the class is kept
until the build ends, this means that the classloader
for the class is also kept, a classloader contains
pointers to all the classes loaded by it - so a lot
of memory can be blocked.
When ant, or antcall is used and the called project
typedef the antcontrib, these will be new classloaders,
hence the memory being used up.

The fix is to use the name of the class, check if the IH
in the map is the same class, and if not replace that IH.



Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=465073&r1=465072&r2=465073
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Oct 17 14:56:16 2006
@@ -7,6 +7,9 @@
 Fixed bugs:
 -----------
 
+* OOM caused by IH holding on to classes and thus their classloaders.
+  Bugzilla 28283 and 33061.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java?view=diff&rev=465073&r1=465072&r2=465073
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java Tue Oct 17 14:56:16
2006
@@ -48,9 +48,9 @@
         = Collections.unmodifiableMap(new HashMap(0));
 
     /**
-     * Helper instances we've already created (Class to IntrospectionHelper).
+     * Helper instances we've already created (Class.getName() to IntrospectionHelper).
      */
-    private static final Hashtable HELPERS = new Hashtable();
+    private static final Map HELPERS = new Hashtable();
 
     /**
      * Map from primitive types to wrapper classes for use in
@@ -331,13 +331,15 @@
      * @return a helper for the specified class
      */
     public static IntrospectionHelper getHelper(Project p, Class c) {
-        IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c);
-        if (ih == null) {
+        IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c.getName());
+        // If a helper cannot be found, or if the helper is for another
+        // classloader, create a new IH
+        if (ih == null || ih.bean != c) {
             ih = new IntrospectionHelper(c);
             if (p != null) {
                 // #30162: do *not* cache this if there is no project, as we
                 // cannot guarantee that the cache will be cleared.
-                HELPERS.put(c, ih);
+                HELPERS.put(c.getName(), ih);
             }
         }
         if (p != null) {



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


Mime
View raw message