• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 // clang-format off
18 
19 class Main extends IntMathBase {
20 
21     public static boolean mBoolean1, mBoolean2;
22     public static byte mByte1, mByte2;
23     public static char mChar1, mChar2;
24     public static short mShort1, mShort2;
25     public static int mInt1, mInt2;
26     public static float mFloat1, mFloat2;
27     public static long mLong1, mLong2;
28     public static double mDouble1, mDouble2;
29     public static volatile long mVolatileLong1, mVolatileLong2;
30 
31 
32     private int foo_;
33 
Main(int stuff)34     public Main(int stuff) {
35         super();
36         foo_ = stuff;
37     }
38 
Main()39     public Main() {
40         super();
41         foo_ = 123;
42     }
43 
44     /* Regression test: triggered an SSA renaming bug. */
divideLongByBillion(long a)45     static long divideLongByBillion(long a) {
46         long quot;
47         long rem;
48 
49         if (a >= 0) {
50             long bLong = 1000000000L;
51             quot = (a / bLong);
52             rem = (a % bLong);
53         } else {
54             /*
55              * Make the dividend positive shifting it right by 1 bit then get
56              * the quotient an remainder and correct them properly
57              */
58             long aPos = a >>> 1;
59             long bPos = 1000000000L >>> 1;
60             quot = aPos / bPos;
61             rem = aPos % bPos;
62             // double the remainder and add 1 if 'a' is odd
63             rem = (rem << 1) + (a & 1);
64         }
65         return ((rem << 32) | (quot & 0xFFFFFFFFL));
66     }
67 
68 
instanceTest(int x)69     static int instanceTest(int x) {
70         IntMathBase a = new IntMathBase();
71         Main b = new Main();
72 
73         if (!(null instanceof IntMathBase)) {
74             x = x + 42;
75         }
76 
77         if (a instanceof IntMathBase) {
78             x = x * 2;
79         }
80 
81         if (a instanceof Main) {
82             x = x + 13;
83         }
84 
85         if (b instanceof IntMathBase) {
86             x = x -1;
87         }
88 
89         if (b instanceof Main) {
90             x = x + 1333;
91         }
92         return x;
93     }
94 
tryThing()95     int tryThing() {
96         int val = super.tryThing();
97         return val + 10;
98     }
99 
superTest(int x)100     static int superTest(int x) {
101         Main instance = new Main();
102         Main base = instance;
103         int val1 = instance.tryThing();
104         int val2 = base.tryThing();
105         return val1 + val2 + x;
106     }
107 
constClassTest(int x)108     static int constClassTest(int x) {
109         Class<?> c = String.class;
110         if (c != null) {
111            return x * 2;
112         } else {
113            return x;
114         }
115     }
116 
constStringTest(int x)117     static int constStringTest(int x) {
118         String str = "Hello World!";
119         return x + str.length();
120     }
121 
throwNullPointerException()122     static void throwNullPointerException() {
123         throw new NullPointerException();
124     }
125 
throwImplicitNullPointerException()126     static void throwImplicitNullPointerException() {
127       throw null;
128     }
129 
catchBlock(int x)130     static int catchBlock(int x) {
131         try {
132             if (x == 1000) {
133                 x += 123;
134                 throwNullPointerException();
135             } else {
136                 x += 321;
137                 throwImplicitNullPointerException();
138             }
139         } catch (NullPointerException npe) {
140             x += 456;
141         }
142         return x;
143     }
144 
catchBlockNoThrow(int x)145     static int catchBlockNoThrow(int x) {
146         try {
147             x += 123;
148         } catch (NullPointerException npe) {
149             x += 456;
150         }
151         return x;
152     }
153 
staticFieldTest(int x)154     static int staticFieldTest(int x) {
155         mBoolean1 = true;
156         mBoolean2 = false;
157         mByte1 = 127;
158         mByte2 = -128;
159         mChar1 = 32767;
160         mChar2 = 65535;
161         mShort1 = 32767;
162         mShort2 = -32768;
163         mInt1 = 65537;
164         mInt2 = -65537;
165         mFloat1 = 3.1415f;
166         mFloat2 = -1.0f / 0.0f;                // -inf
167         mLong1 = 1234605616436508552L;     // 0x1122334455667788
168         mLong2 = -1234605616436508552L;
169         mDouble1 = 3.1415926535;
170         mDouble2 = 1.0 / 0.0;               // +inf
171         mVolatileLong1 = mLong1 - 1;
172         mVolatileLong2 = mLong2 + 1;
173 
174         if (!mBoolean1) { return 10; }
175         if (mBoolean2) { return 11; }
176         if (mByte1 != 127) { return 12; }
177         if (mByte2 != -128) { return 13; }
178         if (mChar1 != 32767) { return 14; }
179         if (mChar2 != 65535) { return 15; }
180         if (mShort1 != 32767) { return 16; }
181         if (mShort2 != -32768) { return 17; }
182         if (mInt1 != 65537) { return 18; }
183         if (mInt2 != -65537) { return 19; }
184         if (!(mFloat1 > 3.141f && mFloat1 < 3.142f)) { return 20; }
185         if (mFloat2 >= mFloat1) { return 21; }
186         if (mLong1 != 1234605616436508552L) { return 22; }
187         if (mLong2 != -1234605616436508552L) { return 23; }
188         if (!(mDouble1 > 3.141592653 && mDouble1 < 3.141592654)) { return 24; }
189         if (mDouble2 <= mDouble1) { return 25; }
190         if (mVolatileLong1 != 1234605616436508551L) { return 26; }
191         if (mVolatileLong2 != -1234605616436508551L) { return 27; }
192 
193         return 1000 + x;
194     }
195 
196     /*
197      * Try to cause some unary operations.
198      */
unopTest(int x)199     static int unopTest(int x) {
200         x = -x;
201         x ^= 0xffffffff;
202         return x;
203     }
204 
shiftTest1()205     static int shiftTest1() {
206         final int[] mBytes = {
207             0x11, 0x22, 0x33, 0x44, 0x88, 0x99, 0xaa, 0xbb
208         };
209         long l;
210         int i1, i2;
211 
212         if (mBytes[0] != 0x11) return 20;
213         if (mBytes[1] != 0x22) return 21;
214         if (mBytes[2] != 0x33) return 22;
215         if (mBytes[3] != 0x44) return 23;
216         if (mBytes[4] != 0x88) return 24;
217         if (mBytes[5] != 0x99) return 25;
218         if (mBytes[6] != 0xaa) return 26;
219         if (mBytes[7] != 0xbb) return 27;
220 
221         i1 = mBytes[0] | mBytes[1] << 8 | mBytes[2] << 16 | mBytes[3] << 24;
222         i2 = mBytes[4] | mBytes[5] << 8 | mBytes[6] << 16 | mBytes[7] << 24;
223         l = i1 | ((long)i2 << 32);
224 
225         if (i1 != 0x44332211) { return 0x80000000 | i1; }
226         if (i2 != 0xbbaa9988) { return 2; }
227         if (l != 0xbbaa998844332211L) { return 3; }
228 
229         l = (long)mBytes[0]
230                 | (long)mBytes[1] << 8
231                 | (long)mBytes[2] << 16
232                 | (long)mBytes[3] << 24
233                 | (long)mBytes[4] << 32
234                 | (long)mBytes[5] << 40
235                 | (long)mBytes[6] << 48
236                 | (long)mBytes[7] << 56;
237 
238         if (l != 0xbbaa998844332211L) { return 4; }
239         return 0;
240     }
241 
shiftTest2()242     static int shiftTest2() {
243 
244         long    a = 0x11;
245         long    b = 0x22;
246         long    c = 0x33;
247         long    d = 0x44;
248         long    e = 0x55;
249         long    f = 0x66;
250         long    g = 0x77;
251         long    h = 0x88;
252 
253         long    result = ((a << 56) | (b << 48) | (c << 40) | (d << 32) |
254                           (e << 24) | (f << 16) | (g <<  8) | h);
255 
256         if (result != 0x1122334455667788L) { return 1; }
257         return 0;
258     }
259 
unsignedShiftTest()260     static int unsignedShiftTest() {
261         byte b = -4;
262         short s = -4;
263         char c = 0xfffc;
264         int i = -4;
265 
266         b >>>= 4;
267         s >>>= 4;
268         c >>>= 4;
269         i >>>= 4;
270 
271         if ((int) b != -1) { return 1; }
272         if ((int) s != -1) { return 2; }
273         if ((int) c != 0x0fff) { return 3; }
274         if (i != 268435455) { return 4; }
275         return 0;
276     }
277 
convTest()278     static int convTest() {
279 
280         float f;
281         double d;
282         int i;
283         long l;
284 
285         /* int --> long */
286         i = 7654;
287         l = (long) i;
288         if (l != 7654L) { return 1; }
289 
290         i = -7654;
291         l = (long) i;
292         if (l != -7654L) { return 2; }
293 
294         /* long --> int (with truncation) */
295         l = 5678956789L;
296         i = (int) l;
297         if (i != 1383989493) { return 3; }
298 
299         l = -5678956789L;
300         i = (int) l;
301         if (i != -1383989493) { return 4; }
302 
303         /* long --> double */
304         l = 0x7FFFFFFFL;
305         d = (double) l;
306         if (Double.doubleToRawLongBits(d) != 0x41dfffffffc00000L) { return 5; }
307 
308         l = 0xFFFFFFFFL;
309         d = (double) l;
310         if (Double.doubleToRawLongBits(d) != 0x41efffffffe00000L) { return 6; }
311 
312         l = 0x7FFFFFFFFFFFFFFFL;
313         d = (double) l;
314         if (Double.doubleToRawLongBits(d) != 0x43e0000000000000L) { return 7; }
315 
316         l = 0xFFFFFFFFFFFFFFFFL;
317         d = (double) l;
318         if (Double.doubleToRawLongBits(d) != 0xbff0000000000000L) { return 8; }
319 
320         return 0;
321     }
322 
charSubTest()323     static int charSubTest() {
324 
325         char char1 = 0x00e9;
326         char char2 = 0xffff;
327         int i;
328 
329         /* chars are unsigned-expanded to ints before subtraction */
330         i = char1 - char2;
331         if (i != 0xffff00ea) { return 1; }
332         return 0;
333     }
334 
335     /*
336      * We pass in the arguments and return the results so the compiler
337      * doesn't do the math for us.  (x=70000, y=-3)
338      */
intOperTest(int x, int y)339     static int intOperTest(int x, int y) {
340         int[] results = new int[10];
341 
342         /* this seems to generate "op-int" instructions */
343         results[0] = x + y;
344         results[1] = x - y;
345         results[2] = x * y;
346         results[3] = x * x;
347         results[4] = x / y;
348         results[5] = x % -y;
349         results[6] = x & y;
350         results[7] = x | y;
351         results[8] = x ^ y;
352 
353         /* this seems to generate "op-int/2addr" instructions */
354         results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
355 
356         /* check this edge case while we're here (div-int/2addr) */
357         int minInt = -2147483648;
358         int negOne = -results[5];
359         int plusOne = 1;
360         int result = (((minInt + plusOne) - plusOne) / negOne) / negOne;
361         int shouldBeZero = minInt % negOne;
362 
363         if (result != minInt) { return 1;};
364         if (results[0] != 69997) { return 2;};
365         if (results[1] != 70003) { return 3;};
366         if (results[2] != -210000) { return 4;};
367         if (results[3] != 605032704) { return 5;};
368         if (results[4] != -23333) { return 6;};
369         if (results[5] != 1) { return 7;};
370         if (results[6] != 70000) { return 8;};
371         if (results[7] != -3) { return 9;};
372         if (results[8] != -70003) { return 10;};
373         if (results[9] != 70000) { return 11;};
374         if (shouldBeZero != 0) { return 12;};
375 
376         return 0;
377     }
378 
379     /*
380      * More operations, this time with 16-bit constants.  (x=77777)
381      */
lit16Test(int x)382     static int lit16Test(int x) {
383 
384         int[] results = new int[10];
385 
386         /* try to generate op-int/lit16" instructions */
387         results[0] = x + 1000;
388         results[1] = 1000 - x;
389         results[2] = x * 1000;
390         results[3] = x / 1000;
391         results[4] = x % 1000;
392         results[5] = x & 1000;
393         results[6] = x | -1000;
394         results[7] = x ^ -1000;
395         /* use an 16-bit constant that has its MSB (bit-15) set */
396         results[8] = x / 32769;
397         results[9] = x / -32769;
398 
399         if (results[0] != 78777) { return 1; }
400         if (results[1] != -76777) { return 2; }
401         if (results[2] != 77777000) { return 3; }
402         if (results[3] != 77) { return 4; }
403         if (results[4] != 777) { return 5; }
404         if (results[5] != 960) { return 6; }
405         if (results[6] != -39) { return 7; }
406         if (results[7] != -76855) { return 8; }
407         if (results[8] != 2) { return 9; }
408         if (results[9] != -2) { return 10; }
409         return 0;
410     }
411 
412     /*
413      * More operations, this time with 8-bit constants.  (x=-55555)
414      */
lit8Test(int x)415     static int lit8Test(int x) {
416 
417         int[] results = new int[9];
418 
419         /* try to generate op-int/lit8" instructions */
420         results[0] = x + 10;
421         results[1] = 10 - x;
422         results[2] = x * 10;
423         results[3] = x / 10;
424         results[4] = x % 10;
425         results[5] = x & 10;
426         results[6] = x | -10;
427         results[7] = x ^ -10;
428         results[8] = x * -256;
429         int minInt = -2147483648;
430         int result = minInt / -1;
431         if (result != minInt) {return 1; }
432         if (results[0] != -55545) {return 2; }
433         if (results[1] != 55565) {return 3; }
434         if (results[2] != -555550) {return 4; }
435         if (results[3] != -5555) {return 5; }
436         if (results[4] != -5) {return 6; }
437         if (results[5] != 8) {return 7; }
438         if (results[6] != -1) {return 8; }
439         if (results[7] != 55563) {return 9; }
440         if (results[8] != 14222080) {return 10; }
441         return 0;
442     }
443 
444 
445     /*
446      * Shift some data.  (value=0xff00aa01, dist=8)
447      */
intShiftTest(int value, int dist)448     static int intShiftTest(int value, int dist) {
449         int results[] = new int[4];
450         results[0] = value << dist;
451         results[1] = value >> dist;
452         results[2] = value >>> dist;
453         results[3] = (((value << dist) >> dist) >>> dist) << dist;
454         if (results[0] != 0x00aa0100) {return 1; }
455         if (results[1] != 0xffff00aa) {return 2; }
456         if (results[2] != 0x00ff00aa) {return 3; }
457         if (results[3] != 0xaa00) {return 4; }
458         return 0;
459     }
460 
461     /*
462      * We pass in the arguments and return the results so the compiler
463      * doesn't do the math for us.  (x=70000000000, y=-3)
464      */
longOperTest(long x, long y)465     static int longOperTest(long x, long y) {
466         long[] results = new long[10];
467 
468         /* this seems to generate "op-long" instructions */
469         results[0] = x + y;
470         results[1] = x - y;
471         results[2] = x * y;
472         results[3] = x * x;
473         results[4] = x / y;
474         results[5] = x % -y;
475         results[6] = x & y;
476         results[7] = x | y;
477         results[8] = x ^ y;
478         /* this seems to generate "op-long/2addr" instructions */
479         results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
480         /* check this edge case while we're here (div-long/2addr) */
481         long minLong = -9223372036854775808L;
482         long negOne = -results[5];
483         long plusOne = 1;
484         long result = (((minLong + plusOne) - plusOne) / negOne) / negOne;
485         if (result != minLong) { return 1; }
486         if (results[0] != 69999999997L) { return 2; }
487         if (results[1] != 70000000003L) { return 3; }
488         if (results[2] != -210000000000L) { return 4; }
489         if (results[3] != -6833923606740729856L) { return 5; }    // overflow
490         if (results[4] != -23333333333L) { return 6; }
491         if (results[5] != 1) { return 7; }
492         if (results[6] != 70000000000L) { return 8; }
493         if (results[7] != -3) { return 9; }
494         if (results[8] != -70000000003L) { return 10; }
495         if (results[9] != 70000000000L) { return 11; }
496         if (results.length != 10) { return 12; }
497         return 0;
498     }
499 
500     /*
501      * Shift some data.  (value=0xd5aa96deff00aa01, dist=16)
502      */
longShiftTest(long value, int dist)503     static long longShiftTest(long value, int dist) {
504         long results[] = new long[4];
505         results[0] = value << dist;
506         results[1] = value >> dist;
507         results[2] = value >>> dist;
508         results[3] = (((value << dist) >> dist) >>> dist) << dist;
509         if (results[0] != 0x96deff00aa010000L) { return results[0]; }
510         if (results[1] != 0xffffd5aa96deff00L) { return results[1]; }
511         if (results[2] != 0x0000d5aa96deff00L) { return results[2]; }
512         if (results[3] != 0xffff96deff000000L) { return results[3]; }
513         if (results.length != 4) { return 5; }
514 
515         return results[0];      // test return-long
516     }
517 
switchTest(int a)518     static int switchTest(int a) {
519         int res = 1234;
520 
521         switch (a) {
522             case -1: res = 1; return res;
523             case 0: res = 2; return res;
524             case 1: /*correct*/ break;
525             case 2: res = 3; return res;
526             case 3: res = 4; return res;
527             case 4: res = 5; return res;
528             default: res = 6; return res;
529         }
530         switch (a) {
531             case 3: res = 7; return res;
532             case 4: res = 8; return res;
533             default: /*correct*/ break;
534         }
535 
536         a = 0x12345678;
537 
538         switch (a) {
539             case 0x12345678: /*correct*/ break;
540             case 0x12345679: res = 9; return res;
541             default: res = 1; return res;
542         }
543         switch (a) {
544             case 57: res = 10; return res;
545             case -6: res = 11; return res;
546             case 0x12345678: /*correct*/ break;
547             case 22: res = 12; return res;
548             case 3: res = 13; return res;
549             default: res = 14; return res;
550         }
551         switch (a) {
552             case -6: res = 15; return res;
553             case 3: res = 16; return res;
554             default: /*correct*/ break;
555         }
556 
557         a = -5;
558         switch (a) {
559             case 12: res = 17; return res;
560             case -5: /*correct*/ break;
561             case 0: res = 18; return res;
562             default: res = 19; return res;
563         }
564 
565         switch (a) {
566             default: /*correct*/ break;
567         }
568         return res;
569     }
570     /*
571      * Test the integer comparisons in various ways.
572      */
testIntCompare(int minus, int plus, int plus2, int zero)573     static int testIntCompare(int minus, int plus, int plus2, int zero) {
574         int res = 1111;
575 
576         if (minus > plus)
577             return 1;
578         if (minus >= plus)
579             return 2;
580         if (plus < minus)
581             return 3;
582         if (plus <= minus)
583             return 4;
584         if (plus == minus)
585             return 5;
586         if (plus != plus2)
587             return 6;
588 
589         /* try a branch-taken */
590         if (plus != minus) {
591             res = res;
592         } else {
593             return 7;
594         }
595 
596         if (minus > 0)
597             return 8;
598         if (minus >= 0)
599             return 9;
600         if (plus < 0)
601             return 10;
602         if (plus <= 0)
603             return 11;
604         if (plus == 0)
605             return 12;
606         if (zero != 0)
607             return 13;
608 
609         if (zero == 0) {
610             res = res;
611         } else {
612             return 14;
613         }
614         return res;
615     }
616 
617     /*
618      * Test cmp-long.
619      *
620      * minus=-5, alsoMinus=0xFFFFFFFF00000009, plus=4, alsoPlus=8
621      */
testLongCompare(long minus, long alsoMinus, long plus, long alsoPlus)622     static int testLongCompare(long minus, long alsoMinus, long plus,
623                                long alsoPlus) {
624         int res = 2222;
625 
626         if (minus > plus)
627             return 2;
628         if (plus < minus)
629             return 3;
630         if (plus == minus)
631             return 4;
632 
633         if (plus >= plus+1)
634             return 5;
635         if (minus >= minus+1)
636             return 6;
637 
638         /* try a branch-taken */
639         if (plus != minus) {
640             res = res;
641         } else {
642             return 7;
643         }
644 
645         /* compare when high words are equal but low words differ */
646         if (plus > alsoPlus)
647             return 8;
648         if (alsoPlus < plus)
649             return 9;
650         if (alsoPlus == plus)
651             return 10;
652 
653         /* high words are equal, low words have apparently different signs */
654         if (minus < alsoMinus)      // bug!
655             return 11;
656         if (alsoMinus > minus)
657             return 12;
658         if (alsoMinus == minus)
659             return 13;
660 
661         return res;
662     }
663 
664     /*
665      * Test cmpl-float and cmpg-float.
666      */
testFloatCompare(float minus, float plus, float plus2, float nan)667     static int testFloatCompare(float minus, float plus, float plus2,
668                                 float nan) {
669         if (minus > plus)
670             return 1;
671         if (plus < minus)
672             return 2;
673         if (plus == minus)
674             return 3;
675         if (plus != plus2)
676             return 4;
677 
678         if (plus <= nan)
679             return 5;
680         if (plus >= nan)
681             return 6;
682         if (minus <= nan)
683             return 7;
684         if (minus >= nan)
685             return 8;
686         if (nan >= plus)
687             return 9;
688         if (nan <= plus)
689             return 10;
690 
691         if (nan == nan)
692             return 11;
693 
694         return 3333;
695     }
696 
testDoubleCompare(double minus, double plus, double plus2, double nan)697     static int testDoubleCompare(double minus, double plus, double plus2,
698                                  double nan) {
699 
700         int res = 4444;
701 
702         if (minus > plus)
703             return 1;
704         if (plus < minus)
705             return 2;
706         if (plus == minus)
707             return 3;
708         if (plus != plus2)
709             return 4;
710 
711         if (plus <= nan)
712             return 5;
713         if (plus >= nan)
714             return 6;
715         if (minus <= nan)
716             return 7;
717         if (minus >= nan)
718             return 8;
719         if (nan >= plus)
720             return 9;
721         if (nan <= plus)
722             return 10;
723 
724         if (nan == nan)
725             return 11;
726         return res;
727     }
728 
fibonacci(int n)729     static int fibonacci(int n) {
730         if (n == 0) {
731             return 0;
732         } else if (n == 1) {
733             return 1;
734         } else {
735             return fibonacci(n - 1) + fibonacci(n - 2);
736         }
737     }
738 
throwAndCatch()739     static int throwAndCatch() {
740         try {
741             throwNullPointerException();
742             return 1;
743         } catch (NullPointerException npe) {
744             return 0;
745         }
746     }
747 
manyArgs(int a0, long a1, int a2, long a3, int a4, long a5, int a6, int a7, double a8, float a9, double a10, short a11, int a12, char a13, int a14, int a15, byte a16, boolean a17, int a18, int a19, long a20, long a21, int a22, int a23, int a24, int a25, int a26)748     static int manyArgs(int a0, long a1, int a2, long a3, int a4, long a5,
749                         int a6, int a7, double a8, float a9, double a10, short a11, int a12,
750                         char a13, int a14, int a15, byte a16, boolean a17, int a18, int a19,
751                         long a20, long a21, int a22, int a23, int a24, int a25, int a26)
752     {
753         if (a0 != 0) return 0;
754         if (a1 !=  1L) return 1;
755         if (a2 != 2) return 2;
756         if (a3 != 3L) return 3;
757         if (a4 != 4) return 4;
758         if (a5 != 5L) return 5;
759         if (a6 != 6) return 6;
760         if (a7 != 7) return 7;
761         if (a8 != 8.0) return 8;
762         if (a9 !=  9.0f) return 9;
763         if (a10 != 10.0) return 10;
764         if (a11 != (short)11) return 11;
765         if (a12 != 12) return 12;
766         if (a13 != (char)13) return 13;
767         if (a14 != 14) return 14;
768         if (a15 != 15) return 15;
769         if (a16 != (byte)-16) return 16;
770         if (a17 !=  true) return 17;
771         if (a18 != 18) return 18;
772         if (a19 != 19) return 19;
773         if (a20 !=  20L) return 20;
774         if (a21 != 21L) return 21;
775         if (a22 != 22) return 22;
776         if (a23 != 23) return 23;
777         if (a24 != 24) return 24;
778         if (a25 != 25) return 25;
779         if (a26 != 26) return 26;
780         return -1;
781     }
782 
virtualCall(int a)783     int virtualCall(int a)
784     {
785         return a * 2;
786     }
787 
setFoo(int a)788     void setFoo(int a)
789     {
790         foo_ = a;
791     }
792 
getFoo()793     int getFoo()
794     {
795         return foo_;
796     }
797 
staticCall(int a)798     static int staticCall(int a)
799     {
800         Main foo = new Main();
801         return foo.virtualCall(a);
802     }
803 
testIGetPut(int a)804     static int testIGetPut(int a)
805     {
806         Main foo = new Main(99);
807         Main foo123 = new Main();
808         int z  = foo.getFoo();
809         z += a;
810         z += foo123.getFoo();
811         foo.setFoo(z);
812         return foo.getFoo();
813     }
814 
throwClassCast(Object o)815     static int throwClassCast(Object o) {
816       return ((Integer)o).intValue();
817     }
818 
testClassCast()819     static int testClassCast() {
820       int res = 0;
821       try {
822         res += throwClassCast(Integer.valueOf(123));
823       } catch(ClassCastException e) {
824         res += 456;
825       }
826       try {
827         res += throwClassCast(new Short((short)321));
828       } catch(ClassCastException e) {
829         res += 765;
830       }
831       return res;
832     }
833 
throwArrayStoreException(Object[] array, Object element)834     static void throwArrayStoreException(Object[] array, Object element) {
835       array[0] = element;
836     }
837 
testArrayStoreException()838     static int testArrayStoreException() {
839       int res=0;
840       Object[] array = new Number[2];
841       try {
842         throwArrayStoreException(array, null);
843         res += 1;
844       } catch(ArrayStoreException e) {
845         res += 2;
846       }
847       try {
848         throwArrayStoreException(array, Integer.valueOf(1));
849         res += 10;
850       } catch(ArrayStoreException e) {
851         res += 20;
852       }
853       try {
854         throwArrayStoreException(array, "hello MTV-44");
855         res += 100;
856       } catch(ArrayStoreException e) {
857         res += 200;
858       }
859       return res;
860     }
861 
862     static long recursion_count_;
throwStackOverflow(long l)863     static void throwStackOverflow(long l) {
864       recursion_count_++;
865       throwStackOverflow(recursion_count_);
866     }
867 
testStackOverflow()868     static long testStackOverflow() {
869       try {
870         throwStackOverflow(0);
871         if (recursion_count_ != 0) {
872           return recursion_count_;
873         } else {
874           return -1;
875         }
876       } catch(StackOverflowError soe) {
877         return 0;
878       }
879     }
880 
testArrayAllocation()881     static int testArrayAllocation() {
882       int res = 0;
883       try {
884         int[] x = new int[-1];
885         res += 1;
886       } catch (NegativeArraySizeException e) {
887         res += 2;
888       }
889       try {
890         int[] x = new int [1];
891         res += 10;
892       } catch (Throwable e) {
893         res += 20;
894       }
895       return res;
896     }
897 
main(String[] args)898     public static void main(String[] args) {
899         boolean failure = false;
900         int res;
901         long lres;
902 
903         lres = divideLongByBillion(123000000000L);
904         if (lres == 123) {
905             System.out.println("divideLongByBillion PASSED");
906         } else {
907             System.out.println("divideLongByBillion FAILED: " + lres);
908             failure = true;
909         }
910         res = unopTest(38);
911         if (res == 37) {
912             System.out.println("unopTest PASSED");
913         } else {
914             System.out.println("unopTest FAILED: " + res);
915             failure = true;
916         }
917         res = shiftTest1();
918         if (res == 0) {
919             System.out.println("shiftTest1 PASSED");
920         } else {
921             System.out.println("shiftTest1 FAILED: " + res);
922             failure = true;
923         }
924         res = shiftTest2();
925         if (res == 0) {
926             System.out.println("shiftTest2 PASSED");
927         } else {
928             System.out.println("shiftTest2 FAILED: " + res);
929             failure = true;
930         }
931         res = unsignedShiftTest();
932         if (res == 0) {
933             System.out.println("unsignedShiftTest PASSED");
934         } else {
935             System.out.println("unsignedShiftTest FAILED: " + res);
936             failure = true;
937         }
938         res = convTest();
939         if (res == 0) {
940             System.out.println("convTest PASSED");
941         } else {
942             System.out.println("convTest FAILED: " + res);
943             failure = true;
944         }
945         res = charSubTest();
946         if (res == 0) {
947             System.out.println("charSubTest PASSED");
948         } else {
949             System.out.println("charSubTest FAILED: " + res);
950             failure = true;
951         }
952         res = intOperTest(70000, -3);
953         if (res == 0) {
954             System.out.println("intOperTest PASSED");
955         } else {
956             System.out.println("intOperTest FAILED: " + res);
957             failure = true;
958         }
959         res = lit16Test(77777);
960         if (res == 0) {
961             System.out.println("lit16Test PASSED");
962         } else {
963             System.out.println("lit16Test FAILED: " + res);
964             failure = true;
965         }
966         res = lit8Test(-55555);
967         if (res == 0) {
968             System.out.println("lit8Test PASSED");
969         } else {
970             System.out.println("lit8Test FAILED: " + res);
971             failure = true;
972         }
973         res = intShiftTest(0xff00aa01, 8);
974         if (res == 0) {
975             System.out.println("intShiftTest PASSED");
976         } else {
977             System.out.println("intShiftTest FAILED: " + res);
978             failure = true;
979         }
980         res = longOperTest(70000000000L, -3L);
981         if (res == 0) {
982             System.out.println("longOperTest PASSED");
983         } else {
984             System.out.println("longOperTest FAILED: " + res);
985             failure = true;
986         }
987         lres = longShiftTest(0xd5aa96deff00aa01L, 16);
988         if (lres == 0x96deff00aa010000L) {
989             System.out.println("longShiftTest PASSED");
990         } else {
991             System.out.println("longShiftTest FAILED: " + lres);
992             failure = true;
993         }
994 
995         res = switchTest(1);
996         if (res == 1234) {
997             System.out.println("switchTest PASSED");
998         } else {
999             System.out.println("switchTest FAILED: " + res);
1000             failure = true;
1001         }
1002 
1003         res = testIntCompare(-5, 4, 4, 0);
1004         if (res == 1111) {
1005             System.out.println("testIntCompare PASSED");
1006         } else {
1007             System.out.println("testIntCompare FAILED: " + res);
1008             failure = true;
1009         }
1010 
1011         res = testLongCompare(-5L, -4294967287L, 4L, 8L);
1012         if (res == 2222) {
1013             System.out.println("testLongCompare PASSED");
1014         } else {
1015             System.out.println("testLongCompare FAILED: " + res);
1016             failure = true;
1017         }
1018 
1019         res = testFloatCompare(-5.0f, 4.0f, 4.0f, (1.0f/0.0f) / (1.0f/0.0f));
1020         if (res == 3333) {
1021             System.out.println("testFloatCompare PASSED");
1022         } else {
1023             System.out.println("testFloatCompare FAILED: " + res);
1024             failure = true;
1025         }
1026 
1027         res = testDoubleCompare(-5.0, 4.0, 4.0, (1.0/0.0) / (1.0/0.0));
1028         if (res == 4444) {
1029             System.out.println("testDoubleCompare PASSED");
1030         } else {
1031             System.out.println("testDoubleCompare FAILED: " + res);
1032             failure = true;
1033         }
1034 
1035         res = fibonacci(10);
1036         if (res == 55) {
1037             System.out.println("fibonacci PASSED");
1038         } else {
1039             System.out.println("fibonacci FAILED: " + res);
1040             failure = true;
1041         }
1042 
1043         res = throwAndCatch();
1044         if (res == 0) {
1045             System.out.println("throwAndCatch PASSED");
1046         } else {
1047             System.out.println("throwAndCatch FAILED: " + res);
1048             failure = true;
1049         }
1050 
1051         res = testClassCast();
1052         if (res == 888) {
1053             System.out.println("testClassCast PASSED");
1054         } else {
1055             System.out.println("testClassCast FAILED: " + res);
1056             failure = true;
1057         }
1058 
1059         res = testArrayStoreException();
1060         if (res == 211) {
1061           System.out.println("testArrayStore PASSED");
1062         } else {
1063           System.out.println("testArrayStore FAILED: " + res);
1064           failure = true;
1065         }
1066 
1067         lres= testStackOverflow();
1068         if (lres == 0) {
1069             System.out.println("testStackOverflow PASSED");
1070         } else {
1071             System.out.println("testStackOverflow FAILED: " + lres);
1072             failure = true;
1073         }
1074 
1075         res = testArrayAllocation();
1076         if (res == 12) {
1077           System.out.println("testArrayAllocation PASSED");
1078         } else {
1079           System.out.println("testArrayAllocation FAILED: " + res);
1080           failure = true;
1081         }
1082 
1083         res = manyArgs(0, 1L, 2, 3L, 4, 5L, 6, 7, 8.0, 9.0f, 10.0,
1084                        (short)11, 12, (char)13, 14, 15, (byte)-16, true, 18,
1085                        19, 20L, 21L, 22, 23, 24, 25, 26);
1086         if (res == -1) {
1087             System.out.println("manyArgs PASSED");
1088         } else {
1089             System.out.println("manyArgs FAILED: " + res);
1090             failure = true;
1091         }
1092 
1093         res = staticCall(3);
1094         if (res == 6) {
1095             System.out.println("virtualCall PASSED");
1096         } else {
1097             System.out.println("virtualCall FAILED: " + res);
1098             failure = true;
1099         }
1100 
1101         res = testIGetPut(111);
1102         if (res == 333) {
1103             System.out.println("testGetPut PASSED");
1104         } else {
1105             System.out.println("testGetPut FAILED: " + res);
1106             failure = true;
1107         }
1108 
1109         res = staticFieldTest(404);
1110         if (res == 1404) {
1111             System.out.println("staticFieldTest PASSED");
1112         } else {
1113             System.out.println("staticFieldTest FAILED: " + res);
1114             failure = true;
1115         }
1116 
1117         res = catchBlock(1000);
1118         if (res == 1579) {
1119             System.out.println("catchBlock(1000) PASSED");
1120         } else {
1121             System.out.println("catchBlock(1000) FAILED: " + res);
1122             failure = true;
1123         }
1124         res = catchBlock(7000);
1125         if (res == 7777) {
1126             System.out.println("catchBlock(7000) PASSED");
1127         } else {
1128             System.out.println("catchBlock(7000) FAILED: " + res);
1129             failure = true;
1130         }
1131         res = catchBlockNoThrow(1000);
1132         if (res == 1123) {
1133             System.out.println("catchBlockNoThrow PASSED");
1134         } else {
1135             System.out.println("catchBlockNoThrow FAILED: " + res);
1136             failure = true;
1137         }
1138 
1139         res = superTest(4141);
1140         if (res == 4175) {
1141             System.out.println("superTest PASSED");
1142         } else {
1143             System.out.println("superTest FAILED: " + res);
1144             failure = true;
1145         }
1146 
1147         res = constClassTest(1111);
1148         if (res == 2222) {
1149             System.out.println("constClassTest PASSED");
1150         } else {
1151             System.out.println("constClassTest FAILED: " + res);
1152             failure = true;
1153         }
1154 
1155         res = constStringTest(10);
1156         if (res == 22) {
1157             System.out.println("constStringTest PASSED");
1158         } else {
1159             System.out.println("constStringTest FAILED: " + res);
1160             failure = true;
1161         }
1162 
1163         res = instanceTest(10);
1164         if (res == 1436) {
1165             System.out.println("instanceTest PASSED");
1166         } else {
1167             System.out.println("instanceTest FAILED: " + res);
1168             failure = true;
1169         }
1170 
1171         System.exit(failure ? 1 : 0);
1172     }
1173 }
1174 
1175 class IntMathBase {
IntMathBase()1176     IntMathBase() {
1177     }
1178 
tryThing()1179     int tryThing() {
1180         return 7;
1181     }
1182 }
1183