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
17public class Main {
18  public static boolean doThrow = false;
19
20  private Object objectField;
21  private int intField;
22  private float floatField;
23  private long longField;
24  private double doubleField;
25  private byte byteField;
26  private boolean booleanField;
27  private char charField;
28  private short shortField;
29
30  private volatile Object volatileObjectField;
31  private volatile int volatileIntField;
32  private volatile float volatileFloatField;
33  private volatile long volatileLongField;
34  private volatile double volatileDoubleField;
35  private volatile byte volatileByteField;
36  private volatile boolean volatileBooleanField;
37  private volatile char volatileCharField;
38  private volatile short volatileShortField;
39
40  public static void $opt$noinline$setObjectField(Main m) {
41    if (doThrow) { throw new Error(); }
42    m.objectField = null;
43  }
44
45  public static void $opt$noinline$setIntField(Main m) {
46    if (doThrow) { throw new Error(); }
47    m.intField = 0;
48  }
49
50  public static void $opt$noinline$setFloatField(Main m) {
51    if (doThrow) { throw new Error(); }
52    m.floatField = 0;
53  }
54
55  public static void $opt$noinline$setLongField(Main m) {
56    if (doThrow) { throw new Error(); }
57    m.longField = 0;
58  }
59
60  public static void $opt$noinline$setDoubleField(Main m) {
61    if (doThrow) { throw new Error(); }
62    m.doubleField = 0;
63  }
64
65  public static void $opt$noinline$setByteField(Main m) {
66    if (doThrow) { throw new Error(); }
67    m.byteField = 0;
68  }
69
70  public static void $opt$noinline$setBooleanField(Main m) {
71    if (doThrow) { throw new Error(); }
72    m.booleanField = false;
73  }
74
75  public static void $opt$noinline$setCharField(Main m) {
76    if (doThrow) { throw new Error(); }
77    m.charField = 0;
78  }
79
80  public static void $opt$noinline$setShortField(Main m) {
81    if (doThrow) { throw new Error(); }
82    m.shortField = 0;
83  }
84
85  public static Object $opt$noinline$getObjectField(Main m) {
86    if (doThrow) { throw new Error(); }
87    return m.objectField;
88  }
89
90  public static int $opt$noinline$getIntField(Main m) {
91    if (doThrow) { throw new Error(); }
92    return m.intField;
93  }
94
95  public static float $opt$noinline$getFloatField(Main m) {
96    if (doThrow) { throw new Error(); }
97    return m.floatField;
98  }
99
100  public static long $opt$noinline$getLongField(Main m) {
101    if (doThrow) { throw new Error(); }
102    return m.longField;
103  }
104
105  public static double $opt$noinline$getDoubleField(Main m) {
106    if (doThrow) { throw new Error(); }
107    return m.doubleField;
108  }
109
110  public static byte $opt$noinline$getByteField(Main m) {
111    if (doThrow) { throw new Error(); }
112    return m.byteField;
113  }
114
115  public static boolean $opt$noinline$getBooleanField(Main m) {
116    if (doThrow) { throw new Error(); }
117    return m.booleanField;
118  }
119
120  public static char $opt$noinline$getCharField(Main m) {
121    if (doThrow) { throw new Error(); }
122    return m.charField;
123  }
124
125  public static short $opt$noinline$getShortField(Main m) {
126    if (doThrow) { throw new Error(); }
127    return m.shortField;
128  }
129
130  public static void $opt$noinline$setVolatileObjectField(Main m) {
131    if (doThrow) { throw new Error(); }
132    m.volatileObjectField = null;
133  }
134
135  public static void $opt$noinline$setVolatileIntField(Main m) {
136    if (doThrow) { throw new Error(); }
137    m.volatileIntField = 0;
138  }
139
140  public static void $opt$noinline$setVolatileFloatField(Main m) {
141    if (doThrow) { throw new Error(); }
142    m.volatileFloatField = 0;
143  }
144
145  public static void $opt$noinline$setVolatileLongField(Main m) {
146    if (doThrow) { throw new Error(); }
147    m.volatileLongField = 0;
148  }
149
150  public static void $opt$noinline$setVolatileDoubleField(Main m) {
151    if (doThrow) { throw new Error(); }
152    m.volatileDoubleField = 0;
153  }
154
155  public static void $opt$noinline$setVolatileByteField(Main m) {
156    if (doThrow) { throw new Error(); }
157    m.volatileByteField = 0;
158  }
159
160  public static void $opt$noinline$setVolatileBooleanField(Main m) {
161    if (doThrow) { throw new Error(); }
162    m.volatileBooleanField = false;
163  }
164
165  public static void $opt$noinline$setVolatileCharField(Main m) {
166    if (doThrow) { throw new Error(); }
167    m.volatileCharField = 0;
168  }
169
170  public static void $opt$noinline$setVolatileShortField(Main m) {
171    if (doThrow) { throw new Error(); }
172    m.volatileShortField = 0;
173  }
174
175  public static Object $opt$noinline$getVolatileObjectField(Main m) {
176    if (doThrow) { throw new Error(); }
177    return m.volatileObjectField;
178  }
179
180  public static int $opt$noinline$getVolatileIntField(Main m) {
181    if (doThrow) { throw new Error(); }
182    return m.volatileIntField;
183  }
184
185  public static float $opt$noinline$getVolatileFloatField(Main m) {
186    if (doThrow) { throw new Error(); }
187    return m.volatileFloatField;
188  }
189
190  public static long $opt$noinline$getVolatileLongField(Main m) {
191    if (doThrow) { throw new Error(); }
192    return m.volatileLongField;
193  }
194
195  public static double $opt$noinline$getVolatileDoubleField(Main m) {
196    if (doThrow) { throw new Error(); }
197    return m.volatileDoubleField;
198  }
199
200  public static byte $opt$noinline$getVolatileByteField(Main m) {
201    if (doThrow) { throw new Error(); }
202    return m.volatileByteField;
203  }
204
205  public static boolean $opt$noinline$getVolatileBooleanField(Main m) {
206    if (doThrow) { throw new Error(); }
207    return m.volatileBooleanField;
208  }
209
210  public static char $opt$noinline$getVolatileCharField(Main m) {
211    if (doThrow) { throw new Error(); }
212    return m.volatileCharField;
213  }
214
215  public static short $opt$noinline$getVolatileShortField(Main m) {
216    if (doThrow) { throw new Error(); }
217    return m.volatileShortField;
218  }
219
220  public static void $opt$noinline$setObjectElement(Object[] a) {
221    if (doThrow) { throw new Error(); }
222    a[0] = null;
223  }
224
225  public static void $opt$noinline$setIntElement(int[] a) {
226    if (doThrow) { throw new Error(); }
227    a[0] = 0;
228  }
229
230  public static void $opt$noinline$setFloatElement(float[] a) {
231    if (doThrow) { throw new Error(); }
232    a[0] = 0;
233  }
234
235  public static void $opt$noinline$setLongElement(long[] a) {
236    if (doThrow) { throw new Error(); }
237    a[0] = 0;
238  }
239
240  public static void $opt$noinline$setDoubleElement(double[] a) {
241    if (doThrow) { throw new Error(); }
242    a[0] = 0;
243  }
244
245  public static void $opt$noinline$setByteElement(byte[] a) {
246    if (doThrow) { throw new Error(); }
247    a[0] = 0;
248  }
249
250  public static void $opt$noinline$setBooleanElement(boolean[] a) {
251    if (doThrow) { throw new Error(); }
252    a[0] = false;
253  }
254
255  public static void $opt$noinline$setCharElement(char[] a) {
256    if (doThrow) { throw new Error(); }
257    a[0] = 0;
258  }
259
260  public static void $opt$noinline$setShortElement(short[] a) {
261    if (doThrow) { throw new Error(); }
262    a[0] = 0;
263  }
264
265  public static Object $opt$noinline$getObjectElement(Object[] a) {
266    if (doThrow) { throw new Error(); }
267    return a[0];
268  }
269
270  public static int $opt$noinline$getIntElement(int[] a) {
271    if (doThrow) { throw new Error(); }
272    return a[0];
273  }
274
275  public static float $opt$noinline$getFloatElement(float[] a) {
276    if (doThrow) { throw new Error(); }
277    return a[0];
278  }
279
280  public static long $opt$noinline$getLongElement(long[] a) {
281    if (doThrow) { throw new Error(); }
282    return a[0];
283  }
284
285  public static double $opt$noinline$getDoubleElement(double[] a) {
286    if (doThrow) { throw new Error(); }
287    return a[0];
288  }
289
290  public static byte $opt$noinline$getByteElement(byte[] a) {
291    if (doThrow) { throw new Error(); }
292    return a[0];
293  }
294
295  public static boolean $opt$noinline$getBooleanElement(boolean[] a) {
296    if (doThrow) { throw new Error(); }
297    return a[0];
298  }
299
300  public static char $opt$noinline$getCharElement(char[] a) {
301    if (doThrow) { throw new Error(); }
302    return a[0];
303  }
304
305  public static short $opt$noinline$getShortElement(short[] a) {
306    if (doThrow) { throw new Error(); }
307    return a[0];
308  }
309
310  public static void main(String[] args) {
311    int methodLine = 42;
312    int thisLine = 312;
313    try {
314      $opt$noinline$setObjectField(null);
315      throw new RuntimeException("Failed to throw NullPointerException.");
316    } catch (NullPointerException npe) {
317      check(npe, thisLine += 2, methodLine, "$opt$noinline$setObjectField");
318    }
319    try {
320      $opt$noinline$setIntField(null);
321      throw new RuntimeException("Failed to throw NullPointerException.");
322    } catch (NullPointerException npe) {
323      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setIntField");
324    }
325    try {
326      $opt$noinline$setFloatField(null);
327      throw new RuntimeException("Failed to throw NullPointerException.");
328    } catch (NullPointerException npe) {
329      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setFloatField");
330    }
331    try {
332      $opt$noinline$setLongField(null);
333      throw new RuntimeException("Failed to throw NullPointerException.");
334    } catch (NullPointerException npe) {
335      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setLongField");
336    }
337    try {
338      $opt$noinline$setDoubleField(null);
339      throw new RuntimeException("Failed to throw NullPointerException.");
340    } catch (NullPointerException npe) {
341      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setDoubleField");
342    }
343    try {
344      $opt$noinline$setByteField(null);
345      throw new RuntimeException("Failed to throw NullPointerException.");
346    } catch (NullPointerException npe) {
347      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setByteField");
348    }
349    try {
350      $opt$noinline$setBooleanField(null);
351      throw new RuntimeException("Failed to throw NullPointerException.");
352    } catch (NullPointerException npe) {
353      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setBooleanField");
354    }
355    try {
356      $opt$noinline$setCharField(null);
357      throw new RuntimeException("Failed to throw NullPointerException.");
358    } catch (NullPointerException npe) {
359      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setCharField");
360    }
361    try {
362      $opt$noinline$setShortField(null);
363      throw new RuntimeException("Failed to throw NullPointerException.");
364    } catch (NullPointerException npe) {
365      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setShortField");
366    }
367    try {
368      $opt$noinline$getObjectField(null);
369      throw new RuntimeException("Failed to throw NullPointerException.");
370    } catch (NullPointerException npe) {
371      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getObjectField");
372    }
373    try {
374      $opt$noinline$getIntField(null);
375      throw new RuntimeException("Failed to throw NullPointerException.");
376    } catch (NullPointerException npe) {
377      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getIntField");
378    }
379    try {
380      $opt$noinline$getFloatField(null);
381      throw new RuntimeException("Failed to throw NullPointerException.");
382    } catch (NullPointerException npe) {
383      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getFloatField");
384    }
385    try {
386      $opt$noinline$getLongField(null);
387      throw new RuntimeException("Failed to throw NullPointerException.");
388    } catch (NullPointerException npe) {
389      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getLongField");
390    }
391    try {
392      $opt$noinline$getDoubleField(null);
393      throw new RuntimeException("Failed to throw NullPointerException.");
394    } catch (NullPointerException npe) {
395      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getDoubleField");
396    }
397    try {
398      $opt$noinline$getByteField(null);
399      throw new RuntimeException("Failed to throw NullPointerException.");
400    } catch (NullPointerException npe) {
401      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getByteField");
402    }
403    try {
404      $opt$noinline$getBooleanField(null);
405      throw new RuntimeException("Failed to throw NullPointerException.");
406    } catch (NullPointerException npe) {
407      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getBooleanField");
408    }
409    try {
410      $opt$noinline$getCharField(null);
411      throw new RuntimeException("Failed to throw NullPointerException.");
412    } catch (NullPointerException npe) {
413      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getCharField");
414    }
415    try {
416      $opt$noinline$getShortField(null);
417      throw new RuntimeException("Failed to throw NullPointerException.");
418    } catch (NullPointerException npe) {
419      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getShortField");
420    }
421    try {
422      $opt$noinline$setVolatileObjectField(null);
423      throw new RuntimeException("Failed to throw NullPointerException.");
424    } catch (NullPointerException npe) {
425      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileObjectField");
426    }
427    try {
428      $opt$noinline$setVolatileIntField(null);
429      throw new RuntimeException("Failed to throw NullPointerException.");
430    } catch (NullPointerException npe) {
431      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileIntField");
432    }
433    try {
434      $opt$noinline$setVolatileFloatField(null);
435      throw new RuntimeException("Failed to throw NullPointerException.");
436    } catch (NullPointerException npe) {
437      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileFloatField");
438    }
439    try {
440      $opt$noinline$setVolatileLongField(null);
441      throw new RuntimeException("Failed to throw NullPointerException.");
442    } catch (NullPointerException npe) {
443      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileLongField");
444    }
445    try {
446      $opt$noinline$setVolatileDoubleField(null);
447      throw new RuntimeException("Failed to throw NullPointerException.");
448    } catch (NullPointerException npe) {
449      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileDoubleField");
450    }
451    try {
452      $opt$noinline$setVolatileByteField(null);
453      throw new RuntimeException("Failed to throw NullPointerException.");
454    } catch (NullPointerException npe) {
455      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileByteField");
456    }
457    try {
458      $opt$noinline$setVolatileBooleanField(null);
459      throw new RuntimeException("Failed to throw NullPointerException.");
460    } catch (NullPointerException npe) {
461      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileBooleanField");
462    }
463    try {
464      $opt$noinline$setVolatileCharField(null);
465      throw new RuntimeException("Failed to throw NullPointerException.");
466    } catch (NullPointerException npe) {
467      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileCharField");
468    }
469    try {
470      $opt$noinline$setVolatileShortField(null);
471      throw new RuntimeException("Failed to throw NullPointerException.");
472    } catch (NullPointerException npe) {
473      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setVolatileShortField");
474    }
475    try {
476      $opt$noinline$getVolatileObjectField(null);
477      throw new RuntimeException("Failed to throw NullPointerException.");
478    } catch (NullPointerException npe) {
479      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileObjectField");
480    }
481    try {
482      $opt$noinline$getVolatileIntField(null);
483      throw new RuntimeException("Failed to throw NullPointerException.");
484    } catch (NullPointerException npe) {
485      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileIntField");
486    }
487    try {
488      $opt$noinline$getVolatileFloatField(null);
489      throw new RuntimeException("Failed to throw NullPointerException.");
490    } catch (NullPointerException npe) {
491      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileFloatField");
492    }
493    try {
494      $opt$noinline$getVolatileLongField(null);
495      throw new RuntimeException("Failed to throw NullPointerException.");
496    } catch (NullPointerException npe) {
497      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileLongField");
498    }
499    try {
500      $opt$noinline$getVolatileDoubleField(null);
501      throw new RuntimeException("Failed to throw NullPointerException.");
502    } catch (NullPointerException npe) {
503      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileDoubleField");
504    }
505    try {
506      $opt$noinline$getVolatileByteField(null);
507      throw new RuntimeException("Failed to throw NullPointerException.");
508    } catch (NullPointerException npe) {
509      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileByteField");
510    }
511    try {
512      $opt$noinline$getVolatileBooleanField(null);
513      throw new RuntimeException("Failed to throw NullPointerException.");
514    } catch (NullPointerException npe) {
515      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileBooleanField");
516    }
517    try {
518      $opt$noinline$getVolatileCharField(null);
519      throw new RuntimeException("Failed to throw NullPointerException.");
520    } catch (NullPointerException npe) {
521      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileCharField");
522    }
523    try {
524      $opt$noinline$getVolatileShortField(null);
525      throw new RuntimeException("Failed to throw NullPointerException.");
526    } catch (NullPointerException npe) {
527      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getVolatileShortField");
528    }
529    try {
530      $opt$noinline$setObjectElement(null);
531      throw new RuntimeException("Failed to throw NullPointerException.");
532    } catch (NullPointerException npe) {
533      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setObjectElement");
534    }
535    try {
536      $opt$noinline$setIntElement(null);
537      throw new RuntimeException("Failed to throw NullPointerException.");
538    } catch (NullPointerException npe) {
539      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setIntElement");
540    }
541    try {
542      $opt$noinline$setFloatElement(null);
543      throw new RuntimeException("Failed to throw NullPointerException.");
544    } catch (NullPointerException npe) {
545      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setFloatElement");
546    }
547    try {
548      $opt$noinline$setLongElement(null);
549      throw new RuntimeException("Failed to throw NullPointerException.");
550    } catch (NullPointerException npe) {
551      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setLongElement");
552    }
553    try {
554      $opt$noinline$setDoubleElement(null);
555      throw new RuntimeException("Failed to throw NullPointerException.");
556    } catch (NullPointerException npe) {
557      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setDoubleElement");
558    }
559    try {
560      $opt$noinline$setByteElement(null);
561      throw new RuntimeException("Failed to throw NullPointerException.");
562    } catch (NullPointerException npe) {
563      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setByteElement");
564    }
565    try {
566      $opt$noinline$setBooleanElement(null);
567      throw new RuntimeException("Failed to throw NullPointerException.");
568    } catch (NullPointerException npe) {
569      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setBooleanElement");
570    }
571    try {
572      $opt$noinline$setCharElement(null);
573      throw new RuntimeException("Failed to throw NullPointerException.");
574    } catch (NullPointerException npe) {
575      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setCharElement");
576    }
577    try {
578      $opt$noinline$setShortElement(null);
579      throw new RuntimeException("Failed to throw NullPointerException.");
580    } catch (NullPointerException npe) {
581      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$setShortElement");
582    }
583    try {
584      $opt$noinline$getObjectElement(null);
585      throw new RuntimeException("Failed to throw NullPointerException.");
586    } catch (NullPointerException npe) {
587      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getObjectElement");
588    }
589    try {
590      $opt$noinline$getIntElement(null);
591      throw new RuntimeException("Failed to throw NullPointerException.");
592    } catch (NullPointerException npe) {
593      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getIntElement");
594    }
595    try {
596      $opt$noinline$getFloatElement(null);
597      throw new RuntimeException("Failed to throw NullPointerException.");
598    } catch (NullPointerException npe) {
599      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getFloatElement");
600    }
601    try {
602      $opt$noinline$getLongElement(null);
603      throw new RuntimeException("Failed to throw NullPointerException.");
604    } catch (NullPointerException npe) {
605      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getLongElement");
606    }
607    try {
608      $opt$noinline$getDoubleElement(null);
609      throw new RuntimeException("Failed to throw NullPointerException.");
610    } catch (NullPointerException npe) {
611      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getDoubleElement");
612    }
613    try {
614      $opt$noinline$getByteElement(null);
615      throw new RuntimeException("Failed to throw NullPointerException.");
616    } catch (NullPointerException npe) {
617      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getByteElement");
618    }
619    try {
620      $opt$noinline$getBooleanElement(null);
621      throw new RuntimeException("Failed to throw NullPointerException.");
622    } catch (NullPointerException npe) {
623      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getBooleanElement");
624    }
625    try {
626      $opt$noinline$getCharElement(null);
627      throw new RuntimeException("Failed to throw NullPointerException.");
628    } catch (NullPointerException npe) {
629      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getCharElement");
630    }
631    try {
632      $opt$noinline$getShortElement(null);
633      throw new RuntimeException("Failed to throw NullPointerException.");
634    } catch (NullPointerException npe) {
635      check(npe, thisLine += 6, methodLine += 5, "$opt$noinline$getShortElement");
636    }
637
638    $opt$noinline$testRegisterRetrieval();
639  }
640
641  static void $opt$noinline$testRegisterRetrieval() {
642    Main[] array = $noinline$PrepareArray();
643    int i0 = 0;
644    int i1 = 1;
645    int i2 = 2;
646    int i3 = 3;
647    int i4 = 4;
648    int i5 = 5;
649    int i6 = 6;
650    int i7 = 7;
651    int i8 = 8;
652    int i9 = 9;
653    int i10 = 10;
654    int i11 = 11;
655    int i12 = 12;
656    int i13 = 13;
657    int i14 = 14;
658    int i15 = 15;
659    long l0 = 20L;
660    long l1 = 21L;
661    long l2 = 22L;
662    long l3 = 23L;
663    long l4 = 24L;
664    long l5 = 25L;
665    long l6 = 26L;
666    long l7 = 27L;
667    long l8 = 28L;
668    long l9 = 29L;
669    long l10 = 30L;
670    long l11 = 31L;
671    long l12 = 32L;
672    long l13 = 33L;
673    long l14 = 34L;
674    long l15 = 35L;
675    float f0 = 40.0f;
676    float f1 = 41.0f;
677    float f2 = 42.0f;
678    float f3 = 43.0f;
679    float f4 = 44.0f;
680    float f5 = 45.0f;
681    float f6 = 46.0f;
682    float f7 = 47.0f;
683    float f8 = 48.0f;
684    float f9 = 49.0f;
685    float f10 = 50.0f;
686    float f11 = 51.0f;
687    float f12 = 52.0f;
688    float f13 = 53.0f;
689    float f14 = 54.0f;
690    float f15 = 55.0f;
691    double d0 = 60.0;
692    double d1 = 61.0;
693    double d2 = 62.0;
694    double d3 = 63.0;
695    double d4 = 64.0;
696    double d5 = 65.0;
697    double d6 = 66.0;
698    double d7 = 67.0;
699    double d8 = 68.0;
700    double d9 = 69.0;
701    double d10 = 70.0;
702    double d11 = 71.0;
703    double d12 = 72.0;
704    double d13 = 73.0;
705    double d14 = 74.0;
706    double d15 = 75.0;
707    int addInt = -1;
708    long addLong = -2L;
709    float addFloat = -3.0f;
710    double addDouble = -4.0;
711    Main m = null;
712    int i = 0;
713    try {
714      for (i = 0; i < array.length; ++i) {
715        m = array[i];
716        // We have 16 ints, 16 longs, 16 floats, 16 doubles and a few helper variables here,
717        // none of them anonymous. Hopefully, all available physical registers will be allocated
718        // to these variables, so that when `m.intField` throws NPE during the third iteration,
719        // we will fully test retrieval of values from all physical registers.
720        addInt = m.intField;
721        addLong = m.longField;
722        addFloat = m.floatField;
723        addDouble = m.doubleField;
724        i0 += i1;
725        i1 += i2;
726        i2 += i3;
727        i3 += i4;
728        i4 += i5;
729        i5 += i6;
730        i6 += i7;
731        i7 += i8;
732        i8 += i9;
733        i9 += i10;
734        i10 += i11;
735        i11 += i12;
736        i12 += i13;
737        i13 += i14;
738        i14 += i15;
739        i15 += addInt;
740        l0 += l1;
741        l1 += l2;
742        l2 += l3;
743        l3 += l4;
744        l4 += l5;
745        l5 += l6;
746        l6 += l7;
747        l7 += l8;
748        l8 += l9;
749        l9 += l10;
750        l10 += l11;
751        l11 += l12;
752        l12 += l13;
753        l13 += l14;
754        l14 += l15;
755        l15 += addLong;
756        f0 += f1;
757        f1 += f2;
758        f2 += f3;
759        f3 += f4;
760        f4 += f5;
761        f5 += f6;
762        f6 += f7;
763        f7 += f8;
764        f8 += f9;
765        f9 += f10;
766        f10 += f11;
767        f11 += f12;
768        f12 += f13;
769        f13 += f14;
770        f14 += f15;
771        f15 += addFloat;
772        d0 += d1;
773        d1 += d2;
774        d2 += d3;
775        d3 += d4;
776        d4 += d5;
777        d5 += d6;
778        d6 += d7;
779        d7 += d8;
780        d8 += d9;
781        d9 += d10;
782        d10 += d11;
783        d11 += d12;
784        d12 += d13;
785        d13 += d14;
786        d14 += d15;
787        d15 += addDouble;
788      }
789    } catch (NullPointerException npe) {
790      System.out.println("i0=" + i0);
791      System.out.println("i1=" + i1);
792      System.out.println("i2=" + i2);
793      System.out.println("i3=" + i3);
794      System.out.println("i4=" + i4);
795      System.out.println("i5=" + i5);
796      System.out.println("i6=" + i6);
797      System.out.println("i7=" + i7);
798      System.out.println("i8=" + i8);
799      System.out.println("i9=" + i9);
800      System.out.println("i10=" + i10);
801      System.out.println("i11=" + i11);
802      System.out.println("i12=" + i12);
803      System.out.println("i13=" + i13);
804      System.out.println("i14=" + i14);
805      System.out.println("i15=" + i15);
806      System.out.println("l0=" + l0);
807      System.out.println("l1=" + l1);
808      System.out.println("l2=" + l2);
809      System.out.println("l3=" + l3);
810      System.out.println("l4=" + l4);
811      System.out.println("l5=" + l5);
812      System.out.println("l6=" + l6);
813      System.out.println("l7=" + l7);
814      System.out.println("l8=" + l8);
815      System.out.println("l9=" + l9);
816      System.out.println("l10=" + l10);
817      System.out.println("l11=" + l11);
818      System.out.println("l12=" + l12);
819      System.out.println("l13=" + l13);
820      System.out.println("l14=" + l14);
821      System.out.println("l15=" + l15);
822      System.out.println("f0=" + f0);
823      System.out.println("f1=" + f1);
824      System.out.println("f2=" + f2);
825      System.out.println("f3=" + f3);
826      System.out.println("f4=" + f4);
827      System.out.println("f5=" + f5);
828      System.out.println("f6=" + f6);
829      System.out.println("f7=" + f7);
830      System.out.println("f8=" + f8);
831      System.out.println("f9=" + f9);
832      System.out.println("f10=" + f10);
833      System.out.println("f11=" + f11);
834      System.out.println("f12=" + f12);
835      System.out.println("f13=" + f13);
836      System.out.println("f14=" + f14);
837      System.out.println("f15=" + f15);
838      System.out.println("d0=" + d0);
839      System.out.println("d1=" + d1);
840      System.out.println("d2=" + d2);
841      System.out.println("d3=" + d3);
842      System.out.println("d4=" + d4);
843      System.out.println("d5=" + d5);
844      System.out.println("d6=" + d6);
845      System.out.println("d7=" + d7);
846      System.out.println("d8=" + d8);
847      System.out.println("d9=" + d9);
848      System.out.println("d10=" + d10);
849      System.out.println("d11=" + d11);
850      System.out.println("d12=" + d12);
851      System.out.println("d13=" + d13);
852      System.out.println("d14=" + d14);
853      System.out.println("d15=" + d15);
854      System.out.println("addInt=" + addInt);
855      System.out.println("addLong=" + addLong);
856      System.out.println("addFloat=" + addFloat);
857      System.out.println("addDouble=" + addDouble);
858      System.out.println("m=" + m);
859      System.out.println("i=" + i);
860    }
861  }
862
863  static Main[] $noinline$PrepareArray() {
864    if (doThrow) { throw new Error(); }
865    Main[] array = new Main[] { new Main(), new Main(), null, new Main() };
866    array[1].intField = 42;
867    array[1].longField = 111L;
868    array[1].floatField = 0.5f;
869    array[1].doubleField = 0.125;
870    return array;
871  }
872
873  static void check(NullPointerException npe, int mainLine, int methodLine, String methodName) {
874    System.out.println(methodName);
875    StackTraceElement[] trace = npe.getStackTrace();
876    checkElement(trace[0], "Main", methodName, "Main.java", methodLine);
877    checkElement(trace[1], "Main", "main", "Main.java", mainLine);
878  }
879
880  static void checkElement(StackTraceElement element,
881                           String declaringClass, String methodName,
882                           String fileName, int lineNumber) {
883    assertEquals(declaringClass, element.getClassName());
884    assertEquals(methodName, element.getMethodName());
885    assertEquals(fileName, element.getFileName());
886    assertEquals(lineNumber, element.getLineNumber());
887  }
888
889  static void assertEquals(Object expected, Object actual) {
890    if (!expected.equals(actual)) {
891      String msg = "Expected \"" + expected + "\" but got \"" + actual + "\"";
892      throw new AssertionError(msg);
893    }
894  }
895
896  static void assertEquals(int expected, int actual) {
897    if (expected != actual) {
898      throw new AssertionError("Expected " + expected + " got " + actual);
899    }
900  }
901
902}
903