观点纠正:1.7 1.8 默认 UseParallelGC = PS + PO
首先来看下错误的示范,注意!!!是错误的!!!
本来你想靠百度,没想到进了个坑。博客地址就不贴了,希望各位楼主发博之前记得验证下,别再误导了。
两种错误方式!!!
这张图CSDN抽风,试了半天后面都传不上,就不贴了
尤其是第二张图这个博客主,不觉得打脸吗???
还是自己动手好了
查看JVM默认的垃圾回收器
cmd命令: java -XX:+PrintCommandLineFlags -version
1.设置运行参数
-Xmn5M
-Xms5M
-Xmx5M
-Xss5M
-XX:+PrintGCDetails
-XX:+PrintCommandLineFlags
-XX:+UseParallelGC
执行
List list = new ArrayList();
for (int i = 0; i< 10; i++){
list.add(new byte[1024]);
}
结果:
-XX:InitialHeapSize=5242880 -XX:MaxHeapSize=5242880 -XX:MaxNewSize=5242880 -XX:NewSize=5242880 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:ThreadStackSize=5120 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
[GC (Allocation Failure) [PSYoungGen: 4096K->507K(4608K)] 4096K->1201K(5632K), 0.0023635 secs] [Times: user=0.00 sys=0.01, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 507K->498K(4608K)] [ParOldGen: 693K->664K(1024K)] 1201K->1163K(5632K), [Metaspace: 2652K->2652K(1056768K)], 0.0034648 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 4594K->496K(4608K)] [ParOldGen: 664K->995K(1024K)] 5259K->1491K(5632K), [Metaspace: 2833K->2833K(1056768K)], 0.0046685 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 4608K, used 1031K [0x00000000ffb00000, 0x0000000100000000, 0x0000000100000000)
eden space 4096K, 25% used [0x00000000ffb00000,0x00000000ffc01dc0,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 1024K, used 995K [0x00000000ffa00000, 0x00000000ffb00000, 0x00000000ffb00000)
object space 1024K, 97% used [0x00000000ffa00000,0x00000000ffaf8c60,0x00000000ffb00000)
Metaspace used 3203K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 343K, capacity 388K, committed 512K, reserved 1048576K
Process finished with exit code 0
很明显 : UseParallelGC = PS + PO
设置: -XX:+UseSerialGC ,应该是没打 Serial Old
设置:-XX:+UseParNewGC 只看到PN,默认的 Serial Old 应该是没打
[GC (Allocation Failure) [ParNew: 4096K->511K(4608K), 0.0022338 secs] 4096K->1201K(5632K), 0.0022637 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 4607K->4607K(4608K), 0.0000107 secs][Tenured: 690K->1023K(1024K), 0.0023365 secs] 5297K->1732K(5632K), [Metaspace: 2835K->2835K(1056768K)], 0.0023842 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
par new generation total 4608K, used 2309K [0x00000000ffa00000, 0x00000000fff00000, 0x00000000fff00000)
eden space 4096K, 56% used [0x00000000ffa00000, 0x00000000ffc414e8, 0x00000000ffe00000)
from space 512K, 0% used [0x00000000ffe80000, 0x00000000ffe80000, 0x00000000fff00000)
to space 512K, 0% used [0x00000000ffe00000, 0x00000000ffe00000, 0x00000000ffe80000)
tenured generation total 1024K, used 1023K [0x00000000fff00000, 0x0000000100000000, 0x0000000100000000)
the space 1024K, 99% used [0x00000000fff00000, 0x00000000ffffffb0, 0x0000000100000000, 0x0000000100000000)
Metaspace used 3266K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 350K, capacity 388K, committed 512K, reserved 1048576K
-XX:+UseConcMarkSweepGC 完整看到 PN + cms
-XX:InitialHeapSize=5242880 -XX:MaxHeapSize=5242880 -XX:MaxNewSize=5242880 -XX:MaxTenuringThreshold=6 -XX:NewSize=5242880 -XX:OldPLABSize=16 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:ThreadStackSize=5120 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:-UseLargePagesIndividualAllocation -XX:+UseParNewGC
[GC (Allocation Failure) [ParNew (promotion failed): 4096K->4608K(4608K), 0.0026160 secs][CMS: 498K->985K(1024K), 0.0022091 secs] 4096K->1167K(5632K), [Metaspace: 2652K->2652K(1056768K)], 0.0048715 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [CMS: 1023K->1023K(1024K), 0.0039718 secs] 5631K->1669K(5632K), [Metaspace: 3162K->3162K(1056768K)], 0.0040140 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Initial Mark) [1 CMS-initial-mark: 1023K(1024K)] 1712K(5632K), 0.0006037 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 1935 K (4608 K)][Rescan (parallel) , 0.0002704 secs][weak refs processing, 0.0000052 secs][class unloading, 0.0002659 secs][scrub symbol table, 0.0003359 secs][scrub string table, 0.0000815 secs][1 CMS-remark: 1023K(1024K)] 2958K(5632K), 0.0010050 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-reset-start]
[CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
par new generation total 4608K, used 1935K [0x00000000ffa00000, 0x00000000fff00000, 0x00000000fff00000)
eden space 4096K, 47% used [0x00000000ffa00000, 0x00000000ffbe3df0, 0x00000000ffe00000)
from space 512K, 0% used [0x00000000ffe80000, 0x00000000ffe80000, 0x00000000fff00000)
to space 512K, 0% used [0x00000000ffe00000, 0x00000000ffe00000, 0x00000000ffe80000)
concurrent mark-sweep generation total 1024K, used 952K [0x00000000fff00000, 0x0000000100000000, 0x0000000100000000)
Metaspace used 3330K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 353K, capacity 388K, committed 512K, reserved 1048576K
-XX:+UseParallelOldGC PS + PO
-XX:InitialHeapSize=5242880 -XX:MaxHeapSize=5242880 -XX:MaxNewSize=5242880 -XX:NewSize=5242880 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:ThreadStackSize=5120 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelOldGC
[GC (Allocation Failure) [PSYoungGen: 4096K->511K(4608K)] 4096K->1201K(5632K), 0.0009040 secs] [Times: user=0.06 sys=0.02, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 511K->502K(4608K)] [ParOldGen: 690K->661K(1024K)] 1201K->1163K(5632K), [Metaspace: 2652K->2652K(1056768K)], 0.0030615 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 4598K->500K(4608K)] [ParOldGen: 661K->991K(1024K)] 5259K->1492K(5632K), [Metaspace: 2836K->2836K(1056768K)], 0.0046431 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 4608K, used 2180K [0x00000000ffb00000, 0x0000000100000000, 0x0000000100000000)
eden space 4096K, 53% used [0x00000000ffb00000,0x00000000ffd21338,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 1024K, used 991K [0x00000000ffa00000, 0x00000000ffb00000, 0x00000000ffb00000)
object space 1024K, 96% used [0x00000000ffa00000,0x00000000ffaf7f30,0x00000000ffb00000)
Metaspace used 3204K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 342K, capacity 388K, committed 512K, reserved 1048576K
-XX:+UseG1GC