test/compiler/stable/TestStableDouble.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff test/compiler/stable

test/compiler/stable/TestStableDouble.java

Print this page




  71  *                   -XX:+TieredCompilation -XX:TieredStopAtLevel=1
  72  *                   -XX:+FoldStableValues
  73  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  74  *                   java.lang.invoke.TestStableDouble
  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.TestStableDouble
  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 TestStableDouble {
  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(DoubleStable.class);
  96         run(DefaultStaticValue.class);
  97         run(StaticDoubleStable.class);
  98         run(VolatileDoubleStable.class);
  99 
 100         // @Stable arrays: Dim 1-4
 101         run(DoubleArrayDim1.class);
 102         run(DoubleArrayDim2.class);
 103         run(DoubleArrayDim3.class);
 104         run(DoubleArrayDim4.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.0);
 193             assertEquals(val2, (isStableEnabled ? 1.0 : Double.MAX_VALUE));
 194         }
 195     }
 196 
 197     /* ==================================================== */
 198     // @Stable array == field && all components are stable
 199 
 200     static class DoubleArrayDim1 {
 201         public @Stable double[] v;
 202 
 203         public static final DoubleArrayDim1 c = new DoubleArrayDim1();
 204         public static double get() { return c.v[0]; }
 205         public static double get1() { return c.v[10]; }
 206         public static double[] get2() { return c.v; }
 207         public static void test() throws Exception {
 208             {
 209                 c.v = new double[1]; c.v[0] = 1.0; double val1 = get();
 210                                      c.v[0] = 2.0; double val2 = get();
 211                 assertEquals(val1, 1.0);
 212                 assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
 213 
 214                 c.v = new double[1]; c.v[0] = 3.0; double val3 = get();
 215                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 216                                                     : 3.0));
 217             }
 218 
 219             {
 220                 c.v = new double[20]; c.v[10] = 1.0; double val1 = get1();
 221                                       c.v[10] = 2.0; double val2 = get1();
 222                 assertEquals(val1, 1.0);
 223                 assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
 224 
 225                 c.v = new double[20]; c.v[10] = 3.0; double val3 = get1();
 226                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 227                                                     : 3.0));
 228             }
 229 
 230             {
 231                 c.v = new double[1]; double[] val1 = get2();
 232                 c.v = new double[1]; double[] val2 = get2();
 233                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 234             }
 235         }
 236     }
 237 
 238     /* ==================================================== */
 239 
 240     static class DoubleArrayDim2 {
 241         public @Stable double[][] v;
 242 
 243         public static final DoubleArrayDim2 c = new DoubleArrayDim2();
 244         public static double get() { return c.v[0][0]; }
 245         public static double[] get1() { return c.v[0]; }
 246         public static double[][] get2() { return c.v; }
 247         public static void test() throws Exception {
 248             {
 249                 c.v = new double[1][1]; c.v[0][0] = 1.0; double val1 = get();
 250                                         c.v[0][0] = 2.0; double val2 = get();
 251                 assertEquals(val1, 1.0);
 252                 assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
 253 
 254                 c.v = new double[1][1]; c.v[0][0] = 3.0; double val3 = get();
 255                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 256                                                     : 3.0));
 257 
 258                 c.v[0] = new double[1]; c.v[0][0] = 4.0; double val4 = get();
 259                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 260                                                     : 4.0));
 261             }
 262 
 263             {
 264                 c.v = new double[1][1]; double[] val1 = get1();
 265                 c.v[0] = new double[1]; double[] val2 = get1();
 266                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 267             }
 268 
 269             {
 270                 c.v = new double[1][1]; double[][] val1 = get2();
 271                 c.v = new double[1][1]; double[][] val2 = get2();
 272                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 273             }
 274         }
 275     }
 276 
 277     /* ==================================================== */
 278 
 279     static class DoubleArrayDim3 {
 280         public @Stable double[][][] v;
 281 
 282         public static final DoubleArrayDim3 c = new DoubleArrayDim3();
 283         public static double get() { return c.v[0][0][0]; }
 284         public static double[] get1() { return c.v[0][0]; }
 285         public static double[][] get2() { return c.v[0]; }
 286         public static double[][][] get3() { return c.v; }
 287         public static void test() throws Exception {
 288             {
 289                 c.v = new double[1][1][1]; c.v[0][0][0] = 1.0; double val1 = get();
 290                                            c.v[0][0][0] = 2.0; double val2 = get();
 291                 assertEquals(val1, 1.0);
 292                 assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
 293 
 294                 c.v = new double[1][1][1]; c.v[0][0][0] = 3.0; double val3 = get();
 295                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 296                                                     : 3.0));
 297 
 298                 c.v[0] = new double[1][1]; c.v[0][0][0] = 4.0; double val4 = get();
 299                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 300                                                     : 4.0));
 301 
 302                 c.v[0][0] = new double[1]; c.v[0][0][0] = 5.0; double val5 = get();
 303                 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 304                                                     : 5.0));
 305             }
 306 
 307             {
 308                 c.v = new double[1][1][1]; double[] val1 = get1();
 309                 c.v[0][0] = new double[1]; double[] val2 = get1();
 310                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 311             }
 312 
 313             {
 314                 c.v = new double[1][1][1]; double[][] val1 = get2();
 315                 c.v[0] = new double[1][1]; double[][] val2 = get2();
 316                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 317             }
 318 
 319             {
 320                 c.v = new double[1][1][1]; double[][][] val1 = get3();
 321                 c.v = new double[1][1][1]; double[][][] val2 = get3();
 322                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 323             }
 324         }
 325     }
 326 
 327     /* ==================================================== */
 328 
 329     static class DoubleArrayDim4 {
 330         public @Stable double[][][][] v;
 331 
 332         public static final DoubleArrayDim4 c = new DoubleArrayDim4();
 333         public static double get() { return c.v[0][0][0][0]; }
 334         public static double[] get1() { return c.v[0][0][0]; }
 335         public static double[][] get2() { return c.v[0][0]; }
 336         public static double[][][] get3() { return c.v[0]; }
 337         public static double[][][][] get4() { return c.v; }
 338         public static void test() throws Exception {
 339             {
 340                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 1.0; double val1 = get();
 341                                               c.v[0][0][0][0] = 2.0; double val2 = get();
 342                 assertEquals(val1, 1.0);
 343                 assertEquals(val2, (isServerWithStable ? 1.0 : 2.0));
 344 
 345                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 3.0; double val3 = get();
 346                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 347                                                     : 3.0));
 348 
 349                 c.v[0] = new double[1][1][1]; c.v[0][0][0][0] = 4.0; double val4 = get();
 350                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 351                                                     : 4.0));
 352 
 353                 c.v[0][0] = new double[1][1]; c.v[0][0][0][0] = 5.0; double val5 = get();
 354                 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 355                                                     : 5.0));
 356 
 357                 c.v[0][0][0] = new double[1]; c.v[0][0][0][0] = 6.0; double val6 = get();
 358                 assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1.0 : 2.0)
 359                                                     : 6.0));
 360             }
 361 
 362             {
 363                 c.v = new double[1][1][1][1]; double[] val1 = get1();
 364                 c.v[0][0][0] = new double[1]; double[] val2 = get1();
 365                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 366             }
 367 
 368             {
 369                 c.v = new double[1][1][1][1]; double[][] val1 = get2();
 370                 c.v[0][0] = new double[1][1]; double[][] val2 = get2();
 371                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 372             }
 373 
 374             {
 375                 c.v = new double[1][1][1][1]; double[][][] val1 = get3();
 376                 c.v[0] = new double[1][1][1]; double[][][] val2 = get3();
 377                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 378             }
 379 
 380             {
 381                 c.v = new double[1][1][1][1]; double[][][][] val1 = get4();
 382                 c.v = new double[1][1][1][1]; double[][][][] 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 double get() { return ((double[])c.v)[0]; }
 395         public static double[] get1() { return (double[])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 double get() { return ((double[][])c.v)[0][0]; }
 421         public static double[] get1() { return (double[])(c.v[0]); }
 422         public static Object[] get2() { return c.v; }
 423 
 424         public static void test() throws Exception {
 425             {
 426                 c.v = new double[1][1]; ((double[][])c.v)[0][0] = 1.0; double val1 = get();
 427                                         ((double[][])c.v)[0][0] = 2.0; double val2 = get();
 428 
 429                 assertEquals(val1, 1.0);
 430                 assertEquals(val2, 2.0);
 431             }
 432 
 433             {
 434                 c.v = new double[1][1]; c.v[0] = new double[0]; double[] val1 = get1();
 435                                         c.v[0] = new double[0]; double[] val2 = get1();
 436 
 437                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 438             }
 439 
 440             {
 441                 c.v = new double[0][0]; Object[] val1 = get2();
 442                 c.v = new double[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 double get() { return ((double[][][])c.v)[0][0][0]; }
 456         public static double[] get1() { return (double[])(c.v[0][0]); }
 457         public static double[][] get2() { return (double[][])(c.v[0]); }
 458         public static Object[][] get3() { return c.v; }
 459 
 460         public static void test() throws Exception {
 461             {
 462                 c.v = new double[1][1][1]; ((double[][][])c.v)[0][0][0] = 1.0; double val1 = get();
 463                                            ((double[][][])c.v)[0][0][0] = 2.0; double val2 = get();
 464 
 465                 assertEquals(val1, 1.0);
 466                 assertEquals(val2, 2.0);
 467             }
 468 
 469             {
 470                 c.v = new double[1][1][1]; c.v[0][0] = new double[0]; double[] val1 = get1();
 471                                            c.v[0][0] = new double[0]; double[] val2 = get1();
 472 
 473                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 474             }
 475 
 476             {
 477                 c.v = new double[1][1][1]; c.v[0] = new double[0][0]; double[][] val1 = get2();
 478                                            c.v[0] = new double[0][0]; double[][] val2 = get2();
 479 
 480                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
 481             }
 482 
 483             {
 484                 c.v = new double[0][0][0]; Object[][] val1 = get3();
 485                 c.v = new double[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 double a;
 497 
 498         }
 499         public @Stable A v;
 500 


 595         static class A {
 596             public @Stable double 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 double get() { return c.v[0].left[1].left[0].left[1].a; }
 605         public static double 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.0; double val1 = get(); double val2 = get1();
 612                                elem.a = 2.0; double val3 = get(); double val4 = get1();
 613 
 614                 assertEquals(val1, 1.0);
 615                 assertEquals(val3, (isServerWithStable ? 1.0 : 2.0));
 616 
 617                 assertEquals(val2, 1.0);
 618                 assertEquals(val4, 2.0);
 619             }
 620         }
 621     }
 622 
 623     /* ==================================================== */
 624     // Auxiliary methods
 625     static void assertEquals(double i, double 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.TestStableDouble
  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.TestStableDouble
  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 TestStableDouble {
  90     static final boolean isStableEnabled    = StableConfiguration.isStableEnabled;

  91 
  92     public static void main(String[] args) throws Exception {
  93         run(DefaultValue.class);
  94         run(DoubleStable.class);
  95         run(DefaultStaticValue.class);
  96         run(StaticDoubleStable.class);
  97         run(VolatileDoubleStable.class);
  98 
  99         // @Stable arrays: Dim 1-4
 100         run(DoubleArrayDim1.class);
 101         run(DoubleArrayDim2.class);
 102         run(DoubleArrayDim3.class);
 103         run(DoubleArrayDim4.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.0);
 192             assertEquals(val2, (isStableEnabled ? 1.0 : Double.MAX_VALUE));
 193         }
 194     }
 195 
 196     /* ==================================================== */
 197     // @Stable array == field && all components are stable
 198 
 199     static class DoubleArrayDim1 {
 200         public @Stable double[] v;
 201 
 202         public static final DoubleArrayDim1 c = new DoubleArrayDim1();
 203         public static double get() { return c.v[0]; }
 204         public static double get1() { return c.v[10]; }
 205         public static double[] get2() { return c.v; }
 206         public static void test() throws Exception {
 207             {
 208                 c.v = new double[1]; c.v[0] = 1.0; double val1 = get();
 209                                      c.v[0] = 2.0; double val2 = get();
 210                 assertEquals(val1, 1.0);
 211                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 212 
 213                 c.v = new double[1]; c.v[0] = 3.0; double val3 = get();
 214                 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 215                                                     : 3.0));
 216             }
 217 
 218             {
 219                 c.v = new double[20]; c.v[10] = 1.0; double val1 = get1();
 220                                       c.v[10] = 2.0; double val2 = get1();
 221                 assertEquals(val1, 1.0);
 222                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 223 
 224                 c.v = new double[20]; c.v[10] = 3.0; double val3 = get1();
 225                 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 226                                                     : 3.0));
 227             }
 228 
 229             {
 230                 c.v = new double[1]; double[] val1 = get2();
 231                 c.v = new double[1]; double[] val2 = get2();
 232                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 233             }
 234         }
 235     }
 236 
 237     /* ==================================================== */
 238 
 239     static class DoubleArrayDim2 {
 240         public @Stable double[][] v;
 241 
 242         public static final DoubleArrayDim2 c = new DoubleArrayDim2();
 243         public static double get() { return c.v[0][0]; }
 244         public static double[] get1() { return c.v[0]; }
 245         public static double[][] get2() { return c.v; }
 246         public static void test() throws Exception {
 247             {
 248                 c.v = new double[1][1]; c.v[0][0] = 1.0; double val1 = get();
 249                                         c.v[0][0] = 2.0; double val2 = get();
 250                 assertEquals(val1, 1.0);
 251                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 252 
 253                 c.v = new double[1][1]; c.v[0][0] = 3.0; double val3 = get();
 254                 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 255                                                     : 3.0));
 256 
 257                 c.v[0] = new double[1]; c.v[0][0] = 4.0; double val4 = get();
 258                 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 259                                                     : 4.0));
 260             }
 261 
 262             {
 263                 c.v = new double[1][1]; double[] val1 = get1();
 264                 c.v[0] = new double[1]; double[] val2 = get1();
 265                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 266             }
 267 
 268             {
 269                 c.v = new double[1][1]; double[][] val1 = get2();
 270                 c.v = new double[1][1]; double[][] val2 = get2();
 271                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 272             }
 273         }
 274     }
 275 
 276     /* ==================================================== */
 277 
 278     static class DoubleArrayDim3 {
 279         public @Stable double[][][] v;
 280 
 281         public static final DoubleArrayDim3 c = new DoubleArrayDim3();
 282         public static double get() { return c.v[0][0][0]; }
 283         public static double[] get1() { return c.v[0][0]; }
 284         public static double[][] get2() { return c.v[0]; }
 285         public static double[][][] get3() { return c.v; }
 286         public static void test() throws Exception {
 287             {
 288                 c.v = new double[1][1][1]; c.v[0][0][0] = 1.0; double val1 = get();
 289                                            c.v[0][0][0] = 2.0; double val2 = get();
 290                 assertEquals(val1, 1.0);
 291                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 292 
 293                 c.v = new double[1][1][1]; c.v[0][0][0] = 3.0; double val3 = get();
 294                 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 295                                                     : 3.0));
 296 
 297                 c.v[0] = new double[1][1]; c.v[0][0][0] = 4.0; double val4 = get();
 298                 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 299                                                     : 4.0));
 300 
 301                 c.v[0][0] = new double[1]; c.v[0][0][0] = 5.0; double val5 = get();
 302                 assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 303                                                     : 5.0));
 304             }
 305 
 306             {
 307                 c.v = new double[1][1][1]; double[] val1 = get1();
 308                 c.v[0][0] = new double[1]; double[] val2 = get1();
 309                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 310             }
 311 
 312             {
 313                 c.v = new double[1][1][1]; double[][] val1 = get2();
 314                 c.v[0] = new double[1][1]; double[][] val2 = get2();
 315                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 316             }
 317 
 318             {
 319                 c.v = new double[1][1][1]; double[][][] val1 = get3();
 320                 c.v = new double[1][1][1]; double[][][] val2 = get3();
 321                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 322             }
 323         }
 324     }
 325 
 326     /* ==================================================== */
 327 
 328     static class DoubleArrayDim4 {
 329         public @Stable double[][][][] v;
 330 
 331         public static final DoubleArrayDim4 c = new DoubleArrayDim4();
 332         public static double get() { return c.v[0][0][0][0]; }
 333         public static double[] get1() { return c.v[0][0][0]; }
 334         public static double[][] get2() { return c.v[0][0]; }
 335         public static double[][][] get3() { return c.v[0]; }
 336         public static double[][][][] get4() { return c.v; }
 337         public static void test() throws Exception {
 338             {
 339                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 1.0; double val1 = get();
 340                                               c.v[0][0][0][0] = 2.0; double val2 = get();
 341                 assertEquals(val1, 1.0);
 342                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 343 
 344                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 3.0; double val3 = get();
 345                 assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 346                                                     : 3.0));
 347 
 348                 c.v[0] = new double[1][1][1]; c.v[0][0][0][0] = 4.0; double val4 = get();
 349                 assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 350                                                     : 4.0));
 351 
 352                 c.v[0][0] = new double[1][1]; c.v[0][0][0][0] = 5.0; double val5 = get();
 353                 assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 354                                                     : 5.0));
 355 
 356                 c.v[0][0][0] = new double[1]; c.v[0][0][0][0] = 6.0; double val6 = get();
 357                 assertEquals(val6, (isStableEnabled ? (isStableEnabled ? 1.0 : 2.0)
 358                                                     : 6.0));
 359             }
 360 
 361             {
 362                 c.v = new double[1][1][1][1]; double[] val1 = get1();
 363                 c.v[0][0][0] = new double[1]; double[] val2 = get1();
 364                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 365             }
 366 
 367             {
 368                 c.v = new double[1][1][1][1]; double[][] val1 = get2();
 369                 c.v[0][0] = new double[1][1]; double[][] val2 = get2();
 370                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 371             }
 372 
 373             {
 374                 c.v = new double[1][1][1][1]; double[][][] val1 = get3();
 375                 c.v[0] = new double[1][1][1]; double[][][] val2 = get3();
 376                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 377             }
 378 
 379             {
 380                 c.v = new double[1][1][1][1]; double[][][][] val1 = get4();
 381                 c.v = new double[1][1][1][1]; double[][][][] 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 double get() { return ((double[])c.v)[0]; }
 394         public static double[] get1() { return (double[])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 double get() { return ((double[][])c.v)[0][0]; }
 420         public static double[] get1() { return (double[])(c.v[0]); }
 421         public static Object[] get2() { return c.v; }
 422 
 423         public static void test() throws Exception {
 424             {
 425                 c.v = new double[1][1]; ((double[][])c.v)[0][0] = 1.0; double val1 = get();
 426                                         ((double[][])c.v)[0][0] = 2.0; double val2 = get();
 427 
 428                 assertEquals(val1, 1.0);
 429                 assertEquals(val2, 2.0);
 430             }
 431 
 432             {
 433                 c.v = new double[1][1]; c.v[0] = new double[0]; double[] val1 = get1();
 434                                         c.v[0] = new double[0]; double[] val2 = get1();
 435 
 436                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 437             }
 438 
 439             {
 440                 c.v = new double[0][0]; Object[] val1 = get2();
 441                 c.v = new double[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 double get() { return ((double[][][])c.v)[0][0][0]; }
 455         public static double[] get1() { return (double[])(c.v[0][0]); }
 456         public static double[][] get2() { return (double[][])(c.v[0]); }
 457         public static Object[][] get3() { return c.v; }
 458 
 459         public static void test() throws Exception {
 460             {
 461                 c.v = new double[1][1][1]; ((double[][][])c.v)[0][0][0] = 1.0; double val1 = get();
 462                                            ((double[][][])c.v)[0][0][0] = 2.0; double val2 = get();
 463 
 464                 assertEquals(val1, 1.0);
 465                 assertEquals(val2, 2.0);
 466             }
 467 
 468             {
 469                 c.v = new double[1][1][1]; c.v[0][0] = new double[0]; double[] val1 = get1();
 470                                            c.v[0][0] = new double[0]; double[] val2 = get1();
 471 
 472                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 473             }
 474 
 475             {
 476                 c.v = new double[1][1][1]; c.v[0] = new double[0][0]; double[][] val1 = get2();
 477                                            c.v[0] = new double[0][0]; double[][] val2 = get2();
 478 
 479                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 480             }
 481 
 482             {
 483                 c.v = new double[0][0][0]; Object[][] val1 = get3();
 484                 c.v = new double[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 double a;
 496 
 497         }
 498         public @Stable A v;
 499 


 594         static class A {
 595             public @Stable double 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 double get() { return c.v[0].left[1].left[0].left[1].a; }
 604         public static double 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.0; double val1 = get(); double val2 = get1();
 611                                elem.a = 2.0; double val3 = get(); double val4 = get1();
 612 
 613                 assertEquals(val1, 1.0);
 614                 assertEquals(val3, (isStableEnabled ? 1.0 : 2.0));
 615 
 616                 assertEquals(val2, 1.0);
 617                 assertEquals(val4, 2.0);
 618             }
 619         }
 620     }
 621 
 622     /* ==================================================== */
 623     // Auxiliary methods
 624     static void assertEquals(double i, double 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) {
test/compiler/stable/TestStableDouble.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File