
1.Serial Collector - mark copy
① Single threaded collector
② Simple and efficient, minimal additional memory consumption, no thread interaction overhead
③ Virtual machine for client mode
2.Serial Old Collector - Tag sorting
① Single threaded collector
② It is suitable for the client mode virtual machine. It is suitable for the cooperation of Serial and ParNew on the server side, and can be used as a CMS backup plan
3.ParNew Collector - mark copy
① Multithreaded parallel collection
② It can cooperate with CMS and Serial Old. It is the default new generation collector after CMS is activated
4.Parallel Scavenge Collector - Tag replication
① Focus on throughput, suitable for background operation and analysis tasks
Three parameter control throughput:
-XX:MaxGcPauseMillis Parallel Scavenge Maximum garbage collection pause time -XX:GcTimeRatio=N Parallel Scavenge Set throughput directly (garbage collection time accounts for 1%)/1+N) -XX:UseAdaptiveSizePolicy Manual assignment is not required after activation-xmn Cenozoic size-XX:SurvivorRatio(eden And survivor Scale)-XX:PretenureSizeThreshold(Promotion of old age size),Virtual machine auto tuning
② Adaptive adjustment
5.Parallel Old Collector - mark sorting
Throughput priority combination
The collection process of 1-5 is non concurrent, and the collection thread and user thread run alternately
6.CMS Collector - mark removal
① The goal is the shortest pause time, concurrent collection and low pause
② Operation process:
1)Initial marking: stw,sign GCRoots Objects directly associated to 2)Concurrent marking 3)Retag: stw,Is an incremental update in the concurrent marking phase 4)Concurrent cleanup
③ Disadvantages:
1)The concurrency phase occupies threads, which slows down the application and reduces the total throughput 2)Floating garbage cannot be disposed of and may occur Concurrent Mode Failure cause stw of FULL gc,Therefore, space must be reserved for concurrent programs to try 3)Space debris caused by mark removal
7.G1 Collector - overall mark sorting and local mark copying
① For server applications, suitable for large memory applications
② Implement the pause time model: within the specified time segment of M milliseconds, the garbage collection time probably does not exceed N milliseconds
③ Mixed GC, the java heap is divided into multiple regions. In particular, Humongous is used to store large objects (more than half of objects in a single Region). Maintain the priority list and select the priority Region according to the pause time.
④ Details:
1)How to solve cross Region Reference object? Using special memory sets, each Region Maintain your own memory set and record "who I point to" and "who points to me" 2)How to solve the interference between the two in the concurrent marking phase? The object disappearance problem is solved by using the original snapshot SATB Way. New object memory allocation problem try two TAMS Pointer, used to allocate memory. The two pointers point to the objects in the area. The default is to live 3)How to build pause time model? Record the previous recovery time, number of dirty cards and other statistical information to measure the average attenuation
⑤ Operation process
1)Initial marking: stw,sign GCRoots Objects directly associated to, modifying TAMS Pointer value 2)Concurrent marking 3)Retag: stw,Is the original snapshot of the concurrent marking phase ※4)Filter recycling: stw,choice Region Recycle, recycle Region Copy live objects to empty Region
⑥ Shortcomings
1)The card and table are complex, many, and the memory occupation is high 2)In order to maintain the original snapshot, the pre write barrier is used to track pointer changes, and the post write barrier updates the card table (the same as CMS);The barrier to be executed is put into the message queue, and the execution load is high
8.Shenandoah Collector - overall mark sorting and local mark copying
① It is the successor of G1. What is the difference from G1?
1)Generation is not used by default 2)The recovery phase can be concurrent 3)Discard the memory set and use the link matrix to indicate Region Cross generational references between
② Operation process (marking stage is the same as G1) (concurrent marking, concurrent recycling, concurrent reference update)
1)Initial marking: stw,sign GCRoots Objects directly associated to, modifying TAMS Pointer value 2)Concurrent marking 3)Retag: stw,Is the original snapshot of the concurrent marking phase 4)Concurrent cleanup: Clean up no surviving objects Region ※5)Concurrent recycling: copy live objects to null Region,The read barrier and forward pointer are used to solve the concurrency problem, and the size of the recovery set determines the time 6)Initial reference update: Pause briefly to ensure that the move is complete Concurrent reference update: search linearly according to the order of physical addresses, and change the old value to the new value copied to Final reference update: pause, resolve GC Roots Reference update for 7)Concurrent cleanup
③ Forwarding pointer and reference access barrier + CAS
A reference field is added to the object header. When the object is not in the concurrent move state, the reference points to the object itself, and when the object is moved, it points to a new object. Only the reference type reading is intercepted - the problem of concurrent reading is solved
CAS ensures the correctness of object access during concurrency - solves the problem of concurrent write
9.ZGC collector
① It can also be regarded as the successor of G1. What are the differences between Shenandoah?
1)Region It is divided into large, medium and small, with fixed capacity and large capacity Region It is used to prevent large objects from being fixed and reallocated 2)Dye pointer record mark, Shenandoah and G1 use bitmap Record marked objects
② Advantages of stained pointer? – the mark is directly printed in the high position of the pointer
1)"The "self-healing" feature makes a Region The live object is released for reuse immediately after it is removed, and She You must wait for references to update before cleaning up 2)Use only read barriers to reduce the number of memory barriers 3)The coloring pointer can be extended to record more data
③ Operation process
1)Concurrent Tags: similar G1,She,Update the colored pointer flag. 2)Concurrent provisioning reassignment: scan all Region The redistribution set is statistically derived Region Mark copy, but others region Garbage collection can also occur. *3)Concurrent Reallocation: copy the surviving objects in the reallocation set, each Region Maintain forwarding. The memory barrier intercepts the access request, determines whether it is in the reallocation set according to the address, accesses and modifies the reference according to the forwarding 4)Concurrent remapping: it is not urgent to modify the reference to the old object in the reallocation set, and merge it to the next concurrent mark