author | iveresov |
Thu, 11 Feb 2010 15:52:19 -0800 | |
changeset 4902 | 991aaddb5165 |
parent 4458 | 075a9ef4e467 |
child 5033 | 55f476a32544 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
3795 | 2 |
* Copyright 2001-2009 Sun Microsystems, Inc. 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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "incls/_precompiled.incl" |
|
26 |
#include "incls/_g1MMUTracker.cpp.incl" |
|
27 |
||
28 |
#define _DISABLE_MMU 0 |
|
29 |
||
30 |
// can't rely on comparing doubles with tolerating a small margin for error |
|
31 |
#define SMALL_MARGIN 0.0000001 |
|
32 |
#define is_double_leq_0(_value) ( (_value) < SMALL_MARGIN ) |
|
33 |
#define is_double_leq(_val1, _val2) is_double_leq_0((_val1) - (_val2)) |
|
34 |
#define is_double_geq(_val1, _val2) is_double_leq_0((_val2) - (_val1)) |
|
35 |
||
36 |
/***** ALL TIMES ARE IN SECS!!!!!!! *****/ |
|
37 |
||
38 |
G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) : |
|
39 |
_time_slice(time_slice), |
|
3691 | 40 |
_max_gc_time(max_gc_time) { } |
1374 | 41 |
|
42 |
G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) : |
|
43 |
G1MMUTracker(time_slice, max_gc_time), |
|
44 |
_head_index(0), |
|
45 |
_tail_index(trim_index(_head_index+1)), |
|
46 |
_no_entries(0) { } |
|
47 |
||
48 |
void G1MMUTrackerQueue::remove_expired_entries(double current_time) { |
|
49 |
double limit = current_time - _time_slice; |
|
50 |
while (_no_entries > 0) { |
|
51 |
if (is_double_geq(limit, _array[_tail_index].end_time())) { |
|
52 |
_tail_index = trim_index(_tail_index + 1); |
|
53 |
--_no_entries; |
|
54 |
} else |
|
55 |
return; |
|
56 |
} |
|
57 |
guarantee(_no_entries == 0, "should have no entries in the array"); |
|
58 |
} |
|
59 |
||
60 |
double G1MMUTrackerQueue::calculate_gc_time(double current_time) { |
|
61 |
double gc_time = 0.0; |
|
62 |
double limit = current_time - _time_slice; |
|
63 |
for (int i = 0; i < _no_entries; ++i) { |
|
64 |
int index = trim_index(_tail_index + i); |
|
65 |
G1MMUTrackerQueueElem *elem = &_array[index]; |
|
66 |
if (elem->end_time() > limit) { |
|
67 |
if (elem->start_time() > limit) |
|
68 |
gc_time += elem->duration(); |
|
69 |
else |
|
70 |
gc_time += elem->end_time() - limit; |
|
71 |
} |
|
72 |
} |
|
73 |
return gc_time; |
|
74 |
} |
|
75 |
||
76 |
void G1MMUTrackerQueue::add_pause(double start, double end, bool gc_thread) { |
|
77 |
double longest_allowed = longest_pause_internal(start); |
|
78 |
if (longest_allowed < 0.0) |
|
79 |
longest_allowed = 0.0; |
|
80 |
double duration = end - start; |
|
81 |
||
82 |
remove_expired_entries(end); |
|
83 |
if (_no_entries == QueueLength) { |
|
84 |
// OK, right now when we fill up we bomb out |
|
85 |
// there are a few ways of dealing with this "gracefully" |
|
86 |
// increase the array size (:-) |
|
87 |
// remove the oldest entry (this might allow more GC time for |
|
88 |
// the time slice than what's allowed) |
|
4458
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
89 |
// 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
|
90 |
// (this might allow less GC time than what's allowed) |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
91 |
guarantee(NOT_PRODUCT(ScavengeALot ||) G1ForgetfulMMUTracker, |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
92 |
"array full, currently we can't recover unless +G1ForgetfulMMUTracker"); |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
93 |
// 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
|
94 |
// 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
|
95 |
// or performance (we are GC'ing most of the time anyway!), |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
96 |
// simply overwrite the oldest entry in the tracker: this |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
97 |
// is also the behaviour when G1ForgetfulMMUTracker is enabled. |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
98 |
_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
|
99 |
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
|
100 |
_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
|
101 |
} else { |
075a9ef4e467
6902303: G1: ScavengeALot should cause an incremental, rather than a full, collection
ysr
parents:
3795
diff
changeset
|
102 |
_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
|
103 |
++_no_entries; |
1374 | 104 |
} |
105 |
_array[_head_index] = G1MMUTrackerQueueElem(start, end); |
|
106 |
} |
|
107 |
||
108 |
// basically the _internal call does not remove expired entries |
|
109 |
// this is for trying things out in the future and a couple |
|
110 |
// of other places (debugging) |
|
111 |
||
112 |
double G1MMUTrackerQueue::longest_pause(double current_time) { |
|
113 |
if (_DISABLE_MMU) |
|
114 |
return _max_gc_time; |
|
115 |
||
116 |
MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); |
|
117 |
remove_expired_entries(current_time); |
|
118 |
||
119 |
return longest_pause_internal(current_time); |
|
120 |
} |
|
121 |
||
122 |
double G1MMUTrackerQueue::longest_pause_internal(double current_time) { |
|
123 |
double target_time = _max_gc_time; |
|
124 |
||
125 |
while( 1 ) { |
|
126 |
double gc_time = |
|
3691 | 127 |
calculate_gc_time(current_time + target_time); |
1374 | 128 |
double diff = target_time + gc_time - _max_gc_time; |
129 |
if (!is_double_leq_0(diff)) { |
|
130 |
target_time -= diff; |
|
131 |
if (is_double_leq_0(target_time)) { |
|
132 |
target_time = -1.0; |
|
133 |
break; |
|
134 |
} |
|
135 |
} else { |
|
136 |
break; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
return target_time; |
|
141 |
} |
|
142 |
||
143 |
// basically the _internal call does not remove expired entries |
|
144 |
// this is for trying things out in the future and a couple |
|
145 |
// of other places (debugging) |
|
146 |
||
147 |
double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { |
|
148 |
if (_DISABLE_MMU) |
|
149 |
return 0.0; |
|
150 |
||
151 |
MutexLockerEx x(MMUTracker_lock, Mutex::_no_safepoint_check_flag); |
|
152 |
remove_expired_entries(current_time); |
|
153 |
||
154 |
return when_internal(current_time, pause_time); |
|
155 |
} |
|
156 |
||
157 |
double G1MMUTrackerQueue::when_internal(double current_time, |
|
158 |
double pause_time) { |
|
159 |
// if the pause is over the maximum, just assume that it's the maximum |
|
160 |
double adjusted_pause_time = |
|
161 |
(pause_time > max_gc_time()) ? max_gc_time() : pause_time; |
|
162 |
double earliest_end = current_time + adjusted_pause_time; |
|
163 |
double limit = earliest_end - _time_slice; |
|
164 |
double gc_time = calculate_gc_time(earliest_end); |
|
165 |
double diff = gc_time + adjusted_pause_time - max_gc_time(); |
|
166 |
if (is_double_leq_0(diff)) |
|
167 |
return 0.0; |
|
168 |
||
169 |
int index = _tail_index; |
|
170 |
while ( 1 ) { |
|
171 |
G1MMUTrackerQueueElem *elem = &_array[index]; |
|
172 |
if (elem->end_time() > limit) { |
|
173 |
if (elem->start_time() > limit) |
|
174 |
diff -= elem->duration(); |
|
175 |
else |
|
176 |
diff -= elem->end_time() - limit; |
|
177 |
if (is_double_leq_0(diff)) |
|
178 |
return elem->end_time() + diff + _time_slice - adjusted_pause_time - current_time; |
|
179 |
} |
|
180 |
index = trim_index(index+1); |
|
181 |
guarantee(index != trim_index(_head_index + 1), "should not go past head"); |
|
182 |
} |
|
183 |
} |