Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMAfterNonRTMDeopt.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 if we use RTMDeopt, then deoptimization
28
* caused by reason other then rtm_state_change will reset
29
* method's RTM state. And if we don't use RTMDeopt, then
30
* RTM state remain the same after such deoptimization.
31
* @library /test/lib /
32
* @modules java.base/jdk.internal.misc
33
* java.management
34
* @requires vm.rtm.cpu & vm.rtm.compiler
35
* @build sun.hotspot.WhiteBox
36
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
37
* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
38
* -XX:+WhiteBoxAPI
39
* compiler.rtm.locking.TestRTMAfterNonRTMDeopt
40
*/
41
42
package compiler.rtm.locking;
43
44
import compiler.testlibrary.rtm.AbortProvoker;
45
import compiler.testlibrary.rtm.XAbortProvoker;
46
import compiler.testlibrary.rtm.CompilableTest;
47
import compiler.testlibrary.rtm.RTMLockingStatistics;
48
import compiler.testlibrary.rtm.RTMTestBase;
49
import jdk.test.lib.Asserts;
50
import jdk.test.lib.process.OutputAnalyzer;
51
import jdk.test.lib.cli.CommandLineOptionTest;
52
53
import java.util.List;
54
55
/**
56
* To verify that with +UseRTMDeopt method's RTM state will be
57
* changed to ProfileRTM on deoptimization unrelated to
58
* rtm_state_change following sequence of events is used:
59
* <pre>
60
*
61
* rtm state ^
62
* |
63
* UseRTM | ******| ******
64
* | |
65
* ProfileRTM |******| |*****|
66
* | | | |
67
* 0-------|-----|-----|---------------------&gt; time
68
* | | \ force abort
69
* | |
70
* | \ force deoptimization
71
* |
72
* \ force xabort
73
* </pre>
74
* When xabort is forced by native method call method should
75
* change it's state to UseRTM, because we use RTMAbortRatio=100
76
* and low RTMLockingThreshold, so at this point actual abort
77
* ratio will be below 100% and there should be enough lock
78
* attempts to recompile method without RTM profiling.
79
*/
80
public class TestRTMAfterNonRTMDeopt {
81
private static final int ABORT_THRESHOLD = 1000;
82
private static final String RANGE_CHECK = "range_check";
83
84
protected void runTestCases() throws Throwable {
85
verifyRTMAfterDeopt(false, false);
86
verifyRTMAfterDeopt(true, false);
87
88
verifyRTMAfterDeopt(false, true);
89
verifyRTMAfterDeopt(true, true);
90
}
91
92
private void verifyRTMAfterDeopt(boolean useStackLock,
93
boolean useRTMDeopt) throws Throwable {
94
CompilableTest test = new Test();
95
String logFile = String.format("rtm_%s_stack_lock_%s_deopt.xml",
96
(useStackLock ? "use" : "no"), (useRTMDeopt ? "use" : "no"));
97
98
OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
99
logFile,
100
test,
101
"-XX:CompileThreshold=1",
102
CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",
103
useStackLock),
104
CommandLineOptionTest.prepareBooleanFlag("UseRTMDeopt",
105
useRTMDeopt),
106
"-XX:RTMAbortRatio=100",
107
CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
108
TestRTMAfterNonRTMDeopt.ABORT_THRESHOLD),
109
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
110
TestRTMAfterNonRTMDeopt.ABORT_THRESHOLD / 2L),
111
"-XX:RTMTotalCountIncrRate=1",
112
"-XX:+PrintPreciseRTMLockingStatistics",
113
Test.class.getName(),
114
Boolean.toString(!useStackLock)
115
);
116
117
outputAnalyzer.shouldHaveExitValue(0);
118
119
int traps = RTMTestBase.firedRTMStateChangeTraps(logFile);
120
121
if (useRTMDeopt) {
122
Asserts.assertEQ(traps, 2, "Two uncommon traps with "
123
+ "reason rtm_state_change should be fired.");
124
} else {
125
Asserts.assertEQ(traps, 0, "No uncommon traps with "
126
+ "reason rtm_state_change should be fired.");
127
}
128
129
int rangeCheckTraps = RTMTestBase.firedUncommonTraps(logFile,
130
TestRTMAfterNonRTMDeopt.RANGE_CHECK);
131
132
Asserts.assertEQ(rangeCheckTraps, 1,
133
"One range_check uncommon trap should be fired.");
134
135
List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
136
test.getMethodWithLockName(), outputAnalyzer.getOutput());
137
138
int expectedStatEntries = (useRTMDeopt ? 4 : 2);
139
140
Asserts.assertEQ(statistics.size(), expectedStatEntries,
141
String.format("VM output should contain %d RTM locking "
142
+ "statistics entries.", expectedStatEntries));
143
}
144
145
public static class Test implements CompilableTest {
146
// Following field have to be static in order to avoid escape analysis.
147
@SuppressWarnings("UnsuedDeclaration")
148
private static int field = 0;
149
private static final int ITERATIONS = 10000;
150
private static final int RANGE_CHECK_AT = ITERATIONS / 2;
151
private final XAbortProvoker xabort = new XAbortProvoker();
152
private final Object monitor = new Object();
153
154
@Override
155
public String getMethodWithLockName() {
156
return this.getClass().getName() + "::forceAbort";
157
}
158
159
@Override
160
public String[] getMethodsToCompileNames() {
161
return new String[] { getMethodWithLockName(),
162
XAbortProvoker.class.getName() + "::doAbort()" };
163
}
164
165
public void forceAbort(int a[], boolean abort) {
166
try {
167
synchronized(monitor) {
168
a[0]++;
169
if (abort) {
170
Test.field = xabort.doAbort();
171
}
172
}
173
} catch (Throwable t) {
174
// suppress any throwables
175
}
176
}
177
178
/**
179
* Usage:
180
* Test &lt;inflate monitor&gt;
181
*/
182
public static void main(String args[]) throws Throwable {
183
Test t = new Test();
184
185
boolean shouldBeInflated = Boolean.valueOf(args[0]);
186
if (shouldBeInflated) {
187
AbortProvoker.inflateMonitor(t.monitor);
188
}
189
190
int tmp[] = new int[1];
191
192
for (int i = 0; i < Test.ITERATIONS; i++ ) {
193
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
194
if (i == Test.RANGE_CHECK_AT) {
195
t.forceAbort(new int[0], false);
196
} else {
197
boolean isThreshold
198
= (i == TestRTMAfterNonRTMDeopt.ABORT_THRESHOLD);
199
boolean isThresholdPlusRange
200
= (i == TestRTMAfterNonRTMDeopt.ABORT_THRESHOLD
201
+ Test.RANGE_CHECK_AT);
202
t.forceAbort(tmp, isThreshold || isThresholdPlusRange);
203
}
204
}
205
}
206
}
207
208
public static void main(String args[]) throws Throwable {
209
new TestRTMAfterNonRTMDeopt().runTestCases();
210
}
211
}
212
213
214