The following is JDK version 1.7

1. Look for recyclable objects

1.1 counter: Counts the number of references to reference objects. Disadvantages do not solve the problem of circular references
1.2 Accessibility Analysis: The objects that are unreachable will be marked and filtered (whether the Finalize method has been executed, whether the Finalize method has been overwritten). If not, they will be put into a queue, and the virtual machine will execute the Finalize method of the objects in the queue (which can point the reference to the objects that are reachable by Gcroot). It will not be collected in the next GC, pointing references need to be pointed before the next GC)

2. Enumerate gc Root

2.1. When the virtual machine finishes loading the class, it will record which places in the stack and registers are references (i.e. references to constants and static attributes) and store these references into an oopMap data structure
2.2. With the assistance of oopMap, virtual machines can quickly complete the enumeration of gcRoot
2.3 the virtual machine does not generate oopMap markers for each instruction. As mentioned above, certain locations are called safe points (not too few gc frequencies too low, and not too many GC frequencies too high, so the selection of safe points requires the program to be running for a long time).
Preemptive interrupt: When GC occurs, all threads are interrupted. If the interrupted thread is not at the safe point, it will be released until it runs to the safe point. Instead of operating directly on the thread, only a flag is set, and each thread actively rotates the flag during execution. If true, the current thread is suspended

3. Garbage collection algorithm

3.1: mark – clear the memory space that the mark needs to reclaim, and then uniformly clear the disadvantage will produce a large number of discontinuous memory space, when allocating large objects, it may not be able to find the contiguous memory space
3.2: Replication algorithm copies objects that do not need to be reclaimed to another block of memory, and then deletes the currently used memory. The disadvantage is that 50% of the memory is required as replication memory
3.3: Mark-declutter is the same as the first step of tag cleanup, but after mark-declutter, objects that do not need to be reclaimed are moved to one end, and then content beyond the end boundary is deleted
3.4: There is no best algorithm, so different Collection algorithms are used according to the objects in the heap memory of different generations. The current garbage Collection algorithm of commercial VMS is “Generational Collection”. There is nothing new in this algorithm, but just according to the survival cycle of objects
Divide memory into blocks. Typically, the Java heap is divided into the new generation and the old generation, so that the most appropriate collection algorithm can be used for each generation. In the new generation, a large number of objects are found dead and only a few survive in garbage collection, so the replication algorithm is selected, and only a small amount of the replication cost of the surviving objects can be collected. In the old days, because the object has a high survival rate and there is no extra space to allocate it, it has to use the “mark-clean” or “mark-tidy” algorithm for recycling.

Garbage collector

4.1 Serial collector, Serial Old collector, pauses all threads for garbage collection, is single-threaded.
4.2. The ParNew collector suspends all threads for garbage collection and is multithreaded
The Parallel Collector, the Parallel Old collector, is essentially the same as the 4.2 collector, although it provides two parameters, the garbage collector thread pause time and set throughput size. -xx: MaxGCPauseMillis and -xx: GCTimeRatio, which directly sets the throughput size. The Parallel Exploiture collector also has a parameter -xx: +UseAdaptiveSizePolicy that should be noted. This is a switch parameter. When turned on, there is no need to manually specify the size of the new generation (-xMN), Eden to Survivor ratio (-xx: SurvivorRatio), and age of the older age (-xx: SurvivorRatio). PretenureSizeThreshold), the vm automatically allocates memory and is an adaptive garbage collector
4.4 CMS collector has four processes, initial mark (mark the object that gcRoot can be directly associated with), concurrent mark (is the process of reachable analysis, can be executed with the user thread), re-mark (correct concurrent mark interval mark produced by the change of mark), concurrent clear (clear, CMS is a mark-clearing algorithm, with a parameter that controls the number of fullGCs to be mark-collated. The CMS collector provides a -xx: + UseCMSCompactAtFullCollection switch parameters (the default is open), is used to hold the CMS collector to FullGC open memory fragments of combined finishing process, it is impossible to concurrent process of memory consolidation, the problem of space debris, but not the same long pauses. Virtual machine designers also provides another parameter – XX: CMSFullGCsBeforeCompaction, how many times this parameter is used to set the execution without compression after Full GC, followed by a with compression (the default value is 0, said every time they enter FullGC defragmentation).
The G1 collector, similar to CMS, manages the entire heap without the cooperation of other collectors. Track the value of garbage accumulation in each area (the time required and the amount of space after recycling), and prioritize the areas with high value for recycling. Each region in G1 has a corresponding Remembered Set. When assigning references to data, it checks whether the referenced data is in a different region. If the referenced data is in a different region, it is recorded in the Remembered Set of the referenced object through the ttable

I have nothing to write, there are mistakes welcome correction.