1. Prepare GC logs

-xx :+PrintGC prints GC logs -xx :+PrintGCDetails Prints GC logs -xx :+PrintGCTimeStamps Prints GC timestamps (in the form of baseline time) -xx :+PrintGCDateStamps -xx :+PrintHeapAtGC Prints heap information before and after GC -Xloggc:.. /logs/gc.log Output path of the log fileCopy the code

2. Young GENERATION GC logs

2019-09-17T23:12:05.334+ 0800:6950.220: [gC2019-09-17T23:12:05.334 + 0800:6950.220: [ParNew: 2019-09-17T23:12:05.334+ 0800:6950.220: 1713371K->30726K(1887488K), secs] 1910235K->227695K(6081792K), secs] [Times: User sys = = 0.12 0.01, real = 0.04 secsCopy the code

3. CMS GC logs

2019-09-17T21:19:48.213+ 0800:213.099: [GC [1 CMS-initial-mark: Secs] [Times: Times: 3194304K] 319922K (6081792K), 0.0269660 secs] [Times: 3194304K] 319922k (6081792K), 0.0269660 secs] Sys =0.00, real= 0.05secs] 2019-09-17t21:48.240 + 0800/213.126: [cmS-concurrent-mark-start] 2019-09-17T21:19:48.499+ 0800:213.385:[Times: 2019-09-17T21:19:48.499+ 0800:213.385:] [Times: 2019-09-17T21:19:48.499+ 0800:213.385:] 2019-09-17T21:48.499 + 0800:213.385: [CMS - concurrent - preclean - start] 2019-09-17 T21: this. 508 + 0800:213.394: [CMS - concurrent - preclean: [Times: user= 0.03sec = 0.03sec, real= 0.03secs] 2019-09-17T21:419.509 + 0805:419.589: [CMS - concurrent - abortable - preclean - start] 2019-09-17 T21: timnathserah. 125 + 0800:215.011: [CMS - concurrent - abortable - preclean: [Times: user=3.28 sys= 3.62, real= 3.62] 2019-09-17t21:19:50.99 + 08000:615.011: [GC[YG occupancy:] [Times: user= 3.62, real= 3.62] 2019-09-17t21:50.99 + 08000:615.011: [GC[YG occupancy:] 1065145K (188745k)] 2019-09-17T21:519.125 + 0800:215.011: [Rescan (PARALLEL), 0.1963400 SECs] 2019-09-17T21:50.321 + 0800:215.207: [Rescan (Parallel), 0.1963400 secs] 2019-09-17T21:50.321 + 0800:215.207: [weak refs processing, 0.0003260 secs]2019-09-17T21:19:50.322+ 0800:215.208: [class class] brown brown brown brown brown brown brown brown brown brown brown brown brown [Scrub symbol table, 0.0894820 secs]2019-09-17T21:19:50.438+ 08000:215.324: Scrub scrub [Scrub string table, 0.0028500 secs] [1 CMS-remark: 2136781K(4194304K)] 3201926K(6081792K), 0.3199900 secs] [Times: scrub scrub 2019-09-17T21:50.445 + 0800:215.331: [cmS-concurrent-start] 2019-09-17T21:19:51.334+ 0800:216.220: [CMS-concurrent-start: 0.888/0.889secs] [Times: 2019-09-17T21:19:51.334+ 0800:216.220: [cms-concurrent-reset-start] 2019-09-17T21:19:51.378+ 0800:216.264: [cms-concurrent-reset: 0.044/0.044secs] [Times: 2019-09-17T21:19:51.378+ 0800:216.264: [cms-concurrent-reset: 0.044/0.044secs] User sys = = 0.09 0.04, real = 0.04 secs]Copy the code

4. CMS GC 7 phase analysis

1. Initial tag

This is one of two CMS stop-the-Wolrd events. The goal of this phase is to mark all objects that are referenced directly by GC root or by young generation survivable objects, as shown in the following example:

2. Concurrent markup

At this stage the Garbage Collector traverses the ages and then marks all surviving objects, which it traverses based on the GC Roots found in the previous stage. Concurrent marking phase, which runs concurrently with the user’s application. Not all surviving objects of the old age are marked, as the user’s program may change some references during marking, as shown below:

3. Concurrent pre-clearing

Concurrent Preclean: This is also a Concurrent phase, running concurrently with the application threads without stopping the application threads. Some object references may change during concurrent running, but when this happens, the JVM marks the area (Card) containing the object as Dirty, which is Card Marking. As shown below:In the pre-clean phase, objects that can be reached from Dirty objects are also marked. Once marked, the Dirty card tag is cleared, as follows:

4. Concurrent precleaning can be terminated

This is also a concurrent phase, but again does not affect the application threads that affect the user, and this phase is intended to do as much as possible of the final tagging phase in STW (Stop-the-world). The duration of this phase depends on a number of factors. Since many of the same tasks are repeated in this phase, some conditions are directly met (such as the number of iterations, the amount of work completed or the clock time, etc.).

5. Re-mark

This is the second STW phase, and the last one in the CMS. The goal of this phase is to mark all live objects of all ages. Since the previous phase was executed concurrently, the GC thread might not be able to keep up with the changes in the application, the STW is necessary to accomplish this goal. Usually, the Final Remark phase of CMS will be run when the young generation is as clean as possible, in order to reduce the possibility of continuous STW (if there are too many living objects in the young generation, there will be too many living objects involved in the old generation). This stage will be a little more complicated than the previous ones

6. Concurrent markup

There is no need for STW, which runs concurrently with the user’s application. This phase is to clean up objects that are no longer used and reclaim their space for future use. As shown below:

7. Concurrent resets

This phase, also executed concurrently, resets the data structures inside the CMS in preparation for the next GC