Java virtual machines in the course of executing a Java program will divide the memory that it manages into several zones, each of which has its own purpose, as well as the time of creation and destruction, and some regions that exist as virtual machine processes start, and some that depend on the start and end of the user's thread to build and destroy. According to the Java Virtual Machine specification, the memory managed by the Java Virtual machine will include the following runtime data regions.
As shown in the following:
Java Virtual Runtime Data area can be divided into:
Program Counter Heap Method Area run a constant pool local method stack java Virtual machine stack. The program counter, Java stack, and local method stack are created based on the startup of the thread, while the heap, method area, and run constant pool are created with the JVM's startup, where the data can be shared by individual threads.
(Photo excerpt from: http://286.iteye.com/blog/1928180, I think it's clearer than the one on "deep understanding of Java Virtual machines")
1, program counter
A program counter is a small amount of memory space that can be thought of as the line number indicator of the byte code executed by the current thread. Because the multithreading of a Java Virtual machine is implemented in a way that threads take turns switching and allocating processor execution time, at any given moment, a processor executes only the instructions in one thread. As a result, the correct execution location can be restored after the thread is switched, and each thread has a separate program counter. If the thread is executing a Java method, this counter records the address of the virtual machine bytecode instruction being executed, and if the native method is being executed, the counter value is empty.
2,java Virtual Machine Stack
The Java Virtual machine stack is also thread-private, with the same life cycle as the thread. The virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame at the same time as it executes. Used to store information such as local variable tables, operand stacks, dynamic links, method exits, and so on. Each method from the call until the completion of the process, it corresponds to a stack post in the virtual machine into the stack to the process of the stack. The Java Virtual machine stack is used to store stack frames, while stack frames hold local variables and partial results, and call and return of participating methods.
Frames are used to store information such as local variable tables, operand stacks, dynamic links, method exits, and delivery exceptions. When the method call ends, the frame is destroyed; the frame is allocated space by the Java stack of the thread that created the frame, each with its own array of local variables, an operand stack, and a reference to run a constant pool
3, local method stack
The local method stack is very similar to the virtual machine, but the difference between them is that the virtual machine stack executes the Java method, while the local method stack is the native used by the Java virtual machine to the native method service.
4,java Heap
For most applications, Java (heap) is the largest piece of memory managed by a Java virtual machine. The Java heap is a piece of memory that is shared by all threads and created when the virtual machine is started. Its main purpose is to create object instances where all instances of the image are assigned.
5, Method area
The method area, like the Java heap, is an area of memory shared by each thread that stores data such as class information, constants, static variables, and code compiled by the immediate compiler that have been loaded by the virtual machine.
Running a constant pool is part of the method area. In addition to descriptive information such as the version, field, method, and interface of the class file, there is also a message that a constant pool is used to store the various literal and symbolic references generated during the compilation period.
---restore content ends---
Java Runtime Data Area