1

We have a Jenkins job for testing our application. When executing we get the famous OutOfMemoryError while executing our target that generates the junitreport using the following snippet.

        <junitreport todir="${tmp.dir}/reports-test-shared">
            <fileset dir="${tmp.dir}/reports-test-shared">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="html" />
        </junitreport>

The exact stack trace we get is the following.

/app/ci/jenkins/jobs/FLEETperfect Trunk Junit Test MOS/workspace/trunk/com.bsiag.fleet.build/build.xml:818: java.lang.OutOfMemoryError: Java heap space
    at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1380)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanCDATASection(XMLDocumentFragmentScannerImpl.java:1654)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2986)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180)
    at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.createDocument(XMLResultAggregator.java:254)
    at org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator.execute(XMLResultAggregator.java:144)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    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)

Edit: Line 818 in our build.xml is the junitreport task shown above

I have already looked at some of the suggestions given in other SO question such as here, here and here.

The most commonly given advice is

  • Increase Xms and Xms in JAVA_OPTS
  • Increase Xmx and Xms in ANT_OPTS

Here is what I have done so far:

  • Set env variable JAVA_OPTS to "-Xms512m -Xmx2048m"
  • Set env variable ANT_OPTS to "-Xms512m -Xmx2048m"
  • Created setenv.sh in tomcat/bin directory where I do a: export JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx2048m"
  • Added "-XX:MaxPermSize=256m" to env variables JAVA_OPTS and ANT_OPTS

My problem is the following. I don't know if the memory settings I make are the ones that are taken by ANT to use for running the report generation (junitreport)

Where do I have to increase the heap size in order for junitreport to terminate without an OutOfMemoryError?

Community
  • 1
  • 1
Tobias
  • 4,999
  • 7
  • 34
  • 40

4 Answers4

5

A problem like this might be fixed using another approach. Instead of increasing the heap space I tried to find the reason for such a big space requirement. I found a test that wrote a lot of information to sysout. That caused the resulting xml-file to be >200mb large. Apparently too large for a heap size of 2 or 3 gb.

Tobias
  • 4,999
  • 7
  • 34
  • 40
  • I found something similar. One test in particular was outputting so much trace information that it was causing the junitreport task to fail. Turning off traces solved the problem. If, at a later time, the test fails for some reason, it is a trivial matter to turn traces on for the debugging act. – PKCLsoft Jan 29 '15 at 04:13
1

Try setting the maxmemory option of the junit ant target as follows;

<junit maxmemory="512m" fork="true">

Note that according to the junit ant target documentation you need to set the fork="true" in order for the maxmemory element to be taken. Otherwise it is ignored.

dinukadev
  • 2,279
  • 17
  • 22
  • Sorry, I didn't mention that we don't use the junit task to test but pde.launch.test.product. – Tobias Dec 06 '12 at 07:26
1

This error has been raised in ANT bug 34342. The general consensus is that it's caused by excessive memory consumption in the XSLT used to generate the report, and it WON'T be fixed in ANT.

What has worked for me has been to increase the maximum heap size passed to ant, eg -Xmx3304m

In Jenkins you can pass the maximum heap size to ANT in InvokeAnt>Advanced>JavaOptions and adding something like -Xmx2000m

Regarding the actual maximum heap size value, it is recommended that it should be either 1/4th of physical memory or 1GB, whichever is smaller. You may need to go beyond the 1GB limit to avoid this memory error however. See Garbage Collector Ergonomics guide on the Oracle website.

Ivo Bosticky
  • 6,338
  • 6
  • 34
  • 35
0

Please try adding,

-Xms512m
-Xmx1024m
-XX:MaxPermSize=256m
  • Do you mean explicitly setting the heap sizes to that values or setting them in general? I set the MaxPermSize but it didn't help. – Tobias Dec 06 '12 at 08:27