Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMLockingThreshold.java
41154 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 RTMLockingThreshold affects rtm state transition
28
* ProfileRTM => UseRTM.
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.TestRTMLockingThreshold
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 RTMLockingThreshold option actually affects how soon
55
* method will be deoptimized on low abort ratio.
56
*/
57
public class TestRTMLockingThreshold {
58
59
/**
60
* We use non-zero abort threshold to avoid abort related to
61
* interrupts, VMM calls, etc. during first lock attempt.
62
*
63
*/
64
private static final int MIN_ABORT_THRESHOLD = 10;
65
66
protected void runTestCases() throws Throwable {
67
verifyLockingThreshold(0, false);
68
verifyLockingThreshold(100, false);
69
verifyLockingThreshold(1000, false);
70
71
verifyLockingThreshold(0, true);
72
verifyLockingThreshold(100, true);
73
verifyLockingThreshold(1000, true);
74
}
75
76
private void verifyLockingThreshold(int lockingThreshold,
77
boolean useStackLock) throws Throwable {
78
CompilableTest test = new Test();
79
80
int abortThreshold = Math.max(lockingThreshold / 2,
81
TestRTMLockingThreshold.MIN_ABORT_THRESHOLD);
82
83
OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
84
test,
85
"-XX:CompileThreshold=1",
86
CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",
87
useStackLock),
88
"-XX:+UseRTMDeopt",
89
"-XX:RTMTotalCountIncrRate=1",
90
"-XX:RTMRetryCount=0",
91
CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
92
abortThreshold),
93
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
94
lockingThreshold),
95
"-XX:RTMAbortRatio=100",
96
"-XX:+PrintPreciseRTMLockingStatistics",
97
Test.class.getName(),
98
Boolean.toString(!useStackLock),
99
Integer.toString(lockingThreshold)
100
);
101
102
outputAnalyzer.shouldHaveExitValue(0);
103
104
List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
105
test.getMethodWithLockName(), outputAnalyzer.getOutput());
106
107
Asserts.assertEQ(statistics.size(), 2, "VM output should contain two "
108
+ "RTM locking statistics entries.");
109
110
/**
111
* If RTMLockingThreshold==0, then we have to make at least 1 call.
112
*/
113
long expectedValue = lockingThreshold;
114
if (expectedValue == 0) {
115
expectedValue++;
116
}
117
118
RTMLockingStatistics statBeforeDeopt = null;
119
for (RTMLockingStatistics s : statistics) {
120
if (s.getTotalLocks() == expectedValue) {
121
Asserts.assertNull(statBeforeDeopt,
122
"Only one statistics entry should contain aborts");
123
statBeforeDeopt = s;
124
}
125
}
126
127
Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
128
+ "statistics entry corresponding to ProfileRTM state.");
129
}
130
131
public static class Test implements CompilableTest {
132
// Following field have to be static in order to avoid escape analysis.
133
@SuppressWarnings("UnsuedDeclaration")
134
private static int field = 0;
135
private static final int TOTAL_ITERATIONS = 10000;
136
private final XAbortProvoker xabort = new XAbortProvoker();
137
private final Object monitor = new Object();
138
139
@Override
140
public String getMethodWithLockName() {
141
return this.getClass().getName() + "::lock";
142
}
143
144
@Override
145
public String[] getMethodsToCompileNames() {
146
return new String[] { getMethodWithLockName(),
147
XAbortProvoker.class.getName() + "::doAbort" };
148
}
149
150
public void lock(boolean abort) {
151
synchronized(monitor) {
152
if (abort) {
153
Test.field += xabort.doAbort();
154
}
155
}
156
}
157
158
/**
159
* Usage:
160
* Test &lt;inflate monitor&gt;
161
*/
162
public static void main(String args[]) throws Throwable {
163
Asserts.assertGTE(args.length, 2, "Two arguments required.");
164
Test t = new Test();
165
boolean shouldBeInflated = Boolean.valueOf(args[0]);
166
int lockingThreshold = Integer.valueOf(args[1]);
167
if (shouldBeInflated) {
168
AbortProvoker.inflateMonitor(t.monitor);
169
}
170
for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
171
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
172
t.lock(i >= lockingThreshold / 2);
173
}
174
}
175
}
176
177
public static void main(String args[]) throws Throwable {
178
new TestRTMLockingThreshold().runTestCases();
179
}
180
}
181
182