8290376: G1: Refactor G1MMUTracker::when_sec
Reviewed-by: tschatzl, iwalulya
This commit is contained in:
parent
5a20bc44b1
commit
dc7e2562f4
src/hotspot/share/gc/g1
@ -111,46 +111,61 @@ void G1MMUTracker::add_pause(double start, double end) {
|
||||
}
|
||||
}
|
||||
|
||||
// current_timestamp
|
||||
// GC events / pause_time
|
||||
// / | \ \ | / /
|
||||
// -------------[----]-[---]--[--]---[---]------|[--]-----> Time
|
||||
// | | |
|
||||
// | | |
|
||||
// |<- limit | |
|
||||
// | |<- balance_timestamp |
|
||||
// | ^ |
|
||||
// | |
|
||||
// |<-------- _time_slice ------>|
|
||||
//
|
||||
// The MMU constraint requires that we can spend up to `max_gc_time()` on GC
|
||||
// pauses inside a window of `_time_slice` length. Therefore, we have a GC
|
||||
// budget of `max_gc_time() - pause_time`, which is to be accounted for by past
|
||||
// GC events.
|
||||
//
|
||||
// Focusing on GC events that are inside [limit, current_timestamp], we iterate
|
||||
// over them from the newest to the oldest (right-to-left in the diagram) and
|
||||
// try to locate the timestamp annotated with ^, so that the accumulated GC
|
||||
// time inside [balance_timestamp, current_timestamp] is equal to the budget.
|
||||
// Next, return `balance_timestamp - limit`.
|
||||
//
|
||||
// When there are no enough GC events, i.e. we have a surplus buget, a new GC
|
||||
// pause can start right away, so return 0.
|
||||
double G1MMUTracker::when_sec(double current_timestamp, double pause_time) {
|
||||
assert(pause_time > 0.0, "precondition");
|
||||
|
||||
// If the pause is over the maximum, just assume that it's the maximum.
|
||||
double adjusted_pause_time =
|
||||
(pause_time > max_gc_time()) ? max_gc_time() : pause_time;
|
||||
pause_time = MIN2(pause_time, max_gc_time());
|
||||
|
||||
// Earliest end time of a hypothetical pause starting now, taking pause_time.
|
||||
double earliest_end_time = current_timestamp + adjusted_pause_time;
|
||||
double gc_time_in_recent_time_slice = calculate_gc_time(earliest_end_time) + adjusted_pause_time;
|
||||
double gc_budget = max_gc_time() - pause_time;
|
||||
|
||||
// How much gc time is needed to pass within the MMU window to fit the given pause into the MMU.
|
||||
double gc_time_to_pass = gc_time_in_recent_time_slice - max_gc_time();
|
||||
|
||||
// If that time to pass is zero or negative we could start the pause immediately.
|
||||
if (is_double_leq_0(gc_time_to_pass)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Trivially, if the pause is of maximum pause time, the required delay is what the MMU dictates by
|
||||
// the time slice and maximum gc pause, counted from the end of the last pause.
|
||||
if (adjusted_pause_time == max_gc_time()) {
|
||||
G1MMUTrackerElem *elem = &_array[_head_index];
|
||||
return (elem->end_time() + (_time_slice - max_gc_time())) - current_timestamp;
|
||||
}
|
||||
|
||||
// Now go through the recent pause time events,
|
||||
double limit = earliest_end_time - _time_slice;
|
||||
int index = _tail_index;
|
||||
while ( 1 ) {
|
||||
double limit = current_timestamp + pause_time - _time_slice;
|
||||
// Iterate from newest to oldest.
|
||||
for (int i = 0; i < _no_entries; ++i) {
|
||||
int index = trim_index(_head_index + i);
|
||||
G1MMUTrackerElem *elem = &_array[index];
|
||||
if (elem->end_time() > limit) {
|
||||
if (elem->start_time() > limit) {
|
||||
gc_time_to_pass -= elem->duration();
|
||||
} else {
|
||||
gc_time_to_pass -= elem->end_time() - limit;
|
||||
}
|
||||
if (is_double_leq_0(gc_time_to_pass)) {
|
||||
return elem->end_time() + (_time_slice + gc_time_to_pass) - earliest_end_time;
|
||||
}
|
||||
// Outside the window.
|
||||
if (elem->end_time() <= limit) {
|
||||
break;
|
||||
}
|
||||
index = trim_index(index+1);
|
||||
guarantee(index != trim_index(_head_index + 1), "should not go past head");
|
||||
|
||||
double duration = (elem->end_time() - MAX2(elem->start_time(), limit));
|
||||
// This duration would exceed (strictly greater than) the budget.
|
||||
if (duration > gc_budget) {
|
||||
// This timestamp captures the instant the budget is balanced (or used up).
|
||||
double balance_timestamp = elem->end_time() - gc_budget;
|
||||
assert(balance_timestamp >= limit, "inv");
|
||||
return balance_timestamp - limit;
|
||||
}
|
||||
|
||||
gc_budget -= duration;
|
||||
}
|
||||
|
||||
// Not enough gc time spent inside the window, we have a budget surplus.
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ private:
|
||||
// Returns the amount of time spent in gc pauses in the time slice before the
|
||||
// given timestamp.
|
||||
double calculate_gc_time(double current_timestamp);
|
||||
|
||||
public:
|
||||
G1MMUTracker(double time_slice, double max_gc_time);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user