JEP draft: Abortable mixed collections for G1

OwnerErik Helin
Created2017/10/27 09:56
Updated2017/11/02 14:15
TypeFeature
StatusDraft
Componenthotspot / gc
ScopeImplementation
Discussion hotspot dash gc dash dev at openjdk dot java dot net
EffortM
DurationM
Priority3
Reviewed byStefan Johansson, Thomas Schatzl
Issue8190269

Summary

Make G1 mixed collections abortable if they might exceed the pause target.

Non-Goals

Make all pauses in G1 abortable.

Motivation

One of the goals of G1 is to meet a user supplied pause time target for its collection pauses. G1 uses an advanced analysis engine to select the amount of work to be done during a collection (this is partly based on application behavior). The result of this selection is a set of regions called the the collection set. Once the collection set has been determined and the collection has been started then G1 must collect all live objects in all regions of the collection set without stopping. This behavior can lead to G1 exceeding the pause time goal if the heuristics choose a too large collection set, which for example can happen if the application behavior recently changed (the heuristics then work on "stale" data). This can in particular be observed during mixed collections, where the collection set often can contain too many old regions. There is need for a mechanism that detects when the heuristics repeatedly select a wrong amount of work for collections, and if so, have G1 perform the collection work incrementally in steps, where the collection can be aborted after each step. Such a mechanism would allow G1 to meet the pause time goal more often.

Description

If G1 discovers that the collection set selection heuristics repeatedly select the wrong number of regions, switch to a more incremental way of doing mixed collections: split the collection set into two parts, a mandatory and an optional part. The mandatory part comprises parts of the collection set that G1 can not process incrementally (e.g. the young regions) but can also contain old regions for improved efficiency. This may e.g. be 80% of the predicted collection set. The remaining 20% of the predicted collection set, which would consist of only old regions, then form the optional part.

After G1 finishes collecting the mandatory part, G1 starts collecting the optional part at a much more granular level (if there is time left). The granularity of collection of this optional part depends on the amount of time left, at most down to one region at a time. After completing collection of any part of the optional collection set, G1 can decide to stop the collection depending on the remaining time. As the predictions get more accurate again, the optional part of a collection are made smaller and smaller, until the mandatory part once again comprises all of the collection set (i.e. G1 completely relies on its heuristics). If the predictions becomes inaccurate again, then the next collections will consist of both a mandatory and optional part again.

Alternatives

Testing

The individual C++ parts making up the implementation should be tested using C++ unit tests. Since the abortable mixed collections would be an integral part of the G1 GC the code will be exercised by just running the existing tests.

Risks and Assumptions