From 2b63b5d1d76914fa75b884e386f7f84bbcde53f4 Mon Sep 17 00:00:00 2001 From: Lev Priima Date: Tue, 24 Mar 2015 03:46:57 -0400 Subject: [PATCH] 8075071: [TEST_BUG] TimSortStackSize2.java: OOME: Java heap space: MaxHeap shrinked by MaxRAMFraction Reviewed-by: dholmes --- .../java/util/Arrays/TimSortStackSize2.java | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/jdk/test/java/util/Arrays/TimSortStackSize2.java b/jdk/test/java/util/Arrays/TimSortStackSize2.java index a456c883000..9e212fd00bd 100644 --- a/jdk/test/java/util/Arrays/TimSortStackSize2.java +++ b/jdk/test/java/util/Arrays/TimSortStackSize2.java @@ -24,22 +24,63 @@ /* * @test * @bug 8072909 - * @run main/othervm -Xms385m TimSortStackSize2 67108864 + * @library /lib/testlibrary /../../test/lib + * @build jdk.testlibrary.* + * @build TimSortStackSize2 + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI TimSortStackSize2 * @summary Test TimSort stack size on big arrays - * big tests not for regular execution on all platforms: - * run main/othervm -Xmx8g TimSortStackSize2 1073741824 - * run main/othervm -Xmx16g TimSortStackSize2 2147483644 */ import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.function.Consumer; +import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; +import jdk.testlibrary.Utils; +import sun.hotspot.WhiteBox; + public class TimSortStackSize2 { public static void main(String[] args) { - int lengthOfTest = Integer.parseInt(args[0]); + if ( args == null || args.length == 0 ){ + startMeWithArgs(); + } else { + doTestOfTwoTimSorts(Integer.parseInt(args[0])); + } + } + + private static void startMeWithArgs(){ + /* + * big tests not for regular execution on all platforms: + * run main/othervm -Xmx8g TimSortStackSize2 1073741824 + * run main/othervm -Xmx16g TimSortStackSize2 2147483644 + */ + try { + Boolean compressedOops = WhiteBox.getWhiteBox() + .getBooleanVMFlag("UseCompressedOops"); + final String xmsValue = "-Xms" + + ((compressedOops == null || compressedOops) ? "385" : "770") + + "m"; + System.out.println( "compressedOops: " + compressedOops + + "; Test will be started with \"" + xmsValue + "\""); + ProcessBuilder processBuilder = ProcessTools + .createJavaProcessBuilder(Utils.addTestJavaOpts(xmsValue, + "TimSortStackSize2", "67108864" + ) + ); + OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); + System.out.println(output.getOutput()); + output.shouldHaveExitValue(0); + } catch( Exception e ){ + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private static void doTestOfTwoTimSorts(final int lengthOfTest){ boolean passed = doTest("TimSort", lengthOfTest, (Integer [] a) -> Arrays.sort(a)); passed = doTest("ComparableTimSort", lengthOfTest, (Integer [] a) ->