diff options
author | aclement <aclement> | 2008-05-27 18:52:47 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-05-27 18:52:47 +0000 |
commit | f08b2920cb9f6b1ab9b593b3136886c584ef772c (patch) | |
tree | 40051f9e59f6735e2f5608b8b4289a63e1e9b2f6 /loadtime | |
parent | 9f5a293b81b32acdffd484f1f65d416f18293953 (diff) | |
download | aspectj-f08b2920cb9f6b1ab9b593b3136886c584ef772c.tar.gz aspectj-f08b2920cb9f6b1ab9b593b3136886c584ef772c.zip |
210470: preventing weaver leaks: use a weak classloader ref
Diffstat (limited to 'loadtime')
-rw-r--r-- | loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java index 304476294..3dd07c694 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java @@ -37,6 +37,7 @@ import org.aspectj.weaver.ICrossReferenceHandler; import org.aspectj.weaver.Lint; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.WeakClassLoaderReference; import org.aspectj.weaver.World; import org.aspectj.weaver.Lint.Kind; import org.aspectj.weaver.bcel.BcelWeaver; @@ -96,12 +97,35 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { if (trace.isTraceEnabled()) trace.enter("<init>",this,new Object[] { deprecatedLoader, deprecatedContext }); if (trace.isTraceEnabled()) trace.exit("<init>"); } + + class SimpleGeneratedClassHandler implements GeneratedClassHandler { + private WeakClassLoaderReference loaderRef; + SimpleGeneratedClassHandler(ClassLoader loader) { + loaderRef = new WeakClassLoaderReference(loader); + } + + /** + * Callback when we need to define a Closure in the JVM + * + */ + public void acceptClass(String name, byte[] bytes) { + try { + if (shouldDump(name.replace('/', '.'), false)) { + dump(name, bytes, false); + } + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + + defineClass(loaderRef.getClassLoader(), name, bytes); // could be done lazily using the hook + } + }; protected void initialize (final ClassLoader classLoader, IWeavingContext context) { if (initialized) return; boolean success = true; - if (trace.isTraceEnabled()) trace.enter("initialize",this,new Object[] { classLoader, context }); + // if (trace.isTraceEnabled()) trace.enter("initialize",this,new Object[] { classLoader, context }); this.weavingContext = context; if (weavingContext == null) { @@ -110,25 +134,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { createMessageHandler(); - this.generatedClassHandler = new GeneratedClassHandler() { - /** - * Callback when we need to define a Closure in the JVM - * - * @param name - * @param bytes - */ - public void acceptClass(String name, byte[] bytes) { - try { - if (shouldDump(name.replace('/', '.'), false)) { - dump(name, bytes, false); - } - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - - defineClass(classLoader, name, bytes);// could be done lazily using the hook - } - }; + this.generatedClassHandler = + new SimpleGeneratedClassHandler(classLoader); List definitions = weavingContext.getDefinitions(classLoader,this); if (definitions.isEmpty()) { @@ -179,7 +186,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { * @param loader */ List parseDefinitions(final ClassLoader loader) { - if (trace.isTraceEnabled()) trace.enter("parseDefinitions",this,loader); + if (trace.isTraceEnabled()) trace.enter("parseDefinitions", this); List definitions = new ArrayList(); try { |