openjdk: in the new age of concurrent garbage collectors · 2019-11-05 · algorithm and other...
TRANSCRIPT
![Page 1: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/1.jpg)
Java Team
OpenJDK: In the New Age of Concurrent Garbage CollectorsHotSpot’s Regionalized GCs
Monica BeckwithJVM Performance java-performance@Microsoft
@mon_beck
![Page 2: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/2.jpg)
AgendaPart 1 – Groundwork & Commonalities
Laying the GroundworkStop-the-world (STW) vs concurrent collection
Heap layout – regions and generations
Basic CommonalitiesCopying collector – from and to spaces
Regions – occupied and free
Collection set and priority
Oct 8th, 2019
![Page 3: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/3.jpg)
AgendaPart 2 – Introduction & Differences
Introduction to G1, Shenandoah and Z GCsAlgorithm
Basic DifferencesGC phases
Marking
Barriers
Compaction
Oct 8th, 2019
![Page 4: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/4.jpg)
Groundwork : Stop-the world vs concurrent collections
![Page 5: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/5.jpg)
Stop-the-world aka STW GC
Application Threads
GC Threads
Application Threads
Safepoint Requested
GC Completed
Application Threads GC Threads Application Threads
Safepoint Requested
GC Completed
Handshakes
Thread local handshakes vs Global
Time To Safepoint (TTSP)
![Page 6: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/6.jpg)
Concurrent GC
Application Threads
GC Threads
![Page 7: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/7.jpg)
Groundwork : Heap layout -regions and generations
![Page 8: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/8.jpg)
Heap Layout
Heap
Z GC
Shenandoah GC
Young GenerationG1 GCOld Generation
![Page 9: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/9.jpg)
Commonalities : Copying collector – from and to spaces
From To
![Page 10: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/10.jpg)
HeapFrom Space To SpaceO O O O O O O O O O
O O O O O O O O O O
O O O O O O O O O O
GC ROOTS
THREAD 1 STACK
THREAD N STACK
STATICVARIABLES
ANY JNI REFERENCES
Copying Collector aka Compacting Collector aka Evacuation
![Page 11: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/11.jpg)
O O O O O O O O O OO O O O O O O O O OO O O O O O O O O O
GC ROOTS
THREAD 1 STACK
THREAD N STACK
O OO O
O
STATICVARIABLES
ANY JNI REFERENCES
OOO
O O
O O O O O O O O O OO O O O O O O O O OO O O O O O O O O O
Copying Collector aka Compacting Collector aka Evacuation
![Page 12: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/12.jpg)
Copying Collector aka Compacting Collector aka Evacuation
O O O O O O O OO O O O O O OO O O O O O O
O O OO O O
O O
![Page 13: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/13.jpg)
Commonalities : Regions – occupied and free
![Page 14: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/14.jpg)
Occupied and Free Regions
O O O O O O O O O O
O O O O O O O O O O
O O O O O O O O O O
O O O O
O O O O
O O O O
• List of free regions• In case of generational heap (like G1), the occupied regions could be young, old or humongous
![Page 15: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/15.jpg)
Commonalities : Collection set and priority
![Page 16: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/16.jpg)
Collection Priority and Collection Set
O O O O O O O O O O
O O O O O O O O O O
O O O O O O O O O O
O O O O
O O O O
O O O O
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
OOOO
• Priority is to reclaim regions with most garbage• The candidate regions for collection/reclamation/relocation are said to be in a collection set
• There are threshold based on how expensive a region can get and maximum regions to collect• Incremental collection aka incremental compaction or partial compaction
• Usually needs a threshold that triggers the compaction• Stops after the desired reclamation threshold or free-ness threshold is reached• Doesn’t need to be stop-the-world
![Page 17: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/17.jpg)
Introduction : G1, Shenandoah & Z - Algorithms
![Page 18: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/18.jpg)
Algorithm and Other Considerations
Garbage Collectors G1 GC Shenandoah GC Z GCRegionalized? Yes Yes YesGenerational? Yes No NoCompaction? Yes, STW, Forwarding
address in headerYes, Concurrent, Forwarding Pointer
Yes, Concurrent, Colored Pointers
Target Pause Times? 200ms 10ms 10msConcurrent Marking Algorithm? SATB SATB Striped
![Page 19: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/19.jpg)
Differences – G1
![Page 20: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/20.jpg)
GC Phases of Marking and Compaction
G1 GC GistInitial Mark Mark objects directly reachable by the rootsConcurrent Root Region Scanning Since initial mark is piggy-backed on a young collection, the survivor
regions need to be scannedConcurrent Marking Snapshot-at-the-beginning (SATB) algorithmFinal Marking Drain SATB buffers; traverse unvisited live objectsCleanup Identify and free completely free regions, sort regions based on liveness
and expenseSTW Compaction Move objects in collection set to “to” regions; free regions in collection
set
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.
![Page 21: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/21.jpg)
Concurrent Marking
Logical snapshot of the heapSATB marking guarantees that all garbage objects that are present at the start of the concurrent marking phase will be identified by the snapshot But, application mutates its object graph
Any new objects are considered liveFor any reference update, the mutator needs to log the previous value in a log queue
This is enabled by a pre-write barrier
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.•https://www.jfokus.se/jfokus17/preso/Write-Barriers-in-Garbage-First-Garbage-Collector.pdf
Snapshot-at-the-beginning (SATB) Algorithm
![Page 22: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/22.jpg)
BarriersSATB Pre-Write Barrier
The pseudo-code of the pre-write barrier for an assignment of the form x.f := y is: if (marking_is_active) {
pre_val := x.f; if (pre_val != NULL) {
satb_enqueue(pre_val); }
}
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.
![Page 23: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/23.jpg)
BarriersPost Write Barrier
Consider the following assignment:
object.field = some_other_object
G1 GC will issue a write barrier after the reference is updated, hence the name.
G1 GC filters the need for a barrier by way of a simple check as explained below:
(&object.field XOR &some_other_object) >> RegionSize
If the check evaluates to zero, a barrier is not needed.
If the check != zero, G1 GC enqueues the card in the update log buffer
https://www.jfokus.se/jfokus17/preso/Write-Barriers-in-Garbage-First-Garbage-Collector.pdf
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.
![Page 24: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/24.jpg)
STW CompactionForwarding Pointer in Header
BodyHeader
A Java Object
Pointer
Pointer to an InstanceKlassMark Word
b b GC workers compete to install the forwarding pointer
From source: • An InstanceKlass is the VM level representation of a Java class. It contains all information needed for at class at
execution runtime.• When marked the bits will be 11
![Page 25: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/25.jpg)
Differences – Z
![Page 26: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/26.jpg)
GC Phases of Marking and Compaction
Z GC GistInitial Mark Mark objects directly reachable by the rootsConcurrent Marking Striping - GC threads walk the object graph and markFinal Marking Traverse unvisited live objects; weak root cleaningConcurrent Prepare for Compaction Identify collection set; reference processingStart Compaction Handles roots into the collection setConcurrent Compaction Move objects in collection set to “to” regionsConcurrent Remap (done with Concurrent Marking of next cycle since walks the object graph)
Fixup of all the pointers to now-moved objects
http://cr.openjdk.java.net/~pliden/slides/ZGC-Jfokus-2018.pdf
![Page 27: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/27.jpg)
Striping
Heap divided into logical stripesGC threads work on their own stripeMinimizes shared state
Load barrier to detect loads of non-marked object pointersConcurrent reference processingThread local handshakes
http://cr.openjdk.java.net/~pliden/slides/ZGC-Jfokus-2018.pdf
Heap
GC Thread0
GC Thread1
GC Threadn
…
0 1 … n 0 1 … n 0 1 … n
Stripe0 Stripe1 Stripen
Colored PointersConcurrent Marking
![Page 28: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/28.jpg)
BarriersRead Barrier – For References
Update a “bad” reference to a “good” referenceCan be self-healing/repairing barrier when updates the source memory locationImposes a set of invariants –
“All visible loaded reference values will be safely “marked through” by the collector, if they haven’t been already.All visible loaded reference values point to the current location of the safely accessible contents of the target objects they refer to.”
Tene, G.; Iyengar, B. & Wolf, M. (2011), C4: The Continuously Concurrent Compacting Collector, in 'Proceedings of the international symposium on Memory management' , ACM, New York, NY, USA , pp. 79--88 .
Loaded Reference Barrier
![Page 29: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/29.jpg)
Example
Object o = obj.fieldA; // Loading an object reference from heap
load_barrier(register_for(o), address_of(obj.fieldA));
if (o & bad_bit_mask) { slow_path(register_for(o), address_of(obj.fieldA)); }
![Page 30: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/30.jpg)
Example
mov 0x20(%rax), %rbx // Object o = obj.fieldA;
test %rbx, (0x16)%r15 // Bad color?
jnz slow_path // Yes -> Enter slow path and mark/relocate/remap,
// adjust 0x20(%rax) and %rbx
http://cr.openjdk.java.net/~pliden/slides/ZGC-Jfokus-2018.pdf
![Page 31: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/31.jpg)
Core ConceptColored Pointers
http://cr.openjdk.java.net/~pliden/slides/ZGC-Jfokus-2018.pdf
Object Address041
Unused
Marked0
Marked1
Remapped
Finalizable
4663
Object is known to be marked?
Object is known to not be pointing into the relocation set?
Object is reachable only through a
Finalizer?
Metadata stores in the unused bits of the 64 bit pointers
Virtual address mapping/taggingMulti-mapping on x86-64Hardware support on SPARC, aarch64
![Page 32: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/32.jpg)
Concurrent Compaction
Load barrier to detect object pointers into the collection set
Can be self-healing
Off-heap forwarding tables enable to immediately release and reuse virtual and physical memory
http://cr.openjdk.java.net/~pliden/slides/ZGC-Jfokus-2018.pdf
Off-Heap Forwarding Tables
![Page 33: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/33.jpg)
Differences – Shenandoah
![Page 34: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/34.jpg)
GC Phases of Marking and Compaction
https://wiki.openjdk.java.net/display/shenandoah/Main
Shenandoah GC GistInitial Mark Mark objects directly reachable by the rootsConcurrent Marking Snapshot-at-the-beginning (SATB) algorithmFinal Marking Drain SATB buffers; traverse unvisited live objects; identify
collection setConcurrent Cleanup Free completely free regionsConcurrent Compaction Move objects in collection set to “to” regionsInitial Update Reference Initialize the update reference phaseConcurrent Update Reference Scans the heap linearly; update any references to objects
that have movedFinal Update Reference Update roots to point to to-region copiesConcurrent Cleanup Free regions in collection set
![Page 35: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/35.jpg)
Concurrent Marking
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.•https://www.jfokus.se/jfokus17/preso/Write-Barriers-in-Garbage-First-Garbage-Collector.pdf
Snapshot-at-the-beginning (SATB) Algorithm
![Page 36: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/36.jpg)
BarriersSATB Pre-Write Barrier - Recap
•C. Hunt, M. Beckwith, P. Parhar, B. Rutisson. Java Performance Companion.
Needed for all updatesCheck if “marking-is-active”SATB_enqueue the pre_val
![Page 37: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/37.jpg)
BarriersRead Barrier – For Concurrent Compaction
Here’s an assembly code snippet for reading a field: mov 0x10(%rsi),%rsi ; *getfield value
Here’s what the snippet looks like with Shenandoah:mov -0x8(%rsi),%rsi ; read of forwarding pointer at address object - 0x8 mov 0x10(%rsi),%rsi ; *getfield value
*Flood, Christine & Kennke, Roman & Dinn, Andrew & Haley, Andrew & Westrelin, Roland. (2016). Shenandoah: An open-source concurrent compacting garbage collector for OpenJDK. 1-9. 10.1145/2972206.2972210.
![Page 38: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/38.jpg)
BarriersCopying Write Barrier – For Concurrent Compaction
Needed for all updates to ensure to-space invariantCheck if “evacuation_in_progress”Check if “in_collection_set” and “not_yet_copied”CAS (fwd-ptr(obj), obj, copy)
*Flood, Christine & Kennke, Roman & Dinn, Andrew & Haley, Andrew & Westrelin, Roland. (2016). Shenandoah: An open-source concurrent compacting garbage collector for OpenJDK. 1-9. 10.1145/2972206.2972210.
![Page 39: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/39.jpg)
Superseded
BarriersRead Barrier – For Concurrent Compaction
*Flood, Christine & Kennke, Roman & Dinn, Andrew & Haley, Andrew & Westrelin, Roland. (2016). Shenandoah: An open-source concurrent compacting garbage collector for OpenJDK. 1-9. 10.1145/2972206.2972210.
![Page 40: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/40.jpg)
Superseded
BarriersCopying Write Barrier – For Concurrent Compaction
*Flood, Christine & Kennke, Roman & Dinn, Andrew & Haley, Andrew & Westrelin, Roland. (2016). Shenandoah: An open-source concurrent compacting garbage collector for OpenJDK. 1-9. 10.1145/2972206.2972210.
![Page 41: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/41.jpg)
BarriersLoaded Reference Barrier - Recap
Tene, G.; Iyengar, B. & Wolf, M. (2011), C4: The Continuously Concurrent Compacting Collector, in 'Proceedings of the international symposium on Memory management' , ACM, New York, NY, USA , pp. 79--88 .
https://developers.redhat.com/blog/2019/06/27/shenandoah-gc-in-jdk-13-part-1-load-reference-barriers/
Ensure strong ‘to-space invariant’Utilize barriers at reference loadCheck if fast-path-possible; else do-slow-path
![Page 42: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/42.jpg)
Concurrent CompactionBrooks Style Indirection Pointer
BodyHeader
A Java Object
Indirection Pointer
Forwarding pointer is placed before the objectAdditional work of dereferencing per object
![Page 43: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/43.jpg)
Superseded
Concurrent CompactionBrooks Style Indirection Pointer
Forwarding pointer is placed before the objectAdditional work of dereferencing per object
![Page 44: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/44.jpg)
Concurrent CompactionForwarding Pointer in Header
BodyHeader
To Space Copy Java Object
BodyForwarding Pointer
From Space Java Object
X
https://developers.redhat.com/blog/2019/06/28/shenandoah-gc-in-jdk-13-part-2-eliminating-the-forward-pointer-word/
![Page 45: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/45.jpg)
Performance!
![Page 46: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/46.jpg)
Test SetupAzure VM
Azure VM + Linux:
Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz
16GB; 4 cores
https://adoptopenjdk.net/releases.html#x64_linux
![Page 47: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/47.jpg)
Out-of-box* GC PerformanceThroughput and Responsiveness
0%
20%
40%
60%
80%
100%
120%
G1 (200ms) G1 (50ms) Shenandoah Z
Throughput Responsiveness
*With Xmx=Xms
![Page 48: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/48.jpg)
Further Reading
https://www.youtube.com/watch?v=VCeHkcwfF9Q
https://www.usenix.org/legacy/events/vee05/full_papers/p46-click.pdf
http://mail.openjdk.java.net/pipermail/zgc-dev/2017-December/000047.html
http://hg.openjdk.java.net/zgc/zgc/file/ffab403eaf14/src/hotspot/share/gc/z/zBarrier.cpp
https://wiki.openjdk.java.net/display/zgc/Main
![Page 49: OpenJDK: In the New Age of Concurrent Garbage Collectors · 2019-11-05 · Algorithm and Other Considerations Garbage Collectors G1 GC Shenandoah GC Z GC Regionalized? Yes Yes Yes](https://reader035.vdocument.in/reader035/viewer/2022062918/5ede460cad6a402d6669987d/html5/thumbnails/49.jpg)
© Copyright Microsoft Corporation. All rights reserved.