Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a upper limit on stack frame size

We have an out of memory error for a heap but ( just asking out of curiosity ) is there an equivalent limit on size of an individual stack ? If not then what prevents such an overflow if excess memory is needed by a stack frame ( like thousands of local variable etc ) ?

like image 470
JavaDeveloper Avatar asked Oct 25 '13 06:10

JavaDeveloper


2 Answers

If a thread requests more stack space than it has available it receives a StackOverflowError.

http://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html

The size of an individual stack frame is determined at compile time and stored in the class file together with the method's code. Actually there are two fields: the size of the local variable array, and the depth of the operand stack. Both are limited to 2^16-1. http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546

like image 155
Joni Avatar answered Sep 29 '22 05:09

Joni


The space allocated to the runtime stack is for all of your stack frames on a single execution thread combined, i think.

The default size is different for most OSes. Have a look at these docs. You can increase the size if need be with the -Xss JVM parameter.

http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/jrdocs/refman/optionX.html

like image 20
yamafontes Avatar answered Sep 29 '22 05:09

yamafontes