Understanding JVM Memory Structure and Configuration Parameters
This article explains the JVM memory architecture—including heap, method area, stack, native stack, and program counter—details how each region is organized, and provides common JVM command‑line options and typical configuration examples for optimizing Java applications.
The JVM memory model is a core topic for Java developers and interview preparation, and this article introduces its overall structure and key components.
JVM Memory Structure – The memory space is divided into three main parts: heap, method area, and stack. The stack can be further split into the Java virtual machine stack and the native method stack, while the heap consists of the young generation (Eden, From Survivor, To Survivor) and the old generation.
Heap Memory – The Java heap is the largest shared memory area, used to store object instances. It is divided into young and old generations; the young generation ratio can be set with -XX:NewRatio, and the default Eden:From:To ratio is 8:1:1, configurable via -XX:SurvivorRatio.
Method Area – Also known as the permanent generation (PermGen) in older JDKs, it stores class metadata, constants, and static variables. In JDK 8 and later, PermGen was replaced by Metaspace, which resides in native memory. Typical settings include -XX:PermSize=64M and -XX:MaxPermSize=256M.
Virtual Machine Stack – Each Java method execution creates a stack frame that holds the local variable table, operand stack, and return address. The stack frames are pushed and popped as methods are invoked and completed.
Native Method Stack – Similar to the JVM stack but dedicated to native (C/C++) method execution.
Program Counter – A per‑thread counter that points to the current bytecode instruction; it is not shared between threads.
JVM Memory Parameters – Common command‑line options include: -Xms: set the initial heap size -Xmx: set the maximum heap size -Xmn: set the young generation size -XX:NewSize / -XX:MaxNewSize: set young generation min/max -XX:PermSize / -XX:MaxPermSize: set permanent generation size (pre‑JDK 8) -Xss: set each thread's stack size -XX:+UseParallelGC: enable the parallel garbage collector for the young generation -XX:ParallelGCThreads=20: configure the number of GC threads
Typical JVM Configuration Example –
java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=20. This sets a 3.55 GB heap, a 2 GB young generation, a 128 KB thread stack, and selects concurrent mark‑sweep GC with parallel threads.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
