The introduction
If the collection algorithm is the methodology of garbage collection, then the garbage collector is the concrete implementation of memory collection. Based on the fact that most JVMS we use are HotSpot implementations, the garbage collector discussed in this article is also a HotSpot based JVM.
Garbage collector classification
Serial collector: Has only one GC thread and needs to stop the user program at run time.
Parallel collector: Multiple GC threads that also need to stop the user program at run time.
Concurrent collector: One or more GC threads go through each collection cycle: initial marking, concurrent marking, re-marking, and concurrent cleaning.
Garbage First (G1) : There is one or more GC threads, and the collection actions are similar to those of concurrency: initial marking, concurrent marking, re-marking, cleaning, and transfer collection.
Garbage collector in HotSpot
Now that we know the types of garbage collectors, let’s take a look at each type of garbage collector:
Serial collector implementation: Serial (for the new generation, using the copy algorithm), serial OLD (for the old generation, using the tag/collation algorithm).
The Parallel collector is implemented as ParNew, the Parallel Avenge, the Parallel Old, the tag/collation algorithm.
Implementation of concurrent collector: Concurrent mark sweep[CMS] (for older generations, with mark/sweep algorithm).
Garbage First(G1) : for the new generation and the old generation, the new generation adopts the replication algorithm and the old generation adopts mark-sorting.
As you can see, each of the above garbage collectors is designed for a different area of memory because they use different algorithms, usually the copy algorithm used for the new generation and the mark/sweep or mark/collate algorithm used for the old generation.
Let’s take a look at the JDK garbage collection family and how they work together:
Just to illustrate, the top three are Cenozoic collectors, the bottom three are old-age collectors, and the line between the two indicates that the two can be used together, the G1 collector in the middle.
conclusion
This chapter provides an overview of seven garbage collectors, whose operation and characteristics will be discussed in the next chapter.