您好,我有一个问题期待您的回答
关于《深入理解Java虚拟机》一书2.2.2节 Java虚拟机栈中曾提到:在《Java虚拟机规范》中,对Java虚拟机栈这个区域定义了两种异常状况 原定义如下 摘自https://docs.oracle.com/javase/specs/jvms/se18/html/jvms-2.html#jvms-2.5.2
If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
If Java Virtual Machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java Virtual Machine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.
您好,我有一个问题期待您的回答 关于《深入理解Java虚拟机》一书2.2.2节 Java虚拟机栈中曾提到:在《Java虚拟机规范》中,对Java虚拟机栈这个区域定义了两种异常状况 原定义如下 摘自https://docs.oracle.com/javase/specs/jvms/se18/html/jvms-2.html#jvms-2.5.2 If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
If Java Virtual Machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java Virtual Machine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.
书中说到,如果线程请求的栈深度大于虚拟机所允许的深度,将抛出StackOverflowError异常;
《Java虚拟机规范》中定义的应为: 如果线程中的计算需要比允许的更大的Java虚拟机堆栈,Java虚拟机会抛出StackOverflowError。
引发StackOverflowError异常的情况常见的情况应为三种 1.无限递归循环调用(最常见)书中所指的调用深度问题。 2.执行了大量方法,导致线程栈空间被用完。 3.方法内声明了海量的局部变量。