Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/bmi/BMITestRunner.java
41155 views
1
/*
2
* Copyright (c) 2014, 2020, 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
package compiler.intrinsics.bmi;
25
26
import jdk.test.lib.Asserts;
27
import jdk.test.lib.process.OutputAnalyzer;
28
import jdk.test.lib.process.ProcessTools;
29
import jdk.test.lib.Utils;
30
31
import java.io.IOException;
32
import java.nio.file.Files;
33
import java.nio.file.Paths;
34
import java.util.Collections;
35
import java.util.LinkedList;
36
import java.util.List;
37
import java.util.Random;
38
39
/**
40
* Test runner that invokes all methods implemented by particular Expr
41
* with random arguments in two different JVM processes and compares output.
42
* JVMs being started in different modes - one in int and other in comp
43
* with C2 and disabled tiered compilation.
44
*/
45
public class BMITestRunner {
46
47
enum VMMode {
48
COMP, INT;
49
};
50
51
public static int DEFAULT_ITERATIONS_COUNT = 4000;
52
53
/**
54
* Execute all methods implemented by <b>expr</b> in int and comp modes
55
* and compare output.
56
* Test pass only of output obtained with different VM modes is equal.
57
* To control behaviour of test following options could be passed:
58
* <ul>
59
* <li>-iterations=&lt;N&gt; each operation implemented by
60
* <b>expr</b> will be executed <i>N</i> times. Default value
61
* is 4000.</li>
62
* </ul>
63
*
64
* @param expr operation that should be tested
65
* @param testOpts options to control test behaviour
66
* @param additionalVMOpts additional options for VM
67
*
68
* @throws Throwable if test failed.
69
*/
70
public static void runTests(Class<? extends Expr> expr,
71
String testOpts[],
72
String... additionalVMOpts)
73
throws Throwable {
74
75
// ensure seed got printed out
76
Utils.getRandomInstance();
77
long seed = Utils.SEED;
78
int iterations = DEFAULT_ITERATIONS_COUNT;
79
80
for (String testOption : testOpts) {
81
if (testOption.startsWith("-iterations=")) {
82
iterations = Integer.valueOf(testOption.
83
replace("-iterations=", ""));
84
}
85
}
86
87
OutputAnalyzer intOutput = runTest(expr, VMMode.INT,
88
additionalVMOpts,
89
seed, iterations);
90
OutputAnalyzer compOutput = runTest(expr, VMMode.COMP,
91
additionalVMOpts,
92
seed, iterations);
93
94
dumpOutput(intOutput, "int");
95
dumpOutput(compOutput, "comp");
96
97
Asserts.assertStringsEqual(intOutput.getStdout(),
98
compOutput.getStdout(),
99
"Results obtained in -Xint and " +
100
"-Xcomp should be the same.");
101
}
102
103
/**
104
* Execute tests on methods implemented by <b>expr</b> in new VM
105
* started in <b>testVMMode</b> mode.
106
*
107
* @param expr operation that should be tested
108
* @param testVMMode VM mode for test
109
* @param additionalVMOpts additional options for VM
110
* @param seed for RNG used it tests
111
* @param iterations that will be used to invoke <b>expr</b>'s methods.
112
*
113
* @return OutputAnalyzer for executed test.
114
* @throws Throwable when something goes wrong.
115
*/
116
public static OutputAnalyzer runTest(Class<? extends Expr> expr,
117
VMMode testVMMode,
118
String additionalVMOpts[],
119
long seed, int iterations)
120
throws Throwable {
121
122
List<String> vmOpts = new LinkedList<String>();
123
124
Collections.addAll(vmOpts, additionalVMOpts);
125
126
//setup mode-specific options
127
switch (testVMMode) {
128
case INT:
129
Collections.addAll(vmOpts, new String[] { "-Xint" });
130
break;
131
case COMP:
132
Collections.addAll(vmOpts, new String[] {
133
"-Xcomp",
134
"-XX:-TieredCompilation",
135
String.format("-XX:CompileCommand=compileonly,%s::*",
136
expr.getName())
137
});
138
break;
139
}
140
141
Collections.addAll(vmOpts, new String[] {
142
"-XX:+DisplayVMOutputToStderr",
143
"-D" + Utils.SEED_PROPERTY_NAME + "=" + seed,
144
Executor.class.getName(),
145
expr.getName(),
146
new Integer(iterations).toString()
147
});
148
149
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(vmOpts);
150
151
outputAnalyzer.shouldHaveExitValue(0);
152
153
return outputAnalyzer;
154
}
155
156
/**
157
* Dump stdout and stderr of test process to <i>prefix</i>.test.out
158
* and <i>prefix</i>.test.err respectively.
159
*
160
* @param outputAnalyzer OutputAnalyzer whom output should be dumped
161
* @param prefix Prefix that will be used in file names.
162
* @throws IOException if unable to dump output to file.
163
*/
164
protected static void dumpOutput(OutputAnalyzer outputAnalyzer,
165
String prefix)
166
throws IOException {
167
Files.write(Paths.get(prefix + ".test.out"),
168
outputAnalyzer.getStdout().getBytes());
169
170
Files.write(Paths.get(prefix + ".test.err"),
171
outputAnalyzer.getStderr().getBytes());
172
}
173
174
175
/**
176
* Executor that invoke all methods implemented by particular
177
* Expr instance.
178
*/
179
public static class Executor {
180
181
/**
182
* Usage: BMITestRunner$Executor &lt;ExprClassName&gt; &lt;iterations&gt;
183
*/
184
public static void main(String args[]) throws Exception {
185
@SuppressWarnings("unchecked")
186
Class<? extends Expr> exprClass =
187
(Class<? extends Expr>)Class.forName(args[0]);
188
Expr expr = exprClass.getConstructor().newInstance();
189
int iterations = Integer.valueOf(args[1]);
190
runTests(expr, iterations, Utils.getRandomInstance());
191
}
192
193
194
public static int[] getIntBitShifts() {
195
//SIZE+1 shift is for zero.
196
int data[] = new int[Integer.SIZE+1];
197
for (int s = 0; s < data.length; s++) {
198
data[s] = 1<<s;
199
}
200
return data;
201
}
202
203
public static long[] getLongBitShifts() {
204
//SIZE+1 shift is for zero.
205
long data[] = new long[Long.SIZE+1];
206
for (int s = 0; s < data.length; s++) {
207
data[s] = 1L<<s;
208
}
209
return data;
210
}
211
212
public static void log(String format, Object... args) {
213
System.out.println(String.format(format, args));
214
}
215
216
public static void runTests(Expr expr, int iterations, Random rng) {
217
runUnaryIntRegTest(expr, iterations, rng);
218
runUnaryIntMemTest(expr, iterations, rng);
219
runUnaryLongRegTest(expr, iterations, rng);
220
runUnaryLongMemTest(expr, iterations, rng);
221
runUnaryIntToLongRegTest(expr, iterations, rng);
222
runBinaryRegRegIntTest(expr, iterations, rng);
223
runBinaryRegMemIntTest(expr, iterations, rng);
224
runBinaryMemRegIntTest(expr, iterations, rng);
225
runBinaryMemMemIntTest(expr, iterations, rng);
226
runBinaryRegRegLongTest(expr, iterations, rng);
227
runBinaryRegMemLongTest(expr, iterations, rng);
228
runBinaryMemRegLongTest(expr, iterations, rng);
229
runBinaryMemMemLongTest(expr, iterations, rng);
230
}
231
232
public static void runUnaryIntRegTest(Expr expr, int iterations,
233
Random rng) {
234
if (!(expr.isUnaryArgumentSupported()
235
&& expr.isIntExprSupported())) {
236
return;
237
}
238
239
for (int value : getIntBitShifts()) {
240
log("UnaryIntReg(0X%x) -> 0X%x",
241
value, expr.intExpr(value));
242
}
243
244
for (int i = 0; i < iterations; i++) {
245
int value = rng.nextInt();
246
log("UnaryIntReg(0X%x) -> 0X%x",
247
value, expr.intExpr(value));
248
}
249
}
250
251
public static void runUnaryIntMemTest(Expr expr, int iterations,
252
Random rng) {
253
if (!(expr.isUnaryArgumentSupported()
254
&& expr.isIntExprSupported()
255
&& expr.isMemExprSupported())) {
256
return;
257
}
258
259
for (int value : getIntBitShifts()) {
260
log("UnaryIntMem(0X%x) -> 0X%x",
261
value, expr.intExpr(new Expr.MemI(value)));
262
}
263
264
for (int i = 0; i < iterations; i++) {
265
int value = rng.nextInt();
266
log("UnaryIntMem(0X%x) -> 0X%x",
267
value, expr.intExpr(new Expr.MemI(value)));
268
}
269
}
270
271
public static void runUnaryLongRegTest(Expr expr, int iterations,
272
Random rng) {
273
if (!(expr.isUnaryArgumentSupported()
274
&& expr.isLongExprSupported())) {
275
return;
276
}
277
278
for (long value : getLongBitShifts()) {
279
log("UnaryLongReg(0X%x) -> 0X%x",
280
value, expr.longExpr(value));
281
}
282
283
for (int i = 0; i < iterations; i++) {
284
long value = rng.nextLong();
285
log("UnaryLongReg(0X%x) -> 0X%x",
286
value, expr.longExpr(value));
287
}
288
}
289
290
public static void runUnaryLongMemTest(Expr expr, int iterations,
291
Random rng) {
292
if (!(expr.isUnaryArgumentSupported()
293
&& expr.isLongExprSupported()
294
&& expr.isMemExprSupported())) {
295
return;
296
}
297
298
for (long value : getLongBitShifts()) {
299
log("UnaryLongMem(0X%x) -> 0X%x",
300
value, expr.longExpr(new Expr.MemL(value)));
301
}
302
303
for (int i = 0; i < iterations; i++) {
304
long value = rng.nextLong();
305
log("UnaryLongMem(0X%x) -> 0X%x",
306
value, expr.longExpr(new Expr.MemL(value)));
307
}
308
}
309
310
public static void runUnaryIntToLongRegTest(Expr expr, int iterations,
311
Random rng) {
312
if (!(expr.isUnaryArgumentSupported()
313
&& expr.isIntToLongExprSupported())) {
314
return;
315
}
316
317
for (int value : getIntBitShifts()) {
318
log("UnaryIntToLongReg(0X%x) -> 0X%x",
319
value, expr.intToLongExpr(value));
320
}
321
322
for (int i = 0; i < iterations; i++) {
323
int value = rng.nextInt();
324
log("UnaryIntToLongReg(0X%x) -> 0X%x",
325
value, expr.intToLongExpr(value));
326
}
327
}
328
329
public static void runBinaryRegRegIntTest(Expr expr, int iterations,
330
Random rng) {
331
if (!(expr.isIntExprSupported()
332
&& expr.isBinaryArgumentSupported())) {
333
return;
334
}
335
336
for (int i = 0; i < iterations; i++) {
337
int aValue = rng.nextInt();
338
int bValue = rng.nextInt();
339
log("BinaryIntRegReg(0X%x, 0X%x) -> 0X%x",
340
aValue, bValue, expr.intExpr(aValue, bValue));
341
}
342
}
343
344
public static void runBinaryRegMemIntTest(Expr expr, int iterations,
345
Random rng) {
346
if (!(expr.isIntExprSupported()
347
&& expr.isBinaryArgumentSupported()
348
&& expr.isMemExprSupported())) {
349
return;
350
}
351
352
for (int i = 0; i < iterations; i++) {
353
int aValue = rng.nextInt();
354
int bValue = rng.nextInt();
355
log("BinaryIntRegMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
356
expr.intExpr(aValue, new Expr.MemI(bValue)));
357
}
358
}
359
360
public static void runBinaryMemRegIntTest(Expr expr, int iterations,
361
Random rng) {
362
if (!(expr.isIntExprSupported()
363
&& expr.isBinaryArgumentSupported()
364
&& expr.isMemExprSupported())) {
365
return;
366
}
367
368
for (int i = 0; i < iterations; i++) {
369
int aValue = rng.nextInt();
370
int bValue = rng.nextInt();
371
log("BinaryIntMemReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
372
expr.intExpr(new Expr.MemI(aValue), bValue));
373
}
374
}
375
376
public static void runBinaryMemMemIntTest(Expr expr, int iterations,
377
Random rng) {
378
if (!(expr.isIntExprSupported()
379
&& expr.isBinaryArgumentSupported()
380
&& expr.isMemExprSupported())) {
381
return;
382
}
383
384
for (int i = 0; i < iterations; i++) {
385
int aValue = rng.nextInt();
386
int bValue = rng.nextInt();
387
log("BinaryIntMemMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
388
expr.intExpr(new Expr.MemI(aValue),
389
new Expr.MemI(bValue)));
390
}
391
}
392
393
public static void runBinaryRegRegLongTest(Expr expr,
394
int iterations,
395
Random rng) {
396
if (!(expr.isLongExprSupported()
397
&& expr.isBinaryArgumentSupported())) {
398
return;
399
}
400
401
for (int i = 0; i < iterations; i++) {
402
long aValue = rng.nextLong();
403
long bValue = rng.nextLong();
404
log("BinaryLongRegReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
405
expr.longExpr(aValue, bValue));
406
}
407
}
408
409
public static void runBinaryRegMemLongTest(Expr expr,
410
int iterations,
411
Random rng) {
412
if (!(expr.isLongExprSupported()
413
&& expr.isBinaryArgumentSupported()
414
&& expr.isMemExprSupported())) {
415
return;
416
}
417
418
for (int i = 0; i < iterations; i++) {
419
long aValue = rng.nextLong();
420
long bValue = rng.nextLong();
421
log("BinaryLongRegMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
422
expr.longExpr(aValue, new Expr.MemL(bValue)));
423
}
424
}
425
426
public static void runBinaryMemRegLongTest(Expr expr,
427
int iterations,
428
Random rng) {
429
if (!(expr.isLongExprSupported()
430
&& expr.isBinaryArgumentSupported()
431
&& expr.isMemExprSupported())) {
432
return;
433
}
434
435
for (int i = 0; i < iterations; i++) {
436
long aValue = rng.nextLong();
437
long bValue = rng.nextLong();
438
log("BinaryLongMemReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
439
expr.longExpr(new Expr.MemL(aValue), bValue));
440
}
441
}
442
443
public static void runBinaryMemMemLongTest(Expr expr,
444
int iterations,
445
Random rng) {
446
if (!(expr.isLongExprSupported()
447
&& expr.isBinaryArgumentSupported()
448
&& expr.isMemExprSupported())) {
449
return;
450
}
451
452
for (int i = 0; i < iterations; i++) {
453
long aValue = rng.nextLong();
454
long bValue = rng.nextLong();
455
log("BinaryLongMemMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
456
expr.longExpr(new Expr.MemL(aValue),
457
new Expr.MemL(bValue)));
458
}
459
}
460
}
461
}
462
463