|
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 RTMSpinLoopCount affects time spent |
|
29 * between locking attempts. |
|
30 * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary |
|
31 * @build TestRTMSpinLoopCount |
|
32 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
|
33 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
|
34 * -XX:+WhiteBoxAPI TestRTMSpinLoopCount |
|
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 RTMSpinLoopCount increase time spent between retries |
|
47 * by comparing amount of retries done with different RTMSpinLoopCount's values. |
|
48 */ |
|
49 public class TestRTMSpinLoopCount extends CommandLineOptionTest { |
|
50 private static final int LOCKING_TIME = 1000; |
|
51 private static final int RTM_RETRY_COUNT = 1000; |
|
52 private static final boolean INFLATE_MONITOR = true; |
|
53 private static final long MAX_ABORTS = RTM_RETRY_COUNT + 1L; |
|
54 private static final int[] SPIN_LOOP_COUNTS |
|
55 = new int[] { 0, 100, 1_000, 1_000_000, 10_000_000 }; |
|
56 |
|
57 private TestRTMSpinLoopCount() { |
|
58 super(new AndPredicate(new SupportedVM(), new SupportedCPU())); |
|
59 } |
|
60 |
|
61 @Override |
|
62 protected void runTestCases() throws Throwable { |
|
63 long[] aborts = new long[TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length]; |
|
64 for (int i = 0; i < TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length; i++) { |
|
65 aborts[i] = getAbortsCountOnLockBusy( |
|
66 TestRTMSpinLoopCount.SPIN_LOOP_COUNTS[i]); |
|
67 } |
|
68 |
|
69 for (int i = 1; i < aborts.length; i++) { |
|
70 Asserts.assertLTE(aborts[i], aborts[i - 1], "Increased spin loop " |
|
71 + "count should not increase retries count."); |
|
72 } |
|
73 } |
|
74 |
|
75 private long getAbortsCountOnLockBusy(int spinLoopCount) throws Throwable { |
|
76 CompilableTest test = new BusyLock(); |
|
77 |
|
78 OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( |
|
79 test, |
|
80 CommandLineOptionTest.prepareNumericFlag("RTMRetryCount", |
|
81 TestRTMSpinLoopCount.RTM_RETRY_COUNT), |
|
82 CommandLineOptionTest.prepareNumericFlag("RTMSpinLoopCount", |
|
83 spinLoopCount), |
|
84 "-XX:-UseRTMXendForLockBusy", |
|
85 "-XX:RTMTotalCountIncrRate=1", |
|
86 "-XX:+PrintPreciseRTMLockingStatistics", |
|
87 BusyLock.class.getName(), |
|
88 Boolean.toString(TestRTMSpinLoopCount.INFLATE_MONITOR), |
|
89 Integer.toString(TestRTMSpinLoopCount.LOCKING_TIME) |
|
90 ); |
|
91 |
|
92 outputAnalyzer.shouldHaveExitValue(0); |
|
93 |
|
94 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( |
|
95 test.getMethodWithLockName(), outputAnalyzer.getOutput()); |
|
96 |
|
97 Asserts.assertEQ(statistics.size(), 1, |
|
98 "VM output should contain exactly one entry for method " |
|
99 + test.getMethodWithLockName()); |
|
100 |
|
101 RTMLockingStatistics lock = statistics.get(0); |
|
102 |
|
103 Asserts.assertLTE(lock.getTotalAborts(), |
|
104 TestRTMSpinLoopCount.MAX_ABORTS, String.format("Total aborts " |
|
105 + "count (%d) should be less or equal to %d", |
|
106 lock.getTotalAborts(), |
|
107 TestRTMSpinLoopCount.MAX_ABORTS)); |
|
108 |
|
109 return lock.getTotalAborts(); |
|
110 } |
|
111 |
|
112 public static void main(String args[]) throws Throwable { |
|
113 new TestRTMSpinLoopCount().test(); |
|
114 } |
|
115 } |