Home > Java > javaTutorial > body text

13 Diagrams Illustrating the Memory Model in Java

Release: 2023-07-26 15:58:55
forward
1419 people have browsed it
Preface
  • It is very important to understand the memory area where objects, variables, etc. in Java are stored
  • This article will comprehensively explain the memory model & partitioning in the Java virtual machine. I hope you will like it

Directory

13 Diagrams Illustrating the Memory Model in Java

##1. Memory Model & Partition


When the Java virtual machine runs a Java program, it will manage a memory area: the runtime data area

In the runtime data area, it will be divided according to usage:

  1. Java virtual machine stack (stack area)
  2. Local method stack
  3. Java heap (heap area)
  4. Method Area
  5. Program Counter

13 Diagrams Illustrating the Memory Model in Java

## Below, I will introduce each memory model partition in detail

2. Java堆


13 Diagrams Illustrating the Memory Model in Java
简介
13 Diagrams Illustrating the Memory Model in Java


3. Java虚拟机栈


13 Diagrams Illustrating the Memory Model in Java

简介
13 Diagrams Illustrating the Memory Model in Java


4. 本地方法栈


13 Diagrams Illustrating the Memory Model in Java
Introduction: Very similar to the Java virtual machine stack, but different from the Java virtual machine It lies in: the service object, that is, the Java virtual machine stack serves to execute Java methods; the local method stack serves to execute Native methods


5. 方法区



13 Diagrams Illustrating the Memory Model in Java
简介
13 Diagrams Illustrating the Memory Model in Java
注:其内部包含一个运行时常量池,具体介绍如下:
13 Diagrams Illustrating the Memory Model in Java

6. 程序计数器


13 Diagrams Illustrating the Memory Model in Java
简介
13 Diagrams Illustrating the Memory Model in Java  

7. 额外知识:直接内存


  • Definition: The channel- and buffer-based I/O method in the NIO class (introduced in JDK1.4) uses the Native function library Directly allocated off-heap memory
  • Features: Not limited by heap size
Does not belong to virtual machine runtime data Part of the area & not allocated in the heap
  • Application scenario: Suitable for scenarios with frequent calls
Operate through a DirectByteBuffer object stored in the Java heap as a reference to this memory, thereby avoiding copying data back and forth between the Java heap and the Native heap and improving performance
  • Exception thrown: OutOfMemoryError, that is, the sum of other memory areas is greater than the physical memory limit


8. Summary


This article comprehensively explains the memory model & partitioning in JVM, summarized as follows


13 Diagrams Illustrating the Memory Model in Java

The above is the detailed content of 13 Diagrams Illustrating the Memory Model in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:Java学习指南
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template