blob: 14c68d1447e4f12ea54daedc1618bc57d8995ee1 [file] [log] [blame]
Brian Carlstrom9f30b382011-08-28 22:41:38 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
buzbee4a3164f2011-09-03 11:25:10 -07003class IntMath extends IntMathBase {
Brian Carlstrom9f30b382011-08-28 22:41:38 -07004
5 public static boolean mBoolean1, mBoolean2;
6 public static byte mByte1, mByte2;
7 public static char mChar1, mChar2;
8 public static short mShort1, mShort2;
9 public static int mInt1, mInt2;
10 public static float mFloat1, mFloat2;
11 public static long mLong1, mLong2;
12 public static double mDouble1, mDouble2;
13 public static volatile long mVolatileLong1, mVolatileLong2;
14
15
16 private int foo_;
17
18 public IntMath(int stuff) {
buzbee4a3164f2011-09-03 11:25:10 -070019 super();
Brian Carlstrom9f30b382011-08-28 22:41:38 -070020 foo_ = stuff;
21 }
22
23 public IntMath() {
buzbee4a3164f2011-09-03 11:25:10 -070024 super();
Brian Carlstrom9f30b382011-08-28 22:41:38 -070025 foo_ = 123;
26 }
27
buzbee4a3164f2011-09-03 11:25:10 -070028 int tryThing() {
29 int val = super.tryThing();
30 return val + 10;
31 }
32
33 static int superTest(int x) {
34 IntMath instance = new IntMath();
35 IntMath base = instance;
36 int val1 = instance.tryThing();
37 int val2 = base.tryThing();
38 return val1 + val2 + x;
39 }
40
buzbee561227c2011-09-02 15:28:19 -070041 static int constClassTest(int x) {
42 Class c = String.class;
43 if (c != null) {
44 return x * 2;
45 } else {
46 return x;
47 }
48 }
49
buzbee1b4c8592011-08-31 10:43:51 -070050 static int constStringTest(int x) {
51 /* TODO: flesh this test out when we can call string library */
52 String str = "Hello World!";
53 return x * 2;
54 }
55
56 static void throwNullPointerException() {
57 throw new NullPointerException();
58 }
59
60 static int catchBlock(int x) {
61 try {
62 x += 123;
63 throwNullPointerException();
64 } catch (NullPointerException npe) {
65 x += 456;
66 }
67 return x;
68 }
69
buzbeee9a72f62011-09-04 17:59:07 -070070 static int catchBlockNoThrow(int x) {
71 try {
72 x += 123;
73 } catch (NullPointerException npe) {
74 x += 456;
75 }
76 return x;
77 }
78
Brian Carlstrom9f30b382011-08-28 22:41:38 -070079 static int staticFieldTest(int x) {
80 mBoolean1 = true;
81 mBoolean2 = false;
82 mByte1 = 127;
83 mByte2 = -128;
84 mChar1 = 32767;
85 mChar2 = 65535;
86 mShort1 = 32767;
87 mShort2 = -32768;
88 mInt1 = 65537;
89 mInt2 = -65537;
90 mFloat1 = 3.1415f;
91 mFloat2 = -1.0f / 0.0f; // -inf
92 mLong1 = 1234605616436508552L; // 0x1122334455667788
93 mLong2 = -1234605616436508552L;
94 mDouble1 = 3.1415926535;
95 mDouble2 = 1.0 / 0.0; // +inf
96 mVolatileLong1 = mLong1 - 1;
97 mVolatileLong2 = mLong2 + 1;
98
99 if (!mBoolean1) { return 10; }
100 if (mBoolean2) { return 11; }
101 if (mByte1 != 127) { return 12; }
102 if (mByte2 != -128) { return 13; }
103 if (mChar1 != 32767) { return 14; }
104 if (mChar2 != 65535) { return 15; }
105 if (mShort1 != 32767) { return 16; }
106 if (mShort2 != -32768) { return 17; }
107 if (mInt1 != 65537) { return 18; }
108 if (mInt2 != -65537) { return 19; }
109 if (!(mFloat1 > 3.141f && mFloat1 < 3.142f)) { return 20; }
110 if (mFloat2 >= mFloat1) { return 21; }
111 if (mLong1 != 1234605616436508552L) { return 22; }
112 if (mLong2 != -1234605616436508552L) { return 23; }
113 if (!(mDouble1 > 3.141592653 && mDouble1 < 3.141592654)) { return 24; }
114 if (mDouble2 <= mDouble1) { return 25; }
115 if (mVolatileLong1 != 1234605616436508551L) { return 26; }
116 if (mVolatileLong2 != -1234605616436508551L) { return 27; }
117
118 return 1000 + x;
119 }
120
121 /*
122 * Try to cause some unary operations.
123 */
124 static int unopTest(int x) {
125 x = -x;
126 x ^= 0xffffffff;
127 return x;
128 }
129
130 static int shiftTest1() {
131 final int[] mBytes = {
132 0x11, 0x22, 0x33, 0x44, 0x88, 0x99, 0xaa, 0xbb
133 };
134 long l;
135 int i1, i2;
136
137 if (mBytes[0] != 0x11) return 20;
138 if (mBytes[1] != 0x22) return 21;
139 if (mBytes[2] != 0x33) return 22;
140 if (mBytes[3] != 0x44) return 23;
141 if (mBytes[4] != 0x88) return 24;
142 if (mBytes[5] != 0x99) return 25;
143 if (mBytes[6] != 0xaa) return 26;
144 if (mBytes[7] != 0xbb) return 27;
145
146 i1 = mBytes[0] | mBytes[1] << 8 | mBytes[2] << 16 | mBytes[3] << 24;
147 i2 = mBytes[4] | mBytes[5] << 8 | mBytes[6] << 16 | mBytes[7] << 24;
148 l = i1 | ((long)i2 << 32);
149
150 if (i1 != 0x44332211) { return 0x80000000 | i1; }
151 if (i2 != 0xbbaa9988) { return 2; }
152 if (l != 0xbbaa998844332211L) { return 3; }
153
154 l = (long)mBytes[0]
155 | (long)mBytes[1] << 8
156 | (long)mBytes[2] << 16
157 | (long)mBytes[3] << 24
158 | (long)mBytes[4] << 32
159 | (long)mBytes[5] << 40
160 | (long)mBytes[6] << 48
161 | (long)mBytes[7] << 56;
162
163 if (l != 0xbbaa998844332211L) { return 4; }
164 return 0;
165 }
166
167 static int shiftTest2() {
168
169 long a = 0x11;
170 long b = 0x22;
171 long c = 0x33;
172 long d = 0x44;
173 long e = 0x55;
174 long f = 0x66;
175 long g = 0x77;
176 long h = 0x88;
177
178 long result = ((a << 56) | (b << 48) | (c << 40) | (d << 32) |
179 (e << 24) | (f << 16) | (g << 8) | h);
180
181 if (result != 0x1122334455667788L) { return 1; }
182 return 0;
183 }
184
185 static int unsignedShiftTest() {
186 byte b = -4;
187 short s = -4;
188 char c = 0xfffc;
189 int i = -4;
190
191 b >>>= 4;
192 s >>>= 4;
193 c >>>= 4;
194 i >>>= 4;
195
196 if ((int) b != -1) { return 1; }
197 if ((int) s != -1) { return 2; }
198 if ((int) c != 0x0fff) { return 3; }
199 if (i != 268435455) { return 4; }
200 return 0;
201 }
202
203 static int convTest() {
204
205 float f;
206 double d;
207 int i;
208 long l;
209
210 /* int --> long */
211 i = 7654;
212 l = (long) i;
213 if (l != 7654L) { return 1; }
214
215 i = -7654;
216 l = (long) i;
217 if (l != -7654L) { return 2; }
218
219 /* long --> int (with truncation) */
220 l = 5678956789L;
221 i = (int) l;
222 if (i != 1383989493) { return 3; }
223
224 l = -5678956789L;
225 i = (int) l;
226 if (i != -1383989493) { return 4; }
227 return 0;
228 }
229
230 static int charSubTest() {
231
232 char char1 = 0x00e9;
233 char char2 = 0xffff;
234 int i;
235
236 /* chars are unsigned-expanded to ints before subtraction */
237 i = char1 - char2;
238 if (i != 0xffff00ea) { return 1; }
239 return 0;
240 }
241
242 /*
243 * We pass in the arguments and return the results so the compiler
244 * doesn't do the math for us. (x=70000, y=-3)
245 */
246 static int intOperTest(int x, int y) {
247 int[] results = new int[10];
248
249 /* this seems to generate "op-int" instructions */
250 results[0] = x + y;
251 results[1] = x - y;
252 results[2] = x * y;
253 results[3] = x * x;
254 results[4] = x / y;
255 results[5] = x % -y;
256 results[6] = x & y;
257 results[7] = x | y;
258 results[8] = x ^ y;
259
260 /* this seems to generate "op-int/2addr" instructions */
261 results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
262
263 /* check this edge case while we're here (div-int/2addr) */
264 int minInt = -2147483648;
265 int negOne = -results[5];
266 int plusOne = 1;
267 int result = (((minInt + plusOne) - plusOne) / negOne) / negOne;
268
269 if (result != minInt) { return 1;};
270 if (results[0] != 69997) { return 2;};
271 if (results[1] != 70003) { return 3;};
272 if (results[2] != -210000) { return 4;};
273 if (results[3] != 605032704) { return 5;};
274 if (results[4] != -23333) { return 6;};
275 if (results[5] != 1) { return 7;};
276 if (results[6] != 70000) { return 8;};
277 if (results[7] != -3) { return 9;};
278 if (results[8] != -70003) { return 10;};
279 if (results[9] != 70000) { return 11;};
280
281 return 0;
282 }
283
284 /*
285 * More operations, this time with 16-bit constants. (x=77777)
286 */
287 static int lit16Test(int x) {
288
289 int[] results = new int[8];
290
291 /* try to generate op-int/lit16" instructions */
292 results[0] = x + 1000;
293 results[1] = 1000 - x;
294 results[2] = x * 1000;
295 results[3] = x / 1000;
296 results[4] = x % 1000;
297 results[5] = x & 1000;
298 results[6] = x | -1000;
299 results[7] = x ^ -1000;
300
301 if (results[0] != 78777) { return 1; }
302 if (results[1] != -76777) { return 2; }
303 if (results[2] != 77777000) { return 3; }
304 if (results[3] != 77) { return 4; }
305 if (results[4] != 777) { return 5; }
306 if (results[5] != 960) { return 6; }
307 if (results[6] != -39) { return 7; }
308 if (results[7] != -76855) { return 8; }
309 return 0;
310 }
311
312 /*
313 * More operations, this time with 8-bit constants. (x=-55555)
314 */
315 static int lit8Test(int x) {
316
317 int[] results = new int[8];
318
319 /* try to generate op-int/lit8" instructions */
320 results[0] = x + 10;
321 results[1] = 10 - x;
322 results[2] = x * 10;
323 results[3] = x / 10;
324 results[4] = x % 10;
325 results[5] = x & 10;
326 results[6] = x | -10;
327 results[7] = x ^ -10;
328 int minInt = -2147483648;
329 int result = minInt / -1;
330 if (result != minInt) {return 1; }
331 if (results[0] != -55545) {return 2; }
332 if (results[1] != 55565) {return 3; }
333 if (results[2] != -555550) {return 4; }
334 if (results[3] != -5555) {return 5; }
335 if (results[4] != -5) {return 6; }
336 if (results[5] != 8) {return 7; }
337 if (results[6] != -1) {return 8; }
338 if (results[7] != 55563) {return 9; }
339 return 0;
340 }
341
342
343 /*
344 * Shift some data. (value=0xff00aa01, dist=8)
345 */
346 static int intShiftTest(int value, int dist) {
347 int results[] = new int[4];
348 results[0] = value << dist;
349 results[1] = value >> dist;
350 results[2] = value >>> dist;
351 results[3] = (((value << dist) >> dist) >>> dist) << dist;
352 if (results[0] != 0x00aa0100) {return 1; }
353 if (results[1] != 0xffff00aa) {return 2; }
354 if (results[2] != 0x00ff00aa) {return 3; }
355 if (results[3] != 0xaa00) {return 4; }
356 return 0;
357 }
358
359 /*
360 * We pass in the arguments and return the results so the compiler
361 * doesn't do the math for us. (x=70000000000, y=-3)
362 */
363 static int longOperTest(long x, long y) {
364 long[] results = new long[10];
365
366 /* this seems to generate "op-long" instructions */
367 results[0] = x + y;
368 results[1] = x - y;
369 results[2] = x * y;
370 results[3] = x * x;
371 results[4] = x / y;
372 results[5] = x % -y;
373 results[6] = x & y;
374 results[7] = x | y;
375 results[8] = x ^ y;
376 /* this seems to generate "op-long/2addr" instructions */
377 results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
378 /* check this edge case while we're here (div-long/2addr) */
379 long minLong = -9223372036854775808L;
380 long negOne = -results[5];
381 long plusOne = 1;
382 long result = (((minLong + plusOne) - plusOne) / negOne) / negOne;
383 if (result != minLong) { return 1; }
384 if (results[0] != 69999999997L) { return 2; }
385 if (results[1] != 70000000003L) { return 3; }
386 if (results[2] != -210000000000L) { return 4; }
387 if (results[3] != -6833923606740729856L) { return 5; } // overflow
388 if (results[4] != -23333333333L) { return 6; }
389 if (results[5] != 1) { return 7; }
390 if (results[6] != 70000000000L) { return 8; }
391 if (results[7] != -3) { return 9; }
392 if (results[8] != -70000000003L) { return 10; }
393 if (results[9] != 70000000000L) { return 11; }
394 if (results.length != 10) { return 12; }
395 return 0;
396 }
397
398 /*
399 * Shift some data. (value=0xd5aa96deff00aa01, dist=16)
400 */
401 static long longShiftTest(long value, int dist) {
402 long results[] = new long[4];
403 results[0] = value << dist;
404 results[1] = value >> dist;
405 results[2] = value >>> dist;
406 results[3] = (((value << dist) >> dist) >>> dist) << dist;
407 if (results[0] != 0x96deff00aa010000L) { return results[0]; }
408 if (results[1] != 0xffffd5aa96deff00L) { return results[1]; }
409 if (results[2] != 0x0000d5aa96deff00L) { return results[2]; }
410 if (results[3] != 0xffff96deff000000L) { return results[3]; }
411 if (results.length != 4) { return 5; }
412
413 return results[0]; // test return-long
414 }
415
416 static int switchTest(int a) {
417 int res = 1234;
418
419 switch (a) {
420 case -1: res = 1; return res;
421 case 0: res = 2; return res;
422 case 1: /*correct*/ break;
423 case 2: res = 3; return res;
424 case 3: res = 4; return res;
425 case 4: res = 5; return res;
426 default: res = 6; return res;
427 }
428 switch (a) {
429 case 3: res = 7; return res;
430 case 4: res = 8; return res;
431 default: /*correct*/ break;
432 }
433
434 a = 0x12345678;
435
436 switch (a) {
437 case 0x12345678: /*correct*/ break;
438 case 0x12345679: res = 9; return res;
439 default: res = 1; return res;
440 }
441 switch (a) {
442 case 57: res = 10; return res;
443 case -6: res = 11; return res;
444 case 0x12345678: /*correct*/ break;
445 case 22: res = 12; return res;
446 case 3: res = 13; return res;
447 default: res = 14; return res;
448 }
449 switch (a) {
450 case -6: res = 15; return res;
451 case 3: res = 16; return res;
452 default: /*correct*/ break;
453 }
454
455 a = -5;
456 switch (a) {
457 case 12: res = 17; return res;
458 case -5: /*correct*/ break;
459 case 0: res = 18; return res;
460 default: res = 19; return res;
461 }
462
463 switch (a) {
464 default: /*correct*/ break;
465 }
466 return res;
467 }
468 /*
469 * Test the integer comparisons in various ways.
470 */
471 static int testIntCompare(int minus, int plus, int plus2, int zero) {
472 int res = 1111;
473
474 if (minus > plus)
475 return 1;
476 if (minus >= plus)
477 return 2;
478 if (plus < minus)
479 return 3;
480 if (plus <= minus)
481 return 4;
482 if (plus == minus)
483 return 5;
484 if (plus != plus2)
485 return 6;
486
487 /* try a branch-taken */
488 if (plus != minus) {
489 res = res;
490 } else {
491 return 7;
492 }
493
494 if (minus > 0)
495 return 8;
496 if (minus >= 0)
497 return 9;
498 if (plus < 0)
499 return 10;
500 if (plus <= 0)
501 return 11;
502 if (plus == 0)
503 return 12;
504 if (zero != 0)
505 return 13;
506
507 if (zero == 0) {
508 res = res;
509 } else {
510 return 14;
511 }
512 return res;
513 }
514
515 /*
516 * Test cmp-long.
517 *
518 * minus=-5, alsoMinus=0xFFFFFFFF00000009, plus=4, alsoPlus=8
519 */
520 static int testLongCompare(long minus, long alsoMinus, long plus,
521 long alsoPlus) {
522 int res = 2222;
523
524 if (minus > plus)
525 return 2;
526 if (plus < minus)
527 return 3;
528 if (plus == minus)
529 return 4;
530
531 if (plus >= plus+1)
532 return 5;
533 if (minus >= minus+1)
534 return 6;
535
536 /* try a branch-taken */
537 if (plus != minus) {
538 res = res;
539 } else {
540 return 7;
541 }
542
543 /* compare when high words are equal but low words differ */
544 if (plus > alsoPlus)
545 return 8;
546 if (alsoPlus < plus)
547 return 9;
548 if (alsoPlus == plus)
549 return 10;
550
551 /* high words are equal, low words have apparently different signs */
552 if (minus < alsoMinus) // bug!
553 return 11;
554 if (alsoMinus > minus)
555 return 12;
556 if (alsoMinus == minus)
557 return 13;
558
559 return res;
560 }
561
562 /*
563 * Test cmpl-float and cmpg-float.
564 */
565 static int testFloatCompare(float minus, float plus, float plus2,
566 float nan) {
567
568 int res = 3333;
569 if (minus > plus)
570 res = 1;
571 if (plus < minus)
572 res = 2;
573 if (plus == minus)
574 res = 3;
575 if (plus != plus2)
576 res = 4;
577
578 if (plus <= nan)
579 res = 5;
580 if (plus >= nan)
581 res = 6;
582 if (minus <= nan)
583 res = 7;
584 if (minus >= nan)
585 res = 8;
586 if (nan >= plus)
587 res = 9;
588 if (nan <= plus)
589 res = 10;
590
591 if (nan == nan)
592 res = 1212;
593
594 return res;
595 }
596
597 static int testDoubleCompare(double minus, double plus, double plus2,
598 double nan) {
599
600 int res = 4444;
601
602 if (minus > plus)
603 return 1;
604 if (plus < minus)
605 return 2;
606 if (plus == minus)
607 return 3;
608 if (plus != plus2)
609 return 4;
610
611 if (plus <= nan)
612 return 5;
613 if (plus >= nan)
614 return 6;
615 if (minus <= nan)
616 return 7;
617 if (minus >= nan)
618 return 8;
619 if (nan >= plus)
620 return 9;
621 if (nan <= plus)
622 return 10;
623
624 if (nan == nan)
625 return 11;
626 return res;
627 }
628
629 static int fibonacci(int n) {
630 if (n == 0) {
631 return 0;
632 } else if (n == 1) {
633 return 1;
634 } else {
635 return fibonacci(n - 1) + fibonacci(n - 2);
636 }
637 }
638
buzbeee9a72f62011-09-04 17:59:07 -0700639 static int throwAndCatch() {
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700640 try {
buzbeee9a72f62011-09-04 17:59:07 -0700641 throwNullPointerException();
642 return 1;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700643 } catch (NullPointerException npe) {
buzbeee9a72f62011-09-04 17:59:07 -0700644 return 0;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700645 }
buzbeee9a72f62011-09-04 17:59:07 -0700646 }
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700647
648 static int manyArgs(int a0, long a1, int a2, long a3, int a4, long a5,
649 int a6, int a7, double a8, float a9, double a10, short a11, int a12,
650 char a13, int a14, int a15, byte a16, boolean a17, int a18, int a19,
651 long a20, long a21, int a22, int a23, int a24, int a25, int a26)
652 {
653 if (a0 != 0) return 0;
654 if (a1 != 1L) return 1;
655 if (a2 != 2) return 2;
656 if (a3 != 3L) return 3;
657 if (a4 != 4) return 4;
658 if (a5 != 5L) return 5;
659 if (a6 != 6) return 6;
660 if (a7 != 7) return 7;
661 if (a8 != 8.0) return 8;
662 if (a9 != 9.0f) return 9;
663 if (a10 != 10.0) return 10;
664 if (a11 != (short)11) return 11;
665 if (a12 != 12) return 12;
666 if (a13 != (char)13) return 13;
667 if (a14 != 14) return 14;
668 if (a15 != 15) return 15;
669 if (a16 != (byte)-16) return 16;
670 if (a17 != true) return 17;
671 if (a18 != 18) return 18;
672 if (a19 != 19) return 19;
673 if (a20 != 20L) return 20;
674 if (a21 != 21L) return 21;
675 if (a22 != 22) return 22;
676 if (a23 != 23) return 23;
677 if (a24 != 24) return 24;
678 if (a25 != 25) return 25;
679 if (a26 != 26) return 26;
680 return -1;
681 }
682
683 int virtualCall(int a)
684 {
685 return a * 2;
686 }
687
688 void setFoo(int a)
689 {
690 foo_ = a;
691 }
692
693 int getFoo()
694 {
695 return foo_;
696 }
697
698 static int staticCall(int a)
699 {
700 IntMath foo = new IntMath();
701 return foo.virtualCall(a);
702 }
703
704 static int testIGetPut(int a)
705 {
706 IntMath foo = new IntMath(99);
707 IntMath foo123 = new IntMath();
708 int z = foo.getFoo();
709 z += a;
710 z += foo123.getFoo();
711 foo.setFoo(z);
712 return foo.getFoo();
713 }
714
715 public static void main(String[] args) {
716 int res = unopTest(38);
717 if (res == 37) {
buzbee1da522d2011-09-04 11:22:20 -0700718 System.out.println("unopTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700719 } else {
buzbee1da522d2011-09-04 11:22:20 -0700720 System.out.println("unopTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700721 }
722 res = shiftTest1();
723 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700724 System.out.println("shiftTest1 PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700725 } else {
buzbee1da522d2011-09-04 11:22:20 -0700726 System.out.println("shiftTest1 FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700727 }
728 res = shiftTest2();
729 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700730 System.out.println("shiftTest2 PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700731 } else {
buzbee1da522d2011-09-04 11:22:20 -0700732 System.out.println("shiftTest2 FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700733 }
734 res = unsignedShiftTest();
735 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700736 System.out.println("unsignedShiftTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700737 } else {
buzbee1da522d2011-09-04 11:22:20 -0700738 System.out.println("unsignedShiftTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700739 }
740 res = convTest();
741 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700742 System.out.println("convTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700743 } else {
buzbee1da522d2011-09-04 11:22:20 -0700744 System.out.println("convTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700745 }
746 res = charSubTest();
747 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700748 System.out.println("charSubTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700749 } else {
buzbee1da522d2011-09-04 11:22:20 -0700750 System.out.println("charSubTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700751 }
752 res = intOperTest(70000, -3);
753 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700754 System.out.println("intOperTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700755 } else {
buzbee1da522d2011-09-04 11:22:20 -0700756 System.out.println("intOperTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700757 }
758 res = longOperTest(70000000000L, -3L);
759 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700760 System.out.println("longOperTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700761 } else {
buzbee1da522d2011-09-04 11:22:20 -0700762 System.out.println("longOperTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700763 }
764 long lres = longShiftTest(0xd5aa96deff00aa01L, 16);
765 if (lres == 0x96deff00aa010000L) {
buzbee1da522d2011-09-04 11:22:20 -0700766 System.out.println("longShiftTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700767 } else {
buzbee1da522d2011-09-04 11:22:20 -0700768 System.out.println("longShiftTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700769 }
770
771 res = switchTest(1);
772 if (res == 1234) {
buzbee1da522d2011-09-04 11:22:20 -0700773 System.out.println("switchTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700774 } else {
buzbee1da522d2011-09-04 11:22:20 -0700775 System.out.println("switchTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700776 }
777
778 res = testIntCompare(-5, 4, 4, 0);
779 if (res == 1111) {
buzbee1da522d2011-09-04 11:22:20 -0700780 System.out.println("testIntCompare PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700781 } else {
buzbee1da522d2011-09-04 11:22:20 -0700782 System.out.println("testIntCompare FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700783 }
784
785 res = testLongCompare(-5L, -4294967287L, 4L, 8L);
786 if (res == 2222) {
buzbee1da522d2011-09-04 11:22:20 -0700787 System.out.println("testLongCompare PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700788 } else {
buzbee1da522d2011-09-04 11:22:20 -0700789 System.out.println("testLongCompare FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700790 }
791
792 res = testFloatCompare(-5.0f, 4.0f, 4.0f, (1.0f/0.0f) / (1.0f/0.0f));
793 if (res == 3333) {
buzbee1da522d2011-09-04 11:22:20 -0700794 System.out.println("testFloatCompare PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700795 } else {
buzbee1da522d2011-09-04 11:22:20 -0700796 System.out.println("testFloatCompare FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700797 }
798
799 res = testDoubleCompare(-5.0, 4.0, 4.0, (1.0/0.0) / (1.0/0.0));
800 if (res == 4444) {
buzbee1da522d2011-09-04 11:22:20 -0700801 System.out.println("testDoubleCompare PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700802 } else {
buzbee1da522d2011-09-04 11:22:20 -0700803 System.out.println("testDoubleCompare FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700804 }
805
806 res = fibonacci(10);
807 if (res == 55) {
buzbee1da522d2011-09-04 11:22:20 -0700808 System.out.println("fibonacci PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700809 } else {
buzbee1da522d2011-09-04 11:22:20 -0700810 System.out.println("fibonacci FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700811 }
812
buzbeee9a72f62011-09-04 17:59:07 -0700813 res = throwAndCatch();
814 if (res == 0) {
buzbee1da522d2011-09-04 11:22:20 -0700815 System.out.println("throwAndCatch PASSED");
buzbeee9a72f62011-09-04 17:59:07 -0700816 } else {
buzbee1da522d2011-09-04 11:22:20 -0700817 System.out.println("throwAndCatch FAILED: " + res);
buzbeee9a72f62011-09-04 17:59:07 -0700818 }
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700819
820 res = manyArgs(0, 1L, 2, 3L, 4, 5L, 6, 7, 8.0, 9.0f, 10.0,
821 (short)11, 12, (char)13, 14, 15, (byte)-16, true, 18,
822 19, 20L, 21L, 22, 23, 24, 25, 26);
823 if (res == -1) {
buzbee1da522d2011-09-04 11:22:20 -0700824 System.out.println("manyArgs PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700825 } else {
buzbee1da522d2011-09-04 11:22:20 -0700826 System.out.println("manyArgs FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700827 }
828
829 res = staticCall(3);
830 if (res == 6) {
buzbee1da522d2011-09-04 11:22:20 -0700831 System.out.println("virtualCall PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700832 } else {
buzbee1da522d2011-09-04 11:22:20 -0700833 System.out.println("virtualCall FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700834 }
835
836 res = testIGetPut(111);
837 if (res == 333) {
buzbee1da522d2011-09-04 11:22:20 -0700838 System.out.println("testGetPut PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700839 } else {
buzbee1da522d2011-09-04 11:22:20 -0700840 System.out.println("testGetPut FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700841 }
842
843 res = staticFieldTest(404);
844 if (res == 1404) {
buzbee1da522d2011-09-04 11:22:20 -0700845 System.out.println("staticFieldTest PASSED");
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700846 } else {
buzbee1da522d2011-09-04 11:22:20 -0700847 System.out.println("staticFieldTest FAILED: " + res);
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700848 }
buzbee1b4c8592011-08-31 10:43:51 -0700849
850 res = catchBlock(1000);
851 if (res == 1579) {
buzbee1da522d2011-09-04 11:22:20 -0700852 System.out.println("catchBlock PASSED");
buzbee1b4c8592011-08-31 10:43:51 -0700853 } else {
buzbee1da522d2011-09-04 11:22:20 -0700854 System.out.println("catchBlock FAILED: " + res);
buzbee1b4c8592011-08-31 10:43:51 -0700855 }
buzbee4a3164f2011-09-03 11:25:10 -0700856
buzbeee9a72f62011-09-04 17:59:07 -0700857 res = catchBlockNoThrow(1000);
858 if (res == 1123) {
859 System.out.println("catchBlockNoThrow PASSED");
860 } else {
861 System.out.println("catchBlockNoThrow FAILED: " + res);
862 }
863
buzbee4a3164f2011-09-03 11:25:10 -0700864 res = superTest(4141);
865 if (res == 4175) {
buzbee1da522d2011-09-04 11:22:20 -0700866 System.out.println("superTest PASSED");
buzbee4a3164f2011-09-03 11:25:10 -0700867 } else {
buzbee1da522d2011-09-04 11:22:20 -0700868 System.out.println("superTest FAILED: " + res);
buzbee4a3164f2011-09-03 11:25:10 -0700869 }
870 }
871}
872
873class IntMathBase {
874 IntMathBase() {
875 }
876
877 int tryThing() {
878 return 7;
Brian Carlstrom9f30b382011-08-28 22:41:38 -0700879 }
880}