JVM memory depth anatomy

1. roughly classified into the heap, the method area, local memory.
2. (1) heap is shared by the threads, the heap memory allocation (new keywords, reflection, garbage collection, etc.)
stack area there is also a method, the method area also known as the living area (which kept constant, static variables, class variables ) runtime constant pool is part of the zone method, which kept the various editing symbol period and literals. In jdk1.7, constant pool moved to the heap. After jdk1.8, remove eternal life area. Yuan method district changed to put in local memory space.
(2) the method area is private to the thread. There are java stack, native method stacks, program counter. Program counter is to record the line number for multi-thread switching resources. java stack, each thread of the life cycle and will create a stack frame for storing: the local variable table, stack frame operation, Dynamic Link, a method exports. The method corresponds to the execution stack of the virtual machine frames pushing and popping process. Native method stacks holds information native methods. When a thread calls the native method created by the JVM, jvm will not create a stack frame, but simply dynamic link and call the native method.
(3) local memory there are direct memory, main memory of the JVM running the program. For operating system calls. (MAXDridectMemerorySize)
3. the difference between heap and stack:
the stack in a manner of stack frames stored procedure call method, and stores the basic data types of the method call phase value of the variable and the object reference variable. Its memory allocated on the stack, variables out of scope will be automatically released. Heap: in java for storing objects, regardless of the member variables, local variables, or class variables, they point to objects stored in the heap memory.
Stack memory belong to a single thread, each thread will have a stack memory, its memory variables, can only be seen in their respective thread. Heap visible to the thread. Heap memory object can be accessed by all threads.
The stack size (1M) is smaller than the heap memory (1G) size. If the stack is found dead in a recursive likely stackoverflowerror appear. You can set the stack by xss, xms start of the heap size, xmx set the maximum heap size.

Guess you like

Origin blog.csdn.net/weixin_39507514/article/details/89640580