This is the 10th day of my participation in the August More Text Challenge

1. Acquisition algorithm

1. Mark – clear

  1. Advantages: No need to move the position of the object.
  2. Disadvantages: Traversal all objects, low efficiency. Moving objects is not involved, resulting in large memory fragmentation space.
  3. Main process: ① Mark whether the object is dead. ② Clear the dead object.

2. Mark and tidy

  1. Advantages: Does not create a lot of debris space.
  2. Disadvantages: If there are too many live objects, the replication times are too many, which reduces the efficiency of the algorithm.
  3. Main process: ① Mark whether the object is dead. (2) Undead objects are moved to another space and the remaining objects are cleared.

3. Copy

  1. Advantages: No memory fragmentation is generated.
  2. Disadvantages: Space for time, instance available memory is only half of the original.
  3. 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

  1. It is inefficient and may produce long pauses.

2. The Parallel | Parallel

  1. Disadvantages: Incomplete cleaning reduces system throughput and performance.

3. CMS

  1. Concurrent + tag clearing.
  2. Initial mark (STW), concurrent mark, re-mark (STW), concurrent clear.
  3. The goal: Keep pause times as low as possible.
  4. Disadvantages: Incomplete cleanup, fragmentation space, and inconvenient redistribution of large objects.

4. G1

– XX: + UseG1GC open

  1. Concurrent + replication + generational collection.
  2. 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.
  3. The heap is divided into young generation and old generation, mainly focusing on the collection of young generation.
  4. 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.
  5. The Full GC is triggered when the old decade space usage reaches the threshold.