1 /*
   2  * Copyright (c) 2014, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.invoke;
  26 
  27 /*
  28  * @test TestStableDouble
  29  * @summary tests on stable fields and arrays
  30  * @library /testlibrary
  31  * @compile -XDignore.symbol.file TestStableDouble.java
  32  * @run main ClassFileInstaller
  33  *           java/lang/invoke/TestStableDouble
  34  *           java/lang/invoke/TestStableDouble$DoubleStable
  35  *           java/lang/invoke/TestStableDouble$StaticDoubleStable
  36  *           java/lang/invoke/TestStableDouble$VolatileDoubleStable
  37  *           java/lang/invoke/TestStableDouble$DoubleArrayDim1
  38  *           java/lang/invoke/TestStableDouble$DoubleArrayDim2
  39  *           java/lang/invoke/TestStableDouble$DoubleArrayDim3
  40  *           java/lang/invoke/TestStableDouble$DoubleArrayDim4
  41  *           java/lang/invoke/TestStableDouble$ObjectArrayLowerDim0
  42  *           java/lang/invoke/TestStableDouble$ObjectArrayLowerDim1
  43  *           java/lang/invoke/TestStableDouble$NestedStableField
  44  *           java/lang/invoke/TestStableDouble$NestedStableField$A
  45  *           java/lang/invoke/TestStableDouble$NestedStableField1
  46  *           java/lang/invoke/TestStableDouble$NestedStableField1$A
  47  *           java/lang/invoke/TestStableDouble$NestedStableField2
  48  *           java/lang/invoke/TestStableDouble$NestedStableField2$A
  49  *           java/lang/invoke/TestStableDouble$NestedStableField3
  50  *           java/lang/invoke/TestStableDouble$NestedStableField3$A
  51  *           java/lang/invoke/TestStableDouble$DefaultValue
  52  *           java/lang/invoke/TestStableDouble$ObjectArrayLowerDim2
  53  *
  54  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
  55  *                   -XX:+FoldStableValues -XX:+UseCompressedOop
  56  *                   -server -XX:-TieredCompilation -Xcomp
  57  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  58  *                   java.lang.invoke.TestStableDouble
  59  *
  60  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
  61  *                   -XX:+FoldStableValues -XX:-UseCompressedOop
  62  *                   -server -XX:-TieredCompilation -Xcomp
  63  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  64  *                   java.lang.invoke.TestStableDouble
  65  *
  66  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
  67  *                   -XX:-FoldStableValues -XX:+UseCompressedOop
  68  *                   -server -XX:-TieredCompilation -Xcomp
  69  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  70  *                   java.lang.invoke.TestStableDouble
  71  *
  72  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
  73  *                   -XX:-FoldStableValues -XX:-UseCompressedOop
  74  *                   -server -XX:-TieredCompilation -Xcomp
  75  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  76  *                   java.lang.invoke.TestStableDouble
  77  */
  78 import com.sun.management.HotSpotDiagnosticMXBean;
  79 import com.sun.management.VMOption;
  80 import sun.management.ManagementFactoryHelper;
  81 import java.lang.reflect.InvocationTargetException;
  82 
  83 public class TestStableDouble {
  84     public static void main(String[] args) throws Exception {
  85         System.out.println("@Stable enabled: "+isStableEnabled);
  86         System.out.println();
  87 
  88         run(DefaultValue.class);
  89         run(DoubleStable.class);
  90         run(StaticDoubleStable.class);
  91         run(VolatileDoubleStable.class);
  92 
  93         // @Stable arrays: Dim 1-4
  94         run(DoubleArrayDim1.class);
  95         run(DoubleArrayDim2.class);
  96         run(DoubleArrayDim3.class);
  97         run(DoubleArrayDim4.class);
  98 
  99         // @Stable Object field: dynamic arrays
 100         run(ObjectArrayLowerDim0.class);
 101         run(ObjectArrayLowerDim1.class);
 102         run(ObjectArrayLowerDim2.class);
 103 
 104         // Nested @Stable fields
 105         run(NestedStableField.class);
 106         run(NestedStableField1.class);
 107         run(NestedStableField2.class);
 108         run(NestedStableField3.class);
 109 
 110         if (failed) {
 111             throw new Error("TEST FAILED");
 112         }
 113     }
 114 
 115     /* ==================================================== */
 116 
 117     static class DefaultValue {
 118         public @Stable double v;
 119 
 120         public static final DefaultValue c = new DefaultValue();
 121         public static double get() { return c.v; }
 122         public static void test() throws Exception {
 123                        double val1 = get();
 124             c.v = 1.0; double val2 = get();
 125             assertEquals(val1, 0);
 126             assertEquals(val2, 1.0);
 127         }
 128     }
 129 
 130     /* ==================================================== */
 131 
 132     static class DoubleStable {
 133         public @Stable double v;
 134 
 135         public static final DoubleStable c = new DoubleStable();
 136         public static double get() { return c.v; }
 137         public static void test() throws Exception {
 138             c.v = 1.0; double val1 = get();
 139             c.v = Double.MAX_VALUE; double val2 = get();
 140             assertEquals(val1, 1.0);
 141             assertEquals(val2, (isStableEnabled ? 1.0 : Double.MAX_VALUE));
 142         }
 143     }
 144 
 145     /* ==================================================== */
 146 
 147     static class StaticDoubleStable {
 148         public static @Stable double v;
 149 
 150         public static final StaticDoubleStable c = new StaticDoubleStable();
 151         public static double get() { return c.v; }
 152         public static void test() throws Exception {
 153             c.v = 1.0; double val1 = get();
 154             c.v = Double.MAX_VALUE; double val2 = get();
 155             assertEquals(val1, 1.0);
 156             assertEquals(val2, (isStableEnabled ? 1.0 : Double.MAX_VALUE));
 157         }
 158     }
 159 
 160     /* ==================================================== */
 161 
 162     static class VolatileDoubleStable {
 163         public @Stable double v;
 164 
 165         public static final VolatileDoubleStable c = new VolatileDoubleStable();
 166         public static double get() { return c.v; }
 167         public static void test() throws Exception {
 168             c.v = 1.0; double val1 = get();
 169             c.v = Double.MAX_VALUE; double val2 = get();
 170             assertEquals(val1, 1.0);
 171             assertEquals(val2, (isStableEnabled ? 1.0 : Double.MAX_VALUE));
 172         }
 173     }
 174 
 175     /* ==================================================== */
 176     // @Stable array == field && all components are stable
 177 
 178     static class DoubleArrayDim1 {
 179         public @Stable double[] v;
 180 
 181         public static final DoubleArrayDim1 c = new DoubleArrayDim1();
 182         public static double get() { return c.v[0]; }
 183         public static double get1() { return c.v[10]; }
 184         public static double[] get2() { return c.v; }
 185         public static void test() throws Exception {
 186             {
 187                 c.v = new double[1]; c.v[0] = 1.0; double val1 = get();
 188                                      c.v[0] = 2.0; double val2 = get();
 189                 assertEquals(val1, 1.0);
 190                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 191 
 192                 c.v = new double[1]; c.v[0] = 3.0; double val3 = get();
 193                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 194             }
 195 
 196             {
 197                 c.v = new double[20]; c.v[10] = 1.0; double val1 = get1();
 198                                       c.v[10] = 2.0; double val2 = get1();
 199                 assertEquals(val1, 1.0);
 200                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 201 
 202                 c.v = new double[20]; c.v[10] = 3.0; double val3 = get1();
 203                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 204             }
 205 
 206             {
 207                 c.v = new double[1]; double[] val1 = get2();
 208                 c.v = new double[1]; double[] val2 = get2();
 209                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 210             }
 211         }
 212     }
 213 
 214     /* ==================================================== */
 215 
 216     static class DoubleArrayDim2 {
 217         public @Stable double[][] v;
 218 
 219         public static final DoubleArrayDim2 c = new DoubleArrayDim2();
 220         public static double get() { return c.v[0][0]; }
 221         public static double[] get1() { return c.v[0]; }
 222         public static double[][] get2() { return c.v; }
 223         public static void test() throws Exception {
 224             {
 225                 c.v = new double[1][1]; c.v[0][0] = 1.0; double val1 = get();
 226                                         c.v[0][0] = 2.0; double val2 = get();
 227                 assertEquals(val1, 1.0);
 228                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 229 
 230                 c.v = new double[1][1]; c.v[0][0] = 3.0; double val3 = get();
 231                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 232 
 233                 c.v[0] = new double[1]; c.v[0][0] = 4.0; double val4 = get();
 234                 assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
 235             }
 236 
 237             {
 238                 c.v = new double[1][1]; double[] val1 = get1();
 239                 c.v[0] = new double[1]; double[] val2 = get1();
 240                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 241             }
 242 
 243             {
 244                 c.v = new double[1][1]; double[][] val1 = get2();
 245                 c.v = new double[1][1]; double[][] val2 = get2();
 246                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 247             }
 248         }
 249     }
 250 
 251     /* ==================================================== */
 252 
 253     static class DoubleArrayDim3 {
 254         public @Stable double[][][] v;
 255 
 256         public static final DoubleArrayDim3 c = new DoubleArrayDim3();
 257         public static double get() { return c.v[0][0][0]; }
 258         public static double[] get1() { return c.v[0][0]; }
 259         public static double[][] get2() { return c.v[0]; }
 260         public static double[][][] get3() { return c.v; }
 261         public static void test() throws Exception {
 262             {
 263                 c.v = new double[1][1][1]; c.v[0][0][0] = 1.0; double val1 = get();
 264                                            c.v[0][0][0] = 2.0; double val2 = get();
 265                 assertEquals(val1, 1.0);
 266                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 267 
 268                 c.v = new double[1][1][1]; c.v[0][0][0] = 3.0; double val3 = get();
 269                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 270 
 271                 c.v[0] = new double[1][1]; c.v[0][0][0] = 4.0; double val4 = get();
 272                 assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
 273 
 274                 c.v[0][0] = new double[1]; c.v[0][0][0] = 5.0; double val5 = get();
 275                 assertEquals(val5, (isStableEnabled ? 1.0 : 5.0));
 276             }
 277 
 278             {
 279                 c.v = new double[1][1][1]; double[] val1 = get1();
 280                 c.v[0][0] = new double[1]; double[] val2 = get1();
 281                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 282             }
 283 
 284             {
 285                 c.v = new double[1][1][1]; double[][] val1 = get2();
 286                 c.v[0] = new double[1][1]; double[][] val2 = get2();
 287                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 288             }
 289 
 290             {
 291                 c.v = new double[1][1][1]; double[][][] val1 = get3();
 292                 c.v = new double[1][1][1]; double[][][] val2 = get3();
 293                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 294             }
 295         }
 296     }
 297 
 298     /* ==================================================== */
 299 
 300     static class DoubleArrayDim4 {
 301         public @Stable double[][][][] v;
 302 
 303         public static final DoubleArrayDim4 c = new DoubleArrayDim4();
 304         public static double get() { return c.v[0][0][0][0]; }
 305         public static double[] get1() { return c.v[0][0][0]; }
 306         public static double[][] get2() { return c.v[0][0]; }
 307         public static double[][][] get3() { return c.v[0]; }
 308         public static double[][][][] get4() { return c.v; }
 309         public static void test() throws Exception {
 310             {
 311                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 1.0; double val1 = get();
 312                                               c.v[0][0][0][0] = 2.0; double val2 = get();
 313                 assertEquals(val1, 1.0);
 314                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 315 
 316                 c.v = new double[1][1][1][1]; c.v[0][0][0][0] = 3.0; double val3 = get();
 317                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 318 
 319                 c.v[0] = new double[1][1][1]; c.v[0][0][0][0] = 4.0; double val4 = get();
 320                 assertEquals(val4, (isStableEnabled ? 1.0 : 4.0));
 321 
 322                 c.v[0][0] = new double[1][1]; c.v[0][0][0][0] = 5.0; double val5 = get();
 323                 assertEquals(val5, (isStableEnabled ? 1.0 : 5.0));
 324 
 325                 c.v[0][0][0] = new double[1]; c.v[0][0][0][0] = 6.0; double val6 = get();
 326                 assertEquals(val6, (isStableEnabled ? 1.0 : 6.0));
 327             }
 328 
 329             {
 330                 c.v = new double[1][1][1][1]; double[] val1 = get1();
 331                 c.v[0][0][0] = new double[1]; double[] val2 = get1();
 332                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 333             }
 334 
 335             {
 336                 c.v = new double[1][1][1][1]; double[][] val1 = get2();
 337                 c.v[0][0] = new double[1][1]; double[][] val2 = get2();
 338                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 339             }
 340 
 341             {
 342                 c.v = new double[1][1][1][1]; double[][][] val1 = get3();
 343                 c.v[0] = new double[1][1][1]; double[][][] val2 = get3();
 344                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 345             }
 346 
 347             {
 348                 c.v = new double[1][1][1][1]; double[][][][] val1 = get4();
 349                 c.v = new double[1][1][1][1]; double[][][][] val2 = get4();
 350                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 351             }
 352 
 353         }
 354     }
 355 
 356     /* ==================================================== */
 357     // Dynamic Dim is higher than static
 358 
 359     static class ObjectArrayLowerDim0 {
 360         public @Stable Object v;
 361 
 362         public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
 363         public static double get() { return ((double[])c.v)[0]; }
 364         public static double[] get1() { return (double[])c.v; }
 365 
 366         public static void test() throws Exception {
 367             {
 368                 c.v = new double[1]; ((double[])c.v)[0] = 1.0; double val1 = get();
 369                                      ((double[])c.v)[0] = 2.0; double val2 = get();
 370 
 371                 assertEquals(val1, 1.0);
 372                 assertEquals(val2, 2.0);
 373             }
 374 
 375             {
 376                 c.v = new double[1]; double[] val1 = get1();
 377                 c.v = new double[1]; double[] val2 = get1();
 378                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 379             }
 380         }
 381     }
 382 
 383     /* ==================================================== */
 384 
 385     static class ObjectArrayLowerDim1 {
 386         public @Stable Object[] v;
 387 
 388         public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
 389         public static double get() { return ((double[][])c.v)[0][0]; }
 390         public static double[] get1() { return (double[])(c.v[0]); }
 391         public static Object[] get2() { return c.v; }
 392 
 393         public static void test() throws Exception {
 394             {
 395                 c.v = new double[1][1]; ((double[][])c.v)[0][0] = 1.0; double val1 = get();
 396                                         ((double[][])c.v)[0][0] = 2.0; double val2 = get();
 397 
 398                 assertEquals(val1, 1.0);
 399                 assertEquals(val2, 2.0);
 400             }
 401 
 402             {
 403                 c.v = new double[1][1]; c.v[0] = new double[0]; double[] val1 = get1();
 404                                         c.v[0] = new double[0]; double[] val2 = get1();
 405 
 406                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 407             }
 408 
 409             {
 410                 c.v = new double[0][0]; Object[] val1 = get2();
 411                 c.v = new double[0][0]; Object[] val2 = get2();
 412 
 413                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 414             }
 415         }
 416     }
 417 
 418     /* ==================================================== */
 419 
 420     static class ObjectArrayLowerDim2 {
 421         public @Stable Object[][] v;
 422 
 423         public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
 424         public static double get() { return ((double[][][])c.v)[0][0][0]; }
 425         public static double[] get1() { return (double[])(c.v[0][0]); }
 426         public static double[][] get2() { return (double[][])(c.v[0]); }
 427         public static Object[][] get3() { return c.v; }
 428 
 429         public static void test() throws Exception {
 430             {
 431                 c.v = new double[1][1][1]; ((double[][][])c.v)[0][0][0] = 1.0; double val1 = get();
 432                                            ((double[][][])c.v)[0][0][0] = 2.0; double val2 = get();
 433 
 434                 assertEquals(val1, 1.0);
 435                 assertEquals(val2, 2.0);
 436             }
 437 
 438             {
 439                 c.v = new double[1][1][1]; c.v[0][0] = new double[0]; double[] val1 = get1();
 440                                            c.v[0][0] = new double[0]; double[] val2 = get1();
 441 
 442                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 443             }
 444 
 445             {
 446                 c.v = new double[1][1][1]; c.v[0] = new double[0][0]; double[][] val1 = get2();
 447                                            c.v[0] = new double[0][0]; double[][] val2 = get2();
 448 
 449                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 450             }
 451 
 452             {
 453                 c.v = new double[0][0][0]; Object[][] val1 = get3();
 454                 c.v = new double[0][0][0]; Object[][] val2 = get3();
 455 
 456                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
 457             }
 458         }
 459     }
 460 
 461     /* ==================================================== */
 462 
 463     static class NestedStableField {
 464         static class A {
 465             public @Stable double a;
 466 
 467         }
 468         public @Stable A v;
 469 
 470         public static final NestedStableField c = new NestedStableField();
 471         public static A get() { return c.v; }
 472         public static double get1() { return get().a; }
 473 
 474         public static void test() throws Exception {
 475             {
 476                 c.v = new A(); c.v.a = 1.0; A val1 = get();
 477                                c.v.a = 2.0; A val2 = get();
 478 
 479                 assertEquals(val1.a, 2.0);
 480                 assertEquals(val2.a, 2.0);
 481             }
 482 
 483             {
 484                 c.v = new A(); c.v.a = 1.0; double val1 = get1();
 485                                c.v.a = 2.0; double val2 = get1();
 486                 c.v = new A(); c.v.a = 3.0; double val3 = get1();
 487 
 488                 assertEquals(val1, 1.0);
 489                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 490                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 491             }
 492         }
 493     }
 494 
 495     /* ==================================================== */
 496 
 497     static class NestedStableField1 {
 498         static class A {
 499             public @Stable double a;
 500             public @Stable A next;
 501         }
 502         public @Stable A v;
 503 
 504         public static final NestedStableField1 c = new NestedStableField1();
 505         public static A get() { return c.v.next.next.next.next.next.next.next; }
 506         public static double get1() { return get().a; }
 507 
 508         public static void test() throws Exception {
 509             {
 510                 c.v = new A(); c.v.next = new A();   c.v.next.next  = c.v;
 511                                c.v.a = 1.0; c.v.next.a = 1.0; A val1 = get();
 512                                c.v.a = 2.0; c.v.next.a = 2.0; A val2 = get();
 513 
 514                 assertEquals(val1.a, 2.0);
 515                 assertEquals(val2.a, 2.0);
 516             }
 517 
 518             {
 519                 c.v = new A(); c.v.next = c.v;
 520                                c.v.a = 1.0; double val1 = get1();
 521                                c.v.a = 2.0; double val2 = get1();
 522                 c.v = new A(); c.v.next = c.v;
 523                                c.v.a = 3.0; double val3 = get1();
 524 
 525                 assertEquals(val1, 1.0);
 526                 assertEquals(val2, (isStableEnabled ? 1.0 : 2.0));
 527                 assertEquals(val3, (isStableEnabled ? 1.0 : 3.0));
 528             }
 529         }
 530     }
 531    /* ==================================================== */
 532 
 533     static class NestedStableField2 {
 534         static class A {
 535             public @Stable double a;
 536             public @Stable A left;
 537             public         A right;
 538         }
 539 
 540         public @Stable A v;
 541 
 542         public static final NestedStableField2 c = new NestedStableField2();
 543         public static double get() { return c.v.left.left.left.a; }
 544         public static double get1() { return c.v.left.left.right.left.a; }
 545 
 546         public static void test() throws Exception {
 547             {
 548                 c.v = new A(); c.v.left = c.v.right = c.v;
 549                                c.v.a = 1.0; double val1 = get(); double val2 = get1();
 550                                c.v.a = 2.0; double val3 = get(); double val4 = get1();
 551 
 552                 assertEquals(val1, 1.0);
 553                 assertEquals(val3, (isStableEnabled ? 1.0 : 2.0));
 554 
 555                 assertEquals(val2, 1.0);
 556                 assertEquals(val4, 2.0);
 557             }
 558         }
 559     }
 560 
 561     /* ==================================================== */
 562 
 563     static class NestedStableField3 {
 564         static class A {
 565             public @Stable double a;
 566             public @Stable A[] left;
 567             public         A[] right;
 568         }
 569 
 570         public @Stable A[] v;
 571 
 572         public static final NestedStableField3 c = new NestedStableField3();
 573         public static double get() { return c.v[0].left[1].left[0].left[1].a; }
 574         public static double get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
 575 
 576         public static void test() throws Exception {
 577             {
 578                 A elem = new A();
 579                 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
 580                                elem.a = 1.0; double val1 = get(); double val2 = get1();
 581                                elem.a = 2.0; double val3 = get(); double val4 = get1();
 582 
 583                 assertEquals(val1, 1.0);
 584                 assertEquals(val3, (isStableEnabled ? 1.0 : 2.0));
 585 
 586                 assertEquals(val2, 1.0);
 587                 assertEquals(val4, 2.0);
 588             }
 589         }
 590     }
 591 
 592     /* ==================================================== */
 593     // Auxiliary methods
 594     static void assertEquals(double i, double j) { if (i != j)  throw new AssertionError(i + " != " + j); }
 595     static void assertTrue(boolean b) { if (!b)  throw new AssertionError(); }
 596 
 597     static boolean failed = false;
 598 
 599     public static void run(Class<?> test) {
 600         Throwable ex = null;
 601         System.out.print(test.getName()+": ");
 602         try {
 603             test.getMethod("test").invoke(null);
 604         } catch (InvocationTargetException e) {
 605             ex = e.getCause();
 606         } catch (Throwable e) {
 607             ex = e;
 608         } finally {
 609             if (ex == null) {
 610                 System.out.println("PASSED");
 611             } else {
 612                 failed = true;
 613                 System.out.println("FAILED");
 614                 ex.printStackTrace(System.out);
 615             }
 616         }
 617     }
 618 
 619     static final boolean isStableEnabled;
 620     static {
 621         HotSpotDiagnosticMXBean diagnostic
 622                 = ManagementFactoryHelper.getDiagnosticMXBean();
 623         VMOption tmp;
 624         try {
 625             tmp = diagnostic.getVMOption("FoldStableValues");
 626         } catch (IllegalArgumentException e) {
 627             tmp = null;
 628         }
 629         isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
 630     }
 631 }