Mark-Clear
The mark-and-sweep algorithm is the basic idea of modern garbage collection algorithm. The tag-purge algorithm divides garbage collection into two phases: the tagging phase and the purge phase. A feasible implementation is to mark all the objects that can be reached from the root node, first through the root node, in the tagging phase. Therefore, an object that is not marked is a garbage object that is not referenced. Then, in the purge phase, clear all unmarked objects
Mark-Organize
According to the characteristics of the old age, the marker-collation algorithm is presented. It does some optimizations based on the mark-and-sweep algorithm. Like the mark-and-sweep algorithm, the tag-grooming algorithm first needs to start with the root node and mark all objects that can be reached. However, it does not simply clean up unmarked objects, but instead compresses all the surviving objects to one end of the memory. After that, clean up all the space outside the boundary.
Replication Algorithms
New Generation recovery algorithm. Divide the original memory space into three pieces, a larger Eden Space and two smaller survivor space. Use Eden and a piece of survivor each time. Copies the surviving object to another survivor space when the object is recycled. If there is not enough space, go straight to the old age.
Generational thinking
According to the survival period of the object, the short-lived object is classified as the new generation and the long-life object belongs to the old age.
According to the characteristics of different generations, select the appropriate collection algorithm
Few objects survive, suitable for replication algorithms
Large number of objects survive, suitable for tag cleanup or tag compression
Stop-the-world
A phenomenon of global pauses in Java
Global pause, all Java code stops, native code can execute, but cannot interact with JVM
Mostly due to GC
Dump thread
Deadlock Check
Heap Dump
Procedures continue to run the garbage produced, we all have to stop, and so collect, we continue to work. Let everyone stop, long time will certainly be uncomfortable.
JVM Garbage Collection algorithm