GCs Caused by System.gc()
Prerequisites
Procedure
- Perform profiling analysis on the target program.
- Switch to the GC tab page.
Invoke http://IP_address:9118/gctest/systemgc to trigger a GC event.
Figure 1 GC tab page
Figure 2 Tuning Suggestions
It is found that some GC events are caused by the calling of the System.gc() function. In this case, read the precautions for using the System.gc() function in the tuning suggestions.
- Enable the startup parameters based on the tuning suggestions.
Enable the startup parameter -XX:+ExplicitGCInvokesConcurrent.
Figure 3 Overview
Figure 4 GC tab page
It is found that the GC garbage collector caused by the System.gc() function changes from Old to Young, relieving the garbage collection pressure.
- Summarize the tuning.
Exercise caution when using the System.gc() function in the program. If the function is not used in the program and the dependent framework is not used, you can enable the -XX:+DisableExplicitGC parameter to disable the function. If the program or dependency framework needs to use this function, enable the -XX:+ExplicitGCInvokesConcurrent parameter to tune the GC mode.