Skip to content

Apache Lucene open-source search software

LUCENE-4488: Enable heapdumps for Jenkins builds on supported JVMs

Uwe Schindler5455c64a19a6
diff --git a/build.xml b/build.xml
index 2a5bbee7b42..ecf16215e2c 100644
--- a/build.xml
+++ b/build.xml
@@ -30,6 +30,8 @@
<subant buildpath="lucene" target="test-help" inheritall="false" failonerror="true"/>
</target>
+ <property name="tests.heap-dump-dir" location="heapdumps"/>
+
<target name="precommit" description="Run basic checks before committing"
depends="check-svn-working-copy,validate,documentation-lint"/>
@@ -218,13 +220,11 @@
<target name="clean" description="Clean Lucene and Solr build dirs">
<delete dir="dist" />
- <sequential>
- <subant target="clean" inheritall="false" failonerror="true">
- <fileset dir="lucene" includes="build.xml" />
- <fileset dir="solr" includes="build.xml" />
- </subant>
- <delete dir="dist" failonerror="false" />
- </sequential>
+ <delete dir="${tests.heap-dump-dir}" />
+ <subant target="clean" inheritall="false" failonerror="true">
+ <fileset dir="lucene" includes="build.xml" />
+ <fileset dir="solr" includes="build.xml" />
+ </subant>
</target>
<target name="ivy-bootstrap" description="Download and install Ivy in the users ant lib dir">
@@ -309,7 +309,7 @@
<param name="run.clover" value="true"/>
<!-- must be 1, as clover does not like parallel test runs: -->
<param name="tests.jvms" value="1"/>
- <!-- Also override some other props to be fast, ignoring what's set on command line: -->
+ <!-- Also override some other props to be fast: -->
<param name="tests.multiplier" value="1"/>
<param name="tests.nightly" value="false"/>
<param name="tests.weekly" value="false"/>
@@ -326,8 +326,40 @@
<subant buildpath="." antfile="extra-targets.xml" target="-generate-clover-reports" inheritall="false" failonerror="true"/>
</target>
+ <target name="test-with-heapdumps" depends="-test-with-heapdumps-enabled,-test-with-heapdumps-disabled" description="Runs tests with heap dumps on OOM enabled (if VM supports this)"/>
+
+ <condition property="vm.supports.heapdumps">
+ <or>
+ <contains string="${java.vm.name}" substring="hotspot" casesensitive="false"/>
+ <contains string="${java.vm.name}" substring="openjdk" casesensitive="false"/>
+ <contains string="${java.vm.name}" substring="jrockit" casesensitive="false"/>
+ </or>
+ </condition>
+
+ <target name="-test-with-heapdumps-enabled" if="vm.supports.heapdumps">
+ <echo level="info" message="${java.vm.name}: Enabling heap dumps on OutOfMemoryError to dir '${tests.heap-dump-dir}'."/>
+ <mkdir dir="${tests.heap-dump-dir}"/>
+ <delete includeEmptyDirs="true">
+ <fileset dir="${tests.heap-dump-dir}" includes="**/*"/>
+ </delete>
+ <antcall inheritAll="false" target="test">
+ <param name="tests.heapdump.args" value="-XX:+HeapDumpOnOutOfMemoryError &quot;-XX:HeapDumpPath=${tests.heap-dump-dir}&quot;"/>
+ </antcall>
+ <pathconvert property="heapdumps.list" setonempty="false" pathsep="${line.separator}">
+ <fileset dir="${tests.heap-dump-dir}"/>
+ <map from="${tests.heap-dump-dir}${file.separator}" to="* "/>
+ </pathconvert>
+ <fail if="heapdumps.list" message="Some of the tests produced a heap dump, but did not fail. Maybe a suppressed OutOfMemoryError? Dumps created:${line.separator}${heapdumps.list}"/>
+ <delete dir="${tests.heap-dump-dir}"/>
+ </target>
+
+ <target name="-test-with-heapdumps-disabled" unless="vm.supports.heapdumps">
+ <echo level="warning" message="WARN: The used JVM (${java.vm.name}) does not support HPROF heap dumps on OutOfMemoryError."/>
+ <antcall target="test"/>
+ </target>
+
<!-- Jenkins tasks -->
- <target name="jenkins-hourly" depends="clean,test,validate,-jenkins-documentation-lint,jar-checksums,check-svn-working-copy"/>
+ <target name="jenkins-hourly" depends="clean,test-with-heapdumps,validate,-jenkins-documentation-lint,jar-checksums,check-svn-working-copy"/>
<target name="jenkins-maven-nightly" depends="clean,remove-maven-artifacts,run-maven-build,generate-maven-artifacts,validate-maven-dependencies"/>
diff --git a/lucene/common-build.xml b/lucene/common-build.xml
index e02f3518e60..042b089e748 100644
--- a/lucene/common-build.xml
+++ b/lucene/common-build.xml
@@ -109,6 +109,8 @@
</condition>
<property name="tests.clover.args" value=""/>
+ <property name="tests.heapdump.args" value=""/>
+
<property name="tests.tempDir" location="${build.dir}/test"/>
<property name="tests.cachefile" location="${common.dir}/tools/junit4/cached-timehints.txt" />
@@ -827,6 +829,7 @@
<!-- JVM arguments and system properties. -->
<jvmarg line="${args}"/>
+ <jvmarg line="${tests.heapdump.args}"/>
<jvmarg line="${tests.clover.args}"/>
<!-- set the number of times tests should run -->