JVM learning--GC algorithm, Stop-The-World phenomenon

1. GC algorithm

  ① Reference counting method: The old garbage collection algorithm uses reference counting to collect garbage. (no need for Java)

 

  One of the problems: it's hard to deal with circular references: when the root object disappears, all three other objects should actually be reclaimed, but none of these three objects will be cleaned up because of the ring.

  ② Mark removal algorithm

   The mark-sweep algorithm is the ideological basis of modern garbage collection algorithms. There are two phases: the marking phase and the clearing phase. A possible implementation is to mark all reachable objects starting from the root node first through the root node in the marking phase. Therefore, an object that is marked is an unreferenced garbage object. Then, in the cleanup phase, all unmarked objects are cleaned up.

 

  ③Mark compression algorithm

   The mark-compression algorithm is suitable for occasions where there are many surviving objects, such as the old age. It does some optimizations based on the mark-sweep algorithm. Like the mark-sweep algorithm, the mark-squeeze algorithm also needs to start from the root node and mark all reachable objects once. But then, instead of simply cleaning up untagged objects, it compacts all live objects into one end of memory. After that, clear all the space outside the boundary.

  

Advantages over mark clear: clear memory fragmentation, more contiguous address space.

   ④ Replication algorithm: suitable for scenarios where a small number of objects survive, such as the new generation.

The definition of accessibility

  Looking at the algorithm just now, we found that we need to identify garbage objects, so we give a definition of accessibility.

I found that we have been talking about root objects above, here are some objects that can be used as root objects:

   ① Objects referenced in the stack

   ② Objects (global objects) referenced by static members or constants in the method area (merged into Metaspace)

   ③ Objects referenced in the JNI (Java Native Interface) method stack

3. Stop-The-World Phenomenon

The Stop-The-World phenomenon is actually related to the "parallel" collector used in Full GC. The parallel here actually means preempting user processes, not multi-threaded parallel cleanup.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024952&siteId=291194637