2. Copyright 2018 Kirk Pepperdine
HOW TO TUNE THE G1GC
▸ Set -XX:+UseG1GC
▸ Set max heap size using -mx
▸default value is 1/4 of physical RAM
▸ Set pause time goal using -XX:MaxGCPauseMillis=200 (default value)
jClarity
7. Copyright 2018 Kirk Pepperdine
jClarity
▸ Kirk Pepperdine
▸ Author of jPDM, a performance diagnostic model
▸ Author of the original Java Performance Tuning workshop
▸ Co-founded jClarity
▸ Building the smart generation of performance diagnostic tooling
▸ Bring predictability into the diagnostic process
▸ Co-founded JCrete
▸ The hottest unconference on the planet
▸ Java Champion(s)
OUR MARKETING SLIDE
8. Copyright 2018 Kirk Pepperdine
▸Models help us to
▸ understand how things work
▸ develop a cost model
▸Memory management consists of
▸ allocators
▸ mutators
▸ Garbage Collector
IMPORTANCE OF MODELS
jClarity
9. Copyright 2018 Kirk Pepperdine
▸Allocator/Mutator takes on all responsibility for managing memory
▸ unmanaged runtimes
▸Workload is shared between Allocator/Mutator and Garbage Collectors
▸ balance between allocation/mutation throughput and GC pause time
▸more work to GC equates to longer GC pause times
▸more work to allocator/mutators equates to reduces application throughput
▸ Lets develop an understanding so we can build a cost model
ALLOCATORS VS COLLECTORS
jClarity
10. Copyright 2018 Kirk Pepperdine
THINGS WE NEED
▸ Java Heap
▸Regions
▸ Mark-Sweep (copy)
▸Young generational collection
▸Tenured Mark
▸Mixed collection
▸ Supporting Data Structures
▸ Collection set (CSet)
▸ Remembered Set (RSet)
▸ RSet refinement queue
▸ Tuning G1GC
jClarity
11. Copyright 2018 Kirk Pepperdine
THE G1GC HEAP
jClarity
▸Reserved as a single contiguous
region at JVM startup
▸Divide into 2048 to 4095 regions
▸ heap size is specified with -mx
▸ regions size is one of 1, 2, 4, 8,
16, or 32m
▸-XX:G1HeapRegionSize=<n>
▸example for -mx10G
Region size = 10240M/2048
= 5m
Number of regions = 10G/4m
= 2560 regions
12. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
All regions are put into a free region list
14. Copyright 2018 Kirk Pepperdine
ERGONOMICS
jClarity
Free Region List
Regions
allotted
for Eden
15. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
Free Region List
MyDominObject mdo = new MyDomainObject
Take region from free list
16. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
Free Region List
MyDominObject mdo = new MyDomainObject
Label it as Eden
17. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
Free Region List
MyDominObject mdo = new MyDomainObject
allocate
18. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
Free Region List
Continue until
allotted Regions
are full
19. Copyright 2018 Kirk Pepperdine
G1GC ALLOCATION
jClarity
Free Region List
Allocation failure triggers Young Gen collection
20. Copyright 2018 Kirk Pepperdine
FORMING A CSET
jClarity
Free Region List
Allocation failure triggers Young Gen collection
CSet
21. Copyright 2018 Kirk Pepperdine
YOUNG COLLECTION
▸ Mark/Sweep (copy)
▸Mix of parallel and serial phases
jClarity
1. Place all young gen regions into a CSet
2. Calculate a root set for the CSet
3. Mark all live data in the CSet
4. Evacuate all live data to the ‘to’ space
The ‘to’ space regions allocated from the free region list
5. Place eden regions back on free list
6. Ergonomics recalculates number of regions to allocate to Eden
22. Copyright 2018 Kirk Pepperdine
G1GC SIZING
jClarity
Free Region List
Head of List
New allocation limit
-XX:G1MaxNewSizePercentage=60, -XX:G1NewSizePercentage=5
Survivor regions
23. Copyright 2018 Kirk Pepperdine
THE G1GC HEAP
Eden Regions
Unallocated Regions
Young
jClarity
Survivor Region
aka: to space
24. Copyright 2018 Kirk Pepperdine
TENURING
Young
jClarity
Survivor Region
aka: to space
Tenured Region
Eden Regions
Unallocated Regions
25. Copyright 2018 Kirk Pepperdine
YOUNG COLLECTION
▸ Mark/Sweep (copy)
▸Mix of parallel and serial phases
▸Place all young gen regions into a CSet
▸Calculation a root set for the CSet
▸Mark all live
▸Evacuate all live to survivor regions allocated from the free region list
▸Place eden regions back on free list
▸Ergonomics recalculates number of regions to allocate to Eden
jClarity
Time complexity!!!!
34. Copyright 2018 Kirk Pepperdine
SCAN FOR ROOTS
▸ Multi-threaded but….
▸Each individual space can be managed by a single thread
▸Large collections can only be managed by a single thread
▸ Scan for root time will be the longest time for scanning any single space
▸Often scan for roots is linear to the size of tenured
▸ G1 avoids this by introducing a remembered set (RSet)
jClarity
35. Copyright 2018 Kirk Pepperdine
RSET
▸Each Young gen region has an RSet
▸ Tracks pointers from Tenured regions into target region
▸ Requires a write barrier
▸ Has an associated space complexity
▸Complex implemetation solves this
▸RSet maintenance costs are non-linear to size of the region
▸ Mutations place an unwanted burden on the mutator threads
jClarity
36. Copyright 2018 Kirk Pepperdine
RSET REFINEMENT QUEUE
No threads are working
Number of RSets that can be processed run
less than 10% of the pause time goal
All refinement threads are working
G1UpdatingPauseTimePercent > 10%
Application threads are involved in RSet refinement.
Slow mutation rates which acts as back pressure
jClarity
43. Copyright 2018 Kirk Pepperdine
BUILDING A CSET REVISITED
▸ CSet contains all eden and survivor regions
▸a mixed collection will add a subset of tenured regions to the CSet
▸ CSet size is controlled by
▸the pause time goal (200ms default)
▸minimum collection percentages (10%)
▸other factors
jClarity
44. Copyright 2018 Kirk Pepperdine
MARK AND CALCULATE LIVELINESS
Tenured regions
jClarity
49. Copyright 2018 Kirk Pepperdine
HUMONGOUS ALLOCATIONS
Tenured
Young
jClarity
Tenured Region
Humungous Region (start)
Humungous Region (cont)
Survivor Region
aka: to space
Eden Region
Unallocated Region
50. Copyright 2018 Kirk Pepperdine
HUMONGOUS ALLOCATIONS
Humungous Region (start)
Humungous Region (cont)
jClarity
▸Allocation that is 1/2 the size of a region
▸Fragmented heaps may not have enough
space to satisfy an allocation
▸ dip into reserved space
▸ trigger a young gen collection with and
initial-mark
▸commit more regions to the heap
▸ worst case can trigger a Full GC
51. Copyright 2018 Kirk Pepperdine
RESERVED SPACE
Tenured Region
Humungous Region (start)
Humungous Region (cont)
Survivor Region
aka: to space
Eden Region
Unallocated Region
Tenured
Young
jClarity
Reserved
53. Copyright 2018 Kirk Pepperdine
HOW TO GET A GC LOG
jClarity
-Xloggc:gc.log
-XX:+PrintGCDetails
-XX:+PrintTenuringDistribution
-XX:+PrintGCDateStamps
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintReferenceGC
-Xlog:gc*,gc+ref,gc+phases=debug,gc+age=debug,safepoint:file=gc.log
54. Copyright 2018 Kirk Pepperdine
jClarity
DON’T LIKE READING GC LOGS?
I’ve got
your back
55. Copyright 2018 Kirk Pepperdine
▸ JDK 9
▸ G1GC is default collector
▸ improve ability to determine important memory setting
▸ migrate GC logging to Unified logging
▸ JDK 10
▸ Parallel full GC
▸ JDK 11
▸ new perf counters for STW during concurrent collection
▸ adaptive parallel reference processing
▸ Adaptive scaling for threads
RELEASE NOTES
jClarity
56. Copyright 2018 Kirk Pepperdine
WHY IS IT TAKING SO LONG???
jClarity
Lets look at a GC Log using Censum
57. Copyright 2018 Kirk Pepperdine
CONTROLLING OBJECT COPY COSTS
volume of reachable objects
jClarity
Occupancy
Age
58. Copyright 2018 Kirk Pepperdine
TEXT
TITLE TEXT
▸ Body Level One
▸ Body Level Two
▸ Body Level Three
▸ Body Level Four
▸ Body Level Five
Java Performance Tuning Workshop
Send us a Java 11 GC log or
tweet about @jclarity
and #censum
and
receive a free Censum License