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