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 that RTMAbortThreshold option affects 29 * amount of aborts after which abort ratio is calculated. 30 * @library /testlibrary /../../test/lib /compiler/testlibrary 31 * @modules java.base/sun.misc 32 * java.management 33 * @build TestRTMAbortThreshold 34 * @run main ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 37 * -XX:+WhiteBoxAPI TestRTMAbortThreshold 38 */ 39 40 import java.util.List; 41 import jdk.test.lib.*; 42 import jdk.test.lib.cli.CommandLineOptionTest; 43 import jdk.test.lib.cli.predicate.AndPredicate; 44 import rtm.*; 45 import rtm.predicate.SupportedCPU; 46 import rtm.predicate.SupportedVM; 47 48 /** 49 * Test verifies that on RTMAbortThreshold option actually affects how soon 50 * method will be deoptimized on high abort ratio. 51 */ 52 public class TestRTMAbortThreshold extends CommandLineOptionTest { 53 private TestRTMAbortThreshold() { 54 super(new AndPredicate(new SupportedCPU(), new SupportedVM())); 55 } 56 57 @Override 58 protected void runTestCases() throws Throwable { 59 verifyAbortThreshold(false, 1); 60 verifyAbortThreshold(false, 10); 61 verifyAbortThreshold(false, 1000); 62 63 verifyAbortThreshold(true, 1); 64 verifyAbortThreshold(true, 10); 65 verifyAbortThreshold(true, 1000); 66 } 67 68 private void verifyAbortThreshold(boolean useStackLock, 69 long abortThreshold) throws Throwable { 70 AbortProvoker provoker = AbortType.XABORT.provoker(); 71 72 OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( 73 provoker, 74 "-XX:+UseRTMDeopt", 75 "-XX:RTMAbortRatio=0", 76 CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold", 77 abortThreshold), 78 CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", 79 useStackLock), 80 "-XX:RTMTotalCountIncrRate=1", 81 "-XX:+PrintPreciseRTMLockingStatistics", 82 AbortProvoker.class.getName(), 83 AbortType.XABORT.toString(), 84 Boolean.toString(!useStackLock)); 85 86 outputAnalyzer.shouldHaveExitValue(0); 87 88 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( 89 provoker.getMethodWithLockName(), outputAnalyzer.getOutput()); 90 91 Asserts.assertEQ(statistics.size(), 1, "VM output should contain " 92 + "exactly one RTM locking statistics entry for method " 93 + provoker.getMethodWithLockName()); 94 95 Asserts.assertEQ(statistics.get(0).getTotalLocks(), abortThreshold, 96 String.format("Expected that method with rtm lock elision was" 97 + " deoptimized after %d lock attempts", 98 abortThreshold)); 99 } 100 101 public static void main(String args[]) throws Throwable { 102 new TestRTMAbortThreshold().test(); 103 } 104 } 105