I recently did a good amount of code change (due to a 3rd party library upgrade) in my java project. It resulted in my ant compilation task to go outofmemory (Heap space - old generation).
I was using 1G of Xmx earlier, I have to use 2G now for successful compilation. I have profiled the javac process, but I do not get much insight. I have enabled verbose output and I find that it goes out of memory while loading the classes.
Is there a way to find if there is a memory leak in a javac program?
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlAnyElement.class)]]
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlAttribute.class)]]
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlSchemaType.class)]]
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlElementDecl.class)]]
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlSeeAlso.class)]]
javac] [loading ZipFileIndexFileObject[C:\Dev\jdks\jdk7\jre\lib\rt.jar(javax/xml/bind/annotation/XmlElement.class)]]
javac]
javac]
javac] The system is out of resources.
javac] Consult the following stack trace for details.
javac] java.lang.OutOfMemoryError: Java heap space
javac] at com.sun.tools.javac.code.Scope$ImportScope.makeEntry(Scope.java:515)
javac] at com.sun.tools.javac.code.Scope.enter(Scope.java:219)
javac] at com.sun.tools.javac.code.Scope.enter(Scope.java:201)
javac] at com.sun.tools.javac.code.Scope$StarImportScope.importAll(Scope.java:540)
javac] at com.sun.tools.javac.comp.MemberEnter.importAll(MemberEnter.java:147)
javac] at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:522)
javac] at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
javac] at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:401)
javac] at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:876)
javac] at com.sun.tools.javac.code.Symbol.complete(Symbol.java:421)
javac] at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:821)
javac] at com.sun.tools.javac.comp.Enter.complete(Enter.java:491)
javac] at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
javac] at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
javac] at com.sun.tools.javac.main.Main.compile(Main.java:439)
Most likely your javac
just needs more memory than the default.
The more complex the code, the more memory it uses. This is unlikely to be a bug or because you are using the wrong JAR.
I would make sure you are using the latest update in case it's an issue which has been fixed but this is unlikely to make a difference.