preface
Let me share a few of the JVM’s overlooked issues that I hope will help you
Which areas will appear in OOM?
The Java heap overflow
- We know that the JVM parameter configuration
-Xms
saidJVM
Memory allocated at startup,-Xmx
saidJVM
Maximum available memory during running. - OOM occurs when the number of object instances exceeds the maximum heap allocation limit.
Stack overflow
- Stack memory capacity parameter by
-Xss
The stack memory depends onThe number of stack frames, i.e. the stack depth, as well asSize of each stack frame. - Virtual machine stack common
2
Species anomaly classificationOOM
As well asStackOverflowError
So, depending on what circumstances, the corresponding exception will be thrown?
Depending on whether the stack memory supports scaling, the HotSpot VIRTUAL machine does not
- Due to the
HotSpot
The VIRTUAL machine does not support scaling, thereforeOOM
Occurs when a thread is created because it cannot get enough memoryOOM
Out of memory when creating thread, cha-chaThe reason may be that the stack allocation setting for each thread is too largeOccurs under the influence of the operating system memory usage state. - For example, recursive calls cause the stack to be too deep and define a large number of local variables to increase the length of the local variable table in the stack frame beyond
-Xss
The amount of stack memory determined is thrownStackOverflowError
.
Method area and runtime constant pool overflow
The relationship between method areas and constant pools?
- The runtime constant pool is part of the method area
- The method area stores type information that has been loaded by the virtual machine, constants, static variables, just-in-time compiler compiled code caches, and so on.
- Runtime constant pool: Table of constant pools used to hold various literal and symbolic references generated at compile time. The runtime can also put new constants into the pool, for example
String: : intern ()
)
Method area == permanent generation?
- It can be said that the HotSpot VIRTUAL machine uses persistent generation to implement method areas, and the two are not equivalent.
- HotSpot in JDK 7 puts the original string constant pool in the persistent generation
String: : intern ()
, static variables, etc. moved out of the heap memory; JDK8 abandons the permanent generation entirely in favor of the local memory metspace (the type information is also moved into the metspace).
Return to the chase
- So if you use
String: : intern ()
To create the method area and constant poolOOM
1. JDK6 or earlier: string constant pool size increases, causing permanent generation memory size to exceed -xx :MaxPermSize, causing PermGen space to appear in OOM. 2, starting with JDK7, the String constant pool is moved to the Java heap, using String:: Intern () to declare OOM is also the Java heap space
CGLib generates a large number of classes to populate the method area, manufacturedOOM
- 1. JDK7 appears
PermGen space
appearOOM
- 2. JDK8 appears
Java heap space
What does GC Roots stand for?
- Objects referenced in the virtual machine stack, parameters, local variables, and temporary variables used in methods called by individual threads.
- Method area the object referenced by the static property of the class.
- An object referenced by a method area constant, such as a reference to a string constant pool.
- Internal Java virtual machine references, Class objects, exception objects, system Class loaders.
- Synchronized objects held by a lock.
reference
- Stackoverflow.com/questions/3…
- Deep Into the JVM (version 3)
- Russxia.com/2018/02/08/…