JVM Troubleshooting

HotSpot Garbage Collectors

  • Young Generation

    • Serial
      • is a stop-the-world
      • copying collector that uses a single GC thread
    • ParNew
      • is a stop-the-world
      • copying collector that uses multiple GC threads
    • ParallelScavenge
      • is a stop-the-world
      • copying collector that uses multiple GC threads
  • Old Generation

    • Serial Old (Mark Sweep Compact)
      • is a stop-the-world
      • mark-sweep-compact collector that uses a single GC thread
    • CMS
      • is a mostly concurrent
      • low-pause collector
    • Parellel Old
      • is a compacting collector that uses multiple GC threads
  • Both

    • G1
      • is the Garbage First collector for large heaps
      • provides reliable short GC pauses
      • has generations but uses different memory layout

How to enable the Collectors

  • UseSerialGC : Serial + Serial Old
  • UseParNewGC : ParNew + Serial Old
  • UseConcMarkSweepGC : ParNew + CMS + Serial Old.
    • CMS is used most of the time to collect the old generation. Serial Old is used when a concurrent mode failure occurs.
  • UseParallelGC : Parallel Scavenge + Parallel Old
  • UseG1GC : G1 GC for both generations

Collectors

Mark-Sweep-Compact Collector
  • -XX:+UseSerialGC or –XX:+UseParNewGC selects Serial Old collector for old generation
  • Stop-the-world old generation collector.
  • Old is collected using mark-sweep-compact.
  • Mark phase: marks all live objects.
  • Sweep phase: sweeps over the heap identifying garbage.
  • Slide phase: the GC performs a sliding compaction, sliding the live objects towards the start of the Heap.
Parallel Collector
  • -XX:+UseParallelGC
    • Young Generation collected with Parallel Scavenge
    • Old Generation collected with Parallel collector
  • It is also called the throughput collector
  • Stop-the-world collections
  • Default on Server type machines up until JDK 9
  • Collection is performed in parallel on multiple cores
Concurrent Mark Sweep Collector (CMS)
  • -XX:+UseConcMarkSweepGC
    • Young gen – ParNew collector
    • Old gen – CMS collector
  • Low-latency collector, Mostly concurrent
  • No heap compaction – fragmentation
  • Free lists link unallocated regions
  • Allocations expensive as compared to bump-the-pointer allocations
  • Additional overhead on young collections
  • Larger heap size requirement and floating garbage
  • Deprecated in Java 9
G1 Collector
  • Server-style garbage collector, targeted for multi-processor machines with large memories
  • Meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput.
  • Better GC ergonomics
  • Low pauses without fragmentation
  • Parallelism and concurrency in collections
  • G1 is a compacting collector.
  • Fully supported in Oracle JDK 7 update 4 and later releases
  • Default collector in JDK 9

References