堆栈帧大小是否有上限 [英] Is there a upper limit on stack frame size

查看:130
本文介绍了堆栈帧大小是否有上限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于堆,我们有一个内存不足错误,但是(出于好奇而问)单个堆栈的大小是否有相同的限制?如果不是这样,那么如果堆栈帧需要过多的内存(例如成千上万的局部变量等),那么如何防止这种溢出呢?

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

推荐答案

如果线程请求的堆栈空间超出其可用空间,则会收到StackOverflowError.

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

单个堆栈帧的大小在编译时确定,并与方法的代码一起存储在类文件中.实际上有两个字段:局部变量数组的大小和操作数堆栈的深度.两者都限于2 ^ 16-1. http://docs.oracle.com /javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546

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

这篇关于堆栈帧大小是否有上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆