From 12ae031068c8dc69dc744f1a4060aba054975801 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Tue, 17 Oct 2006 21:56:16 +0000 Subject: [PATCH] Fix for OOME with <*ant*> and 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. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@465073 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ .../org/apache/tools/ant/IntrospectionHelper.java | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index ce82b7223..d4d3281ab 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -7,6 +7,9 @@ Changes that could break older environments: Fixed bugs: ----------- +* OOM caused by IH holding on to classes and thus their classloaders. + Bugzilla 28283 and 33061. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index 05f675f66..55055d7f1 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -48,9 +48,9 @@ public final class IntrospectionHelper implements BuildListener { = 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 @@ public final class IntrospectionHelper implements BuildListener { * @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) {