The GC algorithm evolved slowly, evolving into the current generational GC. Its evolutionary process labeling-clearing algorithm –> tag-copy algorithm –> marker-collation algorithm –> the generational algorithm.
Before we introduce the algorithm, we know that Java is dynamic loading. Its characteristics:
1. Hierarchical relationship, by Bootstrap class loader–> Extension class loader, System class loader (APP class loader), User Defin Ed Class Loader.
2. Delegate load mode, load a class, first see whether the parent class has been loaded, only the parent class cannot load, the subclass will try to load, which ensures that the application is loading the same class (the same code).
3. To make the class have restrictions, the parent class cannot access the class that the child class loads, and the subclass can use the class that the parent class loads.
4. Although the load class cannot unload its loaded class, it can delete the current load class.
Through the dynamic loading mechanism of Java, we can know that a live object in Java can be traced from the root (the topmost loading class). To understand this, let's go back to the specific GC algorithm.
Tag-Purge algorithm:
By marking the objects that can be traced back, and then deleting the objects that are not marked. The disadvantage of this algorithm is that it can cause memory fragmentation.
Tag-Copy algorithm:
Divide the memory into two, delete unmarked objects, and then copy the tagged objects to another. This algorithm avoids the memory fragmentation problem, but it brings a memory waste problem (half of memory space-time).
Tag-Collation algorithm:
This algorithm removes unmarked objects and then organizes the tagged objects into memory. This algorithm avoids the defects of the first two algorithms, but it brings the problem of inefficiency.
Split-generation algorithm:
This algorithm can be based on the needs of the application algorithm selection and parameter adjustment, the next section we will talk about the GC parameter adjustment.
Three GC-related three-minute recognition of GC algorithms