From: aclement Date: Tue, 27 May 2008 18:50:19 +0000 (+0000) Subject: 210470: preventing weaver leaks: use a weak classloader ref X-Git-Tag: V1_6_1x~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=804d34e3224c14414d34c2fba8b9bf5c99f6483c;p=aspectj.git 210470: preventing weaver leaks: use a weak classloader ref --- diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index a5ac53aef..2f1aaa09d 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -46,6 +46,7 @@ import org.aspectj.apache.bcel.generic.NEWARRAY; import org.aspectj.apache.bcel.generic.ObjectType; import org.aspectj.apache.bcel.generic.PUTSTATIC; import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.apache.bcel.util.ClassLoaderReference; import org.aspectj.apache.bcel.util.ClassLoaderRepository; import org.aspectj.apache.bcel.util.ClassPath; import org.aspectj.apache.bcel.util.NonCachingClassLoaderRepository; @@ -69,6 +70,7 @@ import org.aspectj.weaver.ResolvedMemberImpl; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.WeakClassLoaderReference; import org.aspectj.weaver.World; import org.aspectj.weaver.AjAttribute.Aspect; import org.aspectj.weaver.patterns.DeclareAnnotation; @@ -84,7 +86,7 @@ public class BcelWorld extends World implements Repository { private ClassPathManager classPath; protected Repository delegate; - private ClassLoader loader; + private WeakClassLoaderReference loaderRef; //private ClassPathManager aspectPath = null; @@ -153,7 +155,7 @@ public class BcelWorld extends World implements Repository { */ public BcelWorld(ClassLoader loader, IMessageHandler handler, ICrossReferenceHandler xrefHandler) { this.classPath = null; - this.loader = loader; + this.loaderRef = new WeakClassLoaderReference(loader); setMessageHandler(handler); setCrossReferenceHandler(xrefHandler); // Tell BCEL to use us for resolving any classes @@ -162,16 +164,20 @@ public class BcelWorld extends World implements Repository { public void ensureRepositorySetup() { if (delegate==null) { - delegate = getClassLoaderRepositoryFor(loader); + delegate = getClassLoaderRepositoryFor(loaderRef); } } - public Repository getClassLoaderRepositoryFor(ClassLoader loader) { - if (bcelRepositoryCaching) { - return new ClassLoaderRepository(loader); - } else { - return new NonCachingClassLoaderRepository(loader); - } + private ClassLoader getClassLoader() { + return loaderRef.getClassLoader(); + } + + public Repository getClassLoaderRepositoryFor(ClassLoaderReference loader) { + if (bcelRepositoryCaching) { + return new ClassLoaderRepository(loader); + } else { + return new NonCachingClassLoaderRepository(loader); + } } public void addPath (String name) {