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