JVM Runtime Data Areas — Heap, Stack, Metaspace, Code Cache
Fast recall
Quick revision
Core answer
Whether you can map JVM errors (OOM, StackOverflow) to their specific memory areas
Thinking String literals go on the stack — they go in the String Pool on the heap (Java 7+)
Explain that metaspace replaced PermGen in Java 8 and grows automatically to native memory
Interview-ready guide
Interview answer
The JVM divides memory into thread-private areas and shared areas — knowing which area maps to which error is the first step in any JVM diagnosis.
Thread-private (no synchronization needed):
- Stack: one per thread; holds method frames with local variables and partial results; size via
-Xss; deep recursion →StackOverflowError - PC register: current instruction pointer
- Native method stack: for JNI calls
Shared areas:
- Heap: all objects and arrays; garbage collected; sized via
-Xms/-Xmx; exhaustion →OutOfMemoryError: Java heap space - Metaspace: class metadata and bytecode; replaced PermGen in Java 8; uses native memory, grows dynamically; cap via
-XX:MaxMetaspaceSize - Code cache: JIT-compiled native code; fixed size; exhaustion stops JIT compilation
Heap structure:
- Young generation (Eden + Survivor spaces) + Old generation for most collectors
- G1, ZGC, and Shenandoah use region-based layouts instead of contiguous fixed-size generations
I recommend understanding these areas because every JVM error maps to a specific region — knowing which area is involved tells you where to start looking.
JVM Runtime Data Areas — Heap, Stack, Metaspace, Code Cache
Direct Answer
The JVM splits memory into per-thread areas (stack, PC register, native stack) and shared areas (heap for objects, metaspace for class metadata, code cache for JIT code). StackOverflowError = stack; OutOfMemoryError: Java heap space = heap; Metaspace OOM = too many classes loaded.
Common Mistakes & Pitfalls
Thinking String literals go on the stack — they go in the String Pool on the heap (Java 7+)
Check your understanding
Answer these without looking back at the article.
- What is the String Pool and where does it live in the JVM?
- What causes OutOfMemoryError: Metaspace and how do you diagnose it?
- What happens when the JVM Code Cache fills up?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.