Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMTotalCountIncrRate.java
41155 views
1
/*
2
* Copyright (c) 2014, 2021, 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
* @test
26
* @bug 8031320
27
* @summary Verify that RTMTotalCountIncrRate option affects
28
* RTM locking statistics.
29
* @library /test/lib /
30
* @modules java.base/jdk.internal.misc
31
* java.management
32
* @requires vm.rtm.cpu & vm.rtm.compiler
33
* @build sun.hotspot.WhiteBox
34
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
35
* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
36
* -XX:+WhiteBoxAPI
37
* compiler.rtm.locking.TestRTMTotalCountIncrRate
38
*/
39
40
package compiler.rtm.locking;
41
42
import compiler.testlibrary.rtm.AbortProvoker;
43
import compiler.testlibrary.rtm.XAbortProvoker;
44
import compiler.testlibrary.rtm.CompilableTest;
45
import compiler.testlibrary.rtm.RTMLockingStatistics;
46
import compiler.testlibrary.rtm.RTMTestBase;
47
import jdk.test.lib.Asserts;
48
import jdk.test.lib.process.OutputAnalyzer;
49
import jdk.test.lib.cli.CommandLineOptionTest;
50
51
import java.util.List;
52
53
/**
54
* Test verifies that with RTMTotalCountIncrRate=1 RTM locking statistics
55
* contains precise information abort attempted locks and that with other values
56
* statistics contains information abort non-zero locking attempts.
57
* Since assert done for RTMTotalCountIncrRate=1 is pretty strict, test uses
58
* -XX:RTMRetryCount=0 to avoid issue with retriable aborts. For more details on
59
* that issue see {@link TestUseRTMAfterLockInflation}.
60
*/
61
public class TestRTMTotalCountIncrRate {
62
protected void runTestCases() throws Throwable {
63
verifyLocksCount(1, false);
64
verifyLocksCount(64, false);
65
verifyLocksCount(128, false);
66
verifyLocksCount(1, true);
67
verifyLocksCount(64, true);
68
verifyLocksCount(128, true);
69
}
70
71
private void verifyLocksCount(int incrRate, boolean useStackLock)
72
throws Throwable{
73
CompilableTest test = new Test();
74
75
OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
76
test,
77
CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",
78
useStackLock),
79
CommandLineOptionTest.prepareNumericFlag(
80
"RTMTotalCountIncrRate", incrRate),
81
"-XX:RTMRetryCount=0",
82
"-XX:+PrintPreciseRTMLockingStatistics",
83
Test.class.getName(),
84
Boolean.toString(!useStackLock)
85
);
86
87
outputAnalyzer.shouldHaveExitValue(0);
88
89
List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
90
test.getMethodWithLockName(), outputAnalyzer.getOutput());
91
92
Asserts.assertEQ(statistics.size(), 1, "VM output should contain "
93
+ "exactly one RTM locking statistics entry for method "
94
+ test.getMethodWithLockName());
95
96
RTMLockingStatistics lock = statistics.get(0);
97
if (incrRate == 1) {
98
Asserts.assertEQ(lock.getTotalLocks(), Test.TOTAL_ITERATIONS,
99
"Total locks should be exactly the same as amount of "
100
+ "iterations.");
101
}
102
}
103
104
public static class Test implements CompilableTest {
105
private static final long TOTAL_ITERATIONS = 10000L;
106
private final XAbortProvoker xabort = new XAbortProvoker();
107
private final Object monitor = new Object();
108
// Following field have to be static in order to avoid escape analysis.
109
@SuppressWarnings("UnsuedDeclaration")
110
private static int field = 0;
111
112
@Override
113
public String getMethodWithLockName() {
114
return this.getClass().getName() + "::lock";
115
}
116
117
@Override
118
public String[] getMethodsToCompileNames() {
119
return new String[] { getMethodWithLockName(), "*.doAbort" };
120
}
121
122
public void lock(boolean forceAbort) {
123
synchronized(monitor) {
124
if (forceAbort) {
125
// We're calling native method in order to force
126
// abort. It's done by explicit xabort call emitted
127
// in SharedRuntime::generate_native_wrapper.
128
// If an actual JNI call will be replaced by
129
// intrinsic - we'll be in trouble, since xabort
130
// will be no longer called and test may fail.
131
xabort.doAbort();
132
}
133
Test.field++;
134
}
135
}
136
137
/**
138
* Usage:
139
* Test &lt;inflate monitor&gt;
140
*/
141
public static void main(String args[]) throws Throwable {
142
Asserts.assertGTE(args.length, 1, "One argument required.");
143
Test test = new Test();
144
boolean shouldBeInflated = Boolean.valueOf(args[0]);
145
if (shouldBeInflated) {
146
AbortProvoker.inflateMonitor(test.monitor);
147
}
148
for (long i = 0L; i < Test.TOTAL_ITERATIONS; i++) {
149
AbortProvoker.verifyMonitorState(test.monitor,
150
shouldBeInflated);
151
// Force abort on first iteration to avoid rare case when
152
// there were no aborts and locks count was not incremented
153
// with RTMTotalCountIncrRate > 1 (in such case JVM won't
154
// print JVM locking statistics).
155
test.lock(i == 0);
156
}
157
}
158
}
159
160
public static void main(String args[]) throws Throwable {
161
new TestRTMTotalCountIncrRate().runTestCases();
162
}
163
}
164
165