public class extest {
+ final static int COLUMN = 55;
+
final static int INDEX1 = 0xcafebabe;
final static int INDEX2 = 0xbabecafe;
final static int INDEX3 = 0xdeadbeef;
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();
}
}
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):");
}
}
- 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];
}
}
- 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];
pstacktrace(e);
}
-
try {
p("ClassCastException:");
Object o = new Object();
}
try {
- p("ClassCastException:");
- Object o = new Object();
- Integer i = null;
- i = (Integer) o;
- failed();
- } catch (ClassCastException e) {
- ok();
- pstacktrace(e);
- }
-
-
- try {
- p("NegativeArraySizeException:");
+ p("NegativeArraySizeException (newarray):");
int[] ia = new int[-1];
failed();
} catch (NegativeArraySizeException e) {
}
try {
- p("NegativeArraySizeException:");
- int[] ia = new int[-1];
+ p("NegativeArraySizeException (multianewarray):");
+ int[][] ia = new int[1][-1];
failed();
} catch (NegativeArraySizeException 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("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();
}
try {
- p("OutOfMemoryError:");
- /* 100 MB should be enough */
- byte[] ba = new byte[100 * 1024 * 1024];
+ p("OutOfMemoryError (multianewarray):");
+ byte[][] ba = new byte[maxmem][maxmem];
failed();
} catch (OutOfMemoryError e) {
ok();
pln();
- pln("---------- exceptions in leaf functions ---------");
+ pheader("exceptions in leaf functions");
try {
p("ArithmeticException:");
pstacktrace(e);
}
- pln();
-
-
- pln("---------- some asmpart exceptions --------------");
-
try {
- p("NullPointerException in <clinit> (PUTSTATIC):");
- extest_clinit_1.i = 1;
+ 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);
- }
- }
-
- try {
- p("NullPointerException in <clinit> (GETSTATIC):");
- int i = extest_clinit_2.i;
- 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);
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 {
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) {
pln();
- pln("---------- no OK beyond this point --------------");
+ pheader("exception thrown to command-line");
pln("NullPointerException (without catch):");
String s = null;
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();
}
}
}
-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();
}