Java GC Tutorials - Herong's Tutorial Examples

Copyright © 2022 Dr. Herong Yang. All rights reserved.

Java GC Tutorials This book is a collection of tutorial notes and sample codes written by the author while he was learning JVM GC (Garbage Collection) processes. Topics include Java Garbage Collectors, STW (Stop-The-World), Serial Collector, Parallel Collector, Concurrent Collector, G1 Collector, GC Algorithms, Generational GC, Regional GC, Heap Memory Management, Young/New Generation, Tenured/Old Generation, Object Reference, Eden Space, Survivor Spaces, Minor GC, Major GC, Full GC, Performance Tuning, Throughput/Latency Performance, Heap Footprint. Updated in 2022 (Version v1.11) with JVM 17.

Table of Contents

About This Book

Heap Memory Area and Size Control

Java Exception: "java.lang.OutOfMemoryError: Java heap space"

Memory Allocation Limits on Windows Systems

OutOfMemoryError Comparison of HotSpot and JRockit

JVM Garbage Collection Logging

Garbage Collection Demo Program

Garbage Collection Logging Options

"-Xlog:gc" - Default GC Logging Level: INFO

"-Xlog:gc=trace" - Lowest GC Logging Level: TRACE

"-Xlog:gc+heap=trace" - GC+HEAP Log Messages

"-Xlog:gc*=trace" - Maximum GC Logging

"-XX:+PrintFlagsFinal" - Print JVM Options

Introduction of Garbage Collectors

JVM Memory Manager - Garbage Collector

Generational Garbage Collection in HotSpot

Young Generation Collection - Minor GC

Young Generation Collectors - Serial, PS, ParNew, G1

Tenured Generation Collection - Major GC

Tenured Generation Collectors - Serial, ParOldGen, CMS, G1

Collector Combinations: Serial, Parallel, Concurrent, G1, Z

Serial Collector - "+XX:+UseSerialGC"

What Is Serial Collector

GC Log Message Format for Serial Collector

GC Log Message Examples of Serial Collector

Log Message Types from Serial Collector

Serial Collector Stops Application for Minor/Major GC

Usage Report on Heap Memory Areas

Default NewRatio - Old vs. New Generation

"-XX:NewRatio" - Ratio of Tenured and "new" Generation

"-XX:SurvivorRatio" - Ratio of Eden and Survivor Space

Serial GC Tracing - Tight Heap

Serial GC Tracing - Tight Heap (Part 2)

Serial GC Tracing - Tight Heap (Part 3)

Serial GC Tracing - Plenty of Heap

Serial GC Tracing - Aged Live Objects

Serial GC Tracing - Tenuring Threshold

"-XX:TargetSurvivorRatio" - Second Tenuring Condition

Serial GC Tracing - Tenuring Threshold Controlled

"-XX:+NeverTenure" and "-XX:+AlwaysTenure" Working

Minor GC Triggering Condition of Serial Collector

Parallel Collector - "+XX:+UseParallelGC"

What Is Parallel Collector

Parallel Collector GC Log Message Format

Log Message Types from Parallel Collector

"--Xlog:gc+task+time=debug" - Print GC Threads

"-XX:ParallelGCThreads" - # of Threads

Parallel Collector Stops Application for Minor/Major GC

PSYoungGen Collector Using Tenuring Age

Parallel Collector Changing NewRatio and SurvivorRatio

Parallel Collector Adaptive Size Policy

Adaptive Size Policy Log Messages

"-Xlog:gc+ergo=trace" - Minor GC Report

Adaptive Size Policy Changed Survivor Space

Adaptive Size Policy Changed Eden Space

Adaptive Size Policy for Best Latency

Parallel Collector Stopped using Young Generation

Adaptive Size Policy for Best Throughput

Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

What Is Concurrent Mark-Sweep (CMS) Collector

Concurrent Mark-Sweep Collector GC Log Message Format

Reduce Stop-The-World with Concurrent Mark and Sweep

Parallel New (ParNew) Collector for Minor GC

ParNew Collector - Tenuring Age Distribution

Maximum Logging of All Phases on Young GC

"-XX:ParallelGCThreads=6" - Young GC Parallel Threads

"-XX:MaxTenuringThreshold=0" - Tenuring Objects Immediately

"-XX:CMSInitiatingOccupancyFraction=20" - Initiate CMS

Maximum Logging of All Phases on Old GC

Maximum Logging of All Phases on Full GC

"-XX:ParallelGCThreads=6" - Old GC Parallel Threads

"-XX:ConcGCThreads=3" - Old GC Concurrent Threads

Garbage First (G1) Collector - "+XX:+UseG1GC"

The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

Object References and Garbage Collection

Garbage Collection Performance Test Program - GC Performance Test Program - Program Output

Performance Impact of Wait Time

Performance Impact of Object Size

Performance Impact of Chunk Size

Performance Jumps Not Related to GC

Performance Test and System Interruptions

"START /REALTIME" - Run JVM with Highest Priority - 99th Percentile Performance - Output Verification - Percentile Performance with Load - Work Load Level - Object Number and Size

Performance Tests on Serial Collector

Performance Tests on Parallel collector

Performance Tests on Concurrent collector

Performance Tests on G1 collector

Garbage Collection Performance Test Summary

General Suggestions for Better GC Performance


Full Version in PDF/EPUB

Keywords: Java, Virtual, Machine, JVM, GC, Garbage Collection