JVM memory structure and overview

JVM memory structure

  • JVM runs on the operating system, it does not directly interact with the hardware.
    Insert picture description here

  • JVM memory architecture diagram:
    Insert picture description here

    Note: Orange represents the area shared by all threads and gray represents the data area isolated by threads

  • Program counter : is a small memory space, it can be seen as the line number indicator of the bytecode executed by the current thread. When the bytecode interpreter works, it selects the next bytecode instruction that needs to be executed by changing the value of this counter. Basic functions such as branching, looping, jumping, exception handling, thread activation, etc. all rely on this counter to complete. At the same time, in order to restore to the correct execution position after thread switching, each thread needs an independent program counter. The counters between the threads do not affect each other and are stored independently. We call this type of memory area "thread private" RAM.

  • Java virtual machine stack : Like the program counter, it is also private to the thread and has the same life cycle as the thread. The virtual machine stack describes the memory model of Java method execution: when each method is executed, a stack frame is created to store information such as the local variable table, operand stack, dynamic link, method exit, etc. The process of each method from invocation to completion of execution corresponds to the process of pushing a stack frame in the virtual machine stack to popping out of the stack, (the "stack" referred to in the course is the virtual machine stack explained now) as shown in the figure Show:
    Insert picture description here

  • Native method stack : Serves the Native method used by the virtual machine, which also belongs to the thread private data area. Under normal circumstances, we do not need to pay attention to this area.

  • Method area : Also known as non-heap, it is used to store data such as class information, constants, static variables, and code compiled by the JIT compiler that has been loaded by the virtual machine. It is also a memory area shared by each thread.

    Note: There is an area called Runtime Constant Pool in the method area, which is mainly used to store various literal values ​​and symbol references generated by compilation. This part of the content will be stored in the runtime constant pool after the class is loaded. in.

  • Java heap : It is the largest piece of memory managed by the Java virtual machine. It is a memory area shared by all threads. It is created when the virtual machine starts, and its main purpose is to store object instances. At the same time, this area is the most important area managed by the garbage collector, so it is often called the "GC heap". According to the generational collection algorithm adopted by the garbage collector, the Java heap can also be subdivided into the new generation and the old generation.
    Insert picture description here

Guess you like

Origin blog.csdn.net/Java_lover_zpark/article/details/105460375