Understanding the JVM: Its Position in the JDK and Four Core Components
This article explains where the JVM resides within the JDK, describes its four main components—ClassLoader, Native Interface, Execution Engine, and Runtime Data Areas—and details memory management, garbage‑collection algorithms, collector types, diagnostic commands, and the Java class‑file structure.
JVM Position in the JDK and Startup Process
After javac compiles a .java source file into a .class bytecode file, the java command launches the JVM. The JVM locates jvm.cfg under the JRE, selects the appropriate jvm.dll (client or server) according to the -client / -server flag, loads the native library, and attaches it to a JNIENV instance. The ClassLoader then loads the class files, and the Execution Engine interprets or JIT‑compiles the bytecode for execution.
Four Main Parts of the JVM
ClassLoader – loads .class files; three built‑in loaders follow the parent‑delegation model: Bootstrap, ExtClassLoader, and App ClassLoader.
Native Interface – provides access to native libraries; native methods are recorded in the Native Method Stack and invoked by the Execution Engine.
Execution Engine (Interpreter) – executes the loaded bytecode instructions.
Runtime Data Areas – consist of Stack, Heap, Method Area, PC Register, and Native Method Stack.
Runtime Data Areas
Heap – the largest memory region, created at JVM start, stores objects and arrays. It is divided into Young Generation (Eden, From/To Survivor spaces) and Old Generation (Tenured). In HotSpot the Method Area is implemented as non‑heap memory (PermanentSpace).
Stack – thread‑private, holds stack frames with local variables, operand stack, dynamic linking, and return information.
Native Method Stack – similar to the Java stack but serves native method calls.
Method Area – shared among threads; stores class metadata, constants, static variables, and JIT‑compiled code. It is often called “non‑heap”.
PC Register – per‑thread pointer to the next bytecode instruction; undefined for native methods.
Heap Organization and Configuration
Heap size is set with -Xms (initial) and -Xmx (maximum).
Young Generation size is set with -Xmn. The ratio between Young and Old generations can be adjusted with -XX:NewRatio (when -Xms equals -Xmx, the flag is optional).
Survivor space ratio is configured with -XX:SurvivorRatio, which defines the size relationship between Eden and each Survivor space.
Stack size per thread is configured with -Xss. The default varies by platform and JVM implementation.
Garbage‑Collection Triggers
Object becomes unreachable.
Uncaught exception causes a scope to end.
Normal program termination.
Explicit call to System.exit().
Abnormal termination.
GC Algorithms
Mark‑Sweep – scans from GC roots, marks live objects, then sweeps unmarked objects; efficient when many objects survive but can fragment memory.
Copying – copies live objects to a new space; efficient when few objects survive.
Mark‑Compact – marks live objects and compacts them to eliminate fragmentation.
HotSpot Garbage Collectors
Serial GC – single‑threaded; pauses all application threads during collection; typical for client‑mode JVMs.
ParNew GC – adds multithreading to Serial GC; less efficient on single‑CPU machines.
Parallel Scavenge GC – throughput‑oriented collector; default for server‑mode JVMs. Throughput = program run time / (GC time + program run time).
Parallel Old – parallel collector for the old generation; uses the Mark‑Compact algorithm.
Serial Old – single‑threaded old‑generation collector; also serves as the fallback for CMS failures.
CMS (Concurrent Mark‑Sweep) – low‑pause collector using Mark‑Sweep; phases: initial mark, concurrent mark, remark, concurrent sweep. Thread count for CMS is (CPU cores + 3) / 4.
G1 (Garbage‑First) – can collect both young and old generations; balances throughput and pause time; introduced in JDK 6.
Diagnostic Commands
jcmd -lLists JVM processes and their PIDs.
jcmd 24684 VM.flags
-XX:InitialHeapSize=98566144 -XX:MaxHeapSize=1547698176 -XX:MaxNewSize=515899392 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=1572864 -XX:OldSize=96993280 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGCShows the JVM flags for the process with PID 24684.
Full GC Conditions
Old generation cannot allocate a large object or array.
Permanent Generation (or Metaspace) is exhausted in non‑CMS configurations.
CMS encounters “promotion failed” or “concurrent mode failure”.
After a Minor GC, an object slated for promotion is larger than the remaining old‑generation space.
Frequent Full GC indicates memory pressure.
Common JVM Options
java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxPermSize=16m -XX:MaxTenuringThreshold=0 -XX:+UseParallelGC -XX:+PrintGCDetails -Xloggc:gc.log -Xmx3550m– maximum heap size. -Xms3550m – initial heap size (set equal to -Xmx to avoid resizing). -Xmn2g – young generation size (≈ 3/8 of total heap, per Sun recommendation). -Xss128k – per‑thread stack size (default ≈ 1 MiB on JDK 5+; smaller values allow more threads). -XX:NewRatio=4 – Young : Old generation ratio = 1 : 4. -XX:SurvivorRatio=4 – Eden : each Survivor space = 4 : 1 (total Survivor space = 1/6 of young generation). -XX:MaxPermSize=16m – size of the permanent (non‑heap) space. -XX:MaxTenuringThreshold=0 – objects move directly from Eden to old generation; larger values keep objects longer in Survivor spaces.
Collector selection flags: -XX:+UseSerialGC, -XX:+UseParallelGC, -XX:+UseParallelOldGC, -XX:+UseConcMarkSweepGC.
GC logging flags: -XX:+PrintGC, -XX:+PrintGCDetails, -XX:+PrintGCTimeStamps, -Xloggc:filename.
Class File Structure
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count; field_info fields[fields_count];
u2 methods_count; method_info methods[methods_count];
u2 attributes_count; attribute_info attributes[attributes_count];
}magic – fixed value 0xCAFEBABE, identifies the file as a valid class file.
minor_version and major_version – specify the class file format version; higher major versions are backward compatible with lower ones.
constant_pool_count – equals the number of entries in the constant pool plus one (indexing starts at 1).
constant_pool[] – table of literals, class and interface names, field and method references, etc.
access_flags – bitmask indicating class or interface modifiers (public, final, abstract, etc.).
this_class – index into the constant pool that must be a CONSTANT_Class_info entry representing the class defined by this file.
super_class – index into the constant pool for the direct superclass; zero for java.lang.Object.
interfaces_count and interfaces[] – number of directly implemented interfaces and their constant‑pool indexes.
fields_count and fields[] – number and descriptions of fields declared by the class.
methods_count and methods[] – number and descriptions of methods (including constructors and static initializers).
attributes_count and attributes[] – additional attributes such as Code, SourceFile, etc.
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.
ZhiKe AI
We dissect AI-era technologies, tools, and trends with a hardcore perspective. Focused on large models, agents, MCP, function calling, and hands‑on AI development. No fluff, no hype—only actionable insights, source code, and practical ideas. Get a daily dose of intelligence to simplify tech and make efficiency tangible.
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.
