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 instance 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   // Instance fields.
27   //
28 
29   private boolean mZ;
30   private byte mB;
31   private char mC;
32   private short mS;
33   private int mI;
34   private long mJ;
35   private float mF;
36   private double mD;
37   private Object mL;
38 
39   //
40   // Instance arrays.
41   //
42 
43   private boolean[] mArrZ;
44   private byte[] mArrB;
45   private char[] mArrC;
46   private short[] mArrS;
47   private int[] mArrI;
48   private long[] mArrJ;
49   private float[] mArrF;
50   private double[] mArrD;
51   private Object[] mArrL;
52 
53   //
54   // Loops on instance arrays with invariant instance field references.
55   // The checker is used to ensure hoisting occurred.
56   //
57 
58   /// CHECK-START: void Main.InvLoopZ() licm (before)
59   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
60   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
61 
62   /// CHECK-START: void Main.InvLoopZ() licm (after)
63   /// CHECK-DAG: InstanceFieldGet loop:none
64   /// CHECK-DAG: InstanceFieldGet loop:none
65 
InvLoopZ()66   private void InvLoopZ() {
67     for (int i = 0; i < mArrZ.length; i++) {
68       mArrZ[i] = mZ;
69     }
70   }
71 
72   /// CHECK-START: void Main.InvLoopB() licm (before)
73   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
74   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
75 
76   /// CHECK-START: void Main.InvLoopB() licm (after)
77   /// CHECK-DAG: InstanceFieldGet loop:none
78   /// CHECK-DAG: InstanceFieldGet loop:none
79 
InvLoopB()80   private void InvLoopB() {
81     for (int i = 0; i < mArrB.length; i++) {
82       mArrB[i] = mB;
83     }
84   }
85 
86   /// CHECK-START: void Main.InvLoopC() licm (before)
87   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
88   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
89 
90   /// CHECK-START: void Main.InvLoopC() licm (after)
91   /// CHECK-DAG: InstanceFieldGet loop:none
92   /// CHECK-DAG: InstanceFieldGet loop:none
93 
InvLoopC()94   private void InvLoopC() {
95     for (int i = 0; i < mArrC.length; i++) {
96       mArrC[i] = mC;
97     }
98   }
99 
100   /// CHECK-START: void Main.InvLoopS() licm (before)
101   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
102   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
103 
104   /// CHECK-START: void Main.InvLoopS() licm (after)
105   /// CHECK-DAG: InstanceFieldGet loop:none
106   /// CHECK-DAG: InstanceFieldGet loop:none
107 
InvLoopS()108   private void InvLoopS() {
109     for (int i = 0; i < mArrS.length; i++) {
110       mArrS[i] = mS;
111     }
112   }
113 
114   /// CHECK-START: void Main.InvLoopI() licm (before)
115   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
116   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
117 
118   /// CHECK-START: void Main.InvLoopI() licm (after)
119   /// CHECK-DAG: InstanceFieldGet loop:none
120   /// CHECK-DAG: InstanceFieldGet loop:none
121 
InvLoopI()122   private void InvLoopI() {
123     for (int i = 0; i < mArrI.length; i++) {
124       mArrI[i] = mI;
125     }
126   }
127 
128   /// CHECK-START: void Main.InvLoopJ() licm (before)
129   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
130   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
131 
132   /// CHECK-START: void Main.InvLoopJ() licm (after)
133   /// CHECK-DAG: InstanceFieldGet loop:none
134   /// CHECK-DAG: InstanceFieldGet loop:none
135 
InvLoopJ()136   private void InvLoopJ() {
137     for (int i = 0; i < mArrJ.length; i++) {
138       mArrJ[i] = mJ;
139     }
140   }
141 
142   /// CHECK-START: void Main.InvLoopF() licm (before)
143   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
144   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
145 
146   /// CHECK-START: void Main.InvLoopF() licm (after)
147   /// CHECK-DAG: InstanceFieldGet loop:none
148   /// CHECK-DAG: InstanceFieldGet loop:none
149 
InvLoopF()150   private void InvLoopF() {
151     for (int i = 0; i < mArrF.length; i++) {
152       mArrF[i] = mF;
153     }
154   }
155 
156   /// CHECK-START: void Main.InvLoopD() licm (before)
157   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
158   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
159 
160   /// CHECK-START: void Main.InvLoopD() licm (after)
161   /// CHECK-DAG: InstanceFieldGet loop:none
162   /// CHECK-DAG: InstanceFieldGet loop:none
163 
InvLoopD()164   private void InvLoopD() {
165     for (int i = 0; i < mArrD.length; i++) {
166       mArrD[i] = mD;
167     }
168   }
169 
170   /// CHECK-START: void Main.InvLoopL() licm (before)
171   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
172   /// CHECK-DAG: InstanceFieldGet loop:{{B\d+}}
173 
174   /// CHECK-START: void Main.InvLoopL() licm (after)
175   /// CHECK-DAG: InstanceFieldGet loop:none
176   /// CHECK-DAG: InstanceFieldGet loop:none
177 
InvLoopL()178   private void InvLoopL() {
179     for (int i = 0; i < mArrL.length; i++) {
180       mArrL[i] = mL;
181     }
182   }
183 
184   //
185   // Loops on instance arrays with variant instance field references.
186   // Incorrect hoisting is detected by incorrect outcome.
187   //
188 
VarLoopZ()189   private void VarLoopZ() {
190     for (int i = 0; i < mArrZ.length; i++) {
191       mArrZ[i] = mZ;
192       if (i == 10)
193         mZ = !mZ;
194     }
195   }
196 
VarLoopB()197   private void VarLoopB() {
198     for (int i = 0; i < mArrB.length; i++) {
199       mArrB[i] = mB;
200       if (i == 10)
201         mB++;
202     }
203   }
204 
VarLoopC()205   private void VarLoopC() {
206     for (int i = 0; i < mArrC.length; i++) {
207       mArrC[i] = mC;
208       if (i == 10)
209         mC++;
210     }
211   }
212 
VarLoopS()213   private void VarLoopS() {
214     for (int i = 0; i < mArrS.length; i++) {
215       mArrS[i] = mS;
216       if (i == 10)
217         mS++;
218     }
219   }
220 
VarLoopI()221   private void VarLoopI() {
222     for (int i = 0; i < mArrI.length; i++) {
223       mArrI[i] = mI;
224       if (i == 10)
225         mI++;
226     }
227   }
228 
VarLoopJ()229   private void VarLoopJ() {
230     for (int i = 0; i < mArrJ.length; i++) {
231       mArrJ[i] = mJ;
232       if (i == 10)
233         mJ++;
234     }
235   }
236 
VarLoopF()237   private void VarLoopF() {
238     for (int i = 0; i < mArrF.length; i++) {
239       mArrF[i] = mF;
240       if (i == 10)
241         mF++;
242     }
243   }
244 
VarLoopD()245   private void VarLoopD() {
246     for (int i = 0; i < mArrD.length; i++) {
247       mArrD[i] = mD;
248       if (i == 10)
249         mD++;
250     }
251   }
252 
VarLoopL()253   private void VarLoopL() {
254     for (int i = 0; i < mArrL.length; i++) {
255       mArrL[i] = mL;
256       if (i == 10)
257         mL = anotherObject;
258     }
259   }
260 
261   //
262   // Loops on instance 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 void CrossOverLoopZ() {
278     mArrZ[20] = false;
279     for (int i = 0; i < mArrZ.length; i++) {
280       mArrZ[i] = !mArrZ[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 void CrossOverLoopB() {
295     mArrB[20] = 111;
296     for (int i = 0; i < mArrB.length; i++) {
297       mArrB[i] = (byte)(mArrB[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 void CrossOverLoopC() {
312     mArrC[20] = 111;
313     for (int i = 0; i < mArrC.length; i++) {
314       mArrC[i] = (char)(mArrC[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 void CrossOverLoopS() {
329     mArrS[20] = 111;
330     for (int i = 0; i < mArrS.length; i++) {
331       mArrS[i] = (short)(mArrS[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 void CrossOverLoopI() {
346     mArrI[20] = 111;
347     for (int i = 0; i < mArrI.length; i++) {
348       mArrI[i] = mArrI[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 void CrossOverLoopJ() {
363     mArrJ[20] = 111;
364     for (int i = 0; i < mArrJ.length; i++) {
365       mArrJ[i] = mArrJ[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 void CrossOverLoopF() {
380     mArrF[20] = 111;
381     for (int i = 0; i < mArrF.length; i++) {
382       mArrF[i] = mArrF[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 void CrossOverLoopD() {
397     mArrD[20] = 111;
398     for (int i = 0; i < mArrD.length; i++) {
399       mArrD[i] = mArrD[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 void CrossOverLoopL() {
414     mArrL[20] = anotherObject;
415     for (int i = 0; i < mArrL.length; i++) {
416       mArrL[i] = (mArrL[20] == anObject) ? anotherObject : anObject;
417     }
418   }
419 
420   //
421   // False cross-over loops on instance 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 void FalseCrossOverLoop1() {
437     mArrF[20] = -1;
438     for (int i = 0; i < mArrI.length; i++) {
439       mArrI[i] = (int) mArrF[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 void FalseCrossOverLoop2() {
454     mArrI[20] = -2;
455     for (int i = 0; i < mArrF.length; i++) {
456       mArrF[i] = mArrI[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 void FalseCrossOverLoop3() {
471     mArrD[20] = -3;
472     for (int i = 0; i < mArrJ.length; i++) {
473       mArrJ[i] = (long) mArrD[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 void FalseCrossOverLoop4() {
488     mArrJ[20] = -4;
489     for (int i = 0; i < mArrD.length; i++) {
490       mArrD[i] = mArrJ[20] - 2;
491     }
492   }
493 
494   //
495   // Main driver and testers.
496   //
497 
main(String[] args)498   public static void main(String[] args) {
499     new Main().DoInstanceTests();
500     System.out.println("passed");
501   }
502 
DoInstanceTests()503   private void DoInstanceTests() {
504     // Type Z.
505     mZ = true;
506     mArrZ = new boolean[100];
507     InvLoopZ();
508     for (int i = 0; i < mArrZ.length; i++) {
509       expectEquals(true, mArrZ[i]);
510     }
511     VarLoopZ();
512     for (int i = 0; i < mArrZ.length; i++) {
513       expectEquals(i <= 10, mArrZ[i]);
514     }
515     CrossOverLoopZ();
516     for (int i = 0; i < mArrZ.length; i++) {
517       expectEquals(i <= 20, mArrZ[i]);
518     }
519     // Type B.
520     mB = 1;
521     mArrB = new byte[100];
522     InvLoopB();
523     for (int i = 0; i < mArrB.length; i++) {
524       expectEquals(1, mArrB[i]);
525     }
526     VarLoopB();
527     for (int i = 0; i < mArrB.length; i++) {
528       expectEquals(i <= 10 ? 1 : 2, mArrB[i]);
529     }
530     CrossOverLoopB();
531     for (int i = 0; i < mArrB.length; i++) {
532       expectEquals(i <= 20 ? 113 : 115, mArrB[i]);
533     }
534     // Type C.
535     mC = 2;
536     mArrC = new char[100];
537     InvLoopC();
538     for (int i = 0; i < mArrC.length; i++) {
539       expectEquals(2, mArrC[i]);
540     }
541     VarLoopC();
542     for (int i = 0; i < mArrC.length; i++) {
543       expectEquals(i <= 10 ? 2 : 3, mArrC[i]);
544     }
545     CrossOverLoopC();
546     for (int i = 0; i < mArrC.length; i++) {
547       expectEquals(i <= 20 ? 113 : 115, mArrC[i]);
548     }
549     // Type S.
550     mS = 3;
551     mArrS = new short[100];
552     InvLoopS();
553     for (int i = 0; i < mArrS.length; i++) {
554       expectEquals(3, mArrS[i]);
555     }
556     VarLoopS();
557     for (int i = 0; i < mArrS.length; i++) {
558       expectEquals(i <= 10 ? 3 : 4, mArrS[i]);
559     }
560     CrossOverLoopS();
561     for (int i = 0; i < mArrS.length; i++) {
562       expectEquals(i <= 20 ? 113 : 115, mArrS[i]);
563     }
564     // Type I.
565     mI = 4;
566     mArrI = new int[100];
567     InvLoopI();
568     for (int i = 0; i < mArrI.length; i++) {
569       expectEquals(4, mArrI[i]);
570     }
571     VarLoopI();
572     for (int i = 0; i < mArrI.length; i++) {
573       expectEquals(i <= 10 ? 4 : 5, mArrI[i]);
574     }
575     CrossOverLoopI();
576     for (int i = 0; i < mArrI.length; i++) {
577       expectEquals(i <= 20 ? 113 : 115, mArrI[i]);
578     }
579     // Type J.
580     mJ = 5;
581     mArrJ = new long[100];
582     InvLoopJ();
583     for (int i = 0; i < mArrJ.length; i++) {
584       expectEquals(5, mArrJ[i]);
585     }
586     VarLoopJ();
587     for (int i = 0; i < mArrJ.length; i++) {
588       expectEquals(i <= 10 ? 5 : 6, mArrJ[i]);
589     }
590     CrossOverLoopJ();
591     for (int i = 0; i < mArrJ.length; i++) {
592       expectEquals(i <= 20 ? 113 : 115, mArrJ[i]);
593     }
594     // Type F.
595     mF = 6.0f;
596     mArrF = new float[100];
597     InvLoopF();
598     for (int i = 0; i < mArrF.length; i++) {
599       expectEquals(6, mArrF[i]);
600     }
601     VarLoopF();
602     for (int i = 0; i < mArrF.length; i++) {
603       expectEquals(i <= 10 ? 6 : 7, mArrF[i]);
604     }
605     CrossOverLoopF();
606     for (int i = 0; i < mArrF.length; i++) {
607       expectEquals(i <= 20 ? 113 : 115, mArrF[i]);
608     }
609     // Type D.
610     mD = 7.0;
611     mArrD = new double[100];
612     InvLoopD();
613     for (int i = 0; i < mArrD.length; i++) {
614       expectEquals(7.0, mArrD[i]);
615     }
616     VarLoopD();
617     for (int i = 0; i < mArrD.length; i++) {
618       expectEquals(i <= 10 ? 7 : 8, mArrD[i]);
619     }
620     CrossOverLoopD();
621     for (int i = 0; i < mArrD.length; i++) {
622       expectEquals(i <= 20 ? 113 : 115, mArrD[i]);
623     }
624     // Type L.
625     mL = anObject;
626     mArrL = new Object[100];
627     InvLoopL();
628     for (int i = 0; i < mArrL.length; i++) {
629       expectEquals(anObject, mArrL[i]);
630     }
631     VarLoopL();
632     for (int i = 0; i < mArrL.length; i++) {
633       expectEquals(i <= 10 ? anObject : anotherObject, mArrL[i]);
634     }
635     CrossOverLoopL();
636     for (int i = 0; i < mArrL.length; i++) {
637       expectEquals(i <= 20 ? anObject : anotherObject, mArrL[i]);
638     }
639     // False cross-over.
640     FalseCrossOverLoop1();
641     for (int i = 0; i < mArrI.length; i++) {
642       expectEquals(-3, mArrI[i]);
643     }
644     FalseCrossOverLoop2();
645     for (int i = 0; i < mArrF.length; i++) {
646       expectEquals(-4, mArrF[i]);
647     }
648     FalseCrossOverLoop3();
649     for (int i = 0; i < mArrJ.length; i++) {
650       expectEquals(-5, mArrJ[i]);
651     }
652     FalseCrossOverLoop4();
653     for (int i = 0; i < mArrD.length; i++) {
654       expectEquals(-6, mArrD[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