Post

Java GC

JEP 304: Garbage Collector Interface is a must read if you want to learn the internal mechanism of Java GC.

ZGC

ZGC has 24k lines of code, which seems readable :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ cloc src/hotspot/share/gc/z/
     238 text files.
     237 unique files.
       1 file ignored.

github.com/AlDanial/cloc v 1.98  T=0.13 s (1893.5 files/s, 318891.2 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C++                             80           3788           4049          14729
C/C++ Header                   157           3109           4557           9683
-------------------------------------------------------------------------------
SUM:                           237           6897           8606          24412
-------------------------------------------------------------------------------

There is a good paper about the overall design of ZGC: Deep Dive into ZGC: A Modern Garbage Collector in OpenJDK. In its introduction, it wrote:

The ZGC C++ source code is readily accessible in the OpenJDK repository, but reading it (25 KLOC) can be very intimidating, and one might easily get lost in low-level implementation details, obscuring the key concepts. To make the ZGC algorithm more approachable, this work provides a thorough description on a high-level, focusing on the overall design with moderate implementation details.

mmap

Memory mapped file is a great way to efficiently read/write large files. It is efficient because it avoids copying data between kernel and user space. Also, mmap is outside of JVM heap, so it does not incur GC. Checkout this introduction post.

This post is licensed under CC BY 4.0 by the author.