Algorithm

Mark-Sweep

First Mark all cleanable memory, then Clean at one time

  • Efficiency problem
  • Memory fragmentation

Copying

Use when surviving rate is low(Usually it is the case)

  1. Divide the entire memory into 2 sections
  2. Use only one of the section as memory allocation section.
  3. Once that allocation section is exhausted, move the part that are still being used onto the top of the other memory section
  4. Cleaning the allocation section.

In this way, there is no memory fragmentation, and cleaning is quite efficient. Major commercial JVM use this strategy

  • Memory usability is 50% only

Mark-Compact

Use when surviving rate is high.

  1. Just like Mark-Sweep
  2. But compact the memory. Move the memory into one direct so that there is no memory fragment

Generational

Major commercial JVM use this strategy. Must use along with other strategy.

Collector

Serial

Must stop all the other works when collecting, which is so bad.

ParNew

Multi-thread version of Serial collector, nothing new.

Parallel Scavenger

Similar to ParNew but this collector focuses on reaching a controllable throughout. Sometimes also called Throughout first collector

Concurrent Mark Sweep

To collect as fast as possible.

  1. Init mark(Stop the world)(Only mark objects that are directly GC related)
  2. Concurrent mark(GC Roots tracing)
  3. Remark(Stop the world)(Check objects that changed during concurrent mark)
  4. Concurrent sweep

Great collector. Sensitive to CPU

G1

Art of the state collector. Based on Mark-Compact Maintain a priority queue of garbage, collect the garbage first to ensure good throughout.



Published

16 February 2017

Category

development

Tags