简体   繁体   中英

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 ) ?

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

Each thread gets its own allocation of stack space. You can set how big this allocation is with the -Xss option on the Java command line; the default is different on different platforms, but it's always a "per thread" amount.

The limit is an amount of memory per thread, not a number of entries on the stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM