Skip to content

Commit b659132

Browse files
JohnTortugokstefanj
authored andcommitted
8252888: Collapse G1MMUTracker class hierarchy
Reviewed-by: ayang, sjohanss, kbarrett
1 parent e63b90c commit b659132

File tree

3 files changed

+54
-67
lines changed

3 files changed

+54
-67
lines changed

src/hotspot/share/gc/g1/g1MMUTracker.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@
3939

4040
G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) :
4141
_time_slice(time_slice),
42-
_max_gc_time(max_gc_time) { }
43-
44-
G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) :
45-
G1MMUTracker(time_slice, max_gc_time),
42+
_max_gc_time(max_gc_time),
4643
_head_index(0),
4744
_tail_index(trim_index(_head_index+1)),
4845
_no_entries(0) { }
4946

50-
void G1MMUTrackerQueue::remove_expired_entries(double current_time) {
47+
void G1MMUTracker::remove_expired_entries(double current_time) {
5148
double limit = current_time - _time_slice;
5249
while (_no_entries > 0) {
5350
if (is_double_geq(limit, _array[_tail_index].end_time())) {
@@ -59,12 +56,12 @@ void G1MMUTrackerQueue::remove_expired_entries(double current_time) {
5956
guarantee(_no_entries == 0, "should have no entries in the array");
6057
}
6158

62-
double G1MMUTrackerQueue::calculate_gc_time(double current_time) {
59+
double G1MMUTracker::calculate_gc_time(double current_time) {
6360
double gc_time = 0.0;
6461
double limit = current_time - _time_slice;
6562
for (int i = 0; i < _no_entries; ++i) {
6663
int index = trim_index(_tail_index + i);
67-
G1MMUTrackerQueueElem *elem = &_array[index];
64+
G1MMUTrackerElem *elem = &_array[index];
6865
if (elem->end_time() > limit) {
6966
if (elem->start_time() > limit)
7067
gc_time += elem->duration();
@@ -75,7 +72,7 @@ double G1MMUTrackerQueue::calculate_gc_time(double current_time) {
7572
return gc_time;
7673
}
7774

78-
void G1MMUTrackerQueue::add_pause(double start, double end) {
75+
void G1MMUTracker::add_pause(double start, double end) {
7976
remove_expired_entries(end);
8077
if (_no_entries == QueueLength) {
8178
// OK, we've filled up the queue. There are a few ways
@@ -99,7 +96,7 @@ void G1MMUTrackerQueue::add_pause(double start, double end) {
9996
_head_index = trim_index(_head_index + 1);
10097
++_no_entries;
10198
}
102-
_array[_head_index] = G1MMUTrackerQueueElem(start, end);
99+
_array[_head_index] = G1MMUTrackerElem(start, end);
103100

104101
// Current entry needs to be added before calculating the value
105102
double slice_time = calculate_gc_time(end);
@@ -114,7 +111,7 @@ void G1MMUTrackerQueue::add_pause(double start, double end) {
114111
}
115112
}
116113

117-
double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
114+
double G1MMUTracker::when_sec(double current_time, double pause_time) {
118115
// if the pause is over the maximum, just assume that it's the maximum
119116
double adjusted_pause_time =
120117
(pause_time > max_gc_time()) ? max_gc_time() : pause_time;
@@ -126,13 +123,13 @@ double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) {
126123
return 0.0;
127124

128125
if (adjusted_pause_time == max_gc_time()) {
129-
G1MMUTrackerQueueElem *elem = &_array[_head_index];
126+
G1MMUTrackerElem *elem = &_array[_head_index];
130127
return elem->end_time() - limit;
131128
}
132129

133130
int index = _tail_index;
134131
while ( 1 ) {
135-
G1MMUTrackerQueueElem *elem = &_array[index];
132+
G1MMUTrackerElem *elem = &_array[index];
136133
if (elem->end_time() > limit) {
137134
if (elem->start_time() > limit)
138135
diff -= elem->duration();
Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,45 +29,7 @@
2929
#include "memory/allocation.hpp"
3030
#include "utilities/debug.hpp"
3131

32-
// Two major user controls over G1 behavior are setting a pause time goal (MaxGCPauseMillis),
33-
// over a time slice (GCPauseIntervalMillis). This defines the Minimum Mutator
34-
// Utilisation (MMU) goal.
35-
//
36-
// * Definitions *
37-
// Mutator Utilisation:
38-
// - for a given time slice duration "ts",
39-
// - mutator utilisation is the following fraction:
40-
// non_gc_time / ts
41-
//
42-
// Minimum Mutator Utilisation (MMU):
43-
// - the worst mutator utilisation across all time slices.
44-
//
45-
// G1MMUTracker keeps track of the GC work and decides when it is OK to do GC work
46-
// and for how long so that the MMU invariants are maintained.
47-
//
48-
// ***** ALL TIMES ARE IN SECS!!!!!!! *****
49-
// this is the "interface"
50-
class G1MMUTracker: public CHeapObj<mtGC> {
51-
protected:
52-
double _time_slice;
53-
double _max_gc_time; // this is per time slice
54-
55-
public:
56-
G1MMUTracker(double time_slice, double max_gc_time);
57-
58-
virtual void add_pause(double start, double end) = 0;
59-
virtual double when_sec(double current_time, double pause_time) = 0;
60-
61-
double max_gc_time() const {
62-
return _max_gc_time;
63-
}
64-
65-
inline double when_max_gc_sec(double current_time) {
66-
return when_sec(current_time, max_gc_time());
67-
}
68-
};
69-
70-
class G1MMUTrackerQueueElem {
32+
class G1MMUTrackerElem {
7133
private:
7234
double _start_time;
7335
double _end_time;
@@ -77,25 +39,45 @@ class G1MMUTrackerQueueElem {
7739
inline double end_time() { return _end_time; }
7840
inline double duration() { return _end_time - _start_time; }
7941

80-
G1MMUTrackerQueueElem() {
42+
G1MMUTrackerElem() {
8143
_start_time = 0.0;
8244
_end_time = 0.0;
8345
}
8446

85-
G1MMUTrackerQueueElem(double start_time, double end_time) {
47+
G1MMUTrackerElem(double start_time, double end_time) {
8648
_start_time = start_time;
8749
_end_time = end_time;
8850
}
8951
};
9052

91-
// this is an implementation of the MMUTracker using a (fixed-size) queue
92-
// that keeps track of all the recent pause times
93-
class G1MMUTrackerQueue: public G1MMUTracker {
53+
54+
// Two major user controls over G1 behavior are setting a pause
55+
// time goal (MaxGCPauseMillis), over a time slice (GCPauseIntervalMillis).
56+
// This defines the Minimum Mutator Utilisation (MMU) goal.
57+
//
58+
// * Definitions *
59+
// Mutator Utilisation:
60+
// - for a given time slice duration "ts",
61+
// - mutator utilisation is the following fraction:
62+
// non_gc_time / ts
63+
//
64+
// Minimum Mutator Utilisation (MMU):
65+
// - the worst mutator utilisation across all time slices.
66+
//
67+
// The G1MMUTracker uses a fixed-size queue to keep track of all
68+
// recent pause times. The pause time data is used to avoid
69+
// breaking the MMU.
70+
//
71+
// ***** ALL TIMES ARE IN SECS!!!!!!! *****
72+
class G1MMUTracker: public CHeapObj<mtGC> {
9473
private:
9574
enum PrivateConstants {
9675
QueueLength = 64
9776
};
9877

78+
double _time_slice;
79+
double _max_gc_time; // this is per time slice
80+
9981
// The array keeps track of all the pauses that fall within a time
10082
// slice (the last time slice during which pauses took place).
10183
// The data structure implemented is a circular queue.
@@ -105,13 +87,13 @@ class G1MMUTrackerQueue: public G1MMUTracker {
10587
// If the array is full, an easy fix is to look for the pauses with
10688
// the shortest gap between them and consolidate them.
10789
// For now, we have taken the expedient alternative of forgetting
108-
// the oldest entry in the event that +G1UseFixedWindowMMUTracker, thus
109-
// potentially violating MMU specs for some time thereafter.
90+
// the oldest entry, thus potentially violating MMU specs for
91+
// some time thereafter.
11092

111-
G1MMUTrackerQueueElem _array[QueueLength];
112-
int _head_index;
113-
int _tail_index;
114-
int _no_entries;
93+
G1MMUTrackerElem _array[QueueLength];
94+
int _head_index;
95+
int _tail_index;
96+
int _no_entries;
11597

11698
inline int trim_index(int index) {
11799
return (index + QueueLength) % QueueLength;
@@ -121,11 +103,19 @@ class G1MMUTrackerQueue: public G1MMUTracker {
121103
double calculate_gc_time(double current_time);
122104

123105
public:
124-
G1MMUTrackerQueue(double time_slice, double max_gc_time);
106+
G1MMUTracker(double time_slice, double max_gc_time);
107+
108+
void add_pause(double start, double end);
125109

126-
virtual void add_pause(double start, double end);
110+
double when_sec(double current_time, double pause_time);
127111

128-
virtual double when_sec(double current_time, double pause_time);
112+
double max_gc_time() const {
113+
return _max_gc_time;
114+
}
115+
116+
double when_max_gc_sec(double current_time) {
117+
return when_sec(current_time, max_gc_time());
118+
}
129119
};
130120

131121
#endif // SHARE_GC_G1_G1MMUTRACKER_HPP

src/hotspot/share/gc/g1/g1Policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ G1Policy::G1Policy(STWGCTimer* gc_timer) :
5656
_predictor(G1ConfidencePercent / 100.0),
5757
_analytics(new G1Analytics(&_predictor)),
5858
_remset_tracker(),
59-
_mmu_tracker(new G1MMUTrackerQueue(GCPauseIntervalMillis / 1000.0, MaxGCPauseMillis / 1000.0)),
59+
_mmu_tracker(new G1MMUTracker(GCPauseIntervalMillis / 1000.0, MaxGCPauseMillis / 1000.0)),
6060
_old_gen_alloc_tracker(),
6161
_ihop_control(create_ihop_control(&_old_gen_alloc_tracker, &_predictor)),
6262
_policy_counters(new GCPolicyCounters("GarbageFirst", 1, 2)),

0 commit comments

Comments
 (0)