vlivanov@6528: /* vlivanov@6528: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. vlivanov@6528: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. vlivanov@6528: * vlivanov@6528: * This code is free software; you can redistribute it and/or modify it vlivanov@6528: * under the terms of the GNU General Public License version 2 only, as vlivanov@6528: * published by the Free Software Foundation. Oracle designates this vlivanov@6528: * particular file as subject to the "Classpath" exception as provided vlivanov@6528: * by Oracle in the LICENSE file that accompanied this code. vlivanov@6528: * vlivanov@6528: * This code is distributed in the hope that it will be useful, but WITHOUT vlivanov@6528: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or vlivanov@6528: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License vlivanov@6528: * version 2 for more details (a copy is included in the LICENSE file that vlivanov@6528: * accompanied this code). vlivanov@6528: * vlivanov@6528: * You should have received a copy of the GNU General Public License version vlivanov@6528: * 2 along with this work; if not, write to the Free Software Foundation, vlivanov@6528: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. vlivanov@6528: * vlivanov@6528: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA vlivanov@6528: * or visit www.oracle.com if you need additional information or have any vlivanov@6528: * questions. vlivanov@6528: */ vlivanov@6528: vlivanov@6528: /* vlivanov@6528: * @test TestStableInt vlivanov@6528: * @summary tests on stable fields and arrays vlivanov@6747: * @library /testlibrary /testlibrary/whitebox vlivanov@6747: * @build TestStableInt StableConfiguration sun.hotspot.WhiteBox vlivanov@6747: * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission vlivanov@6528: * @run main ClassFileInstaller vlivanov@6747: * java/lang/invoke/StableConfiguration vlivanov@6528: * java/lang/invoke/TestStableInt vlivanov@6528: * java/lang/invoke/TestStableInt$IntStable vlivanov@6528: * java/lang/invoke/TestStableInt$StaticIntStable vlivanov@6528: * java/lang/invoke/TestStableInt$VolatileIntStable vlivanov@6528: * java/lang/invoke/TestStableInt$IntArrayDim1 vlivanov@6528: * java/lang/invoke/TestStableInt$IntArrayDim2 vlivanov@6528: * java/lang/invoke/TestStableInt$IntArrayDim3 vlivanov@6528: * java/lang/invoke/TestStableInt$IntArrayDim4 vlivanov@6528: * java/lang/invoke/TestStableInt$ObjectArrayLowerDim0 vlivanov@6528: * java/lang/invoke/TestStableInt$ObjectArrayLowerDim1 vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField$A vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField1 vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField1$A vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField2 vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField2$A vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField3 vlivanov@6528: * java/lang/invoke/TestStableInt$NestedStableField3$A vlivanov@6528: * java/lang/invoke/TestStableInt$DefaultValue vlivanov@6747: * java/lang/invoke/TestStableInt$DefaultStaticValue vlivanov@6528: * java/lang/invoke/TestStableInt$ObjectArrayLowerDim2 vlivanov@6528: * vlivanov@6528: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -server -XX:-TieredCompilation vlivanov@6747: * -XX:+FoldStableValues vlivanov@6747: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6747: * java.lang.invoke.TestStableInt vlivanov@6747: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -server -XX:-TieredCompilation vlivanov@6747: * -XX:-FoldStableValues vlivanov@6528: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6528: * java.lang.invoke.TestStableInt vlivanov@6528: * vlivanov@6528: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1 vlivanov@6747: * -XX:+FoldStableValues vlivanov@6747: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6747: * java.lang.invoke.TestStableInt vlivanov@6747: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1 vlivanov@6747: * -XX:-FoldStableValues vlivanov@6528: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6528: * java.lang.invoke.TestStableInt vlivanov@6528: * vlivanov@6528: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -client -XX:-TieredCompilation vlivanov@6747: * -XX:+FoldStableValues vlivanov@6528: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6528: * java.lang.invoke.TestStableInt vlivanov@6528: * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions vlivanov@6747: * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp vlivanov@6747: * -client -XX:-TieredCompilation vlivanov@6747: * -XX:-FoldStableValues vlivanov@6528: * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 vlivanov@6528: * java.lang.invoke.TestStableInt vlivanov@6528: */ vlivanov@6528: package java.lang.invoke; vlivanov@6528: vlivanov@6528: import java.lang.reflect.InvocationTargetException; vlivanov@6528: vlivanov@6528: public class TestStableInt { vlivanov@6747: static final boolean isStableEnabled = StableConfiguration.isStableEnabled; vlivanov@6747: static final boolean isServerWithStable = StableConfiguration.isServerWithStable; vlivanov@6747: vlivanov@6528: public static void main(String[] args) throws Exception { vlivanov@6528: run(DefaultValue.class); vlivanov@6528: run(IntStable.class); vlivanov@6747: run(DefaultStaticValue.class); vlivanov@6528: run(StaticIntStable.class); vlivanov@6528: run(VolatileIntStable.class); vlivanov@6528: vlivanov@6528: // @Stable arrays: Dim 1-4 vlivanov@6528: run(IntArrayDim1.class); vlivanov@6528: run(IntArrayDim2.class); vlivanov@6528: run(IntArrayDim3.class); vlivanov@6528: run(IntArrayDim4.class); vlivanov@6528: vlivanov@6528: // @Stable Object field: dynamic arrays vlivanov@6528: run(ObjectArrayLowerDim0.class); vlivanov@6528: run(ObjectArrayLowerDim1.class); vlivanov@6528: run(ObjectArrayLowerDim2.class); vlivanov@6528: vlivanov@6528: // Nested @Stable fields vlivanov@6528: run(NestedStableField.class); vlivanov@6528: run(NestedStableField1.class); vlivanov@6528: run(NestedStableField2.class); vlivanov@6528: run(NestedStableField3.class); vlivanov@6528: vlivanov@6528: if (failed) { vlivanov@6528: throw new Error("TEST FAILED"); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class DefaultValue { vlivanov@6528: public @Stable int v; vlivanov@6528: vlivanov@6528: public static final DefaultValue c = new DefaultValue(); vlivanov@6528: public static int get() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: int val1 = get(); vlivanov@6528: c.v = 1; int val2 = get(); vlivanov@6528: assertEquals(val1, 0); vlivanov@6528: assertEquals(val2, 1); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class IntStable { vlivanov@6528: public @Stable int v; vlivanov@6528: vlivanov@6528: public static final IntStable c = new IntStable(); vlivanov@6528: public static int get() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: c.v = 1; int val1 = get(); vlivanov@6528: c.v = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, (isStableEnabled ? 1 : 2)); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6747: static class DefaultStaticValue { vlivanov@6747: public static @Stable int v; vlivanov@6747: vlivanov@6747: public static final DefaultStaticValue c = new DefaultStaticValue(); vlivanov@6747: public static int get() { return c.v; } vlivanov@6747: public static void test() throws Exception { vlivanov@6747: int val1 = get(); vlivanov@6747: c.v = 1; int val2 = get(); vlivanov@6747: assertEquals(val1, 0); vlivanov@6747: assertEquals(val2, 1); vlivanov@6747: } vlivanov@6747: } vlivanov@6747: vlivanov@6747: /* ==================================================== */ vlivanov@6747: vlivanov@6528: static class StaticIntStable { vlivanov@6528: public static @Stable int v; vlivanov@6528: vlivanov@6528: public static final StaticIntStable c = new StaticIntStable(); vlivanov@6528: public static int get() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: c.v = 1; int val1 = get(); vlivanov@6528: c.v = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, (isStableEnabled ? 1 : 2)); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class VolatileIntStable { vlivanov@6528: public @Stable volatile int v; vlivanov@6528: vlivanov@6528: public static final VolatileIntStable c = new VolatileIntStable(); vlivanov@6528: public static int get() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: c.v = 1; int val1 = get(); vlivanov@6528: c.v = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, (isStableEnabled ? 1 : 2)); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: // @Stable array == field && all components are stable vlivanov@6528: vlivanov@6528: static class IntArrayDim1 { vlivanov@6528: public @Stable int[] v; vlivanov@6528: vlivanov@6528: public static final IntArrayDim1 c = new IntArrayDim1(); vlivanov@6528: public static int get() { return c.v[0]; } vlivanov@6528: public static int get1() { return c.v[10]; } vlivanov@6528: public static int[] get2() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1]; c.v[0] = 1; int val1 = get(); vlivanov@6528: c.v[0] = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val2, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: c.v = new int[1]; c.v[0] = 3; int val3 = get(); vlivanov@6747: assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 3)); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[20]; c.v[10] = 1; int val1 = get1(); vlivanov@6528: c.v[10] = 2; int val2 = get1(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val2, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: c.v = new int[20]; c.v[10] = 3; int val3 = get1(); vlivanov@6747: assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 3)); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1]; int[] val1 = get2(); vlivanov@6528: c.v = new int[1]; int[] val2 = get2(); vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class IntArrayDim2 { vlivanov@6528: public @Stable int[][] v; vlivanov@6528: vlivanov@6528: public static final IntArrayDim2 c = new IntArrayDim2(); vlivanov@6528: public static int get() { return c.v[0][0]; } vlivanov@6528: public static int[] get1() { return c.v[0]; } vlivanov@6528: public static int[][] get2() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1][1]; c.v[0][0] = 1; int val1 = get(); vlivanov@6528: c.v[0][0] = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val2, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: c.v = new int[1][1]; c.v[0][0] = 3; int val3 = get(); vlivanov@6747: assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 3)); vlivanov@6528: vlivanov@6528: c.v[0] = new int[1]; c.v[0][0] = 4; int val4 = get(); vlivanov@6747: assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 4)); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1]; int[] val1 = get1(); vlivanov@6528: c.v[0] = new int[1]; int[] val2 = get1(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1]; int[][] val1 = get2(); vlivanov@6528: c.v = new int[1][1]; int[][] val2 = get2(); vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class IntArrayDim3 { vlivanov@6528: public @Stable int[][][] v; vlivanov@6528: vlivanov@6528: public static final IntArrayDim3 c = new IntArrayDim3(); vlivanov@6528: public static int get() { return c.v[0][0][0]; } vlivanov@6528: public static int[] get1() { return c.v[0][0]; } vlivanov@6528: public static int[][] get2() { return c.v[0]; } vlivanov@6528: public static int[][][] get3() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; c.v[0][0][0] = 1; int val1 = get(); vlivanov@6528: c.v[0][0][0] = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val2, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: c.v = new int[1][1][1]; c.v[0][0][0] = 3; int val3 = get(); vlivanov@6747: assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 3)); vlivanov@6528: vlivanov@6528: c.v[0] = new int[1][1]; c.v[0][0][0] = 4; int val4 = get(); vlivanov@6747: assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 4)); vlivanov@6528: vlivanov@6528: c.v[0][0] = new int[1]; c.v[0][0][0] = 5; int val5 = get(); vlivanov@6747: assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 5)); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; int[] val1 = get1(); vlivanov@6528: c.v[0][0] = new int[1]; int[] val2 = get1(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; int[][] val1 = get2(); vlivanov@6528: c.v[0] = new int[1][1]; int[][] val2 = get2(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; int[][][] val1 = get3(); vlivanov@6528: c.v = new int[1][1][1]; int[][][] val2 = get3(); vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class IntArrayDim4 { vlivanov@6528: public @Stable int[][][][] v; vlivanov@6528: vlivanov@6528: public static final IntArrayDim4 c = new IntArrayDim4(); vlivanov@6528: public static int get() { return c.v[0][0][0][0]; } vlivanov@6528: public static int[] get1() { return c.v[0][0][0]; } vlivanov@6528: public static int[][] get2() { return c.v[0][0]; } vlivanov@6528: public static int[][][] get3() { return c.v[0]; } vlivanov@6528: public static int[][][][] get4() { return c.v; } vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1][1]; c.v[0][0][0][0] = 1; int val1 = get(); vlivanov@6528: c.v[0][0][0][0] = 2; int val2 = get(); vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val2, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: c.v = new int[1][1][1][1]; c.v[0][0][0][0] = 3; int val3 = get(); vlivanov@6747: assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 3)); vlivanov@6528: vlivanov@6528: c.v[0] = new int[1][1][1]; c.v[0][0][0][0] = 4; int val4 = get(); vlivanov@6747: assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 4)); vlivanov@6528: vlivanov@6528: c.v[0][0] = new int[1][1]; c.v[0][0][0][0] = 5; int val5 = get(); vlivanov@6747: assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 5)); vlivanov@6528: vlivanov@6528: c.v[0][0][0] = new int[1]; c.v[0][0][0][0] = 6; int val6 = get(); vlivanov@6747: assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2) vlivanov@6747: : 6)); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1][1]; int[] val1 = get1(); vlivanov@6528: c.v[0][0][0] = new int[1]; int[] val2 = get1(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1][1]; int[][] val1 = get2(); vlivanov@6528: c.v[0][0] = new int[1][1]; int[][] val2 = get2(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1][1]; int[][][] val1 = get3(); vlivanov@6528: c.v[0] = new int[1][1][1]; int[][][] val2 = get3(); vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1][1]; int[][][][] val1 = get4(); vlivanov@6528: c.v = new int[1][1][1][1]; int[][][][] val2 = get4(); vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: // Dynamic Dim is higher than static vlivanov@6528: static class ObjectArrayLowerDim0 { vlivanov@6528: public @Stable Object v; vlivanov@6528: vlivanov@6528: public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0(); vlivanov@6528: public static int get() { return ((int[])c.v)[0]; } vlivanov@6528: public static int[] get1() { return (int[])c.v; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1]; ((int[])c.v)[0] = 1; int val1 = get(); vlivanov@6528: ((int[])c.v)[0] = 2; int val2 = get(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, 2); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1]; int[] val1 = get1(); vlivanov@6528: c.v = new int[1]; int[] val2 = get1(); vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class ObjectArrayLowerDim1 { vlivanov@6528: public @Stable Object[] v; vlivanov@6528: vlivanov@6528: public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1(); vlivanov@6528: public static int get() { return ((int[][])c.v)[0][0]; } vlivanov@6528: public static int[] get1() { return (int[])(c.v[0]); } vlivanov@6528: public static Object[] get2() { return c.v; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1][1]; ((int[][])c.v)[0][0] = 1; int val1 = get(); vlivanov@6528: ((int[][])c.v)[0][0] = 2; int val2 = get(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, 2); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1]; c.v[0] = new int[0]; int[] val1 = get1(); vlivanov@6528: c.v[0] = new int[0]; int[] val2 = get1(); vlivanov@6528: vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[0][0]; Object[] val1 = get2(); vlivanov@6528: c.v = new int[0][0]; Object[] val2 = get2(); vlivanov@6528: vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class ObjectArrayLowerDim2 { vlivanov@6528: public @Stable Object[][] v; vlivanov@6528: vlivanov@6528: public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2(); vlivanov@6528: public static int get() { return ((int[][][])c.v)[0][0][0]; } vlivanov@6528: public static int[] get1() { return (int[])(c.v[0][0]); } vlivanov@6528: public static int[][] get2() { return (int[][])(c.v[0]); } vlivanov@6528: public static Object[][] get3() { return c.v; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; ((int[][][])c.v)[0][0][0] = 1; int val1 = get(); vlivanov@6528: ((int[][][])c.v)[0][0][0] = 2; int val2 = get(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, 2); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; c.v[0][0] = new int[0]; int[] val1 = get1(); vlivanov@6528: c.v[0][0] = new int[0]; int[] val2 = get1(); vlivanov@6528: vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[1][1][1]; c.v[0] = new int[0][0]; int[][] val1 = get2(); vlivanov@6528: c.v[0] = new int[0][0]; int[][] val2 = get2(); vlivanov@6528: vlivanov@6747: assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new int[0][0][0]; Object[][] val1 = get3(); vlivanov@6528: c.v = new int[0][0][0]; Object[][] val2 = get3(); vlivanov@6528: vlivanov@6528: assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class NestedStableField { vlivanov@6528: static class A { vlivanov@6528: public @Stable int a; vlivanov@6528: vlivanov@6528: } vlivanov@6528: public @Stable A v; vlivanov@6528: vlivanov@6528: public static final NestedStableField c = new NestedStableField(); vlivanov@6528: public static A get() { return c.v; } vlivanov@6528: public static int get1() { return get().a; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new A(); c.v.a = 1; A val1 = get(); vlivanov@6528: c.v.a = 2; A val2 = get(); vlivanov@6528: vlivanov@6528: assertEquals(val1.a, 2); vlivanov@6528: assertEquals(val2.a, 2); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new A(); c.v.a = 1; int val1 = get1(); vlivanov@6528: c.v.a = 2; int val2 = get1(); vlivanov@6528: c.v = new A(); c.v.a = 3; int val3 = get1(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, (isStableEnabled ? 1 : 2)); vlivanov@6528: assertEquals(val3, (isStableEnabled ? 1 : 3)); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class NestedStableField1 { vlivanov@6528: static class A { vlivanov@6528: public @Stable int a; vlivanov@6528: public @Stable A next; vlivanov@6528: } vlivanov@6528: public @Stable A v; vlivanov@6528: vlivanov@6528: public static final NestedStableField1 c = new NestedStableField1(); vlivanov@6528: public static A get() { return c.v.next.next.next.next.next.next.next; } vlivanov@6528: public static int get1() { return get().a; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new A(); c.v.next = new A(); c.v.next.next = c.v; vlivanov@6528: c.v.a = 1; c.v.next.a = 1; A val1 = get(); vlivanov@6528: c.v.a = 2; c.v.next.a = 2; A val2 = get(); vlivanov@6528: vlivanov@6528: assertEquals(val1.a, 2); vlivanov@6528: assertEquals(val2.a, 2); vlivanov@6528: } vlivanov@6528: vlivanov@6528: { vlivanov@6528: c.v = new A(); c.v.next = c.v; vlivanov@6528: c.v.a = 1; int val1 = get1(); vlivanov@6528: c.v.a = 2; int val2 = get1(); vlivanov@6528: c.v = new A(); c.v.next = c.v; vlivanov@6528: c.v.a = 3; int val3 = get1(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val2, (isStableEnabled ? 1 : 2)); vlivanov@6528: assertEquals(val3, (isStableEnabled ? 1 : 3)); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class NestedStableField2 { vlivanov@6528: static class A { vlivanov@6528: public @Stable int a; vlivanov@6528: public @Stable A left; vlivanov@6528: public A right; vlivanov@6528: } vlivanov@6528: vlivanov@6528: public @Stable A v; vlivanov@6528: vlivanov@6528: public static final NestedStableField2 c = new NestedStableField2(); vlivanov@6528: public static int get() { return c.v.left.left.left.a; } vlivanov@6528: public static int get1() { return c.v.left.left.right.left.a; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: c.v = new A(); c.v.left = c.v.right = c.v; vlivanov@6528: c.v.a = 1; int val1 = get(); int val2 = get1(); vlivanov@6528: c.v.a = 2; int val3 = get(); int val4 = get1(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6528: assertEquals(val3, (isStableEnabled ? 1 : 2)); vlivanov@6528: vlivanov@6528: assertEquals(val2, 1); vlivanov@6528: assertEquals(val4, 2); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: vlivanov@6528: static class NestedStableField3 { vlivanov@6528: static class A { vlivanov@6528: public @Stable int a; vlivanov@6528: public @Stable A[] left; vlivanov@6528: public A[] right; vlivanov@6528: } vlivanov@6528: vlivanov@6528: public @Stable A[] v; vlivanov@6528: vlivanov@6528: public static final NestedStableField3 c = new NestedStableField3(); vlivanov@6528: public static int get() { return c.v[0].left[1].left[0].left[1].a; } vlivanov@6528: public static int get1() { return c.v[1].left[0].left[1].right[0].left[1].a; } vlivanov@6528: vlivanov@6528: public static void test() throws Exception { vlivanov@6528: { vlivanov@6528: A elem = new A(); vlivanov@6528: c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v; vlivanov@6528: elem.a = 1; int val1 = get(); int val2 = get1(); vlivanov@6528: elem.a = 2; int val3 = get(); int val4 = get1(); vlivanov@6528: vlivanov@6528: assertEquals(val1, 1); vlivanov@6747: assertEquals(val3, (isServerWithStable ? 1 : 2)); vlivanov@6528: vlivanov@6528: assertEquals(val2, 1); vlivanov@6528: assertEquals(val4, 2); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: vlivanov@6528: /* ==================================================== */ vlivanov@6528: // Auxiliary methods vlivanov@6528: static void assertEquals(int i, int j) { if (i != j) throw new AssertionError(i + " != " + j); } vlivanov@6528: static void assertTrue(boolean b) { if (!b) throw new AssertionError(); } vlivanov@6528: vlivanov@6528: static boolean failed = false; vlivanov@6528: vlivanov@6528: public static void run(Class test) { vlivanov@6528: Throwable ex = null; vlivanov@6528: System.out.print(test.getName()+": "); vlivanov@6528: try { vlivanov@6528: test.getMethod("test").invoke(null); vlivanov@6528: } catch (InvocationTargetException e) { vlivanov@6528: ex = e.getCause(); vlivanov@6528: } catch (Throwable e) { vlivanov@6528: ex = e; vlivanov@6528: } finally { vlivanov@6528: if (ex == null) { vlivanov@6528: System.out.println("PASSED"); vlivanov@6528: } else { vlivanov@6528: failed = true; vlivanov@6528: System.out.println("FAILED"); vlivanov@6528: ex.printStackTrace(System.out); vlivanov@6528: } vlivanov@6528: } vlivanov@6528: } vlivanov@6528: }