ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Chan <cchan...@yahoo.com>
Subject "OutOfMemoryException: PermGen space" error with Ant?
Date Fri, 22 Jun 2012 23:10:12 GMT


Hello,

I was using dbunit's Ant integration and have a for loop that exports a bunch of dataset into
many small xml files (less than 
5-50kb each). After repeating <dbunit> task for ~50 times, I got an OutOfMemoryException:
PermGen space.

(DbUnit v2.4.8 w/ Ant 1.8.2)
C:\test\build.xml:364: java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1124)
        at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1295)
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1351)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1064)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1124)
        at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1295)
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1351)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1064)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1124)
        at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1295)
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1351)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1064)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1124)
        at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1295)

Although I read that using -Xmx256m will solve the problem, I am curious why
this problem occurred in the first place? I am able to import a single 50MB xml file 
without 
specifying -Xmx option, so in theory, exporting 100 50kb xml files 
should NOT cause any problems. Also, the problem can be simulated 
by repeating the following ~100 times in a single Ant task.

        <target name="test-dbunit-export>

                <!-- export individual dataset -->
                <dbunit driver="${mysql.driver}"
                        url="${mysql.url}/database"
                        userid="${mysql.userid}"
                        password="${mysql.password}"
                        classpath="${mysql.classpath}">
                   <export format="xml" dest="${dbunit.data.dir}/test1.xml">
                      <query name="tableQuery" sql="SELECT * FROM table
WHERE column=''"/>
                   </export>
                 </dbunit>

                 <dbunit> ... </dbunit>
                 <dbunit> ... </dbunit>
                 <dbunit> ... </dbunit>
                  ...  <!-- repeat dbunit many times! -->
                 <dbunit> ... </dbunit>

      </target>

When I look at task manager, the Java process (running Ant) seems to consume more and more
memory, once it reaches above 130MB, the exception is 
thrown. Is there some sort optimization that could be done in the code to alleviate this problem?

I also tried the latest Ant 1.8.4, with similar errors:
java.lang.OutOfMemoryError: PermGen space
        at java.lang.Throwable.getStackTraceElement(Native Method)
        at java.lang.Throwable.getOurStackTrace(Throwable.java:591)
        at java.lang.Throwable.printStackTrace(Throwable.java:462)
        at java.lang.Throwable.printStackTrace(Throwable.java:451)
        at org.apache.tools.ant.Main.runBuild(Main.java:838)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
PermGen space java.lang.OutOfMemoryError: PermGen space
        at java.lang.Runtime.exit(Runtime.java:90)
        at java.lang.System.exit(System.java:904)
        at org.apache.tools.ant.Main.exit(Main.java:245)
        at org.apache.tools.ant.Main.startAnt(Main.java:235)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Thank you!
Charles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message