Since JDK 9, G1 GC is the default garbage collector (JEP 248). Up until 2017, Monica has shared some G1 GC details, performance tips, and optimizations that help G1's adaptiveness and provided advice on manual tuning.
Since then, G1 has come a long way in improving its adaptiveness. In this session, Monica will cover most of the important optimizations that are delivered from JDK9+ and how they can help your application's responsiveness, throughput, and help with footprint reduction. This is a saga that involves various regions and generations (all pun intended).
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
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
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
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
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
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
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