/* * 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 options have been removed, or are deprecated, or are aliased. Can be extended to test other options as needed. * @library /testlibrary */ import java.util.ArrayList; import com.oracle.java.testlibrary.*; public class VMOptionsLifecycle { private static final String PRINT_FLAGS_FINAL_FORMAT = "%s\\s*:?=\\s*%s"; public static final String[] REMOVED_OPTIONS = { "CMSParPromoteBlocksToClaim", "ParCMSPromoteBlocksToClaim", "ParallelGCOldGenAllocBufferSize", "ParallelGCToSpaceAllocBufferSize", "UseGCTimeLimit", "CMSPermGenSweepingEnabled", "MaxTLERatio", "ResizeTLE", "PrintTLE", "TLEFragmentationRatio", "TLESize", "TLEThreadRatio", "UseTLE" }; /** * each entry is {[0]: alias name, [1]: alias target, [2]: value to set * (+/-/n)} */ public static final String[][] UNDEPRECATED_ALIAS_OPTIONS = { //undeprecated aliases: // --- none --- }; /** * 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[][] DEPRECATED_ALIAS_OPTIONS = { {"CMSMarkStackSizeMax", "MarkStackSizeMax", "1032"}, {"CMSMarkStackSize", "MarkStackSize", "1032"}, {"G1MarkStackSize", "MarkStackSize", "1032"}, {"ParallelMarkingThreads", "ConcGCThreads", "77"}, {"ParallelCMSThreads", "ConcGCThreads", "77"} }; public static final String[][] ALIAS_OPTIONS; // = UNDEPRECATED_ALIAS_OPTIONS + DEPRECATED_ALIAS_OPTIONS /** * each entry is {[0]: option name, [1]: value to set (+/-/n)} */ public static final String[][] DEPRECATED_SIMPLE_OPTIONS = { //deprecated options: // --- none --- }; public static final String[][] DEPRECATED_OPTIONS; // = DEPRECATED_SIMPLE_OPTIONS + DEPRECATED_ALIAS_OPTIONS static String[][] concatOptions(String[][] a, String[][] b) { String[][] result = new String[a.length + b.length][]; System.arraycopy(a, 0, result, 0, a.length); System.arraycopy(b, 0, result, a.length, b.length); return result; } static { ALIAS_OPTIONS = concatOptions(UNDEPRECATED_ALIAS_OPTIONS, DEPRECATED_ALIAS_OPTIONS); DEPRECATED_OPTIONS = concatOptions(DEPRECATED_SIMPLE_OPTIONS, DEPRECATED_ALIAS_OPTIONS); } static void testRemoved(String option, boolean normalTest) throws Throwable { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+" + option, "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); if (!normalTest) { output.shouldNotContain("Unrecognized VM option '" + option + "'"); output.shouldHaveExitValue(0); } else { output.shouldContain("Unrecognized VM option '" + option + "'"); output.shouldHaveExitValue(1); } // System.out.println("=== output ==="); // System.out.print(output.getOutput()); } /** * Turn the optionInfo into a legal -XX: command line argument. * @param optionInfo * @return */ static String makeOptionArg(String[] optionInfo) { String value = optionInfo[optionInfo.length-1]; if (value.equals("+")) { return "-XX:+" + optionInfo[0]; } else if (value.equals("-")) { return "-XX:-" + optionInfo[0]; } else { return "-XX:" + optionInfo[0] + "=" + value; } } /** * Turn the optionInfo into pattern that might match "-XX:+PrintFlagsFinal output. * @param optionInfo * @return */ 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); } /** * Test all aliased options in one jvm exec. */ static void testAliases(String[][] optionInfo, boolean normalTest) throws Throwable { ArrayList args = new ArrayList<>(); // construct args: for (String[] alias: optionInfo) { args.add(makeOptionArg(alias)); } 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); } } } /** * Test all deprecated options in one jvm exec. */ static void testDeprecated(String[][] optionInfo, boolean normalTest) throws Throwable { ArrayList args = new ArrayList<>(); // construct args: for (String[] deprecated: optionInfo) { args.add(makeOptionArg(deprecated)); } 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 for option deprecation messages: output.shouldHaveExitValue(0); for (String[] deprecated: optionInfo) { // Searching precisely for deprecation warnings is too hard at the moment. // There is no standard format. For now, just search for the option name in the output, // which should only be printed if there was some deprecation warning. String realOpt = (deprecated.length == 2) ? deprecated[0] : deprecated[1]; String match = realOpt; if (normalTest) { output.shouldMatch(match); } else { output.shouldNotMatch(match); } } } public static void main(String[] args) throws Throwable { testRemoved("UseTLAB", false); // Test the test. UseTLAB has NOT been removed. for (String str: REMOVED_OPTIONS) { testRemoved(str, true); // Test should fail for each removed option. } String[][] testTestAliases = {{"MarkStackSizeMax", "CMSMarkStackSizeMax", "1032"}}; testAliases(testTestAliases, false); // MarkStackSizeMax is NOT an alias for CMSMarkStackSizeMax. testAliases(ALIAS_OPTIONS, true); String[][] testTestDeprecated = {{"UseTLAB", "+"}}; testDeprecated(testTestDeprecated, false); // Test the test. The output should NOT mention "UseTLAB" at all. testDeprecated(DEPRECATED_OPTIONS, true); // Make sure that each deprecated option is mentioned in the output. } }