preface

  • To understandJavaThe area of memory where objects, variables, and so on are stored is very important
  • This article will give a comprehensive explanationJavaMemory model & partition in virtual machine, hope you like it

In the coming days, I will publish a series of articles on the JVM, as follows; Interested in sustainable follow Carson_Ho’s Android development notes


Schematic diagram


directory


Schematic diagram


1. Memory model & Partitioning

  • JavaThe VIRTUAL machine is runningJavaA program manages one area of memory: the runtime data area
  • In the runtime data section, it is divided according to usage:
    1. JavaVirtual machine stack (stack area)
    2. Local method stack
    3. JavaHeap (heap area)
    4. Methods area
    5. Program counter


Schematic diagram

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

2. The Java heap

  • Schematic diagram


    Schematic diagram

  • Introduction to the


Schematic diagram

Garbage collection will be explained in an upcoming article


3. Java VM stack

  • Schematic diagram


    Schematic diagram

  • Introduction to the


Schematic diagram


4. Local method stack

  • Schematic diagram


Schematic diagram

  • Introduction to the

    Very similarJavaThe vm stack differs from the Java VM in the following aspects: Service object, namely

    Java virtual machine stack for executionJavaMethod service; The local method stack is executionNativeMethods the service

5. Methods area

  • Schematic diagram


    Schematic diagram

  • Introduction to the


Schematic diagram

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


Schematic diagram


6. Program counter

  • Schematic diagram


Schematic diagram

  • Introduction to the


Schematic diagram


7. Extra knowledge: Direct memory

  • Definition:NIOClass (JDKChannel – and buffer-based in 1.4I/OBy usingNativeOut-of-heap memory allocated directly by the library
  • Features: Not limited by heap size

Not part of the virtual machine run-time data area & not allocated in the heap

  • Application scenario: This mode is applicable to frequently invoked scenarios

A DirectByteBuffer object stored in the Java heap is used as a reference to this memory to avoid copying data back and forth between the Java heap and Native heap and improve performance

  • Exception thrown:OutOfMemoryErrorThat is, 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


Schematic diagram

  • In the coming days, I’ll be presenting a series of presentationsJVMArticle, as follows; Interested in sustainable concernsCarson_Ho android Development Notes


Schematic diagram


Thumb up, please! Because your encouragement is the biggest power that I write!

The Android event distribution mechanism is the most comprehensive and easy to understand solution for Android screen adaptation. It is the most comprehensive and easy to understand solution for Android screen adaptation. Android development: JSON introduction and the most comprehensive analysis method! BroadcastReceiver Is the most comprehensive version of Android’s BroadcastReceiver


Welcome to attentionCarson_HoJane books!

Share the dry things about Android development from time to time, the pursuit of short, flat, fast, but there is no lack of depth.