Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMAbortRatio.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 RTMAbortRatio affects amount of aborts before
28
* deoptimization.
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.TestRTMAbortRatio
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 method will be deoptimized on high abort ratio
55
* as soon as abort ratio reaches RTMAbortRatio's value.
56
*/
57
public class TestRTMAbortRatio {
58
59
protected void runTestCases() throws Throwable {
60
verifyAbortRatio(0, false);
61
verifyAbortRatio(10, false);
62
verifyAbortRatio(50, false);
63
verifyAbortRatio(100, false);
64
65
verifyAbortRatio(0, true);
66
verifyAbortRatio(10, true);
67
verifyAbortRatio(50, true);
68
verifyAbortRatio(100, true);
69
}
70
71
private void verifyAbortRatio(int abortRatio, 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
"-XX:+UseRTMDeopt",
80
"-XX:RTMTotalCountIncrRate=1",
81
"-XX:RTMAbortThreshold=0",
82
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
83
10 * Test.TOTAL_ITERATIONS),
84
CommandLineOptionTest.prepareNumericFlag("RTMAbortRatio",
85
abortRatio),
86
"-XX:+PrintPreciseRTMLockingStatistics",
87
test.getClass().getName(),
88
Boolean.toString(!useStackLock));
89
90
outputAnalyzer.shouldHaveExitValue(0);
91
92
List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
93
test.getMethodWithLockName(), outputAnalyzer.getOutput());
94
95
Asserts.assertEQ(statistics.size(), 1, "VM output should contain "
96
+ "exactly one RTM locking statistics entry.");
97
98
RTMLockingStatistics lock = statistics.get(0);
99
int actualRatio;
100
101
if (lock.getTotalAborts() == 1L) {
102
actualRatio = 0;
103
} else {
104
actualRatio = (int) (lock.getTotalLocks()
105
/ (lock.getTotalAborts() - 1L));
106
}
107
108
Asserts.assertLTE(actualRatio, abortRatio, String.format(
109
"Actual abort ratio (%d) should lower or equal to "
110
+ "specified (%d).", actualRatio, abortRatio));
111
}
112
113
/**
114
* Force abort after {@code Test.WARMUP_ITERATIONS} is done.
115
*/
116
public static class Test implements CompilableTest {
117
private static final int TOTAL_ITERATIONS = 10000;
118
private static final int WARMUP_ITERATIONS = 1000;
119
private final XAbortProvoker xabort = new XAbortProvoker();
120
private final Object monitor = new Object();
121
// Following field have to be static in order to avoid escape analysis.
122
@SuppressWarnings("UnsuedDeclaration")
123
private static int field = 0;
124
125
@Override
126
public String getMethodWithLockName() {
127
return this.getClass().getName() + "::lock";
128
}
129
130
@Override
131
public String[] getMethodsToCompileNames() {
132
return new String[] { getMethodWithLockName(), "*.doAbort" };
133
}
134
135
public void lock(boolean abort) {
136
synchronized(monitor) {
137
if (abort) {
138
xabort.doAbort();
139
}
140
}
141
}
142
143
/**
144
* Usage:
145
* Test &lt;inflate monitor&gt;
146
*/
147
public static void main(String args[]) throws Throwable {
148
Asserts.assertGTE(args.length, 1, "One argument required.");
149
Test t = new Test();
150
boolean shouldBeInflated = Boolean.valueOf(args[0]);
151
if (shouldBeInflated) {
152
AbortProvoker.inflateMonitor(t.monitor);
153
}
154
for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
155
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
156
t.lock(i >= Test.WARMUP_ITERATIONS);
157
}
158
}
159
}
160
161
public static void main(String args[]) throws Throwable {
162
new TestRTMAbortRatio().runTestCases();
163
}
164
}
165
166
167