Fundamentals 4 min read

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.

Java Captain
Java Captain
Java Captain
Understanding the Java JVM Memory Model and Its Partitions

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.

Java Heap diagram
Java Heap diagram

3. Java Virtual Machine Stack

Details about the JVM stack, which holds frames for method invocations, local variables, and operand stacks.

JVM Stack diagram
JVM Stack diagram

4. Native Method Stack

The native method stack is similar to the JVM stack but serves native (non‑Java) method calls.

Native Method Stack diagram
Native Method Stack diagram

5. Method Area

The method area stores class structures, static variables, and the runtime constant pool.

Method Area diagram
Method Area diagram

It also contains a runtime constant pool, which holds literals and symbolic references.

Constant Pool diagram
Constant Pool diagram

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.

Program Counter diagram
Program Counter diagram

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 -
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMRuntimeMemory Model
Java Captain
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.