要对Minor GC、Major GC 、Full GC做一个解释
从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC,可以这里理解比较好记忆morning(早晨)就是年轻。这一定义既清晰又易于理解。但是,当发生MinorGC事件的时候,有一些有趣的地方需要注意到:
1.当 JVM 无法为一个新的对象分配空间时会触发 Minor GC,比如当 Eden 区满了。所以分配率越高,越频繁执行 Minor GC
2.意思就是,在分配内存的时候先分配到eden区,如果eden区空间不够,则会发生Minor GC,之后如果eden区还是不能存下,而刚好Survivor区域可以存下,则会把对象存放到Survivor区域
Major GC是从老年代回收
Full GC (Full 全部)是从所有的空间回收,需要Stop The World
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 15 (max 15)
-age 1: 985528 bytes, 985528 total
: 4515K->962K(7680K), 0.0034246 secs] 4515K->3010K(17920K), 0.0034523 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 15 (max 15)
-age 2: 963736 bytes, 963736 total
: 5058K->941K(7680K), 0.0013148 secs] 7106K->2989K(17920K), 0.0013366 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 7680K, used 5139K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)
eden space 5120K, 82% used [0x00000007bec00000, 0x00000007bf019b30, 0x00000007bf100000)
from space 2560K, 36% used [0x00000007bf100000, 0x00000007bf1eb498, 0x00000007bf380000)
to space 2560K, 0% used [0x00000007bf380000, 0x00000007bf380000, 0x00000007bf600000)
tenured generation total 10240K, used 2048K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)
the space 10240K, 20% used [0x00000007bf600000, 0x00000007bf800010, 0x00000007bf800200, 0x00000007c0000000)
Metaspace used 3093K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 341K, capacity 388K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 1 (max 1)
-age 1: 951560 bytes, 951560 total
: 4409K->929K(7680K), 0.0036465 secs] 4409K->2977K(17920K), 0.0036764 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 1 (max 1)
-age 1: 21904 bytes, 21904 total
: 5077K->21K(7680K), 0.0015070 secs] 7125K->2998K(17920K), 0.0015301 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 7680K, used 4203K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)
eden space 5120K, 81% used [0x00000007bec00000, 0x00000007bf015790, 0x00000007bf100000)
from space 2560K, 0% used [0x00000007bf100000, 0x00000007bf105590, 0x00000007bf380000)
to space 2560K, 0% used [0x00000007bf380000, 0x00000007bf380000, 0x00000007bf600000)
tenured generation total 10240K, used 2977K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)
the space 10240K, 29% used [0x00000007bf600000, 0x00000007bf8e8518, 0x00000007bf8e8600, 0x00000007c0000000)
Metaspace used 3000K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 330K, capacity 388K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 1 (max 15)
-age 1: 1749016 bytes, 1749016 total
: 3235K->1708K(7680K), 0.0027534 secs] 3235K->1708K(17920K), 0.0027799 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew
Desired survivor size 1310720 bytes, new threshold 15 (max 15)
: 5858K->0K(7680K), 0.0019749 secs] 5858K->1684K(17920K), 0.0020036 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 7680K, used 4183K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)
eden space 5120K, 81% used [0x00000007bec00000, 0x00000007bf015d28, 0x00000007bf100000)
from space 2560K, 0% used [0x00000007bf100000, 0x00000007bf100000, 0x00000007bf380000)
to space 2560K, 0% used [0x00000007bf380000, 0x00000007bf380000, 0x00000007bf600000)
tenured generation total 10240K, used 1684K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)
the space 10240K, 16% used [0x00000007bf600000, 0x00000007bf7a53b8, 0x00000007bf7a5400, 0x00000007c0000000)
Metaspace used 3093K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 341K, capacity 388K, committed 512K, reserved 1048576K
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |