测试堆栈溢出
@Testpublic void testStackOverflow() {try {foo1();} catch (Throwable throwable) {// 栈满时,打印递归深度System.out.println(countRecursion);throw throwable;}}public void foo1() {++countRecursion;foo1();}
- JVM option
- Xmx50m
- Xss20m
线程栈大小默认下与堆内存相关,可直接给值
总 -Xmx50m -Xss20m
输出如下:
1112405java.lang.StackOverflowErrorat org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)
作为对比,不设置Xss
11356java.lang.StackOverflowErrorat org.test.learn.jvm.JVMProf.foo1(JVMProf.java:55)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)