Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.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 on low abort ratio method will be recompiled.
28
* @library /test/lib /
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
* @requires vm.rtm.cpu & vm.rtm.compiler
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
35
* -XX:+WhiteBoxAPI
36
* compiler.rtm.locking.TestRTMDeoptOnLowAbortRatio
37
*/
38
39
package compiler.rtm.locking;
40
41
import compiler.testlibrary.rtm.AbortProvoker;
42
import compiler.testlibrary.rtm.XAbortProvoker;
43
import compiler.testlibrary.rtm.CompilableTest;
44
import compiler.testlibrary.rtm.RTMLockingStatistics;
45
import compiler.testlibrary.rtm.RTMTestBase;
46
import jdk.test.lib.Asserts;
47
import jdk.test.lib.process.OutputAnalyzer;
48
import jdk.test.lib.cli.CommandLineOptionTest;
49
50
import java.util.List;
51
52
/**
53
* Test verifies that low abort ratio method will be deoptimized with
54
* <i>rtm_state_change</i> reason and will continue to use RTM-based lock
55
* elision after that.
56
* This test make asserts on total locks count done by compiled method,
57
* so in order to avoid issue with retriable locks -XX:RTMRetryCount=0 is used.
58
* For more details on that issue see {@link TestUseRTMAfterLockInflation}.
59
*/
60
public class TestRTMDeoptOnLowAbortRatio {
61
private static final long LOCKING_THRESHOLD = 100L;
62
private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;
63
64
protected void runTestCases() throws Throwable {
65
verifyRTMDeopt(false);
66
verifyRTMDeopt(true);
67
}
68
69
private void verifyRTMDeopt(boolean useStackLock) throws Throwable {
70
CompilableTest test = new Test();
71
String logFileName = String.format("rtm_deopt_%s_stack_lock.xml",
72
useStackLock ? "use" : "no");
73
74
OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
75
logFileName,
76
test,
77
"-XX:+UseRTMDeopt",
78
CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",
79
useStackLock),
80
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
81
TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD),
82
CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
83
TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD),
84
"-XX:RTMAbortRatio=100",
85
"-XX:CompileThreshold=1",
86
"-XX:RTMRetryCount=0",
87
"-XX:RTMTotalCountIncrRate=1",
88
"-XX:+PrintPreciseRTMLockingStatistics",
89
Test.class.getName(),
90
Boolean.toString(!useStackLock)
91
);
92
93
outputAnalyzer.shouldHaveExitValue(0);
94
95
int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName);
96
97
Asserts.assertEQ(firedTraps, 1,
98
"Expected to get only one deoptimization due to rtm"
99
+ " state change");
100
101
List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
102
test.getMethodWithLockName(), outputAnalyzer.getOutput());
103
104
Asserts.assertEQ(statistics.size(), 2,
105
"VM output should contain two RTM locking "
106
+ "statistics entries for method "
107
+ test.getMethodWithLockName());
108
109
RTMLockingStatistics statisticsBeforeDeopt = null;
110
111
for (RTMLockingStatistics s : statistics) {
112
if (s.getTotalLocks()
113
== TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {
114
Asserts.assertNull(statisticsBeforeDeopt,
115
"Only one abort was expected during test run");
116
statisticsBeforeDeopt = s;
117
}
118
}
119
120
Asserts.assertNotNull(statisticsBeforeDeopt,
121
"After LockThreshold was reached, method should be recompiled "
122
+ "with rtm lock eliding.");
123
}
124
125
public static class Test implements CompilableTest {
126
private final XAbortProvoker xabort = new XAbortProvoker();
127
private final Object monitor = new Object();
128
129
@Override
130
public String getMethodWithLockName() {
131
return this.getClass().getName() + "::forceAbort";
132
}
133
134
@Override
135
public String[] getMethodsToCompileNames() {
136
return new String[] { getMethodWithLockName(),
137
XAbortProvoker.class.getName() + "::doAbort" };
138
}
139
140
public void forceAbort(boolean abort) {
141
synchronized(monitor) {
142
if (abort) {
143
xabort.doAbort();
144
}
145
}
146
}
147
148
/**
149
* Usage:
150
* Test &lt;inflate monitor&gt;
151
*/
152
public static void main(String args[]) throws Throwable {
153
Asserts.assertGTE(args.length, 1, "One argument required.");
154
Test t = new Test();
155
boolean shouldBeInflated = Boolean.valueOf(args[0]);
156
if (shouldBeInflated) {
157
AbortProvoker.inflateMonitor(t.monitor);
158
}
159
for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
160
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
161
t.forceAbort(i >= TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD);
162
}
163
}
164
}
165
166
public static void main(String args[]) throws Throwable {
167
new TestRTMDeoptOnLowAbortRatio().runTestCases();
168
}
169
}
170
171