Path: blob/master/test/hotspot/jtreg/compiler/rtm/cli/TestUseRTMLockingOptionOnUnsupportedCPU.java
41152 views
/*1* Copyright (c) 2014, 2021, 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*/2223/**24* @test25* @bug 803132026* @summary Verify UseRTMLocking option processing on CPUs without27* rtm support.28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31* @requires vm.flagless32* @requires !vm.rtm.cpu & vm.rtm.compiler33* @run driver compiler.rtm.cli.TestUseRTMLockingOptionOnUnsupportedCPU34*/3536package compiler.rtm.cli;3738import jdk.test.lib.process.ExitCode;39import jdk.test.lib.Platform;40import jdk.test.lib.cli.CommandLineOptionTest;4142public class TestUseRTMLockingOptionOnUnsupportedCPU {43private static final String DEFAULT_VALUE = "false";4445public void runTestCases() throws Throwable {46String unrecognizedOption47= CommandLineOptionTest.getUnrecognizedOptionErrorMessage(48"UseRTMLocking");49String errorMessage = RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR;5051if (Platform.isX86() || Platform.isX64() || Platform.isPPC()) {52String shouldFailMessage = "JVM startup should fail with option " +53"-XX:+UseRTMLocking on unsupported CPU";5455try {56// verify that we get an error when use +UseRTMLocking57// on unsupported CPU58CommandLineOptionTest.verifySameJVMStartup(59new String[] { errorMessage },60new String[] { unrecognizedOption }, shouldFailMessage,61shouldFailMessage + ". Error message should be shown.",62ExitCode.FAIL, "-XX:+UseRTMLocking");63} catch (Throwable e) {64// verify that we get an error when use +UseRTMLocking65// on unsupported OS. It might be the case that although CPU66// supports RTM the OS version does not support RTM67if (Platform.isPPC()) {68String errorMessage2 = RTMGenericCommandLineOptionTest.RTM_OS_ERROR;69String shouldFailMessage2 = "JVM startup should fail with option " +70"-XX:+UseRTMLocking on unsupported CPU or " +71"OS version";7273CommandLineOptionTest.verifySameJVMStartup(74new String[] { errorMessage2 },75new String[] { unrecognizedOption}, shouldFailMessage2,76shouldFailMessage2 + ". Error message should be shown.",77ExitCode.FAIL, "-XX:+UseRTMLocking");78} else {79throw e; // checking unsupported OS error is not necessary80}81}8283String shouldPassMessage = "JVM startup should pass with option "84+ "-XX:-UseRTMLocking even on unsupported CPU";85// verify that we can pass -UseRTMLocking without86// getting any error messages87CommandLineOptionTest.verifySameJVMStartup(null, new String[] {88errorMessage, unrecognizedOption }, shouldPassMessage,89shouldPassMessage + " without any warnings", ExitCode.OK,90"-XX:-UseRTMLocking");9192// verify that UseRTMLocking is false by default93CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking",94TestUseRTMLockingOptionOnUnsupportedCPU.DEFAULT_VALUE,95String.format("Default value of option 'UseRTMLocking' "96+"should be '%s'", DEFAULT_VALUE));97} else {98String shouldFailMessage = "RTMLocking should be unrecognized"99+ " on non-x86 CPUs. JVM startup should fail."100+ "Error message should be shown";101// verify that on non-x86 CPUs RTMLocking could not be used102CommandLineOptionTest.verifySameJVMStartup(103new String[] { unrecognizedOption },104null, shouldFailMessage, shouldFailMessage,105ExitCode.FAIL, "-XX:+UseRTMLocking");106107CommandLineOptionTest.verifySameJVMStartup(108new String[] { unrecognizedOption },109null, shouldFailMessage, shouldFailMessage,110ExitCode.FAIL, "-XX:-UseRTMLocking");111}112}113114public static void main(String args[]) throws Throwable {115new TestUseRTMLockingOptionOnUnsupportedCPU().runTestCases();116}117}118119120