主頁 > 後端開發 > 4種GC日志解讀和分析

4種GC日志解讀和分析

2021-02-25 11:26:18 後端開發

4種GC日志解讀和分析

目標

  • 并行GC演示和分析
  • 串行GC演示和分析
  • CMSGC演示和分析
  • G1GC演示和分析
  • GC 如何選擇

如下是模擬記憶體溢位的Java代碼

案例代碼存在生產垃圾物件,當垃圾物件超過最大堆記憶體時,就造成記憶體溢位

import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
/*
演示GC日志生成與解讀
*/
public class GCLogAnalysis {
    private static Random random = new Random();
    public static void main(String[] args) {
        // 當前毫秒時間戳
        long startMillis = System.currentTimeMillis();
        // 持續運行毫秒數; 可根據需要進行修改
        long timeoutMillis = TimeUnit.SECONDS.toMillis(1);
        // 結束時間戳
        long endMillis = startMillis + timeoutMillis;
        LongAdder counter = new LongAdder();
        System.out.println("正在執行...");
        // 快取一部分物件; 進入老年代
        int cacheSize = 2000;
        Object[] cachedGarbage = new Object[cacheSize];
        // 在此時間范圍內,持續回圈
        while (System.currentTimeMillis() < endMillis) {
            // 生成垃圾物件
            Object garbage = generateGarbage(100*1024);
            counter.increment();
            int randomIndex = random.nextInt(2 * cacheSize);
            if (randomIndex < cacheSize) {
                cachedGarbage[randomIndex] = garbage;
            }
        }
        System.out.println("執行結束!共生成物件次數:" + counter.longValue());
    }

    // 生成物件
    private static Object generateGarbage(int max) {
        int randomSize = random.nextInt(max);
        int type = randomSize % 4;
        Object result = null;
        switch (type) {
            case 0:
                result = new int[randomSize];
                break;
            case 1:
                result = new byte[randomSize];
                break;
            case 2:
                result = new double[randomSize];
                break;
            default:
                StringBuilder builder = new StringBuilder();
                String randomString = "randomString-Anything";
                while (builder.length() < randomSize) {
                    builder.append(randomString);
                    builder.append(max);
                    builder.append(randomSize);
                }
                result = builder.toString();
                break;
        }
        return result;
    }
}

演示GC日志生成與解讀

  • 當時在win下編譯的,需要加引數-encoding UTF-8,linux不需要 (win默認使用GBDK字符,如果檔案是UTF-8不能編譯)

D:\F盤\JavaCourseCodes\01jvm>javac -encoding UTF-8 GCLogAnalysis.java

  • 執行GCLogAnalysis檔案,列印的GC日志生產到當前目錄下demo.log

D:\F盤\JavaCourseCodes\01jvm>java -Xloggc:gc.demo.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps
-XX:MaxHeapSize=4244185088,如果沒有設定最大堆記憶體,默認是服務器的最大記憶體的1/4大小 ,默認采用UseParallelGC 并行GC

Java HotSpot(TM) 64-Bit Server VM (25.201-b09) for windows-amd64 JRE (1.8.0_201-b09), built on Dec 15 2018 18:36:39 by "java_re" with MS VC++ 10.0 (VS2010)
Memory: 4k page, physical 16578848k(2260340k free), swap 30350536k(4206764k free)
CommandLine flags: -XX:InitialHeapSize=265261568 -XX:MaxHeapSize=4244185088 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
//-XX:MaxHeapSize=4244185088,如果沒有設定最大堆記憶體,默認是服務器的最大記憶體的1/4大小 ,默認采用UseParallelGC 并行GC

2021-02-23T07:34:15.501+0800: 0.274: [GC (Allocation Failure) [PSYoungGen: 65024K->10747K(75776K)] 65024K->23007K(249344K), 0.0072693 secs] [Times: user=0.03 sys=0.08, real=0.01 secs] 
//65024K->10747K(75776K)] 65024K->23007K(249344K), 0.0072693 secs] :young區從65M >10M,Old區從65M > 23M  ,old區減到23M,說明此時部分物件從young提升到old區
//Times: user=0.03   用戶執行緒耗時  sys=0.08   系統耗時, real=0.01 secs STW暫停時間
2021-02-23T07:34:15.531+0800: 0.304: [GC (Allocation Failure) [PSYoungGen: 75204K->10744K(140800K)] 87463K->42977K(314368K), 0.0097131 secs] [Times: user=0.03 sys=0.05, real=0.01 secs] 
2021-02-23T07:34:15.610+0800: 0.382: [GC (Allocation Failure) [PSYoungGen: 140564K->10747K(140800K)] 172797K->88342K(314368K), 0.0153475 secs] [Times: user=0.03 sys=0.08, real=0.02 secs] 
2021-02-23T07:34:15.664+0800: 0.436: [GC (Allocation Failure) [PSYoungGen: 140795K->10749K(270848K)] 218390K->127729K(444416K), 0.0157620 secs] [Times: user=0.02 sys=0.08, real=0.02 secs] 
2021-02-23T07:34:15.810+0800: 0.583: [GC (Allocation Failure) [PSYoungGen: 270845K->10747K(270848K)] 387825K->204045K(465408K), 0.0291165 secs] [Times: user=0.03 sys=0.19, real=0.03 secs] 
2021-02-23T07:34:15.839+0800: 0.612: [Full GC (Ergonomics) [PSYoungGen: 10747K->0K(270848K)] [ParOldGen: 193297K->170244K(330240K)] 204045K->170244K(601088K), [Metaspace: 2628K->2628K(1056768K)], 0.0301415 secs] [Times: user=0.16 sys=0.00, real=0.03 secs] 
//經過五次youngGC(每次GC耗時遞增),old區越來越大,此時進行fullGC一次,, 0.0301415 secs對比youngGC,fullGC耗時非常多
//fungGC時,young區直接減到0,old區從193M > 170M
2021-02-23T07:34:15.941+0800: 0.713: [GC (Allocation Failure) [PSYoungGen: 260096K->78120K(546816K)] 430340K->248364K(877056K), 0.0249608 secs] [Times: user=0.02 sys=0.06, real=0.03 secs] 
2021-02-23T07:34:16.189+0800: 0.961: [GC (Allocation Failure) [PSYoungGen: 546600K->101880K(588800K)] 716844K->353984K(919040K), 0.0510303 secs] [Times: user=0.11 sys=0.22, real=0.05 secs] 
2021-02-23T07:34:16.240+0800: 1.013: [Full GC (Ergonomics) [PSYoungGen: 101880K->0K(588800K)] [ParOldGen: 252103K->266559K(460800K)] 353984K->266559K(1049600K), [Metaspace: 2628K->2628K(1056768K)], 0.0374054 secs] [Times: user=0.20 sys=0.00, real=0.04 secs] 
2021-02-23T07:34:16.398+0800: 1.171: [GC (Allocation Failure) [PSYoungGen: 486345K->142934K(982016K)] 752905K->409493K(1442816K), 0.0431602 secs] [Times: user=0.05 sys=0.22, real=0.04 secs] 
Heap
 PSYoungGen      total 982016K, used 176414K [0x000000076bb00000, 0x00000007b5680000, 0x00000007c0000000)
  eden space 821760K, 4% used [0x000000076bb00000,0x000000076dbb2160,0x000000079dd80000)
  from space 160256K, 89% used [0x00000007a8e00000,0x00000007b1995908,0x00000007b2a80000)
  to   space 180736K, 0% used [0x000000079dd80000,0x000000079dd80000,0x00000007a8e00000)
 ParOldGen       total 460800K, used 266559K [0x00000006c3000000, 0x00000006df200000, 0x000000076bb00000)
  object space 460800K, 57% used [0x00000006c3000000,0x00000006d344fda0,0x00000006df200000)
 Metaspace       used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 291K, capacity 386K, committed 512K, reserved 1048576K

執行結束!共生成物件次數:8885

  • 設定初始最小和最大對大小一樣時,

共生成物件次數:12035,性能對沒有設定初始化最小堆時提升39%,解讀:Xms設定與-Xmx相同,以避免每次垃圾回收完成后JVM重新分配記憶體

D:\F盤\JavaCourseCodes\01jvm>java  -Xms4g -Xmx4g  -XX:+PrintGCDetails -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-24T06:48:52.516+0800: [GC (Allocation Failure) [PSYoungGen: 1048576K->174589K(1223168K)] 1048576K->235252K(4019712K), 0.0441413 secs] [Times: user=0.02 sys=0.20, real=0.04 secs]
2021-02-24T06:48:52.718+0800: [GC (Allocation Failure) [PSYoungGen: 1223165K->174591K(1223168K)] 1283828K->357504K(4019712K), 0.1024186 secs] [Times: user=0.23 sys=0.52, real=0.10 secs]
2021-02-24T06:48:52.978+0800: [GC (Allocation Failure) [PSYoungGen: 1223167K->174577K(1223168K)] 1406080K->473105K(4019712K), 0.4661695 secs] [Times: user=0.27 sys=2.50, real=0.47 secs]
執行結束!共生成物件次數:12035
Heap
 PSYoungGen      total 1223168K, used 216650K [0x000000076ab00000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 1048576K, 4% used [0x000000076ab00000,0x000000076d416238,0x00000007aab00000)
  from space 174592K, 99% used [0x00000007aab00000,0x00000007b557c750,0x00000007b5580000)
  to   space 174592K, 0% used [0x00000007b5580000,0x00000007b5580000,0x00000007c0000000)
 ParOldGen       total 2796544K, used 298527K [0x00000006c0000000, 0x000000076ab00000, 0x000000076ab00000)
  object space 2796544K, 10% used [0x00000006c0000000,0x00000006d2387f40,0x000000076ab00000)
 Metaspace       used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 291K, capacity 386K, committed 512K, reserved 1048576K

D:\F盤\JavaCourseCodes\01jvm>
  • 圖解說明并行GC的記憶體變化
    在這里插入圖片描述

每次youngGC,young區空間減少很多,Eden和S0全部清空,部分物件復制到S1區,old區越來越大,然后進行fullGC,下一次youngGC會把Eden和S1清空 ,

延伸問題:年輕代和老年代的垃圾回收都會觸發STW 事件,在年輕代使用標記-復制(mark-copy)演算法,在老年代使用標記-清除-整理(mark-sweepcompact)演算法,-XX:ParallelGCThreads=N 來指定GC 執行緒數, 其默認值為CPU 核心數,

fullGC,會把Eden ,S0,S1區全部清空
默認yungGC次數15次,超過15次還存活的物件采用移動方式晉升到老年代區,老年代能減少些但不多

串行GC演示( -XX:+UseSerialGC)

  • 當前最大堆記憶體512M
D:\F盤\JavaCourseCodes\01jvm>java -XX:+UseSerialGC -Xms512m -Xmx512m  -XX:+PrintGCDetails -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-23T22:35:13.453+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.453+0800: [DefNew: 139776K->17472K(157248K), 0.0324775 secs] 139776K->48832K(506816K), 0.0330806 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
2021-02-23T22:35:13.521+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.521+0800: [DefNew: 157127K->17471K(157248K), 0.0427665 secs] 188488K->98605K(506816K), 0.0434445 secs] [Times: user=0.03 sys=0.00, real=0.04 secs]
2021-02-23T22:35:13.607+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.608+0800: [DefNew: 157247K->17471K(157248K), 0.0323721 secs] 238381K->140525K(506816K), 0.0331904 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
2021-02-23T22:35:13.682+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.682+0800: [DefNew: 157247K->17471K(157248K), 0.0337171 secs] 280301K->184841K(506816K), 0.0344639 secs] [Times: user=0.02 sys=0.01, real=0.03 secs]
2021-02-23T22:35:13.757+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.758+0800: [DefNew: 156573K->17472K(157248K), 0.0318421 secs] 323942K->226784K(506816K), 0.0327063 secs] [Times: user=0.01 sys=0.02, real=0.03 secs]
2021-02-23T22:35:13.831+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.832+0800: [DefNew: 157248K->17471K(157248K), 0.0357931 secs] 366560K->273563K(506816K), 0.0364656 secs] [Times: user=0.02 sys=0.02, real=0.04 secs]
2021-02-23T22:35:13.909+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.910+0800: [DefNew: 157098K->17471K(157248K), 0.0321501 secs] 413190K->312630K(506816K), 0.0330849 secs] [Times: user=0.02 sys=0.02, real=0.03 secs]
2021-02-23T22:35:13.981+0800: [GC (Allocation Failure) 2021-02-23T22:35:13.981+0800: [DefNew: 157247K->17470K(157248K), 0.0342253 secs] 452406K->354246K(506816K), 0.0349803 secs] [Times: user=0.02 sys=0.02, real=0.04 secs]
2021-02-23T22:35:14.053+0800: [GC (Allocation Failure) 2021-02-23T22:35:14.054+0800: [DefNew: 157246K->157246K(157248K), 0.0002210 secs]2021-02-23T22:35:14.054+0800: [Tenured: 336776K->273961K(349568K), 0.0635833 secs] 494022K->273961K(506816K), [Metaspace: 2628K->2628K(1056768K)], 0.0645362 secs] [Times: user=0.06 sys=0.00, real=0.07 secs]
2021-02-23T22:35:14.155+0800: [GC (Allocation Failure) 2021-02-23T22:35:14.155+0800: [DefNew: 139776K->17471K(157248K), 0.0137345 secs] 413737K->324486K(506816K), 0.0144490 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
2021-02-23T22:35:14.207+0800: [GC (Allocation Failure) 2021-02-23T22:35:14.207+0800: [DefNew: 157247K->157247K(157248K), 0.0002225 secs]2021-02-23T22:35:14.207+0800: [Tenured: 307014K->301297K(349568K), 0.0715632 secs] 464262K->301297K(506816K), [Metaspace: 2628K->2628K(1056768K)], 0.0724522 secs] [Times: user=0.06 sys=0.00, real=0.07 secs]
執行結束!共生成物件次數:6288
Heap
 def new generation   total 157248K, used 126441K [0x00000000e0000000, 0x00000000eaaa0000, 0x00000000eaaa0000)
  eden space 139776K,  90% used [0x00000000e0000000, 0x00000000e7b7a608, 0x00000000e8880000)
  from space 17472K,   0% used [0x00000000e9990000, 0x00000000e9990000, 0x00000000eaaa0000)
  to   space 17472K,   0% used [0x00000000e8880000, 0x00000000e8880000, 0x00000000e9990000)
 tenured generation   total 349568K, used 301297K [0x00000000eaaa0000, 0x0000000100000000, 0x0000000100000000)
   the space 349568K,  86% used [0x00000000eaaa0000, 0x00000000fd0dc620, 0x00000000fd0dc800, 0x0000000100000000)
 Metaspace       used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 291K, capacity 386K, committed 512K, reserved 1048576K

D:\F盤\JavaCourseCodes\01jvm>
  • 當前最大堆記憶體128M時,出現記憶體溢位例外了

fullGC對垃圾回收幾乎沒有作用,垃圾一直占的記憶體空間

D:\F盤\JavaCourseCodes\01jvm>java -XX:+UseSerialGC -Xms128m -Xmx128m  -XX:+PrintGCDetails -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-23T22:42:07.153+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.154+0800: [DefNew: 34915K->4351K(39296K), 0.0105513 secs] 34915K->12378K(126720K), 0.0115875 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.182+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.182+0800: [DefNew: 39197K->4349K(39296K), 0.0123236 secs] 47223K->22965K(126720K), 0.0138073 secs] [Times: user=0.00 sys=0.02, real=0.01 secs]
2021-02-23T22:42:07.213+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.214+0800: [DefNew: 38618K->4343K(39296K), 0.0091259 secs] 57234K->33897K(126720K), 0.0100570 secs] [Times: user=0.01 sys=0.02, real=0.01 secs]
2021-02-23T22:42:07.237+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.238+0800: [DefNew: 39146K->4351K(39296K), 0.0104840 secs] 68701K->45751K(126720K), 0.0111278 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.265+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.266+0800: [DefNew: 38929K->4338K(39296K), 0.0086908 secs] 80329K->55306K(126720K), 0.0096184 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.288+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.288+0800: [DefNew: 39269K->4348K(39296K), 0.0137101 secs] 90238K->68836K(126720K), 0.0144757 secs] [Times: user=0.00 sys=0.02, real=0.01 secs]
2021-02-23T22:42:07.313+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.313+0800: [DefNew: 39292K->4349K(39296K), 0.0142091 secs] 103780K->83540K(126720K), 0.0150465 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
2021-02-23T22:42:07.344+0800: [GC (Allocation Failure) 2021-02-23T22:42:07.350+0800: [DefNew: 39008K->39008K(39296K), 0.0011520 secs]2021-02-23T22:42:07.352+0800: [Tenured: 79190K->87419K(87424K), 0.0237885 secs] 118199K->90743K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0361671 secs] [Times: user=0.02 sys=0.00, real=0.04 secs]
2021-02-23T22:42:07.394+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.396+0800: [Tenured: 87419K->87397K(87424K), 0.0191946 secs] 126695K->99685K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0212197 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
2021-02-23T22:42:07.429+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.429+0800: [Tenured: 87397K->87232K(87424K), 0.0221254 secs] 126683K->106532K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0232227 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]
2021-02-23T22:42:07.462+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.463+0800: [Tenured: 87304K->87268K(87424K), 0.0306981 secs] 126540K->108960K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0328040 secs] [Times: user=0.03 sys=0.00, real=0.03 secs]
2021-02-23T22:42:07.504+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.506+0800: [Tenured: 87268K->87268K(87424K), 0.0079315 secs] 126362K->113405K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0106992 secs] [Times: user=0.00 sys=0.02, real=0.01 secs]
2021-02-23T22:42:07.520+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.529+0800: [Tenured: 87268K->87268K(87424K), 0.0050639 secs] 126526K->116875K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0144243 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
2021-02-23T22:42:07.541+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.550+0800: [Tenured: 87268K->87398K(87424K), 0.0116193 secs] 126410K->118705K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0215769 secs] [Times: user=0.00 sys=0.00, real=0.02 secs]
2021-02-23T22:42:07.569+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.574+0800: [Tenured: 87398K->87249K(87424K), 0.0315818 secs] 126427K->116175K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0369570 secs] [Times: user=0.03 sys=0.00, real=0.04 secs]
2021-02-23T22:42:07.613+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.616+0800: [Tenured: 87249K->87249K(87424K), 0.0091864 secs] 126101K->119359K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0126861 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.634+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.636+0800: [Tenured: 87249K->87249K(87424K), 0.0047839 secs] 126005K->121203K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0077264 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.651+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.651+0800: [Tenured: 87249K->87249K(87424K), 0.0049760 secs] 126470K->123275K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0061458 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.669+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.680+0800: [Tenured: 87357K->87423K(87424K), 0.0342295 secs] 126618K->121943K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0459635 secs] [Times: user=0.03 sys=0.00, real=0.05 secs]
2021-02-23T22:42:07.717+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.717+0800: [Tenured: 87423K->87423K(87424K), 0.0109540 secs] 126119K->123382K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0122313 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.737+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.742+0800: [Tenured: 87423K->87423K(87424K), 0.0046415 secs] 126694K->124383K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0101329 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.753+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.768+0800: [Tenured: 87423K->87423K(87424K), 0.0114733 secs] 126437K->124440K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0268546 secs] [Times: user=0.00 sys=0.00, real=0.03 secs]
2021-02-23T22:42:07.786+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.794+0800: [Tenured: 87423K->87362K(87424K), 0.0319215 secs] 126709K->124372K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0403032 secs] [Times: user=0.03 sys=0.00, real=0.04 secs]
2021-02-23T22:42:07.831+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.832+0800: [Tenured: 87362K->87362K(87424K), 0.0037068 secs] 126024K->125099K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0073521 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.840+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.842+0800: [Tenured: 87362K->87362K(87424K), 0.0046366 secs] 125758K->125758K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0095181 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-23T22:42:07.851+0800: [Full GC (Allocation Failure) 2021-02-23T22:42:07.866+0800: [Tenured: 87362K->87279K(87424K), 0.0246226 secs] 125758K->125675K(126720K), [Metaspace: 2628K->2628K(1056768K)], 0.0399895 secs] [Times: user=0.01 sys=0.00, real=0.04 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at GCLogAnalysis.generateGarbage(GCLogAnalysis.java:48)
        at GCLogAnalysis.main(GCLogAnalysis.java:25)
Heap
 def new generation   total 39296K, used 38845K [0x00000000f8000000, 0x00000000faaa0000, 0x00000000faaa0000)
  eden space 34944K, 100% used [0x00000000f8000000, 0x00000000fa220000, 0x00000000fa220000)
  from space 4352K,  89% used [0x00000000fa660000, 0x00000000faa2f408, 0x00000000faaa0000)
  to   space 4352K,   0% used [0x00000000fa220000, 0x00000000fa220000, 0x00000000fa660000)
 tenured generation   total 87424K, used 87279K [0x00000000faaa0000, 0x0000000100000000, 0x0000000100000000)
   the space 87424K,  99% used [0x00000000faaa0000, 0x00000000fffdbe90, 0x00000000fffdc000, 0x0000000100000000)
 Metaspace       used 2658K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 294K, capacity 386K, committed 512K, reserved 1048576K

D:\F盤\JavaCourseCodes\01jvm>
  • 當前最大堆記憶體2048M時,

此時GC次數只有兩次了,但是GC耗時很久,對比設定最大堆記憶體512M時產生的物件減少了20%,也就是說性能反而較少,Xmx不是越大越好

D:\F盤\JavaCourseCodes\01jvm>java -XX:+UseSerialGC -Xms2048m -Xmx2048m  -XX:+PrintGCDetails -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-23T22:47:56.035+0800: [GC (Allocation Failure) 2021-02-23T22:47:56.035+0800: [DefNew: 559232K->69888K(629120K), 0.1193025 secs] 559232K->157347K(2027264K), 0.1198591 secs] [Times: user=0.06 sys=0.05, real=0.12 secs]
2021-02-23T22:47:56.304+0800: [GC (Allocation Failure) 2021-02-23T22:47:56.304+0800: [DefNew: 629120K->69888K(629120K), 0.1559310 secs] 716579K->289236K(2027264K), 0.1568711 secs] [Times: user=0.09 sys=0.06, real=0.16 secs]
執行結束!共生成物件次數:4917
Heap
 def new generation   total 629120K, used 291713K [0x0000000080000000, 0x00000000aaaa0000, 0x00000000aaaa0000)
  eden space 559232K,  39% used [0x0000000080000000, 0x000000008d8a07a8, 0x00000000a2220000)
  from space 69888K, 100% used [0x00000000a2220000, 0x00000000a6660000, 0x00000000a6660000)
  to   space 69888K,   0% used [0x00000000a6660000, 0x00000000a6660000, 0x00000000aaaa0000)
 tenured generation   total 1398144K, used 219348K [0x00000000aaaa0000, 0x0000000100000000, 0x0000000100000000)
   the space 1398144K,  15% used [0x00000000aaaa0000, 0x00000000b80d53e8, 0x00000000b80d5400, 0x0000000100000000)
 Metaspace       used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 291K, capacity 386K, committed 512K, reserved 1048576K

D:\F盤\JavaCourseCodes\01jvm>

CMSGC演示( -XX:+UseConcMarkSweepGC)

  • 當前最大堆記憶體512M

當發生5五次youngGC后,就進行CMSGC,

[GC (CMS Initial Mark) [1 CMS-initial-mark: 207528K(349568K)] 225479K(506816K), 0.0009352 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Initial Mark(初始標記):當前步驟需要JVM暫停STW,標記的根物件GC root
[CMS-concurrent-mark-start] Concurrent Mark(并發標記)
[CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Concurrent Preclean(并發預清理)
[CMS-concurrent-preclean-start] Final Remark(最終標記)
[CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Concurrent Sweep(并發清除)
[CMS-concurrent-abortable-preclean-start] Concurrent Reset(并發重置)
一共6個步驟,5個步驟是并發執行,CMS 使用的并發執行緒數等于CPU 核心數的1/4

CMS GC 的設計目標是避免在老年代垃圾收集時出現長時間的卡頓

D:\F盤\JavaCourseCodes\01jvm>java -XX:+UseConcMarkSweepGC  -Xms512m -Xmx512m  -XX:+PrintGCDetails -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-24T07:02:07.839+0800: [GC (Allocation Failure) 2021-02-24T07:02:07.840+0800: [ParNew: 139776K->17468K(157248K), 0.0079185 secs] 139776K->44649K(506816K), 0.0085489 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:07.879+0800: [GC (Allocation Failure) 2021-02-24T07:02:07.879+0800: [ParNew: 157199K->17459K(157248K), 0.0130003 secs] 184380K->97930K(506816K), 0.0133819 secs] [Times: user=0.03 sys=0.09, real=0.01 secs]
2021-02-24T07:02:07.923+0800: [GC (Allocation Failure) 2021-02-24T07:02:07.923+0800: [ParNew: 157235K->17472K(157248K), 0.0219433 secs] 237706K->138548K(506816K), 0.0223873 secs] [Times: user=0.08 sys=0.02, real=0.02 secs]
2021-02-24T07:02:07.972+0800: [GC (Allocation Failure) 2021-02-24T07:02:07.972+0800: [ParNew: 157248K->17472K(157248K), 0.0225044 secs] 278324K->181476K(506816K), 0.0231603 secs] [Times: user=0.09 sys=0.02, real=0.02 secs]
2021-02-24T07:02:08.023+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.024+0800: [ParNew: 156802K->17471K(157248K), 0.0235213 secs] 320806K->225000K(506816K), 0.0239944 secs] [Times: user=0.17 sys=0.03, real=0.02 secs]
2021-02-24T07:02:08.049+0800: [GC (CMS Initial Mark) [1 CMS-initial-mark: 207528K(349568K)] 225479K(506816K), 0.0009352 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.050+0800: [CMS-concurrent-mark-start]
2021-02-24T07:02:08.052+0800: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.053+0800: [CMS-concurrent-preclean-start]
2021-02-24T07:02:08.055+0800: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.055+0800: [CMS-concurrent-abortable-preclean-start]
2021-02-24T07:02:08.082+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.083+0800: [ParNew: 157247K->17471K(157248K), 0.0207909 secs] 364776K->262029K(506816K), 0.0213737 secs] [Times: user=0.09 sys=0.00, real=0.02 secs]
2021-02-24T07:02:08.130+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.131+0800: [ParNew: 157247K->17470K(157248K), 0.0221870 secs] 401805K->300663K(506816K), 0.0227283 secs] [Times: user=0.17 sys=0.02, real=0.02 secs]
2021-02-24T07:02:08.176+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.176+0800: [ParNew: 157246K->17471K(157248K), 0.0268265 secs] 440439K->348831K(506816K), 0.0273241 secs] [Times: user=0.17 sys=0.01, real=0.03 secs]
2021-02-24T07:02:08.205+0800: [CMS-concurrent-abortable-preclean: 0.006/0.146 secs] [Times: user=0.51 sys=0.03, real=0.15 secs]
2021-02-24T07:02:08.206+0800: [GC (CMS Final Remark) [YG occupancy: 25957 K (157248 K)]2021-02-24T07:02:08.207+0800: [Rescan (parallel) , 0.0004543 secs]2021-02-24T07:02:08.207+0800: [weak refs processing, 0.0000867 secs]2021-02-24T07:02:08.207+0800: [class unloading, 0.0008495 secs]2021-02-24T07:02:08.208+0800: [scrub symbol table, 0.0004637 secs]2021-02-24T07:02:08.209+0800: [scrub string table, 0.0002037 secs][1 CMS-remark: 331359K(349568K)] 357316K(506816K), 0.0035973 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.210+0800: [CMS-concurrent-sweep-start]
2021-02-24T07:02:08.211+0800: [CMS-concurrent-sweep: 0.001/0.001 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.214+0800: [CMS-concurrent-reset-start]
2021-02-24T07:02:08.222+0800: [CMS-concurrent-reset: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.234+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.234+0800: [ParNew: 157247K->17471K(157248K), 0.0133071 secs] 444418K->351340K(506816K), 0.0137356 secs] [Times: user=0.09 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.249+0800: [GC (CMS Initial Mark) [1 CMS-initial-mark: 333869K(349568K)] 351485K(506816K), 0.0008960 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.250+0800: [CMS-concurrent-mark-start]
2021-02-24T07:02:08.253+0800: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.260+0800: [CMS-concurrent-preclean-start]
2021-02-24T07:02:08.262+0800: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.263+0800: [CMS-concurrent-abortable-preclean-start]
2021-02-24T07:02:08.263+0800: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.265+0800: [GC (CMS Final Remark) [YG occupancy: 79605 K (157248 K)]2021-02-24T07:02:08.265+0800: [Rescan (parallel) , 0.0004118 secs]2021-02-24T07:02:08.266+0800: [weak refs processing, 0.0001727 secs]2021-02-24T07:02:08.266+0800: [class unloading, 0.0011286 secs]2021-02-24T07:02:08.267+0800: [scrub symbol table, 0.0004355 secs]2021-02-24T07:02:08.268+0800: [scrub string table, 0.0001893 secs][1 CMS-remark: 333869K(349568K)] 413475K(506816K), 0.0038621 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.275+0800: [CMS-concurrent-sweep-start]
2021-02-24T07:02:08.278+0800: [CMS-concurrent-sweep: 0.001/0.001 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.278+0800: [CMS-concurrent-reset-start]
2021-02-24T07:02:08.280+0800: [CMS-concurrent-reset: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.292+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.292+0800: [ParNew: 157112K->17470K(157248K), 0.0115372 secs] 387069K->288883K(506816K), 0.0123590 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.306+0800: [GC (CMS Initial Mark) [1 CMS-initial-mark: 271412K(349568K)] 289062K(506816K), 0.0008636 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.307+0800: [CMS-concurrent-mark-start]
2021-02-24T07:02:08.309+0800: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.05 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.310+0800: [CMS-concurrent-preclean-start]
2021-02-24T07:02:08.311+0800: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.312+0800: [CMS-concurrent-abortable-preclean-start]
2021-02-24T07:02:08.334+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.335+0800: [ParNew: 156988K->17471K(157248K), 0.0125048 secs] 428400K->327382K(506816K), 0.0129594 secs] [Times: user=0.11 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.375+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.375+0800: [ParNew: 157199K->157199K(157248K), 0.0001566 secs]2021-02-24T07:02:08.376+0800: [CMS2021-02-24T07:02:08.376+0800: [CMS-concurrent-abortable-preclean: 0.003/0.060 secs] [Times: user=0.16 sys=0.00, real=0.06 secs]
 (concurrent mode failure): 309910K->289393K(349568K), 0.0562658 secs] 467109K->289393K(506816K), [Metaspace: 2628K->2628K(1056768K)], 0.0569689 secs] [Times: user=0.05 sys=0.00, real=0.06 secs]
2021-02-24T07:02:08.459+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.459+0800: [ParNew: 139776K->17472K(157248K), 0.0088130 secs] 429169K->336093K(506816K), 0.0093098 secs] [Times: user=0.09 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.470+0800: [GC (CMS Initial Mark) [1 CMS-initial-mark: 318621K(349568K)] 336237K(506816K), 0.0009292 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.471+0800: [CMS-concurrent-mark-start]
2021-02-24T07:02:08.475+0800: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.475+0800: [CMS-concurrent-preclean-start]
2021-02-24T07:02:08.477+0800: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.479+0800: [CMS-concurrent-abortable-preclean-start]
2021-02-24T07:02:08.486+0800: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.488+0800: [GC (CMS Final Remark) [YG occupancy: 88636 K (157248 K)]2021-02-24T07:02:08.491+0800: [Rescan (parallel) , 0.0004964 secs]2021-02-24T07:02:08.492+0800: [weak refs processing, 0.0001096 secs]2021-02-24T07:02:08.492+0800: [class unloading, 0.0059392 secs]2021-02-24T07:02:08.498+0800: [scrub symbol table, 0.0006367 secs]2021-02-24T07:02:08.499+0800: [scrub string table, 0.0002811 secs][1 CMS-remark: 318621K(349568K)] 407257K(506816K), 0.0135319 secs] [Times: user=0.00 sys=0.00, real=0.02 secs]
2021-02-24T07:02:08.503+0800: [CMS-concurrent-sweep-start]
2021-02-24T07:02:08.516+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.516+0800: [ParNew: 157248K->17471K(157248K), 0.0143191 secs] 443039K->350400K(506816K), 0.0145845 secs] [Times: user=0.08 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.530+0800: [CMS-concurrent-sweep: 0.001/0.016 secs] [Times: user=0.09 sys=0.00, real=0.04 secs]
2021-02-24T07:02:08.540+0800: [CMS-concurrent-reset-start]
2021-02-24T07:02:08.547+0800: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.560+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.561+0800: [ParNew: 157247K->157247K(157248K), 0.0001587 secs]2021-02-24T07:02:08.561+0800: [CMS: 328412K->312126K(349568K), 0.0522486 secs] 485660K->312126K(506816K), [Metaspace: 2628K->2628K(1056768K)], 0.0537724 secs] [Times: user=0.05 sys=0.00, real=0.05 secs]
2021-02-24T07:02:08.614+0800: [GC (CMS Initial Mark) [1 CMS-initial-mark: 312126K(349568K)] 312630K(506816K), 0.0007227 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.615+0800: [CMS-concurrent-mark-start]
2021-02-24T07:02:08.618+0800: [CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.618+0800: [CMS-concurrent-preclean-start]
2021-02-24T07:02:08.620+0800: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]
2021-02-24T07:02:08.620+0800: [CMS-concurrent-abortable-preclean-start]
2021-02-24T07:02:08.625+0800: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.631+0800: [GC (CMS Final Remark) [YG occupancy: 88449 K (157248 K)]2021-02-24T07:02:08.632+0800: [Rescan (parallel) , 0.0004337 secs]2021-02-24T07:02:08.632+0800: [weak refs processing, 0.0014522 secs]2021-02-24T07:02:08.634+0800: [class unloading, 0.0100824 secs]2021-02-24T07:02:08.644+0800: [scrub symbol table, 0.0004037 secs]2021-02-24T07:02:08.645+0800: [scrub string table, 0.0002123 secs][1 CMS-remark: 312126K(349568K)] 400576K(506816K), 0.0142744 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2021-02-24T07:02:08.646+0800: [CMS-concurrent-sweep-start]
2021-02-24T07:02:08.656+0800: [GC (Allocation Failure) 2021-02-24T07:02:08.663+0800: [ParNew: 139566K->139566K(157248K), 0.0001837 secs]2021-02-24T07:02:08.663+0800: [CMS2021-02-24T07:02:08.663+0800: [CMS-concurrent-sweep: 0.001/0.008 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
 (concurrent mode failure): 311478K->323317K(349568K), 0.0660418 secs] 451044K->323317K(506816K), [Metaspace: 2628K->2628K(1056768K)], 0.0729739 secs] [Times: user=0.05 sys=0.00, real=0.07 secs]
執行結束!共生成物件次數:8831
Heap
 par new generation   total 157248K, used 111872K [0x00000000e0000000, 0x00000000eaaa0000, 0x00000000eaaa0000)
  eden space 139776K,  80% used [0x00000000e0000000, 0x00000000e6d400b8, 0x00000000e8880000)
  from space 17472K,   0% used [0x00000000e9990000, 0x00000000e9990000, 0x00000000eaaa0000)
  to   space 17472K,   0% used [0x00000000e8880000, 0x00000000e8880000, 0x00000000e9990000)
 concurrent mark-sweep generation total 349568K, used 323317K [0x00000000eaaa0000, 0x0000000100000000, 0x0000000100000000)
 Metaspace       used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 291K, capacity 386K, committed 512K, reserved 1048576K

D:\F盤\JavaCourseCodes\01jvm>
  • 圖解GC變化
    在這里插入圖片描述

G1GC演示(-XX:+UseG1GC)

  • 當前最大堆記憶體512M

當發生5五次youngGC后,就進行CMSGC,

階段1: Initial Mark(初始標記)
階段2: Root Region Scan(Root區掃描)
階段3:Evacuation Pause (mixed)(轉移暫停: 混合模式)
階段4: Remark(再次標記)
階段5: Cleanup(清理)


D:\F盤\JavaCourseCodes\01jvm>java -XX:+UseG1GC  -Xms512m -Xmx512m  -XX:+PrintGC -XX:+PrintGCDateStamps GCLogAnalysis
正在執行...
2021-02-24T07:28:03.140+0800: [GC pause (G1 Evacuation Pause) (young) 32M->11M(512M), 0.0028508 secs]       //Evacuation Pause: young(純年輕代模式轉移暫停)
2021-02-24T07:28:03.153+0800: [GC pause (G1 Evacuation Pause) (young) 39M->20M(512M), 0.0027907 secs]
2021-02-24T07:28:03.178+0800: [GC pause (G1 Evacuation Pause) (young) 67M->37M(512M), 0.0042861 secs]
2021-02-24T07:28:03.208+0800: [GC pause (G1 Evacuation Pause) (young) 102M->60M(512M), 0.0052239 secs]
2021-02-24T07:28:03.276+0800: [GC pause (G1 Evacuation Pause) (young) 214M->108M(512M), 0.0072020 secs]
2021-02-24T07:28:03.316+0800: [GC pause (G1 Evacuation Pause) (young) 242M->149M(512M), 0.0077214 secs]
2021-02-24T07:28:03.383+0800: [GC pause (G1 Humongous Allocation) (young) (initial-mark) 342M->202M(512M), 0.0342600 secs]   //Concurrent Marking(并發標記)
2021-02-24T07:28:03.417+0800: [GC concurrent-root-region-scan-start]
2021-02-24T07:28:03.419+0800: [GC concurrent-root-region-scan-end, 0.0012973 secs]
2021-02-24T07:28:03.419+0800: [GC concurrent-mark-start]
2021-02-24T07:28:03.422+0800: [GC concurrent-mark-end, 0.0024423 secs]
2021-02-24T07:28:03.422+0800: [GC remark, 0.0017725 secs]
2021-02-24T07:28:03.424+0800: [GC cleanup 228M->228M(512M), 0.0012586 secs]
     //階段1: Initial Mark(初始標記)
     //階段2: Root Region Scan(Root區掃描)
     //階段3:Evacuation Pause (mixed)(轉移暫停: 混合模式)
     //階段4: Remark(再次標記)
     //階段5: Cleanup(清理)
2021-02-24T07:28:03.471+0800: [GC pause (G1 Evacuation Pause) (young)-- 406M->307M(512M), 0.0083992 secs]
2021-02-24T07:28:03.480+0800: [GC pause (G1 Evacuation Pause) (mixed) 310M->299M(512M), 0.0048689 secs]             //Evacuation Pause (mixed)(轉移暫停: 混合模式)
2021-02-24T07:28:03.487+0800: [GC pause (G1 Humongous Allocation) (young) (initial-mark) 303M->300M(512M), 0.0011917 secs]
2021-02-24T07:28:03.489+0800: [GC concurrent-root-region-scan-start]
2021-02-24T07:28:03.497+0800: [GC concurrent-root-region-scan-end, 0.0085547 secs]
2021-02-24T07:28:03.504+0800: [GC concurrent-mark-start]
2021-02-24T07:28:03.507+0800: [GC concurrent-mark-end, 0.0026832 secs]
2021-02-24T07:28:03.508+0800: [GC remark, 0.0113277 secs]
2021-02-24T07:28:03.520+0800: [GC cleanup 383M->383M(512M), 0.0010538 secs]
2021-02-24T07:28:03.529+0800: [GC pause (G1 Evacuation Pause) (young) 412M->332M(512M), 0.0084896 secs]
2021-02-24T07:28:03.541+0800: [GC pause (G1 Evacuation Pause) (mixed) 349M->291M(512M), 0.0047697 secs]
2021-02-24T07:28:03.552+0800: [GC pause (G1 Evacuation Pause) (mixed) 316M->278M(512M), 0.0044825 secs]
2021-02-24T07:28:03.558+0800: [GC pause (G1 Humongous Allocation) (young) (initial-mark) 283M->279M(512M), 0.0016376 secs]
2021-02-24T07:28:03.560+0800: [GC concurrent-root-region-scan-start]
2021-02-24T07:28:03.569+0800: [GC concurrent-root-region-scan-end, 0.0091800 secs]
  • 圖解GC變化
    在這里插入圖片描述
  • 延伸知識

通過劃分多個記憶體區域做增量整理和回收,進一步降低延遲
G1 的全稱是Garbage-First,意為垃圾優先,哪一塊的垃圾最多就優先清理它
G1 GC 最主要的設計目標是:將STW 停頓的時間和分布,變成可預期且可配置的
堆不再分成年輕代和老年代,而是劃分為多個(通常是2048 個)可以存放物件的小塊堆區域(smaller heap regions),每個小塊,可能一會被定義成Eden 區,一會被指定為Survivor區或者Old 區,在邏輯上,所有的Eden 區和Survivor區合起來就是年輕代,所有的Old 區拼在一起那就是老年
Java8默認并行GC,Java9, Java11 默認G1GC

GC 如何選擇

  1. 如果系統考慮吞吐優先,CPU 資源都用來最大程度處理業務,用Parallel GC;
  2. 如果系統考慮低延遲有限,每次GC 時間盡量短,用CMS GC;
  3. 如果系統記憶體堆較大,同時希望整體來看平均GC 時間可控,使用G1 GC,.對于記憶體大小的考量:
    1. 一般4G 以上,算是比較大,用G1 的性價比較高,
    2. 一般超過8G,比如16G-64G 記憶體,非常推薦使用G1 GC

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/263431.html

標籤:java

上一篇:【SpringMVC】 4.3 攔截器

下一篇:遞回+IO(位元組流)

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more