什么是JVM的崩溃呢?
JVM已经无法抛出异常了,你会看到这样的错误
# # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x6d8a99c6, pid=2572, tid=964 # # JRE version: 6.0_22-b04 # Java VM: Java HotSpot(TM) Client VM (17.1-b03 mixed mode, sharing windows-x86 ) # Problematic frame: # V [jvm.dll+0x99c6] # # An error report file with more information is saved as: # D:\E\Projects\Java\Crash\hs_err_pid2572.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp #
同时会生成hs_err_pidxxxx.log的日志文件。
怎么把JVM弄崩溃呢?
总结了一下,感觉有三种方法
1是利用编译器及JVM自身特性,导致不可恢复的灾难;
2是利用JDK或JVM的bug;
3是用JNI,让JVM鞭长莫及,无论是sun提供的,还是我们自己写的;
import sun.dc.pr.PathDasher;
import sun.misc.Unsafe;
//方法1
//我最认可的方法
public static void main(String[] args) {
Object[] o = null;
while (true) {
o = new Object[] { o };
}
}
//方法2
//JDK1.6u23 以前版本中的bug
public static void main(String[] args) {
Double.parseDouble("2.2250738585072012e-308");
}
//方法3
//JNI
public static void main(String[] args)
{
PathDasher dasher = new PathDasher(null) ;
}
//方法4
//JNI
//java -Xbootclasspath/p:. Crash
private static final Unsafe unsafe = Unsafe.getUnsafe();
public static void crash()
{
unsafe.putAddress(0, 0);
}
public static void main(String[] args) {
crash();
}