Java虚拟机本地方法栈溢出例子

JVM配置

-Xss128k

代码

package com.example.oom;

public class JavaVmStackSOF {
    public int getStackLength() {
        return stackLength;
    }

    private int stackLength = 1;


    public void stackLeak() {
        stackLength++;
        stackLeak();
    }
}

测试

class JavaVmStackSOFTest {
    @Test
    public void test() {
        JavaVmStackSOF sof = new JavaVmStackSOF();

        try {
            sof.stackLeak();
        } catch (Throwable throwable) {
            System.out.println("stack length: " + String.valueOf(sof.getStackLength()));
            throw throwable;
        }
    }
}

结果

 

 调大xss的配置

-Xss1000M

二次结果

最终还是SOF,但是stack length达到了6000W

 

posted @ 2020-05-12 23:07  ibrake  阅读(370)  评论(1编辑  收藏  举报