JVM-GC总结
Four types of garbage collector available in Java.
- Serial Garbage Collector (-XX:+UseSerialGC)
- Parallel Garbage Collector (-XX:+UseParallelGC)
- CMS Garbage Collector (-XX:+UseConcMarkSweepGC)
- G1 Garbage Collector (–XX:+UseG1GC)

- Serial Garbage Collector(-XX:+UseSerialGC)
This garbage collector only uses for the very small application that easily runs on the single core CPU.It's holding all threads of an application during garbage collection.It is created only for single-threaded applications and this only use single thread for garbage collection.When it is doing garbage collection then it freezes all threads of an application.This is not suitable for multiple user application if We will use this then will drop the performance of application significantly.
2.Parallel Garbage Collector(-XX:+UseParallelGC)
This garbage collector is also freeze all threads of the application during garbage collection process but unlike serial garbage collector, this uses multiple threads for garbage collection.It is default collector of JVM. It is also known as throughput GC. The garbage collector is suited best for those applications that can bear application pauses .
-
CMS Garbage Collector(-XX:+UseConcMarkSweepGC)
This garbage collector uses multiple threads(“concurrent”) at the same time to scan the heap memory and mark in that available for eviction(“mark”) and then sweep the marked instances (“sweep”). This garbage collector is entered stop the world mode only in two cases
1.During marking the referenced objects in the old generation space.
2.Any change in heap memory in parallel with doing the garbage collection
STW time of CMS garbage collector is very short. -
G1 Garbage Collector(–XX:+UseG1GC)
This garbage collector introduced in JDK 7 update 4 was designed to better support larger heap size application.It uses multiple threads to scan through the heap that it divides into different regions and size of the region depend on heap size of the application.This garbage collector scans that region first that contains maximum available garbage object that is reason giving it its name (Garbage first). G1 also does compact the free heap space just after garbage collection.
In Java 8, some improvements are done in the G1 garbage collector.Using -XX:+UseStringDeduplication JVM argument using with the G1 garbage collector. This helps to remove duplicate strings values to a single value to a single char[] array.this is introduced in Java 8 u 20.
JVM结构:

JVM = 类加载器 classloader + 执行引擎 execution engine + 运行时数据区域 runtime data area
classloader 把硬盘上的class 文件加载到JVM中的运行时数据区域, 但是它不负责这个类文件能否执行,而这个是 执行引擎 负责的。
Heap组成
