Skip to content

Commit

Permalink
8290177: Improve documentation in G1MMUTracker
Browse files Browse the repository at this point in the history
Reviewed-by: iwalulya, ayang
  • Loading branch information
Thomas Schatzl committed Jul 14, 2022
1 parent 890bced commit 757a742
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
44 changes: 28 additions & 16 deletions src/hotspot/share/gc/g1/g1MMUTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ void G1MMUTracker::remove_expired_entries(double current_time) {
guarantee(_no_entries == 0, "should have no entries in the array");
}

double G1MMUTracker::calculate_gc_time(double current_time) {
double G1MMUTracker::calculate_gc_time(double current_timestamp) {
double gc_time = 0.0;
double limit = current_time - _time_slice;
double limit = current_timestamp - _time_slice;
for (int i = 0; i < _no_entries; ++i) {
int index = trim_index(_tail_index + i);
G1MMUTrackerElem *elem = &_array[index];
Expand Down Expand Up @@ -111,32 +111,44 @@ void G1MMUTracker::add_pause(double start, double end) {
}
}

double G1MMUTracker::when_sec(double current_time, double pause_time) {
// if the pause is over the maximum, just assume that it's the maximum
double G1MMUTracker::when_sec(double current_timestamp, double pause_time) {
// 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;
double earliest_end = current_time + adjusted_pause_time;
double limit = earliest_end - _time_slice;
double gc_time = calculate_gc_time(earliest_end);
double diff = gc_time + adjusted_pause_time - max_gc_time();
if (is_double_leq_0(diff))

// 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;

// 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() - limit;
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 ) {
G1MMUTrackerElem *elem = &_array[index];
if (elem->end_time() > limit) {
if (elem->start_time() > limit)
diff -= elem->duration();
else
diff -= elem->end_time() - limit;
if (is_double_leq_0(diff))
return elem->end_time() + diff - 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;
}
}
index = trim_index(index+1);
guarantee(index != trim_index(_head_index + 1), "should not go past head");
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/gc/g1/g1MMUTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ class G1MMUTracker: public CHeapObj<mtGC> {
}

void remove_expired_entries(double current_time);
double calculate_gc_time(double current_time);
// 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);

void add_pause(double start, double end);

double when_sec(double current_time, double pause_time);
// Minimum delay required from current_timestamp until a GC pause of duration
// pause_time may be scheduled without violating the MMU constraint.
double when_sec(double current_timestamp, double pause_time);

double max_gc_time() const {
return _max_gc_time;
Expand Down

1 comment on commit 757a742

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.