Search code examples
javaeclipsejavaceclipse-jdt

Eclipse JDT Batch Compiler OutOfMemoryError


I'm trying to use a multi-threaded compiler to decrease the duration of our build and I found that the eclipse JDT Batch Compiler does just that.

When I switched to the JDT compiler however I'm getting an OutOfMemoryError. Increasing the heap size doesn't help.

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...
Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.io.BufferedReader.<init>(BufferedReader.java:80)
        at java.io.BufferedReader.<init>(BufferedReader.java:91)
...

Here is the relevant part of our build.xml.

<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<javac srcdir="${env.BUILDSRC}" 
       destdir="${env.BUILDBIN}" 
       includeantruntime="false"
       debug="on" 
       deprecation="no" 
       target="1.6" 
       source="1.6"
       fork="true" 
       executable="/opt/java/jdk1.6.0_65_64bit/bin/javac"
       memoryInitialSize="1024M"
       memoryMaximumSize="2560M"
>
<compilerarg compiler="org.eclipse.jdt.core.JDTCompilerAdapter" line="-1.6"/>

Solution

  • The JDTCompilerAdapter does not support 'fork' therefore it is compiling in the same process running ant. This is evident from the output:

    Since compiler setting isn't classic or modern, ignoring fork setting.

    You must increase the memory usage allocated to ant, I did this with ANT_OPTS:

    export ANT_OPTS="-Xmx3584M"