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 with rtm support and 29 * on VM with rtm-locking support. 30 * @library /testlibrary /test/lib /compiler/testlibrary 31 * @modules java.base/sun.misc 32 * java.management 33 * @build TestUseRTMLockingOptionOnSupportedConfig 34 * @run main ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI TestUseRTMLockingOptionOnSupportedConfig 38 */ 39 40 import jdk.test.lib.ExitCode; 41 import jdk.test.lib.cli.*; 42 import jdk.test.lib.cli.predicate.AndPredicate; 43 import rtm.predicate.SupportedCPU; 44 import rtm.predicate.SupportedVM; 45 46 public class TestUseRTMLockingOptionOnSupportedConfig 47 extends CommandLineOptionTest { 48 private static final String DEFAULT_VALUE = "false"; 49 50 private TestUseRTMLockingOptionOnSupportedConfig() { 51 super(new AndPredicate(new SupportedVM(), new SupportedCPU())); 52 } 53 54 @Override 55 public void runTestCases() throws Throwable { 56 String unrecongnizedOption 57 = CommandLineOptionTest.getUnrecognizedOptionErrorMessage( 58 "UseRTMLocking"); 59 String shouldPassMessage = "VM option 'UseRTMLocking' is experimental" 60 + "%nJVM startup should pass with " 61 + "-XX:+UnlockExperimentalVMOptions flag"; 62 // verify that there are no warning or error in VM output 63 CommandLineOptionTest.verifySameJVMStartup(null, 64 new String[]{ 65 RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR, 66 unrecongnizedOption 67 }, shouldPassMessage, "There should not be any warning when use" 68 + "with -XX:+UnlockExperimentalVMOptions", ExitCode.OK, 69 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 70 "-XX:+UseRTMLocking" 71 ); 72 73 CommandLineOptionTest.verifySameJVMStartup(null, 74 new String[]{ 75 RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR, 76 unrecongnizedOption 77 }, shouldPassMessage, "There should not be any warning when use" 78 + "with -XX:+UnlockExperimentalVMOptions", ExitCode.OK, 79 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 80 "-XX:-UseRTMLocking" 81 ); 82 // verify that UseRTMLocking is of by default 83 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking", 84 TestUseRTMLockingOptionOnSupportedConfig.DEFAULT_VALUE, 85 String.format("Default value of option 'UseRTMLocking' should " 86 + "be '%s'", DEFAULT_VALUE), 87 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS); 88 // verify that we can change UseRTMLocking value 89 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking", 90 TestUseRTMLockingOptionOnSupportedConfig.DEFAULT_VALUE, 91 String.format("Default value of option 'UseRTMLocking' should " 92 + "be '%s'", DEFAULT_VALUE), 93 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 94 "-XX:-UseRTMLocking"); 95 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking", 96 "true", "Value of 'UseRTMLocking' should be set " 97 + "to 'true' if -XX:+UseRTMLocking flag set", 98 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 99 "-XX:+UseRTMLocking"); 100 } 101 102 public static void main(String args[]) throws Throwable { 103 new TestUseRTMLockingOptionOnSupportedConfig().test(); 104 } 105 }