1 /* 2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8031320 27 * @summary Verify UseRTMLocking option processing on CPU without 28 * rtm support. 29 * @library /test/lib / 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * @requires (!vm.rtm.cpu) & (vm.flavor == "server" & !vm.emulatedClient) 33 * @build sun.hotspot.WhiteBox 34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI 38 * compiler.rtm.cli.TestUseRTMLockingOptionOnUnsupportedCPU 39 */ 40 41 package compiler.rtm.cli; 42 43 import jdk.test.lib.process.ExitCode; 44 import jdk.test.lib.Platform; 45 import jdk.test.lib.cli.CommandLineOptionTest; 46 47 public class TestUseRTMLockingOptionOnUnsupportedCPU { 48 private static final String DEFAULT_VALUE = "false"; 49 50 public void runTestCases() throws Throwable { 51 String unrecognizedOption 52 = CommandLineOptionTest.getUnrecognizedOptionErrorMessage( 53 "UseRTMLocking"); 54 String errorMessage = RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR; 55 56 if (Platform.isX86() || Platform.isX64() || Platform.isPPC()) { 57 String shouldFailMessage = "JVM startup should fail with option " + 58 "-XX:+UseRTMLocking on unsupported CPU"; 59 60 try { 61 // verify that we get an error when use +UseRTMLocking 62 // on unsupported CPU 63 CommandLineOptionTest.verifySameJVMStartup( 64 new String[] { errorMessage }, 65 new String[] { unrecognizedOption }, shouldFailMessage, 66 shouldFailMessage + ". Error message should be shown.", 67 ExitCode.FAIL, "-XX:+UseRTMLocking"); 68 } catch (Throwable e) { 69 // verify that we get an error when use +UseRTMLocking 70 // on unsupported OS. It might be the case that although CPU 71 // supports RTM the OS version does not support RTM 72 if (Platform.isPPC()) { 73 String errorMessage2 = RTMGenericCommandLineOptionTest.RTM_OS_ERROR; 74 String shouldFailMessage2 = "JVM startup should fail with option " + 75 "-XX:+UseRTMLocking on unsupported CPU or " + 76 "OS version"; 77 78 CommandLineOptionTest.verifySameJVMStartup( 79 new String[] { errorMessage2 }, 80 new String[] { unrecognizedOption}, shouldFailMessage2, 81 shouldFailMessage2 + ". Error message should be shown.", 82 ExitCode.FAIL, "-XX:+UseRTMLocking"); 83 } else { 84 throw e; // checking unsupported OS error is not necessary 85 } 86 } 87 88 String shouldPassMessage = "JVM startup should pass with option " 89 + "-XX:-UseRTMLocking even on unsupported CPU"; 90 // verify that we can pass -UseRTMLocking without 91 // getting any error messages 92 CommandLineOptionTest.verifySameJVMStartup(null, new String[] { 93 errorMessage, unrecognizedOption }, shouldPassMessage, 94 shouldPassMessage + " without any warnings", ExitCode.OK, 95 "-XX:-UseRTMLocking"); 96 97 // verify that UseRTMLocking is false by default 98 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking", 99 TestUseRTMLockingOptionOnUnsupportedCPU.DEFAULT_VALUE, 100 String.format("Default value of option 'UseRTMLocking' " 101 +"should be '%s'", DEFAULT_VALUE)); 102 } else { 103 String shouldFailMessage = "RTMLocking should be unrecognized" 104 + " on non-x86 CPUs. JVM startup should fail." 105 + "Error message should be shown"; 106 // verify that on non-x86 CPUs RTMLocking could not be used 107 CommandLineOptionTest.verifySameJVMStartup( 108 new String[] { unrecognizedOption }, 109 null, shouldFailMessage, shouldFailMessage, 110 ExitCode.FAIL, "-XX:+UseRTMLocking"); 111 112 CommandLineOptionTest.verifySameJVMStartup( 113 new String[] { unrecognizedOption }, 114 null, shouldFailMessage, shouldFailMessage, 115 ExitCode.FAIL, "-XX:-UseRTMLocking"); 116 } 117 } 118 119 public static void main(String args[]) throws Throwable { 120 new TestUseRTMLockingOptionOnUnsupportedCPU().runTestCases(); 121 } 122 }