author | brutisso |
Fri, 17 Apr 2015 08:09:41 +0200 | |
changeset 30262 | 04d3680cd029 |
parent 29796 | 7a04e5c250d1 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24092
diff
changeset
|
2 |
* Copyright (c) 2001, 2014, 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:
5350
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5350
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:
5350
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
|
27 |
#include "gc_implementation/g1/g1CollectorPolicy.hpp" |
|
28 |
#include "gc_implementation/g1/heapRegion.hpp" |
|
29 |
#include "gc_implementation/g1/survRateGroup.hpp" |
|
30 |
#include "memory/allocation.hpp" |
|
1374 | 31 |
|
32 |
SurvRateGroup::SurvRateGroup(G1CollectorPolicy* g1p, |
|
33 |
const char* name, |
|
34 |
size_t summary_surv_rates_len) : |
|
35 |
_g1p(g1p), _name(name), |
|
36 |
_summary_surv_rates_len(summary_surv_rates_len), |
|
37 |
_summary_surv_rates_max_len(0), |
|
2009 | 38 |
_summary_surv_rates(NULL), |
39 |
_surv_rate(NULL), |
|
40 |
_accum_surv_rate_pred(NULL), |
|
12117 | 41 |
_surv_rate_pred(NULL), |
42 |
_stats_arrays_length(0) { |
|
2009 | 43 |
reset(); |
1374 | 44 |
if (summary_surv_rates_len > 0) { |
45 |
size_t length = summary_surv_rates_len; |
|
13195 | 46 |
_summary_surv_rates = NEW_C_HEAP_ARRAY(NumberSeq*, length, mtGC); |
12117 | 47 |
for (size_t i = 0; i < length; ++i) { |
48 |
_summary_surv_rates[i] = new NumberSeq(); |
|
1374 | 49 |
} |
50 |
} |
|
51 |
||
52 |
start_adding_regions(); |
|
53 |
} |
|
54 |
||
12117 | 55 |
void SurvRateGroup::reset() { |
2009 | 56 |
_all_regions_allocated = 0; |
57 |
_setup_seq_num = 0; |
|
58 |
_accum_surv_rate = 0.0; |
|
59 |
_last_pred = 0.0; |
|
60 |
// the following will set up the arrays with length 1 |
|
61 |
_region_num = 1; |
|
12117 | 62 |
|
63 |
// The call to stop_adding_regions() will use "new" to refill |
|
64 |
// the _surv_rate_pred array, so we need to make sure to call |
|
65 |
// "delete". |
|
66 |
for (size_t i = 0; i < _stats_arrays_length; ++i) { |
|
67 |
delete _surv_rate_pred[i]; |
|
68 |
} |
|
69 |
_stats_arrays_length = 0; |
|
70 |
||
2009 | 71 |
stop_adding_regions(); |
72 |
guarantee( _stats_arrays_length == 1, "invariant" ); |
|
73 |
guarantee( _surv_rate_pred[0] != NULL, "invariant" ); |
|
74 |
_surv_rate_pred[0]->add(0.4); |
|
75 |
all_surviving_words_recorded(false); |
|
76 |
_region_num = 0; |
|
77 |
} |
|
78 |
||
1374 | 79 |
void |
80 |
SurvRateGroup::start_adding_regions() { |
|
2009 | 81 |
_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
|
82 |
_region_num = 0; |
1374 | 83 |
_accum_surv_rate = 0.0; |
84 |
} |
|
85 |
||
86 |
void |
|
87 |
SurvRateGroup::stop_adding_regions() { |
|
2009 | 88 |
if (_region_num > _stats_arrays_length) { |
1374 | 89 |
double* old_surv_rate = _surv_rate; |
90 |
double* old_accum_surv_rate_pred = _accum_surv_rate_pred; |
|
91 |
TruncatedSeq** old_surv_rate_pred = _surv_rate_pred; |
|
92 |
||
13195 | 93 |
_surv_rate = NEW_C_HEAP_ARRAY(double, _region_num, mtGC); |
94 |
_accum_surv_rate_pred = NEW_C_HEAP_ARRAY(double, _region_num, mtGC); |
|
95 |
_surv_rate_pred = NEW_C_HEAP_ARRAY(TruncatedSeq*, _region_num, mtGC); |
|
1374 | 96 |
|
12117 | 97 |
for (size_t i = 0; i < _stats_arrays_length; ++i) { |
1374 | 98 |
_surv_rate_pred[i] = old_surv_rate_pred[i]; |
12117 | 99 |
} |
2009 | 100 |
for (size_t i = _stats_arrays_length; i < _region_num; ++i) { |
1374 | 101 |
_surv_rate_pred[i] = new TruncatedSeq(10); |
102 |
} |
|
103 |
||
2009 | 104 |
_stats_arrays_length = _region_num; |
1374 | 105 |
|
12117 | 106 |
if (old_surv_rate != NULL) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
107 |
FREE_C_HEAP_ARRAY(double, old_surv_rate); |
12117 | 108 |
} |
109 |
if (old_accum_surv_rate_pred != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
110 |
FREE_C_HEAP_ARRAY(double, old_accum_surv_rate_pred); |
12117 | 111 |
} |
112 |
if (old_surv_rate_pred != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
113 |
FREE_C_HEAP_ARRAY(TruncatedSeq*, old_surv_rate_pred); |
12117 | 114 |
} |
1374 | 115 |
} |
116 |
||
12117 | 117 |
for (size_t i = 0; i < _stats_arrays_length; ++i) { |
1374 | 118 |
_surv_rate[i] = 0.0; |
12117 | 119 |
} |
1374 | 120 |
} |
121 |
||
122 |
double |
|
123 |
SurvRateGroup::accum_surv_rate(size_t adjustment) { |
|
124 |
// we might relax this one in the future... |
|
125 |
guarantee( adjustment == 0 || adjustment == 1, "pre-condition" ); |
|
126 |
||
127 |
double ret = _accum_surv_rate; |
|
128 |
if (adjustment > 0) { |
|
2009 | 129 |
TruncatedSeq* seq = get_seq(_region_num+1); |
1374 | 130 |
double surv_rate = _g1p->get_new_prediction(seq); |
131 |
ret += surv_rate; |
|
132 |
} |
|
133 |
||
134 |
return ret; |
|
135 |
} |
|
136 |
||
137 |
int |
|
138 |
SurvRateGroup::next_age_index() { |
|
2009 | 139 |
TruncatedSeq* seq = get_seq(_region_num); |
1374 | 140 |
double surv_rate = _g1p->get_new_prediction(seq); |
141 |
_accum_surv_rate += surv_rate; |
|
142 |
||
2009 | 143 |
++_region_num; |
1374 | 144 |
return (int) ++_all_regions_allocated; |
145 |
} |
|
146 |
||
147 |
void |
|
148 |
SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) { |
|
2009 | 149 |
guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num, |
1374 | 150 |
"pre-condition" ); |
151 |
guarantee( _surv_rate[age_in_group] <= 0.00001, |
|
152 |
"should only update each slot once" ); |
|
153 |
||
154 |
double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords; |
|
155 |
_surv_rate[age_in_group] = surv_rate; |
|
156 |
_surv_rate_pred[age_in_group]->add(surv_rate); |
|
157 |
if ((size_t)age_in_group < _summary_surv_rates_len) { |
|
158 |
_summary_surv_rates[age_in_group]->add(surv_rate); |
|
159 |
if ((size_t)(age_in_group+1) > _summary_surv_rates_max_len) |
|
160 |
_summary_surv_rates_max_len = age_in_group+1; |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
void |
|
165 |
SurvRateGroup::all_surviving_words_recorded(bool propagate) { |
|
2009 | 166 |
if (propagate && _region_num > 0) { // conservative |
167 |
double surv_rate = _surv_rate_pred[_region_num-1]->last(); |
|
168 |
for (size_t i = _region_num; i < _stats_arrays_length; ++i) { |
|
1374 | 169 |
guarantee( _surv_rate[i] <= 0.00001, |
170 |
"the slot should not have been updated" ); |
|
171 |
_surv_rate_pred[i]->add(surv_rate); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
double accum = 0.0; |
|
176 |
double pred = 0.0; |
|
2009 | 177 |
for (size_t i = 0; i < _stats_arrays_length; ++i) { |
1374 | 178 |
pred = _g1p->get_new_prediction(_surv_rate_pred[i]); |
179 |
if (pred > 1.0) pred = 1.0; |
|
180 |
accum += pred; |
|
181 |
_accum_surv_rate_pred[i] = accum; |
|
182 |
// gclog_or_tty->print_cr("age %3d, accum %10.2lf", i, accum); |
|
183 |
} |
|
184 |
_last_pred = pred; |
|
185 |
} |
|
186 |
||
187 |
#ifndef PRODUCT |
|
188 |
void |
|
189 |
SurvRateGroup::print() { |
|
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
190 |
gclog_or_tty->print_cr("Surv Rate Group: %s (" SIZE_FORMAT " entries)", |
5350
cccf0925702e
6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents:
2105
diff
changeset
|
191 |
_name, _region_num); |
2009 | 192 |
for (size_t i = 0; i < _region_num; ++i) { |
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
193 |
gclog_or_tty->print_cr(" age " SIZE_FORMAT_W(4) " surv rate %6.2lf %% pred %6.2lf %%", |
1374 | 194 |
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
|
195 |
_g1p->get_new_prediction(_surv_rate_pred[i]) * 100.0); |
1374 | 196 |
} |
197 |
} |
|
198 |
||
199 |
void |
|
200 |
SurvRateGroup::print_surv_rate_summary() { |
|
201 |
size_t length = _summary_surv_rates_max_len; |
|
202 |
if (length == 0) |
|
203 |
return; |
|
204 |
||
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24092
diff
changeset
|
205 |
gclog_or_tty->cr(); |
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
206 |
gclog_or_tty->print_cr("%s Rate Summary (for up to age " SIZE_FORMAT ")", _name, length-1); |
1374 | 207 |
gclog_or_tty->print_cr(" age range survival rate (avg) samples (avg)"); |
208 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
209 |
||
210 |
size_t index = 0; |
|
211 |
size_t limit = MIN2((int) length, 10); |
|
212 |
while (index < limit) { |
|
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
213 |
gclog_or_tty->print_cr(" " SIZE_FORMAT_W(4) |
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
214 |
" %6.2lf%% %6.2lf", |
1374 | 215 |
index, _summary_surv_rates[index]->avg() * 100.0, |
216 |
(double) _summary_surv_rates[index]->num()); |
|
217 |
++index; |
|
218 |
} |
|
219 |
||
220 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
221 |
||
222 |
int num = 0; |
|
223 |
double sum = 0.0; |
|
224 |
int samples = 0; |
|
225 |
while (index < length) { |
|
226 |
++num; |
|
227 |
sum += _summary_surv_rates[index]->avg() * 100.0; |
|
228 |
samples += _summary_surv_rates[index]->num(); |
|
229 |
++index; |
|
230 |
||
231 |
if (index == length || num % 10 == 0) { |
|
24092
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
232 |
gclog_or_tty->print_cr(" " SIZE_FORMAT_W(4) " .. " SIZE_FORMAT_W(4) |
e274d864545a
8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents:
13195
diff
changeset
|
233 |
" %6.2lf%% %6.2lf", |
1374 | 234 |
(index-1) / 10 * 10, index-1, sum / (double) num, |
235 |
(double) samples / (double) num); |
|
236 |
sum = 0.0; |
|
237 |
num = 0; |
|
238 |
samples = 0; |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
|
243 |
} |
|
244 |
#endif // PRODUCT |