Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/stable/TestStableBoolean.java
41152 views
1
/*
2
* Copyright (c) 2014, 2018, 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 TestStableBoolean
26
* @summary tests on stable fields and arrays
27
* @library /test/lib /
28
* @modules java.base/jdk.internal.misc
29
* @modules java.base/jdk.internal.vm.annotation
30
* @build sun.hotspot.WhiteBox
31
*
32
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
33
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
34
* -XX:-TieredCompilation
35
* -XX:+FoldStableValues
36
* compiler.stable.TestStableBoolean
37
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
38
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
39
* -XX:-TieredCompilation
40
* -XX:-FoldStableValues
41
* compiler.stable.TestStableBoolean
42
*
43
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
44
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
45
* -XX:+TieredCompilation -XX:TieredStopAtLevel=1
46
* -XX:+FoldStableValues
47
* compiler.stable.TestStableBoolean
48
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
49
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
50
* -XX:+TieredCompilation -XX:TieredStopAtLevel=1
51
* -XX:-FoldStableValues
52
* compiler.stable.TestStableBoolean
53
*/
54
55
package compiler.stable;
56
57
import jdk.internal.vm.annotation.Stable;
58
59
import java.lang.reflect.InvocationTargetException;
60
61
public class TestStableBoolean {
62
static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
63
64
public static void main(String[] args) throws Exception {
65
run(DefaultValue.class);
66
run(BooleanStable.class);
67
run(DefaultStaticValue.class);
68
run(StaticBooleanStable.class);
69
run(VolatileBooleanStable.class);
70
71
// @Stable arrays: Dim 1-4
72
run(BooleanArrayDim1.class);
73
run(BooleanArrayDim2.class);
74
run(BooleanArrayDim3.class);
75
run(BooleanArrayDim4.class);
76
77
// @Stable Object field: dynamic arrays
78
run(ObjectArrayLowerDim0.class);
79
run(ObjectArrayLowerDim1.class);
80
run(ObjectArrayLowerDim2.class);
81
82
// Nested @Stable fields
83
run(NestedStableField.class);
84
run(NestedStableField1.class);
85
run(NestedStableField2.class);
86
run(NestedStableField3.class);
87
88
if (failed) {
89
throw new Error("TEST FAILED");
90
}
91
}
92
93
/* ==================================================== */
94
95
static class DefaultValue {
96
public @Stable boolean v;
97
98
public static final DefaultValue c = new DefaultValue();
99
public static boolean get() { return c.v; }
100
public static void test() throws Exception {
101
boolean val1 = get();
102
c.v = true; boolean val2 = get();
103
assertEquals(val1, false);
104
assertEquals(val2, true);
105
}
106
}
107
108
/* ==================================================== */
109
110
static class BooleanStable {
111
public @Stable boolean v;
112
113
public static final BooleanStable c = new BooleanStable();
114
public static boolean get() { return c.v; }
115
public static void test() throws Exception {
116
c.v = true; boolean val1 = get();
117
c.v = false; boolean val2 = get();
118
assertEquals(val1, true);
119
assertEquals(val2, (isStableEnabled ? true : false));
120
}
121
}
122
123
/* ==================================================== */
124
125
static class DefaultStaticValue {
126
public static @Stable boolean v;
127
128
public static final DefaultStaticValue c = new DefaultStaticValue();
129
public static boolean get() { return c.v; }
130
public static void test() throws Exception {
131
boolean val1 = get();
132
c.v = true; boolean val2 = get();
133
assertEquals(val1, false);
134
assertEquals(val2, true);
135
}
136
}
137
138
/* ==================================================== */
139
140
static class StaticBooleanStable {
141
public static @Stable boolean v;
142
143
public static final StaticBooleanStable c = new StaticBooleanStable();
144
public static boolean get() { return c.v; }
145
public static void test() throws Exception {
146
c.v = true; boolean val1 = get();
147
c.v = false; boolean val2 = get();
148
assertEquals(val1, true);
149
assertEquals(val2, (isStableEnabled ? true : false));
150
}
151
}
152
153
/* ==================================================== */
154
155
static class VolatileBooleanStable {
156
public @Stable volatile boolean v;
157
158
public static final VolatileBooleanStable c = new VolatileBooleanStable();
159
public static boolean get() { return c.v; }
160
public static void test() throws Exception {
161
c.v = true; boolean val1 = get();
162
c.v = false; boolean val2 = get();
163
assertEquals(val1, true);
164
assertEquals(val2, (isStableEnabled ? true : false));
165
}
166
}
167
168
/* ==================================================== */
169
// @Stable array == field && all components are stable
170
171
static class BooleanArrayDim1 {
172
public @Stable boolean[] v;
173
174
public static final BooleanArrayDim1 c = new BooleanArrayDim1();
175
public static boolean get() { return c.v[0]; }
176
public static boolean get1() { return c.v[10]; }
177
public static boolean[] get2() { return c.v; }
178
public static void test() throws Exception {
179
{
180
c.v = new boolean[1]; c.v[0] = true; boolean val1 = get();
181
c.v[0] = false; boolean val2 = get();
182
assertEquals(val1, true);
183
assertEquals(val2, (isStableEnabled ? true : false));
184
}
185
186
{
187
c.v = new boolean[20]; c.v[10] = true; boolean val1 = get1();
188
c.v[10] = false; boolean val2 = get1();
189
assertEquals(val1, true);
190
assertEquals(val2, (isStableEnabled ? true : false));
191
}
192
193
{
194
c.v = new boolean[1]; boolean[] val1 = get2();
195
c.v = new boolean[1]; boolean[] val2 = get2();
196
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
197
}
198
}
199
}
200
201
/* ==================================================== */
202
203
static class BooleanArrayDim2 {
204
public @Stable boolean[][] v;
205
206
public static final BooleanArrayDim2 c = new BooleanArrayDim2();
207
public static boolean get() { return c.v[0][0]; }
208
public static boolean[] get1() { return c.v[0]; }
209
public static boolean[][] get2() { return c.v; }
210
public static void test() throws Exception {
211
{
212
c.v = new boolean[1][1]; c.v[0][0] = true; boolean val1 = get();
213
c.v[0][0] = false; boolean val2 = get();
214
assertEquals(val1, true);
215
assertEquals(val2, (isStableEnabled ? true : false));
216
217
c.v = new boolean[1][1]; c.v[0][0] = false; boolean val3 = get();
218
assertEquals(val3, (isStableEnabled ? true : false));
219
220
c.v[0] = new boolean[1]; c.v[0][0] = false; boolean val4 = get();
221
assertEquals(val4, (isStableEnabled ? true : false));
222
}
223
224
{
225
c.v = new boolean[1][1]; boolean[] val1 = get1();
226
c.v[0] = new boolean[1]; boolean[] val2 = get1();
227
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
228
}
229
230
{
231
c.v = new boolean[1][1]; boolean[][] val1 = get2();
232
c.v = new boolean[1][1]; boolean[][] val2 = get2();
233
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
234
}
235
}
236
}
237
238
/* ==================================================== */
239
240
static class BooleanArrayDim3 {
241
public @Stable boolean[][][] v;
242
243
public static final BooleanArrayDim3 c = new BooleanArrayDim3();
244
public static boolean get() { return c.v[0][0][0]; }
245
public static boolean[] get1() { return c.v[0][0]; }
246
public static boolean[][] get2() { return c.v[0]; }
247
public static boolean[][][] get3() { return c.v; }
248
public static void test() throws Exception {
249
{
250
c.v = new boolean[1][1][1]; c.v[0][0][0] = true; boolean val1 = get();
251
c.v[0][0][0] = false; boolean val2 = get();
252
assertEquals(val1, true);
253
assertEquals(val2, (isStableEnabled ? true : false));
254
255
c.v = new boolean[1][1][1]; c.v[0][0][0] = false; boolean val3 = get();
256
assertEquals(val3, (isStableEnabled ? true : false));
257
258
c.v[0] = new boolean[1][1]; c.v[0][0][0] = false; boolean val4 = get();
259
assertEquals(val4, (isStableEnabled ? true : false));
260
261
c.v[0][0] = new boolean[1]; c.v[0][0][0] = false; boolean val5 = get();
262
assertEquals(val5, (isStableEnabled ? true : false));
263
}
264
265
{
266
c.v = new boolean[1][1][1]; boolean[] val1 = get1();
267
c.v[0][0] = new boolean[1]; boolean[] val2 = get1();
268
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
269
}
270
271
{
272
c.v = new boolean[1][1][1]; boolean[][] val1 = get2();
273
c.v[0] = new boolean[1][1]; boolean[][] val2 = get2();
274
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
275
}
276
277
{
278
c.v = new boolean[1][1][1]; boolean[][][] val1 = get3();
279
c.v = new boolean[1][1][1]; boolean[][][] val2 = get3();
280
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
281
}
282
}
283
}
284
285
/* ==================================================== */
286
287
static class BooleanArrayDim4 {
288
public @Stable boolean[][][][] v;
289
290
public static final BooleanArrayDim4 c = new BooleanArrayDim4();
291
public static boolean get() { return c.v[0][0][0][0]; }
292
public static boolean[] get1() { return c.v[0][0][0]; }
293
public static boolean[][] get2() { return c.v[0][0]; }
294
public static boolean[][][] get3() { return c.v[0]; }
295
public static boolean[][][][] get4() { return c.v; }
296
public static void test() throws Exception {
297
{
298
c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = true; boolean val1 = get();
299
c.v[0][0][0][0] = false; boolean val2 = get();
300
assertEquals(val1, true);
301
assertEquals(val2, (isStableEnabled ? true : false));
302
303
c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = false; boolean val3 = get();
304
assertEquals(val3, (isStableEnabled ? true : false));
305
306
c.v[0] = new boolean[1][1][1]; c.v[0][0][0][0] = false; boolean val4 = get();
307
assertEquals(val4, (isStableEnabled ? true : false));
308
309
c.v[0][0] = new boolean[1][1]; c.v[0][0][0][0] = false; boolean val5 = get();
310
assertEquals(val5, (isStableEnabled ? true : false));
311
312
c.v[0][0][0] = new boolean[1]; c.v[0][0][0][0] = false; boolean val6 = get();
313
assertEquals(val6, (isStableEnabled ? true : false));
314
}
315
316
{
317
c.v = new boolean[1][1][1][1]; boolean[] val1 = get1();
318
c.v[0][0][0] = new boolean[1]; boolean[] val2 = get1();
319
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
320
}
321
322
{
323
c.v = new boolean[1][1][1][1]; boolean[][] val1 = get2();
324
c.v[0][0] = new boolean[1][1]; boolean[][] val2 = get2();
325
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
326
}
327
328
{
329
c.v = new boolean[1][1][1][1]; boolean[][][] val1 = get3();
330
c.v[0] = new boolean[1][1][1]; boolean[][][] val2 = get3();
331
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
332
}
333
334
{
335
c.v = new boolean[1][1][1][1]; boolean[][][][] val1 = get4();
336
c.v = new boolean[1][1][1][1]; boolean[][][][] val2 = get4();
337
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
338
}
339
340
}
341
}
342
343
/* ==================================================== */
344
// Dynamic Dim is higher than static
345
346
static class ObjectArrayLowerDim0 {
347
public @Stable Object v;
348
349
public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
350
public static boolean get() { return ((boolean[])c.v)[0]; }
351
public static boolean[] get1() { return (boolean[])c.v; }
352
public static boolean[] get2() { return (boolean[])c.v; }
353
354
public static void test() throws Exception {
355
{
356
c.v = new boolean[1]; ((boolean[])c.v)[0] = true; boolean val1 = get();
357
((boolean[])c.v)[0] = false; boolean val2 = get();
358
359
assertEquals(val1, true);
360
assertEquals(val2, false);
361
}
362
363
{
364
c.v = new boolean[1]; boolean[] val1 = get1();
365
c.v = new boolean[1]; boolean[] val2 = get1();
366
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
367
}
368
}
369
}
370
371
/* ==================================================== */
372
373
static class ObjectArrayLowerDim1 {
374
public @Stable Object[] v;
375
376
public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
377
public static boolean get() { return ((boolean[][])c.v)[0][0]; }
378
public static boolean[] get1() { return (boolean[])(c.v[0]); }
379
public static Object[] get2() { return c.v; }
380
381
public static void test() throws Exception {
382
{
383
c.v = new boolean[1][1]; ((boolean[][])c.v)[0][0] = true; boolean val1 = get();
384
((boolean[][])c.v)[0][0] = false; boolean val2 = get();
385
386
assertEquals(val1, true);
387
assertEquals(val2, false);
388
}
389
390
{
391
c.v = new boolean[1][1]; c.v[0] = new boolean[0]; boolean[] val1 = get1();
392
c.v[0] = new boolean[0]; boolean[] val2 = get1();
393
394
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
395
}
396
397
{
398
c.v = new boolean[0][0]; Object[] val1 = get2();
399
c.v = new boolean[0][0]; Object[] val2 = get2();
400
401
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
402
}
403
}
404
}
405
406
/* ==================================================== */
407
408
static class ObjectArrayLowerDim2 {
409
public @Stable Object[][] v;
410
411
public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
412
public static boolean get() { return ((boolean[][][])c.v)[0][0][0]; }
413
public static boolean[] get1() { return (boolean[])(c.v[0][0]); }
414
public static boolean[][] get2() { return (boolean[][])(c.v[0]); }
415
public static Object[][] get3() { return c.v; }
416
417
public static void test() throws Exception {
418
{
419
c.v = new boolean[1][1][1]; ((boolean[][][])c.v)[0][0][0] = true; boolean val1 = get();
420
((boolean[][][])c.v)[0][0][0] = false; boolean val2 = get();
421
422
assertEquals(val1, true);
423
assertEquals(val2, false);
424
}
425
426
{
427
c.v = new boolean[1][1][1]; c.v[0][0] = new boolean[0]; boolean[] val1 = get1();
428
c.v[0][0] = new boolean[0]; boolean[] val2 = get1();
429
430
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
431
}
432
433
{
434
c.v = new boolean[1][1][1]; c.v[0] = new boolean[0][0]; boolean[][] val1 = get2();
435
c.v[0] = new boolean[0][0]; boolean[][] val2 = get2();
436
437
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
438
}
439
440
{
441
c.v = new boolean[0][0][0]; Object[][] val1 = get3();
442
c.v = new boolean[0][0][0]; Object[][] val2 = get3();
443
444
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
445
}
446
}
447
}
448
449
/* ==================================================== */
450
451
static class NestedStableField {
452
static class A {
453
public @Stable boolean a;
454
455
}
456
public @Stable A v;
457
458
public static final NestedStableField c = new NestedStableField();
459
public static A get() { return c.v; }
460
public static boolean get1() { return get().a; }
461
462
public static void test() throws Exception {
463
{
464
c.v = new A(); c.v.a = true; A val1 = get();
465
c.v.a = false; A val2 = get();
466
467
assertEquals(val1.a, false);
468
assertEquals(val2.a, false);
469
}
470
471
{
472
c.v = new A(); c.v.a = true; boolean val1 = get1();
473
c.v.a = false; boolean val2 = get1();
474
c.v = new A(); c.v.a = false; boolean val3 = get1();
475
476
assertEquals(val1, true);
477
assertEquals(val2, (isStableEnabled ? true : false));
478
assertEquals(val3, (isStableEnabled ? true : false));
479
}
480
}
481
}
482
483
/* ==================================================== */
484
485
static class NestedStableField1 {
486
static class A {
487
public @Stable boolean a;
488
public @Stable A next;
489
}
490
public @Stable A v;
491
492
public static final NestedStableField1 c = new NestedStableField1();
493
public static A get() { return c.v.next.next.next.next.next.next.next; }
494
public static boolean get1() { return get().a; }
495
496
public static void test() throws Exception {
497
{
498
c.v = new A(); c.v.next = new A(); c.v.next.next = c.v;
499
c.v.a = true; c.v.next.a = true; A val1 = get();
500
c.v.a = false; c.v.next.a = false; A val2 = get();
501
502
assertEquals(val1.a, false);
503
assertEquals(val2.a, false);
504
}
505
506
{
507
c.v = new A(); c.v.next = c.v;
508
c.v.a = true; boolean val1 = get1();
509
c.v.a = false; boolean val2 = get1();
510
c.v = new A(); c.v.next = c.v;
511
c.v.a = false; boolean val3 = get1();
512
513
assertEquals(val1, true);
514
assertEquals(val2, (isStableEnabled ? true : false));
515
assertEquals(val3, (isStableEnabled ? true : false));
516
}
517
}
518
}
519
/* ==================================================== */
520
521
static class NestedStableField2 {
522
static class A {
523
public @Stable boolean a;
524
public @Stable A left;
525
public A right;
526
}
527
528
public @Stable A v;
529
530
public static final NestedStableField2 c = new NestedStableField2();
531
public static boolean get() { return c.v.left.left.left.a; }
532
public static boolean get1() { return c.v.left.left.right.left.a; }
533
534
public static void test() throws Exception {
535
{
536
c.v = new A(); c.v.left = c.v.right = c.v;
537
c.v.a = true; boolean val1 = get(); boolean val2 = get1();
538
c.v.a = false; boolean val3 = get(); boolean val4 = get1();
539
540
assertEquals(val1, true);
541
assertEquals(val3, (isStableEnabled ? true : false));
542
543
assertEquals(val2, true);
544
assertEquals(val4, false);
545
}
546
}
547
}
548
549
/* ==================================================== */
550
551
static class NestedStableField3 {
552
static class A {
553
public @Stable boolean a;
554
public @Stable A[] left;
555
public A[] right;
556
}
557
558
public @Stable A[] v;
559
560
public static final NestedStableField3 c = new NestedStableField3();
561
public static boolean get() { return c.v[0].left[1].left[0].left[1].a; }
562
public static boolean get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
563
564
public static void test() throws Exception {
565
{
566
A elem = new A();
567
c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
568
elem.a = true; boolean val1 = get(); boolean val2 = get1();
569
elem.a = false; boolean val3 = get(); boolean val4 = get1();
570
571
assertEquals(val1, true);
572
assertEquals(val3, (isStableEnabled ? true : false));
573
574
assertEquals(val2, true);
575
assertEquals(val4, false);
576
}
577
}
578
}
579
580
/* ==================================================== */
581
// Auxiliary methods
582
static void assertEquals(boolean i, boolean j) { if (i != j) throw new AssertionError(i + " != " + j); }
583
static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }
584
585
static boolean failed = false;
586
587
public static void run(Class<?> test) {
588
Throwable ex = null;
589
System.out.print(test.getName()+": ");
590
try {
591
test.getMethod("test").invoke(null);
592
} catch (InvocationTargetException e) {
593
ex = e.getCause();
594
} catch (Throwable e) {
595
ex = e;
596
} finally {
597
if (ex == null) {
598
System.out.println("PASSED");
599
} else {
600
failed = true;
601
System.out.println("FAILED");
602
ex.printStackTrace(System.out);
603
}
604
}
605
}
606
}
607
608