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 /** 26 * @test 27 * @bug 8031320 28 * @summary Verify that UseRTMLockEliding option could be applied to 29 * specified method and that such method will not be deoptimized 30 * on high abort ratio. 31 * @library /test/lib / 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * @build sun.hotspot.WhiteBox 35 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 36 * sun.hotspot.WhiteBox$WhiteBoxPermission 37 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 38 * -XX:+WhiteBoxAPI 39 * compiler.rtm.method_options.TestUseRTMLockElidingOption 40 */ 41 42 package compiler.rtm.method_options; 43 44 import compiler.testlibrary.rtm.AbortProvoker; 45 import compiler.testlibrary.rtm.AbortType; 46 import compiler.testlibrary.rtm.RTMLockingStatistics; 47 import compiler.testlibrary.rtm.RTMTestBase; 48 import compiler.testlibrary.rtm.predicate.SupportedCPU; 49 import compiler.testlibrary.rtm.predicate.SupportedOS; 50 import compiler.testlibrary.rtm.predicate.SupportedVM; 51 import jdk.test.lib.Asserts; 52 import jdk.test.lib.process.OutputAnalyzer; 53 import jdk.test.lib.cli.CommandLineOptionTest; 54 import jdk.test.lib.cli.predicate.AndPredicate; 55 56 import java.util.List; 57 58 /** 59 * Test verifies that method tagged with option <i>UseRTMLockElidingOption</i> 60 * will use RTM-based lock elision, but will be never deoptimized with 61 * <i>rtm_state_change reason</i>. 62 * Test invokes compiled method and checks that no deoptimization with 63 * <i>rtm_state_change</i> reason had happened and that that VM output 64 * contains RTM locking statistics for compiled method and that total locks 65 * count equals to method's invocations. 66 * Since last assert is pretty strict, test uses -XX:RTMRetryCount=0 in order 67 * to avoid issue with retriable aborts described in 68 * {@link TestUseRTMAfterLockInflation}. 69 */ 70 public class TestUseRTMLockElidingOption extends CommandLineOptionTest { 71 private TestUseRTMLockElidingOption() { 72 super(new AndPredicate(new SupportedCPU(), new SupportedOS(), new SupportedVM())); 73 } 74 75 @Override 76 public void runTestCases() throws Throwable { 77 verifyOption(false); 78 verifyOption(true); 79 } 80 81 public void verifyOption(boolean useStackLock) throws Throwable { 82 AbortProvoker provoker = AbortType.XABORT.provoker(); 83 String logFileName = String.format("rtm_deopt_%s_stack_lock.xml", 84 (useStackLock ? "use" : "no")); 85 String methodOption = String.format("-XX:CompileCommand=option," + 86 "%s,UseRTMLockEliding", provoker.getMethodWithLockName()); 87 88 OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( 89 logFileName, 90 provoker, 91 CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", 92 useStackLock), 93 methodOption, 94 "-XX:RTMTotalCountIncrRate=1", 95 "-XX:RTMRetryCount=0", 96 "-XX:+UseRTMDeopt", 97 "-XX:+PrintPreciseRTMLockingStatistics", 98 provoker.getClass().getName(), 99 AbortType.XABORT.toString(), 100 Boolean.toString(!useStackLock) 101 ); 102 103 outputAnalyzer.shouldHaveExitValue(0); 104 105 int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName); 106 107 Asserts.assertEQ(firedTraps, 0, 108 "Method deoptimization with rtm_state_change is unexpected"); 109 110 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( 111 provoker.getMethodWithLockName(), outputAnalyzer.getOutput()); 112 113 Asserts.assertEQ(statistics.size(), 1, 114 "VM output should contain exactly one RTM locking " 115 + "statistics entry for method " 116 + provoker.getMethodWithLockName()); 117 118 RTMLockingStatistics lock = statistics.get(0); 119 120 Asserts.assertEQ(lock.getTotalLocks(), AbortProvoker.DEFAULT_ITERATIONS, 121 "Expected to get total locks count equal to total amount of " 122 + "lock attempts."); 123 } 124 125 public static void main(String args[]) throws Throwable { 126 new TestUseRTMLockElidingOption().test(); 127 } 128 }