In depth analysis of the use of JAVA memory area

JAVA memory partition:

In JAVA memory allocation, Java divides memory into: method area, heap, virtual machine stack, local method stack and program counter. The method area and heap are shared by all threads, while the virtual machine stack, local method stack and program counter are isolated from threads. Each area has its own creation and destruction time.

Program counter: the line number indicator of the bytes executed by the current thread. Java multithreading is realized by switching threads in turn and allocating processor execution time. Therefore, in order to recover to the correct position after switching, each thread needs an independent program counter.

Java virtual machine stack:

Each stack frame will be created at the same time when it is executed to store local variable table, operand stack, dynamic link, method exit and other information. Virtual memory stack is what we often call "stack". The memory required by the local variable table is allocated at compile time.

Local method stack:

Similar to the virtual machine stack, the difference is that the virtual machine stack executes Java method services for the virtual machine, while the local method stack uses native method services for the virtual machine.

Java heap:

Shared by all programs and created when the virtual machine starts. This memory area is used to store object instances. According to the provisions of Java virtual machine, Java heap can be in physically discontinuous memory space, as long as it is logically continuous.

Method area:

Like the heap, it is shared among threads. The function is to store class information, constants, static variables, code compiled by the real-time compiler and other data that have been loaded by the virtual machine.

Runtime constant pool:

Is part of the method area. The function is to store various literal and symbolic references generated at compile time.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>