1 /* 2 * Copyright (c) 2014, 2015, 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 /** 26 * @test 27 * @bug 8031320 28 * @summary Verify UseRTMLocking option processing on CPU without 29 * rtm support. 30 * @library /testlibrary /../../test/lib /compiler/testlibrary 31 * @modules java.base/sun.misc 32 * java.management 33 * @build TestUseRTMLockingOptionOnUnsupportedCPU 34 * @run main ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI TestUseRTMLockingOptionOnUnsupportedCPU 38 */ 39 40 import jdk.test.lib.*; 41 import jdk.test.lib.cli.*; 42 import jdk.test.lib.cli.predicate.AndPredicate; 43 import jdk.test.lib.cli.predicate.NotPredicate; 44 import rtm.predicate.SupportedCPU; 45 import rtm.predicate.SupportedVM; 46 47 public class TestUseRTMLockingOptionOnUnsupportedCPU 48 extends CommandLineOptionTest { 49 private static final String DEFAULT_VALUE = "false"; 50 51 private TestUseRTMLockingOptionOnUnsupportedCPU() { 52 super(new AndPredicate(new NotPredicate(new SupportedCPU()), 53 new SupportedVM())); 54 } 55 56 @Override 57 public void runTestCases() throws Throwable { 58 String unrecongnizedOption 59 = CommandLineOptionTest.getUnrecognizedOptionErrorMessage( 60 "UseRTMLocking"); 61 String errorMessage = RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR; 62 63 if (Platform.isX86() || Platform.isX64()) { 64 String shouldFailMessage = "JVM startup should fail with option " 65 + "-XX:+UseRTMLocking on unsupported CPU"; 66 // verify that we get an error when use +UseRTMLocking 67 // on unsupported CPU 68 CommandLineOptionTest.verifySameJVMStartup( 69 new String[] { errorMessage }, 70 new String[] { unrecongnizedOption }, shouldFailMessage, 71 shouldFailMessage + ". Error message should be shown", 72 ExitCode.FAIL, "-XX:+UseRTMLocking"); 73 74 String shouldPassMessage = "JVM startup should pass with option " 75 + "-XX:-UseRTMLocking even on unsupported CPU"; 76 // verify that we can pass -UseRTMLocking without 77 // getting any error messages 78 CommandLineOptionTest.verifySameJVMStartup(null, new String[] { 79 errorMessage, unrecongnizedOption }, shouldPassMessage, 80 shouldPassMessage + " without any warnings", ExitCode.OK, 81 "-XX:-UseRTMLocking"); 82 83 // verify that UseRTMLocking is false by default 84 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking", 85 TestUseRTMLockingOptionOnUnsupportedCPU.DEFAULT_VALUE, 86 String.format("Default value of option 'UseRTMLocking' " 87 +"should be '%s'", DEFAULT_VALUE)); 88 } else { 89 String shouldFailMessage = "RTMLocking should be unrecognized" 90 + " on non-x86 CPUs. JVM startup should fail." 91 + "Error message should be shown"; 92 // verify that on non-x86 CPUs RTMLocking could not be used 93 CommandLineOptionTest.verifySameJVMStartup( 94 new String[] { unrecongnizedOption }, 95 null, shouldFailMessage, shouldFailMessage, 96 ExitCode.FAIL, "-XX:+UseRTMLocking"); 97 98 CommandLineOptionTest.verifySameJVMStartup( 99 new String[] { unrecongnizedOption }, 100 null, shouldFailMessage, shouldFailMessage, 101 ExitCode.FAIL, "-XX:-UseRTMLocking"); 102 } 103 } 104 105 public static void main(String args[]) throws Throwable { 106 new TestUseRTMLockingOptionOnUnsupportedCPU().test(); 107 } 108 }