Java Runtime Data Area, runtimearea
During java program execution, the java Virtual Machine divides the memory it manages into several regions, each of which has its own purposes and the creation and destruction time, some regions exist along with the startup of virtual machine processes, while some regions depend on the startup and termination of user threads to establish and destroy them. According to java Virtual Machine specifications, the memory managed by the java Virtual Machine will include the following runtime data areas.
As shown in:
The data zone of the Java Virtual Machine runtime can be divided:
Program countersHeapMethod AreaRunning time pool local method StackJava Virtual Machine stack.The program counters, java stacks, and local method stacks are created based on the thread startup. the heap, method zone, and runtime pool are created with the jvm startup, the data can be shared by various threads.
(Picture taken from: http://286.iteye.com/blog/1928180. The figure on the Java Virtual Machine is clearer)
1. program counter
The program counter is a small memory space, which can be seen as the row number indicator of the bytecode executed by the current thread. Java Virtual Machine multithreading is implemented by switching threads in turn and allocating the processor execution time. At any specific time, a single processor will only execute the commands in one thread. Therefore, in order to restore the correct execution position after thread switching, each thread has an independent program counter. If the thread is executing a java method, the counter records the address of the Virtual Machine bytecode instruction being executed. If the native method is being executed, the counter value is null.
2. Java Virtual Machine Stack
The Java Virtual Machine stack is also thread-proprietary, and its lifecycle is the same as that of the thread. The VM stack describes the Memory Model of java method execution: each method creates a stack frame while executing it ). Stores information about local variable tables, operand stacks, dynamic links, and method exits. The process from calling to execution completion of each method corresponds to the process of putting a stack post into the stack in the virtual machine to the out stack. The Java Virtual Machine stack is used to store stack frames, while stack frames hold local variables and partial results, as well as call and return of participating methods.
Frames are used to store information such as the local variable table, operand stack, dynamic link, method exit, and delivery exception. Frames are destroyed only when the method call ends. frames are allocated by the java stack of the thread that creates the frames, each frame has its own local variable array, operand stack, and reference for running the constant pool.
3. Local method Stack
Native method stack plays a very similar role with virtual machines. The difference between them is that the virtual machine stack executes java methods, the local method stack is the native method service used by the Java Virtual Machine.
4. java heap
For most applications, java (HEAP) is the largest piece of memory managed by java virtual machines. Java heap is a memory area shared by all threads. It is created when the VM is started. Its main purpose is to create an object instance and allocate it to all the object instances.
5. Method Area
The method area is the same as the java heap. It is the memory area shared by various threads. It is used to store data such as class information, constants, static variables, and Code Compiled by the real-time compiler.
The runtime constant pool is part of the method area. in addition to the description information such as the version, field, method, and interface of the Class, the Class file also contains the constant pool used to store various literal quantities generated during compilation and symbol references.
--- Restore content end ---