< prev index next >

test/gc/arguments/TestMaxMinHeapFreeRatioFlags.java

Print this page




  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 */
  23 
  24 /*
  25  * @test TestMaxMinHeapFreeRatioFlags
  26  * @key gc
  27  * @summary Verify that heap size changes according to max and min heap free ratios.
  28  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management
  31  * @run driver/timeout=240 TestMaxMinHeapFreeRatioFlags
  32  */
  33 
  34 import java.util.LinkedList;
  35 import java.util.Arrays;
  36 import java.util.Collections;
  37 import jdk.test.lib.process.OutputAnalyzer;
  38 import jdk.test.lib.process.ProcessTools;
  39 import jdk.test.lib.Utils;
  40 import jdk.test.lib.unsafe.UnsafeHelper;
  41 import jdk.internal.misc.Unsafe;
  42 
  43 public class TestMaxMinHeapFreeRatioFlags {
  44 
  45     public static final long M = 1024 * 1024;
  46     public static final long MAX_HEAP_SIZE = 200 * M;
  47     public static final long HEAP_SIZE = 10 * M;
  48     public static final long MAX_NEW_SIZE = 20 * M;
  49     public static final long NEW_SIZE = 5 * M;
  50 
  51     public static void main(String args[]) throws Exception {
  52         LinkedList<String> options = new LinkedList<>(
  53                 Arrays.asList(Utils.getFilteredTestJavaOpts("-XX:[^ ]*HeapFreeRatio","-XX:\\+ExplicitGCInvokesConcurrent"))
  54         );
  55 
  56         negativeTest(20, false, 10, true, options);
  57         negativeTest(100, true, 0, false, options);
  58         negativeTest(101, false, 50, false, options);
  59         negativeTest(49, true, 102, true, options);
  60         negativeTest(-1, false, 50, false, options);


 117 
 118         LinkedList<String> vmOptions = new LinkedList<>(options);
 119         Collections.addAll(vmOptions,
 120                 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
 121                 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
 122                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
 123                 "-version"
 124         );
 125         ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
 126         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 127         analyzer.shouldHaveExitValue(1);
 128         analyzer.shouldContain("Error: Could not create the Java Virtual Machine.");
 129     }
 130 
 131     /**
 132      * RatioVerifier will be executed in the tested VM.
 133      * It will check that real heap usage after collection lies between MinHeapFreeRatio and MaxHeapFreeRatio.
 134      */
 135     public static class RatioVerifier {
 136 
 137         private static final Unsafe unsafe = UnsafeHelper.getUnsafe();
 138 
 139         // Size of byte array that will be allocated
 140         public static final int CHUNK_SIZE = 1024;
 141         // Length of byte array, that will be added to "garbage" list.
 142         public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET;
 143         // Amount of tries to force heap shrinking/expansion using GC
 144         public static final int GC_TRIES = 10;
 145 
 146         // Value that will be added/substracted from expected min/max heap free ratio
 147         // during memory allocation to make sure that specified limit will be exceeded.
 148         public static final double OVERLOAD = 0.05;
 149         // Acceptable heap free ratio limit exceedance: verification will fail if
 150         // actual ratio is lower than expected min heap free ratio - VARIANCE or
 151         // higher than expected max heap free ratio + VARIANCE.
 152         public static final double VARIANCE = 0.025;
 153 
 154         public static LinkedList<Object> garbage = new LinkedList<>();
 155 
 156         public static void main(String args[]) throws Exception {
 157             if (args.length != 3) {




  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 */
  23 
  24 /*
  25  * @test TestMaxMinHeapFreeRatioFlags
  26  * @key gc
  27  * @summary Verify that heap size changes according to max and min heap free ratios.
  28  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management
  31  * @run driver/timeout=240 TestMaxMinHeapFreeRatioFlags
  32  */
  33 
  34 import java.util.LinkedList;
  35 import java.util.Arrays;
  36 import java.util.Collections;
  37 import jdk.test.lib.process.OutputAnalyzer;
  38 import jdk.test.lib.process.ProcessTools;
  39 import jdk.test.lib.Utils;

  40 import jdk.internal.misc.Unsafe;
  41 
  42 public class TestMaxMinHeapFreeRatioFlags {
  43 
  44     public static final long M = 1024 * 1024;
  45     public static final long MAX_HEAP_SIZE = 200 * M;
  46     public static final long HEAP_SIZE = 10 * M;
  47     public static final long MAX_NEW_SIZE = 20 * M;
  48     public static final long NEW_SIZE = 5 * M;
  49 
  50     public static void main(String args[]) throws Exception {
  51         LinkedList<String> options = new LinkedList<>(
  52                 Arrays.asList(Utils.getFilteredTestJavaOpts("-XX:[^ ]*HeapFreeRatio","-XX:\\+ExplicitGCInvokesConcurrent"))
  53         );
  54 
  55         negativeTest(20, false, 10, true, options);
  56         negativeTest(100, true, 0, false, options);
  57         negativeTest(101, false, 50, false, options);
  58         negativeTest(49, true, 102, true, options);
  59         negativeTest(-1, false, 50, false, options);


 116 
 117         LinkedList<String> vmOptions = new LinkedList<>(options);
 118         Collections.addAll(vmOptions,
 119                 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
 120                 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
 121                 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
 122                 "-version"
 123         );
 124         ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
 125         OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
 126         analyzer.shouldHaveExitValue(1);
 127         analyzer.shouldContain("Error: Could not create the Java Virtual Machine.");
 128     }
 129 
 130     /**
 131      * RatioVerifier will be executed in the tested VM.
 132      * It will check that real heap usage after collection lies between MinHeapFreeRatio and MaxHeapFreeRatio.
 133      */
 134     public static class RatioVerifier {
 135 
 136         private static final Unsafe unsafe = Unsafe.getUnsafe();
 137 
 138         // Size of byte array that will be allocated
 139         public static final int CHUNK_SIZE = 1024;
 140         // Length of byte array, that will be added to "garbage" list.
 141         public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET;
 142         // Amount of tries to force heap shrinking/expansion using GC
 143         public static final int GC_TRIES = 10;
 144 
 145         // Value that will be added/substracted from expected min/max heap free ratio
 146         // during memory allocation to make sure that specified limit will be exceeded.
 147         public static final double OVERLOAD = 0.05;
 148         // Acceptable heap free ratio limit exceedance: verification will fail if
 149         // actual ratio is lower than expected min heap free ratio - VARIANCE or
 150         // higher than expected max heap free ratio + VARIANCE.
 151         public static final double VARIANCE = 0.025;
 152 
 153         public static LinkedList<Object> garbage = new LinkedList<>();
 154 
 155         public static void main(String args[]) throws Exception {
 156             if (args.length != 3) {


< prev index next >