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