Path: blob/master/test/hotspot/jtreg/compiler/rtm/cli/RTMLockingAwareTest.java
41152 views
/*1* Copyright (c) 2014, 2016, 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.cli.CommandLineOptionTest;2728import java.util.LinkedList;29import java.util.List;3031/**32* Base for all RTM-related CLI tests on options whose processing depends33* on UseRTMLocking value.34*35* Since UseRTMLocking option could be used when both CPU and VM supports RTM36* locking, this test will be skipped on all unsupported configurations.37*/38public abstract class RTMLockingAwareTest39extends RTMGenericCommandLineOptionTest {40protected final String warningMessage;41protected final String[] correctValues;42protected final String[] incorrectValues;43/**44* Constructs new test for option {@code optionName} that should be executed45* only on CPU with RTM support.46* Test will be executed using set of correct values from47* {@code correctValues} and set of incorrect values from48* {@code incorrectValues}.49*50* @param optionName name of option to be tested51* @param isBoolean {@code true} if tested option is binary52* @param isExperimental {@code true} if tested option is experimental53* @param defaultValue default value of tested option54* @param correctValues array with correct values, that should not emit55* {@code warningMessage} to VM output56* @param incorrectValues array with incorrect values, that should emit57* {@code waningMessage} to VM output58* @param warningMessage warning message associated with tested option59*/60protected RTMLockingAwareTest(String optionName, boolean isBoolean,61boolean isExperimental, String defaultValue,62String[] correctValues, String[] incorrectValues,63String warningMessage) {64super(optionName, isBoolean, isExperimental, defaultValue);65this.correctValues = correctValues;66this.incorrectValues = incorrectValues;67this.warningMessage = warningMessage;68}6970@Override71protected void verifyJVMStartup() throws Throwable {72// Run generic sanity checks73super.verifyJVMStartup();74// Verify how option values will be processed depending on75// UseRTMLocking value.76if (correctValues != null) {77for (String correctValue : correctValues) {78// For correct values it is expected to see no warnings79// regardless to UseRTMLocking80verifyStartupWarning(correctValue, true, false);81verifyStartupWarning(correctValue, false, false);82}83}8485if (incorrectValues != null) {86for (String incorrectValue : incorrectValues) {87// For incorrect values it is expected to see warning88// only with -XX:+UseRTMLocking89verifyStartupWarning(incorrectValue, true, true);90verifyStartupWarning(incorrectValue, false, false);91}92}93}9495@Override96protected void verifyOptionValues() throws Throwable {97super.verifyOptionValues();98// Verify how option values will be setup after processing99// depending on UseRTMLocking value100if (correctValues != null) {101for (String correctValue : correctValues) {102// Correct value could be set up regardless to UseRTMLocking103verifyOptionValues(correctValue, false, correctValue);104verifyOptionValues(correctValue, true, correctValue);105}106}107108if (incorrectValues != null) {109for (String incorrectValue : incorrectValues) {110// With -XX:+UseRTMLocking, incorrect value will be changed to111// default value.112verifyOptionValues(incorrectValue, false, incorrectValue);113verifyOptionValues(incorrectValue, true, defaultValue);114}115}116}117118private void verifyStartupWarning(String value, boolean useRTMLocking,119boolean isWarningExpected) throws Throwable {120String warnings[] = new String[] { warningMessage };121List<String> options = new LinkedList<>();122options.add(CommandLineOptionTest.prepareBooleanFlag("UseRTMLocking",123useRTMLocking));124125if (isExperimental) {126options.add(CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS);127}128options.add(prepareOptionValue(value));129130String errorString = String.format("JVM should start with option '%s'"131+ "'%nWarnings should be shown: %s", optionName,132isWarningExpected);133CommandLineOptionTest.verifySameJVMStartup(134(isWarningExpected ? warnings : null),135(isWarningExpected ? null : warnings),136errorString, errorString, ExitCode.OK,137options.toArray(new String[options.size()]));138}139140private void verifyOptionValues(String value, boolean useRTMLocking,141String expectedValue) throws Throwable {142List<String> options = new LinkedList<>();143options.add(CommandLineOptionTest.prepareBooleanFlag("UseRTMLocking",144useRTMLocking));145146if (isExperimental) {147options.add(CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS);148}149options.add(prepareOptionValue(value));150151CommandLineOptionTest.verifyOptionValueForSameVM(optionName,152expectedValue, String.format("Option '%s' should have '%s' "153+ "value if '%s' flag set",154optionName, expectedValue, prepareOptionValue(value)),155options.toArray(new String[options.size()]));156}157}158159160