1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // 18 // Test on (in)variant static field and array references in loops. 19 // 20 public class Main { 21 22 private static Object anObject = new Object(); 23 private static Object anotherObject = new Object(); 24 25 // 26 // Static fields. 27 // 28 29 private static boolean sZ; 30 private static byte sB; 31 private static char sC; 32 private static short sS; 33 private static int sI; 34 private static long sJ; 35 private static float sF; 36 private static double sD; 37 private static Object sL; 38 39 // 40 // Static arrays. 41 // 42 43 private static boolean[] sArrZ; 44 private static byte[] sArrB; 45 private static char[] sArrC; 46 private static short[] sArrS; 47 private static int[] sArrI; 48 private static long[] sArrJ; 49 private static float[] sArrF; 50 private static double[] sArrD; 51 private static Object[] sArrL; 52 53 // 54 // Loops on static arrays with invariant static field references. 55 // The checker is used to ensure hoisting occurred. 56 // 57 58 /// CHECK-START: void Main.InvLoopZ() licm (before) 59 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 60 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 61 62 /// CHECK-START: void Main.InvLoopZ() licm (after) 63 /// CHECK-DAG: StaticFieldGet loop:none 64 /// CHECK-DAG: StaticFieldGet loop:none 65 InvLoopZ()66 private static void InvLoopZ() { 67 for (int i = 0; i < sArrZ.length; i++) { 68 sArrZ[i] = sZ; 69 } 70 } 71 72 /// CHECK-START: void Main.InvLoopB() licm (before) 73 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 74 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 75 76 /// CHECK-START: void Main.InvLoopB() licm (after) 77 /// CHECK-DAG: StaticFieldGet loop:none 78 /// CHECK-DAG: StaticFieldGet loop:none 79 InvLoopB()80 private static void InvLoopB() { 81 for (int i = 0; i < sArrB.length; i++) { 82 sArrB[i] = sB; 83 } 84 } 85 86 /// CHECK-START: void Main.InvLoopC() licm (before) 87 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 88 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 89 90 /// CHECK-START: void Main.InvLoopC() licm (after) 91 /// CHECK-DAG: StaticFieldGet loop:none 92 /// CHECK-DAG: StaticFieldGet loop:none 93 InvLoopC()94 private static void InvLoopC() { 95 for (int i = 0; i < sArrC.length; i++) { 96 sArrC[i] = sC; 97 } 98 } 99 100 /// CHECK-START: void Main.InvLoopS() licm (before) 101 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 102 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 103 104 /// CHECK-START: void Main.InvLoopS() licm (after) 105 /// CHECK-DAG: StaticFieldGet loop:none 106 /// CHECK-DAG: StaticFieldGet loop:none 107 InvLoopS()108 private static void InvLoopS() { 109 for (int i = 0; i < sArrS.length; i++) { 110 sArrS[i] = sS; 111 } 112 } 113 114 /// CHECK-START: void Main.InvLoopI() licm (before) 115 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 116 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 117 118 /// CHECK-START: void Main.InvLoopI() licm (after) 119 /// CHECK-DAG: StaticFieldGet loop:none 120 /// CHECK-DAG: StaticFieldGet loop:none 121 InvLoopI()122 private static void InvLoopI() { 123 for (int i = 0; i < sArrI.length; i++) { 124 sArrI[i] = sI; 125 } 126 } 127 128 /// CHECK-START: void Main.InvLoopJ() licm (before) 129 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 130 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 131 132 /// CHECK-START: void Main.InvLoopJ() licm (after) 133 /// CHECK-DAG: StaticFieldGet loop:none 134 /// CHECK-DAG: StaticFieldGet loop:none 135 InvLoopJ()136 private static void InvLoopJ() { 137 for (int i = 0; i < sArrJ.length; i++) { 138 sArrJ[i] = sJ; 139 } 140 } 141 142 /// CHECK-START: void Main.InvLoopF() licm (before) 143 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 144 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 145 146 /// CHECK-START: void Main.InvLoopF() licm (after) 147 /// CHECK-DAG: StaticFieldGet loop:none 148 /// CHECK-DAG: StaticFieldGet loop:none 149 InvLoopF()150 private static void InvLoopF() { 151 for (int i = 0; i < sArrF.length; i++) { 152 sArrF[i] = sF; 153 } 154 } 155 156 /// CHECK-START: void Main.InvLoopD() licm (before) 157 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 158 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 159 160 /// CHECK-START: void Main.InvLoopD() licm (after) 161 /// CHECK-DAG: StaticFieldGet loop:none 162 /// CHECK-DAG: StaticFieldGet loop:none 163 InvLoopD()164 private static void InvLoopD() { 165 for (int i = 0; i < sArrD.length; i++) { 166 sArrD[i] = sD; 167 } 168 } 169 170 /// CHECK-START: void Main.InvLoopL() licm (before) 171 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 172 /// CHECK-DAG: StaticFieldGet loop:{{B\d+}} 173 174 /// CHECK-START: void Main.InvLoopL() licm (after) 175 /// CHECK-DAG: StaticFieldGet loop:none 176 /// CHECK-DAG: StaticFieldGet loop:none 177 InvLoopL()178 private static void InvLoopL() { 179 for (int i = 0; i < sArrL.length; i++) { 180 sArrL[i] = sL; 181 } 182 } 183 184 // 185 // Loops on static arrays with variant static field references. 186 // Incorrect hoisting is detected by incorrect outcome. 187 // 188 VarLoopZ()189 private static void VarLoopZ() { 190 for (int i = 0; i < sArrZ.length; i++) { 191 sArrZ[i] = sZ; 192 if (i == 10) 193 sZ = !sZ; 194 } 195 } 196 VarLoopB()197 private static void VarLoopB() { 198 for (int i = 0; i < sArrB.length; i++) { 199 sArrB[i] = sB; 200 if (i == 10) 201 sB++; 202 } 203 } 204 VarLoopC()205 private static void VarLoopC() { 206 for (int i = 0; i < sArrC.length; i++) { 207 sArrC[i] = sC; 208 if (i == 10) 209 sC++; 210 } 211 } 212 VarLoopS()213 private static void VarLoopS() { 214 for (int i = 0; i < sArrS.length; i++) { 215 sArrS[i] = sS; 216 if (i == 10) 217 sS++; 218 } 219 } 220 VarLoopI()221 private static void VarLoopI() { 222 for (int i = 0; i < sArrI.length; i++) { 223 sArrI[i] = sI; 224 if (i == 10) 225 sI++; 226 } 227 } 228 VarLoopJ()229 private static void VarLoopJ() { 230 for (int i = 0; i < sArrJ.length; i++) { 231 sArrJ[i] = sJ; 232 if (i == 10) 233 sJ++; 234 } 235 } 236 VarLoopF()237 private static void VarLoopF() { 238 for (int i = 0; i < sArrF.length; i++) { 239 sArrF[i] = sF; 240 if (i == 10) 241 sF++; 242 } 243 } 244 VarLoopD()245 private static void VarLoopD() { 246 for (int i = 0; i < sArrD.length; i++) { 247 sArrD[i] = sD; 248 if (i == 10) 249 sD++; 250 } 251 } 252 VarLoopL()253 private static void VarLoopL() { 254 for (int i = 0; i < sArrL.length; i++) { 255 sArrL[i] = sL; 256 if (i == 10) 257 sL = anotherObject; 258 } 259 } 260 261 // 262 // Loops on static arrays with a cross-over reference. 263 // Incorrect hoisting is detected by incorrect outcome. 264 // In addition, the checker is used to detect no hoisting. 265 // 266 267 /// CHECK-START: void Main.CrossOverLoopZ() licm (before) 268 /// CHECK-DAG: ArraySet loop:none 269 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 270 /// CHECK-DAG: ArraySet loop:{{B\d+}} 271 272 /// CHECK-START: void Main.CrossOverLoopZ() licm (after) 273 /// CHECK-DAG: ArraySet loop:none 274 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 275 /// CHECK-DAG: ArraySet loop:{{B\d+}} 276 CrossOverLoopZ()277 private static void CrossOverLoopZ() { 278 sArrZ[20] = false; 279 for (int i = 0; i < sArrZ.length; i++) { 280 sArrZ[i] = !sArrZ[20]; 281 } 282 } 283 284 /// CHECK-START: void Main.CrossOverLoopB() licm (before) 285 /// CHECK-DAG: ArraySet loop:none 286 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 287 /// CHECK-DAG: ArraySet loop:{{B\d+}} 288 289 /// CHECK-START: void Main.CrossOverLoopB() licm (after) 290 /// CHECK-DAG: ArraySet loop:none 291 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 292 /// CHECK-DAG: ArraySet loop:{{B\d+}} 293 CrossOverLoopB()294 private static void CrossOverLoopB() { 295 sArrB[20] = 11; 296 for (int i = 0; i < sArrB.length; i++) { 297 sArrB[i] = (byte)(sArrB[20] + 2); 298 } 299 } 300 301 /// CHECK-START: void Main.CrossOverLoopC() licm (before) 302 /// CHECK-DAG: ArraySet loop:none 303 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 304 /// CHECK-DAG: ArraySet loop:{{B\d+}} 305 306 /// CHECK-START: void Main.CrossOverLoopC() licm (after) 307 /// CHECK-DAG: ArraySet loop:none 308 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 309 /// CHECK-DAG: ArraySet loop:{{B\d+}} 310 CrossOverLoopC()311 private static void CrossOverLoopC() { 312 sArrC[20] = 11; 313 for (int i = 0; i < sArrC.length; i++) { 314 sArrC[i] = (char)(sArrC[20] + 2); 315 } 316 } 317 318 /// CHECK-START: void Main.CrossOverLoopS() licm (before) 319 /// CHECK-DAG: ArraySet loop:none 320 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 321 /// CHECK-DAG: ArraySet loop:{{B\d+}} 322 323 /// CHECK-START: void Main.CrossOverLoopS() licm (after) 324 /// CHECK-DAG: ArraySet loop:none 325 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 326 /// CHECK-DAG: ArraySet loop:{{B\d+}} 327 CrossOverLoopS()328 private static void CrossOverLoopS() { 329 sArrS[20] = 11; 330 for (int i = 0; i < sArrS.length; i++) { 331 sArrS[i] = (short)(sArrS[20] + 2); 332 } 333 } 334 335 /// CHECK-START: void Main.CrossOverLoopI() licm (before) 336 /// CHECK-DAG: ArraySet loop:none 337 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 338 /// CHECK-DAG: ArraySet loop:{{B\d+}} 339 340 /// CHECK-START: void Main.CrossOverLoopI() licm (after) 341 /// CHECK-DAG: ArraySet loop:none 342 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 343 /// CHECK-DAG: ArraySet loop:{{B\d+}} 344 CrossOverLoopI()345 private static void CrossOverLoopI() { 346 sArrI[20] = 11; 347 for (int i = 0; i < sArrI.length; i++) { 348 sArrI[i] = sArrI[20] + 2; 349 } 350 } 351 352 /// CHECK-START: void Main.CrossOverLoopJ() licm (before) 353 /// CHECK-DAG: ArraySet loop:none 354 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 355 /// CHECK-DAG: ArraySet loop:{{B\d+}} 356 357 /// CHECK-START: void Main.CrossOverLoopJ() licm (after) 358 /// CHECK-DAG: ArraySet loop:none 359 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 360 /// CHECK-DAG: ArraySet loop:{{B\d+}} 361 CrossOverLoopJ()362 private static void CrossOverLoopJ() { 363 sArrJ[20] = 11; 364 for (int i = 0; i < sArrJ.length; i++) { 365 sArrJ[i] = sArrJ[20] + 2; 366 } 367 } 368 369 /// CHECK-START: void Main.CrossOverLoopF() licm (before) 370 /// CHECK-DAG: ArraySet loop:none 371 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 372 /// CHECK-DAG: ArraySet loop:{{B\d+}} 373 374 /// CHECK-START: void Main.CrossOverLoopF() licm (after) 375 /// CHECK-DAG: ArraySet loop:none 376 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 377 /// CHECK-DAG: ArraySet loop:{{B\d+}} 378 CrossOverLoopF()379 private static void CrossOverLoopF() { 380 sArrF[20] = 11; 381 for (int i = 0; i < sArrF.length; i++) { 382 sArrF[i] = sArrF[20] + 2; 383 } 384 } 385 386 /// CHECK-START: void Main.CrossOverLoopD() licm (before) 387 /// CHECK-DAG: ArraySet loop:none 388 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 389 /// CHECK-DAG: ArraySet loop:{{B\d+}} 390 391 /// CHECK-START: void Main.CrossOverLoopD() licm (after) 392 /// CHECK-DAG: ArraySet loop:none 393 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 394 /// CHECK-DAG: ArraySet loop:{{B\d+}} 395 CrossOverLoopD()396 private static void CrossOverLoopD() { 397 sArrD[20] = 11; 398 for (int i = 0; i < sArrD.length; i++) { 399 sArrD[i] = sArrD[20] + 2; 400 } 401 } 402 403 /// CHECK-START: void Main.CrossOverLoopL() licm (before) 404 /// CHECK-DAG: ArraySet loop:none 405 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 406 /// CHECK-DAG: ArraySet loop:{{B\d+}} 407 408 /// CHECK-START: void Main.CrossOverLoopL() licm (after) 409 /// CHECK-DAG: ArraySet loop:none 410 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 411 /// CHECK-DAG: ArraySet loop:{{B\d+}} 412 CrossOverLoopL()413 private static void CrossOverLoopL() { 414 sArrL[20] = anotherObject; 415 for (int i = 0; i < sArrL.length; i++) { 416 sArrL[i] = (sArrL[20] == anObject) ? anotherObject : anObject; 417 } 418 } 419 420 // 421 // False cross-over loops on static arrays with data types (I/F and J/D) that used 422 // to be aliased in an older version of the compiler. This alias has been removed, 423 // however, which enables hoisting the invariant array reference. 424 // 425 426 /// CHECK-START: void Main.FalseCrossOverLoop1() licm (before) 427 /// CHECK-DAG: ArraySet loop:none 428 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 429 /// CHECK-DAG: ArraySet loop:{{B\d+}} 430 431 /// CHECK-START: void Main.FalseCrossOverLoop1() licm (after) 432 /// CHECK-DAG: ArraySet loop:none 433 /// CHECK-DAG: ArrayGet loop:none 434 /// CHECK-DAG: ArraySet loop:{{B\d+}} 435 FalseCrossOverLoop1()436 private static void FalseCrossOverLoop1() { 437 sArrF[20] = -1; 438 for (int i = 0; i < sArrI.length; i++) { 439 sArrI[i] = (int) sArrF[20] - 2; 440 } 441 } 442 443 /// CHECK-START: void Main.FalseCrossOverLoop2() licm (before) 444 /// CHECK-DAG: ArraySet loop:none 445 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 446 /// CHECK-DAG: ArraySet loop:{{B\d+}} 447 448 /// CHECK-START: void Main.FalseCrossOverLoop2() licm (after) 449 /// CHECK-DAG: ArraySet loop:none 450 /// CHECK-DAG: ArrayGet loop:none 451 /// CHECK-DAG: ArraySet loop:{{B\d+}} 452 FalseCrossOverLoop2()453 private static void FalseCrossOverLoop2() { 454 sArrI[20] = -2; 455 for (int i = 0; i < sArrF.length; i++) { 456 sArrF[i] = sArrI[20] - 2; 457 } 458 } 459 460 /// CHECK-START: void Main.FalseCrossOverLoop3() licm (before) 461 /// CHECK-DAG: ArraySet loop:none 462 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 463 /// CHECK-DAG: ArraySet loop:{{B\d+}} 464 465 /// CHECK-START: void Main.FalseCrossOverLoop3() licm (after) 466 /// CHECK-DAG: ArraySet loop:none 467 /// CHECK-DAG: ArrayGet loop:none 468 /// CHECK-DAG: ArraySet loop:{{B\d+}} 469 FalseCrossOverLoop3()470 private static void FalseCrossOverLoop3() { 471 sArrD[20] = -3; 472 for (int i = 0; i < sArrJ.length; i++) { 473 sArrJ[i] = (long) sArrD[20] - 2; 474 } 475 } 476 477 /// CHECK-START: void Main.FalseCrossOverLoop4() licm (before) 478 /// CHECK-DAG: ArraySet loop:none 479 /// CHECK-DAG: ArrayGet loop:{{B\d+}} 480 /// CHECK-DAG: ArraySet loop:{{B\d+}} 481 482 /// CHECK-START: void Main.FalseCrossOverLoop4() licm (after) 483 /// CHECK-DAG: ArraySet loop:none 484 /// CHECK-DAG: ArrayGet loop:none 485 /// CHECK-DAG: ArraySet loop:{{B\d+}} 486 FalseCrossOverLoop4()487 private static void FalseCrossOverLoop4() { 488 sArrJ[20] = -4; 489 for (int i = 0; i < sArrD.length; i++) { 490 sArrD[i] = sArrJ[20] - 2; 491 } 492 } 493 494 // 495 // Main driver and testers. 496 // 497 main(String[] args)498 public static void main(String[] args) { 499 DoStaticTests(); 500 System.out.println("passed"); 501 } 502 DoStaticTests()503 private static void DoStaticTests() { 504 // Type Z. 505 sZ = true; 506 sArrZ = new boolean[100]; 507 InvLoopZ(); 508 for (int i = 0; i < sArrZ.length; i++) { 509 expectEquals(true, sArrZ[i]); 510 } 511 VarLoopZ(); 512 for (int i = 0; i < sArrZ.length; i++) { 513 expectEquals(i <= 10, sArrZ[i]); 514 } 515 CrossOverLoopZ(); 516 for (int i = 0; i < sArrZ.length; i++) { 517 expectEquals(i <= 20, sArrZ[i]); 518 } 519 // Type B. 520 sB = 1; 521 sArrB = new byte[100]; 522 InvLoopB(); 523 for (int i = 0; i < sArrB.length; i++) { 524 expectEquals(1, sArrB[i]); 525 } 526 VarLoopB(); 527 for (int i = 0; i < sArrB.length; i++) { 528 expectEquals(i <= 10 ? 1 : 2, sArrB[i]); 529 } 530 CrossOverLoopB(); 531 for (int i = 0; i < sArrB.length; i++) { 532 expectEquals(i <= 20 ? 13 : 15, sArrB[i]); 533 } 534 // Type C. 535 sC = 2; 536 sArrC = new char[100]; 537 InvLoopC(); 538 for (int i = 0; i < sArrC.length; i++) { 539 expectEquals(2, sArrC[i]); 540 } 541 VarLoopC(); 542 for (int i = 0; i < sArrC.length; i++) { 543 expectEquals(i <= 10 ? 2 : 3, sArrC[i]); 544 } 545 CrossOverLoopC(); 546 for (int i = 0; i < sArrC.length; i++) { 547 expectEquals(i <= 20 ? 13 : 15, sArrC[i]); 548 } 549 // Type S. 550 sS = 3; 551 sArrS = new short[100]; 552 InvLoopS(); 553 for (int i = 0; i < sArrS.length; i++) { 554 expectEquals(3, sArrS[i]); 555 } 556 VarLoopS(); 557 for (int i = 0; i < sArrS.length; i++) { 558 expectEquals(i <= 10 ? 3 : 4, sArrS[i]); 559 } 560 CrossOverLoopS(); 561 for (int i = 0; i < sArrS.length; i++) { 562 expectEquals(i <= 20 ? 13 : 15, sArrS[i]); 563 } 564 // Type I. 565 sI = 4; 566 sArrI = new int[100]; 567 InvLoopI(); 568 for (int i = 0; i < sArrI.length; i++) { 569 expectEquals(4, sArrI[i]); 570 } 571 VarLoopI(); 572 for (int i = 0; i < sArrI.length; i++) { 573 expectEquals(i <= 10 ? 4 : 5, sArrI[i]); 574 } 575 CrossOverLoopI(); 576 for (int i = 0; i < sArrI.length; i++) { 577 expectEquals(i <= 20 ? 13 : 15, sArrI[i]); 578 } 579 // Type J. 580 sJ = 5; 581 sArrJ = new long[100]; 582 InvLoopJ(); 583 for (int i = 0; i < sArrJ.length; i++) { 584 expectEquals(5, sArrJ[i]); 585 } 586 VarLoopJ(); 587 for (int i = 0; i < sArrJ.length; i++) { 588 expectEquals(i <= 10 ? 5 : 6, sArrJ[i]); 589 } 590 CrossOverLoopJ(); 591 for (int i = 0; i < sArrJ.length; i++) { 592 expectEquals(i <= 20 ? 13 : 15, sArrJ[i]); 593 } 594 // Type F. 595 sF = 6.0f; 596 sArrF = new float[100]; 597 InvLoopF(); 598 for (int i = 0; i < sArrF.length; i++) { 599 expectEquals(6, sArrF[i]); 600 } 601 VarLoopF(); 602 for (int i = 0; i < sArrF.length; i++) { 603 expectEquals(i <= 10 ? 6 : 7, sArrF[i]); 604 } 605 CrossOverLoopF(); 606 for (int i = 0; i < sArrF.length; i++) { 607 expectEquals(i <= 20 ? 13 : 15, sArrF[i]); 608 } 609 // Type D. 610 sD = 7.0; 611 sArrD = new double[100]; 612 InvLoopD(); 613 for (int i = 0; i < sArrD.length; i++) { 614 expectEquals(7.0, sArrD[i]); 615 } 616 VarLoopD(); 617 for (int i = 0; i < sArrD.length; i++) { 618 expectEquals(i <= 10 ? 7 : 8, sArrD[i]); 619 } 620 CrossOverLoopD(); 621 for (int i = 0; i < sArrD.length; i++) { 622 expectEquals(i <= 20 ? 13 : 15, sArrD[i]); 623 } 624 // Type L. 625 sL = anObject; 626 sArrL = new Object[100]; 627 InvLoopL(); 628 for (int i = 0; i < sArrL.length; i++) { 629 expectEquals(anObject, sArrL[i]); 630 } 631 VarLoopL(); 632 for (int i = 0; i < sArrL.length; i++) { 633 expectEquals(i <= 10 ? anObject : anotherObject, sArrL[i]); 634 } 635 CrossOverLoopL(); 636 for (int i = 0; i < sArrL.length; i++) { 637 expectEquals(i <= 20 ? anObject : anotherObject, sArrL[i]); 638 } 639 // False cross-over. 640 FalseCrossOverLoop1(); 641 for (int i = 0; i < sArrI.length; i++) { 642 expectEquals(-3, sArrI[i]); 643 } 644 FalseCrossOverLoop2(); 645 for (int i = 0; i < sArrF.length; i++) { 646 expectEquals(-4, sArrF[i]); 647 } 648 FalseCrossOverLoop3(); 649 for (int i = 0; i < sArrJ.length; i++) { 650 expectEquals(-5, sArrJ[i]); 651 } 652 FalseCrossOverLoop4(); 653 for (int i = 0; i < sArrD.length; i++) { 654 expectEquals(-6, sArrD[i]); 655 } 656 } 657 expectEquals(boolean expected, boolean result)658 private static void expectEquals(boolean expected, boolean result) { 659 if (expected != result) { 660 throw new Error("Expected: " + expected + ", found: " + result); 661 } 662 } 663 expectEquals(byte expected, byte result)664 private static void expectEquals(byte expected, byte result) { 665 if (expected != result) { 666 throw new Error("Expected: " + expected + ", found: " + result); 667 } 668 } 669 expectEquals(char expected, char result)670 private static void expectEquals(char expected, char result) { 671 if (expected != result) { 672 throw new Error("Expected: " + expected + ", found: " + result); 673 } 674 } 675 expectEquals(short expected, short result)676 private static void expectEquals(short expected, short result) { 677 if (expected != result) { 678 throw new Error("Expected: " + expected + ", found: " + result); 679 } 680 } 681 expectEquals(int expected, int result)682 private static void expectEquals(int expected, int result) { 683 if (expected != result) { 684 throw new Error("Expected: " + expected + ", found: " + result); 685 } 686 } 687 expectEquals(long expected, long result)688 private static void expectEquals(long expected, long result) { 689 if (expected != result) { 690 throw new Error("Expected: " + expected + ", found: " + result); 691 } 692 } 693 expectEquals(float expected, float result)694 private static void expectEquals(float expected, float result) { 695 if (expected != result) { 696 throw new Error("Expected: " + expected + ", found: " + result); 697 } 698 } 699 expectEquals(double expected, double result)700 private static void expectEquals(double expected, double result) { 701 if (expected != result) { 702 throw new Error("Expected: " + expected + ", found: " + result); 703 } 704 } 705 expectEquals(Object expected, Object result)706 private static void expectEquals(Object expected, Object result) { 707 if (expected != result) { 708 throw new Error("Expected: " + expected + ", found: " + result); 709 } 710 } 711 } 712