Bug 161137

Summary: memory leak when doing post-compile time weaving
Product: [Tools] AspectJ Reporter: Daniel Abramovich <dabramovich>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: aclement
Version: DEVELOPMENT   
Target Milestone: 1.6.0   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
zip file that contains scripts to reproduce none

Description Daniel Abramovich CLA 2006-10-16 16:14:28 EDT
If you weave (post-compile time) a large number jars within the same ant invocation (without forking) you will reliably get a "java.lang.OutOfMemoryError: PermGen space". I

This was tested with Java 1.5.0_09-b01, AspectJ nightly from 10-11-2006 and 1.5.2. 

Test case is an ant build script that just weaves a jar (log4j.jar) and then deletes the output jar in a loop. After 31 iteration I get the OutOfMemory error. The aspect that I'm weaving is just a simple tracer aspect with a join point doesn't even match the classes in the log4.jar.
Comment 1 Daniel Abramovich CLA 2006-10-16 16:20:39 EDT
Created attachment 52072 [details]
zip file that contains scripts to reproduce

Contains a zip file with an ant build script that will continually weave a jar and cause an OutOfMemory error. See contained readme.txt for other instructions.
Comment 2 Andrew Clement CLA 2006-10-18 05:18:33 EDT
Permgen problems indicate leaking classloaders holding onto classes.  If I turn on -verbose:class and run your build.xml then I can see all the AspectJ classes are loaded many times (if we crash on the 15th iteration, I see they've been loaded 15times).  If I remove the <antcall> in your xml and inline the iajc call at that point, I see the classes loaded once and the jar is woven fine any number of times (it is much faster too).  This is all because <antcall> spawns a new classloader that is causing the reload of the whole compiler/weaver.

The problem is I can't determine if it is AspectJ that has an anchored classloader reference in static somewhere - I can't see how we could leak classloader references when not loadtime weaving.
Comment 3 Daniel Abramovich CLA 2006-10-18 13:36:54 EDT
So is it an Ant bug that after the antcall invocation the new classloader isn't released? 

As an aside, knowing that it's the <antcall> that's was causing the problem, I was able to "inline" the <iajc> invocation by using the ant <macrodef> tag (learn something every day). 

As a further aside, the way we're using a iajc is to do post-compile time weaving of numerous jars that have already been built. Right now there isn't a way with iajc to provide a list of jars and have each jar be woven in place. 
Comment 4 Andrew Clement CLA 2007-10-25 08:08:18 EDT
investigate for 1.5.4 - whether there is something to document here or a particular level of Ant to prereq.
Comment 5 Andrew Clement CLA 2008-01-22 15:51:19 EST
looks fixed in Ant 1.7.0 - your test program runs with that level.  Possibly related blog post: http://www.mailinglistarchive.com/dev@ant.apache.org/msg04776.html