src/share/vm/gc_implementation/g1/survRateGroup.cpp

Wed, 02 Jan 2013 11:32:41 -0800

author
johnc
date
Wed, 02 Jan 2013 11:32:41 -0800
changeset 4384
b735136e0d82
parent 3900
d2a62e0f25eb
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8004132: SerialGC: ValidateMarkSweep broken when running GCOld
Summary: Remove bit-rotten ValidateMarkSweep functionality and flag.
Reviewed-by: johnc, jmasa
Contributed-by: tamao <tao.mao@oracle.com>

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

mercurial