1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8061611 27 * @summary Test that various alias options correctly set the target options. 28 * @library /testlibrary 29 */ 30 import java.util.ArrayList; 31 import com.oracle.java.testlibrary.*; 32 33 public class GCAliasOptions8061611 { 34 35 private static final String PRINT_FLAGS_FINAL_FORMAT = "%s\\s*:?=\\s*%s"; 36 37 /** 38 * each entry is {[0]: alias name, [1]: alias target, [2]: value to set 39 * (+/-/n)}. n can be any valid value for the option. 40 */ 41 public static final String[][] ALIAS_OPTIONS = { 42 {"CMSMarkStackSizeMax", "MarkStackSizeMax", "1032"}, 43 {"CMSMarkStackSize", "MarkStackSize", "1032"}, 44 {"G1MarkStackSize", "MarkStackSize", "1032"}, 45 {"ParallelMarkingThreads", "ConcGCThreads", "77"}, 46 {"ParallelCMSThreads", "ConcGCThreads", "77"} 47 }; 48 49 /** 50 * Turn the option and value into a legal -XX: command line argument. 51 * For example,"-XX:ParallelCMSThreads=77" 52 */ 53 static String makeOptionArg(String option, String value) { 54 if (value.equals("+")) { 55 return "-XX:+" + option; 56 } else if (value.equals("-")) { 57 return "-XX:-" + option; 58 } else { 59 return "-XX:" + option + "=" + value; 60 } 61 } 62 63 /** 64 * Turn the optionInfo into pattern that might match "-XX:+PrintFlagsFinal" output. 65 * For example, match "uintx ConcGCThreads := 77 {product}" 66 */ 67 static String makeOptionFinalValue(String option, String value) { 68 if (value.equals("+")) { 69 value = "true"; 70 } else if (value.equals("-")) { 71 value = "false"; 72 } 73 return String.format(PRINT_FLAGS_FINAL_FORMAT, 74 option, value); 75 } 76 77 static void testAliases(String[][] optionInfo, boolean normalTest) throws Throwable { 78 ArrayList<String> args = new ArrayList<>(); 79 // construct args: 80 for (String[] alias: optionInfo) { 81 args.add(makeOptionArg(alias[0], alias[2])); 82 } 83 args.add("-XX:+PrintFlagsFinal"); 84 args.add("-version"); 85 86 // start vm: 87 String[] args_array = new String[args.size()]; 88 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(args_array)); 89 90 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 91 92 // check option values: 93 output.shouldHaveExitValue(0); 94 for (String[] alias: optionInfo) { 95 String match = makeOptionFinalValue(alias[1], alias[2]); 96 if (normalTest) { 97 output.shouldMatch(match); 98 } else { 99 output.shouldNotMatch(match); 100 } 101 } 102 } 103 104 public static void main(String[] args) throws Throwable { 105 // test the test: 106 String[][] testTestAliases = {{"MarkStackSizeMax", "CMSMarkStackSizeMax", "1032"}}; 107 testAliases(testTestAliases, false); // MarkStackSizeMax is NOT an alias for CMSMarkStackSizeMax. 108 109 // run real test: 110 testAliases(ALIAS_OPTIONS, true); 111 } 112 }