Java Virtual machine in the process of executing a Java program, it manages the memory divided into several different data regions. The use of these areas, as well as the creation and destruction of the time, some regions with the virtual machine process started, some regions rely on the user thread start and end to build and destroy.
1. Program counter
A small amount of memory space, can be regarded as the current thread execution of the bytecode of the line number indicator, the bytecode interpreter works by changing the value of this counter to select the next need to execute the bytecode instruction, branch, loop, jump, exception processing, thread recovery and other basic functions to rely on this counter to complete. 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 (a kernel for a multicore processor) executes only the instructions in one thread. Therefore, in order for the thread to switch back to the correct execution location, each thread needs to have a separate program counter. If the thread is executing a Java method, the counter records the address of the virtual machine bytecode instruction being executed, and if the native method is being executed, the calculator value is empty.
2. Virtual Machine stack
The thread is private and the life cycle is the same as the thread. Describes the memory model that Java methods perform: Each method creates a stack frame to store information such as local variable tables, operand stacks, dynamic links, method exits, and so on. Each method from the call to the completion of the process, corresponding to a stack frame in the virtual machine stack into the stack of the process.
A local variable table holds the various basic data types, object references, and ReturnAddress types (addresses that point to a bytecode directive) at compile time.
The memory space required for the local variable table is allocated during compilation and does not change the size of the local variable table during the run of the method.
3. Local Method Stack
Similar to the role of the virtual machine stack, the difference is that the virtual machine stack executes the Java method, and the local method stack executes the native method.
Some virtual machines, such as Sun Hotspot, directly merge the virtual machine stack with the local method stack.
4. Heap
A chunk of memory that is shared by all threads, created at virtual machine startup, and where almost all object instances and arrays are allocated memory, but with the development of the JIT compiler and the escape analysis technique ripe, stack allocation, scalar substitution makes all objects allocated on the heap less absolute.
The Java heap is the main area of garbage collector management, called the GC heap.
Java heap can be subdivided into the new generation and the old age, and then a little more detailed there is Eden space, from Survivor space, to survivor space.
The thread-shared heap has the potential to divide multiple thread-private allocation buffers (thread Local Allocation buffer,tlab).
The Java heap can be in a physically discontinuous memory space as long as it is logically contiguous.
5. Method area
A thread-shared area of memory used to store data such as class information, constants, static variables, and instant compiler-compiled code that are loaded by the virtual machine.
6. Run a constant-rate pool
is a part of the method area that holds the various literal and symbolic references generated during the compilation period, and is dynamic, and may also put new constants into the pool during run time, such as The Intern () method of the String class.
7. Direct Memory
JDK 1.4 Joins the new Input/output class, introducing a channel-based I/O method that can be used to directly allocate out-of-heap memory using the native function library. It then operates as a reference to this memory through a Directbytebuffer object stored in the Java heap. This can improve performance in some scenarios because it avoids copying data back and forth in the Java heap and the native heap.
Java Memory Area