what objects need to be recycled?? objects that are not referenced are recycled.
How to determine that the object has not been quoted??? 1, reference counting algorithm. (Java does not use this method because of circular reference problems.) 2, accessibility analysis method.
mainstream implementation. Determines whether the object is referenced。 Find the reference chain from the GC roots node.
(object references are divided into: strong references, soft references, weak references, virtual references.) First, no matter ~)Classify garbage collection by region
New generation of garbage collection (minor GC)When the new generation is full, the garbage collection performed is minor GC.
- Most of the newly created objects are in the Eden area.
- When the Eden area is full, the Minor GC executes, and all the objects inside the survivor area are thrown into a survivor.
- In one time, one of the survivor areas must be empty.
- Many rounds of minor GC are still existing objects and will be moved to the Laosheng generation. Generally there is a threshold (threshold for the age of the young generation)
garbage collection for Laosheng generation (major GC)
Laosheng is full, execute this GC.
Perm only perform garbage collection under full GC(It is found that only CMS will reclaim P-zone?) )
performing the above garbage collection will halt all applications inside the JVM! The minor GC is fast, but the major GC is time-consuming.
The full GC performs the minor gc,major GC separately, and the P-zone is reclaimed by garbage.
garbage collection algorithm
1. Mark-Clear Algorithm (mark-sweep)The most basic and earliest garbage collection algorithm. is generally not applicable. For example, a generation is triggered when the memory is exhausted. The steps are as follows:--stop the world. --Traverse all GC roots. The attainable representation is to survive. --Traversal of objects in the heap, with no cleanup marked as alive. Cons: Slow, need to traverse, clean out the space is not continuous. (Reference: http://www.th7.cn/Program/java/201308/146907.shtml)
2. Copy (copying)A common implementation algorithm. Replicate a region's survival to another region. For example eden+ one survivor--> another survivor. If it is full, it will be thrown into the Laosheng generation. Disadvantage: The object has a higher survival rate and slows down.
3, marking--finishing (mark-compact)The way the old age was realized. --stop the world. --Traverse all GC roots. The attainable representation is to survive. --All surviving objects move to the side.
4. Collection of generational (generational collection)Current methods of commercial collection. is 2, 3 of the complex. Use 2 or 3 depending on the object's characteristics.
garbage collector
no matter what kind of garbage collector, the world will stop. Just pause the length of time difference. Different garbage collectors have different effects.
Serial collector:
the earliest implementation.
single Thread.
for the new generation.
Use the replication algorithm.
still in use, virtual machines running in client mode are good.
Parallel Scavenge:
Multi-Threading for the new generation.
Use the replication algorithm.
can be used in server mode.
It is not recommended to use the single CPU.
parnew Collector:
enhanced version of Parallel scavenge, which can be used in conjunction with CMS.
Serial old:
single Thread.
tag--Clears the algorithm.
for Laosheng Generation
Parallel old:
Multithreading
tag-collation algorithm.
for Laosheng Generation
CMS:
multi-threaded, for Laosheng generation.
Stop the World two times.
CMS is generally sweep (clear) operation, not. After finishing the space is discontinuous.
There is a threshold, the space is not continuous to a certain extent after the compact (finishing). Or a full GC.
There is a parameter setting that can collect the P-zone.
- Initial tag (init Mark): Collects the root reference, which is a stop-the-world phase.
- Concurrent tagging (concurrent mark): This phase can be performed concurrently with the user application. Traverse the object graph of the old age, marking the caller object.
- Concurrent pre-cleanup (concurrent Preclean): This is also a concurrent phase. The main purpose is also to mark the references that have changed after the previous tag. The main purpose is to shorten the stop-the-world time of the remark stage.
- Re-tagging (remark): This is a stop-the-world operation. Pause each app to count the tags that have changed.
- Concurrent Cleanup (concurrent sweep): Concurrent scanning the entire old age, reclaiming some space occupied by objects that are unreachable in the object graph.
- Concurrent Reset (concurrent reset): Resets some data results in case the next recycling cycle begins.
|
G1:
does not distinguish between the new generation or the Laosheng generation of garbage collectors. Based on tag--collation. No fragments. Different garbage collector, the role of Where:
Reference:Https://blogs.oracle.com/jonthecollector/entry/our_collectors cms garbage collector: http://blog.griddynamics.com/2011/06/ understanding-gc-pauses-in-jvm-hotspots_02.html Youdao Cloud Notes: http://note.youdao.com/share/?id= 4e102baa9a3fa30230ff3837f6a9e79e&type=note
JVM Series (iii) garbage collection