Preface:

In this article, you will learn about the memory model of Java virtual machine (JVM) and how to store objects, variables, etc. Doesn’t it smell good?

Directory:

5 minutes to teach you how to create a VIRTUAL machine! Doesn’t it smell good?

  1. Memory model & partitioning

    When running Java programs, the Java virtual machine manages one area of memory: Runtime data area The runtime data area is divided according to its purpose: Java virtual machine stack (stack area) Local method stack Java heap (heap area) Method area program counter

Below, I’ll describe each memory model partition in detail

  1. Java heap: schematic

Introduction to the

  1. Java Virtual machine stack diagram

Introduction to the

  1. Diagram of the local method stack

The introduction is similar to the Java Virtual machine stack, but differs from the Java VIRTUAL machine in the following aspects: Service objects, that is, the Java virtual machine stack serves the execution of Java methods. The local method stack serves to execute Native methods

  1. Schematic diagram of method area

Introduction to the

Note that it contains an internal run-time constant pool, described as follows:

  1. Schematic diagram of program counter

Introduction to the

  1. Additional knowledge: direct memory definition: channel – and buffer-based I/O in the NIO class (introduced in JDK1.4) is off-heap memory allocated directly by using Native libraries

Features: Not limited by the heap size Application Scenario: Applicable to frequent calls A DirectByteBuffer object stored in the Java heap is used as a reference to the memory to avoid data replication between the Java heap and Native heap and improve the usage performance

Exception thrown: OutOfMemoryError, where the sum with other memory regions is greater than the physical memory limit

This article provides a comprehensive overview of the memory model & partitioning in the JVM, summarized below

PDF, which covers the JVM, locking, high concurrency, reflection, Spring principles, microservices, Zookeeper, databases, data structures, and more, can be found at shimo.im/docs/pVhDCp… Can be