author | johnc |
Thu, 22 Apr 2010 10:02:38 -0700 | |
changeset 5350 | cccf0925702e |
parent 2105 | 347008ce7984 |
child 5547 | f4b087cbb361 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
2 |
* Copyright 2001-2010 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/_survRateGroup.cpp.incl" |
|
27 |
||
28 |
SurvRateGroup::SurvRateGroup(G1CollectorPolicy* g1p, |
|
29 |
const char* name, |
|
30 |
size_t summary_surv_rates_len) : |
|
31 |
_g1p(g1p), _name(name), |
|
32 |
_summary_surv_rates_len(summary_surv_rates_len), |
|
33 |
_summary_surv_rates_max_len(0), |
|
2009 | 34 |
_summary_surv_rates(NULL), |
35 |
_surv_rate(NULL), |
|
36 |
_accum_surv_rate_pred(NULL), |
|
37 |
_surv_rate_pred(NULL) |
|
38 |
{ |
|
39 |
reset(); |
|
1374 | 40 |
if (summary_surv_rates_len > 0) { |
41 |
size_t length = summary_surv_rates_len; |
|
42 |
_summary_surv_rates = NEW_C_HEAP_ARRAY(NumberSeq*, length); |
|
43 |
if (_summary_surv_rates == NULL) { |
|
44 |
vm_exit_out_of_memory(sizeof(NumberSeq*) * length, |
|
45 |
"Not enough space for surv rate summary"); |
|
46 |
} |
|
47 |
for (size_t i = 0; i < length; ++i) |
|
48 |
_summary_surv_rates[i] = new NumberSeq(); |
|
49 |
} |
|
50 |
||
51 |
start_adding_regions(); |
|
52 |
} |
|
53 |
||
2009 | 54 |
|
55 |
void SurvRateGroup::reset() |
|
56 |
{ |
|
57 |
_all_regions_allocated = 0; |
|
58 |
_setup_seq_num = 0; |
|
59 |
_stats_arrays_length = 0; |
|
60 |
_accum_surv_rate = 0.0; |
|
61 |
_last_pred = 0.0; |
|
62 |
// the following will set up the arrays with length 1 |
|
63 |
_region_num = 1; |
|
64 |
stop_adding_regions(); |
|
65 |
guarantee( _stats_arrays_length == 1, "invariant" ); |
|
66 |
guarantee( _surv_rate_pred[0] != NULL, "invariant" ); |
|
67 |
_surv_rate_pred[0]->add(0.4); |
|
68 |
all_surviving_words_recorded(false); |
|
69 |
_region_num = 0; |
|
70 |
} |
|
71 |
||
72 |
||
1374 | 73 |
void |
74 |
SurvRateGroup::start_adding_regions() { |
|
2009 | 75 |
_setup_seq_num = _stats_arrays_length; |
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
76 |
_region_num = 0; |
1374 | 77 |
_accum_surv_rate = 0.0; |
78 |
||
79 |
#if 0 |
|
2009 | 80 |
gclog_or_tty->print_cr("[%s] start adding regions, seq num %d, length %d", |
81 |
_name, _setup_seq_num, _region_num); |
|
1374 | 82 |
#endif // 0 |
83 |
} |
|
84 |
||
85 |
void |
|
86 |
SurvRateGroup::stop_adding_regions() { |
|
87 |
||
88 |
#if 0 |
|
2009 | 89 |
gclog_or_tty->print_cr("[%s] stop adding regions, length %d", _name, _region_num); |
1374 | 90 |
#endif // 0 |
91 |
||
2009 | 92 |
if (_region_num > _stats_arrays_length) { |
1374 | 93 |
double* old_surv_rate = _surv_rate; |
94 |
double* old_accum_surv_rate_pred = _accum_surv_rate_pred; |
|
95 |
TruncatedSeq** old_surv_rate_pred = _surv_rate_pred; |
|
96 |
||
2009 | 97 |
_surv_rate = NEW_C_HEAP_ARRAY(double, _region_num); |
1374 | 98 |
if (_surv_rate == NULL) { |
2009 | 99 |
vm_exit_out_of_memory(sizeof(double) * _region_num, |
1374 | 100 |
"Not enough space for surv rate array."); |
101 |
} |
|
2009 | 102 |
_accum_surv_rate_pred = NEW_C_HEAP_ARRAY(double, _region_num); |
1374 | 103 |
if (_accum_surv_rate_pred == NULL) { |
2009 | 104 |
vm_exit_out_of_memory(sizeof(double) * _region_num, |
1374 | 105 |
"Not enough space for accum surv rate pred array."); |
106 |
} |
|
2009 | 107 |
_surv_rate_pred = NEW_C_HEAP_ARRAY(TruncatedSeq*, _region_num); |
1374 | 108 |
if (_surv_rate == NULL) { |
2009 | 109 |
vm_exit_out_of_memory(sizeof(TruncatedSeq*) * _region_num, |
1374 | 110 |
"Not enough space for surv rate pred array."); |
111 |
} |
|
112 |
||
2009 | 113 |
for (size_t i = 0; i < _stats_arrays_length; ++i) |
1374 | 114 |
_surv_rate_pred[i] = old_surv_rate_pred[i]; |
115 |
||
116 |
#if 0 |
|
2009 | 117 |
gclog_or_tty->print_cr("[%s] stop adding regions, new seqs %d to %d", |
118 |
_name, _array_length, _region_num - 1); |
|
1374 | 119 |
#endif // 0 |
120 |
||
2009 | 121 |
for (size_t i = _stats_arrays_length; i < _region_num; ++i) { |
1374 | 122 |
_surv_rate_pred[i] = new TruncatedSeq(10); |
123 |
// _surv_rate_pred[i]->add(last_pred); |
|
124 |
} |
|
125 |
||
2009 | 126 |
_stats_arrays_length = _region_num; |
1374 | 127 |
|
128 |
if (old_surv_rate != NULL) |
|
129 |
FREE_C_HEAP_ARRAY(double, old_surv_rate); |
|
130 |
if (old_accum_surv_rate_pred != NULL) |
|
131 |
FREE_C_HEAP_ARRAY(double, old_accum_surv_rate_pred); |
|
132 |
if (old_surv_rate_pred != NULL) |
|
133 |
FREE_C_HEAP_ARRAY(NumberSeq*, old_surv_rate_pred); |
|
134 |
} |
|
135 |
||
2009 | 136 |
for (size_t i = 0; i < _stats_arrays_length; ++i) |
1374 | 137 |
_surv_rate[i] = 0.0; |
138 |
} |
|
139 |
||
140 |
double |
|
141 |
SurvRateGroup::accum_surv_rate(size_t adjustment) { |
|
142 |
// we might relax this one in the future... |
|
143 |
guarantee( adjustment == 0 || adjustment == 1, "pre-condition" ); |
|
144 |
||
145 |
double ret = _accum_surv_rate; |
|
146 |
if (adjustment > 0) { |
|
2009 | 147 |
TruncatedSeq* seq = get_seq(_region_num+1); |
1374 | 148 |
double surv_rate = _g1p->get_new_prediction(seq); |
149 |
ret += surv_rate; |
|
150 |
} |
|
151 |
||
152 |
return ret; |
|
153 |
} |
|
154 |
||
155 |
int |
|
156 |
SurvRateGroup::next_age_index() { |
|
2009 | 157 |
TruncatedSeq* seq = get_seq(_region_num); |
1374 | 158 |
double surv_rate = _g1p->get_new_prediction(seq); |
159 |
_accum_surv_rate += surv_rate; |
|
160 |
||
2009 | 161 |
++_region_num; |
1374 | 162 |
return (int) ++_all_regions_allocated; |
163 |
} |
|
164 |
||
165 |
void |
|
166 |
SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) { |
|
2009 | 167 |
guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num, |
1374 | 168 |
"pre-condition" ); |
169 |
guarantee( _surv_rate[age_in_group] <= 0.00001, |
|
170 |
"should only update each slot once" ); |
|
171 |
||
172 |
double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords; |
|
173 |
_surv_rate[age_in_group] = surv_rate; |
|
174 |
_surv_rate_pred[age_in_group]->add(surv_rate); |
|
175 |
if ((size_t)age_in_group < _summary_surv_rates_len) { |
|
176 |
_summary_surv_rates[age_in_group]->add(surv_rate); |
|
177 |
if ((size_t)(age_in_group+1) > _summary_surv_rates_max_len) |
|
178 |
_summary_surv_rates_max_len = age_in_group+1; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
void |
|
183 |
SurvRateGroup::all_surviving_words_recorded(bool propagate) { |
|
2009 | 184 |
if (propagate && _region_num > 0) { // conservative |
185 |
double surv_rate = _surv_rate_pred[_region_num-1]->last(); |
|
1374 | 186 |
|
187 |
#if 0 |
|
188 |
gclog_or_tty->print_cr("propagating %1.2lf from %d to %d", |
|
189 |
surv_rate, _curr_length, _array_length - 1); |
|
190 |
#endif // 0 |
|
191 |
||
2009 | 192 |
for (size_t i = _region_num; i < _stats_arrays_length; ++i) { |
1374 | 193 |
guarantee( _surv_rate[i] <= 0.00001, |
194 |
"the slot should not have been updated" ); |
|
195 |
_surv_rate_pred[i]->add(surv_rate); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
double accum = 0.0; |
|
200 |
double pred = 0.0; |
|
2009 | 201 |
for (size_t i = 0; i < _stats_arrays_length; ++i) { |
1374 | 202 |
pred = _g1p->get_new_prediction(_surv_rate_pred[i]); |
203 |
if (pred > 1.0) pred = 1.0; |
|
204 |
accum += pred; |
|
205 |
_accum_surv_rate_pred[i] = accum; |
|
206 |
// gclog_or_tty->print_cr("age %3d, accum %10.2lf", i, accum); |
|
207 |
} |
|
208 |
_last_pred = pred; |
|
209 |
} |
|
210 |
||
211 |
#ifndef PRODUCT |
|
212 |
void |
|
213 |
SurvRateGroup::print() { |
|
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
214 |
gclog_or_tty->print_cr("Surv Rate Group: %s (%d entries)", |
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
215 |
_name, _region_num); |
2009 | 216 |
for (size_t i = 0; i < _region_num; ++i) { |
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
217 |
gclog_or_tty->print_cr(" age %4d surv rate %6.2lf %% pred %6.2lf %%", |
1374 | 218 |
i, _surv_rate[i] * 100.0, |
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
219 |
_g1p->get_new_prediction(_surv_rate_pred[i]) * 100.0); |
1374 | 220 |
} |
221 |
} |
|
222 |
||
223 |
void |
|
224 |
SurvRateGroup::print_surv_rate_summary() { |
|
225 |
size_t length = _summary_surv_rates_max_len; |
|
226 |
if (length == 0) |
|
227 |
return; |
|
228 |
||
229 |
gclog_or_tty->print_cr(""); |
|
230 |
gclog_or_tty->print_cr("%s Rate Summary (for up to age %d)", _name, length-1); |
|
231 |
gclog_or_tty->print_cr(" age range survival rate (avg) samples (avg)"); |
|
232 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
233 |
||
234 |
size_t index = 0; |
|
235 |
size_t limit = MIN2((int) length, 10); |
|
236 |
while (index < limit) { |
|
237 |
gclog_or_tty->print_cr(" %4d %6.2lf%% %6.2lf", |
|
238 |
index, _summary_surv_rates[index]->avg() * 100.0, |
|
239 |
(double) _summary_surv_rates[index]->num()); |
|
240 |
++index; |
|
241 |
} |
|
242 |
||
243 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
244 |
||
245 |
int num = 0; |
|
246 |
double sum = 0.0; |
|
247 |
int samples = 0; |
|
248 |
while (index < length) { |
|
249 |
++num; |
|
250 |
sum += _summary_surv_rates[index]->avg() * 100.0; |
|
251 |
samples += _summary_surv_rates[index]->num(); |
|
252 |
++index; |
|
253 |
||
254 |
if (index == length || num % 10 == 0) { |
|
255 |
gclog_or_tty->print_cr(" %4d .. %4d %6.2lf%% %6.2lf", |
|
256 |
(index-1) / 10 * 10, index-1, sum / (double) num, |
|
257 |
(double) samples / (double) num); |
|
258 |
sum = 0.0; |
|
259 |
num = 0; |
|
260 |
samples = 0; |
|
261 |
} |
|
262 |
} |
|
263 |
||
264 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
265 |
} |
|
266 |
#endif // PRODUCT |