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 ) ?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With