How do you crash a JVM?

前端 未结 27 1306
故里飘歌
故里飘歌 2020-11-28 00:22

I was reading a book on programming skills wherein the author asks the interviewee, \"How do you crash a JVM?\" I thought that you could do so by writing an infinite for-loo

27条回答
  •  [愿得一人]
    2020-11-28 01:21

    Last time I tried this would do it:

    public class Recur {
        public static void main(String[] argv) {
            try {
                recur();
            }
            catch (Error e) {
                System.out.println(e.toString());
            }
            System.out.println("Ended normally");
        }
        static void recur() {
            Object[] o = null;
            try {
                while(true) {
                    Object[] newO = new Object[1];
                    newO[0] = o;
                    o = newO;
                }
            }
            finally {
                recur();
            }
        }
    }
    

    First part of generated log file:

    #
    # An unexpected error has been detected by Java Runtime Environment:
    #
    #  EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x000000006dad5c3d, pid=6752, tid=1996
    #
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (11.2-b01 mixed mode windows-amd64)
    # Problematic frame:
    # V  [jvm.dll+0x2e5c3d]
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    #
    
    ---------------  T H R E A D  ---------------
    
    Current thread (0x00000000014c6000):  VMThread [stack: 0x0000000049810000,0x0000000049910000] [id=1996]
    
    siginfo: ExceptionCode=0xc00000fd, ExceptionInformation=0x0000000000000001 0x0000000049813fe8 
    
    Registers:
    EAX=0x000000006dc83090, EBX=0x000000003680f400, ECX=0x0000000005d40ce8, EDX=0x000000003680f400
    ESP=0x0000000049813ff0, EBP=0x00000000013f2df0, ESI=0x00000000013f0e40, EDI=0x000000003680f400
    EIP=0x000000006dad5c3d, EFLAGS=0x0000000000010206
    

提交回复
热议问题