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