71 /** 72 * Verify that heap size will be changed to conform 73 * min and max heap free ratios. 74 * 75 * @param minRatio value of MinHeapFreeRatio option 76 * @param useXminf used Xminf option instead of MinHeapFreeRatio 77 * @param maxRatio value of MaxHeapFreeRatio option 78 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio 79 * @param options additional options for JVM 80 */ 81 public static void positiveTest(int minRatio, boolean useXminf, 82 int maxRatio, boolean useXmaxf, boolean shrinkHeapInSteps, 83 LinkedList<String> options) throws Exception { 84 85 LinkedList<String> vmOptions = new LinkedList<>(options); 86 Collections.addAll(vmOptions, 87 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio), 88 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio), 89 "-Xmx" + MAX_HEAP_SIZE, 90 "-Xms" + HEAP_SIZE, 91 "-XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED", 92 "-XX:NewSize=" + NEW_SIZE, 93 "-XX:MaxNewSize=" + MAX_NEW_SIZE, 94 "-XX:" + (shrinkHeapInSteps ? '+' : '-') + "ShrinkHeapInSteps", 95 RatioVerifier.class.getName(), 96 Integer.toString(minRatio), 97 Integer.toString(maxRatio), 98 Boolean.toString(shrinkHeapInSteps) 99 ); 100 101 ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); 102 OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); 103 analyzer.shouldHaveExitValue(0); 104 } 105 106 /** 107 * Verify that VM will fail to start with specified ratios. 108 * 109 * @param minRatio value of MinHeapFreeRatio option 110 * @param useXminf used Xminf option instead of MinHeapFreeRatio 111 * @param maxRatio value of MaxHeapFreeRatio option 112 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio 113 * @param options additional options for JVM 114 */ 115 public static void negativeTest(int minRatio, boolean useXminf, 116 int maxRatio, boolean useXmaxf, 117 LinkedList<String> options) throws Exception { 118 119 LinkedList<String> vmOptions = new LinkedList<>(options); 120 Collections.addAll(vmOptions, 121 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio), 122 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio), 123 "-XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED", 124 "-version" 125 ); 126 ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); 127 OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); 128 analyzer.shouldHaveExitValue(1); 129 analyzer.shouldContain("Error: Could not create the Java Virtual Machine."); 130 } 131 132 /** 133 * RatioVerifier will be executed in the tested VM. 134 * It will check that real heap usage after collection lies between MinHeapFreeRatio and MaxHeapFreeRatio. 135 */ 136 public static class RatioVerifier { 137 138 private static final Unsafe unsafe = Utils.getUnsafe(); 139 140 // Size of byte array that will be allocated 141 public static final int CHUNK_SIZE = 1024; 142 // Length of byte array, that will be added to "garbage" list. 143 public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET; | 71 /** 72 * Verify that heap size will be changed to conform 73 * min and max heap free ratios. 74 * 75 * @param minRatio value of MinHeapFreeRatio option 76 * @param useXminf used Xminf option instead of MinHeapFreeRatio 77 * @param maxRatio value of MaxHeapFreeRatio option 78 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio 79 * @param options additional options for JVM 80 */ 81 public static void positiveTest(int minRatio, boolean useXminf, 82 int maxRatio, boolean useXmaxf, boolean shrinkHeapInSteps, 83 LinkedList<String> options) throws Exception { 84 85 LinkedList<String> vmOptions = new LinkedList<>(options); 86 Collections.addAll(vmOptions, 87 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio), 88 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio), 89 "-Xmx" + MAX_HEAP_SIZE, 90 "-Xms" + HEAP_SIZE, 91 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 92 "-XX:NewSize=" + NEW_SIZE, 93 "-XX:MaxNewSize=" + MAX_NEW_SIZE, 94 "-XX:" + (shrinkHeapInSteps ? '+' : '-') + "ShrinkHeapInSteps", 95 RatioVerifier.class.getName(), 96 Integer.toString(minRatio), 97 Integer.toString(maxRatio), 98 Boolean.toString(shrinkHeapInSteps) 99 ); 100 101 ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); 102 OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); 103 analyzer.shouldHaveExitValue(0); 104 } 105 106 /** 107 * Verify that VM will fail to start with specified ratios. 108 * 109 * @param minRatio value of MinHeapFreeRatio option 110 * @param useXminf used Xminf option instead of MinHeapFreeRatio 111 * @param maxRatio value of MaxHeapFreeRatio option 112 * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio 113 * @param options additional options for JVM 114 */ 115 public static void negativeTest(int minRatio, boolean useXminf, 116 int maxRatio, boolean useXmaxf, 117 LinkedList<String> options) throws Exception { 118 119 LinkedList<String> vmOptions = new LinkedList<>(options); 120 Collections.addAll(vmOptions, 121 (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio), 122 (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio), 123 "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", 124 "-version" 125 ); 126 ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); 127 OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); 128 analyzer.shouldHaveExitValue(1); 129 analyzer.shouldContain("Error: Could not create the Java Virtual Machine."); 130 } 131 132 /** 133 * RatioVerifier will be executed in the tested VM. 134 * It will check that real heap usage after collection lies between MinHeapFreeRatio and MaxHeapFreeRatio. 135 */ 136 public static class RatioVerifier { 137 138 private static final Unsafe unsafe = Utils.getUnsafe(); 139 140 // Size of byte array that will be allocated 141 public static final int CHUNK_SIZE = 1024; 142 // Length of byte array, that will be added to "garbage" list. 143 public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET; |