Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/stress/TestStressArrayCopy.java
64507 views
1
/*
2
* Copyright (c) 2021, Red Hat, Inc. 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
package compiler.arraycopy.stress;
25
26
import java.util.ArrayList;
27
import java.util.List;
28
import java.util.Random;
29
30
import jdk.test.lib.Platform;
31
import jdk.test.lib.Utils;
32
import jdk.test.lib.process.OutputAnalyzer;
33
import jdk.test.lib.process.ProcessTools;
34
35
import jdk.test.whitebox.cpuinfo.CPUInfo;
36
37
/**
38
* @test
39
* @key stress randomness
40
* @library /test/lib
41
* @build compiler.arraycopy.stress.AbstractStressArrayCopy
42
* compiler.arraycopy.stress.StressBooleanArrayCopy
43
* compiler.arraycopy.stress.StressByteArrayCopy
44
* compiler.arraycopy.stress.StressCharArrayCopy
45
* compiler.arraycopy.stress.StressShortArrayCopy
46
* compiler.arraycopy.stress.StressIntArrayCopy
47
* compiler.arraycopy.stress.StressFloatArrayCopy
48
* compiler.arraycopy.stress.StressLongArrayCopy
49
* compiler.arraycopy.stress.StressDoubleArrayCopy
50
* compiler.arraycopy.stress.StressObjectArrayCopy
51
* jdk.test.whitebox.WhiteBox
52
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
53
*
54
* @run main/othervm/timeout=7200
55
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
56
* compiler.arraycopy.stress.TestStressArrayCopy
57
*/
58
public class TestStressArrayCopy {
59
60
// These tests are remarkably memory bandwidth hungry. Running multiple
61
// configs in parallel makes sense only when running a single test in
62
// isolation, and only on machines with many memory channels. In common
63
// testing, or even running all arraycopy stress tests at once, overloading
64
// the system with many configs become counter-productive very quickly.
65
//
66
// Default to 1/4 of the CPUs, and allow users to override.
67
static final int MAX_PARALLELISM = Integer.getInteger("maxParallelism",
68
Math.max(1, Runtime.getRuntime().availableProcessors() / 4));
69
70
private static List<String> mix(List<String> o, String... mix) {
71
List<String> n = new ArrayList<>(o);
72
for (String m : mix) {
73
n.add(m);
74
}
75
return n;
76
}
77
78
private static List<List<String>> product(List<List<String>> list, String... mix) {
79
List<List<String>> newList = new ArrayList<>();
80
for (List<String> c : list) {
81
for (String m : mix) {
82
newList.add(mix(c, m));
83
}
84
}
85
return newList;
86
}
87
88
private static List<List<String>> alternate(List<List<String>> list, String opt) {
89
return product(list, "-XX:+" + opt, "-XX:-" + opt);
90
}
91
92
private static boolean containsFuzzy(List<String> list, String sub) {
93
for (String s : list) {
94
if (s.contains(sub)) return true;
95
}
96
return false;
97
}
98
99
public static void main(String... args) throws Exception {
100
List<List<String>> configs = new ArrayList<>();
101
List<String> cpuFeatures = CPUInfo.getFeatures();
102
103
if (Platform.isX64() || Platform.isX86()) {
104
// If CPU features were not found, provide a default config.
105
if (cpuFeatures.isEmpty()) {
106
configs.add(new ArrayList());
107
}
108
109
// Otherwise, select the tests that make sense on current platform.
110
if (containsFuzzy(cpuFeatures, "avx512")) {
111
configs.add(List.of("-XX:UseAVX=3"));
112
}
113
if (containsFuzzy(cpuFeatures, "avx2")) {
114
configs.add(List.of("-XX:UseAVX=2"));
115
}
116
if (containsFuzzy(cpuFeatures, "avx")) {
117
configs.add(List.of("-XX:UseAVX=1"));
118
}
119
if (containsFuzzy(cpuFeatures, "sse4")) {
120
configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=4"));
121
}
122
if (containsFuzzy(cpuFeatures, "sse3")) {
123
configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=3"));
124
}
125
if (containsFuzzy(cpuFeatures, "sse2")) {
126
configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=2"));
127
}
128
129
// x86_64 always has UseSSE >= 2. These lower configurations only
130
// make sense for x86_32.
131
if (Platform.isX86()) {
132
if (containsFuzzy(cpuFeatures, "sse")) {
133
configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=1"));
134
}
135
136
configs.add(List.of("-XX:UseAVX=0", "-XX:UseSSE=0"));
137
}
138
139
// Alternate configs with other flags
140
if (Platform.isX64()) {
141
configs = alternate(configs, "UseCompressedOops");
142
}
143
configs = alternate(configs, "UseUnalignedLoadStores");
144
145
} else if (Platform.isAArch64()) {
146
// AArch64.
147
configs.add(new ArrayList());
148
149
// Alternate configs with other flags
150
configs = alternate(configs, "UseCompressedOops");
151
configs = alternate(configs, "UseSIMDForMemoryOps");
152
} else {
153
// Generic config.
154
configs.add(new ArrayList());
155
}
156
157
String[] classNames = {
158
"compiler.arraycopy.stress.StressBooleanArrayCopy",
159
"compiler.arraycopy.stress.StressByteArrayCopy",
160
"compiler.arraycopy.stress.StressCharArrayCopy",
161
"compiler.arraycopy.stress.StressShortArrayCopy",
162
"compiler.arraycopy.stress.StressIntArrayCopy",
163
"compiler.arraycopy.stress.StressFloatArrayCopy",
164
"compiler.arraycopy.stress.StressLongArrayCopy",
165
"compiler.arraycopy.stress.StressDoubleArrayCopy",
166
"compiler.arraycopy.stress.StressObjectArrayCopy",
167
};
168
169
ArrayList<Fork> forks = new ArrayList<>();
170
int jobs = 0;
171
172
for (List<String> c : configs) {
173
for (String className : classNames) {
174
// Start a new job
175
{
176
ProcessBuilder pb = ProcessTools.createTestJvm(mix(c, "-Xmx256m", className));
177
Process p = pb.start();
178
OutputAnalyzer oa = new OutputAnalyzer(p);
179
forks.add(new Fork(p, oa));
180
jobs++;
181
}
182
183
// Wait for the completion of other jobs
184
while (jobs >= MAX_PARALLELISM) {
185
Fork f = findDone(forks);
186
if (f != null) {
187
OutputAnalyzer oa = f.oa();
188
oa.shouldHaveExitValue(0);
189
forks.remove(f);
190
jobs--;
191
} else {
192
// Nothing is done, wait a little.
193
Thread.sleep(200);
194
}
195
}
196
}
197
}
198
199
// Drain the rest
200
for (Fork f : forks) {
201
OutputAnalyzer oa = f.oa();
202
oa.shouldHaveExitValue(0);
203
}
204
}
205
206
private static Fork findDone(List<Fork> forks) {
207
for (Fork f : forks) {
208
if (!f.p().isAlive()) {
209
return f;
210
}
211
}
212
return null;
213
}
214
215
private static record Fork(Process p, OutputAnalyzer oa) {};
216
217
}
218
219