* .hgignore: Removed tests/regression/junit/*.class, added
[cacao.git] / tests / regression / extest.java
index 7efefb486b427d15d5e9460eabfe3d8b186b5ae4..4a91243b98dbeed4f7a3c65737cd07cb1a08c894 100644 (file)
@@ -1,4 +1,6 @@
 public class extest {
+    final static int COLUMN = 55;
+
     final static int INDEX1 = 0xcafebabe;
     final static int INDEX2 = 0xbabecafe;
     final static int INDEX3 = 0xdeadbeef;
@@ -8,25 +10,27 @@ public class extest {
     public static void main(String[] argv) {
        printStackTrace = true;
 
+        Runtime r = Runtime.getRuntime();
+        int maxmem = (int) r.maxMemory();
+
 //     if (argv.length > 0) 
 //              if (argv[0].equals("stacktrace"))
 //                  printStackTrace = true;
 
-        boolean catched = false;
+        boolean caught = false;
 
-       pln("---------- normal exceptions --------------------");
+       pheader("normal exceptions");
 
        try {
             p("throw new Exception():");
            throw new Exception();
        } catch (Exception e) {
-            catched = true;
+            caught = true;
            ok();
            pstacktrace(e);
-
        } finally {
             /* check if catch block was executed */
-            if (!catched) {
+            if (!caught) {
                 failed();
             }
         }
@@ -53,8 +57,7 @@ public class extest {
        pln();
 
 
-       pln("---------- test soft inline exceptions ----------");
-       pln("/* thrown twice to check the inline jump code */");
+       pheader("exceptions thrown in JIT code");
 
         try {
             p("ArithmeticException (only w/ -softnull):");
@@ -72,23 +75,6 @@ public class extest {
             }
        }
 
-        try {
-            p("ArithmeticException (only w/ -softnull):");
-            long i = 1, j = 0, k = i / j;
-            failed();
-        } catch (ArithmeticException e) {
-           String msg = e.getMessage();
-
-           if (msg == null || !msg.equals("/ by zero")) {
-               pln("FAILED: wrong message: " + msg + ", should be: / by zero");
-
-           } else {
-                ok();
-                pstacktrace(e);
-            }
-       }
-
-
         try {
             p("ArrayIndexOutOfBoundsException:");
             int[] ia = new int[1];
@@ -106,36 +92,6 @@ public class extest {
            }
        }
 
-        try {
-            p("ArrayIndexOutOfBoundsException:");
-            int[] ia = new int[1];
-            ia[INDEX2] = 1;
-            failed();
-        } catch (ArrayIndexOutOfBoundsException e) {
-           String msg = e.getMessage();
-
-           if (msg == null || !msg.equals(String.valueOf(INDEX2))) {
-               pln("FAILED: wrong index: " + msg + ", should be: " + INDEX2);
-               pstacktrace(e);
-           } else {
-               ok();
-               pstacktrace(e);
-
-           }
-       }
-
-
-        try {
-            p("ArrayStoreException:");
-           Integer[] ia = new Integer[1];
-            Object[] oa = (Object[]) ia;
-           oa[0] = new Object();
-            failed();
-        } catch (ArrayStoreException e) {
-           ok();
-           pstacktrace(e);
-       }
-
         try {
             p("ArrayStoreException:");
            Integer[] ia = new Integer[1];
@@ -147,7 +103,6 @@ public class extest {
            pstacktrace(e);
        }
 
-
         try {
             p("ClassCastException:");
             Object o = new Object();
@@ -158,27 +113,6 @@ public class extest {
            pstacktrace(e);
        }
 
-        try {
-            p("ClassCastException:");
-            Object o = new Object();
-            Integer i = null;
-            i = (Integer) o;
-            failed();
-        } catch (ClassCastException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-
-        try {
-            p("NegativeArraySizeException (newarray):");
-            int[] ia = new int[-1];
-            failed();
-        } catch (NegativeArraySizeException e) {
-           ok();
-           pstacktrace(e);
-       }
-
         try {
             p("NegativeArraySizeException (newarray):");
             int[] ia = new int[-1];
@@ -197,51 +131,19 @@ public class extest {
            pstacktrace(e);
        }
 
-        
-        try {
-            p("NullPointerException (only w/ -softnull):");
-            int[] ia = null;
-            int i = ia.length;
-            failed();
-        } catch (NullPointerException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-        try {
-            p("NullPointerException (only w/ -softnull):");
-            int[] ia = null;
-            int i = ia.length;
-            failed();
-        } catch (NullPointerException e) {
-           ok();
-           pstacktrace(e);
-       }
-
         try {
             p("OutOfMemoryError:");
-           /* 100 MB should be enough */
-           byte[] ba = new byte[100 * 1024 * 1024];
+           /* use twice the heap size */
+           byte[] ba = new byte[maxmem * 2];
             failed();
         } catch (OutOfMemoryError e) {
            ok();
            pstacktrace(e);
        }
 
-        try {
-            p("OutOfMemoryError:");
-           /* 100 MB should be enough */
-           byte[] ba = new byte[100 * 1024 * 1024];
-            failed();
-        } catch (OutOfMemoryError e) {
-           ok();
-           pstacktrace(e);
-       }
-        
         try {
             p("OutOfMemoryError (multianewarray):");
-           /* 100 MB should be enough */
-           byte[][] ba = new byte[10 * 1024 * 1024][10 * 1024 * 1024];
+           byte[][] ba = new byte[maxmem][maxmem];
             failed();
         } catch (OutOfMemoryError e) {
            ok();
@@ -251,7 +153,7 @@ public class extest {
        pln();
 
 
-       pln("---------- exceptions in leaf functions ---------");
+       pheader("exceptions in leaf functions");
 
         try {
             p("ArithmeticException:");
@@ -297,48 +199,26 @@ public class extest {
             pstacktrace(e);
         }
 
-       pln();
-
-
-       pln("---------- some asmpart exceptions --------------");
-
-        try {
-            p("NullPointerException in <clinit> (PUTSTATIC):");
-            extest_clinit_1.i = 1;
-            failed();
-        } catch (ExceptionInInitializerError e) {
-            if (e.getCause().getClass() != NullPointerException.class) {
-                failed();
-            } else {
-                ok();
-               pstacktrace(e);
-            }
-        }
-
         try {
-            p("NullPointerException in <clinit> (GETSTATIC):");
-            int i = extest_clinit_2.i;
+            p("Exception in <clinit> triggered from a leaf method:");
+            extest_clinit_patcher.i = 1;
             failed();
         } catch (ExceptionInInitializerError e) {
-            if (e.getCause().getClass() != NullPointerException.class) {
-                failed();
-            } else {
-                ok();
-               pstacktrace(e);
-            }
+            ok();
+            pstacktrace(e);
         }
 
        pln();
 
 
-       pln("---------- exception related things -------------");
+       pheader("exception related things");
 
         try {
             p("load/link an exception class in asmpart:");
             throw new Exception();
         } catch (UnknownError e) {
             /* this exception class MUST NOT be loaded before!!!
-               otherwise this test in useless */
+               otherwise this test is useless */
         } catch (Exception e) {
            ok();
            pstacktrace(e);
@@ -347,19 +227,15 @@ public class extest {
         pln();
 
 
-       pln("---------- native stub exceptions ---------------");
+       pheader("native stub exceptions");
 
         try {
             p("NullPointerException in <clinit>:");
-            extest_clinit_3.sub();
+            extest_clinit.sub();
             failed();
         } catch (ExceptionInInitializerError e) {
             ok();
             pstacktrace(e);
-        } catch (UnsatisfiedLinkError e) {
-            /* catch this one for staticvm and say it's ok */
-            ok();
-            pstacktrace(e);
         }
 
         try {
@@ -383,11 +259,12 @@ public class extest {
         pln();
 
 
-       pln("---------- special exceptions -------------------");
+       pheader("special exceptions");
 
        try {
             p("OutOfMemoryError (array clone):");
-            byte[] ba1 = new byte[40 * 1024 * 1024];
+            /* use half of the heap size */
+            byte[] ba1 = new byte[maxmem / 2];
             byte[] ba2 = (byte[]) ba1.clone();
             failed();
        } catch (OutOfMemoryError e) {
@@ -398,7 +275,7 @@ public class extest {
         pln();
 
 
-       pln("---------- no OK beyond this point --------------");
+       pheader("exception thrown to command-line");
 
         pln("NullPointerException (without catch):");
         String s = null;
@@ -442,11 +319,20 @@ public class extest {
 
     static void p(String s) {
        System.out.print(s);
-        for (int i = s.length(); i < 46; i++) {
+        for (int i = s.length(); i < COLUMN; i++) {
             System.out.print(" ");
         }
     }
 
+    static void pheader(String s) {
+       System.out.print(s);
+        for (int i = s.length(); i < COLUMN + 3; i++) {
+            System.out.print("-");
+        }
+        System.out.println();
+        System.out.println();
+    }
+
     static void pln() {
        System.out.println();
     }
@@ -471,29 +357,20 @@ public class extest {
     }
 }
 
-public class extest_clinit_1 {
+class extest_clinit {
     static {
         String s = null;
         s.length();
     }
 
-    public static int i;
+    public static native void sub();
 }
 
-public class extest_clinit_2 {
-    static {
-        String s = null;
-        s.length();
-    }
-
-    public static int i;
-}
+class extest_clinit_patcher {
+    static int i;
 
-public class extest_clinit_3 {
     static {
-        String s = null;
-        s.length();
+        int[] ia = null;
+        int a = ia.length;
     }
-
-    public static native void sub();
 }