JEP 364: ZGC on macOS

OwnerErik Österlund
TypeFeature
ScopeImplementation
StatusCandidate
Componenthotspot / gc
Discussionhotspot dash gc dash dev at openjdk dot java dot net
EffortS
DurationS
Reviewed byMikael Vidstedt, Per Liden
Created2019/08/09 13:06
Updated2019/10/04 17:13
Issue8229358

Summary

Port the ZGC garbage collector to macOS.

Non-Goals

Support for large pages is not a goal. (None of the HotSpot garbage collectors supports large pages on macOS.)

Motivation

While we expect users that require the scalability of ZGC to use Linux-based environments, it is not uncommon that developers use Macs for local development and testing, before deploying applications. There are also users who wish to run desktop applications such as IDEs with ZGC.

Description

The macOS implementation of ZGC consists of two parts:

Alternatives

We attempted an alternative prototype using the Mach microkernel VM system for multi-mapped memory. It used vm_remap() to map the same memory multiple times, and could trivially support large pages. We abandoned this approach due to bad interactions with the mmap API, which we still had to use to reserve virtual address space. One cannot vm_map memory over mmap’ed memory, despite the mapping using MAP_NORESERVE. So the mmap’ed VA reservation must be unmapped first, before mapping in the committed memory using the Mach APIs. During that time, however, a race is exposed where another mmap user in the same process could hijack that memory first. Dealing with the consequences of that is extremely awkward, which is why we chose to use POSIX shared memory objects instead.

Testing

The tests that usually run for ZGC on Linux, will be run for macOS too.

Dependencies

The work to purge the VM of the assumption that GCs have one discontiguous memory reservation is required to pave the way for the macOS port. These changes are described in preparatory enhancements, to make reviewing easier: