]> source.dussan.org Git - aspectj.git/commitdiff
210470: preventing weaver leaks: use a weak classloader ref
authoraclement <aclement>
Tue, 27 May 2008 18:50:34 +0000 (18:50 +0000)
committeraclement <aclement>
Tue, 27 May 2008 18:50:34 +0000 (18:50 +0000)
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java

index 01c16ef8209183b74ba755b81ffa8b23cc91b430..1e3628c47029d8028c71704d16a2991a9b05cb0d 100644 (file)
@@ -30,6 +30,7 @@ import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.SourceContextImpl;
 import org.aspectj.weaver.TypeVariable;
 import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.WeakClassLoaderReference;
 import org.aspectj.weaver.WeaverStateInfo;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.patterns.PerClause;
@@ -42,10 +43,10 @@ import org.aspectj.weaver.patterns.PerClause;
  */
 public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelegate {
 
-       private static final ClassLoader BootClassLoader = new URLClassLoader(new URL[0]);
+       private static final ClassLoader BootClassLoader = new URLClassLoader(new URL[0]);// ReflectionBasedReferenceTypeDelegate.class.getClassLoader();
        
        protected Class myClass = null;
-       protected ClassLoader classLoader = null;
+       protected WeakClassLoaderReference classLoaderReference = null;
        private World world;
        private ReferenceType resolvedType;
        private ResolvedMember[] fields = null;
@@ -63,7 +64,7 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
                this.myClass = aClass;
                this.resolvedType = aType;
                this.world = aWorld;
-               this.classLoader = (aClassLoader != null) ? aClassLoader : BootClassLoader;
+               this.classLoaderReference = new WeakClassLoaderReference((aClassLoader != null) ? aClassLoader : BootClassLoader);
        }
        
        protected Class getBaseClass() { 
index 7994d8f390cb95a5a2fc0df9ef20cb351d9e0614..12107649cc1bf5f51b18364b74d77495dbd8d278 100644 (file)
@@ -25,6 +25,7 @@ import org.aspectj.weaver.ResolvedMember;
 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.AdviceAttribute;
 import org.aspectj.weaver.patterns.Pointcut;
@@ -38,23 +39,23 @@ import org.aspectj.weaver.patterns.PerClause.Kind;
  */
 public class ReflectionWorld extends World implements IReflectionWorld {
 
-       private ClassLoader classLoader;
+       private WeakClassLoaderReference classLoaderReference;
        private AnnotationFinder annotationFinder;
        
        private ReflectionWorld() {
                super();
                this.setMessageHandler(new ExceptionBasedMessageHandler());
                setBehaveInJava5Way(LangUtil.is15VMOrGreater());
-               this.classLoader = ReflectionWorld.class.getClassLoader();
-               this.annotationFinder = makeAnnotationFinderIfAny(classLoader, this);
+               this.classLoaderReference = new WeakClassLoaderReference(ReflectionWorld.class.getClassLoader());
+               this.annotationFinder = makeAnnotationFinderIfAny(classLoaderReference.getClassLoader(), this);
        }
        
        public ReflectionWorld(ClassLoader aClassLoader) {
                super();
                this.setMessageHandler(new ExceptionBasedMessageHandler());
                setBehaveInJava5Way(LangUtil.is15VMOrGreater());
-               this.classLoader = aClassLoader;
-               this.annotationFinder = makeAnnotationFinderIfAny(classLoader, this);
+               this.classLoaderReference = new WeakClassLoaderReference(aClassLoader);
+               this.annotationFinder = makeAnnotationFinderIfAny(classLoaderReference.getClassLoader(), this);
        }
 
        public static AnnotationFinder makeAnnotationFinderIfAny(ClassLoader loader, World world) {
@@ -78,7 +79,7 @@ public class ReflectionWorld extends World implements IReflectionWorld {
        }
        
        public ClassLoader getClassLoader() {
-               return this.classLoader;
+               return this.classLoaderReference.getClassLoader();
        }
        
        public AnnotationFinder getAnnotationFinder() {
@@ -107,7 +108,7 @@ public class ReflectionWorld extends World implements IReflectionWorld {
         * @see org.aspectj.weaver.World#resolveDelegate(org.aspectj.weaver.ReferenceType)
         */
        protected ReferenceTypeDelegate resolveDelegate(ReferenceType ty) {
-               return ReflectionBasedReferenceTypeDelegateFactory.createDelegate(ty, this, this.classLoader);
+               return ReflectionBasedReferenceTypeDelegateFactory.createDelegate(ty, this, this.classLoaderReference.getClassLoader());
        }
 
        /* (non-Javadoc)