Simple understanding of JVM virtual machine-JVM memory area division

 Program counter

 In the JVM specification, each thread has its own program counter, and a thread has only one method executing at any time, which is the so-called current method. The program counter stores the JVM instruction address of the Java method being executed by the current thread; or, if it is executing a local method, it is an unspecified value.

Java virtual machine stack

When each thread is created, a virtual machine stack is created, which saves a stack frame (Stack Frame), corresponding to the Java method calls. When talking about the program counter, the current method was mentioned; in the same way, at a point in time, there will be only one active stack frame, usually called the current frame, and the class in which the method is located is called the current class. If other methods are called in this method, the corresponding new stack frame will be created and become the new current frame until it returns the result or the execution ends. The JVM has only two direct operations on the Java stack, namely pushing and popping the stack frame. The stack frame stores the local variable table, operand (operand) stack, dynamic link, the definition of normal exit or abnormal exit of the method, etc.

Heap

The heap is the core area of ​​Java memory management and is used to place Java object instances. Almost all created Java object instances are directly allocated on the heap. The heap is shared by all threads. When the virtual machine starts, the parameters such as "Xmx" are used to specify indicators such as the maximum heap space. Of course, the heap is also an area that the garbage collector focuses on, so the space in the heap will be further subdivided by different garbage collectors, such as the new generation and the old generation.

Method area

This is also a memory area shared by all threads, used to store so-called meta (Meta) data, such as class structure information, and the corresponding runtime constant pool, fields, method code, etc. Due to the early implementation of Hotspot JVM, many people are accustomed to refer to the method area as the permanent generation (Permanent Generation). In Oracle JDK 8, the permanent generation is removed, and the metadata area (Metaspace) is added.

Runtime constant pool

This is part of the method area . If you carefully analyze the structure of the decompiled class file, you can see various information such as version numbers, fields, methods, superclasses, and interfaces, and another piece of information is the constant pool. Java's constant pool can store various constant information, whether it is a variety of literals generated during compilation or symbol references that need to be determined at runtime, so it is more extensive than the information stored in the symbol table of general languages.

Native method stack

The local method stack is very similar to the Java virtual machine stack. It supports calling local methods, and each thread will create one. In Oracle Hotspot JVM, the native method stack and the Java virtual machine stack are in the same area, which depends entirely on the decision of technical implementation, and is not mandatory in the specification

Reference materials
Java core technical interviews

 

Guess you like

Origin blog.csdn.net/samz5906/article/details/104519077