What Is JVM Stack?
This section describes what are JVM stacks. One stack is created for each thread to hold frames which store local variables, partial results of currently executing nested methods.
What Is JVM (Java Virtual Machine) Stack?
A JVM stack, also called thread stack, is a data area in the JVM memory created for a single execution thread.
The JVM stack of a thread is used by the thread to store local variables, partial results,
and data for method invocations and returns.
What Is a Stack Frame?
A JVM stack data area is actually organized as a stack of frames.
The life cycle of a frame looks like this:
- A new frame is created when a new method is invoked.
- The new frame is added to the top of the stack with the execution control is transferred to the new method.
- The new frame is used during the execution of the new method to store local variables, partial results,
and data for subsequent method invocations and returns.
- The new frame is removed from the top of the stack when the execution control is returned from the new method.
What Is a StackOverflowError?
A StackOverflowError is an exception thrown by a thread, when it's stack
has no more room to add a new frame to make the next method call.
You may use the JVM -Xss option to increase JVM stack size to avoid StackOverflowError exceptions.
When there are too many threads running, the memory area
reserved to allocate JVM stacks may also become full, resulting an OutOfMemoryError exception.
Unfortunately, I don't see any JVM option to increase the JVM stack area to avoid OutOfMemoryError exceptions.
The picture below illustrates the JVM stack area, stacks and frames:
Last update: 2014.
Table of Contents
About This Book
Downloading and Installing JDK 1.8.0 on Windows
Downloading and Installing JDK 1.7.0 on Windows
java.lang.Runtime Class - The JVM Instance
java.lang.System Class - The Operating System
ClassLoader Class - Class Loaders
Class Class - Class Reflections
Sun's JVM - Java HotSpot VM
JRockit JVM 28.2.7 by Oracle Corporation
JVM Runtime Data Areas
Memory Management and Garbage Collectors
Garbage Collection Tests
►JVM Stack, Frame and Stack Overflow
►What Is JVM Stack?
StackOverflowError Exception Test
-Xss JVM Option for Stack Size
Frame Impact of Extra Statements
JVM Stack Expansion and Footprint
JVM Stack Expansion and OutOfMemoryError
Largest Stack Size for HotSpot on Windows
Default Stack Sizes of HotSpot and JRockit
JRockit Frame Size Smaller than HotSpot
JRockit Expanding Stacks in Bigger Chunks
JRockit Running Out Of Memory Quicker
Largest Stack Size for JRockit on Windows
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
CDS (Class Data Sharing)
Micro Benchmark Runner and JVM Options
Micro Benchmark Tests on "int" Operations
Micro Benchmark Tests on "long" Operations
Micro Benchmark Tests in JIT Compilation Mode
Micro Benchmark Tests on "float" and "double" Operations
PDF Printing Version