71 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
72 * -XX:+FoldStableValues
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
74 * java.lang.invoke.TestStableFloat
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.TestStableFloat
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 TestStableFloat {
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(FloatStable.class);
96 run(DefaultStaticValue.class);
97 run(StaticFloatStable.class);
98 run(VolatileFloatStable.class);
99
100 // @Stable arrays: Dim 1-4
101 run(FloatArrayDim1.class);
102 run(FloatArrayDim2.class);
103 run(FloatArrayDim3.class);
104 run(FloatArrayDim4.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, 1.0F);
193 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
194 }
195 }
196
197 /* ==================================================== */
198 // @Stable array == field && all components are stable
199
200 static class FloatArrayDim1 {
201 public @Stable float[] v;
202
203 public static final FloatArrayDim1 c = new FloatArrayDim1();
204 public static float get() { return c.v[0]; }
205 public static float get1() { return c.v[10]; }
206 public static float[] get2() { return c.v; }
207 public static void test() throws Exception {
208 {
209 c.v = new float[1]; c.v[0] = 1.0F; float val1 = get();
210 c.v[0] = 2.0F; float val2 = get();
211 assertEquals(val1, 1.0F);
212 assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
213
214 c.v = new float[1]; c.v[0] = 3.0F; float val3 = get();
215 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
216 : 3.0F));
217 }
218
219 {
220 c.v = new float[20]; c.v[10] = 1.0F; float val1 = get1();
221 c.v[10] = 2.0F; float val2 = get1();
222 assertEquals(val1, 1.0F);
223 assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
224
225 c.v = new float[20]; c.v[10] = 3.0F; float val3 = get1();
226 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
227 : 3.0F));
228 }
229
230 {
231 c.v = new float[1]; float[] val1 = get2();
232 c.v = new float[1]; float[] val2 = get2();
233 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
234 }
235 }
236 }
237
238 /* ==================================================== */
239
240 static class FloatArrayDim2 {
241 public @Stable float[][] v;
242
243 public static final FloatArrayDim2 c = new FloatArrayDim2();
244 public static float get() { return c.v[0][0]; }
245 public static float[] get1() { return c.v[0]; }
246 public static float[][] get2() { return c.v; }
247 public static void test() throws Exception {
248 {
249 c.v = new float[1][1]; c.v[0][0] = 1.0F; float val1 = get();
250 c.v[0][0] = 2.0F; float val2 = get();
251 assertEquals(val1, 1.0F);
252 assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
253
254 c.v = new float[1][1]; c.v[0][0] = 3.0F; float val3 = get();
255 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
256 : 3.0F));
257
258 c.v[0] = new float[1]; c.v[0][0] = 4.0F; float val4 = get();
259 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
260 : 4.0F));
261 }
262
263 {
264 c.v = new float[1][1]; float[] val1 = get1();
265 c.v[0] = new float[1]; float[] val2 = get1();
266 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
267 }
268
269 {
270 c.v = new float[1][1]; float[][] val1 = get2();
271 c.v = new float[1][1]; float[][] val2 = get2();
272 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
273 }
274 }
275 }
276
277 /* ==================================================== */
278
279 static class FloatArrayDim3 {
280 public @Stable float[][][] v;
281
282 public static final FloatArrayDim3 c = new FloatArrayDim3();
283 public static float get() { return c.v[0][0][0]; }
284 public static float[] get1() { return c.v[0][0]; }
285 public static float[][] get2() { return c.v[0]; }
286 public static float[][][] get3() { return c.v; }
287 public static void test() throws Exception {
288 {
289 c.v = new float[1][1][1]; c.v[0][0][0] = 1.0F; float val1 = get();
290 c.v[0][0][0] = 2.0F; float val2 = get();
291 assertEquals(val1, 1.0F);
292 assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
293
294 c.v = new float[1][1][1]; c.v[0][0][0] = 3.0F; float val3 = get();
295 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
296 : 3.0F));
297
298 c.v[0] = new float[1][1]; c.v[0][0][0] = 4.0F; float val4 = get();
299 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
300 : 4.0F));
301
302 c.v[0][0] = new float[1]; c.v[0][0][0] = 5.0F; float val5 = get();
303 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
304 : 5.0F));
305 }
306
307 {
308 c.v = new float[1][1][1]; float[] val1 = get1();
309 c.v[0][0] = new float[1]; float[] val2 = get1();
310 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
311 }
312
313 {
314 c.v = new float[1][1][1]; float[][] val1 = get2();
315 c.v[0] = new float[1][1]; float[][] val2 = get2();
316 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
317 }
318
319 {
320 c.v = new float[1][1][1]; float[][][] val1 = get3();
321 c.v = new float[1][1][1]; float[][][] val2 = get3();
322 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
323 }
324 }
325 }
326
327 /* ==================================================== */
328
329 static class FloatArrayDim4 {
330 public @Stable float[][][][] v;
331
332 public static final FloatArrayDim4 c = new FloatArrayDim4();
333 public static float get() { return c.v[0][0][0][0]; }
334 public static float[] get1() { return c.v[0][0][0]; }
335 public static float[][] get2() { return c.v[0][0]; }
336 public static float[][][] get3() { return c.v[0]; }
337 public static float[][][][] get4() { return c.v; }
338 public static void test() throws Exception {
339 {
340 c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 1.0F; float val1 = get();
341 c.v[0][0][0][0] = 2.0F; float val2 = get();
342 assertEquals(val1, 1.0F);
343 assertEquals(val2, (isServerWithStable ? 1.0F : 2.0F));
344
345 c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 3.0F; float val3 = get();
346 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
347 : 3.0F));
348
349 c.v[0] = new float[1][1][1]; c.v[0][0][0][0] = 4.0F; float val4 = get();
350 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
351 : 4.0F));
352
353 c.v[0][0] = new float[1][1]; c.v[0][0][0][0] = 5.0F; float val5 = get();
354 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
355 : 5.0F));
356
357 c.v[0][0][0] = new float[1]; c.v[0][0][0][0] = 6.0F; float val6 = get();
358 assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1.0F : 2.0F)
359 : 6.0F));
360 }
361
362 {
363 c.v = new float[1][1][1][1]; float[] val1 = get1();
364 c.v[0][0][0] = new float[1]; float[] val2 = get1();
365 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
366 }
367
368 {
369 c.v = new float[1][1][1][1]; float[][] val1 = get2();
370 c.v[0][0] = new float[1][1]; float[][] val2 = get2();
371 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
372 }
373
374 {
375 c.v = new float[1][1][1][1]; float[][][] val1 = get3();
376 c.v[0] = new float[1][1][1]; float[][][] val2 = get3();
377 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
378 }
379
380 {
381 c.v = new float[1][1][1][1]; float[][][][] val1 = get4();
382 c.v = new float[1][1][1][1]; float[][][][] val2 = get4();
383 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
384 }
385 }
386 }
387
388 /* ==================================================== */
389 // Dynamic Dim is higher than static
390 static class ObjectArrayLowerDim0 {
391 public @Stable Object v;
392
393 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
394 public static float get() { return ((float[])c.v)[0]; }
395 public static float[] get1() { return (float[])c.v; }
396
397 public static void test() throws Exception {
417 public @Stable Object[] v;
418
419 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
420 public static float get() { return ((float[][])c.v)[0][0]; }
421 public static float[] get1() { return (float[])(c.v[0]); }
422 public static Object[] get2() { return c.v; }
423
424 public static void test() throws Exception {
425 {
426 c.v = new float[1][1]; ((float[][])c.v)[0][0] = 1.0F; float val1 = get();
427 ((float[][])c.v)[0][0] = 2.0F; float val2 = get();
428
429 assertEquals(val1, 1.0F);
430 assertEquals(val2, 2.0F);
431 }
432
433 {
434 c.v = new float[1][1]; c.v[0] = new float[0]; float[] val1 = get1();
435 c.v[0] = new float[0]; float[] val2 = get1();
436
437 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
438 }
439
440 {
441 c.v = new float[0][0]; Object[] val1 = get2();
442 c.v = new float[0][0]; Object[] val2 = get2();
443
444 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
445 }
446 }
447 }
448
449 /* ==================================================== */
450
451 static class ObjectArrayLowerDim2 {
452 public @Stable Object[][] v;
453
454 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
455 public static float get() { return ((float[][][])c.v)[0][0][0]; }
456 public static float[] get1() { return (float[])(c.v[0][0]); }
457 public static float[][] get2() { return (float[][])(c.v[0]); }
458 public static Object[][] get3() { return c.v; }
459
460 public static void test() throws Exception {
461 {
462 c.v = new float[1][1][1]; ((float[][][])c.v)[0][0][0] = 1.0F; float val1 = get();
463 ((float[][][])c.v)[0][0][0] = 2.0F; float val2 = get();
464
465 assertEquals(val1, 1.0F);
466 assertEquals(val2, 2.0F);
467 }
468
469 {
470 c.v = new float[1][1][1]; c.v[0][0] = new float[0]; float[] val1 = get1();
471 c.v[0][0] = new float[0]; float[] val2 = get1();
472
473 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
474 }
475
476 {
477 c.v = new float[1][1][1]; c.v[0] = new float[0][0]; float[][] val1 = get2();
478 c.v[0] = new float[0][0]; float[][] val2 = get2();
479
480 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
481 }
482
483 {
484 c.v = new float[0][0][0]; Object[][] val1 = get3();
485 c.v = new float[0][0][0]; Object[][] val2 = get3();
486
487 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
488 }
489 }
490 }
491
492 /* ==================================================== */
493
494 static class NestedStableField {
495 static class A {
496 public @Stable float a;
497
498 }
499 public @Stable A v;
500
595 static class A {
596 public @Stable float a;
597 public @Stable A[] left;
598 public A[] right;
599 }
600
601 public @Stable A[] v;
602
603 public static final NestedStableField3 c = new NestedStableField3();
604 public static float get() { return c.v[0].left[1].left[0].left[1].a; }
605 public static float get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
606
607 public static void test() throws Exception {
608 {
609 A elem = new A();
610 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
611 elem.a = 1.0F; float val1 = get(); float val2 = get1();
612 elem.a = 2.0F; float val3 = get(); float val4 = get1();
613
614 assertEquals(val1, 1.0F);
615 assertEquals(val3, (isServerWithStable ? 1.0F : 2.0F));
616
617 assertEquals(val2, 1.0F);
618 assertEquals(val4, 2.0F);
619 }
620 }
621 }
622
623 /* ==================================================== */
624 // Auxiliary methods
625 static void assertEquals(float i, float j) { if (i != j) throw new AssertionError(i + " != " + j); }
626 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }
627
628 static boolean failed = false;
629
630 public static void run(Class<?> test) {
631 Throwable ex = null;
632 System.out.print(test.getName()+": ");
633 try {
634 test.getMethod("test").invoke(null);
635 } catch (InvocationTargetException e) {
|
71 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1
72 * -XX:+FoldStableValues
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
74 * java.lang.invoke.TestStableFloat
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.TestStableFloat
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 TestStableFloat {
90 static final boolean isStableEnabled = StableConfiguration.isStableEnabled;
91
92 public static void main(String[] args) throws Exception {
93 run(DefaultValue.class);
94 run(FloatStable.class);
95 run(DefaultStaticValue.class);
96 run(StaticFloatStable.class);
97 run(VolatileFloatStable.class);
98
99 // @Stable arrays: Dim 1-4
100 run(FloatArrayDim1.class);
101 run(FloatArrayDim2.class);
102 run(FloatArrayDim3.class);
103 run(FloatArrayDim4.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, 1.0F);
192 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
193 }
194 }
195
196 /* ==================================================== */
197 // @Stable array == field && all components are stable
198
199 static class FloatArrayDim1 {
200 public @Stable float[] v;
201
202 public static final FloatArrayDim1 c = new FloatArrayDim1();
203 public static float get() { return c.v[0]; }
204 public static float get1() { return c.v[10]; }
205 public static float[] get2() { return c.v; }
206 public static void test() throws Exception {
207 {
208 c.v = new float[1]; c.v[0] = 1.0F; float val1 = get();
209 c.v[0] = 2.0F; float val2 = get();
210 assertEquals(val1, 1.0F);
211 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
212
213 c.v = new float[1]; c.v[0] = 3.0F; float val3 = get();
214 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
215 : 3.0F));
216 }
217
218 {
219 c.v = new float[20]; c.v[10] = 1.0F; float val1 = get1();
220 c.v[10] = 2.0F; float val2 = get1();
221 assertEquals(val1, 1.0F);
222 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
223
224 c.v = new float[20]; c.v[10] = 3.0F; float val3 = get1();
225 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
226 : 3.0F));
227 }
228
229 {
230 c.v = new float[1]; float[] val1 = get2();
231 c.v = new float[1]; float[] val2 = get2();
232 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
233 }
234 }
235 }
236
237 /* ==================================================== */
238
239 static class FloatArrayDim2 {
240 public @Stable float[][] v;
241
242 public static final FloatArrayDim2 c = new FloatArrayDim2();
243 public static float get() { return c.v[0][0]; }
244 public static float[] get1() { return c.v[0]; }
245 public static float[][] get2() { return c.v; }
246 public static void test() throws Exception {
247 {
248 c.v = new float[1][1]; c.v[0][0] = 1.0F; float val1 = get();
249 c.v[0][0] = 2.0F; float val2 = get();
250 assertEquals(val1, 1.0F);
251 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
252
253 c.v = new float[1][1]; c.v[0][0] = 3.0F; float val3 = get();
254 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
255 : 3.0F));
256
257 c.v[0] = new float[1]; c.v[0][0] = 4.0F; float val4 = get();
258 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
259 : 4.0F));
260 }
261
262 {
263 c.v = new float[1][1]; float[] val1 = get1();
264 c.v[0] = new float[1]; float[] val2 = get1();
265 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
266 }
267
268 {
269 c.v = new float[1][1]; float[][] val1 = get2();
270 c.v = new float[1][1]; float[][] val2 = get2();
271 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
272 }
273 }
274 }
275
276 /* ==================================================== */
277
278 static class FloatArrayDim3 {
279 public @Stable float[][][] v;
280
281 public static final FloatArrayDim3 c = new FloatArrayDim3();
282 public static float get() { return c.v[0][0][0]; }
283 public static float[] get1() { return c.v[0][0]; }
284 public static float[][] get2() { return c.v[0]; }
285 public static float[][][] get3() { return c.v; }
286 public static void test() throws Exception {
287 {
288 c.v = new float[1][1][1]; c.v[0][0][0] = 1.0F; float val1 = get();
289 c.v[0][0][0] = 2.0F; float val2 = get();
290 assertEquals(val1, 1.0F);
291 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
292
293 c.v = new float[1][1][1]; c.v[0][0][0] = 3.0F; float val3 = get();
294 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
295 : 3.0F));
296
297 c.v[0] = new float[1][1]; c.v[0][0][0] = 4.0F; float val4 = get();
298 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
299 : 4.0F));
300
301 c.v[0][0] = new float[1]; c.v[0][0][0] = 5.0F; float val5 = get();
302 assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
303 : 5.0F));
304 }
305
306 {
307 c.v = new float[1][1][1]; float[] val1 = get1();
308 c.v[0][0] = new float[1]; float[] val2 = get1();
309 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
310 }
311
312 {
313 c.v = new float[1][1][1]; float[][] val1 = get2();
314 c.v[0] = new float[1][1]; float[][] val2 = get2();
315 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
316 }
317
318 {
319 c.v = new float[1][1][1]; float[][][] val1 = get3();
320 c.v = new float[1][1][1]; float[][][] val2 = get3();
321 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
322 }
323 }
324 }
325
326 /* ==================================================== */
327
328 static class FloatArrayDim4 {
329 public @Stable float[][][][] v;
330
331 public static final FloatArrayDim4 c = new FloatArrayDim4();
332 public static float get() { return c.v[0][0][0][0]; }
333 public static float[] get1() { return c.v[0][0][0]; }
334 public static float[][] get2() { return c.v[0][0]; }
335 public static float[][][] get3() { return c.v[0]; }
336 public static float[][][][] get4() { return c.v; }
337 public static void test() throws Exception {
338 {
339 c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 1.0F; float val1 = get();
340 c.v[0][0][0][0] = 2.0F; float val2 = get();
341 assertEquals(val1, 1.0F);
342 assertEquals(val2, (isStableEnabled ? 1.0F : 2.0F));
343
344 c.v = new float[1][1][1][1]; c.v[0][0][0][0] = 3.0F; float val3 = get();
345 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
346 : 3.0F));
347
348 c.v[0] = new float[1][1][1]; c.v[0][0][0][0] = 4.0F; float val4 = get();
349 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
350 : 4.0F));
351
352 c.v[0][0] = new float[1][1]; c.v[0][0][0][0] = 5.0F; float val5 = get();
353 assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
354 : 5.0F));
355
356 c.v[0][0][0] = new float[1]; c.v[0][0][0][0] = 6.0F; float val6 = get();
357 assertEquals(val6, (isStableEnabled ? (isStableEnabled ? 1.0F : 2.0F)
358 : 6.0F));
359 }
360
361 {
362 c.v = new float[1][1][1][1]; float[] val1 = get1();
363 c.v[0][0][0] = new float[1]; float[] val2 = get1();
364 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
365 }
366
367 {
368 c.v = new float[1][1][1][1]; float[][] val1 = get2();
369 c.v[0][0] = new float[1][1]; float[][] val2 = get2();
370 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
371 }
372
373 {
374 c.v = new float[1][1][1][1]; float[][][] val1 = get3();
375 c.v[0] = new float[1][1][1]; float[][][] val2 = get3();
376 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
377 }
378
379 {
380 c.v = new float[1][1][1][1]; float[][][][] val1 = get4();
381 c.v = new float[1][1][1][1]; float[][][][] val2 = get4();
382 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
383 }
384 }
385 }
386
387 /* ==================================================== */
388 // Dynamic Dim is higher than static
389 static class ObjectArrayLowerDim0 {
390 public @Stable Object v;
391
392 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
393 public static float get() { return ((float[])c.v)[0]; }
394 public static float[] get1() { return (float[])c.v; }
395
396 public static void test() throws Exception {
416 public @Stable Object[] v;
417
418 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
419 public static float get() { return ((float[][])c.v)[0][0]; }
420 public static float[] get1() { return (float[])(c.v[0]); }
421 public static Object[] get2() { return c.v; }
422
423 public static void test() throws Exception {
424 {
425 c.v = new float[1][1]; ((float[][])c.v)[0][0] = 1.0F; float val1 = get();
426 ((float[][])c.v)[0][0] = 2.0F; float val2 = get();
427
428 assertEquals(val1, 1.0F);
429 assertEquals(val2, 2.0F);
430 }
431
432 {
433 c.v = new float[1][1]; c.v[0] = new float[0]; float[] val1 = get1();
434 c.v[0] = new float[0]; float[] val2 = get1();
435
436 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
437 }
438
439 {
440 c.v = new float[0][0]; Object[] val1 = get2();
441 c.v = new float[0][0]; Object[] val2 = get2();
442
443 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
444 }
445 }
446 }
447
448 /* ==================================================== */
449
450 static class ObjectArrayLowerDim2 {
451 public @Stable Object[][] v;
452
453 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
454 public static float get() { return ((float[][][])c.v)[0][0][0]; }
455 public static float[] get1() { return (float[])(c.v[0][0]); }
456 public static float[][] get2() { return (float[][])(c.v[0]); }
457 public static Object[][] get3() { return c.v; }
458
459 public static void test() throws Exception {
460 {
461 c.v = new float[1][1][1]; ((float[][][])c.v)[0][0][0] = 1.0F; float val1 = get();
462 ((float[][][])c.v)[0][0][0] = 2.0F; float val2 = get();
463
464 assertEquals(val1, 1.0F);
465 assertEquals(val2, 2.0F);
466 }
467
468 {
469 c.v = new float[1][1][1]; c.v[0][0] = new float[0]; float[] val1 = get1();
470 c.v[0][0] = new float[0]; float[] val2 = get1();
471
472 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
473 }
474
475 {
476 c.v = new float[1][1][1]; c.v[0] = new float[0][0]; float[][] val1 = get2();
477 c.v[0] = new float[0][0]; float[][] val2 = get2();
478
479 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
480 }
481
482 {
483 c.v = new float[0][0][0]; Object[][] val1 = get3();
484 c.v = new float[0][0][0]; Object[][] val2 = get3();
485
486 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
487 }
488 }
489 }
490
491 /* ==================================================== */
492
493 static class NestedStableField {
494 static class A {
495 public @Stable float a;
496
497 }
498 public @Stable A v;
499
594 static class A {
595 public @Stable float a;
596 public @Stable A[] left;
597 public A[] right;
598 }
599
600 public @Stable A[] v;
601
602 public static final NestedStableField3 c = new NestedStableField3();
603 public static float get() { return c.v[0].left[1].left[0].left[1].a; }
604 public static float get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
605
606 public static void test() throws Exception {
607 {
608 A elem = new A();
609 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
610 elem.a = 1.0F; float val1 = get(); float val2 = get1();
611 elem.a = 2.0F; float val3 = get(); float val4 = get1();
612
613 assertEquals(val1, 1.0F);
614 assertEquals(val3, (isStableEnabled ? 1.0F : 2.0F));
615
616 assertEquals(val2, 1.0F);
617 assertEquals(val4, 2.0F);
618 }
619 }
620 }
621
622 /* ==================================================== */
623 // Auxiliary methods
624 static void assertEquals(float i, float j) { if (i != j) throw new AssertionError(i + " != " + j); }
625 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); }
626
627 static boolean failed = false;
628
629 public static void run(Class<?> test) {
630 Throwable ex = null;
631 System.out.print(test.getName()+": ");
632 try {
633 test.getMethod("test").invoke(null);
634 } catch (InvocationTargetException e) {
|