Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
The following program causes JDK1.1.8 and JDK1.2 to crash. import java.applet.*; import java.lang.Class; import java.lang.reflect.*; public class Test implements Runnable { static int depth = 0; static Method m; public static void test(Method m) throws Throwable { ++depth; System.err.println("Test at depth " + depth); Object[] args = {m}; try { m.invoke(null, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } public void run() { try { Class c = Test.class; Class[] sig = {Method.class}; m = c.getMethod("test", sig); test(m); } catch (InvocationTargetException e) { System.err.println("InvocationTargetException occurred."); e.printStackTrace(); e.getTargetException().printStackTrace(); } catch (Throwable e) { System.err.println("Exception occurred."); e.printStackTrace(); } System.err.println("depth " + depth); } public static void main(String[] args) { new Thread(new Test()).start(); } } It purposely runs in a separate thread so that it gets a new native C stack. For Solaris, this is smaller than the main thread's stack, so the test crashes quickly without eating up all your swap space. dean.long@Eng 1999-03-06 Name: skR10017 Date: 04/21/2000 The same test crashes linux VM with Segmentation Fault error. ====================================================================== Name: krC82822 Date: 07/15/2001 [1.3.1 and 1.4 beta build 65 on Linux] 1.) Write some kind of endless indirect recursion (a calls b, b calls a). In my case it was a FilterInputStream where read(b[],ofs,len) calls read(b[]). 2.) Run the program. As soon as control flow gets to the point, the JVM crashes with a segmentation violation signal. The correct behaviour would be to throw a StackOverflowException. I was really confused about the JVM crash and couldn't find the problem. IBM's Linux JVM handles the problem correctly and throws a nice stack dump. (Review ID: 128094) ======================================================================
|