preface

  • It is important to understand the areas of memory where objects, variables, and so on are stored in Java
  • This article will cover the memory model & partitioning in the Java virtual Machine in a comprehensive way. I hope you enjoyed it

directory



1. Memory model & Partitioning

When running Java programs, the Java virtual machine manages one area of memory: the runtime data area

In the runtime data section, it is divided according to usage:

  • Java Virtual Machine stack (Stack area)
  • Local method stack
  • Java heap (heap area)
  • Methods area
  • Program counter



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

2. The Java heap



Introduction to the



3. Java VM stack



Introduction to the



4. Local method stack



Introduction: It is similar to Java Virtual machine stack, but differs from Java virtual machine in that the Java virtual machine stack serves the execution of Java methods. The local method stack serves to execute Native methods

5. Methods area



Introduction to the



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



6. Program counter



Introduction to the



7. Extra knowledge: Direct memory

  • Definition: channel – and buffer-based I/O in the NIO class (introduced in JDK1.4) allocates out-of-heap memory directly using Native libraries
  • Features: heap-free Not part of the virtual machine’s run-time data area & not allocated in the heap
  • Application scenario: For frequently invoked scenarios, a DirectByteBuffer object stored in the Java heap is used as a reference to the memory. This avoids copying data back and forth between the Java heap and Native heap and improves the usage performance
  • Exception thrown: OutOfMemoryError, where the sum with other memory regions is greater than the physical memory limit

8. To summarize

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



Author: Carson_Ho

Link: juejin. Im/post / 6844903677279338509

Welcome to follow my wechat public account “Code farming breakthrough”, share Python, Java, big data, machine learning, artificial intelligence and other technologies, pay attention to code farming technology improvement, career breakthrough, thinking transition, 200,000 + code farming growth charge first stop, accompany you have a dream to grow together