The memory management mechanism of Java
JVM Runtime Data region: program counter, Java Virtual machine stack, local method Stack, Java heap, method area, run constant pool, (direct memory)
Classification by thread sharing: Thread exclusive
1. Program counter, occupies very small space, used to maintain the correctness of the execution process during thread switching
2.Java virtual machine Stack: Java threads do not execute a method that generates a stack frame that stores information such as local variable tables, operand stacks, dynamic links, method exits, and stack frames stored in the Java Virtual machine stack. Use-XSS to control the size of the stack. There are two situations that can cause a virtual machine stack to get an error: A. Too many stack frames, error sof! For example infinite recursion (windows64 bit I measured out is 6w+ error); b. A thread is assigned a virtual machine stack if a new thread is created, and the new virtual machine stack is not assigned to Oom;
3. Local method Stack: There is no difference between the Java Virtual machine stack, but the local native method. (Sun hotspot is merging two stacks together)
Classification by thread sharing: thread sharing
1.Java Heap: Specification Description, all object instances and arrays are allocated on the heap. An Oom exception is thrown when the extensible size is now popular, controlled with-xmx and-XMS, and can no longer be extended
2. Method Area: Stores the class information, constants, static variables, and immediately compiled code data that have been loaded by the virtual machine. Use-xx:maxpermsize for size control when the memory allocation is not sufficient to throw oom. (about-xx:permsize use, I test on the JAVA8, the hint-xx:maxpermsize invalid, need to study, view the data, found that the permanent generation in Java8 no, use what meta-space. Need to learn the changes of JAVA7-JAVA8 memory model)
3. Run a constant pool: it is part of the method area and is used to store a variety of literal variables and symbolic applications. For example, a smaller int, called The Intern () method of String.
Direct memory: Not in the JVM specification, but will be used frequently, using-XMX for size control, if there is not enough space to throw Oom
Java Virtual Machine Learning Chapter II Summary