Path: blob/master/test/hotspot/jtreg/compiler/rtm/cli/RTMGenericCommandLineOptionTest.java
41152 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.rtm.cli;2425import jdk.test.lib.process.ExitCode;26import jdk.test.lib.Platform;27import jdk.test.lib.cli.CommandLineOptionTest;2829import java.util.function.BooleanSupplier;3031/**32* Base for all RTM-related CLI tests.33*/34public abstract class RTMGenericCommandLineOptionTest {3536protected static final String RTM_INSTR_ERROR37= "RTM instructions are not available on this CPU";38protected static final String RTM_OS_ERROR39= "RTM is not supported on this OS version";40protected static final String RTM_UNSUPPORTED_VM_ERROR41= "RTM locking optimization is not supported in this VM";42protected static final String RTM_FOR_STACK_LOCKS_WARNING43= "UseRTMForStackLocks flag should be off when UseRTMLocking "44+ "flag is off";45protected static final String RTM_COUNT_INCR_WARNING46= "must be a power of 2, resetting it to 64";47protected static final String RTM_BIASED_LOCKING_WARNING48= "Biased locking is not supported with RTM locking; "49+ "ignoring UseBiasedLocking flag";5051protected final String optionName;52protected final String errorMessage;53protected final String experimentalOptionError;54protected final boolean isExperimental;55protected final boolean isBoolean;56protected final String defaultValue;57protected final String[] optionValues;5859/**60* Constructs new genetic RTM CLI test, for option {@code optionName} which61* has default value {@code defaultValue}. Test cases will use option's62* values passed via {@code optionValues} for verification of correct63* option processing.64*65* Test constructed using this ctor will be started on any cpu regardless66* it's architecture and supported/unsupported features.67*68* @param optionName name of option to be tested69* @param isBoolean {@code true} if option is binary70* @param isExperimental {@code true} if option is experimental71* @param defaultValue default value of tested option72* @param optionValues different option values73*/74public RTMGenericCommandLineOptionTest(75String optionName, boolean isBoolean, boolean isExperimental,76String defaultValue, String... optionValues) {77this.optionName = optionName;78this.isExperimental = isExperimental;79this.isBoolean = isBoolean;80this.defaultValue = defaultValue;81this.optionValues = optionValues;82this.errorMessage = CommandLineOptionTest.83getUnrecognizedOptionErrorMessage(optionName);84this.experimentalOptionError = CommandLineOptionTest.85getExperimentalOptionErrorMessage(optionName);86}8788public void runTestCases() throws Throwable {89if (Platform.isX86() || Platform.isX64() || Platform.isPPC()) {90if (Platform.isServer()) {91runX86SupportedVMTestCases();92} else {93runX86UnsupportedVMTestCases();94}95} else {96runNonX86TestCases();97}98}99100/**101* Runs test cases on X86 CPU if VM supports RTM locking.102* @throws Throwable103*/104protected void runX86SupportedVMTestCases() throws Throwable {105runGenericX86TestCases();106}107108/**109* Runs test cases on X86 CPU if VM does not support RTM locking.110* @throws Throwable111*/112protected void runX86UnsupportedVMTestCases() throws Throwable {113runGenericX86TestCases();114}115116/**117* Runs test cases on non-X86 CPU.118* @throws Throwable119*/120protected void runNonX86TestCases() throws Throwable {121CommandLineOptionTest.verifySameJVMStartup(122new String[] { errorMessage }, null,123String.format("Option '%s' should be unknown on non-X86CPUs.%n"124+ "JVM startup should fail", optionName), "", ExitCode.FAIL,125prepareOptionValue(defaultValue));126}127128/**129* Runs generic X86 test cases.130* @throws Throwable131*/132protected void runGenericX86TestCases() throws Throwable {133verifyJVMStartup();134verifyOptionValues();135}136137protected void verifyJVMStartup() throws Throwable {138String optionValue = prepareOptionValue(defaultValue);139String shouldFailMessage = String.format("VM option '%s' is "140+ "experimental.%nVM startup expected to fail without "141+ "-XX:+UnlockExperimentalVMOptions option", optionName);142String shouldPassMessage = String.format("VM option '%s' is "143+ "experimental%nVM startup should pass with "144+ "-XX:+UnlockExperimentalVMOptions option", optionName);145if (isExperimental) {146// verify that option is experimental147CommandLineOptionTest.verifySameJVMStartup(148new String[] { experimentalOptionError },149new String[] { errorMessage }, shouldFailMessage,150shouldFailMessage, ExitCode.FAIL, optionValue);151// verify that it could be passed if experimental options152// are unlocked153CommandLineOptionTest.verifySameJVMStartup(null,154new String[] {155experimentalOptionError,156errorMessage157},158shouldPassMessage,159"JVM should start without any warnings or errors",160ExitCode.OK,161CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,162optionValue);163} else {164// verify that option could be passed165CommandLineOptionTest.verifySameJVMStartup(null,166new String[]{errorMessage},167String.format("VM startup shuld pass with '%s' option",168optionName),169"JVM should start without any warnings or errors",170ExitCode.OK, optionValue);171}172}173174protected void verifyOptionValues() throws Throwable {175// verify default value176if (isExperimental) {177CommandLineOptionTest.verifyOptionValueForSameVM(optionName,178defaultValue,179String.format("Option '%s' is expected to have '%s' "180+ "default value", optionName, defaultValue),181CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS);182} else {183CommandLineOptionTest.verifyOptionValueForSameVM(optionName,184defaultValue,185String.format("Option '%s' is expected to have '%s' "186+ "default value", optionName, defaultValue));187}188// verify other specified option values189if (optionValues == null) {190return;191}192193for (String value : optionValues) {194if (isExperimental) {195CommandLineOptionTest.verifyOptionValueForSameVM(optionName,196value,197String.format("Option '%s' is set to have '%s' value",198optionName, value),199CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,200prepareOptionValue(value));201} else {202CommandLineOptionTest.verifyOptionValueForSameVM(optionName,203value,204String.format("Option '%s' is set to have '%s' value",205optionName, value), prepareOptionValue(value));206}207}208}209210protected String prepareOptionValue(String value) {211if (isBoolean) {212return CommandLineOptionTest.prepareBooleanFlag(optionName,213Boolean.valueOf(value));214} else {215return String.format("-XX:%s=%s", optionName, value);216}217}218}219220221