Java: JVM memory model

JVM memory model

JVM memory model can be divided into two parts, as shown below, heap and method area is shared by all threads, the stack of the virtual machine, the program counter stack and local method is private to the thread.
 

1. heap (Heap)

Heap memory is shared by all the threads can be divided into two parts: the old and the young generation's. The figure is representative of the permanent generation of Perm, but note is not part of the permanent generation of heap memory, and after substituting jdk1.8 also be permanently removed.
Heap is java virtual machine memory managed by the largest area of ​​memory, but also by the various threads of shared memory region, the area of ​​memory to store the object instance and an array of (but not all object instances in the heap). -Xms by its size (minimum) and -Xmx (max) parameter (minimum be less than the maximum. 1G), when the former application for minimum memory, the default is the operating system's physical memory 1/64, the latter the JVM may apply maximum memory, physical memory defaults to 1/4, when the default heap memory spare is less than 40%, JVM -Xmx increases the heap memory size specified by -XX: specify this MinHeapFreeRation = than the column; greater than when the spare heap memory 70%, JVM may be reduced to a heap memory size -Xms specified size, can XX: specify this column than MaxHeapFreeRation =, of course, in order to avoid frequent adjustments during operation the size of heap usually provided -Xms -Xmx value into the same. The new generation of heap memory = + + Older Generation lasting generations. When we garbage collection, we tend to heap memory and the new generation into the old generation (size ratio 1: 2), and the new generation by Eden Survivor0, Survivor1 at a ratio of three is 8: 1: 1, the new generation the recovery mechanisms using replication algorithm, in Minor GC, we have to stay a survival area for the object is located survival, regional real conduct is Eden + one of the survival zone, when our object longer than a certain age (default 15, you can by parameter setting), will put objects in the old generation, of course, large objects directly into the old generation. Older Generation collection algorithm uses tags to organize algorithm.

2. Method region (Method Area)

District method, also known as "permanent generation", which is used to store the virtual machine to load class information, constants, static variables, each thread is a shared memory area. The default minimum of 16MB, a maximum of 64MB (64 bit JVM Since pointers expansion, default 85M), by -XX: PermSize and -XX: MaxPermSize size parameter limits zone method. It is a continuous heap space, permanent generational garbage collection and is years old (old generation) bundled together, so no matter who is full, will trigger garbage collection and permanent generation of old age. However, an obvious question is, when loaded by the JVM class information exceeds the capacity of the parameters -XX: MaxPermSize value set, the application will report OOM error. Parameters by -XX: to set MaxPermSize: PermSize and -XX.

3. Virtual Machine stack (JVM Stack)

Java memory model is a description of the method performed: each method when executed creates a "stack frame", for storing local variable table (including parameters), the operation information stack, the method exports. Each method is called to complete execution of the procedure, a stack frame corresponds to a virtual machine from the stack to the stack of a process stack. Lifecycle with the same thread, the thread is private. Stack frame consists of three parts: local variables, an operand stack, the frame data area. Local variables to be organized as a word-wide, the array starts counting from zero, as the local variables and operand stack are also organized into an array for word units. But the former and the difference is that it is not accessible through the index, but the stack is accessed through the stack and out can be seen as a temporary data storage area. In addition to the local variables and operand stack, java stack frames need some data to support constant pool resolution, normal method returns, and exception dispatch mechanism. These data are stored in the data area of ​​the frame java stack frame.
Local variable table: storing basic data of various types known in the compiler, object reference (pointer reference, not the object itself), wherein the long and double the length of the data is 64-bit space two local variables, the remaining data type only one. Required for completion of the local variable table memory space assigned during compilation, when entering a method, this method requires much local variable allocation is fully determined in the stack frame of the stack frame during operation does not change the size of the local variable table space.

4. A native method stacks (Native Stack)

And virtual machine stack substantially similar, except that the stack is java virtual machine virtual machine to perform the method of service, and the local stack method is a method for the Native service. (Stack space is much smaller than the size of the heap)

The program counter (PC Register)

A memory area is minimal, its role is the line number indicator byte code currently executing thread, the virtual machine's model, when the bytecode interpreter is working by changing the value of the counter to select the next bytecode instructions, branching, looping needs to perform exception handling, and other basic functions thread recovery relies counter complete.

6. Direct Memory

Direct Memory is not part of the virtual machine memory, nor memory region Java Virtual Machine Specification defined. jdk1.4 the NIO newly added, and the introduction of the IO buffer mode channel, it can directly call the method allocates heap Native outer memory, the external memory is native heap memory, it will not affect the size of the heap memory.
 

Guess you like

Origin www.cnblogs.com/itsharehome/p/11290907.html