Common memory overflows

1) JVM Heap (heap) overflow: java.lang.OutOfMemoryError: Java heap space
The JVM will automatically set the value of the JVM Heap when it starts up, which can be set by using options such as -Xmn -Xms -Xmx provided by the JVM. The size of the Heap is the sum of Young Generation and Tenured Generation. In the JVM, if 98% of the time is used for GC, and the available Heap size is less than 2%, this exception message will be thrown.
Workaround: Manually set the size of the JVM Heap.
2) PermGen space overflow: java.lang.OutOfMemoryError: PermGen
space The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory. Why does the memory overflow? This is because this memory is mainly used by the JVM to store the Class and Meta information. The Class is put into the PermGen space area when it is loaded. It is different from the Heap area where the Instance is stored, and the GC of sun will not be in the area. The PermGen space is cleaned up when the main program is running, so if your APP loads a lot of CLASS, it is likely to overflow the PermGen space. Usually occurs during the startup phase of the program.
Solution: Set the permanent generation size through -XX:PermSize and -XX:MaxPermSize.
3) Stack overflow: java.lang.StackOverflowError : Thread Stack space
The stack overflows, and the JVM still uses a stack-based virtual machine, which is the same as C and Pascal. The calling process of the function is reflected in the stack and pop-off stack. There are so many "layers" of calling constructors that the stack overflows. Generally speaking, the general stack area is much smaller than the heap area, because the function call process is often not more than a thousand layers, and even if each function call requires 1K space (this is approximately equivalent to declaring 256 in a C function). variable of type int), then the stack area only needs 1MB of space. Usually the stack size is 1-2MB. In layman's terms, a single-threaded program requires too much memory. Usually recursion should not have too many levels of recursion, it is easy to overflow.
Solution: 1: Modify the program. 2: You can set the Stack size of each thread through -Xss:.
4. Therefore, when the Server container starts, we often care about and set several parameters of the JVM as follows (for detailed JVM parameters, please refer to Appendix 3):
-Xms: The initial size of the java Heap, the default is 1/64 of the physical memory.
-Xmx: The maximum value of ava Heap, which cannot exceed physical memory.
-Xmn: heap size of young generation, generally set to 3 or 4 of Xmx. After increasing the young generation, the size of the old generation will be reduced, which can be set reasonably according to monitoring.
-Xss: The stack size of each thread, and the best value should be 128K, the default value seems to be 512k.
-XX:PermSize: Set the initial size of the permanent storage area of ​​the memory, the default value is 64M.
-XX:MaxPermSize: Set the maximum size of the permanent storage area of ​​the memory, the default value is 64M.
-XX:SurvivorRatio: The ratio of the size of the Eden area to the Survivor area, set to 8, then the ratio of two Survivor areas to one Eden area is 2:8, and one Survivor area accounts for 1/10 of the entire young generation
-XX:+UseParallelGC: The young generation of F uses concurrent collection, while the old generation still uses serial collection.
-XX:+UseParNewGC: Set the young generation to parallel collection, JDK5.0 and above, the JVM will set it according to the system configuration, no need Set this value again.
-XX:ParallelGCThreads: The number of threads of the parallel collector, the best value is configured to be equal to the number of processors. It is also applicable to CMS.
-XX:+UseParallelOldGC: The old generation garbage collection method is Parallel Compacting.
-XX:MaxGCPauseMillis: The maximum time (maximum pause time) for each young generation garbage collection. If this time cannot be met, the JVM will automatically adjust the young generation size to meet this value.
-XX:+ScavengeBeforeFullGC: Call YGC before Full GC, the default is true.
Example: JAVA_OPTS=”-Xms4g -Xmx4g -Xmn1024m -XX:PermSize=320M -XX:MaxPermSize=320m -XX:SurvivorRatio=6″

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326450222&siteId=291194637