Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2013, 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. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 8024070 |
aoqi@0 | 27 | * @summary Test that type speculation doesn't cause incorrect execution |
aoqi@0 | 28 | * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation TypeSpeculation |
aoqi@0 | 29 | * |
aoqi@0 | 30 | */ |
aoqi@0 | 31 | |
aoqi@0 | 32 | public class TypeSpeculation { |
aoqi@0 | 33 | |
aoqi@0 | 34 | interface I { |
aoqi@0 | 35 | } |
aoqi@0 | 36 | |
aoqi@0 | 37 | static class A { |
aoqi@0 | 38 | int m() { |
aoqi@0 | 39 | return 1; |
aoqi@0 | 40 | } |
aoqi@0 | 41 | } |
aoqi@0 | 42 | |
aoqi@0 | 43 | static class B extends A implements I { |
aoqi@0 | 44 | int m() { |
aoqi@0 | 45 | return 2; |
aoqi@0 | 46 | } |
aoqi@0 | 47 | } |
aoqi@0 | 48 | |
aoqi@0 | 49 | static class C extends B { |
aoqi@0 | 50 | int m() { |
aoqi@0 | 51 | return 3; |
aoqi@0 | 52 | } |
aoqi@0 | 53 | } |
aoqi@0 | 54 | |
aoqi@0 | 55 | static int test1_invokevirtual(A a) { |
aoqi@0 | 56 | return a.m(); |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
aoqi@0 | 59 | static int test1_1(A a) { |
aoqi@0 | 60 | return test1_invokevirtual(a); |
aoqi@0 | 61 | } |
aoqi@0 | 62 | |
aoqi@0 | 63 | static boolean test1() { |
aoqi@0 | 64 | A a = new A(); |
aoqi@0 | 65 | B b = new B(); |
aoqi@0 | 66 | C c = new C(); |
aoqi@0 | 67 | |
aoqi@0 | 68 | // pollute profile at test1_invokevirtual to make sure the |
aoqi@0 | 69 | // compiler cannot rely on it |
aoqi@0 | 70 | for (int i = 0; i < 5000; i++) { |
aoqi@0 | 71 | test1_invokevirtual(a); |
aoqi@0 | 72 | test1_invokevirtual(b); |
aoqi@0 | 73 | test1_invokevirtual(c); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | // profiling + speculation should make test1_invokevirtual |
aoqi@0 | 77 | // inline A.m() with a guard |
aoqi@0 | 78 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 79 | int res = test1_1(b); |
aoqi@0 | 80 | if (res != b.m()) { |
aoqi@0 | 81 | System.out.println("test1 failed with class B"); |
aoqi@0 | 82 | return false; |
aoqi@0 | 83 | } |
aoqi@0 | 84 | } |
aoqi@0 | 85 | // check that the guard works as expected by passing a |
aoqi@0 | 86 | // different type |
aoqi@0 | 87 | int res = test1_1(a); |
aoqi@0 | 88 | if (res != a.m()) { |
aoqi@0 | 89 | System.out.println("test1 failed with class A"); |
aoqi@0 | 90 | return false; |
aoqi@0 | 91 | } |
aoqi@0 | 92 | return true; |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | static int test2_invokevirtual(A a) { |
aoqi@0 | 96 | return a.m(); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | static int test2_1(A a, boolean t) { |
aoqi@0 | 100 | A aa; |
aoqi@0 | 101 | if (t) { |
aoqi@0 | 102 | aa = (B)a; |
aoqi@0 | 103 | } else { |
aoqi@0 | 104 | aa = a; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | // if a of type B is passed to test2_1, the static type of aa |
aoqi@0 | 107 | // here is no better than A but the profiled type is B so this |
aoqi@0 | 108 | // should inline |
aoqi@0 | 109 | return test2_invokevirtual(aa); |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | static boolean test2() { |
aoqi@0 | 113 | A a = new A(); |
aoqi@0 | 114 | B b = new B(); |
aoqi@0 | 115 | C c = new C(); |
aoqi@0 | 116 | |
aoqi@0 | 117 | // pollute profile at test2_invokevirtual to make sure the |
aoqi@0 | 118 | // compiler cannot rely on it |
aoqi@0 | 119 | for (int i = 0; i < 5000; i++) { |
aoqi@0 | 120 | test2_invokevirtual(a); |
aoqi@0 | 121 | test2_invokevirtual(b); |
aoqi@0 | 122 | test2_invokevirtual(c); |
aoqi@0 | 123 | } |
aoqi@0 | 124 | |
aoqi@0 | 125 | // profiling + speculation should make test2_invokevirtual |
aoqi@0 | 126 | // inline A.m() with a guard |
aoqi@0 | 127 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 128 | int res = test2_1(b, (i % 2) == 0); |
aoqi@0 | 129 | if (res != b.m()) { |
aoqi@0 | 130 | System.out.println("test2 failed with class B"); |
aoqi@0 | 131 | return false; |
aoqi@0 | 132 | } |
aoqi@0 | 133 | } |
aoqi@0 | 134 | // check that the guard works as expected by passing a |
aoqi@0 | 135 | // different type |
aoqi@0 | 136 | int res = test2_1(a, false); |
aoqi@0 | 137 | if (res != a.m()) { |
aoqi@0 | 138 | System.out.println("test2 failed with class A"); |
aoqi@0 | 139 | return false; |
aoqi@0 | 140 | } |
aoqi@0 | 141 | return true; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | static int test3_invokevirtual(A a) { |
aoqi@0 | 145 | return a.m(); |
aoqi@0 | 146 | } |
aoqi@0 | 147 | |
aoqi@0 | 148 | static void test3_2(A a) { |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | static int test3_1(A a, int i) { |
aoqi@0 | 152 | if (i == 0) { |
aoqi@0 | 153 | return 0; |
aoqi@0 | 154 | } |
aoqi@0 | 155 | // If we come here and a is of type B but parameter profiling |
aoqi@0 | 156 | // is polluted, both branches of the if below should have |
aoqi@0 | 157 | // profiling that tell us and inlining of the virtual call |
aoqi@0 | 158 | // should happen |
aoqi@0 | 159 | if (i == 1) { |
aoqi@0 | 160 | test3_2(a); |
aoqi@0 | 161 | } else { |
aoqi@0 | 162 | test3_2(a); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | return test3_invokevirtual(a); |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | static boolean test3() { |
aoqi@0 | 168 | A a = new A(); |
aoqi@0 | 169 | B b = new B(); |
aoqi@0 | 170 | C c = new C(); |
aoqi@0 | 171 | |
aoqi@0 | 172 | // pollute profile at test3_invokevirtual and test3_1 to make |
aoqi@0 | 173 | // sure the compiler cannot rely on it |
aoqi@0 | 174 | for (int i = 0; i < 3000; i++) { |
aoqi@0 | 175 | test3_invokevirtual(a); |
aoqi@0 | 176 | test3_invokevirtual(b); |
aoqi@0 | 177 | test3_invokevirtual(c); |
aoqi@0 | 178 | test3_1(a, 0); |
aoqi@0 | 179 | test3_1(b, 0); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | // profiling + speculation should make test3_invokevirtual |
aoqi@0 | 183 | // inline A.m() with a guard |
aoqi@0 | 184 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 185 | int res = test3_1(b, (i % 2) + 1); |
aoqi@0 | 186 | if (res != b.m()) { |
aoqi@0 | 187 | System.out.println("test3 failed with class B"); |
aoqi@0 | 188 | return false; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | } |
aoqi@0 | 191 | // check that the guard works as expected by passing a |
aoqi@0 | 192 | // different type |
aoqi@0 | 193 | int res = test3_1(a, 1); |
aoqi@0 | 194 | if (res != a.m()) { |
aoqi@0 | 195 | System.out.println("test3 failed with class A"); |
aoqi@0 | 196 | return false; |
aoqi@0 | 197 | } |
aoqi@0 | 198 | return true; |
aoqi@0 | 199 | } |
aoqi@0 | 200 | |
aoqi@0 | 201 | // Mix 2 incompatible profiled types |
aoqi@0 | 202 | static int test4_invokevirtual(A a) { |
aoqi@0 | 203 | return a.m(); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | |
aoqi@0 | 206 | static void test4_2(A a) { |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | static int test4_1(A a, boolean b) { |
aoqi@0 | 210 | if (b) { |
aoqi@0 | 211 | test4_2(a); |
aoqi@0 | 212 | } else { |
aoqi@0 | 213 | test4_2(a); |
aoqi@0 | 214 | } |
aoqi@0 | 215 | // shouldn't inline |
aoqi@0 | 216 | return test4_invokevirtual(a); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | static boolean test4() { |
aoqi@0 | 220 | A a = new A(); |
aoqi@0 | 221 | B b = new B(); |
aoqi@0 | 222 | C c = new C(); |
aoqi@0 | 223 | |
aoqi@0 | 224 | // pollute profile at test3_invokevirtual and test3_1 to make |
aoqi@0 | 225 | // sure the compiler cannot rely on it |
aoqi@0 | 226 | for (int i = 0; i < 3000; i++) { |
aoqi@0 | 227 | test4_invokevirtual(a); |
aoqi@0 | 228 | test4_invokevirtual(b); |
aoqi@0 | 229 | test4_invokevirtual(c); |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 233 | if ((i % 2) == 0) { |
aoqi@0 | 234 | int res = test4_1(a, true); |
aoqi@0 | 235 | if (res != a.m()) { |
aoqi@0 | 236 | System.out.println("test4 failed with class A"); |
aoqi@0 | 237 | return false; |
aoqi@0 | 238 | } |
aoqi@0 | 239 | } else { |
aoqi@0 | 240 | int res = test4_1(b, false); |
aoqi@0 | 241 | if (res != b.m()) { |
aoqi@0 | 242 | System.out.println("test4 failed with class B"); |
aoqi@0 | 243 | return false; |
aoqi@0 | 244 | } |
aoqi@0 | 245 | } |
aoqi@0 | 246 | } |
aoqi@0 | 247 | return true; |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | // Mix one profiled type with an incompatible type |
aoqi@0 | 251 | static int test5_invokevirtual(A a) { |
aoqi@0 | 252 | return a.m(); |
aoqi@0 | 253 | } |
aoqi@0 | 254 | |
aoqi@0 | 255 | static void test5_2(A a) { |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | static int test5_1(A a, boolean b) { |
aoqi@0 | 259 | if (b) { |
aoqi@0 | 260 | test5_2(a); |
aoqi@0 | 261 | } else { |
aoqi@0 | 262 | A aa = (B)a; |
aoqi@0 | 263 | } |
aoqi@0 | 264 | // shouldn't inline |
aoqi@0 | 265 | return test5_invokevirtual(a); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | static boolean test5() { |
aoqi@0 | 269 | A a = new A(); |
aoqi@0 | 270 | B b = new B(); |
aoqi@0 | 271 | C c = new C(); |
aoqi@0 | 272 | |
aoqi@0 | 273 | // pollute profile at test3_invokevirtual and test3_1 to make |
aoqi@0 | 274 | // sure the compiler cannot rely on it |
aoqi@0 | 275 | for (int i = 0; i < 3000; i++) { |
aoqi@0 | 276 | test5_invokevirtual(a); |
aoqi@0 | 277 | test5_invokevirtual(b); |
aoqi@0 | 278 | test5_invokevirtual(c); |
aoqi@0 | 279 | } |
aoqi@0 | 280 | |
aoqi@0 | 281 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 282 | if ((i % 2) == 0) { |
aoqi@0 | 283 | int res = test5_1(a, true); |
aoqi@0 | 284 | if (res != a.m()) { |
aoqi@0 | 285 | System.out.println("test5 failed with class A"); |
aoqi@0 | 286 | return false; |
aoqi@0 | 287 | } |
aoqi@0 | 288 | } else { |
aoqi@0 | 289 | int res = test5_1(b, false); |
aoqi@0 | 290 | if (res != b.m()) { |
aoqi@0 | 291 | System.out.println("test5 failed with class B"); |
aoqi@0 | 292 | return false; |
aoqi@0 | 293 | } |
aoqi@0 | 294 | } |
aoqi@0 | 295 | } |
aoqi@0 | 296 | return true; |
aoqi@0 | 297 | } |
aoqi@0 | 298 | |
aoqi@0 | 299 | // Mix incompatible profiled types |
aoqi@0 | 300 | static void test6_2(Object o) { |
aoqi@0 | 301 | } |
aoqi@0 | 302 | |
aoqi@0 | 303 | static Object test6_1(Object o, boolean b) { |
aoqi@0 | 304 | if (b) { |
aoqi@0 | 305 | test6_2(o); |
aoqi@0 | 306 | } else { |
aoqi@0 | 307 | test6_2(o); |
aoqi@0 | 308 | } |
aoqi@0 | 309 | return o; |
aoqi@0 | 310 | } |
aoqi@0 | 311 | |
aoqi@0 | 312 | static boolean test6() { |
aoqi@0 | 313 | A a = new A(); |
aoqi@0 | 314 | A[] aa = new A[10]; |
aoqi@0 | 315 | |
aoqi@0 | 316 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 317 | if ((i % 2) == 0) { |
aoqi@0 | 318 | test6_1(a, true); |
aoqi@0 | 319 | } else { |
aoqi@0 | 320 | test6_1(aa, false); |
aoqi@0 | 321 | } |
aoqi@0 | 322 | } |
aoqi@0 | 323 | return true; |
aoqi@0 | 324 | } |
aoqi@0 | 325 | |
aoqi@0 | 326 | // Mix a profiled type with an incompatible type |
aoqi@0 | 327 | static void test7_2(Object o) { |
aoqi@0 | 328 | } |
aoqi@0 | 329 | |
aoqi@0 | 330 | static Object test7_1(Object o, boolean b) { |
aoqi@0 | 331 | if (b) { |
aoqi@0 | 332 | test7_2(o); |
aoqi@0 | 333 | } else { |
aoqi@0 | 334 | Object oo = (A[])o; |
aoqi@0 | 335 | } |
aoqi@0 | 336 | return o; |
aoqi@0 | 337 | } |
aoqi@0 | 338 | |
aoqi@0 | 339 | static boolean test7() { |
aoqi@0 | 340 | A a = new A(); |
aoqi@0 | 341 | A[] aa = new A[10]; |
aoqi@0 | 342 | |
aoqi@0 | 343 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 344 | if ((i % 2) == 0) { |
aoqi@0 | 345 | test7_1(a, true); |
aoqi@0 | 346 | } else { |
aoqi@0 | 347 | test7_1(aa, false); |
aoqi@0 | 348 | } |
aoqi@0 | 349 | } |
aoqi@0 | 350 | return true; |
aoqi@0 | 351 | } |
aoqi@0 | 352 | |
aoqi@0 | 353 | // Mix a profiled type with an interface |
aoqi@0 | 354 | static void test8_2(Object o) { |
aoqi@0 | 355 | } |
aoqi@0 | 356 | |
aoqi@0 | 357 | static I test8_1(Object o) { |
aoqi@0 | 358 | test8_2(o); |
aoqi@0 | 359 | return (I)o; |
aoqi@0 | 360 | } |
aoqi@0 | 361 | |
aoqi@0 | 362 | static boolean test8() { |
aoqi@0 | 363 | A a = new A(); |
aoqi@0 | 364 | B b = new B(); |
aoqi@0 | 365 | C c = new C(); |
aoqi@0 | 366 | |
aoqi@0 | 367 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 368 | test8_1(b); |
aoqi@0 | 369 | } |
aoqi@0 | 370 | return true; |
aoqi@0 | 371 | } |
aoqi@0 | 372 | |
aoqi@0 | 373 | // Mix a profiled type with a constant |
aoqi@0 | 374 | static void test9_2(Object o) { |
aoqi@0 | 375 | } |
aoqi@0 | 376 | |
aoqi@0 | 377 | static Object test9_1(Object o, boolean b) { |
aoqi@0 | 378 | Object oo; |
aoqi@0 | 379 | if (b) { |
aoqi@0 | 380 | test9_2(o); |
aoqi@0 | 381 | oo = o; |
aoqi@0 | 382 | } else { |
aoqi@0 | 383 | oo = "some string"; |
aoqi@0 | 384 | } |
aoqi@0 | 385 | return oo; |
aoqi@0 | 386 | } |
aoqi@0 | 387 | |
aoqi@0 | 388 | static boolean test9() { |
aoqi@0 | 389 | A a = new A(); |
aoqi@0 | 390 | |
aoqi@0 | 391 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 392 | if ((i % 2) == 0) { |
aoqi@0 | 393 | test9_1(a, true); |
aoqi@0 | 394 | } else { |
aoqi@0 | 395 | test9_1(a, false); |
aoqi@0 | 396 | } |
aoqi@0 | 397 | } |
aoqi@0 | 398 | return true; |
aoqi@0 | 399 | } |
aoqi@0 | 400 | |
aoqi@0 | 401 | // java/lang/Object:AnyNull:exact *,iid=top |
aoqi@0 | 402 | // meets |
aoqi@0 | 403 | // stable:bottom[int:max..0]:NotNull * |
aoqi@0 | 404 | static void test10_4(Object o) { |
aoqi@0 | 405 | } |
aoqi@0 | 406 | |
aoqi@0 | 407 | static void test10_3(Object o, boolean b) { |
aoqi@0 | 408 | if (b) { |
aoqi@0 | 409 | test10_4(o); |
aoqi@0 | 410 | } |
aoqi@0 | 411 | } |
aoqi@0 | 412 | |
aoqi@0 | 413 | static void test10_2(Object o, boolean b1, boolean b2) { |
aoqi@0 | 414 | if (b1) { |
aoqi@0 | 415 | test10_3(o, b2); |
aoqi@0 | 416 | } |
aoqi@0 | 417 | } |
aoqi@0 | 418 | |
aoqi@0 | 419 | static void test10_1(B[] b, boolean b1, boolean b2) { |
aoqi@0 | 420 | test10_2(b, b1, b2); |
aoqi@0 | 421 | } |
aoqi@0 | 422 | |
aoqi@0 | 423 | static boolean test10() { |
aoqi@0 | 424 | Object o = new Object(); |
aoqi@0 | 425 | A[] a = new A[10]; |
aoqi@0 | 426 | B[] b = new B[10]; |
aoqi@0 | 427 | B[] c = new C[10]; |
aoqi@0 | 428 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 429 | test10_1(b, false, false); |
aoqi@0 | 430 | test10_1(c, false, false); |
aoqi@0 | 431 | test10_2(a, true, false); |
aoqi@0 | 432 | test10_3(o, true); |
aoqi@0 | 433 | } |
aoqi@0 | 434 | return true; |
aoqi@0 | 435 | } |
aoqi@0 | 436 | |
aoqi@0 | 437 | // stable:TypeSpeculation$B:TopPTR *,iid=top[int:max..0]:TopPTR *,iid=top |
aoqi@0 | 438 | // meets |
aoqi@0 | 439 | // java/lang/Object:AnyNull:exact *,iid=top |
aoqi@0 | 440 | static void test11_3(Object o) { |
aoqi@0 | 441 | } |
aoqi@0 | 442 | |
aoqi@0 | 443 | static void test11_2(Object o, boolean b) { |
aoqi@0 | 444 | if (b) { |
aoqi@0 | 445 | test11_3(o); |
aoqi@0 | 446 | } |
aoqi@0 | 447 | } |
aoqi@0 | 448 | |
aoqi@0 | 449 | static void test11_1(B[] b, boolean bb) { |
aoqi@0 | 450 | test11_2(b, bb); |
aoqi@0 | 451 | } |
aoqi@0 | 452 | |
aoqi@0 | 453 | static boolean test11() { |
aoqi@0 | 454 | Object o = new Object(); |
aoqi@0 | 455 | B[] b = new B[10]; |
aoqi@0 | 456 | B[] c = new C[10]; |
aoqi@0 | 457 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 458 | test11_1(b, false); |
aoqi@0 | 459 | test11_1(c, false); |
aoqi@0 | 460 | test11_2(o, true); |
aoqi@0 | 461 | } |
aoqi@0 | 462 | return true; |
aoqi@0 | 463 | } |
aoqi@0 | 464 | |
aoqi@0 | 465 | // TypeSpeculation$I * |
aoqi@0 | 466 | // meets |
aoqi@0 | 467 | // java/lang/Object:AnyNull *,iid=top |
aoqi@0 | 468 | static void test12_3(Object o) { |
aoqi@0 | 469 | } |
aoqi@0 | 470 | |
aoqi@0 | 471 | static void test12_2(Object o, boolean b) { |
aoqi@0 | 472 | if (b) { |
aoqi@0 | 473 | test12_3(o); |
aoqi@0 | 474 | } |
aoqi@0 | 475 | } |
aoqi@0 | 476 | |
aoqi@0 | 477 | static void test12_1(I i, boolean b) { |
aoqi@0 | 478 | test12_2(i, b); |
aoqi@0 | 479 | } |
aoqi@0 | 480 | |
aoqi@0 | 481 | static boolean test12() { |
aoqi@0 | 482 | Object o = new Object(); |
aoqi@0 | 483 | B b = new B(); |
aoqi@0 | 484 | C c = new C(); |
aoqi@0 | 485 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 486 | test12_1(b, false); |
aoqi@0 | 487 | test12_1(c, false); |
aoqi@0 | 488 | test12_2(o, true); |
aoqi@0 | 489 | } |
aoqi@0 | 490 | return true; |
aoqi@0 | 491 | } |
aoqi@0 | 492 | |
aoqi@0 | 493 | // stable:bottom[int:max..0]:NotNull * |
aoqi@0 | 494 | // meets |
aoqi@0 | 495 | // stable:TypeSpeculation$A:TopPTR *,iid=top[int:max..0]:AnyNull:exact *,iid=top |
aoqi@0 | 496 | static Object test13_3(Object o, boolean b) { |
aoqi@0 | 497 | Object oo; |
aoqi@0 | 498 | if (b) { |
aoqi@0 | 499 | oo = o; |
aoqi@0 | 500 | } else { |
aoqi@0 | 501 | oo = new A[10]; |
aoqi@0 | 502 | } |
aoqi@0 | 503 | return oo; |
aoqi@0 | 504 | } |
aoqi@0 | 505 | |
aoqi@0 | 506 | static void test13_2(Object o, boolean b1, boolean b2) { |
aoqi@0 | 507 | if (b1) { |
aoqi@0 | 508 | test13_3(o, b2); |
aoqi@0 | 509 | } |
aoqi@0 | 510 | } |
aoqi@0 | 511 | |
aoqi@0 | 512 | static void test13_1(B[] b, boolean b1, boolean b2) { |
aoqi@0 | 513 | test13_2(b, b1, b2); |
aoqi@0 | 514 | } |
aoqi@0 | 515 | |
aoqi@0 | 516 | static boolean test13() { |
aoqi@0 | 517 | A[] a = new A[10]; |
aoqi@0 | 518 | B[] b = new B[10]; |
aoqi@0 | 519 | B[] c = new C[10]; |
aoqi@0 | 520 | for (int i = 0; i < 20000; i++) { |
aoqi@0 | 521 | test13_1(b, false, false); |
aoqi@0 | 522 | test13_1(c, false, false); |
aoqi@0 | 523 | test13_2(a, true, (i%2) == 0); |
aoqi@0 | 524 | } |
aoqi@0 | 525 | return true; |
aoqi@0 | 526 | } |
aoqi@0 | 527 | |
aoqi@0 | 528 | static public void main(String[] args) { |
aoqi@0 | 529 | boolean success = true; |
aoqi@0 | 530 | |
aoqi@0 | 531 | success = test1() && success; |
aoqi@0 | 532 | |
aoqi@0 | 533 | success = test2() && success; |
aoqi@0 | 534 | |
aoqi@0 | 535 | success = test3() && success; |
aoqi@0 | 536 | |
aoqi@0 | 537 | success = test4() && success; |
aoqi@0 | 538 | |
aoqi@0 | 539 | success = test5() && success; |
aoqi@0 | 540 | |
aoqi@0 | 541 | success = test6() && success; |
aoqi@0 | 542 | |
aoqi@0 | 543 | success = test7() && success; |
aoqi@0 | 544 | |
aoqi@0 | 545 | success = test8() && success; |
aoqi@0 | 546 | |
aoqi@0 | 547 | success = test9() && success; |
aoqi@0 | 548 | |
aoqi@0 | 549 | success = test10() && success; |
aoqi@0 | 550 | |
aoqi@0 | 551 | success = test11() && success; |
aoqi@0 | 552 | |
aoqi@0 | 553 | success = test12() && success; |
aoqi@0 | 554 | |
aoqi@0 | 555 | success = test13() && success; |
aoqi@0 | 556 | |
aoqi@0 | 557 | if (success) { |
aoqi@0 | 558 | System.out.println("TEST PASSED"); |
aoqi@0 | 559 | } else { |
aoqi@0 | 560 | throw new RuntimeException("TEST FAILED: erroneous bound check elimination"); |
aoqi@0 | 561 | } |
aoqi@0 | 562 | } |
aoqi@0 | 563 | } |