test/compiler/stable/TestStableChar.java

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7787
1ec24746bb40
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

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

mercurial