GC有两种
    minor GC:对于新生成的对象,都放在Eden中;当Eden充满时(小孩太多了),GC将开始工作,首先停止应用程序的运行,开始收集垃圾,把所有可找到的对象都复制到old空间中;

    full GC:当old满了,触发full GC。full GC很消耗内存,把old,young里面大部分垃圾回收掉。这个时候用户线程都会被block。


    通过jmap命令也可以查看JVM当前的heap使用情况:

    jmap -heap 4306

    Attaching to process ID 17334, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 17.0-b16

    using thread-local object allocation.
    Concurrent Mark-Sweep GC

    Heap Configuration:
       MinHeapFreeRatio = 40
       MaxHeapFreeRatio = 70
       MaxHeapSize      = 1048576000 (1000.0MB)
       NewSize          = 33554432 (32.0MB)
       MaxNewSize       = 33554432 (32.0MB)
       OldSize          = 100663296 (96.0MB)
       NewRatio         = 7
       SurvivorRatio    = 4
       PermSize         = 21757952 (20.75MB)
       MaxPermSize      = 88080384 (84.0MB)

    Heap Usage:
    New Generation (Eden + 1 Survivor Space):
       capacity = 27983872 (26.6875MB)
       used     = 10699128 (10.203483581542969MB)
       free     = 17284744 (16.48401641845703MB)
       38.23319374817037% used
    Eden Space:
       capacity = 22413312 (21.375MB)
       used     = 5473760 (5.220184326171875MB)
       free     = 16939552 (16.154815673828125MB)
       24.42191497624269% used
    From Space:
       capacity = 5570560 (5.3125MB)
       used     = 5225368 (4.983299255371094MB)
       free     = 345192 (0.32920074462890625MB)
       93.80328010110294% used
    To Space:
       capacity = 5570560 (5.3125MB)
       used     = 0 (0.0MB)
       free     = 5570560 (5.3125MB)
       0.0% used
    concurrent mark-sweep generation:
       capacity = 545476608 (520.20703125MB)
       used     = 311771592 (297.3285598754883MB)
       free     = 233705016 (222.87847137451172MB)
       57.155813361661146% used
    Perm Generation:
       capacity = 39591936 (37.7578125MB)
       used     = 23793192 (22.690956115722656MB)
       free     = 15798744 (15.066856384277344MB)
       60.096055924115454% used