Java itself provides a rich variety of methods and tools to help developers view and analyze the state of the GC and its JVM memory, while the open source community has tools to view and analyze the status of GC and JVM memory.
With these analyses, you can troubleshoot memory leaks in programs and the performance of tuning programs.
1. Output GC Log
The output GC log is undoubtedly the most straightforward method of analyzing the state of the memory recovery for tracking the status of GC, except that the output requires human analysis to determine GC status.
The JVM supports the output of logs to the console and the specified files, as follows:
A> output to the console
Add-xx:+printgc-xx:+printgcdetails-xx:+printgctimestamps-xx:+printgcapplicationstoppedtime to the JVM's startup parameters
Output GC Summary information in the order of the parameters, GC details, GC time information, and the time that the GC caused the application to pause.
B> output to the specified file
Adding-xloggc:gc.log in the JVM startup parameter specifies that the GC's information is output to gc.log.
There are also some parameters:-VERBOSE:GC,-xx:+printtenuringdistribution and so on.
2.GC Portal
While the GC log output has a certain effect, it is quite complex to rely on human analysis. So Sun provides a GC portal to help analyze these GC logs and generate related graphical reports, the GC portal can be cumbersome to deploy, it needs to run on the older version of Tomcat and requires a database , After deployment, the GC log can be analyzed by uploading the log file, and the JVM parameters for this GC log output are:-verbose:gc-xx:+printgcdetails-xx:+printgctimestamps [-XLOGGC: File name], There are only JDK 1.2 or JDK 1.2-1.4 versions of the GC Portal option when uploading logs. Although the logs of JDK 6 can be analyzed by testing , the limitation is that only 5MB of GC log analysis is supported, and GC portal can provide throughput analysis, CPU time, the amount of time it takes to suspend the application, the number of times per second from the Cenozoic to the old generation, Minor GC status and full GC status.
3.JConsole
JConsole can graphically view the changes in memory in the JVM, JConsole is a tool that comes with JDK 5 and later, and is located in the bin directory of the JDK, running directly JConsole.exe or jconsole.sh (requires support for graphical interfaces). On the Local tab page, you see a Java-run PID, double-click to see the JVM status of the process, and Jconsole also supports viewing the health of the remote JVM, as described in Jconsole's user guide.
Jconsole shows a lot of information in the JVM: memory, threads, classes, and Mbean, and when you open Jconsole's Memory tab, you can see the health of the JVM's memory portion. This is more straightforward and jconsole to analyze whether the memory has overflow and GC effect.
4. JVISUALVM
JVISUALVM is a tool introduced after JDK 6 update 7, similar to the Jprofiler tool, which is based on this tool to view memory consumption, thread execution, and CPU and memory consumption in the program.
In memory analysis, the biggest benefit of JVISUALVM is that you can analyze GC trends and memory consumption details by installing the VISUALGC plug-in.
There are a number of tools that can be analyzed, and there's not much to say here.
Java Memory Health review methods and analysis tools