# HG changeset patch # User shade # Date 1481828257 -3600 # Node ID d869414b90b419ed0bcbde02a7bc93d9d172dd66 # Parent afe1acc2f8a137f7a977c33120b356282fff31f8 Tunable min/max heap sizes. Default min heap size to 8192. diff -r afe1acc2f8a1 -r d869414b90b4 src/main/java/org/openjdk/gcbench/GCBench.java --- a/src/main/java/org/openjdk/gcbench/GCBench.java Thu Dec 15 19:40:54 2016 +0100 +++ b/src/main/java/org/openjdk/gcbench/GCBench.java Thu Dec 15 19:57:37 2016 +0100 @@ -69,9 +69,12 @@ .withRequiredArg().ofType(Mode.class).describedAs("mode") .defaultsTo(Mode.normal); - OptionSpec optMaxHeap = parser.accepts("mh", "Max heap to be used for tests. Leave unset to enable auto-detection") + OptionSpec optMaxHeap = parser.accepts("maxHeap", "Max heap to be used for tests. Leave unset to enable auto-detection") .withRequiredArg().ofType(Integer.class).describedAs("MB"); + OptionSpec optMinHeap = parser.accepts("minHeap", "Min heap to be used for tests.") + .withRequiredArg().ofType(Integer.class).describedAs("MB").defaultsTo(8192); + parser.accepts("h", "Print help."); OptionSet set = parser.parse(args); @@ -81,11 +84,11 @@ } if (set.has(optMaxHeap)) { - MaxHeapDetector.override(set.valueOf(optMaxHeap)); + HeapSizeManager.override(set.valueOf(optMinHeap), set.valueOf(optMaxHeap)); } else { pw.println("===== Calibrating max heap size"); pw.println(); - MaxHeapDetector.init(pw); + HeapSizeManager.init(set.valueOf(optMinHeap), pw); } Options opts = new OptionsBuilder() @@ -114,7 +117,7 @@ .warmupIterations(3) .warmupTime(TimeValue.seconds(1)) .measurementIterations(1) - .measurementTime(TimeValue.milliseconds(Math.max(1000, (MaxHeapDetector.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) + .measurementTime(TimeValue.milliseconds(Math.max(1000, (HeapSizeManager.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) .forks(1) .build(); break; @@ -124,7 +127,7 @@ .warmupIterations(3) .warmupTime(TimeValue.seconds(1)) .measurementIterations(1) - .measurementTime(TimeValue.milliseconds(Math.max(1000, 3*(MaxHeapDetector.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) + .measurementTime(TimeValue.milliseconds(Math.max(1000, 3*(HeapSizeManager.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) .forks(3) .build(); break; @@ -134,7 +137,7 @@ .warmupIterations(3) .warmupTime(TimeValue.seconds(1)) .measurementIterations(1) - .measurementTime(TimeValue.seconds(Math.max(1000, 10*(MaxHeapDetector.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) + .measurementTime(TimeValue.seconds(Math.max(1000, 10*(HeapSizeManager.MAX_HEAP * 1000 / targetAllocRate_MbPerSec)))) .forks(5) .build(); break; @@ -155,20 +158,20 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.plain.Objects.class, "alloc.peak.object", groupDescr + "Allocates plain Java Objects.", Dimensions.threads(), - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)) + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.plain.PrimArray.class, "alloc.peak.intarray", groupDescr + "Allocates int[] arrays of different sizes.", Dimensions.threads(), - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen(1, 10_000_000)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.plain.RefArray.class, "alloc.peak.refarray", groupDescr + "Allocates Object[] arrays of different sizes.", Dimensions.threads(), - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen(1, 10_000_000)) )); } @@ -181,7 +184,7 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.uninit.IntArray.class, "alloc.uninit.intarray", groupDescr + "Allocates uninitialized int[] arrays of different sizes.", Dimensions.threads(), - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen(1, 10_000)) )); } @@ -194,20 +197,20 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.ratelimited.Objects.class, "alloc.rated.object", groupDescr + "Allocates plain Java Objects.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)) + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.ratelimited.PrimArray.class, "alloc.rated.intarray", groupDescr + "Allocates int[] arrays of different sizes.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen(1, 10_000_000)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.ratelimited.RefArray.class, "alloc.rated.refarray", groupDescr + "Allocates Object[] arrays of different sizes.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen(1, 10_000_000)) )); } @@ -218,19 +221,19 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.retain.RefArray.class, "retain.array", groupDesc + "Retains an empty reference array of given size.", - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen_Sub(100_000, 100_000_000)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.retain.LinkedLists.class, "retain.linkedlist", groupDesc + "Retains an empty linked list of given size.", - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen_Sub(100_000, 100_000_000)) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.retain.Tree.class, "retain.tree", groupDesc + "Retains an empty tree of given size.", - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen_Sub(100_000, 100_000_000)) )); } @@ -242,21 +245,21 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.fragger.ArrayFragger.class, "fragger.array", groupDescr + "Retains a single large reference array.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.lds(4) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.fragger.TreeFragger.class, "fragger.tree", groupDescr + "Retains a binary tree of Nodes.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.lds(4) )); tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.fragger.LinkedListFragger.class, "fragger.linkedlist", groupDescr + "Retains a LinkedList.", true, - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.lds(4) )); } @@ -266,7 +269,7 @@ tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.sieve.Objects.class, "sieve.object", groupDescr + "Allocates Java Objects.", - Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)), + Dimensions.heapSize(Sequence.powersOfTwo_WithMax(HeapSizeManager.MIN_HEAP, HeapSizeManager.MAX_HEAP)), Dimensions.size(Sequence.powersOfTen_Sub(1, 10_000)) )); } diff -r afe1acc2f8a1 -r d869414b90b4 src/main/java/org/openjdk/gcbench/HeapSizeManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/gcbench/HeapSizeManager.java Thu Dec 15 19:57:37 2016 +0100 @@ -0,0 +1,57 @@ +package org.openjdk.gcbench; + +import org.openjdk.gcbench.util.Dummy; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.VerboseMode; + +import java.io.PrintWriter; + +public class HeapSizeManager { + + public static int MAX_HEAP; + public static int MIN_HEAP; + + public static void override(int min, int max) { + MAX_HEAP = max; + MIN_HEAP = max; + } + + public static void init(int min, PrintWriter pw) { + int baseHeapMB = 1000; + int latestSuccessMB = 0; + boolean progress; + do { + progress = false; + for (int incr = 1000; incr < Integer.MAX_VALUE; incr *= 2) { + int heapGB = baseHeapMB + incr; + pw.print(heapGB + "? "); + pw.flush(); + Options opts = new OptionsBuilder() + .include(Dummy.class.getCanonicalName()) + .threads(1) + .jvmArgsAppend("-Xmx" + heapGB + "m", "-Xms" + heapGB + "m", "-XX:+AlwaysPreTouch") + .verbosity(VerboseMode.SILENT) + .build(); + try { + new Runner(opts).runSingle(); + latestSuccessMB = heapGB; + progress = true; + } catch (RunnerException e) { + baseHeapMB = latestSuccessMB; + break; + } + } + } while (progress); + + pw.println(); + pw.println("Max heap size is " + latestSuccessMB + " Mb"); + pw.println(); + + MIN_HEAP = min; + MAX_HEAP = latestSuccessMB; + } + +} diff -r afe1acc2f8a1 -r d869414b90b4 src/main/java/org/openjdk/gcbench/MaxHeapDetector.java --- a/src/main/java/org/openjdk/gcbench/MaxHeapDetector.java Thu Dec 15 19:40:54 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package org.openjdk.gcbench; - -import org.openjdk.gcbench.util.Dummy; -import org.openjdk.jmh.runner.Runner; -import org.openjdk.jmh.runner.RunnerException; -import org.openjdk.jmh.runner.options.Options; -import org.openjdk.jmh.runner.options.OptionsBuilder; -import org.openjdk.jmh.runner.options.VerboseMode; - -import java.io.PrintWriter; - -public class MaxHeapDetector { - - public static int MAX_HEAP; - - public static void override(int value) { - MAX_HEAP = value; - } - - public static void init(PrintWriter pw) { - int baseHeapMB = 1000; - int latestSuccessMB = 0; - boolean progress; - do { - progress = false; - for (int incr = 1000; incr < Integer.MAX_VALUE; incr *= 2) { - int heapGB = baseHeapMB + incr; - pw.print(heapGB + "? "); - pw.flush(); - Options opts = new OptionsBuilder() - .include(Dummy.class.getCanonicalName()) - .threads(1) - .jvmArgsAppend("-Xmx" + heapGB + "m", "-Xms" + heapGB + "m", "-XX:+AlwaysPreTouch") - .verbosity(VerboseMode.SILENT) - .build(); - try { - new Runner(opts).runSingle(); - latestSuccessMB = heapGB; - progress = true; - } catch (RunnerException e) { - baseHeapMB = latestSuccessMB; - break; - } - } - } while (progress); - - pw.println(); - pw.println("Max heap size is " + latestSuccessMB + " Mb"); - pw.println(); - - MAX_HEAP = latestSuccessMB; - } - -} diff -r afe1acc2f8a1 -r d869414b90b4 src/main/java/org/openjdk/gcbench/tests/Dimensions.java --- a/src/main/java/org/openjdk/gcbench/tests/Dimensions.java Thu Dec 15 19:40:54 2016 +0100 +++ b/src/main/java/org/openjdk/gcbench/tests/Dimensions.java Thu Dec 15 19:57:37 2016 +0100 @@ -1,11 +1,11 @@ package org.openjdk.gcbench.tests; -import org.openjdk.gcbench.MaxHeapDetector; +import org.openjdk.gcbench.HeapSizeManager; public class Dimensions { public static Dimension heapSize(int steps) { - int maxHeap = MaxHeapDetector.MAX_HEAP; + int maxHeap = HeapSizeManager.MAX_HEAP; return new Dimension(DimensionType.HEAPSIZE, Sequence.steps(maxHeap / 16, maxHeap - maxHeap / 16, steps)); } @@ -14,7 +14,7 @@ } public static Dimension lds(int steps) { - int maxHeap = MaxHeapDetector.MAX_HEAP; + int maxHeap = HeapSizeManager.MAX_HEAP; return new Dimension(DimensionType.LDS, Sequence.steps(maxHeap / 16, maxHeap - maxHeap / 16, steps)); }