the design of zgc - oraclecr.openjdk.java.net/~pliden/slides/zgc-plmeetup-2019.pdf · pause times....
TRANSCRIPT
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
The Design of ZGCA Scalable Low-Latency Garbage Collector for Java
Per Lidén (@perliden)Consulting Member of Technical StaffJava Platform Group, OracleJune 12, 2019
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
The Design of ZGC
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
A Scalable Low-Latency Garbage Collector
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Goals
Multi-terabyte heaps Max GC pause time
Easy to tuneMax application throughput reduction
10msTB
15%
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC at a Glance
Concurrent
Tracing
Compacting
Single generation
Region-based
NUMA-aware
Load barriers
Colored pointers
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC pause times do not increasewith the heap or live-set size
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC pause times do increasewith the root-set size
(Number of Java Threads)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC Cycle
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC CycleScan thread stacks
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC CycleWalk object graph
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC CycleSynchronization point
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC CycleReference processing
Class unloadingRelocation set selection
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC Cycle
Scan thread stacks
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC Cycle
Compact heap
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC Cycle
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark/Remap
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
GC Cycle
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
ConcurrentRemap
GC Cycle
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
ConcurrentRemap
GC Cycle
Walks object graph
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
ConcurrentMark
Pause Mark End Pause Relocate StartPause Mark Start
ConcurrentPrepare for Reloc.
ConcurrentRelocate
ConcurrentRemap
GC Cycle
Walks object graph
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Phases
Concurrent RemapConcurrent Mark
Mark End Relocate StartMark Start
Prepare for Reloc Concurrent Reloc Concurrent RemapConcurrent Mark
Concurrent Mark
Mark End Relocate StartMark Start
Prepare for Reloc Concurrent Reloc
Mark End Relocate StartMark Start
Prepare for Reloc Concurrent Reloc Concurrent Remap
GC Cycle 1
GC Cycle 2
GC Cycle 3
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
• Core design concept in ZGC
• Metadata stored in unused bits in 64-bit pointers
– No support for 32-bit platforms
– No support for CompressedOops
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Colors
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Marked0
Marked1Remapped
Finalizable
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Marked0
Marked1Remapped
Finalizable
Known to be marked?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Marked0
Marked1Remapped
Finalizable
Known to not point into the relocation set?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Marked0
Marked1Remapped
Finalizable
Only reachable through a Finalizer?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Colored Pointers
Object Address (44 bits, 16TB address space)
64-bit Object Pointer
Unused (16 bits)
Marked0
Marked1Remapped
Finalizable
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
• A small piece of code injected by the JIT in strategic places
–When loading an object reference from the heap
• Checks if the loaded object reference has a bad color– If so, take action and heal it
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
String n = person.name; // Loading an object reference from heap
String name;int age;double height;
...
Person
String
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
String n = person.name; // Loading an object reference from heap
<load barrier needed here>
String name;int age;double height;
...
Person
String
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
String n = person.name; // Loading an object reference from heap
<load barrier needed here>
String p = n; // No barrier, not a load from heap
n.isEmpty(); // No barrier, not a load from heap
int age = person.age; // No barrier, not an object reference
String name;int age;double height;
...
Person
String
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
String n = person.name; // Loading an object reference from heap
<load barrier needed here>
String name;int age;double height;
...
Person
String
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
String n = person.name; // Loading an object reference from heap
if (n & bad_bit_mask) {
slow_path(register_for(n), address_of(person.name));
}
String name;int age;double height;
...
Person
String
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
mov 0x10(%rax), %rbx // String n = person.name;
test %rbx, 0x20(%r15) // Bad color?
jnz slow_path // Yes -> Enter slow path and
// mark/relocate/remap, adjust
// 0x10(%rax) and %rbx
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Load Barrier
mov 0x10(%rax), %rbx // String n = person.name;
test %rbx, 0x20(%r15) // Bad color?
jnz slow_path // Yes -> Enter slow path and
// mark/relocate/remap, adjust
// 0x10(%rax) and %rbx
~4% execution overhead on SPECjbb®2015
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Heap Multi-Mapping on Linux/x86_64
Heap Remapped View
Heap Marked1 View
Heap Marked0 View
0x00007FFFFFFFFFFF (128TB)
0x0000140000000000 (20TB)
0x0000100000000000 (16TB)
0x00000C0000000000 (12TB)
0x0000080000000000 (8TB)
0x0000040000000000 (4TB)
0x0000000000000000
Heap Memory
Address Space
Same memory mapped in 3different locations
Colored pointer (Remapped)0x0000100012345678
Colorless pointer0x0000000012345678
Colored pointer (Marked1)0x0000080012345678
Colored pointer (Marked0)0x0000040012345678
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Mark
• Concurrent & Parallel
• Load barrier
– Detects loads of non-marked object pointers
• Striped
– Heap divided into logical stripes
– Isolate each GC thread to work on its own stripe
–Minimized shared state
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Relocation
• Concurrent & Parallel
• Load barrier
– Detects loads of object pointers pointing into the relocation set
– Java threads help out with relocation if needed
• Off-heap forwarding tables– No forwarding information stored in old copies of objects
– Important for immediate reuse of heap memory
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
GC Cycle Example
Heap Address Space
Heap
.....
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
GC Cycle Example
Roots
.....
1
2
4
85
3 6 7
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark End
Roots
.....
1
2
4
85
3 6 7
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Prepare for Relocate
Roots
.....
1
2
4
85
3 6 7
Relocation Set
Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Prepare for Relocate
Roots
.....
1
2
4
85
3 6 7
Marked
Forwarding Tables
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Relocate Start
Roots
.....
1
2
4
85
3 6 7
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Relocate Start
Roots
.....
1
2
4
85
3 6 7
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Relocate Start
Roots
.....
1
2
4
85
3 6 7
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Relocate Start
Roots
.....
1
2
4
85
3 6 7 4
4 -> 4’
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Relocate
Roots
.....
1
2
4
85
3 6 7 4
4 -> 4’
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Relocate
Roots
.....
1
2
4
85
3 6 7 4
4 -> 4’5 -> 5’
5
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Relocate
Roots
.....
1
2 8
6 7 4
4 -> 4’5 -> 5’
5
Marked
Remapped +Relocated
Heap Region Becomes Reusable
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Relocate
Roots
.....
1
2 8
6 7 4
4 -> 4’5 -> 5’
5
Marked
Remapped +Relocated
8 -> 8’
8
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Relocate
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Heap Region Becomes Reusable
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
GC Cycle Completed
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
GC Cycle Completed
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Java Thread Loads Pointer
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
GC Cycle Completed
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Java Thread Loads Pointer
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark Start (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Mark (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Pause Mark End (Second Cycle)
Roots
.....
1
2
4
4 -> 4’5 -> 5’
8 -> 8’
5 8
Marked
Remapped +Relocated
Remapped +Marked
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Concurrent Prepare for Relocate (Second Cycle)
Roots
.....
1
2
4
5 8
Marked
Remapped +Relocated
Remapped +Marked
Forwarding Tables Freed
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Performance
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Mode: Composite
Heap Size: 128G
OS: Oracle Linux 7.5
HW: Intel Xeon E5-2690 2.9GHz2 sockets, 16 cores (32 hw-threads)
SPECjbb®2015 is a registered trademark of the Standard PerformanceEvaluation Corporation (spec.org). The actual results are not representedas compliant because the SUT may not meet SPEC's requirements forgeneral availability.
SPECjbb®2015 – Score
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
ZGC Parallel G1
(Higher is better)
max-JOPS (Throughput) critical-JOPS (Throughput with latency requirements)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
0
100
200
300
400
500
600
ZGC Parallel G1
GC
Pau
se T
imes
(m
s)
Linear scale(Lower is better)
Average 95th percentile 99th percentile 99.9th percentile Max
SPECjbb®2015 – GC Pause Times
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
0,1
1
10
100
1000
ZGC Parallel G1
GC
Pau
se T
imes
(m
s)
Logarithmic scale(Lower is better)
Average 95th percentile 99th percentile 99.9th percentile Max
SPECjbb®2015 – GC Pause Times
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
0,1
1
10
100
1000
ZGC Parallel G1
GC
Pau
se T
imes
(m
s)
Logarithmic scale(Lower is better)
Average 95th percentile 99th percentile 99.9th percentile Max
SPECjbb®2015 – GC Pause Times
1.12
0.46
159323
155
482
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
0,1
1
10
100
1000
ZGC Parallel G1
GC
Pau
se T
imes
(m
s)
Logarithmic scale(Lower is better)
Average 95th percentile 99th percentile 99.9th percentile Max
SPECjbb®2015 – GC Pause Times
1.12
0.46
159323
155
482
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Going Forward
• Generational
• Sub-millisecond max pause times
• Support additional platforms
• Graal JIT support
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
ZGC Project
[email protected] [email protected]
http://wiki.openjdk.java.net/display/zgc/Main
http://hg.openjdk.java.net/jdk/jdk
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Thanks!
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Questions?