What memory areas does the JVM have? Where do static variables live?
Short answer
Shared areas: the heap (objects, arrays, managed by GC, capped by -Xmx) and metaspace (class metadata, in native memory since Java 8). Per-thread areas: the JVM stack, the PC register, the native method stack. Static variables live in the heap since Java 7.
3 points to say:
- Shared: heap, metaspace, code cache; per thread: stack, PC register, native method stack.
- Static fields live in the heap (attached to the
Classobject); class metadata lives in metaspace. - PermGen was replaced by metaspace in Java 8.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.