This is the 20th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021″

Common VM parameters (G1 collector)

parameter meaning After jdk9
-Xms Initial heap size
-Xmx / -XX:MaxHeapSize=size Maximum heap size
-Xmn Specify both the initial and maximum size of the Cenozoic
-XX:NewSize=size+ Specifies the initial Cenozoic size
-XX:MaxNewSize=size Specifies the maximum Cenozoic size
-XX:InitialSurvivorRation=ration Ratio of survival zone (dynamically adjust the ratio of survival zone to Eden)
-XX:SurvivorRation=ratio Survival zone ratio (default is 8)
-XX:MaxTenuringThreshold=threshold Promotion old age threshold
-XX:+PrintTenuringDistribution The promotion details
-XX:+PrintGCDetails -verbose:gc Viewing GC Details -Xlog:gc*
-XX:ScavengeBeforeFullGC MinorGC before FullGC
-XX:+PrintHeapAtGC View heap and method area available capacity changes before and after GC -Xlog:gc+heap=debug
-XX:+PrintGCApplicationConcurrentTime Check the concurrent time of the user thread and the pause time during GC -Xlog:safepoint
– XX: + PrintTenuring – Distribution View the age distribution of the remaining objects after collection -Xlog:gc+age=trace
  • Ratio of survivable area -xx :SurvivorRation=ratio The default value is 8. If the new generation allocates 10M memory space, 8M will be allocated to Eden, 1M from survivable area and 1M to survivable area respectively
  • The promotion details – XX: + PrintTenuringDistribution, print out the promotion information of objects
  • -xx :ScavengeBeforeFullGC MinorGC is performed before FullGC to reduce unnecessary objects and speed up the progress of FullGC. Generally, it is turned on by default.
  • To see GC details, use -xx: +PrintGCDetails before JDK 9, and -x-log: GC *, wildcard * after JDK 9 to print out all the GC subdivisions. If you lower the log level, you can get more GC information.

There are many VM parameters are not a list, these commonly used VM parameters can meet a large part of the needs

Garbage collection process

The following example demonstrates the garbage collection process and read garbage collection information

Create a class called DemoTest, add the main method, and start it

Configure DemoTest on IDEA

Add: -xms20m -xmx20m -xmn10m -xx:+ UserSerialGC -xx:+PrintGCDetails -verbose: GC to JVM add: -xms20m -XMx20m -xmn10m -xx:+ UserSerialGC -xx:+PrintGCDetails -verbose: GC +UserSerialGC, the last parameter is to print the details of the GC

When DemoTest is started, the following information will appear. This information is about the heap after the application is finished running.

Def new generation is 9M for the new generation, because we allocated 10M To the new generation, Eden is 8M by default, and the survival zone From and To is 1M, but THE JVM will always leave the survival zone To empty, so only 9M is displayed here. The information on the right side says that the used size is 3M, and finally the memory address. Note: Even the simplest JAVA program loads classes and creates objects, so Eden takes up space.

Tenured Generation An old age, 10M in size, not in use, occupying 0K of space.

Metaspace dimension, although yuan space does not belong to a pile of this part, but * * – xx: + PrintGCDetails verbose: gc ` * * print space information.