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 UseRTMForStackLocks option processing on CPU with 29 * rtm support when VM supports rtm locking. 30 * @library /testlibrary /test/lib / 31 * @modules java.base/jdk.internal.misc 32 * java.management 33 * @build TestUseRTMForStackLocksOptionOnSupportedConfig 34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI 38 * TestUseRTMForStackLocksOptionOnSupportedConfig 39 */ 40 41 import jdk.test.lib.*; 42 import jdk.test.lib.cli.*; 43 import jdk.test.lib.cli.predicate.AndPredicate; 44 import compiler.testlibrary.rtm.predicate.SupportedCPU; 45 import compiler.testlibrary.rtm.predicate.SupportedVM; 46 47 public class TestUseRTMForStackLocksOptionOnSupportedConfig 48 extends CommandLineOptionTest { 49 private static final String DEFAULT_VALUE = "false"; 50 51 private TestUseRTMForStackLocksOptionOnSupportedConfig() { 52 super(new AndPredicate(new SupportedVM(), new SupportedCPU())); 53 } 54 55 @Override 56 public void runTestCases() throws Throwable { 57 String errorMessage 58 = CommandLineOptionTest.getExperimentalOptionErrorMessage( 59 "UseRTMForStackLocks"); 60 String warningMessage 61 = RTMGenericCommandLineOptionTest.RTM_FOR_STACK_LOCKS_WARNING; 62 63 String shouldFailMessage = " VM option 'UseRTMForStackLocks' is " 64 + "experimental%nJVM startup should fail without " 65 + "-XX:+UnlockExperimentalVMOptions flag"; 66 67 CommandLineOptionTest.verifySameJVMStartup( 68 new String[] { errorMessage }, null, shouldFailMessage, 69 shouldFailMessage + "%nError message expected", ExitCode.FAIL, 70 "-XX:+UseRTMForStackLocks"); 71 String shouldPassMessage = " VM option 'UseRTMForStackLocks'" 72 + " is experimental%nJVM startup should pass with " 73 + "-XX:+UnlockExperimentalVMOptions flag"; 74 // verify that we get a warning when trying to use rtm for stack 75 // lock, but not using rtm locking. 76 CommandLineOptionTest.verifySameJVMStartup( 77 new String[] { warningMessage }, null, shouldPassMessage, 78 "There should be warning when trying to use rtm for stack " 79 + "lock, but not using rtm locking", ExitCode.OK, 80 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 81 "-XX:+UseRTMForStackLocks", 82 "-XX:-UseRTMLocking"); 83 // verify that we don't get a warning when no using rtm for stack 84 // lock and not using rtm locking. 85 CommandLineOptionTest.verifySameJVMStartup(null, 86 new String[] { warningMessage }, shouldPassMessage, 87 "There should not be any warning when use both " 88 + "-XX:-UseRTMForStackLocks and -XX:-UseRTMLocking " 89 + "flags", 90 ExitCode.OK, 91 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 92 "-XX:-UseRTMForStackLocks", 93 "-XX:-UseRTMLocking"); 94 // verify that we don't get a warning when using rtm for stack 95 // lock and using rtm locking. 96 CommandLineOptionTest.verifySameJVMStartup(null, 97 new String[] { warningMessage }, shouldPassMessage, 98 "There should not be any warning when use both " 99 + "-XX:+UseRTMForStackLocks and -XX:+UseRTMLocking" 100 + " flags", 101 ExitCode.OK, 102 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 103 "-XX:+UseRTMForStackLocks", 104 "-XX:+UseRTMLocking"); 105 // verify that default value if false 106 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMForStackLocks", 107 TestUseRTMForStackLocksOptionOnSupportedConfig.DEFAULT_VALUE, 108 "Default value of option 'UseRTMForStackLocks' should be false", 109 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS); 110 // verify that default value is false even with +UseRTMLocking 111 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMForStackLocks", 112 TestUseRTMForStackLocksOptionOnSupportedConfig.DEFAULT_VALUE, 113 "Default value of option 'UseRTMForStackLocks' should be false", 114 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 115 "-XX:+UseRTMLocking"); 116 // verify that we can turn the option on 117 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMForStackLocks", 118 "true", "Value of option 'UseRTMForStackLocks' should " 119 + "be able to be set as 'true' when both " 120 + "-XX:+UseRTMForStackLocks and " 121 + "-XX:+UseRTMLocking flags used", 122 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS, 123 "-XX:+UseRTMLocking", "-XX:+UseRTMForStackLocks"); 124 } 125 126 public static void main(String args[]) throws Throwable { 127 new TestUseRTMForStackLocksOptionOnSupportedConfig().test(); 128 } 129 }