+ Java virtual machine memory model

A, java virtual machine memory model is the basis java program running, in order to make java application running, the JVM memory into which the virtual machine program counter, stack virtual machine, native method stacks, heap and method area java.

A program counter for storing an operation of the next instruction;

VM stack and native method stacks used for function call stack;

java stack used to store the desired object java program is running;

Method zone class metadata for program storage information.

094105d11fgjcoq28jm52w.png.thumb.jpg

1, the program counter, a very small memory space. Since the java language support thread, when the number of threads exceeds the number of CPU, CPU resources between threads polling snatch according to time slices. Each thread must use a separate program counter, a record for the next instruction to be run. Each thread counter independently of each other, work independently. It is a piece of thread private memory space. (Java bytecode address if the current thread is executing a java method, the program counter recording is being performed, if the current thread Native method being executed, the program counter is empty)

2, java virtual machine stack, a thread private memory space, and it is at the same time create a java thread that holds the local variables of the method, partial results and participate in the call and return method. If a thread stack depth calculation process, the maximum stack depth is greater than the requests available, a StackOverflowError is thrown, if dynamic java stack may expand, and in the process expanded in the stack, there is not enough memory space to support the expansion of the stack, the Throws OutOfMemoryError.

3, native method stacks, and the java virtual machine stack of similar functions, java virtual machine java stack for call management functions, and call the local method for managing the native method stacks. Local method is not implemented with java, but using c achieve. SUN Hot Spot in the virtual machine, and does not distinguish between native method stacks VM stack. Therefore, the virtual machine and the same stack, can also throw StackOverflowError and OutOfMemoryError.

4, java heap, java heap memory is one of the largest blocks of virtual machine management is an area shared by all threads, created when the virtual machine starts. The sole purpose of this memory area is stored object instance. From the perspective of the memory recovery, due to current collector basically uses generational collection algorithm, can be subdivided into further java heap, year old and the new generation, the new generation may be divided, Eden space, From Survivor space and To Survivor space. java file may be in a discontinuous physical memory space, as long as continuous logical can. And may support the expansion to achieve control (by -Xmx and -Xms).

5. A method as java heap region, the thread is shared memory area, the type of information stored main classes, constant pool, field information, the information method. Full Name Type information includes a class, the full name of the parent class, type modifier (public, protected, private) and type of direct interface class table; constant constant pool information includes information class methods, fields, etc. referenced; domain information including the domain name, the domain type and range modifiers; method information includes method name, return type, method parameters, the method modifier, method bytecode, operand stack and local variable stack frame method area, and the size of the exception table. In short, the method of keeping information area, mostly from the class file is java applications running indispensable data. But the permanent generation of implementation zone with, will be more prone to problems of memory overflow occurs, therefore, for the HotSpot virtual machine, the official publication of the road map information, but now they have to give up permanent generations and gradually replaced by the use of Native Memory to implement planning methods area of . JDK1.7's HotSpot has been originally placed in the permanent generation string constant pool removed.

The total number of articles from the public, Guangzhou dark horse programmer Center (itheimagz) more resources, please visit

image.png

Guess you like

Origin blog.51cto.com/14360146/2429184