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