First, we will briefly introduce some memory setting parameters related to JVM startup. Memory overflow occurs, which is closely related to the settings of these parameters.
Example description:
-Xss128k
The java stack size of each thread. The total size of all stack frames of a thread java stack is 128 kb at the maximum.
-Xms128m
The minimum size of JVM heap (heap memory) is 128 MB and is initially allocated.
-Xmx512m
The maximum size allowed by JVM heap (heap memory) is 256 MB, which is allocated as needed.
-XX: permsize = 20 m
Set the initial size of the Method Area
-XX: maxpermsize = 30 m
Set the maximum value of the method area.
JavaStack Overflow
1. stackoverflowerrorException
The stackoverflowerror exception occurs because the method call level is too deep, and the total size of all stack frames allocated to a thread is greater than the value set by-XSS.
2. outofmemoryerrorException
When Java program code starts a new thread, there is not enough memory space to allocate a java stack to the thread (the size of the java stack of a thread is determined by the-XSS parameter), and JVM throws an outofmemoryerror.
JavaHeap Overflow
Java heap is used to store object instances. When you need to allocate memory for the object instance, and the heap memory usage has reached the maximum value set by-xmx. An outofmemoryerror is thrown.
Method Overflow
The method area stores information about the Java type, such as the class name, access modifier, constant pool, field description, and method description. When the class loader loads the class file to the memory, the virtual opportunity extracts the type information and stores the information to the method area. When class information needs to be stored and the memory usage in the method area has reached the maximum value set by-XX: maxpermsize. An outofmemoryerror is thrown.