author | jwilhelm |
Thu, 03 Oct 2013 21:36:29 +0200 | |
changeset 20398 | b206c580c45f |
parent 10523 | cdb54c167ab0 |
child 30576 | 463e71cefd8f |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
10523
cdb54c167ab0
7050392: G1: Introduce flag to generate a log of the G1 ergonomic decisions
tonyp
parents:
7397
diff
changeset
|
2 |
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. |
1374 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5033
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5033
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5033
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "gc_implementation/g1/g1MMUTracker.hpp" |
|
27 |
#include "runtime/mutexLocker.hpp" |
|
28 |
#include "utilities/ostream.hpp" |
|
1374 | 29 |
|
30 |
#define _DISABLE_MMU 0 |
|
31 |
||
32 |
// can't rely on comparing doubles with tolerating a small margin for error |
|
33 |
#define SMALL_MARGIN 0.0000001 |
|
34 |
#define is_double_leq_0(_value) ( (_value) < SMALL_MARGIN ) |
|
35 |
#define is_double_leq(_val1, _val2) is_double_leq_0((_val1) - (_val2)) |
|
36 |
#define is_double_geq(_val1, _val2) is_double_leq_0((_val2) - (_val1)) |
|
37 |
||
38 |
/***** ALL TIMES ARE IN SECS!!!!!!! *****/ |
|
39 |
||
40 |
G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) : |
|
41 |
_time_slice(time_slice), |
|
3691 | 42 |
_max_gc_time(max_gc_time) { } |
1374 | 43 |
|
44 |
G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) : |
|
45 |
G1MMUTracker(time_slice, max_gc_time), |
|
46 |
_head_index(0), |
|
47 |
_tail_index(trim_index(_head_index+1)), |
|
48 |
_no_entries(0) { } |
|
49 |
||
50 |
void G1MMUTrackerQueue::remove_expired_entries(double current_time) { |
|
51 |
double limit = current_time - _time_slice; |
|
52 |
while (_no_entries > 0) { |
|
53 |
if (is_double_geq(limit, _array[_tail_index].end_time())) { |
|
54 |
_tail_index = trim_index(_tail_index + 1); |
|
55 |
--_no_entries; |
|
56 |
} else |
|
57 |
return; |
|
58 |
} |
|
59 |
guarantee(_no_entries == 0, "should have no entries in the array"); |
|
60 |
} |
|
61 |
||
62 |
double G1MMUTrackerQueue::calculate_gc_time(double current_time) { |
|
63 |
double gc_time = 0.0; |
|
64 |
double limit = current_time - _time_slice; |
|
65 |
for (int i = 0; i < _no_entries; ++i) { |
|
66 |
int index = trim_index(_tail_index + i); |
|
67 |
G1MMUTrackerQueueElem *elem = &_array[index]; |
|
68 |
if (elem->end_time() > limit) { |
|
69 |
if (elem->start_time() > limit) |
|
70 |
gc_time += elem->duration(); |
|
71 |
else |
|
72 |
gc_time += elem->end_time() - limit; |
|
73 |
} |
|
74 |
} |
|
75 |
return gc_time; |
|
76 |
} |
|
77 |
||
78 |
void G1MMUTrackerQueue::add_pause(double start, double end, bool gc_thread) { |
|
79 |
double longest_allowed = longest_pause_internal(start); |
|
80 |
if (longest_allowed < 0.0) |
|
81 |
longest_allowed = 0.0; |
|
82 |
double duration = end - start; |
|
83 |
||
84 |
remove_expired_entries(end); |
|
85 |
if (_no_entries == QueueLength) { |
|
5714
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
86 |
// OK, we've filled up the queue. There are a few ways |
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
87 |
// of dealing with this "gracefully" |
1374 | 88 |
// increase the array size (:-) |
89 |
// remove the oldest entry (this might allow more GC time for |
|
5714
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
90 |
// the time slice than what's allowed) - this is what we |
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
91 |
// currently do |
4458
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
92 |
// consolidate the two entries with the minimum gap between them |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
93 |
// (this might allow less GC time than what's allowed) |
5714
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
94 |
|
4458
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
95 |
// In the case where ScavengeALot is true, such overflow is not |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
96 |
// uncommon; in such cases, we can, without much loss of precision |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
97 |
// or performance (we are GC'ing most of the time anyway!), |
5714
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
98 |
// simply overwrite the oldest entry in the tracker. |
f8777c8c7a3b
6941378: G1: change default value of G1UseFixedWindowMMUTracker to true
johnc
parents:
5033
diff
changeset
|
99 |
|
4458
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
100 |
_head_index = trim_index(_head_index + 1); |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
101 |
assert(_head_index == _tail_index, "Because we have a full circular buffer"); |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
102 |
_tail_index = trim_index(_tail_index + 1); |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
103 |
} else { |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
104 |
_head_index = trim_index(_head_index + 1); |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
105 |
++_no_entries; |
1374 | 106 |
} |
107 |
_array[_head_index] = G1MMUTrackerQueueElem(start, end); |
|
108 |
} |
|
109 |
||
110 |
// basically the _internal call does not remove expired entries |
|
111 |
// this is for trying things out in the future and a couple |
|
112 |
// of other places (debugging) |
|
113 |
||
114 |
double G1MMUTrackerQueue::longest_pause(double current_time) { |
|
115 |
if (_DISABLE_MMU) |
|
116 |
return _max_gc_time; |
|
117 |
||
118 |
MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); |
|
119 |
remove_expired_entries(current_time); |
|
120 |
||
121 |
return longest_pause_internal(current_time); |
|
122 |
} |
|
123 |
||
124 |
double G1MMUTrackerQueue::longest_pause_internal(double current_time) { |
|
125 |
double target_time = _max_gc_time; |
|
126 |
||
127 |
while( 1 ) { |
|
128 |
double gc_time = |
|
3691 | 129 |
calculate_gc_time(current_time + target_time); |
1374 | 130 |
double diff = target_time + gc_time - _max_gc_time; |
131 |
if (!is_double_leq_0(diff)) { |
|
132 |
target_time -= diff; |
|
133 |
if (is_double_leq_0(target_time)) { |
|
134 |
target_time = -1.0; |
|
135 |
break; |
|
136 |
} |
|
137 |
} else { |
|
138 |
break; |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
return target_time; |
|
143 |
} |
|
144 |
||
145 |
// basically the _internal call does not remove expired entries |
|
146 |
// this is for trying things out in the future and a couple |
|
147 |
// of other places (debugging) |
|
148 |
||
149 |
double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { |
|
150 |
if (_DISABLE_MMU) |
|
151 |
return 0.0; |
|
152 |
||
153 |
MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); |
|
154 |
remove_expired_entries(current_time); |
|
155 |
||
156 |
return when_internal(current_time, pause_time); |
|
157 |
} |
|
158 |
||
159 |
double G1MMUTrackerQueue::when_internal(double current_time, |
|
160 |
double pause_time) { |
|
161 |
// if the pause is over the maximum, just assume that it's the maximum |
|
162 |
double adjusted_pause_time = |
|
163 |
(pause_time > max_gc_time()) ? max_gc_time() : pause_time; |
|
164 |
double earliest_end = current_time + adjusted_pause_time; |
|
165 |
double limit = earliest_end - _time_slice; |
|
166 |
double gc_time = calculate_gc_time(earliest_end); |
|
167 |
double diff = gc_time + adjusted_pause_time - max_gc_time(); |
|
168 |
if (is_double_leq_0(diff)) |
|
169 |
return 0.0; |
|
170 |
||
171 |
int index = _tail_index; |
|
172 |
while ( 1 ) { |
|
173 |
G1MMUTrackerQueueElem *elem = &_array[index]; |
|
174 |
if (elem->end_time() > limit) { |
|
175 |
if (elem->start_time() > limit) |
|
176 |
diff -= elem->duration(); |
|
177 |
else |
|
178 |
diff -= elem->end_time() - limit; |
|
179 |
if (is_double_leq_0(diff)) |
|
180 |
return elem->end_time() + diff + _time_slice - adjusted_pause_time - current_time; |
|
181 |
} |
|
182 |
index = trim_index(index+1); |
|
183 |
guarantee(index != trim_index(_head_index + 1), "should not go past head"); |
|
184 |
} |
|
185 |
} |