Wed, 02 Nov 2011 08:04:23 +0100
7106751: G1: gc/gctests/nativeGC03 crashes VM with SIGSEGV
Summary: _cset_rs_update_cl[] was indexed with values beyond what it is set up to handle.
Reviewed-by: ysr, jmasa, johnc
ysr@777 | 1 | /* |
trims@1907 | 2 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 27 | #include "gc_implementation/g1/g1CollectorPolicy.hpp" |
stefank@2314 | 28 | #include "gc_implementation/g1/heapRegion.hpp" |
stefank@2314 | 29 | #include "gc_implementation/g1/survRateGroup.hpp" |
stefank@2314 | 30 | #include "memory/allocation.hpp" |
ysr@777 | 31 | |
ysr@777 | 32 | SurvRateGroup::SurvRateGroup(G1CollectorPolicy* g1p, |
ysr@777 | 33 | const char* name, |
ysr@777 | 34 | size_t summary_surv_rates_len) : |
ysr@777 | 35 | _g1p(g1p), _name(name), |
ysr@777 | 36 | _summary_surv_rates_len(summary_surv_rates_len), |
ysr@777 | 37 | _summary_surv_rates_max_len(0), |
apetrusenko@980 | 38 | _summary_surv_rates(NULL), |
apetrusenko@980 | 39 | _surv_rate(NULL), |
apetrusenko@980 | 40 | _accum_surv_rate_pred(NULL), |
apetrusenko@980 | 41 | _surv_rate_pred(NULL) |
apetrusenko@980 | 42 | { |
apetrusenko@980 | 43 | reset(); |
ysr@777 | 44 | if (summary_surv_rates_len > 0) { |
ysr@777 | 45 | size_t length = summary_surv_rates_len; |
ysr@777 | 46 | _summary_surv_rates = NEW_C_HEAP_ARRAY(NumberSeq*, length); |
ysr@777 | 47 | if (_summary_surv_rates == NULL) { |
ysr@777 | 48 | vm_exit_out_of_memory(sizeof(NumberSeq*) * length, |
ysr@777 | 49 | "Not enough space for surv rate summary"); |
ysr@777 | 50 | } |
ysr@777 | 51 | for (size_t i = 0; i < length; ++i) |
ysr@777 | 52 | _summary_surv_rates[i] = new NumberSeq(); |
ysr@777 | 53 | } |
ysr@777 | 54 | |
ysr@777 | 55 | start_adding_regions(); |
ysr@777 | 56 | } |
ysr@777 | 57 | |
apetrusenko@980 | 58 | |
apetrusenko@980 | 59 | void SurvRateGroup::reset() |
apetrusenko@980 | 60 | { |
apetrusenko@980 | 61 | _all_regions_allocated = 0; |
apetrusenko@980 | 62 | _setup_seq_num = 0; |
apetrusenko@980 | 63 | _stats_arrays_length = 0; |
apetrusenko@980 | 64 | _accum_surv_rate = 0.0; |
apetrusenko@980 | 65 | _last_pred = 0.0; |
apetrusenko@980 | 66 | // the following will set up the arrays with length 1 |
apetrusenko@980 | 67 | _region_num = 1; |
apetrusenko@980 | 68 | stop_adding_regions(); |
apetrusenko@980 | 69 | guarantee( _stats_arrays_length == 1, "invariant" ); |
apetrusenko@980 | 70 | guarantee( _surv_rate_pred[0] != NULL, "invariant" ); |
apetrusenko@980 | 71 | _surv_rate_pred[0]->add(0.4); |
apetrusenko@980 | 72 | all_surviving_words_recorded(false); |
apetrusenko@980 | 73 | _region_num = 0; |
apetrusenko@980 | 74 | } |
apetrusenko@980 | 75 | |
apetrusenko@980 | 76 | |
ysr@777 | 77 | void |
ysr@777 | 78 | SurvRateGroup::start_adding_regions() { |
apetrusenko@980 | 79 | _setup_seq_num = _stats_arrays_length; |
johnc@1829 | 80 | _region_num = 0; |
ysr@777 | 81 | _accum_surv_rate = 0.0; |
ysr@777 | 82 | |
ysr@777 | 83 | #if 0 |
apetrusenko@980 | 84 | gclog_or_tty->print_cr("[%s] start adding regions, seq num %d, length %d", |
apetrusenko@980 | 85 | _name, _setup_seq_num, _region_num); |
ysr@777 | 86 | #endif // 0 |
ysr@777 | 87 | } |
ysr@777 | 88 | |
ysr@777 | 89 | void |
ysr@777 | 90 | SurvRateGroup::stop_adding_regions() { |
ysr@777 | 91 | |
ysr@777 | 92 | #if 0 |
apetrusenko@980 | 93 | gclog_or_tty->print_cr("[%s] stop adding regions, length %d", _name, _region_num); |
ysr@777 | 94 | #endif // 0 |
ysr@777 | 95 | |
apetrusenko@980 | 96 | if (_region_num > _stats_arrays_length) { |
ysr@777 | 97 | double* old_surv_rate = _surv_rate; |
ysr@777 | 98 | double* old_accum_surv_rate_pred = _accum_surv_rate_pred; |
ysr@777 | 99 | TruncatedSeq** old_surv_rate_pred = _surv_rate_pred; |
ysr@777 | 100 | |
apetrusenko@980 | 101 | _surv_rate = NEW_C_HEAP_ARRAY(double, _region_num); |
ysr@777 | 102 | if (_surv_rate == NULL) { |
apetrusenko@980 | 103 | vm_exit_out_of_memory(sizeof(double) * _region_num, |
ysr@777 | 104 | "Not enough space for surv rate array."); |
ysr@777 | 105 | } |
apetrusenko@980 | 106 | _accum_surv_rate_pred = NEW_C_HEAP_ARRAY(double, _region_num); |
ysr@777 | 107 | if (_accum_surv_rate_pred == NULL) { |
apetrusenko@980 | 108 | vm_exit_out_of_memory(sizeof(double) * _region_num, |
ysr@777 | 109 | "Not enough space for accum surv rate pred array."); |
ysr@777 | 110 | } |
apetrusenko@980 | 111 | _surv_rate_pred = NEW_C_HEAP_ARRAY(TruncatedSeq*, _region_num); |
ysr@777 | 112 | if (_surv_rate == NULL) { |
apetrusenko@980 | 113 | vm_exit_out_of_memory(sizeof(TruncatedSeq*) * _region_num, |
ysr@777 | 114 | "Not enough space for surv rate pred array."); |
ysr@777 | 115 | } |
ysr@777 | 116 | |
apetrusenko@980 | 117 | for (size_t i = 0; i < _stats_arrays_length; ++i) |
ysr@777 | 118 | _surv_rate_pred[i] = old_surv_rate_pred[i]; |
ysr@777 | 119 | |
ysr@777 | 120 | #if 0 |
apetrusenko@980 | 121 | gclog_or_tty->print_cr("[%s] stop adding regions, new seqs %d to %d", |
apetrusenko@980 | 122 | _name, _array_length, _region_num - 1); |
ysr@777 | 123 | #endif // 0 |
ysr@777 | 124 | |
apetrusenko@980 | 125 | for (size_t i = _stats_arrays_length; i < _region_num; ++i) { |
ysr@777 | 126 | _surv_rate_pred[i] = new TruncatedSeq(10); |
ysr@777 | 127 | // _surv_rate_pred[i]->add(last_pred); |
ysr@777 | 128 | } |
ysr@777 | 129 | |
apetrusenko@980 | 130 | _stats_arrays_length = _region_num; |
ysr@777 | 131 | |
ysr@777 | 132 | if (old_surv_rate != NULL) |
ysr@777 | 133 | FREE_C_HEAP_ARRAY(double, old_surv_rate); |
ysr@777 | 134 | if (old_accum_surv_rate_pred != NULL) |
ysr@777 | 135 | FREE_C_HEAP_ARRAY(double, old_accum_surv_rate_pred); |
ysr@777 | 136 | if (old_surv_rate_pred != NULL) |
ysr@777 | 137 | FREE_C_HEAP_ARRAY(NumberSeq*, old_surv_rate_pred); |
ysr@777 | 138 | } |
ysr@777 | 139 | |
apetrusenko@980 | 140 | for (size_t i = 0; i < _stats_arrays_length; ++i) |
ysr@777 | 141 | _surv_rate[i] = 0.0; |
ysr@777 | 142 | } |
ysr@777 | 143 | |
ysr@777 | 144 | double |
ysr@777 | 145 | SurvRateGroup::accum_surv_rate(size_t adjustment) { |
ysr@777 | 146 | // we might relax this one in the future... |
ysr@777 | 147 | guarantee( adjustment == 0 || adjustment == 1, "pre-condition" ); |
ysr@777 | 148 | |
ysr@777 | 149 | double ret = _accum_surv_rate; |
ysr@777 | 150 | if (adjustment > 0) { |
apetrusenko@980 | 151 | TruncatedSeq* seq = get_seq(_region_num+1); |
ysr@777 | 152 | double surv_rate = _g1p->get_new_prediction(seq); |
ysr@777 | 153 | ret += surv_rate; |
ysr@777 | 154 | } |
ysr@777 | 155 | |
ysr@777 | 156 | return ret; |
ysr@777 | 157 | } |
ysr@777 | 158 | |
ysr@777 | 159 | int |
ysr@777 | 160 | SurvRateGroup::next_age_index() { |
apetrusenko@980 | 161 | TruncatedSeq* seq = get_seq(_region_num); |
ysr@777 | 162 | double surv_rate = _g1p->get_new_prediction(seq); |
ysr@777 | 163 | _accum_surv_rate += surv_rate; |
ysr@777 | 164 | |
apetrusenko@980 | 165 | ++_region_num; |
ysr@777 | 166 | return (int) ++_all_regions_allocated; |
ysr@777 | 167 | } |
ysr@777 | 168 | |
ysr@777 | 169 | void |
ysr@777 | 170 | SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) { |
apetrusenko@980 | 171 | guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num, |
ysr@777 | 172 | "pre-condition" ); |
ysr@777 | 173 | guarantee( _surv_rate[age_in_group] <= 0.00001, |
ysr@777 | 174 | "should only update each slot once" ); |
ysr@777 | 175 | |
ysr@777 | 176 | double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords; |
ysr@777 | 177 | _surv_rate[age_in_group] = surv_rate; |
ysr@777 | 178 | _surv_rate_pred[age_in_group]->add(surv_rate); |
ysr@777 | 179 | if ((size_t)age_in_group < _summary_surv_rates_len) { |
ysr@777 | 180 | _summary_surv_rates[age_in_group]->add(surv_rate); |
ysr@777 | 181 | if ((size_t)(age_in_group+1) > _summary_surv_rates_max_len) |
ysr@777 | 182 | _summary_surv_rates_max_len = age_in_group+1; |
ysr@777 | 183 | } |
ysr@777 | 184 | } |
ysr@777 | 185 | |
ysr@777 | 186 | void |
ysr@777 | 187 | SurvRateGroup::all_surviving_words_recorded(bool propagate) { |
apetrusenko@980 | 188 | if (propagate && _region_num > 0) { // conservative |
apetrusenko@980 | 189 | double surv_rate = _surv_rate_pred[_region_num-1]->last(); |
ysr@777 | 190 | |
ysr@777 | 191 | #if 0 |
ysr@777 | 192 | gclog_or_tty->print_cr("propagating %1.2lf from %d to %d", |
ysr@777 | 193 | surv_rate, _curr_length, _array_length - 1); |
ysr@777 | 194 | #endif // 0 |
ysr@777 | 195 | |
apetrusenko@980 | 196 | for (size_t i = _region_num; i < _stats_arrays_length; ++i) { |
ysr@777 | 197 | guarantee( _surv_rate[i] <= 0.00001, |
ysr@777 | 198 | "the slot should not have been updated" ); |
ysr@777 | 199 | _surv_rate_pred[i]->add(surv_rate); |
ysr@777 | 200 | } |
ysr@777 | 201 | } |
ysr@777 | 202 | |
ysr@777 | 203 | double accum = 0.0; |
ysr@777 | 204 | double pred = 0.0; |
apetrusenko@980 | 205 | for (size_t i = 0; i < _stats_arrays_length; ++i) { |
ysr@777 | 206 | pred = _g1p->get_new_prediction(_surv_rate_pred[i]); |
ysr@777 | 207 | if (pred > 1.0) pred = 1.0; |
ysr@777 | 208 | accum += pred; |
ysr@777 | 209 | _accum_surv_rate_pred[i] = accum; |
ysr@777 | 210 | // gclog_or_tty->print_cr("age %3d, accum %10.2lf", i, accum); |
ysr@777 | 211 | } |
ysr@777 | 212 | _last_pred = pred; |
ysr@777 | 213 | } |
ysr@777 | 214 | |
ysr@777 | 215 | #ifndef PRODUCT |
ysr@777 | 216 | void |
ysr@777 | 217 | SurvRateGroup::print() { |
johnc@1829 | 218 | gclog_or_tty->print_cr("Surv Rate Group: %s (%d entries)", |
johnc@1829 | 219 | _name, _region_num); |
apetrusenko@980 | 220 | for (size_t i = 0; i < _region_num; ++i) { |
johnc@1829 | 221 | gclog_or_tty->print_cr(" age %4d surv rate %6.2lf %% pred %6.2lf %%", |
ysr@777 | 222 | i, _surv_rate[i] * 100.0, |
johnc@1829 | 223 | _g1p->get_new_prediction(_surv_rate_pred[i]) * 100.0); |
ysr@777 | 224 | } |
ysr@777 | 225 | } |
ysr@777 | 226 | |
ysr@777 | 227 | void |
ysr@777 | 228 | SurvRateGroup::print_surv_rate_summary() { |
ysr@777 | 229 | size_t length = _summary_surv_rates_max_len; |
ysr@777 | 230 | if (length == 0) |
ysr@777 | 231 | return; |
ysr@777 | 232 | |
ysr@777 | 233 | gclog_or_tty->print_cr(""); |
ysr@777 | 234 | gclog_or_tty->print_cr("%s Rate Summary (for up to age %d)", _name, length-1); |
ysr@777 | 235 | gclog_or_tty->print_cr(" age range survival rate (avg) samples (avg)"); |
ysr@777 | 236 | gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
ysr@777 | 237 | |
ysr@777 | 238 | size_t index = 0; |
ysr@777 | 239 | size_t limit = MIN2((int) length, 10); |
ysr@777 | 240 | while (index < limit) { |
ysr@777 | 241 | gclog_or_tty->print_cr(" %4d %6.2lf%% %6.2lf", |
ysr@777 | 242 | index, _summary_surv_rates[index]->avg() * 100.0, |
ysr@777 | 243 | (double) _summary_surv_rates[index]->num()); |
ysr@777 | 244 | ++index; |
ysr@777 | 245 | } |
ysr@777 | 246 | |
ysr@777 | 247 | gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
ysr@777 | 248 | |
ysr@777 | 249 | int num = 0; |
ysr@777 | 250 | double sum = 0.0; |
ysr@777 | 251 | int samples = 0; |
ysr@777 | 252 | while (index < length) { |
ysr@777 | 253 | ++num; |
ysr@777 | 254 | sum += _summary_surv_rates[index]->avg() * 100.0; |
ysr@777 | 255 | samples += _summary_surv_rates[index]->num(); |
ysr@777 | 256 | ++index; |
ysr@777 | 257 | |
ysr@777 | 258 | if (index == length || num % 10 == 0) { |
ysr@777 | 259 | gclog_or_tty->print_cr(" %4d .. %4d %6.2lf%% %6.2lf", |
ysr@777 | 260 | (index-1) / 10 * 10, index-1, sum / (double) num, |
ysr@777 | 261 | (double) samples / (double) num); |
ysr@777 | 262 | sum = 0.0; |
ysr@777 | 263 | num = 0; |
ysr@777 | 264 | samples = 0; |
ysr@777 | 265 | } |
ysr@777 | 266 | } |
ysr@777 | 267 | |
ysr@777 | 268 | gclog_or_tty->print_cr(" ---------------------------------------------------------"); |
ysr@777 | 269 | } |
ysr@777 | 270 | #endif // PRODUCT |