This is the 10th day of my participation in the August More Text Challenge
1. Acquisition algorithm
1. Mark – clear
- Advantages: No need to move the position of the object.
- Disadvantages: Traversal all objects, low efficiency. Moving objects is not involved, resulting in large memory fragmentation space.
- Main process: ① Mark whether the object is dead. ② Clear the dead object.
2. Mark and tidy
- Advantages: Does not create a lot of debris space.
- Disadvantages: If there are too many live objects, the replication times are too many, which reduces the efficiency of the algorithm.
- Main process: ① Mark whether the object is dead. (2) Undead objects are moved to another space and the remaining objects are cleared.
3. Copy
- Advantages: No memory fragmentation is generated.
- Disadvantages: Space for time, instance available memory is only half of the original.
- Main process: The memory is divided into two parts. After half of the memory is full, the memory is sorted and copied to the other half, and then the original area is cleaned.
4. Collect by generation
Refer to G1.
Second, GC implementation
1. The Serial | Serial
- It is inefficient and may produce long pauses.
2. The Parallel | Parallel
- Disadvantages: Incomplete cleaning reduces system throughput and performance.
3. CMS
- Concurrent + tag clearing.
- Initial mark (STW), concurrent mark, re-mark (STW), concurrent clear.
- The goal: Keep pause times as low as possible.
- Disadvantages: Incomplete cleanup, fragmentation space, and inconvenient redistribution of large objects.
4. G1
– XX: + UseG1GC open
- Concurrent + replication + generational collection.
- Target: For multi-core servers with large amounts of memory; Dealing with large amounts of fragmentation space in memory; Predictability (predictable pause time goals of no more than a few hundred milliseconds, avoiding long garbage collection pauses) is achieved by building cost models that track information about previous application behavior and garbage collection pauses.
- The heap is divided into young generation and old generation, mainly focusing on the collection of young generation.
- If the threshold is reached after the new generation (Eden) has been YoungGC several times, the object will be copied to the old age space.
- The Full GC is triggered when the old decade space usage reaches the threshold.