Crashing Java with sun.misc.Unsafe

Alex Kalinins
6 min readNov 10, 2020

Note from the author: the purpose of this article is to explain and educate about the JVM. Please do not use any of the information from this article for malicious purposes. The experiments in this article were written in Java 8, results may vary in more recent versions.

Background

The beauty of Java is that you can compile your program on one machine, but you can run it on any machine that supports Java. When you hit the compile button in your IDE (or run the ‘javac’ command), the Java compiler compiles your .java source files into .class bytecode.

When you run the .class file, Java launches the Java Virtual Machine (JVM), which executes the bytecode. In a language like C or C++, the source files are compiled into architecture-specific assembly language. To run a C program on a device, it has to be compiled specifically for that architecture. In a sense, Java bytecode is the assembly language for the JVM. The JVM implementation becomes the only platform-specific variable, while the bytecode remains universal.

Exception vs. JVM Crash

When a Java program terminates because of an uncaught error or exception, the JVM continues to function. This could be thought of as a program crashing. However, if the JVM crashes, it takes down with it the faulty program and any…

--

--

Alex Kalinins

A brain and computer enthusiast studying what I love at the University of Toronto. Connect with me on LinkedIn: https://www.linkedin.com/in/alex-kalinins/