public class GCLogTest {
public static void main(String[] args) {
ArrayList<byte[]> list = new ArrayList<>();
for (int i = 0; i < 500; i++) {
byte[] arr = new byte[1024 * 100];//100KB
list.add(arr);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
1.8默认为parallel GC
"C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" -Dvisualvm.id=16021384244500 -Xms60m -Xmx60m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:+PrintCommandLineFlags "-javaagent:D:\DevelopTools\IDEA\IntelliJ IDEA 2019.2.2\lib\idea_rt.jar=1759:D:\DevelopTools\IDEA\IntelliJ IDEA 2019.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_211\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\rt.jar;E:\CODE\Architecture\jvm\target\classes;C:\Users\zwz\.m2\repository\org\apache\commons\commons-vfs2\2.2\commons-vfs2-2.2.jar;C:\Users\zwz\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar" com.atguigu.java.GCLogTest
-XX:InitialHeapSize=62914560 -XX:MaxHeapSize=62914560 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
[GC (Allocation Failure) [PSYoungGen: 16313K->2024K(18432K)] 16313K->14454K(59392K), 0.0037880 secs] [Times: user=0.02 sys=0.14, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 18349K->1988K(18432K)] 30780K->30628K(59392K), 0.0042319 secs] [Times: user=0.00 sys=0.16, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 1988K->0K(18432K)] [ParOldGen: 28640K->30484K(40960K)] 30628K->30484K(59392K), [Metaspace: 3726K->3726K(1056768K)], 0.0126215 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (Ergonomics) [PSYoungGen: 16316K->6000K(18432K)] [ParOldGen: 30484K->40775K(40960K)] 46801K->46776K(59392K), [Metaspace: 3726K->3726K(1056768K)], 0.0136024 secs] [Times: user=0.14 sys=0.01, real=0.01 secs]
Heap
PSYoungGen total 18432K, used 10709K [0x00000000fec00000, 0x0000000100000000, 0x0000000100000000)
eden space 16384K, 65% used [0x00000000fec00000,0x00000000ff6754c8,0x00000000ffc00000)
from space 2048K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x0000000100000000)
to space 2048K, 0% used [0x00000000ffc00000,0x00000000ffc00000,0x00000000ffe00000)
ParOldGen total 40960K, used 40775K [0x00000000fc400000, 0x00000000fec00000, 0x00000000fec00000)
object space 40960K, 99% used [0x00000000fc400000,0x00000000febd1f50,0x00000000fec00000)
Metaspace used 3733K, capacity 4536K, committed 4864K, reserved 1056768K
class space used 410K, capacity 428K, committed 512K, reserved 1048576K
Process finished with exit code 0
使用G1 GC日志
"C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" -Dvisualvm.id=15856095499900 -Xms60m -Xmx60m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:+PrintCommandLineFlags -XX:+UseG1GC "-javaagent:D:\DevelopTools\IDEA\IntelliJ IDEA 2019.2.2\lib\idea_rt.jar=1700:D:\DevelopTools\IDEA\IntelliJ IDEA 2019.2.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_211\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\rt.jar;E:\CODE\Architecture\jvm\target\classes;C:\Users\zwz\.m2\repository\org\apache\commons\commons-vfs2\2.2\commons-vfs2-2.2.jar;C:\Users\zwz\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar" com.atguigu.java.GCLogTest
-XX:InitialHeapSize=62914560 -XX:MaxHeapSize=62914560 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
[GC pause (G1 Evacuation Pause) (young), 0.0128531 secs]
[Parallel Time: 6.2 ms, GC Workers: 10]
[GC Worker Start (ms): Min: 10886.5, Avg: 10886.6, Max: 10886.7, Diff: 0.2]
[Ext Root Scanning (ms): Min: 0.1, Avg: 0.2, Max: 0.3, Diff: 0.2, Sum: 1.9]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 4.9, Avg: 5.0, Max: 5.0, Diff: 0.2, Sum: 49.5]
[Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.7]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 10]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.3]
[GC Worker Total (ms): Min: 5.2, Avg: 5.2, Max: 5.4, Diff: 0.2, Sum: 52.5]
[GC Worker End (ms): Min: 10891.9, Avg: 10891.9, Max: 10891.9, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.8 ms]
[Other: 5.8 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.6 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.7 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 24.0M(24.0M)->0.0B(13.0M) Survivors: 0.0B->3072.0K Heap: 24.0M(60.0M)->22.9M(60.0M)]
[Times: user=0.05 sys=0.11, real=0.01 secs]
[GC pause (G1 Evacuation Pause) (young), 0.0071315 secs]
[Parallel Time: 4.8 ms, GC Workers: 10]
[GC Worker Start (ms): Min: 17422.8, Avg: 17422.9, Max: 17423.0, Diff: 0.2]
[Ext Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.3, Diff: 0.3, Sum: 1.2]
[Update RS (ms): Min: 0.0, Avg: 0.7, Max: 4.0, Diff: 4.0, Sum: 7.2]
[Processed Buffers: Min: 0, Avg: 0.3, Max: 1, Diff: 1, Sum: 3]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 0.1, Avg: 3.0, Max: 3.7, Diff: 3.6, Sum: 29.9]
[Termination (ms): Min: 0.0, Avg: 0.3, Max: 0.4, Diff: 0.4, Sum: 3.5]
[Termination Attempts: Min: 1, Avg: 170.8, Max: 210, Diff: 209, Sum: 1708]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[GC Worker Total (ms): Min: 4.1, Avg: 4.2, Max: 4.3, Diff: 0.2, Sum: 41.9]
[GC Worker End (ms): Min: 17427.1, Avg: 17427.1, Max: 17427.1, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 1.1 ms]
[Other: 1.3 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.6 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.6 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 13.0M(13.0M)->0.0B(9216.0K) Survivors: 3072.0K->2048.0K Heap: 35.9M(60.0M)->35.9M(60.0M)]
[Times: user=0.00 sys=0.00, real=0.01 secs]
[GC pause (G1 Evacuation Pause) (young) (initial-mark), 0.0042604 secs]
[Parallel Time: 1.8 ms, GC Workers: 10]
[GC Worker Start (ms): Min: 21923.7, Avg: 21923.8, Max: 21923.9, Diff: 0.2]
[Ext Root Scanning (ms): Min: 0.0, Avg: 0.2, Max: 0.4, Diff: 0.4, Sum: 2.2]
[Update RS (ms): Min: 0.0, Avg: 0.1, Max: 0.6, Diff: 0.6, Sum: 0.9]
[Processed Buffers: Min: 0, Avg: 1.1, Max: 4, Diff: 4, Sum: 11]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 0.5, Avg: 0.9, Max: 1.0, Diff: 0.5, Sum: 9.3]
[Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.2]
[Termination Attempts: Min: 1, Avg: 1.1, Max: 2, Diff: 1, Sum: 11]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[GC Worker Total (ms): Min: 1.2, Avg: 1.3, Max: 1.4, Diff: 0.2, Sum: 12.7]
[GC Worker End (ms): Min: 21925.1, Avg: 21925.1, Max: 21925.1, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 1.0 ms]
[Other: 1.5 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.7 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.7 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 9216.0K(9216.0K)->0.0B(4096.0K) Survivors: 2048.0K->2048.0K Heap: 44.9M(60.0M)->44.7M(60.0M)]
[Times: user=0.00 sys=0.00, real=0.00 secs]
[GC concurrent-root-region-scan-start]
[GC concurrent-root-region-scan-end, 0.0041769 secs]
[GC concurrent-mark-start]
[GC concurrent-mark-end, 0.0007484 secs]
[GC remark [Finalize Marking, 0.0005851 secs] [GC ref-proc, 0.0003975 secs] [Unloading, 0.0010710 secs], 0.0029586 secs]
[Times: user=0.16 sys=0.00, real=0.00 secs]
[GC cleanup 44M->44M(60M), 0.0021057 secs]
[Times: user=0.00 sys=0.00, real=0.00 secs]
[GC pause (G1 Evacuation Pause) (young), 0.0027440 secs]
[Parallel Time: 1.2 ms, GC Workers: 10]
[GC Worker Start (ms): Min: 23844.4, Avg: 23844.5, Max: 23844.6, Diff: 0.2]
[Ext Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 1.1]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Processed Buffers: Min: 0, Avg: 0.2, Max: 1, Diff: 1, Sum: 2]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 0.5, Avg: 0.5, Max: 0.5, Diff: 0.1, Sum: 4.9]
[Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.1, Sum: 0.3]
[Termination Attempts: Min: 2, Avg: 2.9, Max: 4, Diff: 2, Sum: 29]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[GC Worker Total (ms): Min: 0.5, Avg: 0.6, Max: 0.8, Diff: 0.2, Sum: 6.4]
[GC Worker End (ms): Min: 23845.2, Avg: 23845.2, Max: 23845.2, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 0.6 ms]
[Other: 1.0 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.2 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.7 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 4096.0K(4096.0K)->0.0B(2048.0K) Survivors: 2048.0K->1024.0K Heap: 48.7M(60.0M)->48.5M(60.0M)]
[Times: user=0.00 sys=0.00, real=0.00 secs]
[GC pause (G1 Evacuation Pause) (young), 0.0037887 secs]
[Parallel Time: 1.2 ms, GC Workers: 10]
[GC Worker Start (ms): Min: 24806.1, Avg: 24806.3, Max: 24806.3, Diff: 0.2]
[Ext Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.2, Diff: 0.2, Sum: 0.9]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[Processed Buffers: Min: 0, Avg: 0.4, Max: 1, Diff: 1, Sum: 4]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Object Copy (ms): Min: 0.2, Avg: 0.2, Max: 0.2, Diff: 0.0, Sum: 2.0]
[Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.2]
[Termination Attempts: Min: 1, Avg: 1.7, Max: 2, Diff: 1, Sum: 17]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[GC Worker Total (ms): Min: 0.3, Avg: 0.3, Max: 0.5, Diff: 0.2, Sum: 3.3]
[GC Worker End (ms): Min: 24806.6, Avg: 24806.6, Max: 24806.6, Diff: 0.0]
[Code Root Fixup: 0.0 ms]
[Code Root Purge: 0.0 ms]
[Clear CT: 1.0 ms]
[Other: 1.6 ms]
[Choose CSet: 0.0 ms]
[Ref Proc: 0.8 ms]
[Ref Enq: 0.0 ms]
[Redirty Cards: 0.7 ms]
[Humongous Register: 0.0 ms]
[Humongous Reclaim: 0.0 ms]
[Free CSet: 0.0 ms]
[Eden: 2048.0K(2048.0K)->0.0B(2048.0K) Survivors: 1024.0K->1024.0K Heap: 50.5M(60.0M)->50.4M(60.0M)]
[Times: user=0.02 sys=0.00, real=0.00 secs]
Heap
garbage-first heap total 61440K, used 52624K [0x00000000fc400000, 0x00000000fc5001e0, 0x0000000100000000)
region size 1024K, 3 young (3072K), 1 survivors (1024K)
Metaspace used 3732K, capacity 4536K, committed 4864K, reserved 1056768K
class space used 410K, capacity 428K, committed 512K, reserved 1048576K
Process finished with exit code 0
调优
- 根据需求进行JVM规划和预调优
- 优化运行JVM运行环境
- 将JVM运行过程中出现的各种问题