About the memory settings of the java virtual machine

1. Java divides memory into two types: one is stack memory and the other is heap memory.

2. The default space (ie -Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. If the memory remaining is less than 40%, the JVM will increase the heap to the value set by Xmx, and if the memory remaining exceeds 70%, the JVM will decrease the heap to the value set by Xms. Therefore, the Xmx and Xms settings of the server should generally be set the same to avoid adjusting the size of the virtual machine heap after each GC. Assuming that the physical memory is infinite, the maximum value of the JVM memory is related to the operating system. Generally, the 32-bit machine is between 1.5g and 3g, while the 64-bit machine has no limit.

Note: If Xms exceeds the Xmx value, or the sum of the heap maximum and non-heap maximum exceeds the physical memory or the maximum limit of the operating system, the server will not start up.

3. The other is that when the Java memory heap is insufficient, the GC will be called continuously. If the continuous recycling cannot solve the problem of insufficient memory heap, an out of memory error will be reported.

4. The basic type variables and object reference variables defined in the function are allocated in the stack memory of the function.

5. Heap memory is used to store objects and arrays created by new.

6. The advantage of the heap is that the memory size can be dynamically allocated, and the lifetime does not have to be told to the compiler in advance, because it allocates memory dynamically at runtime. The disadvantage is that the memory needs to be dynamically allocated at runtime, and the access speed is slow.

7. The advantage of the stack is that the access speed is faster than that of the heap. The disadvantage is that the size and lifetime of the data in the stack must be definite and inflexible.

8. The maximum Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same, and -Xmn is 1/4 of the -Xmx value.

9. The java heap is divided into three areas: New, Old and Permanent.

Guess you like

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