Stack Overflow handling in HotSpot JVM
As you probably know, HotSpot JVM has one-to-one mapping of Java threads to OS threads. Each thread is associated with its own stack. Sounds simple… until you realize that in Java there are at least 3 different notions of a stack:
- Java Virtual Machine Stack, which stores local variables and keeps track of method invocations. As the specification says, this stack does not need to be contiguous and may be heap allocated. E.g. Java ME virtual machine (that I worked on at Sun Microsystems) indeed had chunked stacks allocated in Java heap.
- Operand Stack, which holds operands for bytecode instructions.
- Native Stack - the classical “C” stack required for native method execution.
Beware of computation in static initializer
It’s a quite common practice to prepare immutable data during class initialization and save the results in
static finalfields. In fact, this is exactly what static initializers are designed for.
PREV 1 of 1 NEXT