Summary of JVM memory knowledge points

1. Memory and data area
The memory managed by JAVA is divided into different data areas, and these data areas have different life cycles for different purposes. Some areas will always exist after the process is started, and some will be created or destroyed with the thread.
Two, JVM has five important data areas

name Whether to share OutOfMemoryError StackOverflowError Features Remarks
Program counter X X X Bytecode line number indicator If the local method is executed, the count value is empty
JAVA virtual machine stack X Used to store information such as local variable table, operand stack, dynamic link, method exit, etc. The so-called java stack generally refers to the java virtual machine stack or local variable table
Native method stack X Serve the native method (native)
Method area X Store type information, constants, static variables, and code cache after just-in-time compilation that have been loaded by the virtual machine
heap X Store instantiation data The main object of GC recycling

3. Objects and space
There are two ways to allocate space for new objects:

method alias Applicable scene GC algorithm GC method
Bump the pointer Pointer collision JAVA heap memory is absolutely regular Compact compression Serial / ParNew
Free list Free list JAVA heap memory canine teeth Sweep CMS

Two ways of object access positioning

interview method JAVA heap Method area
Handle access Handle pool: pointer to object instance data + pointer to object type data instance pool: object instance data Object type data
Direct pointer Pointer to object type data + object instance data Object type data

Four, OutOfMemoryError abnormal location

Overflow area Abnormal characteristics Possible Causes solution
Java heap Java heap space Memory leak, memory overflow leak: View the reference chain of the leaked object to the GC Roots, so as to locate the creation location of the object that cannot be recycled. overflow: Expand the heap
Virtual machine stack, local method stack unable to create native thread Too many threads Reduce the number of threads or reduce the stack memory
Method area PermGen jdk version Upgrade version to 1.8, go to permanent generation

Guess you like

Origin blog.csdn.net/weixin_44159662/article/details/107755611