71 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
72 * -XX:+FoldStableValues
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
74 * java.lang.invoke.TestStableBoolean
75 * @run main/othervm -Xbootclasspath/a:.
76 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
77 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
78 * -XX:-FoldStableValues
79 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
80 * java.lang.invoke.TestStableBoolean
81 *
82 */
83 package java.lang.invoke;
84
85 import jdk.internal.vm.annotation.Stable;
86
87 import java.lang.reflect.InvocationTargetException;
88
89 public class TestStableBoolean {
90 static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
91 static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
92
93 public static void main(String[] args) throws Exception {
94 run(DefaultValue.class);
95 run(BooleanStable.class);
96 run(DefaultStaticValue.class);
97 run(StaticBooleanStable.class);
98 run(VolatileBooleanStable.class);
99
100 // @Stable arrays: Dim 1-4
101 run(BooleanArrayDim1.class);
102 run(BooleanArrayDim2.class);
103 run(BooleanArrayDim3.class);
104 run(BooleanArrayDim4.class);
105
106 // @Stable Object field: dynamic arrays
107 run(ObjectArrayLowerDim0.class);
108 run(ObjectArrayLowerDim1.class);
109 run(ObjectArrayLowerDim2.class);
110
111 // Nested @Stable fields
192 assertEquals(val1, true);
193 assertEquals(val2, (isStableEnabled ? true : false));
194 }
195 }
196
197 /* ==================================================== */
198 // @Stable array == field && all components are stable
199
200 static class BooleanArrayDim1 {
201 public @Stable boolean[] v;
202
203 public static final BooleanArrayDim1 c = new BooleanArrayDim1();
204 public static boolean get() { return c.v[0]; }
205 public static boolean get1() { return c.v[10]; }
206 public static boolean[] get2() { return c.v; }
207 public static void test() throws Exception {
208 {
209 c.v = new boolean[1]; c.v[0] = true; boolean val1 = get();
210 c.v[0] = false; boolean val2 = get();
211 assertEquals(val1, true);
212 assertEquals(val2, (isServerWithStable ? true : false));
213 }
214
215 {
216 c.v = new boolean[20]; c.v[10] = true; boolean val1 = get1();
217 c.v[10] = false; boolean val2 = get1();
218 assertEquals(val1, true);
219 assertEquals(val2, (isServerWithStable ? true : false));
220 }
221
222 {
223 c.v = new boolean[1]; boolean[] val1 = get2();
224 c.v = new boolean[1]; boolean[] val2 = get2();
225 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
226 }
227 }
228 }
229
230 /* ==================================================== */
231
232 static class BooleanArrayDim2 {
233 public @Stable boolean[][] v;
234
235 public static final BooleanArrayDim2 c = new BooleanArrayDim2();
236 public static boolean get() { return c.v[0][0]; }
237 public static boolean[] get1() { return c.v[0]; }
238 public static boolean[][] get2() { return c.v; }
239 public static void test() throws Exception {
240 {
241 c.v = new boolean[1][1]; c.v[0][0] = true; boolean val1 = get();
242 c.v[0][0] = false; boolean val2 = get();
243 assertEquals(val1, true);
244 assertEquals(val2, (isServerWithStable ? true : false));
245
246 c.v = new boolean[1][1]; c.v[0][0] = false; boolean val3 = get();
247 assertEquals(val3, (isServerWithStable ? true : false));
248
249 c.v[0] = new boolean[1]; c.v[0][0] = false; boolean val4 = get();
250 assertEquals(val4, (isServerWithStable ? true : false));
251 }
252
253 {
254 c.v = new boolean[1][1]; boolean[] val1 = get1();
255 c.v[0] = new boolean[1]; boolean[] val2 = get1();
256 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
257 }
258
259 {
260 c.v = new boolean[1][1]; boolean[][] val1 = get2();
261 c.v = new boolean[1][1]; boolean[][] val2 = get2();
262 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
263 }
264 }
265 }
266
267 /* ==================================================== */
268
269 static class BooleanArrayDim3 {
270 public @Stable boolean[][][] v;
271
272 public static final BooleanArrayDim3 c = new BooleanArrayDim3();
273 public static boolean get() { return c.v[0][0][0]; }
274 public static boolean[] get1() { return c.v[0][0]; }
275 public static boolean[][] get2() { return c.v[0]; }
276 public static boolean[][][] get3() { return c.v; }
277 public static void test() throws Exception {
278 {
279 c.v = new boolean[1][1][1]; c.v[0][0][0] = true; boolean val1 = get();
280 c.v[0][0][0] = false; boolean val2 = get();
281 assertEquals(val1, true);
282 assertEquals(val2, (isServerWithStable ? true : false));
283
284 c.v = new boolean[1][1][1]; c.v[0][0][0] = false; boolean val3 = get();
285 assertEquals(val3, (isServerWithStable ? true : false));
286
287 c.v[0] = new boolean[1][1]; c.v[0][0][0] = false; boolean val4 = get();
288 assertEquals(val4, (isServerWithStable ? true : false));
289
290 c.v[0][0] = new boolean[1]; c.v[0][0][0] = false; boolean val5 = get();
291 assertEquals(val5, (isServerWithStable ? true : false));
292 }
293
294 {
295 c.v = new boolean[1][1][1]; boolean[] val1 = get1();
296 c.v[0][0] = new boolean[1]; boolean[] val2 = get1();
297 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
298 }
299
300 {
301 c.v = new boolean[1][1][1]; boolean[][] val1 = get2();
302 c.v[0] = new boolean[1][1]; boolean[][] val2 = get2();
303 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
304 }
305
306 {
307 c.v = new boolean[1][1][1]; boolean[][][] val1 = get3();
308 c.v = new boolean[1][1][1]; boolean[][][] val2 = get3();
309 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
310 }
311 }
312 }
313
314 /* ==================================================== */
315
316 static class BooleanArrayDim4 {
317 public @Stable boolean[][][][] v;
318
319 public static final BooleanArrayDim4 c = new BooleanArrayDim4();
320 public static boolean get() { return c.v[0][0][0][0]; }
321 public static boolean[] get1() { return c.v[0][0][0]; }
322 public static boolean[][] get2() { return c.v[0][0]; }
323 public static boolean[][][] get3() { return c.v[0]; }
324 public static boolean[][][][] get4() { return c.v; }
325 public static void test() throws Exception {
326 {
327 c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = true; boolean val1 = get();
328 c.v[0][0][0][0] = false; boolean val2 = get();
329 assertEquals(val1, true);
330 assertEquals(val2, (isServerWithStable ? true : false));
331
332 c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = false; boolean val3 = get();
333 assertEquals(val3, (isServerWithStable ? true : false));
334
335 c.v[0] = new boolean[1][1][1]; c.v[0][0][0][0] = false; boolean val4 = get();
336 assertEquals(val4, (isServerWithStable ? true : false));
337
338 c.v[0][0] = new boolean[1][1]; c.v[0][0][0][0] = false; boolean val5 = get();
339 assertEquals(val5, (isServerWithStable ? true : false));
340
341 c.v[0][0][0] = new boolean[1]; c.v[0][0][0][0] = false; boolean val6 = get();
342 assertEquals(val6, (isServerWithStable ? true : false));
343 }
344
345 {
346 c.v = new boolean[1][1][1][1]; boolean[] val1 = get1();
347 c.v[0][0][0] = new boolean[1]; boolean[] val2 = get1();
348 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
349 }
350
351 {
352 c.v = new boolean[1][1][1][1]; boolean[][] val1 = get2();
353 c.v[0][0] = new boolean[1][1]; boolean[][] val2 = get2();
354 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
355 }
356
357 {
358 c.v = new boolean[1][1][1][1]; boolean[][][] val1 = get3();
359 c.v[0] = new boolean[1][1][1]; boolean[][][] val2 = get3();
360 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
361 }
362
363 {
364 c.v = new boolean[1][1][1][1]; boolean[][][][] val1 = get4();
365 c.v = new boolean[1][1][1][1]; boolean[][][][] val2 = get4();
366 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
367 }
368
369 }
370 }
371
372 /* ==================================================== */
373 // Dynamic Dim is higher than static
374
375 static class ObjectArrayLowerDim0 {
376 public @Stable Object v;
377
378 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
379 public static boolean get() { return ((boolean[])c.v)[0]; }
380 public static boolean[] get1() { return (boolean[])c.v; }
403 public @Stable Object[] v;
404
405 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
406 public static boolean get() { return ((boolean[][])c.v)[0][0]; }
407 public static boolean[] get1() { return (boolean[])(c.v[0]); }
408 public static Object[] get2() { return c.v; }
409
410 public static void test() throws Exception {
411 {
412 c.v = new boolean[1][1]; ((boolean[][])c.v)[0][0] = true; boolean val1 = get();
413 ((boolean[][])c.v)[0][0] = false; boolean val2 = get();
414
415 assertEquals(val1, true);
416 assertEquals(val2, false);
417 }
418
419 {
420 c.v = new boolean[1][1]; c.v[0] = new boolean[0]; boolean[] val1 = get1();
421 c.v[0] = new boolean[0]; boolean[] val2 = get1();
422
423 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
424 }
425
426 {
427 c.v = new boolean[0][0]; Object[] val1 = get2();
428 c.v = new boolean[0][0]; Object[] val2 = get2();
429
430 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
431 }
432 }
433 }
434
435 /* ==================================================== */
436
437 static class ObjectArrayLowerDim2 {
438 public @Stable Object[][] v;
439
440 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
441 public static boolean get() { return ((boolean[][][])c.v)[0][0][0]; }
442 public static boolean[] get1() { return (boolean[])(c.v[0][0]); }
443 public static boolean[][] get2() { return (boolean[][])(c.v[0]); }
444 public static Object[][] get3() { return c.v; }
445
446 public static void test() throws Exception {
447 {
448 c.v = new boolean[1][1][1]; ((boolean[][][])c.v)[0][0][0] = true; boolean val1 = get();
449 ((boolean[][][])c.v)[0][0][0] = false; boolean val2 = get();
450
451 assertEquals(val1, true);
452 assertEquals(val2, false);
453 }
454
455 {
456 c.v = new boolean[1][1][1]; c.v[0][0] = new boolean[0]; boolean[] val1 = get1();
457 c.v[0][0] = new boolean[0]; boolean[] val2 = get1();
458
459 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
460 }
461
462 {
463 c.v = new boolean[1][1][1]; c.v[0] = new boolean[0][0]; boolean[][] val1 = get2();
464 c.v[0] = new boolean[0][0]; boolean[][] val2 = get2();
465
466 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
467 }
468
469 {
470 c.v = new boolean[0][0][0]; Object[][] val1 = get3();
471 c.v = new boolean[0][0][0]; Object[][] val2 = get3();
472
473 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
474 }
475 }
476 }
477
478 /* ==================================================== */
479
480 static class NestedStableField {
481 static class A {
482 public @Stable boolean a;
483
484 }
485 public @Stable A v;
486
581 static class A {
582 public @Stable boolean a;
583 public @Stable A[] left;
584 public A[] right;
585 }
586
587 public @Stable A[] v;
588
589 public static final NestedStableField3 c = new NestedStableField3();
590 public static boolean get() { return c.v[0].left[1].left[0].left[1].a; }
591 public static boolean get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
592
593 public static void test() throws Exception {
594 {
595 A elem = new A();
596 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
597 elem.a = true; boolean val1 = get(); boolean val2 = get1();
598 elem.a = false; boolean val3 = get(); boolean val4 = get1();
599
600 assertEquals(val1, true);
601 assertEquals(val3, (isServerWithStable ? true : false));
602
603 assertEquals(val2, true);
604 assertEquals(val4, false);
605 }
606 }
607 }
608
609 /* ==================================================== */
610 // Auxiliary methods
611 static void assertEquals(boolean i, boolean j) { if (i != j) throw new AssertionError(i + " != " + j); }
612 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }
613
614 static boolean failed = false;
615
616 public static void run(Class<?> test) {
617 Throwable ex = null;
618 System.out.print(test.getName()+": ");
619 try {
620 test.getMethod("test").invoke(null);
621 } catch (InvocationTargetException e) {
|
71 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
72 * -XX:+FoldStableValues
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
74 * java.lang.invoke.TestStableBoolean
75 * @run main/othervm -Xbootclasspath/a:.
76 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
77 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
78 * -XX:-FoldStableValues
79 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
80 * java.lang.invoke.TestStableBoolean
81 *
82 */
83 package java.lang.invoke;
84
85 import jdk.internal.vm.annotation.Stable;
86
87 import java.lang.reflect.InvocationTargetException;
88
89 public class TestStableBoolean {
90 static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
91
92 public static void main(String[] args) throws Exception {
93 run(DefaultValue.class);
94 run(BooleanStable.class);
95 run(DefaultStaticValue.class);
96 run(StaticBooleanStable.class);
97 run(VolatileBooleanStable.class);
98
99 // @Stable arrays: Dim 1-4
100 run(BooleanArrayDim1.class);
101 run(BooleanArrayDim2.class);
102 run(BooleanArrayDim3.class);
103 run(BooleanArrayDim4.class);
104
105 // @Stable Object field: dynamic arrays
106 run(ObjectArrayLowerDim0.class);
107 run(ObjectArrayLowerDim1.class);
108 run(ObjectArrayLowerDim2.class);
109
110 // Nested @Stable fields
191 assertEquals(val1, true);
192 assertEquals(val2, (isStableEnabled ? true : false));
193 }
194 }
195
196 /* ==================================================== */
197 // @Stable array == field && all components are stable
198
199 static class BooleanArrayDim1 {
200 public @Stable boolean[] v;
201
202 public static final BooleanArrayDim1 c = new BooleanArrayDim1();
203 public static boolean get() { return c.v[0]; }
204 public static boolean get1() { return c.v[10]; }
205 public static boolean[] get2() { return c.v; }
206 public static void test() throws Exception {
207 {
208 c.v = new boolean[1]; c.v[0] = true; boolean val1 = get();
209 c.v[0] = false; boolean val2 = get();
210 assertEquals(val1, true);
211 assertEquals(val2, (isStableEnabled ? true : false));
212 }
213
214 {
215 c.v = new boolean[20]; c.v[10] = true; boolean val1 = get1();
216 c.v[10] = false; boolean val2 = get1();
217 assertEquals(val1, true);
218 assertEquals(val2, (isStableEnabled ? true : false));
219 }
220
221 {
222 c.v = new boolean[1]; boolean[] val1 = get2();
223 c.v = new boolean[1]; boolean[] val2 = get2();
224 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
225 }
226 }
227 }
228
229 /* ==================================================== */
230
231 static class BooleanArrayDim2 {
232 public @Stable boolean[][] v;
233
234 public static final BooleanArrayDim2 c = new BooleanArrayDim2();
235 public static boolean get() { return c.v[0][0]; }
236 public static boolean[] get1() { return c.v[0]; }
237 public static boolean[][] get2() { return c.v; }
238 public static void test() throws Exception {
239 {
240 c.v = new boolean[1][1]; c.v[0][0] = true; boolean val1 = get();
241 c.v[0][0] = false; boolean val2 = get();
242 assertEquals(val1, true);
243 assertEquals(val2, (isStableEnabled ? true : false));
244
245 c.v = new boolean[1][1]; c.v[0][0] = false; boolean val3 = get();
246 assertEquals(val3, (isStableEnabled ? true : false));
247
248 c.v[0] = new boolean[1]; c.v[0][0] = false; boolean val4 = get();
249 assertEquals(val4, (isStableEnabled ? true : false));
250 }
251
252 {
253 c.v = new boolean[1][1]; boolean[] val1 = get1();
254 c.v[0] = new boolean[1]; boolean[] val2 = get1();
255 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
256 }
257
258 {
259 c.v = new boolean[1][1]; boolean[][] val1 = get2();
260 c.v = new boolean[1][1]; boolean[][] val2 = get2();
261 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
262 }
263 }
264 }
265
266 /* ==================================================== */
267
268 static class BooleanArrayDim3 {
269 public @Stable boolean[][][] v;
270
271 public static final BooleanArrayDim3 c = new BooleanArrayDim3();
272 public static boolean get() { return c.v[0][0][0]; }
273 public static boolean[] get1() { return c.v[0][0]; }
274 public static boolean[][] get2() { return c.v[0]; }
275 public static boolean[][][] get3() { return c.v; }
276 public static void test() throws Exception {
277 {
278 c.v = new boolean[1][1][1]; c.v[0][0][0] = true; boolean val1 = get();
279 c.v[0][0][0] = false; boolean val2 = get();
280 assertEquals(val1, true);
281 assertEquals(val2, (isStableEnabled ? true : false));
282
283 c.v = new boolean[1][1][1]; c.v[0][0][0] = false; boolean val3 = get();
284 assertEquals(val3, (isStableEnabled ? true : false));
285
286 c.v[0] = new boolean[1][1]; c.v[0][0][0] = false; boolean val4 = get();
287 assertEquals(val4, (isStableEnabled ? true : false));
288
289 c.v[0][0] = new boolean[1]; c.v[0][0][0] = false; boolean val5 = get();
290 assertEquals(val5, (isStableEnabled ? true : false));
291 }
292
293 {
294 c.v = new boolean[1][1][1]; boolean[] val1 = get1();
295 c.v[0][0] = new boolean[1]; boolean[] val2 = get1();
296 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
297 }
298
299 {
300 c.v = new boolean[1][1][1]; boolean[][] val1 = get2();
301 c.v[0] = new boolean[1][1]; boolean[][] val2 = get2();
302 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
303 }
304
305 {
306 c.v = new boolean[1][1][1]; boolean[][][] val1 = get3();
307 c.v = new boolean[1][1][1]; boolean[][][] val2 = get3();
308 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
309 }
310 }
311 }
312
313 /* ==================================================== */
314
315 static class BooleanArrayDim4 {
316 public @Stable boolean[][][][] v;
317
318 public static final BooleanArrayDim4 c = new BooleanArrayDim4();
319 public static boolean get() { return c.v[0][0][0][0]; }
320 public static boolean[] get1() { return c.v[0][0][0]; }
321 public static boolean[][] get2() { return c.v[0][0]; }
322 public static boolean[][][] get3() { return c.v[0]; }
323 public static boolean[][][][] get4() { return c.v; }
324 public static void test() throws Exception {
325 {
326 c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = true; boolean val1 = get();
327 c.v[0][0][0][0] = false; boolean val2 = get();
328 assertEquals(val1, true);
329 assertEquals(val2, (isStableEnabled ? true : false));
330
331 c.v = new boolean[1][1][1][1]; c.v[0][0][0][0] = false; boolean val3 = get();
332 assertEquals(val3, (isStableEnabled ? true : false));
333
334 c.v[0] = new boolean[1][1][1]; c.v[0][0][0][0] = false; boolean val4 = get();
335 assertEquals(val4, (isStableEnabled ? true : false));
336
337 c.v[0][0] = new boolean[1][1]; c.v[0][0][0][0] = false; boolean val5 = get();
338 assertEquals(val5, (isStableEnabled ? true : false));
339
340 c.v[0][0][0] = new boolean[1]; c.v[0][0][0][0] = false; boolean val6 = get();
341 assertEquals(val6, (isStableEnabled ? true : false));
342 }
343
344 {
345 c.v = new boolean[1][1][1][1]; boolean[] val1 = get1();
346 c.v[0][0][0] = new boolean[1]; boolean[] val2 = get1();
347 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
348 }
349
350 {
351 c.v = new boolean[1][1][1][1]; boolean[][] val1 = get2();
352 c.v[0][0] = new boolean[1][1]; boolean[][] val2 = get2();
353 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
354 }
355
356 {
357 c.v = new boolean[1][1][1][1]; boolean[][][] val1 = get3();
358 c.v[0] = new boolean[1][1][1]; boolean[][][] val2 = get3();
359 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
360 }
361
362 {
363 c.v = new boolean[1][1][1][1]; boolean[][][][] val1 = get4();
364 c.v = new boolean[1][1][1][1]; boolean[][][][] val2 = get4();
365 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
366 }
367
368 }
369 }
370
371 /* ==================================================== */
372 // Dynamic Dim is higher than static
373
374 static class ObjectArrayLowerDim0 {
375 public @Stable Object v;
376
377 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
378 public static boolean get() { return ((boolean[])c.v)[0]; }
379 public static boolean[] get1() { return (boolean[])c.v; }
402 public @Stable Object[] v;
403
404 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
405 public static boolean get() { return ((boolean[][])c.v)[0][0]; }
406 public static boolean[] get1() { return (boolean[])(c.v[0]); }
407 public static Object[] get2() { return c.v; }
408
409 public static void test() throws Exception {
410 {
411 c.v = new boolean[1][1]; ((boolean[][])c.v)[0][0] = true; boolean val1 = get();
412 ((boolean[][])c.v)[0][0] = false; boolean val2 = get();
413
414 assertEquals(val1, true);
415 assertEquals(val2, false);
416 }
417
418 {
419 c.v = new boolean[1][1]; c.v[0] = new boolean[0]; boolean[] val1 = get1();
420 c.v[0] = new boolean[0]; boolean[] val2 = get1();
421
422 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
423 }
424
425 {
426 c.v = new boolean[0][0]; Object[] val1 = get2();
427 c.v = new boolean[0][0]; Object[] val2 = get2();
428
429 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
430 }
431 }
432 }
433
434 /* ==================================================== */
435
436 static class ObjectArrayLowerDim2 {
437 public @Stable Object[][] v;
438
439 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
440 public static boolean get() { return ((boolean[][][])c.v)[0][0][0]; }
441 public static boolean[] get1() { return (boolean[])(c.v[0][0]); }
442 public static boolean[][] get2() { return (boolean[][])(c.v[0]); }
443 public static Object[][] get3() { return c.v; }
444
445 public static void test() throws Exception {
446 {
447 c.v = new boolean[1][1][1]; ((boolean[][][])c.v)[0][0][0] = true; boolean val1 = get();
448 ((boolean[][][])c.v)[0][0][0] = false; boolean val2 = get();
449
450 assertEquals(val1, true);
451 assertEquals(val2, false);
452 }
453
454 {
455 c.v = new boolean[1][1][1]; c.v[0][0] = new boolean[0]; boolean[] val1 = get1();
456 c.v[0][0] = new boolean[0]; boolean[] val2 = get1();
457
458 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
459 }
460
461 {
462 c.v = new boolean[1][1][1]; c.v[0] = new boolean[0][0]; boolean[][] val1 = get2();
463 c.v[0] = new boolean[0][0]; boolean[][] val2 = get2();
464
465 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
466 }
467
468 {
469 c.v = new boolean[0][0][0]; Object[][] val1 = get3();
470 c.v = new boolean[0][0][0]; Object[][] val2 = get3();
471
472 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
473 }
474 }
475 }
476
477 /* ==================================================== */
478
479 static class NestedStableField {
480 static class A {
481 public @Stable boolean a;
482
483 }
484 public @Stable A v;
485
580 static class A {
581 public @Stable boolean a;
582 public @Stable A[] left;
583 public A[] right;
584 }
585
586 public @Stable A[] v;
587
588 public static final NestedStableField3 c = new NestedStableField3();
589 public static boolean get() { return c.v[0].left[1].left[0].left[1].a; }
590 public static boolean get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
591
592 public static void test() throws Exception {
593 {
594 A elem = new A();
595 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
596 elem.a = true; boolean val1 = get(); boolean val2 = get1();
597 elem.a = false; boolean val3 = get(); boolean val4 = get1();
598
599 assertEquals(val1, true);
600 assertEquals(val3, (isStableEnabled ? true : false));
601
602 assertEquals(val2, true);
603 assertEquals(val4, false);
604 }
605 }
606 }
607
608 /* ==================================================== */
609 // Auxiliary methods
610 static void assertEquals(boolean i, boolean j) { if (i != j) throw new AssertionError(i + " != " + j); }
611 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }
612
613 static boolean failed = false;
614
615 public static void run(Class<?> test) {
616 Throwable ex = null;
617 System.out.print(test.getName()+": ");
618 try {
619 test.getMethod("test").invoke(null);
620 } catch (InvocationTargetException e) {
|