Overview
The program counter, the local method stack, and the virtual machine stack are threaded and extinguished with the thread. Java heap and method area are different, this part of memory allocation and recycling is dynamic, the garbage collector is concerned about this part of memory.
An algorithm for judging whether an object is garbage
The JVM does not use the reference counting algorithm to manage memory, and the main thing is that reference counting is difficult to solve the problem of circular references between objects. The JVM uses an accessibility analysis algorithm to determine whether an object can be recycled. Using GC roots objects as a starting point, searching down, searching through the road is called the reference chain (reference chain), when there is no reference chain to an object to the GC roots, the proof object is not available.
Death of Judgment Object
Determine if an object is dead, at least 2 times. If the GC is not available through the Finaliz, the first and first filter is marked, the filter condition is the object's () The method is overwritten and has not been executed. It is then placed in the F-queue queue. The second token is to the F-queue queue to see if the object is saving itself in the Finalize () method, otherwise it is recycled. The Finalize () method of any object is automatically called only once by the system. Using the Finalize () method is strongly deprecated.
Garbage collection algorithm
Tag-Purge algorithm
The most basic algorithm, the other algorithm is to improve and complement it
Replication Algorithms
Virtual machines are now using this collection algorithm to reclaim the new generation.
Tagging-sorting algorithms
Also known as the tag-compression algorithm. This algorithm was adopted in the old age of recycling.
The algorithm implementation of hotspot
- Enumerate root nodes
- Safety Point Pause GC
- Safe Zone GC
Garbage collector serial Collector
The serial garbage collector is the most basic, oldest collector.
Single-threaded GC, when recovering "Stop the World". A copy algorithm is used.
This is a good choice for running virtual machines in client mode.
Serial Old Collector
The Serial old collector is an older version of the Serial. Uses the tag-collation algorithm.
Parnew Collector
Serial garbage collector
This is a good choice for running virtual machines in server mode.
Parallel Scavenge Collector
The Parallel scavenge collector is a new generation collector, which uses complex algorithms to collect and is also a parallel multi-threaded collector.
The main purpose of the Parallel scavenge collector is to achieve a controllable throughput. Throughput = Run user code time/(run user code time + garbage Collection Time)
Parallel Old Collector
Parallel old is an older version of the Parallel scavenge collector, using multithreading and the "mark-and-organize" algorithm.
CMS collector
The CMS (Concurrent Mark Sweep) collector is a collector that targets the shortest recovery pause time.
4 steps
-Initial tag (Stop the World)
-Concurrent tagging
-Re-mark (Stop the World)
-Concurrent cleanup
G1 Collector
Parallel and concurrency, generational collection, spatial integration, predictable pauses. Cutting-edge technology.
JVM garbage collection algorithm and garbage collector notes