in Education by
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-loop that would eventually use up all the memory. Anybody has any idea? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I wouldn't call throwing an OutOfMemoryError or StackOverflowError a crash. These are just normal exceptions. To really crash a VM there are 3 ways: Use JNI and crash in the native code. If no security manager is installed you can use reflection to crash the VM. This is VM specific, but normally a VM stores a bunch of pointers to native resources in private fields (e.g. a pointer to the native thread object is stored in a long field in java.lang.Thread). Just change them via reflection and the VM will crash sooner or later. All VMs have bugs, so you just have to trigger one. For the last method I have a short example, which will crash a Sun Hotspot VM quiet nicely: public class Crash { public static void main(String[] args) { Object[] o = null; while (true) { o = new Object[] {o}; } } } This leads to a stack overflow in the GC so you will get no StackOverflowError but a real crash including a hs_err* file.

Related questions

0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    What does not prevent JVM from terminating? (a) Process (b) Daemon Thread (c) User Thread (d) JVM ... chapter Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What is XMS and XMX in Java Virtual Machine? Initially, what is it’s value? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    What would you do when JVM is consuming 100% CPU & Memory on a server?...
asked Jun 11, 2021 in Technology by JackTerrance
0 votes
    I use Eclipse for java, this is the error is got. Type safety: Unchecked cast from Object to HashMap Now there is ... how to use it? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Do we have get(Object o) method in HashSet. (a) True (b) False The question was posed to me by my ... The Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    what does public String replaceAll(string replace) do? (a) Replace all characters that matches pattern with a ... Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    What does Files.lines(Path path) do? (a) It reads all the files at the path specified as a String ( ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What does setAutoCommit(false) do? (a) commits transaction after each query (b) explicitly commits transaction (c) ... JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    I am new to Hadoop/ZooKeeper. I cannot understand the purpose of using ZooKeeper with Hadoop, is ZooKeeper writing ... with Hadoop? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what does a Java Developer do? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
...