1 /* 2 * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package compiler.valhalla.inlinetypes; 25 26 import jdk.test.lib.Asserts; 27 import compiler.lib.ir_framework.*; 28 import static compiler.valhalla.inlinetypes.InlineTypes.rI; 29 import static compiler.valhalla.inlinetypes.InlineTypes.rL; 30 import static compiler.valhalla.inlinetypes.InlineTypes.rD; 31 import static compiler.valhalla.inlinetypes.InlineTypeIRNode.*; 32 33 import jdk.internal.value.ValueClass; 34 import jdk.internal.vm.annotation.ImplicitlyConstructible; 35 import jdk.internal.vm.annotation.LooselyConsistentValue; 36 import jdk.internal.vm.annotation.NullRestricted; 37 38 import java.lang.reflect.Method; 39 import java.util.Arrays; 40 41 /* 42 * @test 43 * @key randomness 44 * @summary Test nullable value class arrays. 45 * @library /test/lib / 46 * @requires (os.simpleArch == "x64" | os.simpleArch == "aarch64") 47 * @enablePreview 48 * @modules java.base/jdk.internal.value 49 * java.base/jdk.internal.vm.annotation 50 * @run main/othervm/timeout=300 compiler.valhalla.inlinetypes.TestNullableArrays 51 */ 52 53 @ForceCompileClassInitializer 54 public class TestNullableArrays { 55 56 public static void main(String[] args) { 57 58 Scenario[] scenarios = InlineTypes.DEFAULT_SCENARIOS; 59 scenarios[2].addFlags("-XX:-MonomorphicArrayCheck", "-XX:-UncommonNullCast", "-XX:+StressArrayCopyMacroNode"); 60 scenarios[3].addFlags("-XX:-MonomorphicArrayCheck", "-XX:-UncommonNullCast"); 61 scenarios[4].addFlags("-XX:-MonomorphicArrayCheck", "-XX:-UncommonNullCast"); 62 scenarios[5].addFlags("-XX:-MonomorphicArrayCheck", "-XX:-UncommonNullCast", "-XX:+StressArrayCopyMacroNode"); 63 64 InlineTypes.getFramework() 65 .addScenarios(scenarios) 66 .addHelperClasses(MyValue1.class, 67 MyValue2.class, 68 MyValue2Inline.class) 69 .start(); 70 } 71 72 static { 73 // Make sure RuntimeException is loaded to prevent uncommon traps in IR verified tests 74 RuntimeException tmp = new RuntimeException("42"); 75 } 76 77 // Helper methods 78 79 protected long hash() { 80 return hash(rI, rL); 81 } 82 83 protected long hash(int x, long y) { 84 return MyValue1.createWithFieldsInline(x, y).hash(); 85 } 86 87 private static final MyValue1 testValue1 = MyValue1.createWithFieldsInline(rI, rL); 88 89 // Test nullable value class array creation and initialization 90 @Test 91 @IR(applyIf = {"FlatArrayElementMaxSize", "= -1"}, 92 counts = {ALLOCA, "= 1"}) 93 @IR(applyIf = {"FlatArrayElementMaxSize", "!= -1"}, 94 counts = {ALLOCA, "= 1"}, 95 failOn = LOAD) 96 public MyValue1[] test1(int len) { 97 MyValue1[] va = new MyValue1[len]; 98 if (len > 0) { 99 va[0] = null; 100 } 101 for (int i = 1; i < len; ++i) { 102 va[i] = MyValue1.createWithFieldsDontInline(rI, rL); 103 } 104 return va; 105 } 106 107 @Run(test = "test1") 108 public void test1_verifier() { 109 int len = Math.abs(rI % 10); 110 MyValue1[] va = test1(len); 111 if (len > 0) { 112 Asserts.assertEQ(va[0], null); 113 } 114 for (int i = 1; i < len; ++i) { 115 Asserts.assertEQ(va[i].hash(), hash()); 116 } 117 } 118 119 // Test creation of a value class array and element access 120 @Test 121 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 122 public long test2() { 123 MyValue1[] va = new MyValue1[1]; 124 va[0] = MyValue1.createWithFieldsInline(rI, rL); 125 return va[0].hash(); 126 } 127 128 @Run(test = "test2") 129 public void test2_verifier() { 130 long result = test2(); 131 Asserts.assertEQ(result, hash()); 132 } 133 134 // Test receiving a value class array from the interpreter, 135 // updating its elements in a loop and computing a hash. 136 @Test 137 @IR(failOn = {ALLOCA}) 138 public long test3(MyValue1[] va) { 139 long result = 0; 140 for (int i = 0; i < 10; ++i) { 141 if (va[i] != null) { 142 result += va[i].hash(); 143 } 144 va[i] = MyValue1.createWithFieldsInline(rI + 1, rL + 1); 145 } 146 va[0] = null; 147 return result; 148 } 149 150 @Run(test = "test3") 151 public void test3_verifier() { 152 MyValue1[] va = new MyValue1[10]; 153 long expected = 0; 154 for (int i = 1; i < 10; ++i) { 155 va[i] = MyValue1.createWithFieldsDontInline(rI + i, rL + i); 156 expected += va[i].hash(); 157 } 158 long result = test3(va); 159 Asserts.assertEQ(expected, result); 160 Asserts.assertEQ(va[0], null); 161 for (int i = 1; i < 10; ++i) { 162 if (va[i].hash() != hash(rI + 1, rL + 1)) { 163 Asserts.assertEQ(va[i].hash(), hash(rI + 1, rL + 1)); 164 } 165 } 166 } 167 168 // Test returning a value class array received from the interpreter 169 @Test 170 @IR(failOn = {ALLOC, ALLOCA, LOAD, STORE, LOOP, TRAP}) 171 public MyValue1[] test4(MyValue1[] va) { 172 return va; 173 } 174 175 @Run(test = "test4") 176 public void test4_verifier() { 177 MyValue1[] va = new MyValue1[10]; 178 for (int i = 0; i < 10; ++i) { 179 va[i] = MyValue1.createWithFieldsDontInline(rI + i, rL + i); 180 } 181 va = test4(va); 182 for (int i = 0; i < 10; ++i) { 183 Asserts.assertEQ(va[i].hash(), hash(rI + i, rL + i)); 184 } 185 } 186 187 // Merge value class arrays created from two branches 188 @Test 189 public MyValue1[] test5(boolean b) { 190 MyValue1[] va; 191 if (b) { 192 va = new MyValue1[5]; 193 for (int i = 0; i < 5; ++i) { 194 va[i] = MyValue1.createWithFieldsInline(rI, rL); 195 } 196 va[4] = null; 197 } else { 198 va = new MyValue1[10]; 199 for (int i = 0; i < 10; ++i) { 200 va[i] = MyValue1.createWithFieldsInline(rI + i, rL + i); 201 } 202 va[9] = null; 203 } 204 long sum = va[0].hashInterpreted(); 205 if (b) { 206 va[0] = MyValue1.createWithFieldsDontInline(rI, sum); 207 } else { 208 va[0] = MyValue1.createWithFieldsDontInline(rI + 1, sum + 1); 209 } 210 return va; 211 } 212 213 @Run(test = "test5") 214 public void test5_verifier() { 215 MyValue1[] va = test5(true); 216 Asserts.assertEQ(va.length, 5); 217 Asserts.assertEQ(va[0].hash(), hash(rI, hash())); 218 for (int i = 1; i < 4; ++i) { 219 Asserts.assertEQ(va[i].hash(), hash()); 220 } 221 Asserts.assertEQ(va[4], null); 222 va = test5(false); 223 Asserts.assertEQ(va.length, 10); 224 Asserts.assertEQ(va[0].hash(), hash(rI + 1, hash(rI, rL) + 1)); 225 for (int i = 1; i < 9; ++i) { 226 Asserts.assertEQ(va[i].hash(), hash(rI + i, rL + i)); 227 } 228 Asserts.assertEQ(va[9], null); 229 } 230 231 // Test creation of value class array with single element 232 @Test 233 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 234 public MyValue1 test6() { 235 MyValue1[] va = new MyValue1[1]; 236 return va[0]; 237 } 238 239 @Run(test = "test6") 240 public void test6_verifier() { 241 MyValue1[] va = new MyValue1[1]; 242 MyValue1 v = test6(); 243 Asserts.assertEQ(v, null); 244 } 245 246 // Test default initialization of value class arrays 247 @Test 248 @IR(failOn = LOAD) 249 public MyValue1[] test7(int len) { 250 return new MyValue1[len]; 251 } 252 253 @Run(test = "test7") 254 public void test7_verifier() { 255 int len = Math.abs(rI % 10); 256 MyValue1[] va = test7(len); 257 for (int i = 0; i < len; ++i) { 258 Asserts.assertEQ(va[i], null); 259 va[i] = null; 260 } 261 } 262 263 // Test creation of value class array with zero length 264 @Test 265 @IR(failOn = {ALLOC, LOAD, STORE, LOOP, TRAP}) 266 public MyValue1[] test8() { 267 return new MyValue1[0]; 268 } 269 270 @Run(test = "test8") 271 public void test8_verifier() { 272 MyValue1[] va = test8(); 273 Asserts.assertEQ(va.length, 0); 274 } 275 276 static MyValue1[] test9_va; 277 278 // Test that value class array loaded from field has correct type 279 @Test 280 @IR(failOn = LOOP) 281 public long test9() { 282 return test9_va[0].hash(); 283 } 284 285 @Run(test = "test9") 286 public void test9_verifier() { 287 test9_va = new MyValue1[1]; 288 test9_va[0] = testValue1; 289 long result = test9(); 290 Asserts.assertEQ(result, hash()); 291 } 292 293 // Multi-dimensional arrays 294 @Test 295 public MyValue1[][][] test10(int len1, int len2, int len3) { 296 MyValue1[][][] arr = new MyValue1[len1][len2][len3]; 297 for (int i = 0; i < len1; i++) { 298 for (int j = 0; j < len2; j++) { 299 for (int k = 0; k < len3; k++) { 300 arr[i][j][k] = MyValue1.createWithFieldsDontInline(rI + i , rL + j + k); 301 if (k == 0) { 302 arr[i][j][k] = null; 303 } 304 } 305 } 306 } 307 return arr; 308 } 309 310 @Run(test = "test10") 311 public void test10_verifier() { 312 MyValue1[][][] arr = test10(2, 3, 4); 313 for (int i = 0; i < 2; i++) { 314 for (int j = 0; j < 3; j++) { 315 for (int k = 0; k < 4; k++) { 316 if (k == 0) { 317 Asserts.assertEQ(arr[i][j][k], null); 318 } else { 319 Asserts.assertEQ(arr[i][j][k].hash(), MyValue1.createWithFieldsDontInline(rI + i , rL + j + k).hash()); 320 } 321 arr[i][j][k] = null; 322 } 323 } 324 } 325 } 326 327 @Test 328 public void test11(MyValue1[][][] arr, long[] res) { 329 int l = 0; 330 for (int i = 0; i < arr.length; i++) { 331 for (int j = 0; j < arr[i].length; j++) { 332 for (int k = 0; k < arr[i][j].length; k++) { 333 if (arr[i][j][k] != null) { 334 res[l] = arr[i][j][k].hash(); 335 } 336 arr[i][j][k] = null; 337 l++; 338 } 339 } 340 } 341 } 342 343 @Run(test = "test11") 344 public void test11_verifier() { 345 MyValue1[][][] arr = new MyValue1[2][3][4]; 346 long[] res = new long[2*3*4]; 347 long[] verif = new long[2*3*4]; 348 int l = 0; 349 for (int i = 0; i < 2; i++) { 350 for (int j = 0; j < 3; j++) { 351 for (int k = 0; k < 4; k++) { 352 if (j != 2) { 353 arr[i][j][k] = MyValue1.createWithFieldsDontInline(rI + i, rL + j + k); 354 verif[l] = arr[i][j][k].hash(); 355 } 356 l++; 357 } 358 } 359 } 360 test11(arr, res); 361 for (int i = 0; i < verif.length; i++) { 362 Asserts.assertEQ(res[i], verif[i]); 363 } 364 } 365 366 // Array load out of bounds (upper bound) at compile time 367 @Test 368 public int test12() { 369 int arraySize = Math.abs(rI) % 10; 370 MyValue1[] va = new MyValue1[arraySize]; 371 372 for (int i = 0; i < arraySize; i++) { 373 va[i] = MyValue1.createWithFieldsDontInline(rI + 1, rL); 374 } 375 376 try { 377 return va[arraySize + 1].x; 378 } catch (ArrayIndexOutOfBoundsException e) { 379 return rI; 380 } 381 } 382 383 @Run(test = "test12") 384 public void test12_verifier() { 385 Asserts.assertEQ(test12(), rI); 386 } 387 388 // Array load out of bounds (lower bound) at compile time 389 @Test 390 public int test13() { 391 int arraySize = Math.abs(rI) % 10; 392 MyValue1[] va = new MyValue1[arraySize]; 393 394 for (int i = 0; i < arraySize; i++) { 395 va[i] = MyValue1.createWithFieldsDontInline(rI + i, rL); 396 } 397 398 try { 399 return va[-arraySize].x; 400 } catch (ArrayIndexOutOfBoundsException e) { 401 return rI; 402 } 403 } 404 405 @Run(test = "test13") 406 public void test13_verifier() { 407 Asserts.assertEQ(test13(), rI); 408 } 409 410 // Array load out of bound not known to compiler (both lower and upper bound) 411 @Test 412 public int test14(MyValue1[] va, int index) { 413 return va[index].x; 414 } 415 416 @Run(test = "test14") 417 public void test14_verifier() { 418 int arraySize = Math.abs(rI) % 10; 419 MyValue1[] va = new MyValue1[arraySize]; 420 421 for (int i = 0; i < arraySize; i++) { 422 va[i] = MyValue1.createWithFieldsDontInline(rI, rL); 423 } 424 425 int result; 426 for (int i = -20; i < 20; i++) { 427 try { 428 result = test14(va, i); 429 } catch (ArrayIndexOutOfBoundsException e) { 430 result = rI; 431 } 432 Asserts.assertEQ(result, rI); 433 } 434 } 435 436 // Array store out of bounds (upper bound) at compile time 437 @Test 438 public int test15() { 439 int arraySize = Math.abs(rI) % 10; 440 MyValue1[] va = new MyValue1[arraySize]; 441 442 try { 443 for (int i = 0; i <= arraySize; i++) { 444 va[i] = MyValue1.createWithFieldsDontInline(rI + 1, rL); 445 } 446 return rI - 1; 447 } catch (ArrayIndexOutOfBoundsException e) { 448 return rI; 449 } 450 } 451 452 @Run(test = "test15") 453 public void test15_verifier() { 454 Asserts.assertEQ(test15(), rI); 455 } 456 457 // Array store out of bounds (lower bound) at compile time 458 @Test 459 public int test16() { 460 int arraySize = Math.abs(rI) % 10; 461 MyValue1[] va = new MyValue1[arraySize]; 462 463 try { 464 for (int i = -1; i <= arraySize; i++) { 465 va[i] = MyValue1.createWithFieldsDontInline(rI + 1, rL); 466 } 467 return rI - 1; 468 } catch (ArrayIndexOutOfBoundsException e) { 469 return rI; 470 } 471 } 472 473 @Run(test = "test16") 474 public void test16_verifier() { 475 Asserts.assertEQ(test16(), rI); 476 } 477 478 // Array store out of bound not known to compiler (both lower and upper bound) 479 @Test 480 public int test17(MyValue1[] va, int index, MyValue1 vt) { 481 va[index] = vt; 482 return va[index].x; 483 } 484 485 @Run(test = "test17") 486 public void test17_verifier() { 487 int arraySize = Math.abs(rI) % 10; 488 MyValue1[] va = new MyValue1[arraySize]; 489 490 for (int i = 0; i < arraySize; i++) { 491 va[i] = MyValue1.createWithFieldsDontInline(rI, rL); 492 } 493 494 MyValue1 vt = MyValue1.createWithFieldsDontInline(rI + 1, rL); 495 int result; 496 for (int i = -20; i < 20; i++) { 497 try { 498 result = test17(va, i, vt); 499 } catch (ArrayIndexOutOfBoundsException e) { 500 result = rI + 1; 501 } 502 Asserts.assertEQ(result, rI + 1); 503 } 504 505 for (int i = 0; i < arraySize; i++) { 506 Asserts.assertEQ(va[i].x, rI + 1); 507 } 508 } 509 510 // clone() as stub call 511 @Test 512 public MyValue1[] test18(MyValue1[] va) { 513 return va.clone(); 514 } 515 516 @Run(test = "test18") 517 public void test18_verifier(RunInfo info) { 518 int len = Math.abs(rI) % 10; 519 MyValue1[] va1 = new MyValue1[len]; 520 MyValue1[] va2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 521 for (int i = 1; i < len; ++i) { 522 va1[i] = testValue1; 523 va2[i] = testValue1; 524 } 525 MyValue1[] result1 = test18(va1); 526 if (len > 0) { 527 Asserts.assertEQ(result1[0], null); 528 } 529 for (int i = 1; i < len; ++i) { 530 Asserts.assertEQ(result1[i].hash(), va1[i].hash()); 531 } 532 // make sure we do deopt: GraphKit::new_array assumes an 533 // array of references 534 for (int j = 0; j < 10; j++) { 535 MyValue1[] result2 = test18(va2); 536 537 for (int i = 0; i < len; ++i) { 538 Asserts.assertEQ(result2[i].hash(), va2[i].hash()); 539 } 540 } 541 if (compile_and_run_again_if_deoptimized(info)) { 542 MyValue1[] result2 = test18(va2); 543 for (int i = 0; i < len; ++i) { 544 Asserts.assertEQ(result2[i].hash(), va2[i].hash()); 545 } 546 } 547 } 548 549 // clone() as series of loads/stores 550 static MyValue1[] test19_orig = null; 551 552 @Test 553 public MyValue1[] test19() { 554 MyValue1[] va = new MyValue1[8]; 555 for (int i = 1; i < va.length; ++i) { 556 va[i] = MyValue1.createWithFieldsInline(rI, rL); 557 } 558 test19_orig = va; 559 560 return va.clone(); 561 } 562 563 @Run(test = "test19") 564 public void test19_verifier() { 565 MyValue1[] result = test19(); 566 Asserts.assertEQ(result[0], null); 567 for (int i = 1; i < test19_orig.length; ++i) { 568 Asserts.assertEQ(result[i].hash(), test19_orig[i].hash()); 569 } 570 } 571 572 // arraycopy() of value class array with oop fields 573 @Test 574 public void test20(MyValue1[] src, MyValue1[] dst) { 575 System.arraycopy(src, 0, dst, 0, src.length); 576 } 577 578 @Run(test = "test20") 579 public void test20_verifier() { 580 int len = Math.abs(rI) % 10; 581 MyValue1[] src1 = new MyValue1[len]; 582 MyValue1[] src2 = new MyValue1[len]; 583 MyValue1[] src3 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 584 MyValue1[] src4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 585 MyValue1[] dst1 = new MyValue1[len]; 586 MyValue1[] dst2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 587 MyValue1[] dst3 = new MyValue1[len]; 588 MyValue1[] dst4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 589 if (len > 0) { 590 src2[0] = testValue1; 591 } 592 for (int i = 1; i < len; ++i) { 593 src1[i] = testValue1; 594 src2[i] = testValue1; 595 src3[i] = testValue1; 596 src4[i] = testValue1; 597 } 598 test20(src1, dst1); 599 test20(src2, dst2); 600 test20(src3, dst3); 601 test20(src4, dst4); 602 if (len > 0) { 603 Asserts.assertEQ(dst1[0], null); 604 Asserts.assertEQ(dst2[0].hash(), src2[0].hash()); 605 Asserts.assertEQ(dst3[0].hash(), src3[0].hash()); 606 Asserts.assertEQ(dst4[0].hash(), src4[0].hash()); 607 } 608 for (int i = 1; i < len; ++i) { 609 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 610 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 611 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 612 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 613 } 614 } 615 616 // arraycopy() of value class array with no oop field 617 @Test 618 public void test21(MyValue2[] src, MyValue2[] dst) { 619 System.arraycopy(src, 0, dst, 0, src.length); 620 } 621 622 @Run(test = "test21") 623 public void test21_verifier() { 624 int len = Math.abs(rI) % 10; 625 MyValue2[] src1 = new MyValue2[len]; 626 MyValue2[] src2 = new MyValue2[len]; 627 MyValue2[] src3 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, len); 628 MyValue2[] src4 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, len); 629 MyValue2[] dst1 = new MyValue2[len]; 630 MyValue2[] dst2 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, len); 631 MyValue2[] dst3 = new MyValue2[len]; 632 MyValue2[] dst4 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, len); 633 if (len > 0) { 634 src2[0] = MyValue2.createWithFieldsInline(rI, rD); 635 } 636 for (int i = 1; i < len; ++i) { 637 src1[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 638 src2[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 639 src3[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 640 src4[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 641 } 642 test21(src1, dst1); 643 test21(src2, dst2); 644 test21(src3, dst3); 645 test21(src4, dst4); 646 if (len > 0) { 647 Asserts.assertEQ(dst1[0], null); 648 Asserts.assertEQ(dst2[0].hash(), src2[0].hash()); 649 Asserts.assertEQ(dst3[0].hash(), src3[0].hash()); 650 Asserts.assertEQ(dst4[0].hash(), src4[0].hash()); 651 } 652 for (int i = 1; i < len; ++i) { 653 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 654 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 655 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 656 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 657 } 658 } 659 660 // arraycopy() of value class array with oop field and tightly 661 // coupled allocation as dest 662 @Test 663 public MyValue1[] test22(MyValue1[] src) { 664 MyValue1[] dst = new MyValue1[src.length]; 665 System.arraycopy(src, 0, dst, 0, src.length); 666 return dst; 667 } 668 669 @Run(test = "test22") 670 public void test22_verifier() { 671 int len = Math.abs(rI) % 10; 672 MyValue1[] src1 = new MyValue1[len]; 673 MyValue1[] src2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 674 for (int i = 1; i < len; ++i) { 675 src1[i] = testValue1; 676 src2[i] = testValue1; 677 } 678 MyValue1[] dst1 = test22(src1); 679 MyValue1[] dst2 = test22(src2); 680 if (len > 0) { 681 Asserts.assertEQ(dst1[0], null); 682 Asserts.assertEQ(dst2[0].hash(), MyValue1.createDefaultInline().hash()); 683 } 684 for (int i = 1; i < len; ++i) { 685 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 686 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 687 } 688 } 689 690 // arraycopy() of value class array with oop fields and tightly 691 // coupled allocation as dest 692 @Test 693 public MyValue1[] test23(MyValue1[] src) { 694 MyValue1[] dst = new MyValue1[src.length + 10]; 695 System.arraycopy(src, 0, dst, 5, src.length); 696 return dst; 697 } 698 699 @Run(test = "test23") 700 public void test23_verifier() { 701 int len = Math.abs(rI) % 10; 702 MyValue1[] src1 = new MyValue1[len]; 703 MyValue1[] src2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 704 for (int i = 0; i < len; ++i) { 705 src1[i] = testValue1; 706 src2[i] = testValue1; 707 } 708 MyValue1[] dst1 = test23(src1); 709 MyValue1[] dst2 = test23(src2); 710 for (int i = 0; i < 5; ++i) { 711 Asserts.assertEQ(dst1[i], null); 712 Asserts.assertEQ(dst2[i], null); 713 } 714 for (int i = 5; i < len; ++i) { 715 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 716 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 717 } 718 } 719 720 // arraycopy() of value class array passed as Object 721 @Test 722 public void test24(MyValue1[] src, Object dst) { 723 System.arraycopy(src, 0, dst, 0, src.length); 724 } 725 726 @Run(test = "test24") 727 public void test24_verifier() { 728 int len = Math.abs(rI) % 10; 729 MyValue1[] src1 = new MyValue1[len]; 730 MyValue1[] src2 = new MyValue1[len]; 731 MyValue1[] src3 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 732 MyValue1[] src4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 733 MyValue1[] dst1 = new MyValue1[len]; 734 MyValue1[] dst2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 735 MyValue1[] dst3 = new MyValue1[len]; 736 MyValue1[] dst4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 737 if (len > 0) { 738 src2[0] = testValue1; 739 } 740 for (int i = 1; i < len; ++i) { 741 src1[i] = testValue1; 742 src2[i] = testValue1; 743 src3[i] = testValue1; 744 src4[i] = testValue1; 745 } 746 test24(src1, dst1); 747 test24(src2, dst2); 748 test24(src3, dst3); 749 test24(src4, dst4); 750 if (len > 0) { 751 Asserts.assertEQ(dst1[0], null); 752 Asserts.assertEQ(dst2[0].hash(), src2[0].hash()); 753 Asserts.assertEQ(dst3[0].hash(), src3[0].hash()); 754 Asserts.assertEQ(dst4[0].hash(), src4[0].hash()); 755 } 756 for (int i = 1; i < len; ++i) { 757 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 758 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 759 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 760 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 761 } 762 } 763 764 // short arraycopy() with no oop field 765 @Test 766 public void test25(MyValue2[] src, MyValue2[] dst) { 767 System.arraycopy(src, 0, dst, 0, 8); 768 } 769 770 @Run(test = "test25") 771 public void test25_verifier() { 772 MyValue2[] src1 = new MyValue2[8]; 773 MyValue2[] src2 = new MyValue2[8]; 774 MyValue2[] src3 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 8); 775 MyValue2[] src4 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 8); 776 MyValue2[] dst1 = new MyValue2[8]; 777 MyValue2[] dst2 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 8); 778 MyValue2[] dst3 = new MyValue2[8]; 779 MyValue2[] dst4 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 8); 780 src2[0] = MyValue2.createWithFieldsInline(rI, rD); 781 for (int i = 1; i < 8; ++i) { 782 src1[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 783 src2[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 784 src3[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 785 src4[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 786 } 787 test25(src1, dst1); 788 test25(src2, dst2); 789 test25(src3, dst3); 790 test25(src4, dst4); 791 Asserts.assertEQ(dst1[0], null); 792 Asserts.assertEQ(dst2[0].hash(), src2[0].hash()); 793 Asserts.assertEQ(dst3[0].hash(), src3[0].hash()); 794 Asserts.assertEQ(dst4[0].hash(), src4[0].hash()); 795 for (int i = 1; i < 8; ++i) { 796 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 797 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 798 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 799 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 800 } 801 } 802 803 // short arraycopy() with oop fields 804 @Test 805 public void test26(MyValue1[] src, MyValue1[] dst) { 806 System.arraycopy(src, 0, dst, 0, 8); 807 } 808 809 @Run(test = "test26") 810 public void test26_verifier() { 811 MyValue1[] src1 = new MyValue1[8]; 812 MyValue1[] src2 = new MyValue1[8]; 813 MyValue1[] src3 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 814 MyValue1[] src4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 815 MyValue1[] dst1 = new MyValue1[8]; 816 MyValue1[] dst2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 817 MyValue1[] dst3 = new MyValue1[8]; 818 MyValue1[] dst4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 819 src2[0] = testValue1; 820 for (int i = 1; i < 8; ++i) { 821 src1[i] = testValue1; 822 src2[i] = testValue1; 823 src3[i] = testValue1; 824 src4[i] = testValue1; 825 } 826 test26(src1, dst1); 827 test26(src2, dst2); 828 test26(src3, dst3); 829 test26(src4, dst4); 830 Asserts.assertEQ(dst1[0], null); 831 Asserts.assertEQ(dst2[0].hash(), src2[0].hash()); 832 Asserts.assertEQ(dst3[0].hash(), src3[0].hash()); 833 Asserts.assertEQ(dst4[0].hash(), src4[0].hash()); 834 for (int i = 1; i < 8; ++i) { 835 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 836 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 837 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 838 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 839 } 840 } 841 842 // short arraycopy() with oop fields and offsets 843 @Test 844 public void test27(MyValue1[] src, MyValue1[] dst) { 845 System.arraycopy(src, 1, dst, 2, 6); 846 } 847 848 @Run(test = "test27") 849 public void test27_verifier() { 850 MyValue1[] src1 = new MyValue1[8]; 851 MyValue1[] src2 = new MyValue1[8]; 852 MyValue1[] src3 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 853 MyValue1[] src4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 854 MyValue1[] dst1 = new MyValue1[8]; 855 MyValue1[] dst2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 856 MyValue1[] dst3 = new MyValue1[8]; 857 MyValue1[] dst4 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 858 for (int i = 1; i < 8; ++i) { 859 src1[i] = testValue1; 860 src2[i] = testValue1; 861 src3[i] = testValue1; 862 src4[i] = testValue1; 863 } 864 test27(src1, dst1); 865 test27(src2, dst2); 866 test27(src3, dst3); 867 test27(src4, dst4); 868 for (int i = 0; i < 2; ++i) { 869 Asserts.assertEQ(dst1[i], null); 870 Asserts.assertEQ(dst2[i].hash(), MyValue1.createDefaultInline().hash()); 871 Asserts.assertEQ(dst3[i], null); 872 Asserts.assertEQ(dst4[i].hash(), MyValue1.createDefaultInline().hash()); 873 } 874 for (int i = 2; i < 8; ++i) { 875 Asserts.assertEQ(src1[i].hash(), dst1[i].hash()); 876 Asserts.assertEQ(src2[i].hash(), dst2[i].hash()); 877 Asserts.assertEQ(src3[i].hash(), dst3[i].hash()); 878 Asserts.assertEQ(src4[i].hash(), dst4[i].hash()); 879 } 880 } 881 882 // non escaping allocations 883 // TODO 8252027: Make sure this is optimized with ZGC 884 @Test 885 @IR(applyIf = {"UseZGC", "false"}, 886 failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 887 public MyValue2 test28() { 888 MyValue2[] src = new MyValue2[10]; 889 src[0] = null; 890 MyValue2[] dst = (MyValue2[])src.clone(); 891 return dst[0]; 892 } 893 894 @Run(test = "test28") 895 public void test28_verifier() { 896 MyValue2 v = MyValue2.createWithFieldsInline(rI, rD); 897 MyValue2 result = test28(); 898 Asserts.assertEQ(result, null); 899 } 900 901 // non escaping allocations 902 // TODO 8227588: shouldn't this have the same IR matching rules as test6? 903 @Test 904 @IR(failOn = {ALLOCA, LOOP, TRAP}) 905 public MyValue2 test29(MyValue2[] src) { 906 MyValue2[] dst = new MyValue2[10]; 907 System.arraycopy(src, 0, dst, 0, 10); 908 return dst[0]; 909 } 910 911 @Run(test = "test29") 912 public void test29_verifier(RunInfo info) { 913 MyValue2[] src1 = new MyValue2[10]; 914 MyValue2[] src2 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 10); 915 for (int i = 0; i < 10; ++i) { 916 src1[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 917 src2[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 918 } 919 MyValue2 v = test29(src1); 920 Asserts.assertEQ(src1[0].hash(), v.hash()); 921 if (!info.isWarmUp()) { 922 v = test29(src2); 923 Asserts.assertEQ(src2[0].hash(), v.hash()); 924 } 925 } 926 927 // non escaping allocation with uncommon trap that needs 928 // eliminated value class array element as debug info 929 @Test 930 public MyValue2 test30(MyValue2[] src, boolean flag) { 931 MyValue2[] dst = new MyValue2[10]; 932 System.arraycopy(src, 0, dst, 0, 10); 933 if (flag) { } 934 return dst[0]; 935 } 936 937 @Run(test = "test30") 938 @Warmup(10000) 939 public void test30_verifier(RunInfo info) { 940 MyValue2[] src1 = new MyValue2[10]; 941 MyValue2[] src2 = (MyValue2[])ValueClass.newNullRestrictedArray(MyValue2.class, 10); 942 for (int i = 0; i < 10; ++i) { 943 src1[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 944 src2[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 945 } 946 MyValue2 v = test30(src1, !info.isWarmUp()); 947 Asserts.assertEQ(src1[0].hash(), v.hash()); 948 if (!info.isWarmUp()) { 949 v = test30(src2, true); 950 Asserts.assertEQ(src2[0].hash(), v.hash()); 951 } 952 } 953 954 // non escaping allocation with memory phi 955 @Test 956 // TODO 8227588 957 // @Test(failOn = ALLOC + ALLOCA + LOOP + LOAD + STORE + TRAP) 958 public long test31(boolean b, boolean deopt, Method m) { 959 MyValue2[] src = new MyValue2[1]; 960 if (b) { 961 src[0] = MyValue2.createWithFieldsInline(rI, rD); 962 } else { 963 src[0] = MyValue2.createWithFieldsInline(rI+1, rD+1); 964 } 965 if (deopt) { 966 // uncommon trap 967 TestFramework.deoptimize(m); 968 } 969 return src[0].hash(); 970 } 971 972 @Run(test = "test31") 973 public void test31_verifier(RunInfo info) { 974 MyValue2 v1 = MyValue2.createWithFieldsInline(rI, rD); 975 long result1 = test31(true, !info.isWarmUp(), info.getTest()); 976 Asserts.assertEQ(result1, v1.hash()); 977 MyValue2 v2 = MyValue2.createWithFieldsInline(rI+1, rD+1); 978 long result2 = test31(false, !info.isWarmUp(), info.getTest()); 979 Asserts.assertEQ(result2, v2.hash()); 980 } 981 982 // Tests with Object arrays and clone/arraycopy 983 // clone() as stub call 984 @Test 985 public Object[] test32(Object[] va) { 986 return va.clone(); 987 } 988 989 @Run(test = "test32") 990 public void test32_verifier() { 991 int len = Math.abs(rI) % 10; 992 MyValue1[] va1 = new MyValue1[len]; 993 MyValue1[] va2 = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, len); 994 for (int i = 1; i < len; ++i) { 995 va1[i] = testValue1; 996 va2[i] = testValue1; 997 } 998 MyValue1[] result1 = (MyValue1[])test32(va1); 999 MyValue1[] result2 = (MyValue1[])test32(va2); 1000 if (len > 0) { 1001 Asserts.assertEQ(result1[0], null); 1002 Asserts.assertEQ(result2[0].hash(), MyValue1.createDefaultInline().hash()); 1003 } 1004 for (int i = 1; i < len; ++i) { 1005 Asserts.assertEQ(((MyValue1)result1[i]).hash(), ((MyValue1)va1[i]).hash()); 1006 Asserts.assertEQ(((MyValue1)result2[i]).hash(), ((MyValue1)va2[i]).hash()); 1007 } 1008 } 1009 1010 @Test 1011 public Object[] test33(Object[] va) { 1012 return va.clone(); 1013 } 1014 1015 @Run(test = "test33") 1016 public void test33_verifier() { 1017 int len = Math.abs(rI) % 10; 1018 Object[] va = new Object[len]; 1019 for (int i = 0; i < len; ++i) { 1020 va[i] = testValue1; 1021 } 1022 Object[] result = test33(va); 1023 for (int i = 0; i < len; ++i) { 1024 Asserts.assertEQ(((MyValue1)result[i]).hash(), ((MyValue1)va[i]).hash()); 1025 } 1026 } 1027 1028 // clone() as series of loads/stores 1029 static Object[] test34_orig = null; 1030 1031 @ForceInline 1032 public Object[] test34_helper(boolean flag) { 1033 Object[] va = null; 1034 if (flag) { 1035 va = new MyValue1[8]; 1036 for (int i = 0; i < va.length; ++i) { 1037 va[i] = MyValue1.createWithFieldsDontInline(rI, rL); 1038 } 1039 } else { 1040 va = new Object[8]; 1041 } 1042 return va; 1043 } 1044 1045 @Test 1046 public Object[] test34(boolean flag) { 1047 Object[] va = test34_helper(flag); 1048 test34_orig = va; 1049 return va.clone(); 1050 } 1051 1052 @Run(test = "test34") 1053 public void test34_verifier(RunInfo info) { 1054 test34(false); 1055 for (int i = 0; i < 10; i++) { // make sure we do deopt 1056 Object[] result = test34(true); 1057 verify(test34_orig, result); 1058 } 1059 if (compile_and_run_again_if_deoptimized(info)) { 1060 Object[] result = test34(true); 1061 verify(test34_orig, result); 1062 } 1063 } 1064 1065 static void verify(Object[] src, Object[] dst) { 1066 for (int i = 0; i < src.length; ++i) { 1067 if (src[i] != null) { 1068 Asserts.assertEQ(((MyInterface)src[i]).hash(), ((MyInterface)dst[i]).hash()); 1069 } else { 1070 Asserts.assertEQ(dst[i], null); 1071 } 1072 } 1073 } 1074 1075 static void verify(MyValue1[] src, MyValue1[] dst) { 1076 for (int i = 0; i < src.length; ++i) { 1077 if (src[i] != null) { 1078 Asserts.assertEQ(src[i].hash(), dst[i].hash()); 1079 } else { 1080 Asserts.assertEQ(dst[i], null); 1081 } 1082 } 1083 } 1084 1085 static void verify(MyValue1[] src, Object[] dst) { 1086 for (int i = 0; i < src.length; ++i) { 1087 if (src[i] != null) { 1088 Asserts.assertEQ(src[i].hash(), ((MyInterface)dst[i]).hash()); 1089 } else { 1090 Asserts.assertEQ(dst[i], null); 1091 } 1092 } 1093 } 1094 1095 static void verify(MyValue2[] src, MyValue2[] dst) { 1096 for (int i = 0; i < src.length; ++i) { 1097 if (src[i] != null) { 1098 Asserts.assertEQ(src[i].hash(), dst[i].hash()); 1099 } else { 1100 Asserts.assertEQ(dst[i], null); 1101 } 1102 } 1103 } 1104 1105 static void verify(MyValue2[] src, Object[] dst) { 1106 for (int i = 0; i < src.length; ++i) { 1107 if (src[i] != null) { 1108 Asserts.assertEQ(src[i].hash(), ((MyInterface)dst[i]).hash()); 1109 } else { 1110 Asserts.assertEQ(dst[i], null); 1111 } 1112 } 1113 } 1114 1115 static boolean compile_and_run_again_if_deoptimized(RunInfo info) { 1116 if (!info.isWarmUp()) { 1117 Method m = info.getTest(); 1118 if (TestFramework.isCompiled(m)) { 1119 TestFramework.compile(m, CompLevel.C2); 1120 } 1121 } 1122 return false; 1123 } 1124 1125 // arraycopy() of value class array of unknown size 1126 @Test 1127 public void test35(Object src, Object dst, int len) { 1128 System.arraycopy(src, 0, dst, 0, len); 1129 } 1130 1131 @Run(test = "test35") 1132 public void test35_verifier(RunInfo info) { 1133 int len = Math.abs(rI) % 10; 1134 MyValue1[] src = new MyValue1[len]; 1135 MyValue1[] dst = new MyValue1[len]; 1136 for (int i = 1; i < len; ++i) { 1137 src[i] = testValue1; 1138 } 1139 test35(src, dst, src.length); 1140 verify(src, dst); 1141 if (compile_and_run_again_if_deoptimized(info)) { 1142 test35(src, dst, src.length); 1143 verify(src, dst); 1144 } 1145 } 1146 1147 @Test 1148 public void test36(Object src, MyValue2[] dst) { 1149 System.arraycopy(src, 0, dst, 0, dst.length); 1150 } 1151 1152 @Run(test = "test36") 1153 public void test36_verifier(RunInfo info) { 1154 int len = Math.abs(rI) % 10; 1155 MyValue2[] src = new MyValue2[len]; 1156 MyValue2[] dst = new MyValue2[len]; 1157 for (int i = 1; i < len; ++i) { 1158 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1159 } 1160 test36(src, dst); 1161 verify(src, dst); 1162 if (compile_and_run_again_if_deoptimized(info)) { 1163 test36(src, dst); 1164 verify(src, dst); 1165 } 1166 } 1167 1168 @Test 1169 public void test37(MyValue2[] src, Object dst) { 1170 System.arraycopy(src, 0, dst, 0, src.length); 1171 } 1172 1173 @Run(test = "test37") 1174 public void test37_verifier(RunInfo info) { 1175 int len = Math.abs(rI) % 10; 1176 MyValue2[] src = new MyValue2[len]; 1177 MyValue2[] dst = new MyValue2[len]; 1178 for (int i = 1; i < len; ++i) { 1179 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1180 } 1181 test37(src, dst); 1182 verify(src, dst); 1183 if (compile_and_run_again_if_deoptimized(info)) { 1184 test37(src, dst); 1185 verify(src, dst); 1186 } 1187 } 1188 1189 @Test 1190 public void test38(Object src, MyValue2[] dst) { 1191 System.arraycopy(src, 0, dst, 0, dst.length); 1192 } 1193 1194 @Run(test = "test38") 1195 @Warmup(1) // Avoid early compilation 1196 public void test38_verifier(RunInfo info) { 1197 int len = Math.abs(rI) % 10; 1198 Object[] src = new Object[len]; 1199 MyValue2[] dst = new MyValue2[len]; 1200 for (int i = 1; i < len; ++i) { 1201 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1202 } 1203 test38(src, dst); 1204 verify(dst, src); 1205 if (!info.isWarmUp()) { 1206 Method m = info.getTest(); 1207 TestFramework.assertDeoptimizedByC2(m); 1208 TestFramework.compile(m, CompLevel.C2); 1209 test38(src, dst); 1210 verify(dst, src); 1211 TestFramework.assertCompiled(m); 1212 } 1213 } 1214 1215 @Test 1216 public void test39(MyValue2[] src, Object dst) { 1217 System.arraycopy(src, 0, dst, 0, src.length); 1218 } 1219 1220 @Run(test = "test39") 1221 public void test39_verifier(RunInfo info) { 1222 int len = Math.abs(rI) % 10; 1223 MyValue2[] src = new MyValue2[len]; 1224 Object[] dst = new Object[len]; 1225 for (int i = 1; i < len; ++i) { 1226 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1227 } 1228 test39(src, dst); 1229 verify(src, dst); 1230 if (compile_and_run_again_if_deoptimized(info)) { 1231 test39(src, dst); 1232 verify(src, dst); 1233 } 1234 } 1235 1236 @Test 1237 public void test40(Object[] src, Object dst) { 1238 System.arraycopy(src, 0, dst, 0, src.length); 1239 } 1240 1241 @Run(test = "test40") 1242 @Warmup(1) // Avoid early compilation 1243 public void test40_verifier(RunInfo info) { 1244 int len = Math.abs(rI) % 10; 1245 Object[] src = new Object[len]; 1246 MyValue2[] dst = new MyValue2[len]; 1247 for (int i = 1; i < len; ++i) { 1248 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1249 } 1250 test40(src, dst); 1251 verify(dst, src); 1252 if (!info.isWarmUp()) { 1253 Method m = info.getTest(); 1254 TestFramework.assertDeoptimizedByC2(m); 1255 TestFramework.compile(m, CompLevel.C2); 1256 test40(src, dst); 1257 verify(dst, src); 1258 TestFramework.assertCompiled(m); 1259 } 1260 } 1261 1262 @Test 1263 public void test41(Object src, Object[] dst) { 1264 System.arraycopy(src, 0, dst, 0, dst.length); 1265 } 1266 1267 @Run(test = "test41") 1268 public void test41_verifier(RunInfo info) { 1269 int len = Math.abs(rI) % 10; 1270 MyValue2[] src = new MyValue2[len]; 1271 Object[] dst = new Object[len]; 1272 for (int i = 1; i < len; ++i) { 1273 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1274 } 1275 test41(src, dst); 1276 verify(src, dst); 1277 if (compile_and_run_again_if_deoptimized(info)) { 1278 test41(src, dst); 1279 verify(src, dst); 1280 } 1281 } 1282 1283 @Test 1284 public void test42(Object[] src, Object[] dst) { 1285 System.arraycopy(src, 0, dst, 0, src.length); 1286 } 1287 1288 @Run(test = "test42") 1289 public void test42_verifier(RunInfo info) { 1290 int len = Math.abs(rI) % 10; 1291 Object[] src = new Object[len]; 1292 Object[] dst = new Object[len]; 1293 for (int i = 1; i < len; ++i) { 1294 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1295 } 1296 test42(src, dst); 1297 verify(src, dst); 1298 if (!info.isWarmUp()) { 1299 Method m = info.getTest(); 1300 TestFramework.assertCompiled(m); 1301 } 1302 } 1303 1304 // short arraycopy()'s 1305 @Test 1306 public void test43(Object src, Object dst) { 1307 System.arraycopy(src, 0, dst, 0, 8); 1308 } 1309 1310 @Run(test = "test43") 1311 public void test43_verifier(RunInfo info) { 1312 MyValue1[] src = new MyValue1[8]; 1313 MyValue1[] dst = new MyValue1[8]; 1314 for (int i = 1; i < 8; ++i) { 1315 src[i] = testValue1; 1316 } 1317 test43(src, dst); 1318 verify(src, dst); 1319 if (compile_and_run_again_if_deoptimized(info)) { 1320 test43(src, dst); 1321 verify(src, dst); 1322 } 1323 } 1324 1325 @Test 1326 public void test44(Object src, MyValue2[] dst) { 1327 System.arraycopy(src, 0, dst, 0, 8); 1328 } 1329 1330 @Run(test = "test44") 1331 public void test44_verifier(RunInfo info) { 1332 MyValue2[] src = new MyValue2[8]; 1333 MyValue2[] dst = new MyValue2[8]; 1334 for (int i = 1; i < 8; ++i) { 1335 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1336 } 1337 test44(src, dst); 1338 verify(src, dst); 1339 if (compile_and_run_again_if_deoptimized(info)) { 1340 test44(src, dst); 1341 verify(src, dst); 1342 } 1343 } 1344 1345 @Test 1346 public void test45(MyValue2[] src, Object dst) { 1347 System.arraycopy(src, 0, dst, 0, 8); 1348 } 1349 1350 @Run(test = "test45") 1351 public void test45_verifier(RunInfo info) { 1352 MyValue2[] src = new MyValue2[8]; 1353 MyValue2[] dst = new MyValue2[8]; 1354 for (int i = 1; i < 8; ++i) { 1355 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1356 } 1357 test45(src, dst); 1358 verify(src, dst); 1359 if (compile_and_run_again_if_deoptimized(info)) { 1360 test45(src, dst); 1361 verify(src, dst); 1362 } 1363 } 1364 1365 @Test 1366 public void test46(Object[] src, MyValue2[] dst) { 1367 System.arraycopy(src, 0, dst, 0, 8); 1368 } 1369 1370 @Run(test = "test46") 1371 @Warmup(1) // Avoid early compilation 1372 public void test46_verifier(RunInfo info) { 1373 Object[] src = new Object[8]; 1374 MyValue2[] dst = new MyValue2[8]; 1375 for (int i = 1; i < 8; ++i) { 1376 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1377 } 1378 test46(src, dst); 1379 verify(dst, src); 1380 if (!info.isWarmUp()) { 1381 Method m = info.getTest(); 1382 TestFramework.assertDeoptimizedByC2(m); 1383 TestFramework.compile(m, CompLevel.C2); 1384 test46(src, dst); 1385 verify(dst, src); 1386 TestFramework.assertCompiled(m); 1387 } 1388 } 1389 1390 @Test 1391 public void test47(MyValue2[] src, Object[] dst) { 1392 System.arraycopy(src, 0, dst, 0, 8); 1393 } 1394 1395 @Run(test = "test47") 1396 public void test47_verifier(RunInfo info) { 1397 MyValue2[] src = new MyValue2[8]; 1398 Object[] dst = new Object[8]; 1399 for (int i = 1; i < 8; ++i) { 1400 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1401 } 1402 test47(src, dst); 1403 verify(src, dst); 1404 if (compile_and_run_again_if_deoptimized(info)) { 1405 test47(src, dst); 1406 verify(src, dst); 1407 } 1408 } 1409 1410 @Test 1411 public void test48(Object[] src, Object dst) { 1412 System.arraycopy(src, 0, dst, 0, 8); 1413 } 1414 1415 @Run(test = "test48") 1416 @Warmup(1) // Avoid early compilation 1417 public void test48_verifier(RunInfo info) { 1418 Object[] src = new Object[8]; 1419 MyValue2[] dst = new MyValue2[8]; 1420 for (int i = 1; i < 8; ++i) { 1421 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1422 } 1423 test48(src, dst); 1424 verify(dst, src); 1425 if (!info.isWarmUp()) { 1426 Method m = info.getTest(); 1427 TestFramework.assertDeoptimizedByC2(m); 1428 TestFramework.compile(m, CompLevel.C2); 1429 test48(src, dst); 1430 verify(dst, src); 1431 TestFramework.assertCompiled(m); 1432 } 1433 } 1434 1435 @Test 1436 public void test49(Object src, Object[] dst) { 1437 System.arraycopy(src, 0, dst, 0, 8); 1438 } 1439 1440 @Run(test = "test49") 1441 public void test49_verifier(RunInfo info) { 1442 MyValue2[] src = new MyValue2[8]; 1443 Object[] dst = new Object[8]; 1444 for (int i = 1; i < 8; ++i) { 1445 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1446 } 1447 test49(src, dst); 1448 verify(src, dst); 1449 if (compile_and_run_again_if_deoptimized(info)) { 1450 test49(src, dst); 1451 verify(src, dst); 1452 } 1453 } 1454 1455 @Test 1456 public void test50(Object[] src, Object[] dst) { 1457 System.arraycopy(src, 0, dst, 0, 8); 1458 } 1459 1460 @Run(test = "test50") 1461 public void test50_verifier(RunInfo info) { 1462 Object[] src = new Object[8]; 1463 Object[] dst = new Object[8]; 1464 for (int i = 1; i < 8; ++i) { 1465 src[i] = MyValue2.createWithFieldsInline(rI+i, rD+i); 1466 } 1467 test50(src, dst); 1468 verify(src, dst); 1469 if (!info.isWarmUp()) { 1470 Method m = info.getTest(); 1471 TestFramework.assertCompiled(m); 1472 } 1473 } 1474 1475 @Test 1476 public MyValue1[] test51(MyValue1[] va) { 1477 return Arrays.copyOf(va, va.length, MyValue1[].class); 1478 } 1479 1480 @Run(test = "test51") 1481 public void test51_verifier() { 1482 int len = Math.abs(rI) % 10; 1483 MyValue1[] va = new MyValue1[len]; 1484 for (int i = 1; i < len; ++i) { 1485 va[i] = testValue1; 1486 } 1487 MyValue1[] result = test51(va); 1488 verify(va, result); 1489 } 1490 1491 static final MyValue1[] test52_va = new MyValue1[8]; 1492 1493 @Test 1494 public MyValue1[] test52() { 1495 return Arrays.copyOf(test52_va, 8, MyValue1[].class); 1496 } 1497 1498 @Run(test = "test52") 1499 public void test52_verifier() { 1500 for (int i = 1; i < 8; ++i) { 1501 test52_va[i] = testValue1; 1502 } 1503 MyValue1[] result = test52(); 1504 verify(test52_va, result); 1505 } 1506 1507 @Test 1508 public MyValue1[] test53(Object[] va) { 1509 return Arrays.copyOf(va, va.length, MyValue1[].class); 1510 } 1511 1512 @Run(test = "test53") 1513 public void test53_verifier() { 1514 int len = Math.abs(rI) % 10; 1515 MyValue1[] va = new MyValue1[len]; 1516 for (int i = 1; i < len; ++i) { 1517 va[i] = testValue1; 1518 } 1519 MyValue1[] result = test53(va); 1520 verify(result, va); 1521 } 1522 1523 @Test 1524 public Object[] test54(MyValue1[] va) { 1525 return Arrays.copyOf(va, va.length, Object[].class); 1526 } 1527 1528 @Run(test = "test54") 1529 public void test54_verifier() { 1530 int len = Math.abs(rI) % 10; 1531 MyValue1[] va = new MyValue1[len]; 1532 for (int i = 1; i < len; ++i) { 1533 va[i] = testValue1; 1534 } 1535 Object[] result = test54(va); 1536 verify(va, result); 1537 } 1538 1539 @Test 1540 public Object[] test55(Object[] va) { 1541 return Arrays.copyOf(va, va.length, Object[].class); 1542 } 1543 1544 @Run(test = "test55") 1545 public void test55_verifier() { 1546 int len = Math.abs(rI) % 10; 1547 MyValue1[] va = new MyValue1[len]; 1548 for (int i = 1; i < len; ++i) { 1549 va[i] = testValue1; 1550 } 1551 Object[] result = test55(va); 1552 verify(va, result); 1553 } 1554 1555 @Test 1556 public MyValue1[] test56(Object[] va) { 1557 return Arrays.copyOf(va, va.length, MyValue1[].class); 1558 } 1559 1560 @Run(test = "test56") 1561 public void test56_verifier() { 1562 int len = Math.abs(rI) % 10; 1563 Object[] va = new Object[len]; 1564 for (int i = 1; i < len; ++i) { 1565 va[i] = testValue1; 1566 } 1567 MyValue1[] result = test56(va); 1568 verify(result, va); 1569 } 1570 1571 @Test 1572 public Object[] test57(Object[] va, Class klass) { 1573 return Arrays.copyOf(va, va.length, klass); 1574 } 1575 1576 @Run(test = "test57") 1577 public void test57_verifier() { 1578 int len = Math.abs(rI) % 10; 1579 Object[] va = new MyValue1[len]; 1580 for (int i = 1; i < len; ++i) { 1581 va[i] = testValue1; 1582 } 1583 Object[] result = test57(va, MyValue1[].class); 1584 verify(va, result); 1585 } 1586 1587 @Test 1588 public Object[] test58(MyValue1[] va, Class klass) { 1589 return Arrays.copyOf(va, va.length, klass); 1590 } 1591 1592 @Run(test = "test58") 1593 public void test58_verifier(RunInfo info) { 1594 int len = Math.abs(rI) % 10; 1595 MyValue1[] va = new MyValue1[len]; 1596 for (int i = 1; i < len; ++i) { 1597 va[i] = testValue1; 1598 } 1599 for (int i = 1; i < 10; i++) { 1600 Object[] result = test58(va, MyValue1[].class); 1601 verify(va, result); 1602 } 1603 if (compile_and_run_again_if_deoptimized(info)) { 1604 Object[] result = test58(va, MyValue1[].class); 1605 verify(va, result); 1606 } 1607 } 1608 1609 @Test 1610 public Object[] test59(MyValue1[] va) { 1611 return Arrays.copyOf(va, va.length+1, MyValue1[].class); 1612 } 1613 1614 @Run(test = "test59") 1615 public void test59_verifier() { 1616 int len = Math.abs(rI) % 10; 1617 MyValue1[] va = new MyValue1[len]; 1618 MyValue1[] verif = new MyValue1[len+1]; 1619 for (int i = 1; i < len; ++i) { 1620 va[i] = testValue1; 1621 verif[i] = va[i]; 1622 } 1623 Object[] result = test59(va); 1624 verify(verif, result); 1625 } 1626 1627 @Test 1628 public Object[] test60(Object[] va, Class klass) { 1629 return Arrays.copyOf(va, va.length+1, klass); 1630 } 1631 1632 @Run(test = "test60") 1633 public void test60_verifier() { 1634 int len = Math.abs(rI) % 10; 1635 MyValue1[] va = new MyValue1[len]; 1636 MyValue1[] verif = new MyValue1[len+1]; 1637 for (int i = 1; i < len; ++i) { 1638 va[i] = testValue1; 1639 verif[i] = (MyValue1)va[i]; 1640 } 1641 Object[] result = test60(va, MyValue1[].class); 1642 verify(verif, result); 1643 } 1644 1645 @Test 1646 public Object[] test61(Object[] va, Class klass) { 1647 return Arrays.copyOf(va, va.length+1, klass); 1648 } 1649 1650 @Run(test = "test61") 1651 public void test61_verifier() { 1652 int len = Math.abs(rI) % 10; 1653 Object[] va = new NonValueClass[len]; 1654 for (int i = 1; i < len; ++i) { 1655 va[i] = new NonValueClass(rI); 1656 } 1657 Object[] result = test61(va, NonValueClass[].class); 1658 for (int i = 0; i < va.length; ++i) { 1659 Asserts.assertEQ(va[i], result[i]); 1660 } 1661 } 1662 1663 @ForceInline 1664 public Object[] test62_helper(int i, MyValue1[] va, NonValueClass[] oa) { 1665 Object[] arr = null; 1666 if (i == 10) { 1667 arr = oa; 1668 } else { 1669 arr = va; 1670 } 1671 return arr; 1672 } 1673 1674 @Test 1675 public Object[] test62(MyValue1[] va, NonValueClass[] oa) { 1676 int i = 0; 1677 for (; i < 10; i++); 1678 1679 Object[] arr = test62_helper(i, va, oa); 1680 1681 return Arrays.copyOf(arr, arr.length+1, arr.getClass()); 1682 } 1683 1684 @Run(test = "test62") 1685 public void test62_verifier() { 1686 int len = Math.abs(rI) % 10; 1687 MyValue1[] va = new MyValue1[len]; 1688 NonValueClass[] oa = new NonValueClass[len]; 1689 for (int i = 1; i < len; ++i) { 1690 oa[i] = new NonValueClass(rI); 1691 } 1692 test62_helper(42, va, oa); 1693 Object[] result = test62(va, oa); 1694 for (int i = 0; i < va.length; ++i) { 1695 Asserts.assertEQ(oa[i], result[i]); 1696 } 1697 } 1698 1699 @ForceInline 1700 public Object[] test63_helper(int i, MyValue1[] va, NonValueClass[] oa) { 1701 Object[] arr = null; 1702 if (i == 10) { 1703 arr = va; 1704 } else { 1705 arr = oa; 1706 } 1707 return arr; 1708 } 1709 1710 @Test 1711 public Object[] test63(MyValue1[] va, NonValueClass[] oa) { 1712 int i = 0; 1713 for (; i < 10; i++); 1714 1715 Object[] arr = test63_helper(i, va, oa); 1716 1717 return Arrays.copyOf(arr, arr.length+1, arr.getClass()); 1718 } 1719 1720 @Run(test = "test63") 1721 public void test63_verifier() { 1722 int len = Math.abs(rI) % 10; 1723 MyValue1[] va = new MyValue1[len]; 1724 MyValue1[] verif = new MyValue1[len+1]; 1725 for (int i = 1; i < len; ++i) { 1726 va[i] = testValue1; 1727 verif[i] = va[i]; 1728 } 1729 NonValueClass[] oa = new NonValueClass[len]; 1730 test63_helper(42, va, oa); 1731 Object[] result = test63(va, oa); 1732 verify(verif, result); 1733 } 1734 1735 // Test default initialization of value class arrays: small array 1736 @Test 1737 public MyValue1[] test64() { 1738 return new MyValue1[8]; 1739 } 1740 1741 @Run(test = "test64") 1742 public void test64_verifier() { 1743 MyValue1[] va = test64(); 1744 for (int i = 0; i < 8; ++i) { 1745 Asserts.assertEQ(va[i], null); 1746 } 1747 } 1748 1749 // Test default initialization of value class arrays: large array 1750 @Test 1751 public MyValue1[] test65() { 1752 return new MyValue1[32]; 1753 } 1754 1755 @Run(test = "test65") 1756 public void test65_verifier() { 1757 MyValue1[] va = test65(); 1758 for (int i = 0; i < 32; ++i) { 1759 Asserts.assertEQ(va[i], null); 1760 } 1761 } 1762 1763 // Check init store elimination 1764 @Test 1765 @IR(counts = {ALLOCA, "= 1"}) 1766 public MyValue1[] test66(MyValue1 vt) { 1767 MyValue1[] va = new MyValue1[1]; 1768 va[0] = vt; 1769 return va; 1770 } 1771 1772 @Run(test = "test66") 1773 public void test66_verifier() { 1774 MyValue1 vt = MyValue1.createWithFieldsDontInline(rI, rL); 1775 MyValue1[] va = test66(vt); 1776 Asserts.assertEQ(va[0].hashPrimitive(), vt.hashPrimitive()); 1777 } 1778 1779 // Zeroing elimination and arraycopy 1780 @Test 1781 public MyValue1[] test67(MyValue1[] src) { 1782 MyValue1[] dst = new MyValue1[16]; 1783 System.arraycopy(src, 0, dst, 0, 13); 1784 return dst; 1785 } 1786 1787 @Run(test = "test67") 1788 public void test67_verifier() { 1789 MyValue1[] va = new MyValue1[16]; 1790 MyValue1[] var = test67(va); 1791 for (int i = 0; i < 16; ++i) { 1792 Asserts.assertEQ(var[i], null); 1793 } 1794 } 1795 1796 // A store with a default value can be eliminated 1797 @Test 1798 public MyValue1[] test68() { 1799 MyValue1[] va = new MyValue1[2]; 1800 va[0] = va[1]; 1801 return va; 1802 } 1803 1804 @Run(test = "test68") 1805 public void test68_verifier() { 1806 MyValue1[] va = test68(); 1807 for (int i = 0; i < 2; ++i) { 1808 Asserts.assertEQ(va[i], null); 1809 } 1810 } 1811 1812 // Requires individual stores to init array 1813 @Test 1814 public MyValue1[] test69(MyValue1 vt) { 1815 MyValue1[] va = new MyValue1[4]; 1816 va[0] = vt; 1817 va[3] = vt; 1818 return va; 1819 } 1820 1821 @Run(test = "test69") 1822 public void test69_verifier() { 1823 MyValue1 vt = MyValue1.createWithFieldsDontInline(rI, rL); 1824 MyValue1[] va = new MyValue1[4]; 1825 va[0] = vt; 1826 va[3] = vt; 1827 MyValue1[] var = test69(vt); 1828 for (int i = 0; i < va.length; ++i) { 1829 Asserts.assertEQ(va[i], var[i]); 1830 } 1831 } 1832 1833 // A store with a default value can be eliminated: same as test68 1834 // but store is farther away from allocation 1835 @Test 1836 public MyValue1[] test70(MyValue1[] other) { 1837 other[1] = other[0]; 1838 MyValue1[] va = new MyValue1[2]; 1839 other[0] = va[1]; 1840 va[0] = va[1]; 1841 return va; 1842 } 1843 1844 @Run(test = "test70") 1845 public void test70_verifier() { 1846 MyValue1[] va = new MyValue1[2]; 1847 MyValue1[] var = test70(va); 1848 for (int i = 0; i < 2; ++i) { 1849 Asserts.assertEQ(va[i], var[i]); 1850 } 1851 } 1852 1853 // EA needs to consider oop fields in flattened arrays 1854 @Test 1855 public void test71() { 1856 int len = 10; 1857 MyValue2[] src = new MyValue2[len]; 1858 MyValue2[] dst = new MyValue2[len]; 1859 for (int i = 1; i < len; ++i) { 1860 src[i] = MyValue2.createWithFieldsDontInline(rI+i, rD+i); 1861 } 1862 System.arraycopy(src, 0, dst, 0, src.length); 1863 for (int i = 0; i < len; ++i) { 1864 if (src[i] == null) { 1865 Asserts.assertEQ(dst[i], null); 1866 } else { 1867 Asserts.assertEQ(src[i].hash(), dst[i].hash()); 1868 } 1869 } 1870 } 1871 1872 @Run(test = "test71") 1873 public void test71_verifier() { 1874 test71(); 1875 } 1876 1877 // Test EA with leaf call to 'store_unknown_value' 1878 @Test 1879 public void test72(Object[] o, boolean b, Object element) { 1880 Object[] arr1 = new Object[10]; 1881 Object[] arr2 = new Object[10]; 1882 if (b) { 1883 arr1 = o; 1884 } 1885 arr1[0] = element; 1886 arr2[0] = element; 1887 } 1888 1889 @Run(test = "test72") 1890 public void test72_verifier() { 1891 Object[] arr = new Object[1]; 1892 Object elem = new Object(); 1893 test72(arr, true, elem); 1894 test72(arr, false, elem); 1895 } 1896 1897 @Test 1898 public void test73(Object[] oa, MyValue1 v, Object o) { 1899 // TestLWorld.test38 use a C1 Phi node for the array. This test 1900 // adds the case where the stored value is a C1 Phi node. 1901 Object o2 = (o == null) ? v : o; 1902 oa[0] = v; // The stored value is known to be flattenable 1903 oa[1] = o; // The stored value may be flattenable 1904 oa[2] = o2; // The stored value may be flattenable (a C1 Phi node) 1905 oa[0] = oa; // The stored value is known to be not flattenable (an Object[]) 1906 } 1907 1908 @Run(test = "test73") 1909 public void test73_verifier() { 1910 MyValue1 v0 = MyValue1.createWithFieldsDontInline(rI, rL); 1911 MyValue1 v1 = MyValue1.createWithFieldsDontInline(rI+1, rL+1); 1912 MyValue1[] arr = new MyValue1[3]; 1913 try { 1914 test73(arr, v0, v1); 1915 throw new RuntimeException("ArrayStoreException expected"); 1916 } catch (ArrayStoreException t) { 1917 // expected 1918 } 1919 Asserts.assertEQ(arr[0].hash(), v0.hash()); 1920 Asserts.assertEQ(arr[1].hash(), v1.hash()); 1921 Asserts.assertEQ(arr[2].hash(), v1.hash()); 1922 } 1923 1924 // Some more array clone tests 1925 @ForceInline 1926 public Object[] test74_helper(int i, MyValue1[] va, NonValueClass[] oa) { 1927 Object[] arr = null; 1928 if (i == 10) { 1929 arr = oa; 1930 } else { 1931 arr = va; 1932 } 1933 return arr; 1934 } 1935 1936 @Test 1937 public Object[] test74(MyValue1[] va, NonValueClass[] oa) { 1938 int i = 0; 1939 for (; i < 10; i++); 1940 1941 Object[] arr = test74_helper(i, va, oa); 1942 return arr.clone(); 1943 } 1944 1945 @Run(test = "test74") 1946 public void test74_verifier() { 1947 int len = Math.abs(rI) % 10; 1948 MyValue1[] va = new MyValue1[len]; 1949 NonValueClass[] oa = new NonValueClass[len]; 1950 for (int i = 1; i < len; ++i) { 1951 oa[i] = new NonValueClass(rI); 1952 } 1953 test74_helper(42, va, oa); 1954 Object[] result = test74(va, oa); 1955 1956 for (int i = 0; i < va.length; ++i) { 1957 Asserts.assertEQ(oa[i], result[i]); 1958 // Check that array has correct properties (null-ok) 1959 result[i] = null; 1960 } 1961 } 1962 1963 @ForceInline 1964 public Object[] test75_helper(int i, MyValue1[] va, NonValueClass[] oa) { 1965 Object[] arr = null; 1966 if (i == 10) { 1967 arr = va; 1968 } else { 1969 arr = oa; 1970 } 1971 return arr; 1972 } 1973 1974 @Test 1975 public Object[] test75(MyValue1[] va, NonValueClass[] oa) { 1976 int i = 0; 1977 for (; i < 10; i++); 1978 1979 Object[] arr = test75_helper(i, va, oa); 1980 return arr.clone(); 1981 } 1982 1983 @Run(test = "test75") 1984 public void test75_verifier() { 1985 int len = Math.abs(rI) % 10; 1986 MyValue1[] va = new MyValue1[len]; 1987 MyValue1[] verif = new MyValue1[len]; 1988 for (int i = 1; i < len; ++i) { 1989 va[i] = testValue1; 1990 verif[i] = va[i]; 1991 } 1992 NonValueClass[] oa = new NonValueClass[len]; 1993 test75_helper(42, va, oa); 1994 Object[] result = test75(va, oa); 1995 verify(verif, result); 1996 if (len > 0) { 1997 // Check that array has correct properties (null-ok) 1998 result[0] = null; 1999 } 2000 } 2001 2002 // Test mixing nullable and non-nullable arrays 2003 @Test 2004 public Object[] test76(MyValue1[] vva, MyValue1[] vba, MyValue1 vt, Object[] out, int n) { 2005 Object[] result = null; 2006 if (n == 0) { 2007 result = vva; 2008 } else if (n == 1) { 2009 result = vba; 2010 } else if (n == 2) { 2011 result = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2012 } else if (n == 3) { 2013 result = new MyValue1[42]; 2014 } 2015 result[0] = vt; 2016 out[0] = result[1]; 2017 return result; 2018 } 2019 2020 @Run(test = "test76") 2021 public void test76_verifier() { 2022 MyValue1 vt = testValue1; 2023 Object[] out = new Object[1]; 2024 MyValue1[] vva = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2025 MyValue1[] vva_r = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2026 vva_r[0] = vt; 2027 MyValue1[] vba = new MyValue1[42]; 2028 MyValue1[] vba_r = new MyValue1[42]; 2029 vba_r[0] = vt; 2030 Object[] result = test76(vva, vba, vt, out, 0); 2031 verify(result, vva_r); 2032 Asserts.assertEQ(out[0], vva_r[1]); 2033 result = test76(vva, vba, vt, out, 1); 2034 verify(result, vba_r); 2035 Asserts.assertEQ(out[0], vba_r[1]); 2036 result = test76(vva, vba, vt, out, 2); 2037 verify(result, vva_r); 2038 Asserts.assertEQ(out[0], vva_r[1]); 2039 result = test76(vva, vba, vt, out, 3); 2040 verify(result, vba_r); 2041 Asserts.assertEQ(out[0], vba_r[1]); 2042 } 2043 2044 @Test 2045 public Object[] test77(boolean b) { 2046 Object[] va; 2047 if (b) { 2048 va = new MyValue1[5]; 2049 for (int i = 0; i < 5; ++i) { 2050 va[i] = testValue1; 2051 } 2052 } else { 2053 va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 10); 2054 for (int i = 0; i < 10; ++i) { 2055 va[i] = MyValue1.createWithFieldsInline(rI + i, rL + i); 2056 } 2057 } 2058 long sum = ((MyValue1)va[0]).hashInterpreted(); 2059 if (b) { 2060 va[0] = MyValue1.createWithFieldsDontInline(rI, sum); 2061 } else { 2062 va[0] = MyValue1.createWithFieldsDontInline(rI + 1, sum + 1); 2063 } 2064 return va; 2065 } 2066 2067 @Run(test = "test77") 2068 public void test77_verifier() { 2069 Object[] va = test77(true); 2070 Asserts.assertEQ(va.length, 5); 2071 Asserts.assertEQ(((MyValue1)va[0]).hash(), hash(rI, hash())); 2072 for (int i = 1; i < 5; ++i) { 2073 Asserts.assertEQ(((MyValue1)va[i]).hash(), hash()); 2074 } 2075 va = test77(false); 2076 Asserts.assertEQ(va.length, 10); 2077 Asserts.assertEQ(((MyValue1)va[0]).hash(), hash(rI + 1, hash(rI, rL) + 1)); 2078 for (int i = 1; i < 10; ++i) { 2079 Asserts.assertEQ(((MyValue1)va[i]).hash(), hash(rI + i, rL + i)); 2080 } 2081 } 2082 2083 // Same as test76 but with non value class array cases 2084 @Test 2085 public Object[] test78(MyValue1[] vva, MyValue1[] vba, Object val, Object[] out, int n) { 2086 Object[] result = null; 2087 if (n == 0) { 2088 result = vva; 2089 } else if (n == 1) { 2090 result = vba; 2091 } else if (n == 2) { 2092 result = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2093 } else if (n == 3) { 2094 result = new MyValue1[42]; 2095 } else if (n == 4) { 2096 result = new NonValueClass[42]; 2097 } 2098 result[0] = val; 2099 out[0] = result[1]; 2100 return result; 2101 } 2102 2103 @Run(test = "test78") 2104 public void test78_verifier() { 2105 MyValue1 vt = testValue1; 2106 NonValueClass obj = new NonValueClass(42); 2107 Object[] out = new Object[1]; 2108 MyValue1[] vva = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2109 MyValue1[] vva_r = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2110 vva_r[0] = vt; 2111 MyValue1[] vba = new MyValue1[42]; 2112 MyValue1[] vba_r = new MyValue1[42]; 2113 vba_r[0] = vt; 2114 Object[] result = test78(vva, vba, vt, out, 0); 2115 verify(result, vva_r); 2116 Asserts.assertEQ(out[0], vva_r[1]); 2117 result = test78(vva, vba, vt, out, 1); 2118 verify(result, vba_r); 2119 Asserts.assertEQ(out[0], vba_r[1]); 2120 result = test78(vva, vba, vt, out, 2); 2121 verify(result, vva_r); 2122 Asserts.assertEQ(out[0], vva_r[1]); 2123 result = test78(vva, vba, vt, out, 3); 2124 verify(result, vba_r); 2125 Asserts.assertEQ(out[0], vba_r[1]); 2126 result = test78(vva, vba, obj, out, 4); 2127 Asserts.assertEQ(result[0], obj); 2128 Asserts.assertEQ(out[0], null); 2129 } 2130 2131 // Test widening conversions from [Q to [L 2132 @Test 2133 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 2134 public static MyValue1[] test79(MyValue1[] va) { 2135 return va; 2136 } 2137 2138 @Run(test = "test79") 2139 public void test79_verifier() { 2140 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2141 va[0] = testValue1; 2142 MyValue1[] res = test79(va); 2143 Asserts.assertEquals(res[0].hash(), testValue1.hash()); 2144 try { 2145 res[0] = null; 2146 throw new RuntimeException("NullPointerException expected"); 2147 } catch (NullPointerException npe) { 2148 // Expected 2149 } 2150 res[0] = testValue1; 2151 test79(null); // Should not throw NPE 2152 } 2153 2154 // Same as test79 but with explicit cast and Object return 2155 @Test 2156 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 2157 public static Object[] test80(MyValue1[] va) { 2158 return (MyValue1[])va; 2159 } 2160 2161 @Run(test = "test80") 2162 public void test80_verifier() { 2163 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2164 va[0] = testValue1; 2165 Object[] res = test80(va); 2166 Asserts.assertEquals(((MyValue1)res[0]).hash(), testValue1.hash()); 2167 try { 2168 res[0] = null; 2169 throw new RuntimeException("NullPointerException expected"); 2170 } catch (NullPointerException npe) { 2171 // Expected 2172 } 2173 res[0] = testValue1; 2174 test80(null); // Should not throw NPE 2175 } 2176 2177 // Test mixing widened and boxed array type 2178 @Test 2179 public static long test81(MyValue1[] va1, MyValue1[] va2, MyValue1 vt, boolean b, boolean shouldThrow) { 2180 MyValue1[] result = b ? va1 : va2; 2181 try { 2182 result[0] = vt; 2183 } catch (NullPointerException npe) { 2184 // Ignored 2185 } 2186 return result[1].hash(); 2187 } 2188 2189 @Run(test = "test81") 2190 public void test81_verifier() { 2191 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2192 MyValue1[] vaB = new MyValue1[2]; 2193 va[1] = testValue1; 2194 vaB[1] = testValue1; 2195 long res = test81(va, vaB, testValue1, true, true); 2196 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2197 Asserts.assertEquals(res, testValue1.hash()); 2198 res = test81(va, vaB, testValue1, false, false); 2199 Asserts.assertEquals(vaB[0].hash(), testValue1.hash()); 2200 Asserts.assertEquals(res, testValue1.hash()); 2201 res = test81(va, va, testValue1, false, true); 2202 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2203 Asserts.assertEquals(res, testValue1.hash()); 2204 } 2205 2206 // Same as test81 but more cases and null writes 2207 @Test 2208 public static long test82(MyValue1[] va1, MyValue1[] va2, MyValue1 vt1, MyValue1 vt2, int i, boolean shouldThrow) { 2209 MyValue1[] result = null; 2210 if (i == 0) { 2211 result = va1; 2212 } else if (i == 1) { 2213 result = va2; 2214 } else if (i == 2) { 2215 result = new MyValue1[2]; 2216 result[1] = vt1; 2217 } else if (i == 3) { 2218 result = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2219 result[1] = vt1; 2220 } 2221 try { 2222 result[0] = (i <= 1) ? null : vt2; 2223 if (shouldThrow) { 2224 throw new RuntimeException("NullPointerException expected"); 2225 } 2226 } catch (NullPointerException npe) { 2227 Asserts.assertTrue(shouldThrow, "NullPointerException thrown"); 2228 } 2229 result[0] = vt1; 2230 return result[1].hash(); 2231 } 2232 2233 @Run(test = "test82") 2234 public void test82_verifier() { 2235 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2236 MyValue1[] vaB = new MyValue1[2]; 2237 va[1] = testValue1; 2238 vaB[1] = testValue1; 2239 long res = test82(va, vaB, testValue1, testValue1, 0, true); 2240 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2241 Asserts.assertEquals(res, testValue1.hash()); 2242 res = test82(va, vaB, testValue1, testValue1, 1, false); 2243 Asserts.assertEquals(vaB[0].hash(), testValue1.hash()); 2244 Asserts.assertEquals(res, testValue1.hash()); 2245 res = test82(va, va, testValue1, testValue1, 1, true); 2246 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2247 Asserts.assertEquals(res, testValue1.hash()); 2248 res = test82(va, va, testValue1, null, 2, false); 2249 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2250 Asserts.assertEquals(res, testValue1.hash()); 2251 res = test82(va, va, testValue1, null, 3, true); 2252 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2253 Asserts.assertEquals(res, testValue1.hash()); 2254 } 2255 2256 @Test 2257 @IR(failOn = {ALLOC, ALLOCA, STORE}) 2258 public static long test83(MyValue1[] va) { 2259 MyValue1[] result = va; 2260 return result[0].hash(); 2261 } 2262 2263 @Run(test = "test83") 2264 public void test83_verifier() { 2265 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 42); 2266 va[0] = testValue1; 2267 long res = test83(va); 2268 Asserts.assertEquals(res, testValue1.hash()); 2269 } 2270 2271 @Test 2272 @IR(applyIf = {"FlatArrayElementMaxSize", "= -1"}, 2273 failOn = {ALLOC, LOOP, STORE, TRAP}) 2274 public static MyValue1[] test84(MyValue1 vt1, MyValue1 vt2) { 2275 MyValue1[] result = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2276 result[0] = vt1; 2277 result[1] = vt2; 2278 return result; 2279 } 2280 2281 @Run(test = "test84") 2282 public void test84_verifier() { 2283 MyValue1[] res = test84(testValue1, testValue1); 2284 Asserts.assertEquals(res[0].hash(), testValue1.hash()); 2285 Asserts.assertEquals(res[1].hash(), testValue1.hash()); 2286 try { 2287 test84(testValue1, null); 2288 throw new RuntimeException("NullPointerException expected"); 2289 } catch (NullPointerException npe) { 2290 // Expected 2291 } 2292 } 2293 2294 @Test 2295 public static long test85(MyValue1[] va, MyValue1 val) { 2296 va[0] = val; 2297 return va[1].hash(); 2298 } 2299 2300 @Run(test = "test85") 2301 public void test85_verifier() { 2302 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2303 MyValue1[] vab = new MyValue1[2]; 2304 va[1] = testValue1; 2305 vab[1] = testValue1; 2306 long res = test85(va, testValue1); 2307 Asserts.assertEquals(res, testValue1.hash()); 2308 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2309 res = test85(vab, testValue1); 2310 Asserts.assertEquals(res, testValue1.hash()); 2311 Asserts.assertEquals(vab[0].hash(), testValue1.hash()); 2312 } 2313 2314 // Same as test85 but with ref value 2315 @Test 2316 public static long test86(MyValue1[] va, MyValue1 val) { 2317 va[0] = val; 2318 return va[1].hash(); 2319 } 2320 2321 @Run(test = "test86") 2322 public void test86_verifier() { 2323 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2324 MyValue1[] vab = new MyValue1[2]; 2325 va[1] = testValue1; 2326 vab[1] = testValue1; 2327 long res = test86(va, testValue1); 2328 Asserts.assertEquals(res, testValue1.hash()); 2329 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2330 try { 2331 test86(va, null); 2332 throw new RuntimeException("NullPointerException expected"); 2333 } catch (NullPointerException npe) { 2334 // Expected 2335 } 2336 res = test86(vab, testValue1); 2337 Asserts.assertEquals(res, testValue1.hash()); 2338 Asserts.assertEquals(vab[0].hash(), testValue1.hash()); 2339 res = test86(vab, null); 2340 Asserts.assertEquals(res, testValue1.hash()); 2341 Asserts.assertEquals(vab[0], null); 2342 } 2343 2344 // Test initialization of nullable array with constant 2345 @Test 2346 public long test87() { 2347 MyValue1[] va = new MyValue1[1]; 2348 va[0] = testValue1; 2349 return va[0].hash(); 2350 } 2351 2352 @Run(test = "test87") 2353 public void test87_verifier() { 2354 long result = test87(); 2355 Asserts.assertEQ(result, hash()); 2356 } 2357 2358 2359 // Test casting to null restricted array 2360 @Test 2361 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 2362 public static MyValue1[] test88(Class c, MyValue1[] va) { 2363 return (MyValue1[])c.cast(va); 2364 } 2365 2366 @Run(test = "test88") 2367 public void test88_verifier() { 2368 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2369 va[0] = testValue1; 2370 MyValue1[] res = test88(va.getClass(), va); 2371 Asserts.assertEquals(res[0].hash(), testValue1.hash()); 2372 res[0] = testValue1; 2373 test88(va.getClass(), null); // Should not throw NPE 2374 try { 2375 test88(va.getClass(), new MyValue1[1]); 2376 throw new RuntimeException("ClassCastException expected"); 2377 } catch (ClassCastException cce) { 2378 // Expected 2379 } 2380 } 2381 2382 // Same as test88 but with Object argument 2383 @Test 2384 @IR(failOn = {ALLOC, ALLOCA, LOOP, LOAD, STORE, TRAP}) 2385 public static MyValue1[] test89(Class c, Object[] va) { 2386 return (MyValue1[])c.cast(va); 2387 } 2388 2389 @Run(test = "test89") 2390 public void test89_verifier() { 2391 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2392 va[0] = testValue1; 2393 MyValue1[] res = test89(va.getClass(), va); 2394 Asserts.assertEquals(((MyValue1)res[0]).hash(), testValue1.hash()); 2395 res[0] = testValue1; 2396 test89(va.getClass(), null); // Should not throw NPE 2397 try { 2398 test89(va.getClass(), new MyValue1[1]); 2399 throw new RuntimeException("ClassCastException expected"); 2400 } catch (ClassCastException cce) { 2401 // Expected 2402 } 2403 } 2404 2405 // More cast tests 2406 @Test 2407 public static MyValue1[] test90(Object va) { 2408 return (MyValue1[])va; 2409 } 2410 2411 @Run(test = "test90") 2412 public void test90_verifier() { 2413 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2414 MyValue1[] vab = new MyValue1[1]; 2415 try { 2416 // Trigger some ClassCastExceptions so C2 does not add an uncommon trap 2417 test90(new NonValueClass[0]); 2418 } catch (ClassCastException cce) { 2419 // Expected 2420 } 2421 test90(va); 2422 test90(vab); 2423 test90(null); 2424 } 2425 2426 @Test 2427 public static MyValue1[] test91(Object[] va) { 2428 return (MyValue1[])va; 2429 } 2430 2431 @Run(test = "test91") 2432 public void test91_verifier() { 2433 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2434 MyValue1[] vab = new MyValue1[1]; 2435 try { 2436 // Trigger some ClassCastExceptions so C2 does not add an uncommon trap 2437 test91(new NonValueClass[0]); 2438 } catch (ClassCastException cce) { 2439 // Expected 2440 } 2441 test91(va); 2442 test91(vab); 2443 test91(null); 2444 } 2445 2446 // Test if arraycopy intrinsic correctly checks for flattened source array 2447 @Test 2448 public static void test92(MyValue1[] src, MyValue1[] dst) { 2449 System.arraycopy(src, 0, dst, 0, 2); 2450 } 2451 2452 @Run(test = "test92") 2453 public void test92_verifier() { 2454 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2455 MyValue1[] vab = new MyValue1[2]; 2456 va[0] = testValue1; 2457 vab[0] = testValue1; 2458 test92(va, vab); 2459 Asserts.assertEquals(va[0], vab[0]); 2460 Asserts.assertEquals(va[1], vab[1]); 2461 } 2462 2463 @Test 2464 public static void test93(Object src, MyValue1[] dst) { 2465 System.arraycopy(src, 0, dst, 0, 2); 2466 } 2467 2468 @Run(test = "test93") 2469 public void test93_verifier() { 2470 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2471 MyValue1[] vab = new MyValue1[2]; 2472 va[0] = testValue1; 2473 vab[0] = testValue1; 2474 test93(va, vab); 2475 Asserts.assertEquals(va[0], vab[0]); 2476 Asserts.assertEquals(va[1], vab[1]); 2477 } 2478 2479 // Test non-escaping allocation with arraycopy 2480 // that does not modify loaded array element. 2481 @Test 2482 public static long test94() { 2483 MyValue1[] src = new MyValue1[8]; 2484 MyValue1[] dst = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 8); 2485 for (int i = 1; i < 8; ++i) { 2486 src[i] = testValue1; 2487 } 2488 System.arraycopy(src, 1, dst, 2, 6); 2489 return dst[0].hash(); 2490 } 2491 2492 @Run(test = "test94") 2493 public static void test94_verifier() { 2494 long result = test94(); 2495 Asserts.assertEquals(result, MyValue1.createDefaultInline().hash()); 2496 } 2497 2498 // Test meeting constant TypeInstPtr with InlineTypeNode 2499 @ForceInline 2500 public long test95_callee() { 2501 MyValue1[] va = new MyValue1[1]; 2502 va[0] = testValue1; 2503 return va[0].hashInterpreted(); 2504 } 2505 2506 @Test 2507 public long test95() { 2508 return test95_callee(); 2509 } 2510 2511 @Run(test = "test95") 2512 @Warmup(0) 2513 public void test95_verifier() { 2514 long result = test95(); 2515 Asserts.assertEQ(result, hash()); 2516 } 2517 2518 // Matrix multiplication test to exercise type flow analysis with nullable value class arrays 2519 static value class Complex { 2520 private final double re; 2521 private final double im; 2522 2523 Complex(double re, double im) { 2524 this.re = re; 2525 this.im = im; 2526 } 2527 2528 public Complex add(Complex that) { 2529 return new Complex(this.re + that.re, this.im + that.im); 2530 } 2531 2532 public Complex mul(Complex that) { 2533 return new Complex(this.re * that.re - this.im * that.im, 2534 this.re * that.im + this.im * that.re); 2535 } 2536 } 2537 2538 @Test 2539 public Complex[][] test96(Complex[][] A, Complex[][] B) { 2540 int size = A.length; 2541 Complex[][] R = new Complex[size][size]; 2542 for (int i = 0; i < size; i++) { 2543 for (int k = 0; k < size; k++) { 2544 Complex aik = A[i][k]; 2545 for (int j = 0; j < size; j++) { 2546 R[i][j] = B[i][j].add(aik.mul((Complex)B[k][j])); 2547 } 2548 } 2549 } 2550 return R; 2551 } 2552 2553 static Complex[][] test96_A = new Complex[10][10]; 2554 static Complex[][] test96_B = new Complex[10][10]; 2555 static Complex[][] test96_R; 2556 2557 static { 2558 for (int i = 0; i < 10; i++) { 2559 for (int j = 0; j < 10; j++) { 2560 test96_A[i][j] = new Complex(rI, rI); 2561 test96_B[i][j] = new Complex(rI, rI); 2562 } 2563 } 2564 } 2565 2566 @Run(test = "test96") 2567 public void test96_verifier() { 2568 Complex[][] result = test96(test96_A, test96_B); 2569 if (test96_R == null) { 2570 test96_R = result; 2571 } 2572 for (int i = 0; i < 10; i++) { 2573 for (int j = 0; j < 10; j++) { 2574 Asserts.assertEQ(result[i][j], test96_R[i][j]); 2575 } 2576 } 2577 } 2578 2579 // Test loads from vararg arrays 2580 @Test 2581 @IR(failOn = {LOAD_UNKNOWN_INLINE}) 2582 public static Object test97(Object... args) { 2583 return args[0]; 2584 } 2585 2586 @Run(test = "test97") 2587 public static void test97_verifier() { 2588 Object obj = new Object(); 2589 Object result = test97(obj); 2590 Asserts.assertEquals(result, obj); 2591 NonValueClass[] myInt = new NonValueClass[1]; 2592 NonValueClass otherObj = new NonValueClass(rI); 2593 myInt[0] = otherObj; 2594 result = test97((Object[])myInt); 2595 Asserts.assertEquals(result, otherObj); 2596 } 2597 2598 @Test 2599 public static Object test98(Object... args) { 2600 return args[0]; 2601 } 2602 2603 @Run(test = "test98") 2604 public static void test98_verifier(RunInfo info) { 2605 Object obj = new Object(); 2606 Object result = test98(obj); 2607 Asserts.assertEquals(result, obj); 2608 NonValueClass[] myInt = new NonValueClass[1]; 2609 NonValueClass otherObj = new NonValueClass(rI); 2610 myInt[0] = otherObj; 2611 result = test98((Object[])myInt); 2612 Asserts.assertEquals(result, otherObj); 2613 if (!info.isWarmUp()) { 2614 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2615 MyValue1[] vab = new MyValue1[1]; 2616 result = test98((Object[])va); 2617 Asserts.assertEquals(((MyValue1)result).hash(), MyValue1.createDefaultInline().hash()); 2618 result = test98((Object[])vab); 2619 Asserts.assertEquals(result, null); 2620 } 2621 } 2622 2623 @Test 2624 public static Object test99(Object... args) { 2625 return args[0]; 2626 } 2627 2628 @Run(test = "test99") 2629 public static void test99_verifier(RunInfo info) { 2630 Object obj = new Object(); 2631 Object result = test99(obj); 2632 Asserts.assertEquals(result, obj); 2633 NonValueClass[] myInt = new NonValueClass[1]; 2634 NonValueClass otherObj = new NonValueClass(rI); 2635 myInt[0] = otherObj; 2636 result = test99((Object[])myInt); 2637 Asserts.assertEquals(result, otherObj); 2638 if (!info.isWarmUp()) { 2639 try { 2640 test99((Object[])null); 2641 throw new RuntimeException("No NPE thrown"); 2642 } catch (NullPointerException npe) { 2643 // Expected 2644 } 2645 } 2646 } 2647 2648 @Test 2649 public static Object test100(Object... args) { 2650 return args[0]; 2651 } 2652 2653 @Run(test = "test100") 2654 public static void test100_verifier(RunInfo info) { 2655 Object obj = new Object(); 2656 Object result = test100(obj); 2657 Asserts.assertEquals(result, obj); 2658 NonValueClass[] myInt = new NonValueClass[1]; 2659 NonValueClass otherObj = new NonValueClass(rI); 2660 myInt[0] = otherObj; 2661 result = test100((Object[])myInt); 2662 Asserts.assertEquals(result, otherObj); 2663 if (!info.isWarmUp()) { 2664 try { 2665 test100(); 2666 throw new RuntimeException("No AIOOBE thrown"); 2667 } catch (ArrayIndexOutOfBoundsException aioobe) { 2668 // Expected 2669 } 2670 } 2671 } 2672 2673 // Test stores to varag arrays 2674 @Test 2675 @IR(failOn = STORE_UNKNOWN_INLINE) 2676 public static void test101(Object val, Object... args) { 2677 args[0] = val; 2678 } 2679 2680 @Run(test = "test101") 2681 public static void test101_verifier() { 2682 Object obj = new Object(); 2683 test101(obj, obj); 2684 NonValueClass[] myInt = new NonValueClass[1]; 2685 NonValueClass otherObj = new NonValueClass(rI); 2686 test101(otherObj, (Object[])myInt); 2687 Asserts.assertEquals(myInt[0], otherObj); 2688 test101(null, (Object[])myInt); 2689 Asserts.assertEquals(myInt[0], null); 2690 } 2691 2692 @Test 2693 public static void test102(Object val, Object... args) { 2694 args[0] = val; 2695 } 2696 2697 @Run(test = "test102") 2698 public static void test102_verifier(RunInfo info) { 2699 Object obj = new Object(); 2700 test102(obj, obj); 2701 NonValueClass[] myInt = new NonValueClass[1]; 2702 NonValueClass otherObj = new NonValueClass(rI); 2703 test102(otherObj, (Object[])myInt); 2704 Asserts.assertEquals(myInt[0], otherObj); 2705 test102(null, (Object[])myInt); 2706 Asserts.assertEquals(myInt[0], null); 2707 if (!info.isWarmUp()) { 2708 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2709 MyValue1[] vab = new MyValue1[1]; 2710 test102(testValue1, (Object[])va); 2711 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2712 test102(testValue1, (Object[])vab); 2713 Asserts.assertEquals(vab[0].hash(), testValue1.hash()); 2714 test102(null, (Object[])vab); 2715 Asserts.assertEquals(vab[0], null); 2716 } 2717 } 2718 2719 @Test 2720 public static void test103(Object val, Object... args) { 2721 args[0] = val; 2722 } 2723 2724 @Run(test = "test103") 2725 public static void test103_verifier(RunInfo info) { 2726 Object obj = new Object(); 2727 test103(obj, obj); 2728 NonValueClass[] myInt = new NonValueClass[1]; 2729 NonValueClass otherObj = new NonValueClass(rI); 2730 test103(otherObj, (Object[])myInt); 2731 Asserts.assertEquals(myInt[0], otherObj); 2732 test103(null, (Object[])myInt); 2733 Asserts.assertEquals(myInt[0], null); 2734 if (!info.isWarmUp()) { 2735 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2736 try { 2737 test103(null, (Object[])va); 2738 throw new RuntimeException("No NPE thrown"); 2739 } catch (NullPointerException npe) { 2740 // Expected 2741 } 2742 } 2743 } 2744 2745 @Test 2746 public static void test104(Object val, Object... args) { 2747 args[0] = val; 2748 } 2749 2750 @Run(test = "test104") 2751 public static void test104_verifier(RunInfo info) { 2752 Object obj = new Object(); 2753 test104(obj, obj); 2754 NonValueClass[] myInt = new NonValueClass[1]; 2755 NonValueClass otherObj = new NonValueClass(rI); 2756 test104(otherObj, (Object[])myInt); 2757 Asserts.assertEquals(myInt[0], otherObj); 2758 test104(null, (Object[])myInt); 2759 Asserts.assertEquals(myInt[0], null); 2760 if (!info.isWarmUp()) { 2761 try { 2762 test104(testValue1); 2763 throw new RuntimeException("No AIOOBE thrown"); 2764 } catch (ArrayIndexOutOfBoundsException aioobe) { 2765 // Expected 2766 } 2767 } 2768 } 2769 2770 @Test 2771 public static void test105(Object val, Object... args) { 2772 args[0] = val; 2773 } 2774 2775 @Run(test = "test105") 2776 public static void test105_verifier(RunInfo info) { 2777 Object obj = new Object(); 2778 test105(obj, obj); 2779 NonValueClass[] myInt = new NonValueClass[1]; 2780 NonValueClass otherObj = new NonValueClass(rI); 2781 test105(otherObj, (Object[])myInt); 2782 Asserts.assertEquals(myInt[0], otherObj); 2783 test105(null, (Object[])myInt); 2784 Asserts.assertEquals(myInt[0], null); 2785 if (!info.isWarmUp()) { 2786 try { 2787 test105(testValue1, (Object[])null); 2788 throw new RuntimeException("No NPE thrown"); 2789 } catch (NullPointerException npe) { 2790 // Expected 2791 } 2792 } 2793 } 2794 2795 @Test 2796 public static Object[] test106(Object[] dst, Object... args) { 2797 // Access array to speculate on non-flatness 2798 if (args[0] == null) { 2799 args[0] = testValue1; 2800 } 2801 System.arraycopy(args, 0, dst, 0, args.length); 2802 System.arraycopy(dst, 0, args, 0, dst.length); 2803 Object[] clone = args.clone(); 2804 if (clone[0] == null) { 2805 throw new RuntimeException("Unexpected null"); 2806 } 2807 return Arrays.copyOf(args, args.length, Object[].class); 2808 } 2809 2810 @Run(test = "test106") 2811 public static void test106_verifier(RunInfo info) { 2812 Object[] dst = new Object[1]; 2813 Object obj = new Object(); 2814 Object[] result = test106(dst, obj); 2815 Asserts.assertEquals(result[0], obj); 2816 NonValueClass[] myInt = new NonValueClass[1]; 2817 NonValueClass otherObj = new NonValueClass(rI); 2818 myInt[0] = otherObj; 2819 result = test106(myInt, (Object[])myInt); 2820 Asserts.assertEquals(result[0], otherObj); 2821 if (!info.isWarmUp()) { 2822 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2823 MyValue1[] vab = new MyValue1[1]; 2824 result = test106(va, (Object[])va); 2825 Asserts.assertEquals(((MyValue1)result[0]).hash(), MyValue1.createDefaultInline().hash()); 2826 result = test106(vab, (Object[])vab); 2827 Asserts.assertEquals(((MyValue1)result[0]).hash(), testValue1.hash()); 2828 } 2829 } 2830 2831 // TODO 8325632 Fails with "matching stack sizes" in Scenario 5 with -XX:TypeProfileLevel=222 2832 /* 2833 // Test that allocation is not replaced by non-dominating allocation 2834 @ForceInline 2835 public long test107_helper(MyValue1[] va, MyValue1 vt) { 2836 try { 2837 va[0] = vt; 2838 } catch (NullPointerException npe) { } 2839 return va[1].hash(); 2840 } 2841 2842 @Test 2843 public void test107() { 2844 MyValue1[] va = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 2); 2845 MyValue1[] tmp = new MyValue1[2]; 2846 long res1 = test107_helper(va, testValue1); 2847 long res2 = test107_helper(va, testValue1); 2848 Asserts.assertEquals(va[0].hash(), testValue1.hash()); 2849 Asserts.assertEquals(res1, MyValue1.createDefaultInline().hash()); 2850 Asserts.assertEquals(res2, MyValue1.createDefaultInline().hash()); 2851 } 2852 2853 @Run(test = "test107") 2854 public void test107_verifier() { 2855 test107(); 2856 } 2857 */ 2858 2859 @Test 2860 public Object test108(MyValue1[] src, boolean flag) { 2861 MyValue1[] dst = new MyValue1[8]; 2862 System.arraycopy(src, 1, dst, 2, 6); 2863 if (flag) {} // uncommon trap 2864 return dst[2]; 2865 } 2866 2867 @Run(test = "test108") 2868 @Warmup(10000) 2869 public void test108_verifier(RunInfo info) { 2870 MyValue1[] src = new MyValue1[8]; 2871 test108(src, !info.isWarmUp()); 2872 } 2873 2874 // Test LoadNode::can_see_arraycopy_value optimization 2875 @Test 2876 public static void test109() { 2877 MyValue1[] src = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2878 MyValue1[] dst = new MyValue1[1]; 2879 src[0] = testValue1; 2880 System.arraycopy(src, 0, dst, 0, 1); 2881 Asserts.assertEquals(src[0], dst[0]); 2882 } 2883 2884 @Run(test = "test109") 2885 public void test109_verifier() { 2886 test109(); 2887 } 2888 2889 // Same as test109 but with Object destination array 2890 @Test 2891 public static void test110() { 2892 MyValue1[] src = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2893 Object[] dst = new Object[1]; 2894 src[0] = testValue1; 2895 System.arraycopy(src, 0, dst, 0, 1); 2896 Asserts.assertEquals(src[0], dst[0]); 2897 } 2898 2899 @Run(test = "test110") 2900 public void test110_verifier() { 2901 test110(); 2902 } 2903 2904 // Same as test109 but with Arrays.copyOf 2905 @Test 2906 public static void test111() { 2907 MyValue1[] src = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2908 src[0] = testValue1; 2909 MyValue1[] dst = Arrays.copyOf(src, src.length, MyValue1[].class); 2910 Asserts.assertEquals(src[0], dst[0]); 2911 } 2912 2913 @Run(test = "test111") 2914 public void test111_verifier() { 2915 test111(); 2916 } 2917 2918 static final MyValue1[] refArray = new MyValue1[2]; 2919 static final MyValue1[] flatArray = (MyValue1[])ValueClass.newNullRestrictedArray(MyValue1.class, 1); 2920 2921 // Test scalarization 2922 @Test 2923 @IR(failOn = {ALLOC_G, STORE, TRAP}) 2924 public int test112(boolean b) { 2925 MyValue1 val = MyValue1.createWithFieldsInline(rI, rL); 2926 if (b) { 2927 val = refArray[0]; 2928 } 2929 return val.x; 2930 } 2931 2932 @Run(test = "test112") 2933 public void test112_verifier(RunInfo info) { 2934 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 2935 Asserts.assertEquals(test112(true), refArray[0].x); 2936 Asserts.assertEquals(test112(false), testValue1.x); 2937 if (!info.isWarmUp()) { 2938 refArray[0] = null; 2939 try { 2940 Asserts.assertEquals(test112(false), testValue1.x); 2941 test112(true); 2942 throw new RuntimeException("NullPointerException expected"); 2943 } catch (NullPointerException e) { 2944 // Expected 2945 } 2946 } 2947 } 2948 2949 // Same as test112 but with call to hash() 2950 @Test 2951 @IR(failOn = {ALLOC, STORE, TRAP}) 2952 public long test113(boolean b) { 2953 MyValue1 val = MyValue1.createWithFieldsInline(rI, rL); 2954 if (b) { 2955 val = refArray[0]; 2956 } 2957 return val.hash(); 2958 } 2959 2960 @Run(test = "test113") 2961 public void test113_verifier(RunInfo info) { 2962 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 2963 Asserts.assertEquals(test113(true), refArray[0].hash()); 2964 Asserts.assertEquals(test113(false), testValue1.hash()); 2965 if (!info.isWarmUp()) { 2966 refArray[0] = null; 2967 try { 2968 Asserts.assertEquals(test113(false), testValue1.hash()); 2969 test113(true); 2970 throw new RuntimeException("NullPointerException expected"); 2971 } catch (NullPointerException e) { 2972 // Expected 2973 } 2974 } 2975 } 2976 2977 @Test 2978 public MyValue1 test114(boolean b) { 2979 MyValue1 val = MyValue1.createWithFieldsInline(rI, rL); 2980 if (b) { 2981 val = refArray[0]; 2982 } 2983 return val; 2984 } 2985 2986 @Run(test = "test114") 2987 public void test114_verifier(RunInfo info) { 2988 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 2989 Asserts.assertEquals(test114(true).hash(), refArray[0].hash()); 2990 Asserts.assertEquals(test114(false).hash(), testValue1.hash()); 2991 if (!info.isWarmUp()) { 2992 refArray[0] = null; 2993 Asserts.assertEquals(test114(true), null); 2994 } 2995 } 2996 2997 // Test scalarization when .ref is referenced in safepoint debug info 2998 @Test 2999 @IR(failOn = {ALLOC, STORE}) 3000 public int test115(boolean b1, boolean b2, Method m) { 3001 MyValue1 val = MyValue1.createWithFieldsInline(rI, rL); 3002 if (b1) { 3003 val = refArray[0]; 3004 } 3005 if (b2) { 3006 // Uncommon trap 3007 TestFramework.deoptimize(m); 3008 } 3009 return val.x; 3010 } 3011 3012 @Run(test = "test115") 3013 public void test115_verifier(RunInfo info) { 3014 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 3015 Asserts.assertEquals(test115(true, false, info.getTest()), refArray[0].x); 3016 Asserts.assertEquals(test115(false, false, info.getTest()), testValue1.x); 3017 if (!info.isWarmUp()) { 3018 refArray[0] = null; 3019 try { 3020 Asserts.assertEquals(test115(false, false, info.getTest()), testValue1.x); 3021 test115(true, false, info.getTest()); 3022 throw new RuntimeException("NullPointerException expected"); 3023 } catch (NullPointerException e) { 3024 // Expected 3025 } 3026 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 3027 Asserts.assertEquals(test115(true, true, info.getTest()), refArray[0].x); 3028 Asserts.assertEquals(test115(false, true, info.getTest()), testValue1.x); 3029 } 3030 } 3031 3032 @Test 3033 public MyValue1 test116(boolean b1, boolean b2, Method m) { 3034 MyValue1 val = MyValue1.createWithFieldsInline(rI, rL); 3035 if (b1) { 3036 val = refArray[0]; 3037 } 3038 if (b2) { 3039 // Uncommon trap 3040 TestFramework.deoptimize(m); 3041 } 3042 return val; 3043 } 3044 3045 @Run(test = "test116") 3046 public void test116_verifier(RunInfo info) { 3047 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 3048 Asserts.assertEquals(test116(true, false, info.getTest()).hash(), refArray[0].hash()); 3049 Asserts.assertEquals(test116(false, false, info.getTest()).hash(), testValue1.hash()); 3050 if (!info.isWarmUp()) { 3051 refArray[0] = null; 3052 Asserts.assertEquals(test116(true, false, info.getTest()), null); 3053 refArray[0] = MyValue1.createWithFieldsInline(rI+1, rL+1); 3054 Asserts.assertEquals(test116(true, true, info.getTest()).hash(), refArray[0].hash()); 3055 Asserts.assertEquals(test116(false, true, info.getTest()).hash(), testValue1.hash()); 3056 } 3057 } 3058 3059 @Test 3060 @IR(failOn = {ALLOC_G, STORE}) 3061 public int test117(boolean b) { 3062 MyValue1 val = null; 3063 if (b) { 3064 val = refArray[0]; 3065 } 3066 return val.x; 3067 } 3068 3069 @Run(test = "test117") 3070 public void test117_verifier() { 3071 refArray[0] = testValue1; 3072 Asserts.assertEquals(test117(true), testValue1.x); 3073 try { 3074 test117(false); 3075 throw new RuntimeException("NullPointerException expected"); 3076 } catch (NullPointerException e) { 3077 // Expected 3078 } 3079 } 3080 3081 @Test 3082 public MyValue1 test118(boolean b) { 3083 MyValue1 val = null; 3084 if (b) { 3085 val = refArray[0]; 3086 } 3087 return val; 3088 } 3089 3090 @Run(test = "test118") 3091 public void test118_verifier() { 3092 refArray[0] = testValue1; 3093 Asserts.assertEquals(test118(true).hash(), testValue1.hash()); 3094 Asserts.assertEquals(test118(false), null); 3095 } 3096 3097 @Test 3098 @IR(failOn = {ALLOC_G, STORE}) 3099 public int test119(boolean b) { 3100 MyValue1 val = refArray[0]; 3101 if (b) { 3102 val = null; 3103 } 3104 return val.x; 3105 } 3106 3107 @Run(test = "test119") 3108 public void test119_verifier() { 3109 refArray[0] = testValue1; 3110 Asserts.assertEquals(test119(false), testValue1.x); 3111 try { 3112 test119(true); 3113 throw new RuntimeException("NullPointerException expected"); 3114 } catch (NullPointerException e) { 3115 // Expected 3116 } 3117 } 3118 3119 @Test 3120 public MyValue1 test120(boolean b) { 3121 MyValue1 val = refArray[0]; 3122 if (b) { 3123 val = null; 3124 } 3125 return val; 3126 } 3127 3128 @Run(test = "test120") 3129 public void test120_verifier() { 3130 refArray[0] = testValue1; 3131 Asserts.assertEquals(test120(false).hash(), testValue1.hash()); 3132 Asserts.assertEquals(test120(true), null); 3133 } 3134 3135 @ForceInline 3136 public Object test121_helper() { 3137 return flatArray[0]; 3138 } 3139 3140 @Test 3141 @IR(applyIf = {"FlatArrayElementMaxSize", "= -1"}, 3142 failOn = {ALLOC_G, STORE}) 3143 public void test121(boolean b) { 3144 Object o = null; 3145 if (b) { 3146 o = refArray[0]; 3147 } else { 3148 o = test121_helper(); 3149 } 3150 if (o == null) { 3151 return; 3152 } 3153 flatArray[0] = (MyValue1)o; 3154 } 3155 3156 @Run(test = "test121") 3157 public void test121_verifier() { 3158 refArray[0] = testValue1; 3159 MyValue1 vt = MyValue1.createWithFieldsInline(rI+1, rL+1); 3160 flatArray[0] = vt; 3161 test121(false); 3162 Asserts.assertEquals(flatArray[0].hash(), vt.hash()); 3163 test121(true); 3164 Asserts.assertEquals(flatArray[0].hash(), testValue1.hash()); 3165 } 3166 3167 @ForceInline 3168 public Object test122_helper() { 3169 return refArray[0]; 3170 } 3171 3172 @Test 3173 @IR(applyIf = {"FlatArrayElementMaxSize", "= -1"}, 3174 failOn = {ALLOC_G, STORE}) 3175 public void test122(boolean b) { 3176 Object o = null; 3177 if (b) { 3178 o = flatArray[0]; 3179 } else { 3180 o = test122_helper(); 3181 } 3182 if (o == null) { 3183 return; 3184 } 3185 flatArray[0] = (MyValue1)o; 3186 } 3187 3188 @Run(test = "test122") 3189 public void test122_verifier() { 3190 refArray[0] = testValue1; 3191 test122(false); 3192 Asserts.assertEquals(flatArray[0].hash(), testValue1.hash()); 3193 MyValue1 vt = MyValue1.createWithFieldsInline(rI+1, rL+1); 3194 flatArray[0] = vt; 3195 test122(true); 3196 Asserts.assertEquals(flatArray[0].hash(), vt.hash()); 3197 } 3198 3199 @ForceInline 3200 public Object test123_helper() { 3201 return refArray[0]; 3202 } 3203 3204 @Test 3205 @IR(failOn = {ALLOC_G, STORE}) 3206 public long test123(boolean b, MyValue1 val, Method m, boolean deopt) { 3207 MyValue1[] array = new MyValue1[1]; 3208 array[0] = val; 3209 Object res = null; 3210 if (b) { 3211 res = array[0]; 3212 } else { 3213 res = test123_helper(); 3214 } 3215 if (deopt) { 3216 // uncommon trap 3217 TestFramework.deoptimize(m); 3218 } 3219 return ((MyValue1)res).hash(); 3220 } 3221 3222 @Run(test = "test123") 3223 public void test123_verifier(RunInfo info) { 3224 refArray[0] = MyValue1.createDefaultInline(); 3225 Asserts.assertEquals(test123(true, testValue1, info.getTest(), false), testValue1.hash()); 3226 Asserts.assertEquals(test123(false, testValue1, info.getTest(), false), MyValue1.createDefaultInline().hash()); 3227 if (!info.isWarmUp()) { 3228 Asserts.assertEquals(test123(true, testValue1, info.getTest(), true), testValue1.hash()); 3229 } 3230 } 3231 3232 @ForceInline 3233 public Object test124_helper(MyValue2 val) { 3234 MyValue2[] array = new MyValue2[1]; 3235 array[0] = val; 3236 return array[0]; 3237 } 3238 3239 @Test 3240 @IR(failOn = {ALLOC_G, STORE}) 3241 public long test124(boolean b, MyValue2 val, Method m, boolean deopt) { 3242 Object res = null; 3243 if (b) { 3244 res = MyValue2.createWithFieldsInline(rI+1, rD+1); 3245 } else { 3246 res = test124_helper(val); 3247 } 3248 if (deopt) { 3249 // uncommon trap 3250 TestFramework.deoptimize(m); 3251 } 3252 return ((MyValue2)res).hash(); 3253 } 3254 3255 @Run(test = "test124") 3256 public void test124_verifier(RunInfo info) { 3257 refArray[0] = MyValue1.createDefaultInline(); 3258 MyValue2 val1 = MyValue2.createWithFieldsInline(rI, rD); 3259 MyValue2 val2 = MyValue2.createWithFieldsInline(rI+1, rD+1); 3260 Asserts.assertEquals(test124(true, val1, info.getTest(), false), val2.hash()); 3261 Asserts.assertEquals(test124(false, val1, info.getTest(), false), val1.hash()); 3262 if (!info.isWarmUp()) { 3263 Asserts.assertEquals(test124(true, val1, info.getTest(), true), val2.hash()); 3264 } 3265 } 3266 3267 @ForceInline 3268 public void test125_helper(Object[] array, MyValue2 val) { 3269 array[0] = val; 3270 } 3271 3272 @Test 3273 @IR(failOn = {ALLOC_G, STORE}) 3274 public long test125(boolean b, MyValue2 val, Method m, boolean deopt) { 3275 Object[] res = new MyValue2[1]; 3276 if (b) { 3277 res[0] = MyValue2.createWithFieldsInline(rI+1, rD+1); 3278 } else { 3279 test125_helper(res, val); 3280 } 3281 val = ((MyValue2)res[0]); 3282 if (deopt) { 3283 // uncommon trap 3284 TestFramework.deoptimize(m); 3285 } 3286 return val.hash(); 3287 } 3288 3289 @Run(test = "test125") 3290 public void test125_verifier(RunInfo info) { 3291 refArray[0] = MyValue1.createDefaultInline(); 3292 MyValue2 val1 = MyValue2.createWithFieldsInline(rI, rD); 3293 MyValue2 val2 = MyValue2.createWithFieldsInline(rI+1, rD+1); 3294 Asserts.assertEquals(test125(true, val1, info.getTest(), false), val2.hash()); 3295 Asserts.assertEquals(test125(false, val1, info.getTest(), false), val1.hash()); 3296 if (!info.isWarmUp()) { 3297 Asserts.assertEquals(test125(true, val1, info.getTest(), true), val2.hash()); 3298 } 3299 } 3300 }