/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 8061611 * @summary Test that various alias options correctly set the target options. * @library /testlibrary */ import java.util.ArrayList; import com.oracle.java.testlibrary.*; public class GCAliasOptions8061611 { private static final String PRINT_FLAGS_FINAL_FORMAT = "%s\\s*:?=\\s*%s"; /** * each entry is {[0]: alias name, [1]: alias target, [2]: value to set * (+/-/n)}. n can be any valid value for the option. */ public static final String[][] ALIAS_OPTIONS = { {"CMSMarkStackSizeMax", "MarkStackSizeMax", "1032"}, {"CMSMarkStackSize", "MarkStackSize", "1032"}, {"G1MarkStackSize", "MarkStackSize", "1032"}, {"ParallelMarkingThreads", "ConcGCThreads", "77"}, {"ParallelCMSThreads", "ConcGCThreads", "77"} }; /** * Turn the option and value into a legal -XX: command line argument. * For example,"-XX:ParallelCMSThreads=77" */ static String makeOptionArg(String option, String value) { if (value.equals("+")) { return "-XX:+" + option; } else if (value.equals("-")) { return "-XX:-" + option; } else { return "-XX:" + option + "=" + value; } } /** * Turn the optionInfo into pattern that might match "-XX:+PrintFlagsFinal" output. * For example, match "uintx ConcGCThreads := 77 {product}" */ static String makeOptionFinalValue(String option, String value) { if (value.equals("+")) { value = "true"; } else if (value.equals("-")) { value = "false"; } return String.format(PRINT_FLAGS_FINAL_FORMAT, option, value); } static void testAliases(String[][] optionInfo, boolean normalTest) throws Throwable { ArrayList args = new ArrayList<>(); // construct args: for (String[] alias: optionInfo) { args.add(makeOptionArg(alias[0], alias[2])); } args.add("-XX:+PrintFlagsFinal"); args.add("-version"); // start vm: String[] args_array = new String[args.size()]; ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(args_array)); OutputAnalyzer output = new OutputAnalyzer(pb.start()); // check option values: output.shouldHaveExitValue(0); for (String[] alias: optionInfo) { String match = makeOptionFinalValue(alias[1], alias[2]); if (normalTest) { output.shouldMatch(match); } else { output.shouldNotMatch(match); } } } public static void main(String[] args) throws Throwable { // test the test: String[][] testTestAliases = {{"MarkStackSizeMax", "CMSMarkStackSizeMax", "1032"}}; testAliases(testTestAliases, false); // MarkStackSizeMax is NOT an alias for CMSMarkStackSizeMax. // run real test: testAliases(ALIAS_OPTIONS, true); } }