SlideShare a Scribd company logo
Have You Really Taken the Time to Know Me?
- A G1 GC Saga
@mon_beck
By: Monica Beckwith
Agenda Introduction to G1 GC
GC Trifecta for Performance
G1 GC Performance Optimizations
Introduction to G1 GC
Regions and Generations
Heap
Young Generation Old Generation
Regionalized Heap
Generational Heap
Generational Regionalized Heap
G1 GC: A Regionalized, Generational Collector
• List of free regions
• The occupied regions could be young, old or humongous
An Occupied Region
A Free Region
Occupied and Free Regions
Young, Old and Humongous
An Occupied Young Region
A Free Region
An Occupied Old Region
An Occupied Humongous Region
Young Regions - Regions that contain objects in the Eden and Survivor Spaces
Old Regions - Regions that contain objects in the Old generation.
Humongous Regions - Regions that contain Humongous Objects.
G1 GC Phases
• On allocation failures, G1 GC performs young collections
• When the marking threshold (IHOP) is crossed, G1 GC starts a
concurrent marking cycle
• The concurrent marking cycle has a few STW phases such as Initial
Mark, Remark and Cleanup
• Finally, G1 can decide on the fly if mixed collections are need and also
decide on the count target for collections
0
30
60
90
120
150
3415 3416.3 3417.2 3418.4 3419 3422 3423.4 3432.2 3433.2 3436.8 3437.6 3438.9 3440
Pause
time
in
milliseconds
Timestamps
Young Collection Initial Mark Remark Cleanup Mixed Collection
Occupancy == Initiating Heap
Occupancy Percent
G1 GC Pause Histogram
An Occupied Young Region
A Free Region
An Occupied Old Region
An Occupied Humongous Region
A Young Collection and its Collection Set
Young Collection Set = {a,b,c,d,e}
d
c
b
a
e
g
f
An Occupied Young Region
A Free Region
An Occupied Old Region
An Occupied Humongous Region
A Mixed Collection
Young Collection Set = {a,b,c,d,e}
Old Collection Set = {f,g}
Mixed Collection Set = {Young Collection Set, Old Collection Set}
= {a,b,c,d,e,f,g}
d
c
b
a
e
GC Trifecta for Application Performance
Footprint, Responsiveness and Throughput!
How can I fit in more data?
OR
How can I optimize the maintenance
overhead?
Footprint
Native Memory Tracking
-XX:NativeMemoryTracking=summary
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintNMTStatistics
Total: reserved=5607369KB, committed=350057KB
- Java Heap (reserved=4057088KB, committed=253952KB)
(mmap: reserved=4057088KB, committed=253952KB)
- Class (reserved=8368KB, committed=6064KB)
…
- Thread (reserved=23605KB, committed=1097KB)
…
- Code (reserved=247967KB, committed=7771KB)
…
- GC (reserved=201335KB, committed= 60103KB)
(malloc=17463KB #1035)
(mmap: reserved=183872KB, committed=42640KB)
…
Native
Memory
Tracking
Summary for
G1 GC:
NMT GC Info Serial GC Parallel GC G1 GC Z GC Shenandoah
GC
Reserved 13,277KB 177,138KB 201,335KB 8,463,552KB 131,872KB
Committed 917KB 164,726KB 60,103KB 107,712KB 8,936KB
Malloc 29KB 28,850KB 17,463KB 9,344KB 4,448KB
Mmap,
Reserved
13,248KB 148,288KB 183,872KB 8,454,208KB 127,424KB
Mmap,
Commited
888KB 135,876KB 42,640KB 98,368KB 4,488KB
GC Footprint – OpenJDK JDK 11 LTS Out of the Box
NMT GC Info Serial GC Parallel GC G1 GC Z GC Shenandoah
GC
Reserved 6,941KB 105,586KB 133,128KB 8,461,466KB 70,215KB
Committed 6,881KB 105,506KB 133,128KB 105,626KB 37,387KB
Malloc 29KB 28,850KB 22,088KB 7,258KB 4,359KB
Mmap,
Reserved
6,912KB 76,736KB 111,040KB 8,454,208KB 65,856KB
Mmap,
Commited
888KB 76,656KB 111,040KB 98,368KB 33,028KB
GC Footprint – Xmx = Xms = 2G
Data
structures for
generational
GCs
Concurrent
Marking
Maintenance
Regionalized
Heap
Maintenance
Concurrent
Copying
Maintenance
Footprint
If I send a stimulus now, how much time ’til I get a response back?
Application Responsiveness
Application
timeline
Stimulus
arrival
Response
sent
T0 T1
Application Responsiveness
Application
timeline
Stimulus
arrival
Response
sent
Application Responsiveness
T0 T1 T2
GC Elapsed Time indicated the amount of time it takesto execute stop the world (STW) GC
events
The higher the GC elapsed time - the lower the application responsiveness due to the GC induced
latencies
Increase Application Responsiveness by Reducing GC Elapsed Time
How can I maximize the operations per second of
my system?
Throughput
Response
sent
Application
timeline
Stimulus
arrival
T0 T1
Throughput
Application
timeline
Stimulus
arrival
Response
sent
T0 T1 T2
Application
timeline
T0 T1
Throughput
Application
timeline
T0 T1 T2
Overhead is an indication of the frequency of stop the world GC events.
The more frequent the GC events - The more likely it is to negatively impact application
throughput
Increase Application Throughput by Reducing GC Overhead
G1 GC Performance Optimizations
G1 GC
Footprint
Optimizations
Compact Strings and String Deduplication:
JEP 254: Compact Strings
JEP 192: String Deduplication in G1
Java Lang String with Java Object Layout – JDK 8
$ jdk8/bin/java -jar jol-cli-latest.jar footprint java.lang.String
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 0x0000000800000000 base address and 0-bit shift.
# Objects are 8 bytes aligned.
Instantiated the sample instance via default constructor.
java.lang.String@1761e840d footprint:
COUNT AVG SUM DESCRIPTION
1 16 16 [C
1 24 24 java.lang.String
2 40 (total)
string1 = “Happy”
String 1
Object
Char[]
Java String Object – JDK 8
java.lang.String object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) c2 02 00 f8 (11000010 00000010 00000000 11111000) (-
134217022)
12 4 char[] String.value []
16 4 int String.hash 0
20 4 (loss due to the next object alignment)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
Java String Object – JDK 9+; Hello Compact Strings!
java.lang.String object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 05 00 00 00 (00000101 00000000 00000000 00000000) (5)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) 08 18 00 00 (00001000 00011000 00000000 00000000) (6152)
12 4 byte[] String.value []
16 4 int String.hash 0
20 1 byte String.coder 0
21 3 (loss due to the next object alignment)
Instance size: 24 bytes
Space losses: 0 bytes internal + 3 bytes external = 3 bytes total
Trivia: Java String Object – JDK 13+; Hello Boolean!
java.lang.String object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1)
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0)
8 4 (object header) f8 20 00 00 (11111000 00100000 00000000 00000000) (8440)
12 4 int String.hash 0
16 1 byte String.coder 0
17 1 boolean String.hashIsZero false
18 2 (alignment/padding gap)
20 4 byte[] String.value []
Instance size: 24 bytes
Space losses: 2 bytes internal + 0 bytes external = 2 bytes total
Java String Literals – JDK 8
String string1 = “Happy”; string1 = “Happy”
String 1
Object
00
string2 = “”
String 2
Object
70 00 70 00 79
00 61
00 48
Char[] = 26 3A
Char[] =
String string2 = “”;
Java String Literals – JDK 9+
String string1 = “Happy”; string1 = “Happy”
String 1
Object
string2 = “”
String 2
Object
70 70 79
61
48
Byte[] = 26 3A
Byte[] =
String string2 = “”;
Java String Deduplication in G1
string1 = “”
String 1
Object
Byte[]
string2 = “”
String 2
Object
What if string1.equals(string2)?
G1 GC
Footprint
Optimizations
Other Significant Optimizations
G1 GC Footprint Optimizations
 Remembered Sets Space Reductions
 Old Gen On NVDIMM
 Dynamic GC Threads with Lower Heap Size Per Thread
 Early reclamation of large objects in G1
G1 GC
Responsiveness
Optimizations
Periodic GC:
JEP 346: Promptly Return Unused
Committed Memory from G1
GC(34) Pause Young (Prepare Mixed) (G1 Evacuation Pause) 6097M->5571M(15360M) 120.948ms
…
GC(245) Pause Young (Mixed) (G1 Evacuation Pause) 5879M->4794M(15360M) 113.676ms
…
GC(318) Pause Young (Mixed) (G1 Evacuation Pause) 11349M->9046M(15360M) 113.040ms
…
GC(354) Pause Young (Mixed) (G1 Evacuation Pause) 8881M->7022M(15360M) 409.969ms
GC(34) Pause Young (Concurrent Start) (G1 Periodic Collection) 8M->0M(5120M) 5.693ms
…
GC(158) Pause Young (Concurrent Start) (G1 Periodic Collection) 254M->213M(5120M) 169.579ms
…
GC(201) Pause Young (Mixed) (G1 Periodic Collection) 1904M->1713M(7168M) 168.510ms
…
GC(232) Pause Young (Mixed) (G1 Periodic Collection) 3141M->2949M(12456M) 286.378ms
Without Periodic GC
With Periodic GC; -XX:G1PeriodicGCInterval=15
G1 GC
Responsiveness
Optimizations
Parallel Reference Processing:
Make parallel reference processing
default for G1
Single Threaded Reference Processing
G1 GC
Responsiveness
Optimizations
Abortable Mixed Collections:
JEP 344: Abortable Mixed Collections for G1
Start adding old regions to collection set. Min 116 regions, max 192 regions, time remaining
114.00ms, optional threshold 22.80ms
Finish adding old regions to collection set (Predicted time too high).
Finish choosing collection set old regions. Initial: 116, optional: 15, predicted old time: 0.00ms,
predicted optional time: 15.31ms, time remaining: 0.00
…
Prepared 7 regions out of 15 for optional evacuation. Predicted time: 8.083ms
…
Prepared 7 regions out of 8 for optional evacuation. Predicted time: 8.252ms
…
Prepared 1 regions out of 1 for optional evacuation. Predicted time: 1.119ms
…
Merge Optional Heap Roots: 2.0ms
Evacuate Optional Collection Set: 12.7ms
G1 GC Log with GC + Ergo = Debug
GC(264) Pause Young (Mixed) (G1 Evacuation Pause)
GC(264) Merge Optional Heap Roots: 0.2ms
GC(264) Prepare Optional Merge Heap Roots: 0.0ms
GC(264) Optional Remembered Sets (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.4,
Workers: 5
…
GC(264) Evacuate Optional Collection Set: 16.4ms
GC(264) Optional Scan Heap Roots (ms): Min: 0.0, Avg: 1.6, Max: 4.9, Diff: 4.9, Sum: 68.9,
Workers: 43
…
GC(264) Optional Object Copy (ms): Min: 0.0, Avg: 3.0, Max: 5.2, Diff: 5.1, Sum: 128.7, Workers: 43
GC(264) Optional Code Root Scan (ms): Min: 0.0, Avg: 0.3, Max: 14.3, Diff: 14.3, Sum: 14.3,
Workers: 43
GC(264) Optional Termination (ms): Min: 0.2, Avg: 10.3, Max: 10.7, Diff: 10.5, Sum: 443.3, Workers:
43
G1 GC Log with GC + Phases = Debug
G1 GC
Responsiveness
Optimizations
Other Significant Optimizations
G1 GC Responsiveness Optimizations
 Improvements in Remembered Sets Scanning
 Rebuild Remembered Sets During the Concurrent Cycle
 Reduce Barrier Overhead
 Adaptive Initiating Heap Occupancy Percent (IHOP)
G1 GC
Throughput
Optimizations
Adaptive IHOP
(Initiating Heap Occupancy Percentage):
Adaptive sizing for IHOP in G1
Fixed IHOP
-XX:-G1UseAdaptiveIHOP
Adaptive IHOP
-XX:+G1UseAdaptiveIHOP
G1 GC
Throughput
Optimizations
Parallel Full GC:
JEP 307: Parallel Full GC for G1
G1 GC Parallel Full GC
G1 GC
Throughput
Optimizations
Cleanup Phase Improvements:
 Remove concurrent cleanup and
secondary free list handling
Due to the ability to rebuild remembered sets during a concurrent cycle, G1 can
now get rid of the concurrent cleanup and any overhead associated with it
Regions full of garbage can now be freed during a Remark pause
•Remark phase*: This phase is STW collection and helps the completion of the
marking cycle. G1 GC drains SATB buffers, traces unvisited live objects, and
performs reference processing.
•Cleanup phase*: In this final phase, the G1 GC performs the STW operations of
accounting and RSet scrubbing.
•During accounting, the G1 GC identifies completely free regions and mixed
garbage collection candidates.
•The cleanup phase is partly concurrent when it resets and returns the empty
regions to the free list.
* https://www.oracle.com/technical-resources/articles/java/g1gc.html
G1 GC
Throughput
Optimizations
Other Significant Optimizations
G1 GC Throughput Optimizations
 Ergonomic Heap Region Resizing
 Parallel Pretouch
 Rebuild Remembered Sets During the Concurrent Cycle
 Remove Unnecessary Barriers during Object Copy
© Copyright Microsoft Corporation. All rights reserved.
References:
https://www.slideshare.net/MonicaBeckwith
https://tschatzl.github.io/2020/09/01/jdk15-g1-parallel-gc-changes.html
https://docs.oracle.com/en/java/javase/14/gctuning/garbage-first-g1-garbage-collector1.html
https://github.com/openjdk/jol

More Related Content

What's hot

Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performance
Daum DNA
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Jignesh Shah
 

What's hot (20)

RedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ TwitterRedisConf17- Using Redis at scale @ Twitter
RedisConf17- Using Redis at scale @ Twitter
 
Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!Garbage First Garbage Collector: Where the Rubber Meets the Road!
Garbage First Garbage Collector: Where the Rubber Meets the Road!
 
Transaction Management on Cassandra
Transaction Management on CassandraTransaction Management on Cassandra
Transaction Management on Cassandra
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performance
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight Overview
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
 
Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David Anderson
 
Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...
Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...
Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...
 
Z Garbage Collector
Z Garbage CollectorZ Garbage Collector
Z Garbage Collector
 
Enabling Vectorized Engine in Apache Spark
Enabling Vectorized Engine in Apache SparkEnabling Vectorized Engine in Apache Spark
Enabling Vectorized Engine in Apache Spark
 
Kafka PPT.pptx
Kafka PPT.pptxKafka PPT.pptx
Kafka PPT.pptx
 
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
Multi cluster, multitenant and hierarchical kafka messaging service   slideshareMulti cluster, multitenant and hierarchical kafka messaging service   slideshare
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
 
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
 
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
The Missing Manual for Leveled Compaction Strategy (Wei Deng & Ryan Svihla, D...
 
Battle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBootBattle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBoot
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
 
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series Workloads
 

Similar to A G1GC Saga-KCJUG.pptx

Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Jayesh Thakrar
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
Tier1 App
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
Kai Koenig
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
Bin Shao
 

Similar to A G1GC Saga-KCJUG.pptx (20)

Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
 
Jvm heap
Jvm heapJvm heap
Jvm heap
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & Diagnostics
 
Low pause GC in HotSpot
Low pause GC in HotSpotLow pause GC in HotSpot
Low pause GC in HotSpot
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
 
Jvm tuning for low latency application & Cassandra
Jvm tuning for low latency application & CassandraJvm tuning for low latency application & Cassandra
Jvm tuning for low latency application & Cassandra
 
Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
 
Use Ruby GC in full..
Use Ruby GC in full..Use Ruby GC in full..
Use Ruby GC in full..
 
Out ofmemoryerror what is the cost of java objects
Out ofmemoryerror  what is the cost of java objectsOut ofmemoryerror  what is the cost of java objects
Out ofmemoryerror what is the cost of java objects
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
OpenJDK Concurrent Collectors
OpenJDK Concurrent CollectorsOpenJDK Concurrent Collectors
OpenJDK Concurrent Collectors
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
 
Scala to assembly
Scala to assemblyScala to assembly
Scala to assembly
 
Filtering 100M objects in Coherence cache. What can go wrong?
Filtering 100M objects in Coherence cache. What can go wrong?Filtering 100M objects in Coherence cache. What can go wrong?
Filtering 100M objects in Coherence cache. What can go wrong?
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
 

More from Monica Beckwith

More from Monica Beckwith (17)

The ilities of software engineering.pptx
The ilities of software engineering.pptxThe ilities of software engineering.pptx
The ilities of software engineering.pptx
 
ZGC-SnowOne.pdf
ZGC-SnowOne.pdfZGC-SnowOne.pdf
ZGC-SnowOne.pdf
 
QCon London.pdf
QCon London.pdfQCon London.pdf
QCon London.pdf
 
Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!Enabling Java: Windows on Arm64 - A Success Story!
Enabling Java: Windows on Arm64 - A Success Story!
 
Applying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBBApplying Concurrency Cookbook Recipes to SPEC JBB
Applying Concurrency Cookbook Recipes to SPEC JBB
 
Intro to Garbage Collection
Intro to Garbage CollectionIntro to Garbage Collection
Intro to Garbage Collection
 
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORSOPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
OPENJDK: IN THE NEW AGE OF CONCURRENT GARBAGE COLLECTORS
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
 
JFokus Java 9 contended locking performance
JFokus Java 9 contended locking performanceJFokus Java 9 contended locking performance
JFokus Java 9 contended locking performance
 
Java Performance Engineer's Survival Guide
Java Performance Engineer's Survival GuideJava Performance Engineer's Survival Guide
Java Performance Engineer's Survival Guide
 
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
The Performance Engineer's Guide To (OpenJDK) HotSpot Garbage Collection - Th...
 
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationThe Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
 
Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!
 
Game of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GCGame of Performance: A Song of JIT and GC
Game of Performance: A Song of JIT and GC
 
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015Way Improved :) GC Tuning Confessions - presented at JavaOne2015
Way Improved :) GC Tuning Confessions - presented at JavaOne2015
 
GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)GC Tuning Confessions Of A Performance Engineer - Improved :)
GC Tuning Confessions Of A Performance Engineer - Improved :)
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance Engineer
 

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 

A G1GC Saga-KCJUG.pptx

  • 1. Have You Really Taken the Time to Know Me? - A G1 GC Saga @mon_beck By: Monica Beckwith
  • 2. Agenda Introduction to G1 GC GC Trifecta for Performance G1 GC Performance Optimizations
  • 3. Introduction to G1 GC Regions and Generations
  • 4. Heap Young Generation Old Generation Regionalized Heap Generational Heap Generational Regionalized Heap G1 GC: A Regionalized, Generational Collector
  • 5. • List of free regions • The occupied regions could be young, old or humongous An Occupied Region A Free Region Occupied and Free Regions
  • 6. Young, Old and Humongous An Occupied Young Region A Free Region An Occupied Old Region An Occupied Humongous Region Young Regions - Regions that contain objects in the Eden and Survivor Spaces Old Regions - Regions that contain objects in the Old generation. Humongous Regions - Regions that contain Humongous Objects.
  • 7. G1 GC Phases • On allocation failures, G1 GC performs young collections • When the marking threshold (IHOP) is crossed, G1 GC starts a concurrent marking cycle • The concurrent marking cycle has a few STW phases such as Initial Mark, Remark and Cleanup • Finally, G1 can decide on the fly if mixed collections are need and also decide on the count target for collections
  • 8. 0 30 60 90 120 150 3415 3416.3 3417.2 3418.4 3419 3422 3423.4 3432.2 3433.2 3436.8 3437.6 3438.9 3440 Pause time in milliseconds Timestamps Young Collection Initial Mark Remark Cleanup Mixed Collection Occupancy == Initiating Heap Occupancy Percent G1 GC Pause Histogram
  • 9. An Occupied Young Region A Free Region An Occupied Old Region An Occupied Humongous Region A Young Collection and its Collection Set Young Collection Set = {a,b,c,d,e} d c b a e
  • 10. g f An Occupied Young Region A Free Region An Occupied Old Region An Occupied Humongous Region A Mixed Collection Young Collection Set = {a,b,c,d,e} Old Collection Set = {f,g} Mixed Collection Set = {Young Collection Set, Old Collection Set} = {a,b,c,d,e,f,g} d c b a e
  • 11. GC Trifecta for Application Performance Footprint, Responsiveness and Throughput!
  • 12. How can I fit in more data? OR How can I optimize the maintenance overhead? Footprint
  • 14. Total: reserved=5607369KB, committed=350057KB - Java Heap (reserved=4057088KB, committed=253952KB) (mmap: reserved=4057088KB, committed=253952KB) - Class (reserved=8368KB, committed=6064KB) … - Thread (reserved=23605KB, committed=1097KB) … - Code (reserved=247967KB, committed=7771KB) … - GC (reserved=201335KB, committed= 60103KB) (malloc=17463KB #1035) (mmap: reserved=183872KB, committed=42640KB) … Native Memory Tracking Summary for G1 GC:
  • 15. NMT GC Info Serial GC Parallel GC G1 GC Z GC Shenandoah GC Reserved 13,277KB 177,138KB 201,335KB 8,463,552KB 131,872KB Committed 917KB 164,726KB 60,103KB 107,712KB 8,936KB Malloc 29KB 28,850KB 17,463KB 9,344KB 4,448KB Mmap, Reserved 13,248KB 148,288KB 183,872KB 8,454,208KB 127,424KB Mmap, Commited 888KB 135,876KB 42,640KB 98,368KB 4,488KB GC Footprint – OpenJDK JDK 11 LTS Out of the Box
  • 16. NMT GC Info Serial GC Parallel GC G1 GC Z GC Shenandoah GC Reserved 6,941KB 105,586KB 133,128KB 8,461,466KB 70,215KB Committed 6,881KB 105,506KB 133,128KB 105,626KB 37,387KB Malloc 29KB 28,850KB 22,088KB 7,258KB 4,359KB Mmap, Reserved 6,912KB 76,736KB 111,040KB 8,454,208KB 65,856KB Mmap, Commited 888KB 76,656KB 111,040KB 98,368KB 33,028KB GC Footprint – Xmx = Xms = 2G
  • 18. If I send a stimulus now, how much time ’til I get a response back? Application Responsiveness
  • 21. GC Elapsed Time indicated the amount of time it takesto execute stop the world (STW) GC events The higher the GC elapsed time - the lower the application responsiveness due to the GC induced latencies Increase Application Responsiveness by Reducing GC Elapsed Time
  • 22. How can I maximize the operations per second of my system? Throughput
  • 25. Overhead is an indication of the frequency of stop the world GC events. The more frequent the GC events - The more likely it is to negatively impact application throughput Increase Application Throughput by Reducing GC Overhead
  • 26. G1 GC Performance Optimizations
  • 27. G1 GC Footprint Optimizations Compact Strings and String Deduplication: JEP 254: Compact Strings JEP 192: String Deduplication in G1
  • 28. Java Lang String with Java Object Layout – JDK 8 $ jdk8/bin/java -jar jol-cli-latest.jar footprint java.lang.String # Running 64-bit HotSpot VM. # Using compressed oop with 3-bit shift. # Using compressed klass with 0x0000000800000000 base address and 0-bit shift. # Objects are 8 bytes aligned. Instantiated the sample instance via default constructor. java.lang.String@1761e840d footprint: COUNT AVG SUM DESCRIPTION 1 16 16 [C 1 24 24 java.lang.String 2 40 (total) string1 = “Happy” String 1 Object Char[]
  • 29. Java String Object – JDK 8 java.lang.String object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) c2 02 00 f8 (11000010 00000010 00000000 11111000) (- 134217022) 12 4 char[] String.value [] 16 4 int String.hash 0 20 4 (loss due to the next object alignment) Instance size: 24 bytes Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
  • 30. Java String Object – JDK 9+; Hello Compact Strings! java.lang.String object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 05 00 00 00 (00000101 00000000 00000000 00000000) (5) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) 08 18 00 00 (00001000 00011000 00000000 00000000) (6152) 12 4 byte[] String.value [] 16 4 int String.hash 0 20 1 byte String.coder 0 21 3 (loss due to the next object alignment) Instance size: 24 bytes Space losses: 0 bytes internal + 3 bytes external = 3 bytes total
  • 31. Trivia: Java String Object – JDK 13+; Hello Boolean! java.lang.String object internals: OFFSET SIZE TYPE DESCRIPTION VALUE 0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) 4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) 8 4 (object header) f8 20 00 00 (11111000 00100000 00000000 00000000) (8440) 12 4 int String.hash 0 16 1 byte String.coder 0 17 1 boolean String.hashIsZero false 18 2 (alignment/padding gap) 20 4 byte[] String.value [] Instance size: 24 bytes Space losses: 2 bytes internal + 0 bytes external = 2 bytes total
  • 32. Java String Literals – JDK 8 String string1 = “Happy”; string1 = “Happy” String 1 Object 00 string2 = “” String 2 Object 70 00 70 00 79 00 61 00 48 Char[] = 26 3A Char[] = String string2 = “”;
  • 33. Java String Literals – JDK 9+ String string1 = “Happy”; string1 = “Happy” String 1 Object string2 = “” String 2 Object 70 70 79 61 48 Byte[] = 26 3A Byte[] = String string2 = “”;
  • 34. Java String Deduplication in G1 string1 = “” String 1 Object Byte[] string2 = “” String 2 Object What if string1.equals(string2)?
  • 36. G1 GC Footprint Optimizations  Remembered Sets Space Reductions  Old Gen On NVDIMM  Dynamic GC Threads with Lower Heap Size Per Thread  Early reclamation of large objects in G1
  • 37. G1 GC Responsiveness Optimizations Periodic GC: JEP 346: Promptly Return Unused Committed Memory from G1
  • 38. GC(34) Pause Young (Prepare Mixed) (G1 Evacuation Pause) 6097M->5571M(15360M) 120.948ms … GC(245) Pause Young (Mixed) (G1 Evacuation Pause) 5879M->4794M(15360M) 113.676ms … GC(318) Pause Young (Mixed) (G1 Evacuation Pause) 11349M->9046M(15360M) 113.040ms … GC(354) Pause Young (Mixed) (G1 Evacuation Pause) 8881M->7022M(15360M) 409.969ms GC(34) Pause Young (Concurrent Start) (G1 Periodic Collection) 8M->0M(5120M) 5.693ms … GC(158) Pause Young (Concurrent Start) (G1 Periodic Collection) 254M->213M(5120M) 169.579ms … GC(201) Pause Young (Mixed) (G1 Periodic Collection) 1904M->1713M(7168M) 168.510ms … GC(232) Pause Young (Mixed) (G1 Periodic Collection) 3141M->2949M(12456M) 286.378ms Without Periodic GC With Periodic GC; -XX:G1PeriodicGCInterval=15
  • 39. G1 GC Responsiveness Optimizations Parallel Reference Processing: Make parallel reference processing default for G1
  • 41. G1 GC Responsiveness Optimizations Abortable Mixed Collections: JEP 344: Abortable Mixed Collections for G1
  • 42. Start adding old regions to collection set. Min 116 regions, max 192 regions, time remaining 114.00ms, optional threshold 22.80ms Finish adding old regions to collection set (Predicted time too high). Finish choosing collection set old regions. Initial: 116, optional: 15, predicted old time: 0.00ms, predicted optional time: 15.31ms, time remaining: 0.00 … Prepared 7 regions out of 15 for optional evacuation. Predicted time: 8.083ms … Prepared 7 regions out of 8 for optional evacuation. Predicted time: 8.252ms … Prepared 1 regions out of 1 for optional evacuation. Predicted time: 1.119ms … Merge Optional Heap Roots: 2.0ms Evacuate Optional Collection Set: 12.7ms G1 GC Log with GC + Ergo = Debug
  • 43. GC(264) Pause Young (Mixed) (G1 Evacuation Pause) GC(264) Merge Optional Heap Roots: 0.2ms GC(264) Prepare Optional Merge Heap Roots: 0.0ms GC(264) Optional Remembered Sets (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.4, Workers: 5 … GC(264) Evacuate Optional Collection Set: 16.4ms GC(264) Optional Scan Heap Roots (ms): Min: 0.0, Avg: 1.6, Max: 4.9, Diff: 4.9, Sum: 68.9, Workers: 43 … GC(264) Optional Object Copy (ms): Min: 0.0, Avg: 3.0, Max: 5.2, Diff: 5.1, Sum: 128.7, Workers: 43 GC(264) Optional Code Root Scan (ms): Min: 0.0, Avg: 0.3, Max: 14.3, Diff: 14.3, Sum: 14.3, Workers: 43 GC(264) Optional Termination (ms): Min: 0.2, Avg: 10.3, Max: 10.7, Diff: 10.5, Sum: 443.3, Workers: 43 G1 GC Log with GC + Phases = Debug
  • 45. G1 GC Responsiveness Optimizations  Improvements in Remembered Sets Scanning  Rebuild Remembered Sets During the Concurrent Cycle  Reduce Barrier Overhead  Adaptive Initiating Heap Occupancy Percent (IHOP)
  • 46. G1 GC Throughput Optimizations Adaptive IHOP (Initiating Heap Occupancy Percentage): Adaptive sizing for IHOP in G1
  • 49. G1 GC Throughput Optimizations Parallel Full GC: JEP 307: Parallel Full GC for G1
  • 50. G1 GC Parallel Full GC
  • 51. G1 GC Throughput Optimizations Cleanup Phase Improvements:  Remove concurrent cleanup and secondary free list handling
  • 52. Due to the ability to rebuild remembered sets during a concurrent cycle, G1 can now get rid of the concurrent cleanup and any overhead associated with it Regions full of garbage can now be freed during a Remark pause •Remark phase*: This phase is STW collection and helps the completion of the marking cycle. G1 GC drains SATB buffers, traces unvisited live objects, and performs reference processing. •Cleanup phase*: In this final phase, the G1 GC performs the STW operations of accounting and RSet scrubbing. •During accounting, the G1 GC identifies completely free regions and mixed garbage collection candidates. •The cleanup phase is partly concurrent when it resets and returns the empty regions to the free list. * https://www.oracle.com/technical-resources/articles/java/g1gc.html
  • 54. G1 GC Throughput Optimizations  Ergonomic Heap Region Resizing  Parallel Pretouch  Rebuild Remembered Sets During the Concurrent Cycle  Remove Unnecessary Barriers during Object Copy
  • 55. © Copyright Microsoft Corporation. All rights reserved. References: https://www.slideshare.net/MonicaBeckwith https://tschatzl.github.io/2020/09/01/jdk15-g1-parallel-gc-changes.html https://docs.oracle.com/en/java/javase/14/gctuning/garbage-first-g1-garbage-collector1.html https://github.com/openjdk/jol

Editor's Notes

  1. 9 8u20
  2. 11 10 11 9
  3. 12
  4. G1PeriodicGCInvokesConcurrent default = true "Determines the kind of periodic GC. Set to true to have G1 " \ "perform a concurrent GC as periodic GC, otherwise use a STW " \ "Full GC. G1PeriodicGCInterval, 0 Number of milliseconds after a previous GC to wait before " \ "triggering a periodic gc. A value of zero disables periodically "\ "enforced gc cycles
  5. 11
  6. 12
  7. 12, 13 9,10 11 9
  8. 9
  9. 10
  10. 11
  11. 11, 15 – improve ootb perf 14 9.10 11 – weak memory ordered