* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / tests / regression / jctest.java
index cb89494c09f1151511478e841af5e6bb77679864..fecc9f4ec291f2781e9057cc215e5c68c267a204 100644 (file)
@@ -1,8 +1,8 @@
 /* tests/jctest.java - checks most of the JVM instructions
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    TU Wien
 
    This file is part of CACAO.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Reinhard Grafl
-
-   Changes: Christian Thalinger
-
-   $Id: jctest.java 3061 2005-07-19 08:52:11Z twisti $
+            Christian Thalinger
 
 */
 
@@ -123,6 +120,7 @@ public class jctest implements jcinterface {
         testlong(0x3333,143444);
         testlong(4444441,12342);
         testlong(0x8000000000000000L,-1);
+        testlong(0x0000000080000000L,0x0000000080000000L);
 
         p("------------------- test floats");
         testfloat((float) 1,(float) 2.042);
@@ -245,8 +243,10 @@ public class jctest implements jcinterface {
     // ****************** test type casts and array stores *********************
 
     public static void testcasts() {
+        Object     on  = null;
         Object     o   = new Object();
         Object     oi  = new Integer(0);
+        Object[]   ona = null;
         Object[]   oa  = new Object [1];
         Object[]   oia = new Integer[1];
         Integer    i   = new Integer(0);
@@ -257,10 +257,21 @@ public class jctest implements jcinterface {
 
         p ("------------------- test casts");
 
+        p("null is instanceof Object:  ", on instanceof Object);
         p("Integer is instanceof Object:  ", oi instanceof Object);
         p("Integer is instanceof Integer: ", oi instanceof Integer);
         p("Object is instanceof Integer:  ", o instanceof Integer);
 
+        p("null is instanceof Object[]:  ", on instanceof Object[]);
+        p("Integer[] is instanceof Object[]:  ", oia instanceof Object[]);
+        p("Integer[] is instanceof Integer[]: ", oia instanceof Integer[]);
+        p("Object[] is instanceof Integer[]:  ", oa instanceof Integer[]);
+
+        p("Integer is instanceof Object[]:  ", oi instanceof Object[]);
+        p("Integer[] is instanceof Object:  ", oia instanceof Object);
+        p("Integer is instanceof Integer[]: ", oi instanceof Integer[]);
+        p("Object is instanceof Integer[]:  ", o instanceof Integer[]);
+
         try {
             p ("type cast check: Integer = Object(Integer)");
             i = (Integer) oi;
@@ -756,7 +767,7 @@ public class jctest implements jcinterface {
             }
             p("successfully created");
         } catch (Exception e) {
-            p("error: exception thrown");
+            p("error: exception thrown: " + e);
         }
 
         iaaa = new int[2][3][4];
@@ -1174,6 +1185,7 @@ public class jctest implements jcinterface {
     }
 
     static public void testdivremconst(int a) {
+        p("IDIVPOW2 (" + a + " / 0x00000001):  ", a / 0x00000001);
         p("IDIVPOW2 (" + a + " / 0x00000002):  ", a / 0x00000002);
         p("IDIVPOW2 (" + a + " / 0x00000004):  ", a / 0x00000004);
         p("IDIVPOW2 (" + a + " / 0x00000008):  ", a / 0x00000008);
@@ -1206,6 +1218,7 @@ public class jctest implements jcinterface {
         p("IDIVPOW2 (" + a + " / 0x40000000):  ", a / 0x40000000);
         p("IDIVPOW2 (" + a + " / 0x80000000):  ", a / 0x80000000);
 
+        p("IREMPOW2 (" + a + " % 0x00000001):  ", a % 0x00000001);
         p("IREMPOW2 (" + a + " % 0x00000002):  ", a % 0x00000002);
         p("IREMPOW2 (" + a + " % 0x00000004):  ", a % 0x00000004);
         p("IREMPOW2 (" + a + " % 0x00000008):  ", a % 0x00000008);
@@ -1240,6 +1253,7 @@ public class jctest implements jcinterface {
     }
 
     static public void testdivremconst(long a) {
+        p("LDIVPOW2 (" + a + " / 0x00000001):  ", a / 0x00000001);
         p("LDIVPOW2 (" + a + " / 0x00000002):  ", a / 0x00000002);
         p("LDIVPOW2 (" + a + " / 0x00000004):  ", a / 0x00000004);
         p("LDIVPOW2 (" + a + " / 0x00000008):  ", a / 0x00000008);
@@ -1272,6 +1286,7 @@ public class jctest implements jcinterface {
         p("LDIVPOW2 (" + a + " / 0x40000000):  ", a / 0x40000000);
         p("LDIVPOW2 (" + a + " / 0x80000000):  ", a / 0x80000000);
 
+        p("LREMPOW2 (" + a + " % 0x00000001):  ", a % 0x00000001L);
         p("LREMPOW2 (" + a + " % 0x00000002):  ", a % 0x00000002L);
         p("LREMPOW2 (" + a + " % 0x00000004):  ", a % 0x00000004L);
         p("LREMPOW2 (" + a + " % 0x00000008):  ", a % 0x00000008L);
@@ -1307,8 +1322,8 @@ public class jctest implements jcinterface {
 
 
     static public void testint(int a, int b) {
-        p ("TESTINT CALLED WITH ", a);
-        p ("                AND ", b);
+        p("TESTINT called with ", a);
+        p("                AND ", b);
                
         p("IADD:  ", a+b);
         p("ISUB:  ", a-b);
@@ -1332,19 +1347,19 @@ public class jctest implements jcinterface {
         p("INT2CHAR: ", (char) a);     
         p("INT2SHORT: ", (short) a);   
 
-        if (!(a==0)) p("not IFEQ");
-        if (!(a!=0)) p("not IFNE");
-        if (!(a<0))  p("not IFLT");
-        if (!(a<=0)) p("not IFLE");
-        if (!(a>0))  p("not IFGT");
-        if (!(a>=0)) p("not IFGE");
-
-        if (!(a==b)) p("not IF_ICMPEQ");
-        if (!(a!=b)) p("not IF_ICMPNE");
-        if (!(a<b))  p("not IF_ICMPLT");
-        if (!(a<=b)) p("not IF_ICMPLE");
-        if (!(a>b))  p("not IF_ICMPGT");
-        if (!(a>=b)) p("not IF_ICMPGE");
+        if (!(a == 0)) p("not IFEQ");
+        if (!(a != 0)) p("not IFNE");
+        if (!(a < 0))  p("not IFLT");
+        if (!(a <= 0)) p("not IFLE");
+        if (!(a > 0))  p("not IFGT");
+        if (!(a >= 0)) p("not IFGE");
+
+        if (!(a == b)) p("not IF_ICMPEQ");
+        if (!(a != b)) p("not IF_ICMPNE");
+        if (!(a < b))  p("not IF_ICMPLT");
+        if (!(a <= b)) p("not IF_ICMPLE");
+        if (!(a > b))  p("not IF_ICMPGT");
+        if (!(a >= b)) p("not IF_ICMPGE");
                
         p("COND_ICMPEQ " + a + " == 0: " + ((a == 0) ? 0 : 1));
         p("COND_ICMPNE " + a + " != 0: " + ((a != 0) ? 0 : 1));
@@ -1377,8 +1392,8 @@ public class jctest implements jcinterface {
     }
 
     static public void testlong(long a, long b) {
-        p ("TESTLONG called with ", a);
-        p ("                 AND ", b);
+        p("TESTLONG called with ", a);
+        p("                 AND ", b);
                
         p("LADD:  ", a + b);
         p("LSUB:  ", a - b);
@@ -1406,56 +1421,63 @@ public class jctest implements jcinterface {
         p("LCMP a >  b : ", a >  b);
         p("LCMP a >= b : ", a >= b);
 
-        if ((a==b)) p("not IF_LCMPEQ");
-        if ((a!=b)) p("not IF_LCMPNE");
-        if ((a<b))  p("not IF_LCMPLT");
-        if ((a<=b)) p("not IF_LCMPLE");
-        if ((a>b))  p("not IF_LCMPGT");
-        if ((a>=b)) p("not IF_LCMPGE");
+        if (!(a == 0)) p("not IF_LEQ");
+        if (!(a != 0)) p("not IF_LNE");
+        if (!(a < 0))  p("not IF_LLT");
+        if (!(a <= 0)) p("not IF_LLE");
+        if (!(a > 0))  p("not IF_LGT");
+        if (!(a >= 0)) p("not IF_LGE");
+
+        if (!(a == b)) p("not IF_LCMPEQ");
+        if (!(a != b)) p("not IF_LCMPNE");
+        if (!(a < b))  p("not IF_LCMPLT");
+        if (!(a <= b)) p("not IF_LCMPLE");
+        if (!(a > b))  p("not IF_LCMPGT");
+        if (!(a >= b)) p("not IF_LCMPGE");
     }
 
     static public void testfloat(float a, float b) {
-        p ("TESTFLOAT called with ", a);
-        p ("                  AND ", b);
+        p("TESTFLOAT called with ", a);
+        p("                  AND ", b);
                
-        p("FADD:  ", a+b);
-        p("FSUB:  ", a-b);
-        p("FMUL:  ", a*b);
-        p("FDIV:  ", a/b); 
-        p("FREM:  ", a%b);
+        p("FADD:  ", a + b);
+        p("FSUB:  ", a - b);
+        p("FMUL:  ", a * b);
+        p("FDIV:  ", a / b); 
+        p("FREM:  ", a % b);
                
         p("F2I:   ", (int) a);
         p("F2L:   ", (long) a);
         p("F2D:   ", (double) a);
 
-        if ((a==b)) p("FCMP a=b");
-        if ((a!=b)) p("FCMP a!=b");
-        if ((a<b))  p("FCMP a<b");
-        if ((a<=b)) p("FCMP a<=b");
-        if ((a>b))  p("FCMP a>b");
-        if ((a>=b)) p("FCMP a>=b");
+        if ((a == b)) p("FCMP a == b");
+        if ((a != b)) p("FCMP a != b");
+        if ((a < b))  p("FCMP a < b");
+        if ((a <= b)) p("FCMP a <= b");
+        if ((a > b))  p("FCMP a > b");
+        if ((a >= b)) p("FCMP a >= b");
     }
 
     static public void testdouble(double a, double b) {
-        p ("TESTDOUBLE called with ", a);
-        p ("                   AND ", b);
+        p("TESTDOUBLE called with ", a);
+        p("                   AND ", b);
                
-        p("DADD:  ", a+b);
-        p("DSUB:  ", a-b);
-        p("DMUL:  ", a*b);
-        p("DDIV:  ", a/b); 
-        p("DREM:  ", a%b);
+        p("DADD:  ", a + b);
+        p("DSUB:  ", a - b);
+        p("DMUL:  ", a * b);
+        p("DDIV:  ", a / b); 
+        p("DREM:  ", a % b);
                
         p("D2I:   ", (int) a);
         p("D2L:   ", (long) a);
         p("D2F:   ", (float) a);
 
-        if ((a==b)) p("DCMP a=b");
-        if ((a!=b)) p("DCMP a!=b");
-        if ((a<b))  p("DCMP a<b");
-        if ((a<=b)) p("DCMP a<=b");
-        if ((a>b))  p("DCMP a>b");
-        if ((a>=b)) p("DCMP a>=b");
+        if ((a == b)) p("DCMP a == b");
+        if ((a != b)) p("DCMP a != b");
+        if ((a < b))  p("DCMP a < b");
+        if ((a <= b)) p("DCMP a <= b");
+        if ((a > b))  p("DCMP a > b");
+        if ((a >= b)) p("DCMP a >= b");
     }
 
 
@@ -1469,29 +1491,76 @@ public class jctest implements jcinterface {
     }
 
     public static void p(String a) { System.out.print(a); pnl(); }
-    public static void p(boolean a) {System.out.print(a); 
-    pnl();  }
-    public static void p(int a) { System.out.print ("int: ");
-    System.out.print(a); 
-    pnl();  }
-    public static void p(long a) { System.out.print ("long: ");
-    System.out.print(a); 
-    pnl(); }
-    public static void p(short a) { System.out.print ("short: ");
-    System.out.print(a); 
-    pnl(); }
-    public static void p(byte a) { System.out.print ("byte: ");
-    System.out.print(a); 
-    pnl(); }
-    public static void p(char a) { System.out.print ("char: ");
-    System.out.print((int) a); 
-    pnl(); }
-    public static void p(float a) { System.out.print ("float: ");
-    System.out.print ( java.lang.Float.floatToIntBits(a) ); 
-    pnl(); }
-    public static void p(double a) { System.out.print ("double: ");
-    System.out.print( java.lang.Double.doubleToLongBits(a) ); 
-    pnl(); }
+
+    public static void p(boolean a) {
+        System.out.print(a);
+        pnl();
+    }
+
+    public static void p(byte a) {
+        System.out.print("byte: ");
+        System.out.print(a);
+        System.out.print(" (0x");
+        System.out.print(Integer.toHexString(a));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(char a) {
+        System.out.print("char: ");
+        System.out.print((int) a);
+        System.out.print(" (0x");
+        System.out.print(Integer.toHexString((int) a));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(short a) {
+        System.out.print("short: ");
+        System.out.print(a);
+        System.out.print(" (0x");
+        System.out.print(Integer.toHexString(a));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(int a) {
+        System.out.print ("int: ");
+        System.out.print(a);
+        System.out.print(" (0x");
+        System.out.print(Integer.toHexString(a));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(long a) {
+        System.out.print ("long: ");
+        System.out.print(a);
+        System.out.print(" (0x");
+        System.out.print(Long.toHexString(a));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(float a) {
+        int i = Float.floatToIntBits(a);
+        System.out.print("float: ");
+        System.out.print(i);
+        System.out.print(" (0x");
+        System.out.print(Integer.toHexString(i));
+        System.out.print(")");
+        pnl();
+    }
+
+    public static void p(double a) {
+        long l = Double.doubleToLongBits(a);
+        System.out.print("double: ");
+        System.out.print(l);
+        System.out.print(" (0x");
+        System.out.print(Long.toHexString(l));
+        System.out.print(")");
+        pnl();
+    }
 
     public static void p(String s,boolean i) { 
         System.out.print(s); p(i);