Java GC Type
What are the different types of GC in Java?
Parameters |
Describe |
Useserialgc |
The virtual machine runs the default value in client mode, and when this switch parameter is turned on, Use the serial+serial old collector combination for garbage collection. |
Useparnewgc |
After you turn on this switch parameter, use the parnew+serial old collector combination for garbage collection. |
Useconcmarksweepgc |
After you turn on this switch parameter, use the parnew+cms+serial old collector combination for garbage collection. Serial old as a CMS collector appears concurrent Mode failure's backup garbage collector. |
Useparallelgc |
The virtual machine runs the default value in Server mode, and after you turn on this switch parameter, use the parallel scavenge+serial old collector combination for garbage collection. |
Useparalleloldgc |
After you turn on this switch parameter, use the Parallel scavenge+parallel old collector combination for garbage collection. |
After the Java program starts, query to the currently running Java process through the JPS observation process, using the
Java code
- Jinfo–flag USESERIALGC Process
The way you can locate the GC policy that it uses, because these parameters are Boolean constants, and if you use that kind of GC policy, the + sign will appear, otherwise-No.
Use-xx:+ the GC policy above to enable the corresponding GC policy.
GC Log View
Policies such as specifying the corresponding GC type, printing GC log information, and outputting to a file can be specified by adding parameters in the Java command type.
The GC's log is written in a replacement (>) instead of append (>>), and the previous GC content is emptied if it is written to the same file the next time.
The corresponding parameter list
Java code
- -XX:+PRINTGC Output GC Log
- -xx:+printgcdetails verbose log of output GC
- -xx:+printgctimestamps timestamp of output GC (in the form of base time)
- -xx:+printgcdatestamps the timestamp of the output GC (in the form of a date, such as 2013-05-04t21:59.234+0800)
- -XX:+PRINTHEAPATGC to print out heaps of information before and after GC
- -XLOGGC:.. /logs/gc.log the output path of the log file
The following parameters are used to print the log:
Java code
- -xx:+printgcdatestamps-xx:+printgcdetails-xloggc:./gclogs
For a new generation of recycled logs, the basic content is as follows:
Java code
- 2014-07-18t16:17.606+0800: 611.633: [GC 611.633: [Defnew:843458k->2k (948864K), 0.0059180 secs] 2186589k->1343132k (3057292K), 0.0059490 secs] [times:user=0.00 sys=0.00, Real= 0.00 secs]
The meaning of this is probably as follows:
Java code
- 2014-07-18t16:17.606+0800 (current timestamp): 611.633 (timestamp): [GC (indicates young GC) 611.633: [ Defnew (single thread serial Young generation GC): 843458K (size before the young Generation garbage collection)->2k (size of the young generation Recycled) (948864K (total size of young generation)), 0.0059180 secs (Time of this recovery)] 2186589K (the size before the entire heap is reclaimed)->1343132k (the size of the entire heap) (3057292K (total heap size)), 0.0059490 secs (reclaim time)] [times:user= 0.00 (User Time) sys=0.00 (System time), Real=0.00 secs (actual time consuming)]
The old age recycling log is as follows:
Java code
- 2014-07-18t16:16.794+0800: 1630.821: [GC 1630.821: [defnew:1005567k->111679k ( 1005568K), 0.9152360 secs]1631.736: [tenured:
- 2573912k->1340650k (2574068K), 1.8511050 secs] 3122548k->1340650k (3579636K), [Perm:17882k->17882k ( 21248K)], 2.7854350 secs] [times:user=2.57 sys=0.22, real=2.79 secs]
The last of the GC logs looks like a snapshot of the system before it finishes running:
Java code
- Heap
- def New Generation total 1005568K, used 111158K [0x00000006fae00000, 0x000000073f110000, 0x000000075035 0000)
- Eden Space 893888K, 12% used [0x00000006fae00000, 0x0000000701710e90, 0x00000007316f0000)
- From Space 111680K, 3% used [0x0000000738400000, 0x000000073877c9b0, 0x000000073f110000)
- To space 111680K, 0% used [0x00000007316f0000, 0x00000007316f0000, 0x0000000738400000)
- Tenured generation total 2234420K, used 1347671K [0x0000000750350000, 0x00000007d895d000, 0x00000007fae00000)
- The space 2234420K, 60% used [0x0000000750350000, 0x00000007a2765cb8, 0x00000007a2765e00, 0x00000007d895d000)
- Compacting Perm Gen Total 21248K, used 17994K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000) /c3>
- The space 21248K, 84% used [0x00000007fae00000, 0x00000007fbf92a50, 0x00000007fbf92c00, 0x00000007fc2c0000)
- No shared spaces configured.
Offline analysis of GC logs
You can use some offline tools to analyze GC logs, such as Sun's Gchisto (Https://java.net/projects/gchisto), Gcviewer (https://github.com/chewiebug/ Gcviewer), these are open source tools that allow users to download their source code directly from the version control tool for offline analysis
Java GC Log View