1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* 25 * @test TestLoopMiningArguments 26 * @summary Test that loop mining arguments are sane 27 * @key gc 28 * @library /test/lib 29 * @run driver TestLoopMiningArguments 30 */ 31 32 import java.util.*; 33 34 import jdk.test.lib.Asserts; 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 public class TestLoopMiningArguments { 39 40 public static void testWith(String msg, boolean cls, int iters, String... args) throws Exception { 41 String[] cmds = Arrays.copyOf(args, args.length + 2); 42 cmds[args.length] = "-XX:+PrintFlagsFinal"; 43 cmds[args.length + 1] = "-version"; 44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); 45 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 46 output.shouldHaveExitValue(0); 47 output.shouldContain("UseCountedLoopSafepoints"); 48 output.shouldContain("LoopStripMiningIter"); 49 50 Asserts.assertEQ(output.firstMatch("(.+?) UseCountedLoopSafepoints.+?= (.+?) (.+?)", 2), Boolean.toString(cls), msg + ", but got wrong CLS"); 51 Asserts.assertEQ(output.firstMatch("(.+?) LoopStripMiningIter.+?= (.+?) (.+?)", 2), String.valueOf(iters), msg + ", but got wrong LSM"); 52 } 53 54 public static void main(String[] args) throws Exception { 55 testDefaultGC(); 56 testShenandoah(); 57 } 58 59 public static void testDefaultGC() throws Exception { 60 testWith("Default GC should have CLS enabled, LSM = 1000", 61 true, 1000); 62 63 testWith("Default GC with +CLS should set LSM = 1", 64 true, 1, 65 "-XX:+UseCountedLoopSafepoints" 66 ); 67 68 testWith("Default GC with +CLS should not override LSM>1", 69 true, 10, 70 "-XX:LoopStripMiningIter=10", 71 "-XX:+UseCountedLoopSafepoints" 72 ); 73 74 testWith("Default GC with +CLS should not override LSM=1", 75 true, 1, 76 "-XX:LoopStripMiningIter=1", 77 "-XX:+UseCountedLoopSafepoints" 78 ); 79 80 testWith("Default GC with +CLS should override LSM=0 to 1", 81 true, 1, 82 "-XX:LoopStripMiningIter=0", 83 "-XX:+UseCountedLoopSafepoints" 84 ); 85 86 testWith("Default GC with -CLS should set LSM = 0", 87 false, 0, 88 "-XX:-UseCountedLoopSafepoints" 89 ); 90 91 testWith("Default GC with -CLS should override LSM to 0", 92 false, 0, 93 "-XX:LoopStripMiningIter=10", 94 "-XX:-UseCountedLoopSafepoints" 95 ); 96 } 97 98 public static void testShenandoah() throws Exception { 99 testWith("Shenandoah should have CLS and LSM enabled", 100 true, 1000, 101 "-XX:+UnlockExperimentalVMOptions", 102 "-XX:+UseShenandoahGC" 103 ); 104 105 testWith("Shenandoah with +CLS should set LSM = 1", 106 true, 1, 107 "-XX:+UnlockExperimentalVMOptions", 108 "-XX:+UseShenandoahGC", 109 "-XX:+UseCountedLoopSafepoints" 110 ); 111 112 testWith("Shenandoah GC with +CLS should not override LSM>1", 113 true, 10, 114 "-XX:+UnlockExperimentalVMOptions", 115 "-XX:+UseShenandoahGC", 116 "-XX:LoopStripMiningIter=10", 117 "-XX:+UseCountedLoopSafepoints" 118 ); 119 120 testWith("Shenandoah GC with +CLS should not override LSM=1", 121 true, 1, 122 "-XX:+UnlockExperimentalVMOptions", 123 "-XX:+UseShenandoahGC", 124 "-XX:LoopStripMiningIter=1", 125 "-XX:+UseCountedLoopSafepoints" 126 ); 127 128 testWith("Shenandoah GC with +CLS should override LSM=0 to 1", 129 true, 1, 130 "-XX:+UnlockExperimentalVMOptions", 131 "-XX:+UseShenandoahGC", 132 "-XX:LoopStripMiningIter=0", 133 "-XX:+UseCountedLoopSafepoints" 134 ); 135 136 testWith("Shenandoah GC with -CLS should set LSM = 0", 137 false, 0, 138 "-XX:+UnlockExperimentalVMOptions", 139 "-XX:+UseShenandoahGC", 140 "-XX:-UseCountedLoopSafepoints" 141 ); 142 143 testWith("Shenandoah GC with -CLS should override LSM to 0", 144 false, 0, 145 "-XX:+UnlockExperimentalVMOptions", 146 "-XX:+UseShenandoahGC", 147 "-XX:LoopStripMiningIter=10", 148 "-XX:-UseCountedLoopSafepoints" 149 ); 150 } 151 152 }