Home | History | Annotate | Download | only in src
      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 
    301         /* long --> double */
    302         l = 0x7FFFFFFFL;
    303         d = (double) l;
    304         if (Double.doubleToRawLongBits(d) != 0x41dfffffffc00000L) { return 5; }
    305 
    306         l = 0xFFFFFFFFL;
    307         d = (double) l;
    308         if (Double.doubleToRawLongBits(d) != 0x41efffffffe00000L) { return 6; }
    309 
    310         l = 0x7FFFFFFFFFFFFFFFL;
    311         d = (double) l;
    312         if (Double.doubleToRawLongBits(d) != 0x43e0000000000000L) { return 7; }
    313 
    314         l = 0xFFFFFFFFFFFFFFFFL;
    315         d = (double) l;
    316         if (Double.doubleToRawLongBits(d) != 0xbff0000000000000L) { return 8; }
    317 
    318         return 0;
    319     }
    320 
    321     static int charSubTest() {
    322 
    323         char char1 = 0x00e9;
    324         char char2 = 0xffff;
    325         int i;
    326 
    327         /* chars are unsigned-expanded to ints before subtraction */
    328         i = char1 - char2;
    329         if (i != 0xffff00ea) { return 1; }
    330         return 0;
    331     }
    332 
    333     /*
    334      * We pass in the arguments and return the results so the compiler
    335      * doesn't do the math for us.  (x=70000, y=-3)
    336      */
    337     static int intOperTest(int x, int y) {
    338         int[] results = new int[10];
    339 
    340         /* this seems to generate "op-int" instructions */
    341         results[0] = x + y;
    342         results[1] = x - y;
    343         results[2] = x * y;
    344         results[3] = x * x;
    345         results[4] = x / y;
    346         results[5] = x % -y;
    347         results[6] = x & y;
    348         results[7] = x | y;
    349         results[8] = x ^ y;
    350 
    351         /* this seems to generate "op-int/2addr" instructions */
    352         results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
    353 
    354         /* check this edge case while we're here (div-int/2addr) */
    355         int minInt = -2147483648;
    356         int negOne = -results[5];
    357         int plusOne = 1;
    358         int result = (((minInt + plusOne) - plusOne) / negOne) / negOne;
    359         int shouldBeZero = minInt % negOne;
    360 
    361         if (result != minInt) { return 1;};
    362         if (results[0] != 69997) { return 2;};
    363         if (results[1] != 70003) { return 3;};
    364         if (results[2] != -210000) { return 4;};
    365         if (results[3] != 605032704) { return 5;};
    366         if (results[4] != -23333) { return 6;};
    367         if (results[5] != 1) { return 7;};
    368         if (results[6] != 70000) { return 8;};
    369         if (results[7] != -3) { return 9;};
    370         if (results[8] != -70003) { return 10;};
    371         if (results[9] != 70000) { return 11;};
    372         if (shouldBeZero != 0) { return 12;};
    373 
    374         return 0;
    375     }
    376 
    377     /*
    378      * More operations, this time with 16-bit constants.  (x=77777)
    379      */
    380     static int lit16Test(int x) {
    381 
    382         int[] results = new int[10];
    383 
    384         /* try to generate op-int/lit16" instructions */
    385         results[0] = x + 1000;
    386         results[1] = 1000 - x;
    387         results[2] = x * 1000;
    388         results[3] = x / 1000;
    389         results[4] = x % 1000;
    390         results[5] = x & 1000;
    391         results[6] = x | -1000;
    392         results[7] = x ^ -1000;
    393         /* use an 16-bit constant that has its MSB (bit-15) set */
    394         results[8] = x / 32769;
    395         results[9] = x / -32769;
    396 
    397         if (results[0] != 78777) { return 1; }
    398         if (results[1] != -76777) { return 2; }
    399         if (results[2] != 77777000) { return 3; }
    400         if (results[3] != 77) { return 4; }
    401         if (results[4] != 777) { return 5; }
    402         if (results[5] != 960) { return 6; }
    403         if (results[6] != -39) { return 7; }
    404         if (results[7] != -76855) { return 8; }
    405         if (results[8] != 2) { return 9; }
    406         if (results[9] != -2) { return 10; }
    407         return 0;
    408     }
    409 
    410     /*
    411      * More operations, this time with 8-bit constants.  (x=-55555)
    412      */
    413     static int lit8Test(int x) {
    414 
    415         int[] results = new int[8];
    416 
    417         /* try to generate op-int/lit8" instructions */
    418         results[0] = x + 10;
    419         results[1] = 10 - x;
    420         results[2] = x * 10;
    421         results[3] = x / 10;
    422         results[4] = x % 10;
    423         results[5] = x & 10;
    424         results[6] = x | -10;
    425         results[7] = x ^ -10;
    426         int minInt = -2147483648;
    427         int result = minInt / -1;
    428         if (result != minInt) {return 1; }
    429         if (results[0] != -55545) {return 2; }
    430         if (results[1] != 55565) {return 3; }
    431         if (results[2] != -555550) {return 4; }
    432         if (results[3] != -5555) {return 5; }
    433         if (results[4] != -5) {return 6; }
    434         if (results[5] != 8) {return 7; }
    435         if (results[6] != -1) {return 8; }
    436         if (results[7] != 55563) {return 9; }
    437         return 0;
    438     }
    439 
    440 
    441     /*
    442      * Shift some data.  (value=0xff00aa01, dist=8)
    443      */
    444     static int intShiftTest(int value, int dist) {
    445         int results[] = new int[4];
    446         results[0] = value << dist;
    447         results[1] = value >> dist;
    448         results[2] = value >>> dist;
    449         results[3] = (((value << dist) >> dist) >>> dist) << dist;
    450         if (results[0] != 0x00aa0100) {return 1; }
    451         if (results[1] != 0xffff00aa) {return 2; }
    452         if (results[2] != 0x00ff00aa) {return 3; }
    453         if (results[3] != 0xaa00) {return 4; }
    454         return 0;
    455     }
    456 
    457     /*
    458      * We pass in the arguments and return the results so the compiler
    459      * doesn't do the math for us.  (x=70000000000, y=-3)
    460      */
    461     static int longOperTest(long x, long y) {
    462         long[] results = new long[10];
    463 
    464         /* this seems to generate "op-long" instructions */
    465         results[0] = x + y;
    466         results[1] = x - y;
    467         results[2] = x * y;
    468         results[3] = x * x;
    469         results[4] = x / y;
    470         results[5] = x % -y;
    471         results[6] = x & y;
    472         results[7] = x | y;
    473         results[8] = x ^ y;
    474         /* this seems to generate "op-long/2addr" instructions */
    475         results[9] = x + ((((((((x + y) - y) * y) / y) % y) & y) | y) ^ y);
    476         /* check this edge case while we're here (div-long/2addr) */
    477         long minLong = -9223372036854775808L;
    478         long negOne = -results[5];
    479         long plusOne = 1;
    480         long result = (((minLong + plusOne) - plusOne) / negOne) / negOne;
    481         if (result != minLong) { return 1; }
    482         if (results[0] != 69999999997L) { return 2; }
    483         if (results[1] != 70000000003L) { return 3; }
    484         if (results[2] != -210000000000L) { return 4; }
    485         if (results[3] != -6833923606740729856L) { return 5; }    // overflow
    486         if (results[4] != -23333333333L) { return 6; }
    487         if (results[5] != 1) { return 7; }
    488         if (results[6] != 70000000000L) { return 8; }
    489         if (results[7] != -3) { return 9; }
    490         if (results[8] != -70000000003L) { return 10; }
    491         if (results[9] != 70000000000L) { return 11; }
    492         if (results.length != 10) { return 12; }
    493         return 0;
    494     }
    495 
    496     /*
    497      * Shift some data.  (value=0xd5aa96deff00aa01, dist=16)
    498      */
    499     static long longShiftTest(long value, int dist) {
    500         long results[] = new long[4];
    501         results[0] = value << dist;
    502         results[1] = value >> dist;
    503         results[2] = value >>> dist;
    504         results[3] = (((value << dist) >> dist) >>> dist) << dist;
    505         if (results[0] != 0x96deff00aa010000L) { return results[0]; }
    506         if (results[1] != 0xffffd5aa96deff00L) { return results[1]; }
    507         if (results[2] != 0x0000d5aa96deff00L) { return results[2]; }
    508         if (results[3] != 0xffff96deff000000L) { return results[3]; }
    509         if (results.length != 4) { return 5; }
    510 
    511         return results[0];      // test return-long
    512     }
    513 
    514     static int switchTest(int a) {
    515         int res = 1234;
    516 
    517         switch (a) {
    518             case -1: res = 1; return res;
    519             case 0: res = 2; return res;
    520             case 1: /*correct*/ break;
    521             case 2: res = 3; return res;
    522             case 3: res = 4; return res;
    523             case 4: res = 5; return res;
    524             default: res = 6; return res;
    525         }
    526         switch (a) {
    527             case 3: res = 7; return res;
    528             case 4: res = 8; return res;
    529             default: /*correct*/ break;
    530         }
    531 
    532         a = 0x12345678;
    533 
    534         switch (a) {
    535             case 0x12345678: /*correct*/ break;
    536             case 0x12345679: res = 9; return res;
    537             default: res = 1; return res;
    538         }
    539         switch (a) {
    540             case 57: res = 10; return res;
    541             case -6: res = 11; return res;
    542             case 0x12345678: /*correct*/ break;
    543             case 22: res = 12; return res;
    544             case 3: res = 13; return res;
    545             default: res = 14; return res;
    546         }
    547         switch (a) {
    548             case -6: res = 15; return res;
    549             case 3: res = 16; return res;
    550             default: /*correct*/ break;
    551         }
    552 
    553         a = -5;
    554         switch (a) {
    555             case 12: res = 17; return res;
    556             case -5: /*correct*/ break;
    557             case 0: res = 18; return res;
    558             default: res = 19; return res;
    559         }
    560 
    561         switch (a) {
    562             default: /*correct*/ break;
    563         }
    564         return res;
    565     }
    566     /*
    567      * Test the integer comparisons in various ways.
    568      */
    569     static int testIntCompare(int minus, int plus, int plus2, int zero) {
    570         int res = 1111;
    571 
    572         if (minus > plus)
    573             return 1;
    574         if (minus >= plus)
    575             return 2;
    576         if (plus < minus)
    577             return 3;
    578         if (plus <= minus)
    579             return 4;
    580         if (plus == minus)
    581             return 5;
    582         if (plus != plus2)
    583             return 6;
    584 
    585         /* try a branch-taken */
    586         if (plus != minus) {
    587             res = res;
    588         } else {
    589             return 7;
    590         }
    591 
    592         if (minus > 0)
    593             return 8;
    594         if (minus >= 0)
    595             return 9;
    596         if (plus < 0)
    597             return 10;
    598         if (plus <= 0)
    599             return 11;
    600         if (plus == 0)
    601             return 12;
    602         if (zero != 0)
    603             return 13;
    604 
    605         if (zero == 0) {
    606             res = res;
    607         } else {
    608             return 14;
    609         }
    610         return res;
    611     }
    612 
    613     /*
    614      * Test cmp-long.
    615      *
    616      * minus=-5, alsoMinus=0xFFFFFFFF00000009, plus=4, alsoPlus=8
    617      */
    618     static int testLongCompare(long minus, long alsoMinus, long plus,
    619                                long alsoPlus) {
    620         int res = 2222;
    621 
    622         if (minus > plus)
    623             return 2;
    624         if (plus < minus)
    625             return 3;
    626         if (plus == minus)
    627             return 4;
    628 
    629         if (plus >= plus+1)
    630             return 5;
    631         if (minus >= minus+1)
    632             return 6;
    633 
    634         /* try a branch-taken */
    635         if (plus != minus) {
    636             res = res;
    637         } else {
    638             return 7;
    639         }
    640 
    641         /* compare when high words are equal but low words differ */
    642         if (plus > alsoPlus)
    643             return 8;
    644         if (alsoPlus < plus)
    645             return 9;
    646         if (alsoPlus == plus)
    647             return 10;
    648 
    649         /* high words are equal, low words have apparently different signs */
    650         if (minus < alsoMinus)      // bug!
    651             return 11;
    652         if (alsoMinus > minus)
    653             return 12;
    654         if (alsoMinus == minus)
    655             return 13;
    656 
    657         return res;
    658     }
    659 
    660     /*
    661      * Test cmpl-float and cmpg-float.
    662      */
    663     static int testFloatCompare(float minus, float plus, float plus2,
    664                                 float nan) {
    665         if (minus > plus)
    666             return 1;
    667         if (plus < minus)
    668             return 2;
    669         if (plus == minus)
    670             return 3;
    671         if (plus != plus2)
    672             return 4;
    673 
    674         if (plus <= nan)
    675             return 5;
    676         if (plus >= nan)
    677             return 6;
    678         if (minus <= nan)
    679             return 7;
    680         if (minus >= nan)
    681             return 8;
    682         if (nan >= plus)
    683             return 9;
    684         if (nan <= plus)
    685             return 10;
    686 
    687         if (nan == nan)
    688             return 11;
    689 
    690         return 3333;
    691     }
    692 
    693     static int testDoubleCompare(double minus, double plus, double plus2,
    694                                  double nan) {
    695 
    696         int res = 4444;
    697 
    698         if (minus > plus)
    699             return 1;
    700         if (plus < minus)
    701             return 2;
    702         if (plus == minus)
    703             return 3;
    704         if (plus != plus2)
    705             return 4;
    706 
    707         if (plus <= nan)
    708             return 5;
    709         if (plus >= nan)
    710             return 6;
    711         if (minus <= nan)
    712             return 7;
    713         if (minus >= nan)
    714             return 8;
    715         if (nan >= plus)
    716             return 9;
    717         if (nan <= plus)
    718             return 10;
    719 
    720         if (nan == nan)
    721             return 11;
    722         return res;
    723     }
    724 
    725     static int fibonacci(int n) {
    726         if (n == 0) {
    727             return 0;
    728         } else if (n == 1) {
    729             return 1;
    730         } else {
    731             return fibonacci(n - 1) + fibonacci(n - 2);
    732         }
    733     }
    734 
    735     static int throwAndCatch() {
    736         try {
    737             throwNullPointerException();
    738             return 1;
    739         } catch (NullPointerException npe) {
    740             return 0;
    741         }
    742     }
    743 
    744     static int manyArgs(int a0, long a1, int a2, long a3, int a4, long a5,
    745                         int a6, int a7, double a8, float a9, double a10, short a11, int a12,
    746                         char a13, int a14, int a15, byte a16, boolean a17, int a18, int a19,
    747                         long a20, long a21, int a22, int a23, int a24, int a25, int a26)
    748     {
    749         if (a0 != 0) return 0;
    750         if (a1 !=  1L) return 1;
    751         if (a2 != 2) return 2;
    752         if (a3 != 3L) return 3;
    753         if (a4 != 4) return 4;
    754         if (a5 != 5L) return 5;
    755         if (a6 != 6) return 6;
    756         if (a7 != 7) return 7;
    757         if (a8 != 8.0) return 8;
    758         if (a9 !=  9.0f) return 9;
    759         if (a10 != 10.0) return 10;
    760         if (a11 != (short)11) return 11;
    761         if (a12 != 12) return 12;
    762         if (a13 != (char)13) return 13;
    763         if (a14 != 14) return 14;
    764         if (a15 != 15) return 15;
    765         if (a16 != (byte)-16) return 16;
    766         if (a17 !=  true) return 17;
    767         if (a18 != 18) return 18;
    768         if (a19 != 19) return 19;
    769         if (a20 !=  20L) return 20;
    770         if (a21 != 21L) return 21;
    771         if (a22 != 22) return 22;
    772         if (a23 != 23) return 23;
    773         if (a24 != 24) return 24;
    774         if (a25 != 25) return 25;
    775         if (a26 != 26) return 26;
    776         return -1;
    777     }
    778 
    779     int virtualCall(int a)
    780     {
    781         return a * 2;
    782     }
    783 
    784     void setFoo(int a)
    785     {
    786         foo_ = a;
    787     }
    788 
    789     int getFoo()
    790     {
    791         return foo_;
    792     }
    793 
    794     static int staticCall(int a)
    795     {
    796         Main foo = new Main();
    797         return foo.virtualCall(a);
    798     }
    799 
    800     static int testIGetPut(int a)
    801     {
    802         Main foo = new Main(99);
    803         Main foo123 = new Main();
    804         int z  = foo.getFoo();
    805         z += a;
    806         z += foo123.getFoo();
    807         foo.setFoo(z);
    808         return foo.getFoo();
    809     }
    810 
    811     static int throwClassCast(Object o) {
    812       return ((Integer)o).intValue();
    813     }
    814 
    815     static int testClassCast() {
    816       int res = 0;
    817       try {
    818         res += throwClassCast(Integer.valueOf(123));
    819       } catch(ClassCastException e) {
    820         res += 456;
    821       }
    822       try {
    823         res += throwClassCast(new Short((short)321));
    824       } catch(ClassCastException e) {
    825         res += 765;
    826       }
    827       return res;
    828     }
    829 
    830     static void throwArrayStoreException(Object[] array, Object element) {
    831       array[0] = element;
    832     }
    833 
    834     static int testArrayStoreException() {
    835       int res=0;
    836       Object[] array = new Number[2];
    837       try {
    838         throwArrayStoreException(array, null);
    839         res += 1;
    840       } catch(ArrayStoreException e) {
    841         res += 2;
    842       }
    843       try {
    844         throwArrayStoreException(array, Integer.valueOf(1));
    845         res += 10;
    846       } catch(ArrayStoreException e) {
    847         res += 20;
    848       }
    849       try {
    850         throwArrayStoreException(array, "hello MTV-44");
    851         res += 100;
    852       } catch(ArrayStoreException e) {
    853         res += 200;
    854       }
    855       return res;
    856     }
    857 
    858     static long recursion_count_;
    859     static void throwStackOverflow(long l) {
    860       recursion_count_++;
    861       throwStackOverflow(recursion_count_);
    862     }
    863 
    864     static long testStackOverflow() {
    865       try {
    866         throwStackOverflow(0);
    867         if (recursion_count_ != 0) {
    868           return recursion_count_;
    869         } else {
    870           return -1;
    871         }
    872       } catch(StackOverflowError soe) {
    873         return 0;
    874       }
    875     }
    876 
    877     static int testArrayAllocation() {
    878       int res = 0;
    879       try {
    880         int[] x = new int[-1];
    881         res += 1;
    882       } catch (NegativeArraySizeException e) {
    883         res += 2;
    884       }
    885       try {
    886         int[] x = new int [1];
    887         res += 10;
    888       } catch (Throwable e) {
    889         res += 20;
    890       }
    891       return res;
    892     }
    893 
    894     public static void main(String[] args) {
    895         boolean failure = false;
    896         int res;
    897         long lres;
    898 
    899         lres = divideLongByBillion(123000000000L);
    900         if (lres == 123) {
    901             System.out.println("divideLongByBillion PASSED");
    902         } else {
    903             System.out.println("divideLongByBillion FAILED: " + lres);
    904             failure = true;
    905         }
    906         res = unopTest(38);
    907         if (res == 37) {
    908             System.out.println("unopTest PASSED");
    909         } else {
    910             System.out.println("unopTest FAILED: " + res);
    911             failure = true;
    912         }
    913         res = shiftTest1();
    914         if (res == 0) {
    915             System.out.println("shiftTest1 PASSED");
    916         } else {
    917             System.out.println("shiftTest1 FAILED: " + res);
    918             failure = true;
    919         }
    920         res = shiftTest2();
    921         if (res == 0) {
    922             System.out.println("shiftTest2 PASSED");
    923         } else {
    924             System.out.println("shiftTest2 FAILED: " + res);
    925             failure = true;
    926         }
    927         res = unsignedShiftTest();
    928         if (res == 0) {
    929             System.out.println("unsignedShiftTest PASSED");
    930         } else {
    931             System.out.println("unsignedShiftTest FAILED: " + res);
    932             failure = true;
    933         }
    934         res = convTest();
    935         if (res == 0) {
    936             System.out.println("convTest PASSED");
    937         } else {
    938             System.out.println("convTest FAILED: " + res);
    939             failure = true;
    940         }
    941         res = charSubTest();
    942         if (res == 0) {
    943             System.out.println("charSubTest PASSED");
    944         } else {
    945             System.out.println("charSubTest FAILED: " + res);
    946             failure = true;
    947         }
    948         res = intOperTest(70000, -3);
    949         if (res == 0) {
    950             System.out.println("intOperTest PASSED");
    951         } else {
    952             System.out.println("intOperTest FAILED: " + res);
    953             failure = true;
    954         }
    955         res = lit16Test(77777);
    956         if (res == 0) {
    957             System.out.println("lit16Test PASSED");
    958         } else {
    959             System.out.println("lit16Test FAILED: " + res);
    960             failure = true;
    961         }
    962         res = lit8Test(-55555);
    963         if (res == 0) {
    964             System.out.println("lit8Test PASSED");
    965         } else {
    966             System.out.println("lit8Test FAILED: " + res);
    967             failure = true;
    968         }
    969         res = intShiftTest(0xff00aa01, 8);
    970         if (res == 0) {
    971             System.out.println("intShiftTest PASSED");
    972         } else {
    973             System.out.println("intShiftTest FAILED: " + res);
    974             failure = true;
    975         }
    976         res = longOperTest(70000000000L, -3L);
    977         if (res == 0) {
    978             System.out.println("longOperTest PASSED");
    979         } else {
    980             System.out.println("longOperTest FAILED: " + res);
    981             failure = true;
    982         }
    983         lres = longShiftTest(0xd5aa96deff00aa01L, 16);
    984         if (lres == 0x96deff00aa010000L) {
    985             System.out.println("longShiftTest PASSED");
    986         } else {
    987             System.out.println("longShiftTest FAILED: " + lres);
    988             failure = true;
    989         }
    990 
    991         res = switchTest(1);
    992         if (res == 1234) {
    993             System.out.println("switchTest PASSED");
    994         } else {
    995             System.out.println("switchTest FAILED: " + res);
    996             failure = true;
    997         }
    998 
    999         res = testIntCompare(-5, 4, 4, 0);
   1000         if (res == 1111) {
   1001             System.out.println("testIntCompare PASSED");
   1002         } else {
   1003             System.out.println("testIntCompare FAILED: " + res);
   1004             failure = true;
   1005         }
   1006 
   1007         res = testLongCompare(-5L, -4294967287L, 4L, 8L);
   1008         if (res == 2222) {
   1009             System.out.println("testLongCompare PASSED");
   1010         } else {
   1011             System.out.println("testLongCompare FAILED: " + res);
   1012             failure = true;
   1013         }
   1014 
   1015         res = testFloatCompare(-5.0f, 4.0f, 4.0f, (1.0f/0.0f) / (1.0f/0.0f));
   1016         if (res == 3333) {
   1017             System.out.println("testFloatCompare PASSED");
   1018         } else {
   1019             System.out.println("testFloatCompare FAILED: " + res);
   1020             failure = true;
   1021         }
   1022 
   1023         res = testDoubleCompare(-5.0, 4.0, 4.0, (1.0/0.0) / (1.0/0.0));
   1024         if (res == 4444) {
   1025             System.out.println("testDoubleCompare PASSED");
   1026         } else {
   1027             System.out.println("testDoubleCompare FAILED: " + res);
   1028             failure = true;
   1029         }
   1030 
   1031         res = fibonacci(10);
   1032         if (res == 55) {
   1033             System.out.println("fibonacci PASSED");
   1034         } else {
   1035             System.out.println("fibonacci FAILED: " + res);
   1036             failure = true;
   1037         }
   1038 
   1039         res = throwAndCatch();
   1040         if (res == 0) {
   1041             System.out.println("throwAndCatch PASSED");
   1042         } else {
   1043             System.out.println("throwAndCatch FAILED: " + res);
   1044             failure = true;
   1045         }
   1046 
   1047         res = testClassCast();
   1048         if (res == 888) {
   1049             System.out.println("testClassCast PASSED");
   1050         } else {
   1051             System.out.println("testClassCast FAILED: " + res);
   1052             failure = true;
   1053         }
   1054 
   1055         res = testArrayStoreException();
   1056         if (res == 211) {
   1057           System.out.println("testArrayStore PASSED");
   1058         } else {
   1059           System.out.println("testArrayStore FAILED: " + res);
   1060           failure = true;
   1061         }
   1062 
   1063         lres= testStackOverflow();
   1064         if (lres == 0) {
   1065             System.out.println("testStackOverflow PASSED");
   1066         } else {
   1067             System.out.println("testStackOverflow FAILED: " + lres);
   1068             failure = true;
   1069         }
   1070 
   1071         res = testArrayAllocation();
   1072         if (res == 12) {
   1073           System.out.println("testArrayAllocation PASSED");
   1074         } else {
   1075           System.out.println("testArrayAllocation FAILED: " + res);
   1076           failure = true;
   1077         }
   1078 
   1079         res = manyArgs(0, 1L, 2, 3L, 4, 5L, 6, 7, 8.0, 9.0f, 10.0,
   1080                        (short)11, 12, (char)13, 14, 15, (byte)-16, true, 18,
   1081                        19, 20L, 21L, 22, 23, 24, 25, 26);
   1082         if (res == -1) {
   1083             System.out.println("manyArgs PASSED");
   1084         } else {
   1085             System.out.println("manyArgs FAILED: " + res);
   1086             failure = true;
   1087         }
   1088 
   1089         res = staticCall(3);
   1090         if (res == 6) {
   1091             System.out.println("virtualCall PASSED");
   1092         } else {
   1093             System.out.println("virtualCall FAILED: " + res);
   1094             failure = true;
   1095         }
   1096 
   1097         res = testIGetPut(111);
   1098         if (res == 333) {
   1099             System.out.println("testGetPut PASSED");
   1100         } else {
   1101             System.out.println("testGetPut FAILED: " + res);
   1102             failure = true;
   1103         }
   1104 
   1105         res = staticFieldTest(404);
   1106         if (res == 1404) {
   1107             System.out.println("staticFieldTest PASSED");
   1108         } else {
   1109             System.out.println("staticFieldTest FAILED: " + res);
   1110             failure = true;
   1111         }
   1112 
   1113         res = catchBlock(1000);
   1114         if (res == 1579) {
   1115             System.out.println("catchBlock(1000) PASSED");
   1116         } else {
   1117             System.out.println("catchBlock(1000) FAILED: " + res);
   1118             failure = true;
   1119         }
   1120         res = catchBlock(7000);
   1121         if (res == 7777) {
   1122             System.out.println("catchBlock(7000) PASSED");
   1123         } else {
   1124             System.out.println("catchBlock(7000) FAILED: " + res);
   1125             failure = true;
   1126         }
   1127         res = catchBlockNoThrow(1000);
   1128         if (res == 1123) {
   1129             System.out.println("catchBlockNoThrow PASSED");
   1130         } else {
   1131             System.out.println("catchBlockNoThrow FAILED: " + res);
   1132             failure = true;
   1133         }
   1134 
   1135         res = superTest(4141);
   1136         if (res == 4175) {
   1137             System.out.println("superTest PASSED");
   1138         } else {
   1139             System.out.println("superTest FAILED: " + res);
   1140             failure = true;
   1141         }
   1142 
   1143         res = constClassTest(1111);
   1144         if (res == 2222) {
   1145             System.out.println("constClassTest PASSED");
   1146         } else {
   1147             System.out.println("constClassTest FAILED: " + res);
   1148             failure = true;
   1149         }
   1150 
   1151         res = constStringTest(10);
   1152         if (res == 22) {
   1153             System.out.println("constStringTest PASSED");
   1154         } else {
   1155             System.out.println("constStringTest FAILED: " + res);
   1156             failure = true;
   1157         }
   1158 
   1159         res = instanceTest(10);
   1160         if (res == 1436) {
   1161             System.out.println("instanceTest PASSED");
   1162         } else {
   1163             System.out.println("instanceTest FAILED: " + res);
   1164             failure = true;
   1165         }
   1166 
   1167         System.exit(failure ? 1 : 0);
   1168     }
   1169 }
   1170 
   1171 class IntMathBase {
   1172     IntMathBase() {
   1173     }
   1174 
   1175     int tryThing() {
   1176         return 7;
   1177     }
   1178 }
   1179