Jvm default heap size

Many times, the Java program we run does not set the heap memory limit parameter. Normally, there are two parameters to specify the initial allocated heap memory and the maximum value of the heap memory, respectively:

-Xmx is used to set the maximum amount of memory that your application (not JVM) can use (equivalent to -XX:MaxHeapSize).
-Xms is used to set the size of the memory stack when the program is initialized (equivalent to -XX:MaxNewSize).
There is also a -Xss which specifies the size of each thread's stack. In general, 256K is sufficient. This value affects the number of concurrent threads in this process (equivalent to -XX:ThreadStackSize).

Some students have to ask, if I do not set these parameters, what is the default value?
Generally speaking, in terms of JDK8:

The default value of -Xmx is 1/4 of the maximum memory of your current machine
-The default value of Xms is 1/64 of the maximum memory of your current machine (this value needs to be tested repeatedly and adjusted to a suitable value through monitoring, because when Heap is not enough When it is used, memory jitter will occur, which will affect the stability of the program
. The default value of -Xss seems to be platform-dependent (different platforms have different default values). The default value of our most commonly used Linux64-bit server seems to be 1024k (I am not sure about this). Under the same physical memory, reducing this value can generate more threads. This parameter has a more obvious impact on performance in the case of high concurrency. It takes a long time to conduct rigorous testing to define a suitable value (if the stack If the depth is not 128k, 256k is recommended for large applications).

For the initial value and maximum value of the heap, you can use the following command to view:

在Windows里:
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
在Linux里:
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'

在Windows里:
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
在Linux里:
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'

Example entry The following is an example of starting a Java program:

java
    -Xms64m #JVM启动时的初始堆大小
    -Xmx128m #最大堆大小
    -Xmn64m #年轻代的大小,其余的空间是老年代
    -XX:MaxMetaspaceSize=128m #
    -XX:CompressedClassSpaceSize=64m #使用 -XX:CompressedClassSpaceSize 设置为压缩类空间保留的最大内存。
    -Xss256k #线程
    -XX:InitialCodeCacheSize=4m #
    -XX:ReservedCodeCacheSize=8m # 这是由 JIT(即时)编译器编译为本地代码的本机代码(如JNI)或 Java 方法的空间
    -XX:MaxDirectMemorySize=16m
    -jar app.jar

Guess you like

Origin blog.csdn.net/liyang_nash/article/details/108244097