In JDK 11/12 there have appeared two very efficient GC collectors: ZGC and ShenandoahGC. The main reason why they have appeared is a short GC pause, no matter how the root set size is and so as to the developer nothing has to tune. I'll show you previous options and compare them mostly with G1 GC, which is the default GC collector since JDK9.
14. G1
• Low-pause collector - First papers date back to 2004
• Supported since JDK 7u4 (April 2012)
• Replacement for CMS
• Low pauses valued more than max throughput
• Designed to be really ease to tune
• Tuning based on max Stop-The-World pause ( -XX:MaxGCPauseMillis=X)
Default: 250ms
15. G1
• Default GC since Java 9
• Use regions instead generations
• Dynamic size of region
• Parallel Full GC in Java10(jdk-10-ea+34)
27. Mutator problems
Headers
x = 1
y = 2
z = 1
Headers
x = 1
y = 2
z = 1
from-space to-space
Object A
Object B
Object A
Object B
Object C
28. Mutator problems
Headers
x = 1
y = 4
z = 1
Headers
x = 3
y = 2
z = 1
from-space to-space
Application thread 10
Application thread 3 Object A
Object B
Object A
Object B
30. Shenandoah
• Available in AdoptOpenJDK builds
• NOT available in Oracle’s OpenJDK builds
• Present in RedHat OpenJDK 8,11+
• Low pause GC
• Concurrent Compaction, Single Generation
31. Shenandoah
• Available for x86 32-bit and 64-bit
• ARM ports available
• Linux, MacOS, Windows
• Region Based
52. ZGC
• Sub-millisecond max pause times (less than 10ms) (less than 1ms)
• Pauses are O(1)
• Pause times do not increase with the heap, live-set or root-set size
• Handle heaps ranging from a 8MB to 16TB in size
• ZGC was initially introduced as an experimental feature in JDK 11, and was
declared Production Ready in JDK 15.
53. ZGC
• Only for Linux x86 64-bit
• compressed class pointers
• no support compress OOPs
• Region based
• ZPages
• Small ( 2MiB - object size up to 256KiB)
• Medium ( 32MiB - object size up to 4MiB)
• Large ( 4+ MiB - object size > 4MiB)
57. ZGC
ZGC uses a load GC barrier
Object someObject = person.name;
<load_barrier>
// String n = person.name;
mov 0x10(%rax), %rbx
// bad color
test %rbx, (0x16)%r15
// If yes, enter slow path
jnz slow_path
75. Concurrent Thread-Stack Processing
▪Remove thread-stack processing from ZGC safepoints.
▪Make stack processing lazy, cooperative, concurrent, and incremental.
▪Remove all other per-thread root processing from ZGC safepoints.
▪Provide a mechanism by which other HotSpot subsystems can lazily process stacks.
80. JEP-423
• No stalling of threads due to JNI critical regions.
• No additional latency to start a garbage collection due to JNI critical
regions.
• No regressions in GC pause times when no JNI critical regions are
active.
• Minimal regressions in GC pause times when JNI critical regions are
active.