test/compiler/stable/TestStableLong.java

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/stable/TestStableLong.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,659 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +/*
    1.30 + * @test TestStableLong
    1.31 + * @summary tests on stable fields and arrays
    1.32 + * @library /testlibrary /testlibrary/whitebox
    1.33 + * @build TestStableLong StableConfiguration sun.hotspot.WhiteBox
    1.34 + * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
    1.35 + * @run main ClassFileInstaller
    1.36 + *           java/lang/invoke/StableConfiguration
    1.37 + *           java/lang/invoke/TestStableLong
    1.38 + *           java/lang/invoke/TestStableLong$LongStable
    1.39 + *           java/lang/invoke/TestStableLong$StaticLongStable
    1.40 + *           java/lang/invoke/TestStableLong$VolatileLongStable
    1.41 + *           java/lang/invoke/TestStableLong$LongArrayDim1
    1.42 + *           java/lang/invoke/TestStableLong$LongArrayDim2
    1.43 + *           java/lang/invoke/TestStableLong$LongArrayDim3
    1.44 + *           java/lang/invoke/TestStableLong$LongArrayDim4
    1.45 + *           java/lang/invoke/TestStableLong$ObjectArrayLowerDim0
    1.46 + *           java/lang/invoke/TestStableLong$ObjectArrayLowerDim1
    1.47 + *           java/lang/invoke/TestStableLong$NestedStableField
    1.48 + *           java/lang/invoke/TestStableLong$NestedStableField$A
    1.49 + *           java/lang/invoke/TestStableLong$NestedStableField1
    1.50 + *           java/lang/invoke/TestStableLong$NestedStableField1$A
    1.51 + *           java/lang/invoke/TestStableLong$NestedStableField2
    1.52 + *           java/lang/invoke/TestStableLong$NestedStableField2$A
    1.53 + *           java/lang/invoke/TestStableLong$NestedStableField3
    1.54 + *           java/lang/invoke/TestStableLong$NestedStableField3$A
    1.55 + *           java/lang/invoke/TestStableLong$DefaultValue
    1.56 + *           java/lang/invoke/TestStableLong$DefaultStaticValue
    1.57 + *           java/lang/invoke/TestStableLong$ObjectArrayLowerDim2
    1.58 + *
    1.59 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.60 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.61 + *                   -server -XX:-TieredCompilation
    1.62 + *                   -XX:+FoldStableValues
    1.63 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.64 + *                   java.lang.invoke.TestStableLong
    1.65 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.66 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.67 + *                   -server -XX:-TieredCompilation
    1.68 + *                   -XX:-FoldStableValues
    1.69 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.70 + *                   java.lang.invoke.TestStableLong
    1.71 + *
    1.72 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.73 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.74 + *                   -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
    1.75 + *                   -XX:+FoldStableValues
    1.76 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.77 + *                   java.lang.invoke.TestStableLong
    1.78 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.79 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.80 + *                   -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
    1.81 + *                   -XX:-FoldStableValues
    1.82 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.83 + *                   java.lang.invoke.TestStableLong
    1.84 + *
    1.85 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.86 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.87 + *                   -client -XX:-TieredCompilation
    1.88 + *                   -XX:+FoldStableValues
    1.89 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.90 + *                   java.lang.invoke.TestStableLong
    1.91 + * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
    1.92 + *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
    1.93 + *                   -client -XX:-TieredCompilation
    1.94 + *                   -XX:-FoldStableValues
    1.95 + *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
    1.96 + *                   java.lang.invoke.TestStableLong
    1.97 + */
    1.98 +package java.lang.invoke;
    1.99 +
   1.100 +import java.lang.reflect.InvocationTargetException;
   1.101 +
   1.102 +public class TestStableLong {
   1.103 +    static final boolean isStableEnabled    = StableConfiguration.isStableEnabled;
   1.104 +    static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
   1.105 +
   1.106 +    public static void main(String[] args) throws Exception {
   1.107 +        run(DefaultValue.class);
   1.108 +        run(LongStable.class);
   1.109 +        run(DefaultStaticValue.class);
   1.110 +        run(StaticLongStable.class);
   1.111 +        run(VolatileLongStable.class);
   1.112 +
   1.113 +        // @Stable arrays: Dim 1-4
   1.114 +        run(LongArrayDim1.class);
   1.115 +        run(LongArrayDim2.class);
   1.116 +        run(LongArrayDim3.class);
   1.117 +        run(LongArrayDim4.class);
   1.118 +
   1.119 +        // @Stable Object field: dynamic arrays
   1.120 +        run(ObjectArrayLowerDim0.class);
   1.121 +        run(ObjectArrayLowerDim1.class);
   1.122 +        run(ObjectArrayLowerDim2.class);
   1.123 +
   1.124 +        // Nested @Stable fields
   1.125 +        run(NestedStableField.class);
   1.126 +        run(NestedStableField1.class);
   1.127 +        run(NestedStableField2.class);
   1.128 +        run(NestedStableField3.class);
   1.129 +
   1.130 +        if (failed) {
   1.131 +            throw new Error("TEST FAILED");
   1.132 +        }
   1.133 +    }
   1.134 +
   1.135 +    /* ==================================================== */
   1.136 +
   1.137 +    static class DefaultValue {
   1.138 +        public @Stable long v;
   1.139 +
   1.140 +        public static final DefaultValue c = new DefaultValue();
   1.141 +        public static long get() { return c.v; }
   1.142 +        public static void test() throws Exception {
   1.143 +                      long val1 = get();
   1.144 +            c.v = 1L; long val2 = get();
   1.145 +            assertEquals(val1, 0);
   1.146 +            assertEquals(val2, 1L);
   1.147 +        }
   1.148 +    }
   1.149 +
   1.150 +    /* ==================================================== */
   1.151 +
   1.152 +    static class LongStable {
   1.153 +        public @Stable long v;
   1.154 +
   1.155 +        public static final LongStable c = new LongStable();
   1.156 +        public static long get() { return c.v; }
   1.157 +        public static void test() throws Exception {
   1.158 +            c.v = 5;              long val1 = get();
   1.159 +            c.v = Long.MAX_VALUE; long val2 = get();
   1.160 +            assertEquals(val1, 5);
   1.161 +            assertEquals(val2, (isStableEnabled ? 5 : Long.MAX_VALUE));
   1.162 +        }
   1.163 +    }
   1.164 +
   1.165 +    /* ==================================================== */
   1.166 +
   1.167 +    static class DefaultStaticValue {
   1.168 +        public static @Stable long v;
   1.169 +
   1.170 +        public static final DefaultStaticValue c = new DefaultStaticValue();
   1.171 +        public static long get() { return c.v; }
   1.172 +        public static void test() throws Exception {
   1.173 +                      long val1 = get();
   1.174 +            c.v = 1L; long val2 = get();
   1.175 +            assertEquals(val1, 0);
   1.176 +            assertEquals(val2, 1L);
   1.177 +        }
   1.178 +    }
   1.179 +
   1.180 +    /* ==================================================== */
   1.181 +
   1.182 +    static class StaticLongStable {
   1.183 +        public static @Stable long v;
   1.184 +
   1.185 +        public static final StaticLongStable c = new StaticLongStable();
   1.186 +        public static long get() { return c.v; }
   1.187 +        public static void test() throws Exception {
   1.188 +            c.v = 5;              long val1 = get();
   1.189 +            c.v = Long.MAX_VALUE; long val2 = get();
   1.190 +            assertEquals(val1, 5);
   1.191 +            assertEquals(val2, (isStableEnabled ? 5 : Long.MAX_VALUE));
   1.192 +        }
   1.193 +    }
   1.194 +
   1.195 +    /* ==================================================== */
   1.196 +
   1.197 +    static class VolatileLongStable {
   1.198 +        public @Stable volatile long v;
   1.199 +
   1.200 +        public static final VolatileLongStable c = new VolatileLongStable();
   1.201 +        public static long get() { return c.v; }
   1.202 +        public static void test() throws Exception {
   1.203 +            c.v = 5;              long val1 = get();
   1.204 +            c.v = Long.MAX_VALUE; long val2 = get();
   1.205 +            assertEquals(val1, 5);
   1.206 +            assertEquals(val2, (isStableEnabled ? 5 : Long.MAX_VALUE));
   1.207 +        }
   1.208 +    }
   1.209 +
   1.210 +    /* ==================================================== */
   1.211 +    // @Stable array == field && all components are stable
   1.212 +
   1.213 +    static class LongArrayDim1 {
   1.214 +        public @Stable long[] v;
   1.215 +
   1.216 +        public static final LongArrayDim1 c = new LongArrayDim1();
   1.217 +        public static long get() { return c.v[0]; }
   1.218 +        public static long get1() { return c.v[10]; }
   1.219 +        public static long[] get2() { return c.v; }
   1.220 +        public static void test() throws Exception {
   1.221 +            {
   1.222 +                c.v = new long[1]; c.v[0] = 1; long val1 = get();
   1.223 +                                   c.v[0] = 2; long val2 = get();
   1.224 +                assertEquals(val1, 1);
   1.225 +                assertEquals(val2, (isServerWithStable ? 1 : 2));
   1.226 +
   1.227 +                c.v = new long[1]; c.v[0] = 3; long val3 = get();
   1.228 +                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.229 +                                                    : 3));
   1.230 +            }
   1.231 +
   1.232 +            {
   1.233 +                c.v = new long[20]; c.v[10] = 1; long val1 = get1();
   1.234 +                                    c.v[10] = 2; long val2 = get1();
   1.235 +                assertEquals(val1, 1);
   1.236 +                assertEquals(val2, (isServerWithStable ? 1 : 2));
   1.237 +
   1.238 +                c.v = new long[20]; c.v[10] = 3; long val3 = get1();
   1.239 +                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.240 +                                                    : 3));
   1.241 +            }
   1.242 +
   1.243 +            {
   1.244 +                c.v = new long[1]; long[] val1 = get2();
   1.245 +                c.v = new long[1]; long[] val2 = get2();
   1.246 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.247 +            }
   1.248 +        }
   1.249 +    }
   1.250 +
   1.251 +    /* ==================================================== */
   1.252 +
   1.253 +    static class LongArrayDim2 {
   1.254 +        public @Stable long[][] v;
   1.255 +
   1.256 +        public static final LongArrayDim2 c = new LongArrayDim2();
   1.257 +        public static long get() { return c.v[0][0]; }
   1.258 +        public static long[] get1() { return c.v[0]; }
   1.259 +        public static long[][] get2() { return c.v; }
   1.260 +        public static void test() throws Exception {
   1.261 +            {
   1.262 +                c.v = new long[1][1]; c.v[0][0] = 1; long val1 = get();
   1.263 +                                      c.v[0][0] = 2; long val2 = get();
   1.264 +                assertEquals(val1, 1);
   1.265 +                assertEquals(val2, (isServerWithStable ? 1 : 2));
   1.266 +
   1.267 +                c.v = new long[1][1]; c.v[0][0] = 3; long val3 = get();
   1.268 +                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.269 +                                                    : 3));
   1.270 +
   1.271 +                c.v[0] = new long[1]; c.v[0][0] = 4; long val4 = get();
   1.272 +                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.273 +                                                    : 4));
   1.274 +            }
   1.275 +
   1.276 +            {
   1.277 +                c.v = new long[1][1]; long[] val1 = get1();
   1.278 +                c.v[0] = new long[1]; long[] val2 = get1();
   1.279 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.280 +            }
   1.281 +
   1.282 +            {
   1.283 +                c.v = new long[1][1]; long[][] val1 = get2();
   1.284 +                c.v = new long[1][1]; long[][] val2 = get2();
   1.285 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.286 +            }
   1.287 +        }
   1.288 +    }
   1.289 +
   1.290 +    /* ==================================================== */
   1.291 +
   1.292 +    static class LongArrayDim3 {
   1.293 +        public @Stable long[][][] v;
   1.294 +
   1.295 +        public static final LongArrayDim3 c = new LongArrayDim3();
   1.296 +        public static long get() { return c.v[0][0][0]; }
   1.297 +        public static long[] get1() { return c.v[0][0]; }
   1.298 +        public static long[][] get2() { return c.v[0]; }
   1.299 +        public static long[][][] get3() { return c.v; }
   1.300 +        public static void test() throws Exception {
   1.301 +            {
   1.302 +                c.v = new long[1][1][1]; c.v[0][0][0] = 1; long val1 = get();
   1.303 +                                         c.v[0][0][0] = 2; long val2 = get();
   1.304 +                assertEquals(val1, 1);
   1.305 +                assertEquals(val2, (isServerWithStable ? 1 : 2));
   1.306 +
   1.307 +                c.v = new long[1][1][1]; c.v[0][0][0] = 3; long val3 = get();
   1.308 +                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.309 +                                                    : 3));
   1.310 +
   1.311 +                c.v[0] = new long[1][1]; c.v[0][0][0] = 4; long val4 = get();
   1.312 +                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.313 +                                                    : 4));
   1.314 +
   1.315 +                c.v[0][0] = new long[1]; c.v[0][0][0] = 5; long val5 = get();
   1.316 +                assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.317 +                                                    : 5));
   1.318 +            }
   1.319 +
   1.320 +            {
   1.321 +                c.v = new long[1][1][1]; long[] val1 = get1();
   1.322 +                c.v[0][0] = new long[1]; long[] val2 = get1();
   1.323 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.324 +            }
   1.325 +
   1.326 +            {
   1.327 +                c.v = new long[1][1][1]; long[][] val1 = get2();
   1.328 +                c.v[0] = new long[1][1]; long[][] val2 = get2();
   1.329 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.330 +            }
   1.331 +
   1.332 +            {
   1.333 +                c.v = new long[1][1][1]; long[][][] val1 = get3();
   1.334 +                c.v = new long[1][1][1]; long[][][] val2 = get3();
   1.335 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.336 +            }
   1.337 +        }
   1.338 +    }
   1.339 +
   1.340 +    /* ==================================================== */
   1.341 +
   1.342 +    static class LongArrayDim4 {
   1.343 +        public @Stable long[][][][] v;
   1.344 +
   1.345 +        public static final LongArrayDim4 c = new LongArrayDim4();
   1.346 +        public static long get() { return c.v[0][0][0][0]; }
   1.347 +        public static long[] get1() { return c.v[0][0][0]; }
   1.348 +        public static long[][] get2() { return c.v[0][0]; }
   1.349 +        public static long[][][] get3() { return c.v[0]; }
   1.350 +        public static long[][][][] get4() { return c.v; }
   1.351 +        public static void test() throws Exception {
   1.352 +            {
   1.353 +                c.v = new long[1][1][1][1]; c.v[0][0][0][0] = 1; long val1 = get();
   1.354 +                                            c.v[0][0][0][0] = 2; long val2 = get();
   1.355 +                assertEquals(val1, 1);
   1.356 +                assertEquals(val2, (isServerWithStable ? 1 : 2));
   1.357 +
   1.358 +                c.v = new long[1][1][1][1]; c.v[0][0][0][0] = 3; long val3 = get();
   1.359 +                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.360 +                                                    : 3));
   1.361 +
   1.362 +                c.v[0] = new long[1][1][1]; c.v[0][0][0][0] = 4; long val4 = get();
   1.363 +                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.364 +                                                    : 4));
   1.365 +
   1.366 +                c.v[0][0] = new long[1][1]; c.v[0][0][0][0] = 5; long val5 = get();
   1.367 +                assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.368 +                                                    : 5));
   1.369 +
   1.370 +                c.v[0][0][0] = new long[1]; c.v[0][0][0][0] = 6; long val6 = get();
   1.371 +                assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
   1.372 +                                                    : 6));
   1.373 +            }
   1.374 +
   1.375 +            {
   1.376 +                c.v = new long[1][1][1][1]; long[] val1 = get1();
   1.377 +                c.v[0][0][0] = new long[1]; long[] val2 = get1();
   1.378 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.379 +            }
   1.380 +
   1.381 +            {
   1.382 +                c.v = new long[1][1][1][1]; long[][] val1 = get2();
   1.383 +                c.v[0][0] = new long[1][1]; long[][] val2 = get2();
   1.384 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.385 +            }
   1.386 +
   1.387 +            {
   1.388 +                c.v = new long[1][1][1][1]; long[][][] val1 = get3();
   1.389 +                c.v[0] = new long[1][1][1]; long[][][] val2 = get3();
   1.390 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.391 +            }
   1.392 +
   1.393 +            {
   1.394 +                c.v = new long[1][1][1][1]; long[][][][] val1 = get4();
   1.395 +                c.v = new long[1][1][1][1]; long[][][][] val2 = get4();
   1.396 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.397 +            }
   1.398 +        }
   1.399 +    }
   1.400 +
   1.401 +    /* ==================================================== */
   1.402 +    // Dynamic Dim is higher than static
   1.403 +    static class ObjectArrayLowerDim0 {
   1.404 +        public @Stable Object v;
   1.405 +
   1.406 +        public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0();
   1.407 +        public static long get() { return ((long[])c.v)[0]; }
   1.408 +        public static long[] get1() { return (long[])c.v; }
   1.409 +
   1.410 +        public static void test() throws Exception {
   1.411 +            {
   1.412 +                c.v = new long[1]; ((long[])c.v)[0] = 1; long val1 = get();
   1.413 +                                   ((long[])c.v)[0] = 2; long val2 = get();
   1.414 +
   1.415 +                assertEquals(val1, 1);
   1.416 +                assertEquals(val2, 2);
   1.417 +            }
   1.418 +
   1.419 +            {
   1.420 +                c.v = new long[1]; long[] val1 = get1();
   1.421 +                c.v = new long[1]; long[] val2 = get1();
   1.422 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.423 +            }
   1.424 +        }
   1.425 +    }
   1.426 +
   1.427 +    /* ==================================================== */
   1.428 +
   1.429 +    static class ObjectArrayLowerDim1 {
   1.430 +        public @Stable Object[] v;
   1.431 +
   1.432 +        public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1();
   1.433 +        public static long get() { return ((long[][])c.v)[0][0]; }
   1.434 +        public static long[] get1() { return (long[])(c.v[0]); }
   1.435 +        public static Object[] get2() { return c.v; }
   1.436 +
   1.437 +        public static void test() throws Exception {
   1.438 +            {
   1.439 +                c.v = new long[1][1]; ((long[][])c.v)[0][0] = 1; long val1 = get();
   1.440 +                                      ((long[][])c.v)[0][0] = 2; long val2 = get();
   1.441 +
   1.442 +                assertEquals(val1, 1);
   1.443 +                assertEquals(val2, 2);
   1.444 +            }
   1.445 +
   1.446 +            {
   1.447 +                c.v = new long[1][1]; c.v[0] = new long[0]; long[] val1 = get1();
   1.448 +                                     c.v[0] = new long[0]; long[] val2 = get1();
   1.449 +
   1.450 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.451 +            }
   1.452 +
   1.453 +            {
   1.454 +                c.v = new long[0][0]; Object[] val1 = get2();
   1.455 +                c.v = new long[0][0]; Object[] val2 = get2();
   1.456 +
   1.457 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.458 +            }
   1.459 +        }
   1.460 +    }
   1.461 +
   1.462 +    /* ==================================================== */
   1.463 +
   1.464 +    static class ObjectArrayLowerDim2 {
   1.465 +        public @Stable Object[][] v;
   1.466 +
   1.467 +        public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2();
   1.468 +        public static long get() { return ((long[][][])c.v)[0][0][0]; }
   1.469 +        public static long[] get1() { return (long[])(c.v[0][0]); }
   1.470 +        public static long[][] get2() { return (long[][])(c.v[0]); }
   1.471 +        public static Object[][] get3() { return c.v; }
   1.472 +
   1.473 +        public static void test() throws Exception {
   1.474 +            {
   1.475 +                c.v = new long[1][1][1]; ((long[][][])c.v)[0][0][0] = 1L; long val1 = get();
   1.476 +                                         ((long[][][])c.v)[0][0][0] = 2L; long val2 = get();
   1.477 +
   1.478 +                assertEquals(val1, 1L);
   1.479 +                assertEquals(val2, 2L);
   1.480 +            }
   1.481 +
   1.482 +            {
   1.483 +                c.v = new long[1][1][1]; c.v[0][0] = new long[0]; long[] val1 = get1();
   1.484 +                                         c.v[0][0] = new long[0]; long[] val2 = get1();
   1.485 +
   1.486 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.487 +            }
   1.488 +
   1.489 +            {
   1.490 +                c.v = new long[1][1][1]; c.v[0] = new long[0][0]; long[][] val1 = get2();
   1.491 +                                         c.v[0] = new long[0][0]; long[][] val2 = get2();
   1.492 +
   1.493 +                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
   1.494 +            }
   1.495 +
   1.496 +            {
   1.497 +                c.v = new long[0][0][0]; Object[][] val1 = get3();
   1.498 +                c.v = new long[0][0][0]; Object[][] val2 = get3();
   1.499 +
   1.500 +                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
   1.501 +            }
   1.502 +        }
   1.503 +    }
   1.504 +
   1.505 +    /* ==================================================== */
   1.506 +
   1.507 +    static class NestedStableField {
   1.508 +        static class A {
   1.509 +            public @Stable long a;
   1.510 +
   1.511 +        }
   1.512 +        public @Stable A v;
   1.513 +
   1.514 +        public static final NestedStableField c = new NestedStableField();
   1.515 +        public static A get() { return c.v; }
   1.516 +        public static long get1() { return get().a; }
   1.517 +
   1.518 +        public static void test() throws Exception {
   1.519 +            {
   1.520 +                c.v = new A(); c.v.a = 1; A val1 = get();
   1.521 +                               c.v.a = 2; A val2 = get();
   1.522 +
   1.523 +                assertEquals(val1.a, 2);
   1.524 +                assertEquals(val2.a, 2);
   1.525 +            }
   1.526 +
   1.527 +            {
   1.528 +                c.v = new A(); c.v.a = 1; long val1 = get1();
   1.529 +                               c.v.a = 2; long val2 = get1();
   1.530 +                c.v = new A(); c.v.a = 3; long val3 = get1();
   1.531 +
   1.532 +                assertEquals(val1, 1);
   1.533 +                assertEquals(val2, (isStableEnabled ? 1 : 2));
   1.534 +                assertEquals(val3, (isStableEnabled ? 1 : 3));
   1.535 +            }
   1.536 +        }
   1.537 +    }
   1.538 +
   1.539 +    /* ==================================================== */
   1.540 +
   1.541 +    static class NestedStableField1 {
   1.542 +        static class A {
   1.543 +            public @Stable long a;
   1.544 +            public @Stable A next;
   1.545 +        }
   1.546 +        public @Stable A v;
   1.547 +
   1.548 +        public static final NestedStableField1 c = new NestedStableField1();
   1.549 +        public static A get() { return c.v.next.next.next.next.next.next.next; }
   1.550 +        public static long get1() { return get().a; }
   1.551 +
   1.552 +        public static void test() throws Exception {
   1.553 +            {
   1.554 +                c.v = new A(); c.v.next = new A();   c.v.next.next  = c.v;
   1.555 +                               c.v.a = 1; c.v.next.a = 1; A val1 = get();
   1.556 +                               c.v.a = 2; c.v.next.a = 2; A val2 = get();
   1.557 +
   1.558 +                assertEquals(val1.a, 2);
   1.559 +                assertEquals(val2.a, 2);
   1.560 +            }
   1.561 +
   1.562 +            {
   1.563 +                c.v = new A(); c.v.next = c.v;
   1.564 +                               c.v.a = 1; long val1 = get1();
   1.565 +                               c.v.a = 2; long val2 = get1();
   1.566 +                c.v = new A(); c.v.next = c.v;
   1.567 +                               c.v.a = 3; long val3 = get1();
   1.568 +
   1.569 +                assertEquals(val1, 1);
   1.570 +                assertEquals(val2, (isStableEnabled ? 1 : 2));
   1.571 +                assertEquals(val3, (isStableEnabled ? 1 : 3));
   1.572 +            }
   1.573 +        }
   1.574 +    }
   1.575 +   /* ==================================================== */
   1.576 +
   1.577 +    static class NestedStableField2 {
   1.578 +        static class A {
   1.579 +            public @Stable long a;
   1.580 +            public @Stable A left;
   1.581 +            public         A right;
   1.582 +        }
   1.583 +
   1.584 +        public @Stable A v;
   1.585 +
   1.586 +        public static final NestedStableField2 c = new NestedStableField2();
   1.587 +        public static long get() { return c.v.left.left.left.a; }
   1.588 +        public static long get1() { return c.v.left.left.right.left.a; }
   1.589 +
   1.590 +        public static void test() throws Exception {
   1.591 +            {
   1.592 +                c.v = new A(); c.v.left = c.v.right = c.v;
   1.593 +                               c.v.a = 1; long val1 = get(); long val2 = get1();
   1.594 +                               c.v.a = 2; long val3 = get(); long val4 = get1();
   1.595 +
   1.596 +                assertEquals(val1, 1);
   1.597 +                assertEquals(val3, (isStableEnabled ? 1 : 2));
   1.598 +
   1.599 +                assertEquals(val2, 1);
   1.600 +                assertEquals(val4, 2);
   1.601 +            }
   1.602 +        }
   1.603 +    }
   1.604 +
   1.605 +    /* ==================================================== */
   1.606 +
   1.607 +    static class NestedStableField3 {
   1.608 +        static class A {
   1.609 +            public @Stable long a;
   1.610 +            public @Stable A[] left;
   1.611 +            public         A[] right;
   1.612 +        }
   1.613 +
   1.614 +        public @Stable A[] v;
   1.615 +
   1.616 +        public static final NestedStableField3 c = new NestedStableField3();
   1.617 +        public static long get() { return c.v[0].left[1].left[0].left[1].a; }
   1.618 +        public static long get1() { return c.v[1].left[0].left[1].right[0].left[1].a; }
   1.619 +
   1.620 +        public static void test() throws Exception {
   1.621 +            {
   1.622 +                A elem = new A();
   1.623 +                c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v;
   1.624 +                               elem.a = 1; long val1 = get(); long val2 = get1();
   1.625 +                               elem.a = 2; long val3 = get(); long val4 = get1();
   1.626 +
   1.627 +                assertEquals(val1, 1);
   1.628 +                assertEquals(val3, (isServerWithStable ? 1 : 2));
   1.629 +
   1.630 +                assertEquals(val2, 1);
   1.631 +                assertEquals(val4, 2);
   1.632 +            }
   1.633 +        }
   1.634 +    }
   1.635 +
   1.636 +    /* ==================================================== */
   1.637 +    // Auxiliary methods
   1.638 +    static void assertEquals(long i, long j) { if (i != j)  throw new AssertionError(i + " != " + j); }
   1.639 +    static void assertTrue(boolean b) { if (!b)  throw new AssertionError(); }
   1.640 +
   1.641 +    static boolean failed = false;
   1.642 +
   1.643 +    public static void run(Class<?> test) {
   1.644 +        Throwable ex = null;
   1.645 +        System.out.print(test.getName()+": ");
   1.646 +        try {
   1.647 +            test.getMethod("test").invoke(null);
   1.648 +        } catch (InvocationTargetException e) {
   1.649 +            ex = e.getCause();
   1.650 +        } catch (Throwable e) {
   1.651 +            ex = e;
   1.652 +        } finally {
   1.653 +            if (ex == null) {
   1.654 +                System.out.println("PASSED");
   1.655 +            } else {
   1.656 +                failed = true;
   1.657 +                System.out.println("FAILED");
   1.658 +                ex.printStackTrace(System.out);
   1.659 +            }
   1.660 +        }
   1.661 +    }
   1.662 +}

mercurial