Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java
64474 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
/**
25
* @test
26
* @library /test/lib /
27
* @requires vm.flagless
28
* @requires vm.compMode != "Xint"
29
* @run driver compiler.blackhole.BlackholeIntrinsicTest
30
*/
31
32
package compiler.blackhole;
33
34
import java.io.IOException;
35
import java.util.List;
36
import java.util.Arrays;
37
import java.util.ArrayList;
38
import java.util.LinkedHashMap;
39
import java.util.Map;
40
41
import jdk.test.lib.Platform;
42
import jdk.test.lib.process.ProcessTools;
43
import jdk.test.lib.process.OutputAnalyzer;
44
45
public class BlackholeIntrinsicTest {
46
47
private static final Map<String, Runnable> TESTS;
48
49
static {
50
TESTS = new LinkedHashMap<>();
51
TESTS.put("bh_s_boolean_0", BlackholeIntrinsicTest::test_boolean_0);
52
TESTS.put("bh_s_byte_0", BlackholeIntrinsicTest::test_byte_0);
53
TESTS.put("bh_s_char_0", BlackholeIntrinsicTest::test_char_0);
54
TESTS.put("bh_s_short_0", BlackholeIntrinsicTest::test_short_0);
55
TESTS.put("bh_s_int_0", BlackholeIntrinsicTest::test_int_0);
56
TESTS.put("bh_s_float_0", BlackholeIntrinsicTest::test_float_0);
57
TESTS.put("bh_s_long_0", BlackholeIntrinsicTest::test_long_0);
58
TESTS.put("bh_s_double_0", BlackholeIntrinsicTest::test_double_0);
59
TESTS.put("bh_s_Object_0", BlackholeIntrinsicTest::test_Object_0);
60
61
TESTS.put("bh_s_boolean_1", BlackholeIntrinsicTest::test_boolean_1);
62
TESTS.put("bh_s_byte_1", BlackholeIntrinsicTest::test_byte_1);
63
TESTS.put("bh_s_char_1", BlackholeIntrinsicTest::test_char_1);
64
TESTS.put("bh_s_short_1", BlackholeIntrinsicTest::test_short_1);
65
TESTS.put("bh_s_int_1", BlackholeIntrinsicTest::test_int_1);
66
TESTS.put("bh_s_float_1", BlackholeIntrinsicTest::test_float_1);
67
TESTS.put("bh_s_long_1", BlackholeIntrinsicTest::test_long_1);
68
TESTS.put("bh_s_double_1", BlackholeIntrinsicTest::test_double_1);
69
TESTS.put("bh_s_Object_1", BlackholeIntrinsicTest::test_Object_1);
70
71
TESTS.put("bh_s_boolean_2", BlackholeIntrinsicTest::test_boolean_2);
72
TESTS.put("bh_s_byte_2", BlackholeIntrinsicTest::test_byte_2);
73
TESTS.put("bh_s_char_2", BlackholeIntrinsicTest::test_char_2);
74
TESTS.put("bh_s_short_2", BlackholeIntrinsicTest::test_short_2);
75
TESTS.put("bh_s_int_2", BlackholeIntrinsicTest::test_int_2);
76
TESTS.put("bh_s_float_2", BlackholeIntrinsicTest::test_float_2);
77
TESTS.put("bh_s_long_2", BlackholeIntrinsicTest::test_long_2);
78
TESTS.put("bh_s_double_2", BlackholeIntrinsicTest::test_double_2);
79
TESTS.put("bh_s_Object_2", BlackholeIntrinsicTest::test_Object_2);
80
81
// Test calling static methods through instance method to exercise
82
// unusual intrinsic shapes.
83
TESTS.put("bh_is_int_0", BlackholeIntrinsicTest::test_is_int_0);
84
TESTS.put("bh_is_Object_0", BlackholeIntrinsicTest::test_is_Object_0);
85
TESTS.put("bh_is_int_1", BlackholeIntrinsicTest::test_is_int_1);
86
TESTS.put("bh_is_Object_1", BlackholeIntrinsicTest::test_is_Object_1);
87
TESTS.put("bh_is_int_2", BlackholeIntrinsicTest::test_is_int_2);
88
TESTS.put("bh_is_Object_2", BlackholeIntrinsicTest::test_is_Object_2);
89
}
90
91
private static final int CYCLES = 100_000;
92
private static final int TRIES = 10;
93
94
public static void main(String[] args) throws IOException {
95
if (args.length == 0) {
96
driver();
97
} else {
98
test(args[0]);
99
}
100
}
101
102
public static void driver() throws IOException {
103
for (String test : TESTS.keySet()) {
104
check(test, "-XX:TieredStopAtLevel=1");
105
check(test, "-XX:-TieredCompilation");
106
if (Platform.is64bit()) {
107
check(test, "-XX:-UseCompressedOops", "-XX:TieredStopAtLevel=1");
108
check(test, "-XX:-UseCompressedOops", "-XX:-TieredCompilation");
109
}
110
}
111
}
112
113
private static void test(String test) {
114
Runnable r = TESTS.get(test);
115
if (r == null) {
116
throw new IllegalArgumentException("Cannot find test " + test);
117
}
118
for (int t = 0; t < TRIES; t++) {
119
r.run();
120
}
121
}
122
123
public static void check(String test, String... args) throws IOException {
124
List<String> cmdline = new ArrayList();
125
cmdline.add("-Xmx128m");
126
cmdline.add("-Xbatch");
127
cmdline.add("-XX:+UnlockDiagnosticVMOptions");
128
cmdline.add("-XX:+AbortVMOnCompilationFailure");
129
cmdline.add("-XX:+PrintCompilation");
130
cmdline.add("-XX:+PrintInlining");
131
cmdline.add("-XX:+UnlockExperimentalVMOptions");
132
cmdline.add("-XX:CompileCommand=blackhole,compiler/blackhole/BlackholeTarget.bh_*");
133
cmdline.addAll(Arrays.asList(args));
134
cmdline.add("compiler.blackhole.BlackholeIntrinsicTest");
135
cmdline.add(test);
136
137
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmdline);
138
OutputAnalyzer output = new OutputAnalyzer(pb.start());
139
output.shouldHaveExitValue(0);
140
output.stderrShouldBeEmpty();
141
output.stdoutShouldMatch("compiler.blackhole.BlackholeTarget::" + test + ".*intrinsic.*");
142
}
143
144
private static void test_boolean_0() {
145
for (int c = 0; c < CYCLES; c++) {
146
BlackholeTarget.bh_s_boolean_0();
147
}
148
}
149
150
private static void test_byte_0() {
151
for (int c = 0; c < CYCLES; c++) {
152
BlackholeTarget.bh_s_byte_0();
153
}
154
}
155
156
private static void test_char_0() {
157
for (int c = 0; c < CYCLES; c++) {
158
BlackholeTarget.bh_s_char_0();
159
}
160
}
161
162
private static void test_short_0() {
163
for (int c = 0; c < CYCLES; c++) {
164
BlackholeTarget.bh_s_short_0();
165
}
166
}
167
168
private static void test_int_0() {
169
for (int c = 0; c < CYCLES; c++) {
170
BlackholeTarget.bh_s_int_0();
171
}
172
}
173
174
private static void test_is_int_0() {
175
BlackholeTarget t = new BlackholeTarget();
176
for (int c = 0; c < CYCLES; c++) {
177
t.bh_is_int_0();
178
}
179
}
180
181
private static void test_float_0() {
182
for (int c = 0; c < CYCLES; c++) {
183
BlackholeTarget.bh_s_float_0();
184
}
185
}
186
187
private static void test_long_0() {
188
for (int c = 0; c < CYCLES; c++) {
189
BlackholeTarget.bh_s_long_0();
190
}
191
}
192
193
private static void test_double_0() {
194
for (int c = 0; c < CYCLES; c++) {
195
BlackholeTarget.bh_s_double_0();
196
}
197
}
198
199
private static void test_Object_0() {
200
for (int c = 0; c < CYCLES; c++) {
201
BlackholeTarget.bh_s_Object_0();
202
}
203
}
204
205
private static void test_is_Object_0() {
206
BlackholeTarget t = new BlackholeTarget();
207
for (int c = 0; c < CYCLES; c++) {
208
t.bh_is_Object_0();
209
}
210
}
211
212
private static void test_boolean_1() {
213
for (int c = 0; c < CYCLES; c++) {
214
BlackholeTarget.bh_s_boolean_1((c & 0x1) == 0);
215
}
216
}
217
218
private static void test_byte_1() {
219
for (int c = 0; c < CYCLES; c++) {
220
BlackholeTarget.bh_s_byte_1((byte)c);
221
}
222
}
223
224
private static void test_char_1() {
225
for (int c = 0; c < CYCLES; c++) {
226
BlackholeTarget.bh_s_char_1((char)c);
227
}
228
}
229
230
private static void test_short_1() {
231
for (int c = 0; c < CYCLES; c++) {
232
BlackholeTarget.bh_s_short_1((short)c);
233
}
234
}
235
236
private static void test_int_1() {
237
for (int c = 0; c < CYCLES; c++) {
238
BlackholeTarget.bh_s_int_1(c);
239
}
240
}
241
242
private static void test_is_int_1() {
243
BlackholeTarget t = new BlackholeTarget();
244
for (int c = 0; c < CYCLES; c++) {
245
t.bh_is_int_1(c);
246
}
247
}
248
249
private static void test_float_1() {
250
for (int c = 0; c < CYCLES; c++) {
251
BlackholeTarget.bh_s_float_1(c);
252
}
253
}
254
255
private static void test_long_1() {
256
for (int c = 0; c < CYCLES; c++) {
257
BlackholeTarget.bh_s_long_1(c);
258
}
259
}
260
261
private static void test_double_1() {
262
for (int c = 0; c < CYCLES; c++) {
263
BlackholeTarget.bh_s_double_1(c);
264
}
265
}
266
267
private static void test_Object_1() {
268
for (int c = 0; c < CYCLES; c++) {
269
Object o = new Object();
270
BlackholeTarget.bh_s_Object_1(o);
271
}
272
}
273
274
private static void test_is_Object_1() {
275
BlackholeTarget t = new BlackholeTarget();
276
for (int c = 0; c < CYCLES; c++) {
277
Object o = new Object();
278
t.bh_is_Object_1(o);
279
}
280
}
281
282
private static void test_boolean_2() {
283
for (int c = 0; c < CYCLES; c++) {
284
BlackholeTarget.bh_s_boolean_2((c & 0x1) == 0, (c & 0x2) == 0);
285
}
286
}
287
288
private static void test_byte_2() {
289
for (int c = 0; c < CYCLES; c++) {
290
BlackholeTarget.bh_s_byte_2((byte)c, (byte)(c + 1));
291
}
292
}
293
294
private static void test_char_2() {
295
for (int c = 0; c < CYCLES; c++) {
296
BlackholeTarget.bh_s_char_2((char)c, (char)(c + 1));
297
}
298
}
299
300
private static void test_short_2() {
301
for (int c = 0; c < CYCLES; c++) {
302
BlackholeTarget.bh_s_short_2((short)c, (short)(c + 1));
303
}
304
}
305
306
private static void test_int_2() {
307
for (int c = 0; c < CYCLES; c++) {
308
BlackholeTarget.bh_s_int_2(c, c + 1);
309
}
310
}
311
312
private static void test_is_int_2() {
313
BlackholeTarget t = new BlackholeTarget();
314
for (int c = 0; c < CYCLES; c++) {
315
t.bh_is_int_2(c, c + 1);
316
}
317
}
318
319
private static void test_float_2() {
320
for (int c = 0; c < CYCLES; c++) {
321
BlackholeTarget.bh_s_float_2(c, c + 1);
322
}
323
}
324
325
private static void test_long_2() {
326
for (int c = 0; c < CYCLES; c++) {
327
BlackholeTarget.bh_s_long_2(c, c + 1);
328
}
329
}
330
331
private static void test_double_2() {
332
for (int c = 0; c < CYCLES; c++) {
333
BlackholeTarget.bh_s_double_2(c, c + 1);
334
}
335
}
336
337
private static void test_Object_2() {
338
for (int c = 0; c < CYCLES; c++) {
339
Object o1 = new Object();
340
Object o2 = new Object();
341
BlackholeTarget.bh_s_Object_2(o1, o2);
342
}
343
}
344
345
private static void test_is_Object_2() {
346
BlackholeTarget t = new BlackholeTarget();
347
for (int c = 0; c < CYCLES; c++) {
348
Object o1 = new Object();
349
Object o2 = new Object();
350
t.bh_is_Object_2(o1, o2);
351
}
352
}
353
}
354
355