VM stack and native method stack overflow

Since the HotSpot VM does not distinguish the virtual machine stack and native method stacks, therefore, native method stacks while setting the size of the parameters
(-Xoss) exists, but is invalid, the capacity can only be set by the stack -Xss parameters.

About Virtual Machine and native method stacks stack overflow in java virtual machine specification describes two anomalies:

If the stack is greater than the depth of the thread requested the maximum depth allowed by the virtual machine, StackOverflowError will throw an exception
if the virtual machine at the time of application to extend the stack can not be enough memory space, then throw an OutOfMemoryError
though divided into two cases, but both also have something in common: when not continue to allocate stack space, in the end is the memory size, or too much stack space has been used, which is essentially just described two kinds of the same thing.
In an example, the experimental limit the scope of a single thread operation.
Two cases:
using -Xss parameter stack memory capacity is reduced. The results throw an exception, the stack depth output when abnormal reduced accordingly.
Defines a number of local variables, this method increases the length of the frame of the local variable table. Results exception is thrown, a respective output stack depth reduction.

public class JavaVMStackSOF{
	private int stackLength = 1;
	public void stackLeak(){
		stackLength++;
		stackLeak();
		public static void main(String[] args) throws Throwable{
			JavaVMStackSOF oom = new JavaVMStackSOF;
			try{
				oom.stackLeak();
			}catch(Throwable e){
				System.out.println("stack length:" + oom.stackLength);
				throw e;
			}
		}
	}
}

operation result:

Exception in thread "main" java.lang.StackOverflowError

Guess you like

Origin blog.csdn.net/fight252/article/details/91353574