Understanding the Java JVM Memory Model and Its Partitions
This article provides a comprehensive overview of the Java Virtual Machine runtime data area, detailing each memory partition—including the JVM stack, native method stack, heap, method area, and program counter—and explains the concept and usage of direct memory.
Introduction
The Java Virtual Machine (JVM) manages a runtime data area called the "runtime data area" when executing Java programs, and understanding where objects and variables are stored is essential.
1. Memory Model & Partitions
The runtime data area is divided into the following sections:
Java Virtual Machine Stack (stack area)
Native Method Stack
Java Heap (heap area)
Method Area
Program Counter
Each partition serves a specific purpose in the execution of Java code.
2. Java Heap
Overview of the Java heap, which stores all class instances and arrays.
3. Java Virtual Machine Stack
Details about the JVM stack, which holds frames for method invocations, local variables, and operand stacks.
4. Native Method Stack
The native method stack is similar to the JVM stack but serves native (non‑Java) method calls.
5. Method Area
The method area stores class structures, static variables, and the runtime constant pool.
It also contains a runtime constant pool, which holds literals and symbolic references.
6. Program Counter
The program counter is a small memory area that records the address of the next instruction to be executed for each thread.
7. Additional Knowledge: Direct Memory
Definition: Memory allocated outside the Java heap via native functions, introduced with NIO in JDK 1.4.
Features: Not limited by heap size.
Use case: Suitable for high‑frequency I/O operations, accessed through a DirectByteBuffer object to avoid copying between Java heap and native memory.
Possible exception: OutOfMemoryError when total memory usage exceeds physical limits.
8. Summary
The article has thoroughly explained the JVM memory model and its partitions, covering the heap, stacks, method area, program counter, and direct memory, providing a solid foundation for understanding Java runtime memory management.
Author: Carson_Ho
Link: juejin.im/post/6844903677279338509
- END -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.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
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.
