SlideShare a Scribd company logo
Mastering GC: tame the beast and make it
your best ally
Jean-Philippe Bempel
@jpbempel
Agenda
● OpenJDK GCs
● Selecting the right GC
● Tuning GC
OpenJDK GCs
Serial GC
● Generational
● Single threaded
● Stop-The-World
● Default GC for < 2GB or < 2 cores
Spaces & generations
Semi-spaces: Survivors
Young Old
Eden S0 S1
Young
Live objects
Dead objects
5
5
1
1
Parallel GC
● Generational
● Multi threaded
● Stop-The-World
Minor GC marking
Young Old
Live objects
Dead objects
Remember Set: Card Table
Young 0 0 1
Live objects
Dead objects
G1 GC
● Generational
● Multi threaded
● Stop-The-World/Concurrent
● Region based
Regions
Regions
Credit: Kirk Pepperdine
● Memory reclaimed by evacuation of a region (copying objects/compacting)
● Limiting copy and focus on regions with most garbage => G1
● When evacuating objects, you update refs, but avoid scanning the full heap
● Using RememberSet to know which region to scan for refs
Regions
RememberSet
Shenandoah GC
● Not generational (single space)
● Fully Concurrent
● Region based
Concurrent Evacuation: challenges
● How to make sure we can reach an object that is evacuating?
● Read (Load) Barrier
○ Everytime we are loading an object to access it, we check if we need to find it elsewhere or not
● Self-Healing
○ Application thread can help fix addresses not yet fixed by GC threads
Z GC
● Not generational (yet)
● Fully Concurrent
● Region based
Colored pointers
● Store metadata in unused bits of reference address
● 44 bits for addressing 16TB
(Max Heap)
● 4 bits for metadata:
○ Marked0
○ Marked1
○ Remapped
○ Finalizable
Selecting the right GC
Identify your workload: Throughput oriented
● Jobs, processing by steps
● High volume of data
● No response to a human user
● Examples: Spark jobs, Kafka consumer/producer, intakes, ETL, …
Identify your workload: Latency sensitive
● Application based on Request/Response
● Response to human user, even indirect (microservices dependencies)
● Databases
● Examples: Http/gRPC services, Cassandra
Throughput oriented: Which GC?
● JDK Flight Recorder (JFR) files
● Use JDK Mission Control Library for parsing round robin fashion
● Metric: total runtime of a predefined number of JFR files processed
Throughput oriented: Which GC?
Throughput oriented: Analysis G1
Throughput oriented: Analysis G1
Throughput oriented: Analysis Parallel
Throughput oriented: Analysis Parallel
Latency sensitive: Which GC?
● Spring petclinic demo app
● Send requests and waiting for response
● Metric: Percentiles of latency of each request
Latency sensitive: Which GC?
Latency sensitive: Which GC?
Tuning GC
Tuning Parallel GC
● Very simple to reason about
● Main goal: avoid promoting short/middle lived object to postpone Full GC
● Adjust young gen to reach this goal depending on your workload
● Don’t hesitate to increase the young gen sometimes > 50% of the heap
Tuning Parallel GC
Tuning G1: Humongous
● Humongous objects are difficult to handle for G1:
○ Creates fragmentation
○ Cannot move
○ Triggers prematurely GC b/c checked during each Humongous alloc
● GC Cause = Humongous allocation
○ Try to adjust HeapRegionSize to reduce Humongous objects
○ But large objects not Humongous need to be moved, may increase pause time…
○ Cannot do if regions are already 32MB…
Tuning G1: Humongous
Tuning G1: Young Gen Resize
● Resize based on target pause time:
○ Increase if pause time < target
○ Decrease if pause time > target
● Goal overshoot leads to aggressive young gen reduction down to 5%:
○ Short young gen generates very frequent Young GC
○ This storm can lead to over promotion/copy of objects and increase of pause time
○ More frequent GCs + significant pause time => worse than overshooting the initial goal
● Use NewSize/MaxNewSize for min and max Young Gen
○ But not NewRatio or Xmn which will fix the Young Gen
Tuning G1: Target pause time
● Main knob for G1 to tune is MaxGCPauseMillis as Target Pause time
● Increase target pause for more throughput (accepting more pause time)
● Decrease target pause time for more low latency, but below 50ms it’s difficult…
Tuning Shenandoah
● To be effective, allocation rate should not overrun the GC
● Otherwise => Pacer or Full GC
● Need heap headroom for having time to collect and reclaim regions
● cores/Conc Gc threads for finishing cycle faster
● Region reclaim is done at the end of the GC cycle
Tuning Z
● To be effective, allocation rate should not overrun the GC
● Otherwise “Allocation Stall” but No Full GC
● Need heap headroom for having time to collect and reclaim regions
● cores/Conc Gc threads for finishing cycle faster
● Region reclaim is done as soon as relocation is done
Conclusion
How to choose a GC?
● Throughput oriented workload
○ Parallel GC
○ G1 if no issue and good figures
● Latency sensitive workload
○ Shenandoah
○ Z
○ C4
Why not G1?
● Complexity of the heuristic make it difficult to tune
● Couple of things can go wrong:
○ Fragmentation leading to FullGC, not all Old region are considered
○ RememberSet granularity, Post-Write Barrier, Refinement Threads
○ Evacuation failure (=> full GC), InitiatingHeapOccupancyPercent, G1ReservePercent
○ Young Gen dynamic sizing, drastic reduction leads to minor GC storm
○ Humongous allocations, premature minor GC and fragmentation
● G1 Heuristic can save you or can curse you!
References
References
Understanding low latency GCs
G1 One Garbage Collector to rule them all
Tips for Tuning The G1 GC
G1 Garbage Collector Details and Tuning
What’s the deal with humongous objects in Java?
Shenandoah: The Garbage Collector That Could
Load Reference Barriers
Eliminating forward pointer word
Concurrent GC collectors: ZGC & Shenandoah
Deep Dive into ZGC: A Modern Garbage Collector in OpenJDK
GCEasy.io

More Related Content

PPTX
Databricks Platform.pptx
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
PPTX
Diabetes Mellitus
PPTX
Hypertension
PPTX
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
PPTX
Power Point Presentation on Artificial Intelligence
PDF
Caça palavras - Bullying
Databricks Platform.pptx
Testing with JUnit 5 and Spring - Spring I/O 2022
Diabetes Mellitus
Hypertension
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
Power Point Presentation on Artificial Intelligence
Caça palavras - Bullying

What's hot (20)

PDF
[오픈소스컨설팅]Java Performance Tuning
PDF
[Meetup] a successful migration from elastic search to clickhouse
PDF
Secrets of Performance Tuning Java on Kubernetes
PDF
[오픈소스컨설팅]Tomcat6&7 How To
PDF
Ninja Build: Simple Guide for Beginners
PPTX
Capabilities for Resources and Effects
PPT
Red Hat Ansible 적용 사례
PPTX
Apache Flink in the Cloud-Native Era
PPTX
Node.js + Websocket 삽질기
PDF
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
PDF
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
PDF
Dongwon Kim – A Comparative Performance Evaluation of Flink
PDF
Trend Micro Big Data Platform and Apache Bigtop
PDF
리텐션의 산출과 활용
PDF
Backup and-recovery2
PDF
gRPC vs REST: let the battle begin!
PPTX
Flexible and Real-Time Stream Processing with Apache Flink
PDF
[Outdated] Secrets of Performance Tuning Java on Kubernetes
PDF
Facebook은 React를 왜 만들었을까?
PDF
Apache Flink Worst Practices
[오픈소스컨설팅]Java Performance Tuning
[Meetup] a successful migration from elastic search to clickhouse
Secrets of Performance Tuning Java on Kubernetes
[오픈소스컨설팅]Tomcat6&7 How To
Ninja Build: Simple Guide for Beginners
Capabilities for Resources and Effects
Red Hat Ansible 적용 사례
Apache Flink in the Cloud-Native Era
Node.js + Websocket 삽질기
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
HBaseCon 2015: Taming GC Pauses for Large Java Heap in HBase
Dongwon Kim – A Comparative Performance Evaluation of Flink
Trend Micro Big Data Platform and Apache Bigtop
리텐션의 산출과 활용
Backup and-recovery2
gRPC vs REST: let the battle begin!
Flexible and Real-Time Stream Processing with Apache Flink
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Facebook은 React를 왜 만들었을까?
Apache Flink Worst Practices
Ad

Similar to Mastering GC.pdf (20)

PDF
hbaseconasia2017: HBase Practice At XiaoMi
PDF
The Dark Side Of Go -- Go runtime related problems in TiDB in production
ODP
Hotspot gc
PPTX
Progress_190130
PPTX
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
PDF
Solving Multi-tenancy and G1GC in Apache HBase
PDF
Solving Multi-tenancy and G1GC in Apache HBase
PPTX
Memory in go
PPTX
Avoiding Catastrophic Performance Loss
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
PDF
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
PDF
Kubernetes Workload Rebalancing
PPTX
Progress_190118
PDF
Mongodb meetup
PDF
J9 Balanced GC
PDF
How to build TiDB
PPTX
Efficient Buffer Management
ODP
Gc algorithms
PDF
Low latency stream processing with jet
PDF
Retaining Goodput with Query Rate Limiting
hbaseconasia2017: HBase Practice At XiaoMi
The Dark Side Of Go -- Go runtime related problems in TiDB in production
Hotspot gc
Progress_190130
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Solving Multi-tenancy and G1GC in Apache HBase
Solving Multi-tenancy and G1GC in Apache HBase
Memory in go
Avoiding Catastrophic Performance Loss
G1 Garbage Collector - Big Heaps and Low Pauses?
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Kubernetes Workload Rebalancing
Progress_190118
Mongodb meetup
J9 Balanced GC
How to build TiDB
Efficient Buffer Management
Gc algorithms
Low latency stream processing with jet
Retaining Goodput with Query Rate Limiting
Ad

More from Jean-Philippe BEMPEL (18)

PDF
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
PDF
Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...
PDF
Tools in action jdk mission control and flight recorder
PDF
Understanding JVM GC: advanced!
PDF
Understanding low latency jvm gcs V2
PDF
Understanding low latency jvm gcs
PDF
Understanding jvm gc advanced
PPTX
Clr jvm implementation differences
PDF
Le guide de dépannage de la jvm
PDF
Out ofmemoryerror what is the cost of java objects
PDF
OutOfMemoryError : quel est le coût des objets en java
PDF
Low latency & mechanical sympathy issues and solutions
PDF
Lock free programming - pro tips devoxx uk
PDF
Lock free programming- pro tips
PDF
Programmation lock free - les techniques des pros (2eme partie)
PDF
Programmation lock free - les techniques des pros (1ere partie)
PDF
Measuring directly from cpu hardware performance counters
PDF
Devoxx france 2014 compteurs de perf
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Devoxx Fr 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneu...
Tools in action jdk mission control and flight recorder
Understanding JVM GC: advanced!
Understanding low latency jvm gcs V2
Understanding low latency jvm gcs
Understanding jvm gc advanced
Clr jvm implementation differences
Le guide de dépannage de la jvm
Out ofmemoryerror what is the cost of java objects
OutOfMemoryError : quel est le coût des objets en java
Low latency & mechanical sympathy issues and solutions
Lock free programming - pro tips devoxx uk
Lock free programming- pro tips
Programmation lock free - les techniques des pros (2eme partie)
Programmation lock free - les techniques des pros (1ere partie)
Measuring directly from cpu hardware performance counters
Devoxx france 2014 compteurs de perf

Recently uploaded (20)

PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
assetexplorer- product-overview - presentation
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
assetexplorer- product-overview - presentation
Designing Intelligence for the Shop Floor.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Computer Software and OS of computer science of grade 11.pptx
Advanced SystemCare Ultimate Crack + Portable (2025)
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Download FL Studio Crack Latest version 2025 ?
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Design an Analysis of Algorithms II-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
iTop VPN Crack Latest Version Full Key 2025
Monitoring Stack: Grafana, Loki & Promtail
Design an Analysis of Algorithms I-SECS-1021-03
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025

Mastering GC.pdf

  • 1. Mastering GC: tame the beast and make it your best ally Jean-Philippe Bempel @jpbempel
  • 2. Agenda ● OpenJDK GCs ● Selecting the right GC ● Tuning GC
  • 4. Serial GC ● Generational ● Single threaded ● Stop-The-World ● Default GC for < 2GB or < 2 cores
  • 6. Semi-spaces: Survivors Young Old Eden S0 S1 Young Live objects Dead objects 5 5 1 1
  • 7. Parallel GC ● Generational ● Multi threaded ● Stop-The-World
  • 8. Minor GC marking Young Old Live objects Dead objects
  • 9. Remember Set: Card Table Young 0 0 1 Live objects Dead objects
  • 10. G1 GC ● Generational ● Multi threaded ● Stop-The-World/Concurrent ● Region based
  • 13. ● Memory reclaimed by evacuation of a region (copying objects/compacting) ● Limiting copy and focus on regions with most garbage => G1 ● When evacuating objects, you update refs, but avoid scanning the full heap ● Using RememberSet to know which region to scan for refs Regions
  • 15. Shenandoah GC ● Not generational (single space) ● Fully Concurrent ● Region based
  • 16. Concurrent Evacuation: challenges ● How to make sure we can reach an object that is evacuating? ● Read (Load) Barrier ○ Everytime we are loading an object to access it, we check if we need to find it elsewhere or not ● Self-Healing ○ Application thread can help fix addresses not yet fixed by GC threads
  • 17. Z GC ● Not generational (yet) ● Fully Concurrent ● Region based
  • 18. Colored pointers ● Store metadata in unused bits of reference address ● 44 bits for addressing 16TB (Max Heap) ● 4 bits for metadata: ○ Marked0 ○ Marked1 ○ Remapped ○ Finalizable
  • 20. Identify your workload: Throughput oriented ● Jobs, processing by steps ● High volume of data ● No response to a human user ● Examples: Spark jobs, Kafka consumer/producer, intakes, ETL, …
  • 21. Identify your workload: Latency sensitive ● Application based on Request/Response ● Response to human user, even indirect (microservices dependencies) ● Databases ● Examples: Http/gRPC services, Cassandra
  • 22. Throughput oriented: Which GC? ● JDK Flight Recorder (JFR) files ● Use JDK Mission Control Library for parsing round robin fashion ● Metric: total runtime of a predefined number of JFR files processed
  • 28. Latency sensitive: Which GC? ● Spring petclinic demo app ● Send requests and waiting for response ● Metric: Percentiles of latency of each request
  • 32. Tuning Parallel GC ● Very simple to reason about ● Main goal: avoid promoting short/middle lived object to postpone Full GC ● Adjust young gen to reach this goal depending on your workload ● Don’t hesitate to increase the young gen sometimes > 50% of the heap
  • 34. Tuning G1: Humongous ● Humongous objects are difficult to handle for G1: ○ Creates fragmentation ○ Cannot move ○ Triggers prematurely GC b/c checked during each Humongous alloc ● GC Cause = Humongous allocation ○ Try to adjust HeapRegionSize to reduce Humongous objects ○ But large objects not Humongous need to be moved, may increase pause time… ○ Cannot do if regions are already 32MB…
  • 36. Tuning G1: Young Gen Resize ● Resize based on target pause time: ○ Increase if pause time < target ○ Decrease if pause time > target ● Goal overshoot leads to aggressive young gen reduction down to 5%: ○ Short young gen generates very frequent Young GC ○ This storm can lead to over promotion/copy of objects and increase of pause time ○ More frequent GCs + significant pause time => worse than overshooting the initial goal ● Use NewSize/MaxNewSize for min and max Young Gen ○ But not NewRatio or Xmn which will fix the Young Gen
  • 37. Tuning G1: Target pause time ● Main knob for G1 to tune is MaxGCPauseMillis as Target Pause time ● Increase target pause for more throughput (accepting more pause time) ● Decrease target pause time for more low latency, but below 50ms it’s difficult…
  • 38. Tuning Shenandoah ● To be effective, allocation rate should not overrun the GC ● Otherwise => Pacer or Full GC ● Need heap headroom for having time to collect and reclaim regions ● cores/Conc Gc threads for finishing cycle faster ● Region reclaim is done at the end of the GC cycle
  • 39. Tuning Z ● To be effective, allocation rate should not overrun the GC ● Otherwise “Allocation Stall” but No Full GC ● Need heap headroom for having time to collect and reclaim regions ● cores/Conc Gc threads for finishing cycle faster ● Region reclaim is done as soon as relocation is done
  • 41. How to choose a GC? ● Throughput oriented workload ○ Parallel GC ○ G1 if no issue and good figures ● Latency sensitive workload ○ Shenandoah ○ Z ○ C4
  • 42. Why not G1? ● Complexity of the heuristic make it difficult to tune ● Couple of things can go wrong: ○ Fragmentation leading to FullGC, not all Old region are considered ○ RememberSet granularity, Post-Write Barrier, Refinement Threads ○ Evacuation failure (=> full GC), InitiatingHeapOccupancyPercent, G1ReservePercent ○ Young Gen dynamic sizing, drastic reduction leads to minor GC storm ○ Humongous allocations, premature minor GC and fragmentation ● G1 Heuristic can save you or can curse you!
  • 44. References Understanding low latency GCs G1 One Garbage Collector to rule them all Tips for Tuning The G1 GC G1 Garbage Collector Details and Tuning What’s the deal with humongous objects in Java? Shenandoah: The Garbage Collector That Could Load Reference Barriers Eliminating forward pointer word Concurrent GC collectors: ZGC & Shenandoah Deep Dive into ZGC: A Modern Garbage Collector in OpenJDK GCEasy.io