From: aclement Date: Tue, 27 May 2008 18:49:58 +0000 (+0000) Subject: 210470: preventing weaver leaks: Wraps a classloader reference in a weak reference... X-Git-Tag: V1_6_1x~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9676664596aa81eca5b32967213257afbc09a34;p=aspectj.git 210470: preventing weaver leaks: Wraps a classloader reference in a weak reference, for use everywhere inside a weaver --- diff --git a/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java b/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java index e50303b52..26812dc8e 100644 --- a/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java +++ b/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java @@ -11,8 +11,11 @@ * ******************************************************************/ package org.aspectj.weaver; +import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import org.aspectj.apache.bcel.util.ClassLoaderReference; + /** * Wraps a reference to a classloader inside a WeakReference. This should be used where we do not want the existence of * a classloader reference to prevent garbage collection of that classloader (and possibly an associated weaver instance @@ -33,12 +36,20 @@ import java.lang.ref.WeakReference; * * @author Andy Clement */ -public class WeakClassLoaderReference { +public class WeakClassLoaderReference implements ClassLoaderReference { + private int hashcode; + private WeakReference loaderRef; public WeakClassLoaderReference(ClassLoader loader) { loaderRef = new WeakReference(loader); + hashcode = loader.hashCode() * 37; + } + + public WeakClassLoaderReference(ClassLoader loader, ReferenceQueue q) { + loaderRef = new WeakReference(loader, q); + hashcode = loader.hashCode() * 37; } public ClassLoader getClassLoader() { @@ -46,5 +57,15 @@ public class WeakClassLoaderReference { // Assert instance!=null return instance; } + + public boolean equals(Object obj) { + if (!(obj instanceof WeakClassLoaderReference)) return false; + WeakClassLoaderReference other = (WeakClassLoaderReference) obj; + return (other.hashcode == hashcode); + } + + public int hashCode() { + return hashcode; + } }