test/compiler/stable/TestStableByte.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 7994
04ff2f6cd0eb
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

     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  */
    26 /*
    27  * @test TestStableByte
    28  * @summary tests on stable fields and arrays
    29  * @library /testlibrary /testlibrary/whitebox
    30  * @build TestStableByte StableConfiguration sun.hotspot.WhiteBox
    31  * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
    32  * @run main ClassFileInstaller
    33  *           java/lang/invoke/StableConfiguration
    34  *           java/lang/invoke/TestStableByte
    35  *           java/lang/invoke/TestStableByte$ByteStable
    36  *           java/lang/invoke/TestStableByte$StaticByteStable
    37  *           java/lang/invoke/TestStableByte$VolatileByteStable
    38  *           java/lang/invoke/TestStableByte$ByteArrayDim1
    39  *           java/lang/invoke/TestStableByte$ByteArrayDim2
    40  *           java/lang/invoke/TestStableByte$ByteArrayDim3
    41  *           java/lang/invoke/TestStableByte$ByteArrayDim4
    42  *           java/lang/invoke/TestStableByte$ObjectArrayLowerDim0
    43  *           java/lang/invoke/TestStableByte$ObjectArrayLowerDim1
    44  *           java/lang/invoke/TestStableByte$NestedStableField
    45  *           java/lang/invoke/TestStableByte$NestedStableField$A
    46  *           java/lang/invoke/TestStableByte$NestedStableField1
    47  *           java/lang/invoke/TestStableByte$NestedStableField1$A
    48  *           java/lang/invoke/TestStableByte$NestedStableField2
    49  *           java/lang/invoke/TestStableByte$NestedStableField2$A
    50  *           java/lang/invoke/TestStableByte$NestedStableField3
    51  *           java/lang/invoke/TestStableByte$NestedStableField3$A
    52  *           java/lang/invoke/TestStableByte$DefaultValue
    53  *           java/lang/invoke/TestStableByte$DefaultStaticValue
    54  *           java/lang/invoke/TestStableByte$ObjectArrayLowerDim2
    55  *
    56  * @run main/othervm -Xbootclasspath/a:.
    57  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    58  *                   -XX:-TieredCompilation
    59  *                   -XX:+FoldStableValues
    60  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    61  *                   java.lang.invoke.TestStableByte
    62  * @run main/othervm -Xbootclasspath/a:.
    63  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    64  *                   -XX:-TieredCompilation
    65  *                   -XX:-FoldStableValues
    66  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    67  *                   java.lang.invoke.TestStableByte
    68  *
    69  * @run main/othervm -Xbootclasspath/a:.
    70  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    71  *                   -XX:+TieredCompilation -XX:TieredStopAtLevel=1
    72  *                   -XX:+FoldStableValues
    73  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    74  *                   java.lang.invoke.TestStableByte
    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.TestStableByte
    81  *
    82  */
    83 package java.lang.invoke;
    85 import java.lang.reflect.InvocationTargetException;
    87 public class TestStableByte {
    88     static final boolean isStableEnabled    = StableConfiguration.isStableEnabled;
    89     static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
    91     public static void main(String[] args) throws Exception {
    92         run(DefaultValue.class);
    93         run(ByteStable.class);
    94         run(DefaultStaticValue.class);
    95         run(StaticByteStable.class);
    96         run(VolatileByteStable.class);
    98         // @Stable arrays: Dim 1-4
    99         run(ByteArrayDim1.class);
   100         run(ByteArrayDim2.class);
   101         run(ByteArrayDim3.class);
   102         run(ByteArrayDim4.class);
   104         // @Stable Object field: dynamic arrays
   105         run(ObjectArrayLowerDim0.class);
   106         run(ObjectArrayLowerDim1.class);
   107         run(ObjectArrayLowerDim2.class);
   109         // Nested @Stable fields
   110         run(NestedStableField.class);
   111         run(NestedStableField1.class);
   112         run(NestedStableField2.class);
   113         run(NestedStableField3.class);
   115         if (failed) {
   116             throw new Error("TEST FAILED");
   117         }
   118     }
   120     /* ==================================================== */
   122     static class DefaultValue {
   123         public @Stable byte v;
   125         public static final DefaultValue c = new DefaultValue();
   126         public static byte get() { return c.v; }
   127         public static void test() throws Exception {
   128                      byte val1 = get();
   129             c.v = 1; byte val2 = get();
   130             assertEquals(val1, 0);
   131             assertEquals(val2, 1);
   132         }
   133     }
   135     /* ==================================================== */
   137     static class ByteStable {
   138         public @Stable byte v;
   140         public static final ByteStable c = new ByteStable();
   141         public static byte get() { return c.v; }
   142         public static void test() throws Exception {
   143             c.v = 5;   byte val1 = get();
   144             c.v = 127; byte val2 = get();
   145             assertEquals(val1, 5);
   146             assertEquals(val2, (isStableEnabled ? 5 : 127));
   147         }
   148     }
   150     /* ==================================================== */
   152     static class DefaultStaticValue {
   153         public static @Stable byte v;
   155         public static final DefaultStaticValue c = new DefaultStaticValue();
   156         public static byte get() { return c.v; }
   157         public static void test() throws Exception {
   158                      byte val1 = get();
   159             c.v = 1; byte val2 = get();
   160             assertEquals(val1, 0);
   161             assertEquals(val2, 1);
   162         }
   163     }
   165     /* ==================================================== */
   167     static class StaticByteStable {
   168         public static @Stable byte v;
   170         public static final StaticByteStable c = new StaticByteStable();
   171         public static byte get() { return c.v; }
   172         public static void test() throws Exception {
   173             c.v = 5;   byte val1 = get();
   174             c.v = 127; byte val2 = get();
   175             assertEquals(val1, 5);
   176             assertEquals(val2, (isStableEnabled ? 5 : 127));
   177         }
   178     }
   180     /* ==================================================== */
   182     static class VolatileByteStable {
   183         public @Stable volatile byte v;
   185         public static final VolatileByteStable c = new VolatileByteStable();
   186         public static byte get() { return c.v; }
   187         public static void test() throws Exception {
   188             c.v = 5;   byte val1 = get();
   189             c.v = 127; byte val2 = get();
   190             assertEquals(val1, 5);
   191             assertEquals(val2, (isStableEnabled ? 5 : 127));
   192         }
   193     }
   195     /* ==================================================== */
   196     // @Stable array == field && all components are stable
   198     static class ByteArrayDim1 {
   199         public @Stable byte[] v;
   201         public static final ByteArrayDim1 c = new ByteArrayDim1();
   202         public static byte get() { return c.v[0]; }
   203         public static byte get1() { return c.v[10]; }
   204         public static byte[] get2() { return c.v; }
   205         public static void test() throws Exception {
   206             {
   207                 c.v = new byte[1]; c.v[0] = 1; byte val1 = get();
   208                                    c.v[0] = 2; byte val2 = get();
   209                 assertEquals(val1, 1);
   210                 assertEquals(val2, (isServerWithStable ? 1 : 2));
   212                 c.v = new byte[1]; c.v[0] = 3; byte val3 = get();
   213                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   214                                                     : 3));
   215             }
   217             {
   218                 c.v = new byte[20]; c.v[10] = 1; byte val1 = get1();
   219                                     c.v[10] = 2; byte val2 = get1();
   220                 assertEquals(val1, 1);
   221                 assertEquals(val2, (isServerWithStable ? 1 : 2));
   223                 c.v = new byte[20]; c.v[10] = 3; byte val3 = get1();
   224                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   225                                                     : 3));
   226             }
   228             {
   229                 c.v = new byte[1]; byte[] val1 = get2();
   230                 c.v = new byte[1]; byte[] val2 = get2();
   231                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   232             }
   233         }
   234     }
   236     /* ==================================================== */
   238     static class ByteArrayDim2 {
   239         public @Stable byte[][] v;
   241         public static final ByteArrayDim2 c = new ByteArrayDim2();
   242         public static byte get() { return c.v[0][0]; }
   243         public static byte[] get1() { return c.v[0]; }
   244         public static byte[][] get2() { return c.v; }
   245         public static void test() throws Exception {
   246             {
   247                 c.v = new byte[1][1]; c.v[0][0] = 1; byte val1 = get();
   248                                       c.v[0][0] = 2; byte val2 = get();
   249                 assertEquals(val1, 1);
   250                 assertEquals(val2, (isServerWithStable ? 1 : 2));
   252                 c.v = new byte[1][1]; c.v[0][0] = 3; byte val3 = get();
   253                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   254                                                     : 3));
   256                 c.v[0] = new byte[1]; c.v[0][0] = 4; byte val4 = get();
   257                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   258                                                     : 4));
   259             }
   261             {
   262                 c.v = new byte[1][1]; byte[] val1 = get1();
   263                 c.v[0] = new byte[1]; byte[] val2 = get1();
   264                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   265             }
   267             {
   268                 c.v = new byte[1][1]; byte[][] val1 = get2();
   269                 c.v = new byte[1][1]; byte[][] val2 = get2();
   270                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   271             }
   272         }
   273     }
   275     /* ==================================================== */
   277     static class ByteArrayDim3 {
   278         public @Stable byte[][][] v;
   280         public static final ByteArrayDim3 c = new ByteArrayDim3();
   281         public static byte get() { return c.v[0][0][0]; }
   282         public static byte[] get1() { return c.v[0][0]; }
   283         public static byte[][] get2() { return c.v[0]; }
   284         public static byte[][][] get3() { return c.v; }
   285         public static void test() throws Exception {
   286             {
   287                 c.v = new byte[1][1][1]; c.v[0][0][0] = 1; byte val1 = get();
   288                                          c.v[0][0][0] = 2; byte val2 = get();
   289                 assertEquals(val1, 1);
   290                 assertEquals(val2, (isServerWithStable ? 1 : 2));
   292                 c.v = new byte[1][1][1]; c.v[0][0][0] = 3; byte val3 = get();
   293                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   294                                                     : 3));
   296                 c.v[0] = new byte[1][1]; c.v[0][0][0] = 4; byte val4 = get();
   297                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   298                                                     : 4));
   300                 c.v[0][0] = new byte[1]; c.v[0][0][0] = 5; byte val5 = get();
   301                 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   302                                                     : 5));
   303             }
   305             {
   306                 c.v = new byte[1][1][1]; byte[] val1 = get1();
   307                 c.v[0][0] = new byte[1]; byte[] val2 = get1();
   308                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   309             }
   311             {
   312                 c.v = new byte[1][1][1]; byte[][] val1 = get2();
   313                 c.v[0] = new byte[1][1]; byte[][] val2 = get2();
   314                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   315             }
   317             {
   318                 c.v = new byte[1][1][1]; byte[][][] val1 = get3();
   319                 c.v = new byte[1][1][1]; byte[][][] val2 = get3();
   320                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   321             }
   322         }
   323     }
   325     /* ==================================================== */
   327     static class ByteArrayDim4 {
   328         public @Stable byte[][][][] v;
   330         public static final ByteArrayDim4 c = new ByteArrayDim4();
   331         public static byte get() { return c.v[0][0][0][0]; }
   332         public static byte[] get1() { return c.v[0][0][0]; }
   333         public static byte[][] get2() { return c.v[0][0]; }
   334         public static byte[][][] get3() { return c.v[0]; }
   335         public static byte[][][][] get4() { return c.v; }
   336         public static void test() throws Exception {
   337             {
   338                 c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 1; byte val1 = get();
   339                                             c.v[0][0][0][0] = 2; byte val2 = get();
   340                 assertEquals(val1, 1);
   341                 assertEquals(val2, (isServerWithStable ? 1 : 2));
   343                 c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 3; byte val3 = get();
   344                 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   345                                                     : 3));
   347                 c.v[0] = new byte[1][1][1]; c.v[0][0][0][0] = 4; byte val4 = get();
   348                 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   349                                                     : 4));
   351                 c.v[0][0] = new byte[1][1]; c.v[0][0][0][0] = 5; byte val5 = get();
   352                 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   353                                                     : 5));
   355                 c.v[0][0][0] = new byte[1]; c.v[0][0][0][0] = 6; byte val6 = get();
   356                 assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   357                                                     : 6));
   358             }
   360             {
   361                 c.v = new byte[1][1][1][1]; byte[] val1 = get1();
   362                 c.v[0][0][0] = new byte[1]; byte[] val2 = get1();
   363                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   364             }
   366             {
   367                 c.v = new byte[1][1][1][1]; byte[][] val1 = get2();
   368                 c.v[0][0] = new byte[1][1]; byte[][] val2 = get2();
   369                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   370             }
   372             {
   373                 c.v = new byte[1][1][1][1]; byte[][][] val1 = get3();
   374                 c.v[0] = new byte[1][1][1]; byte[][][] val2 = get3();
   375                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   376             }
   378             {
   379                 c.v = new byte[1][1][1][1]; byte[][][][] val1 = get4();
   380                 c.v = new byte[1][1][1][1]; byte[][][][] val2 = get4();
   381                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   382             }
   384         }
   385     }
   387     /* ==================================================== */
   388     // Dynamic Dim is higher than static
   390     static class ObjectArrayLowerDim0 {
   391         public @Stable Object v;
   393         public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
   394         public static byte get() { return ((byte[])c.v)[0]; }
   395         public static byte[] get1() { return (byte[])c.v; }
   397         public static void test() throws Exception {
   398             {
   399                 c.v = new byte[1]; ((byte[])c.v)[0] = 1; byte val1 = get();
   400                                    ((byte[])c.v)[0] = 2; byte val2 = get();
   402                 assertEquals(val1, 1);
   403                 assertEquals(val2, 2);
   404             }
   406             {
   407                 c.v = new byte[1]; byte[] val1 = get1();
   408                 c.v = new byte[1]; byte[] val2 = get1();
   409                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   410             }
   411         }
   412     }
   414     /* ==================================================== */
   416     static class ObjectArrayLowerDim1 {
   417         public @Stable Object[] v;
   419         public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
   420         public static byte get() { return ((byte[][])c.v)[0][0]; }
   421         public static byte[] get1() { return (byte[])(c.v[0]); }
   422         public static Object[] get2() { return c.v; }
   424         public static void test() throws Exception {
   425             {
   426                 c.v = new byte[1][1]; ((byte[][])c.v)[0][0] = 1; byte val1 = get();
   427                                       ((byte[][])c.v)[0][0] = 2; byte val2 = get();
   429                 assertEquals(val1, 1);
   430                 assertEquals(val2, 2);
   431             }
   433             {
   434                 c.v = new byte[1][1]; c.v[0] = new byte[0]; byte[] val1 = get1();
   435                                      c.v[0] = new byte[0]; byte[] val2 = get1();
   437                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   438             }
   440             {
   441                 c.v = new byte[0][0]; Object[] val1 = get2();
   442                 c.v = new byte[0][0]; Object[] val2 = get2();
   444                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   445             }
   446         }
   447     }
   449     /* ==================================================== */
   451     static class ObjectArrayLowerDim2 {
   452         public @Stable Object[][] v;
   454         public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
   455         public static byte get() { return ((byte[][][])c.v)[0][0][0]; }
   456         public static byte[] get1() { return (byte[])(c.v[0][0]); }
   457         public static byte[][] get2() { return (byte[][])(c.v[0]); }
   458         public static Object[][] get3() { return c.v; }
   460         public static void test() throws Exception {
   461             {
   462                 c.v = new byte[1][1][1]; ((byte[][][])c.v)[0][0][0] = 1;  byte val1 = get();
   463                                          ((byte[][][])c.v)[0][0][0] = 2; byte val2 = get();
   465                 assertEquals(val1, 1);
   466                 assertEquals(val2, 2);
   467             }
   469             {
   470                 c.v = new byte[1][1][1]; c.v[0][0] = new byte[0]; byte[] val1 = get1();
   471                                          c.v[0][0] = new byte[0]; byte[] val2 = get1();
   473                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   474             }
   476             {
   477                 c.v = new byte[1][1][1]; c.v[0] = new byte[0][0]; byte[][] val1 = get2();
   478                                          c.v[0] = new byte[0][0]; byte[][] val2 = get2();
   480                 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   481             }
   483             {
   484                 c.v = new byte[0][0][0]; Object[][] val1 = get3();
   485                 c.v = new byte[0][0][0]; Object[][] val2 = get3();
   487                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   488             }
   489         }
   490     }
   492     /* ==================================================== */
   494     static class NestedStableField {
   495         static class A {
   496             public @Stable byte a;
   498         }
   499         public @Stable A v;
   501         public static final NestedStableField c = new NestedStableField();
   502         public static A get() { return c.v; }
   503         public static byte get1() { return get().a; }
   505         public static void test() throws Exception {
   506             {
   507                 c.v = new A(); c.v.a = 1; A val1 = get();
   508                                c.v.a = 2; A val2 = get();
   510                 assertEquals(val1.a, 2);
   511                 assertEquals(val2.a, 2);
   512             }
   514             {
   515                 c.v = new A(); c.v.a = 1; byte val1 = get1();
   516                                c.v.a = 2; byte val2 = get1();
   517                 c.v = new A(); c.v.a = 3; byte val3 = get1();
   519                 assertEquals(val1, 1);
   520                 assertEquals(val2, (isStableEnabled ? 1 : 2));
   521                 assertEquals(val3, (isStableEnabled ? 1 : 3));
   522             }
   523         }
   524     }
   526     /* ==================================================== */
   528     static class NestedStableField1 {
   529         static class A {
   530             public @Stable byte a;
   531             public @Stable A next;
   532         }
   533         public @Stable A v;
   535         public static final NestedStableField1 c = new NestedStableField1();
   536         public static A get() { return c.v.next.next.next.next.next.next.next; }
   537         public static byte get1() { return get().a; }
   539         public static void test() throws Exception {
   540             {
   541                 c.v = new A(); c.v.next = new A();   c.v.next.next  = c.v;
   542                                c.v.a = 1; c.v.next.a = 1; A val1 = get();
   543                                c.v.a = 2; c.v.next.a = 2; A val2 = get();
   545                 assertEquals(val1.a, 2);
   546                 assertEquals(val2.a, 2);
   547             }
   549             {
   550                 c.v = new A(); c.v.next = c.v;
   551                                c.v.a = 1; byte val1 = get1();
   552                                c.v.a = 2; byte val2 = get1();
   553                 c.v = new A(); c.v.next = c.v;
   554                                c.v.a = 3; byte val3 = get1();
   556                 assertEquals(val1, 1);
   557                 assertEquals(val2, (isStableEnabled ? 1 : 2));
   558                 assertEquals(val3, (isStableEnabled ? 1 : 3));
   559             }
   560         }
   561     }
   562    /* ==================================================== */
   564     static class NestedStableField2 {
   565         static class A {
   566             public @Stable byte a;
   567             public @Stable A left;
   568             public         A right;
   569         }
   571         public @Stable A v;
   573         public static final NestedStableField2 c = new NestedStableField2();
   574         public static byte get() { return c.v.left.left.left.a; }
   575         public static byte get1() { return c.v.left.left.right.left.a; }
   577         public static void test() throws Exception {
   578             {
   579                 c.v = new A(); c.v.left = c.v.right = c.v;
   580                                c.v.a = 1; byte val1 = get(); byte val2 = get1();
   581                                c.v.a = 2; byte val3 = get(); byte val4 = get1();
   583                 assertEquals(val1, 1);
   584                 assertEquals(val3, (isStableEnabled ? 1 : 2));
   586                 assertEquals(val2, 1);
   587                 assertEquals(val4, 2);
   588             }
   589         }
   590     }
   592     /* ==================================================== */
   594     static class NestedStableField3 {
   595         static class A {
   596             public @Stable byte a;
   597             public @Stable A[] left;
   598             public         A[] right;
   599         }
   601         public @Stable A[] v;
   603         public static final NestedStableField3 c = new NestedStableField3();
   604         public static byte get() { return c.v[0].left[1].left[0].left[1].a; }
   605         public static byte get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
   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; byte val1 = get(); byte val2 = get1();
   612                                elem.a = 2; byte val3 = get(); byte val4 = get1();
   614                 assertEquals(val1, 1);
   615                 assertEquals(val3, (isServerWithStable ? 1 : 2));
   617                 assertEquals(val2, 1);
   618                 assertEquals(val4, 2);
   619             }
   620         }
   621     }
   623     /* ==================================================== */
   624     // Auxiliary methods
   625     static void assertEquals(int i, int j) { if (i != j)  throw new AssertionError(i + " != " + j); }
   626     static void assertTrue(boolean b) { if (!b)  throw new AssertionError(); }
   628     static boolean failed = false;
   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) {
   636             ex = e.getCause();
   637         } catch (Throwable e) {
   638             ex = e;
   639         } finally {
   640             if (ex == null) {
   641                 System.out.println("PASSED");
   642             } else {
   643                 failed = true;
   644                 System.out.println("FAILED");
   645                 ex.printStackTrace(System.out);
   646             }
   647         }
   648     }
   649 }

mercurial