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

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 980
58054a18d735
child 1829
1316cec51b4d
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

     1 /*
     2  * Copyright 2001-2009 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  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_survRateGroup.cpp.incl"
    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),
    34     _summary_surv_rates(NULL),
    35     _surv_rate(NULL),
    36     _accum_surv_rate_pred(NULL),
    37     _surv_rate_pred(NULL)
    38 {
    39   reset();
    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   }
    51   start_adding_regions();
    52 }
    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 }
    74 void
    75 SurvRateGroup::start_adding_regions() {
    76   _setup_seq_num   = _stats_arrays_length;
    77   _region_num      = _scan_only_prefix;
    78   _accum_surv_rate = 0.0;
    80 #if 0
    81   gclog_or_tty->print_cr("[%s] start adding regions, seq num %d, length %d",
    82                          _name, _setup_seq_num, _region_num);
    83 #endif // 0
    84 }
    86 void
    87 SurvRateGroup::stop_adding_regions() {
    89 #if 0
    90   gclog_or_tty->print_cr("[%s] stop adding regions, length %d", _name, _region_num);
    91 #endif // 0
    93   if (_region_num > _stats_arrays_length) {
    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;
    98     _surv_rate = NEW_C_HEAP_ARRAY(double, _region_num);
    99     if (_surv_rate == NULL) {
   100       vm_exit_out_of_memory(sizeof(double) * _region_num,
   101                             "Not enough space for surv rate array.");
   102     }
   103     _accum_surv_rate_pred = NEW_C_HEAP_ARRAY(double, _region_num);
   104     if (_accum_surv_rate_pred == NULL) {
   105       vm_exit_out_of_memory(sizeof(double) * _region_num,
   106                          "Not enough space for accum surv rate pred array.");
   107     }
   108     _surv_rate_pred = NEW_C_HEAP_ARRAY(TruncatedSeq*, _region_num);
   109     if (_surv_rate == NULL) {
   110       vm_exit_out_of_memory(sizeof(TruncatedSeq*) * _region_num,
   111                             "Not enough space for surv rate pred array.");
   112     }
   114     for (size_t i = 0; i < _stats_arrays_length; ++i)
   115       _surv_rate_pred[i] = old_surv_rate_pred[i];
   117 #if 0
   118     gclog_or_tty->print_cr("[%s] stop adding regions, new seqs %d to %d",
   119                   _name, _array_length, _region_num - 1);
   120 #endif // 0
   122     for (size_t i = _stats_arrays_length; i < _region_num; ++i) {
   123       _surv_rate_pred[i] = new TruncatedSeq(10);
   124       // _surv_rate_pred[i]->add(last_pred);
   125     }
   127     _stats_arrays_length = _region_num;
   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   }
   137   for (size_t i = 0; i < _stats_arrays_length; ++i)
   138     _surv_rate[i] = 0.0;
   139 }
   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" );
   146   double ret = _accum_surv_rate;
   147   if (adjustment > 0) {
   148     TruncatedSeq* seq = get_seq(_region_num+1);
   149     double surv_rate = _g1p->get_new_prediction(seq);
   150     ret += surv_rate;
   151   }
   153   return ret;
   154 }
   156 int
   157 SurvRateGroup::next_age_index() {
   158   TruncatedSeq* seq = get_seq(_region_num);
   159   double surv_rate = _g1p->get_new_prediction(seq);
   160   _accum_surv_rate += surv_rate;
   162   ++_region_num;
   163   return (int) ++_all_regions_allocated;
   164 }
   166 void
   167 SurvRateGroup::record_scan_only_prefix(size_t scan_only_prefix) {
   168   guarantee( scan_only_prefix <= _region_num, "pre-condition" );
   169   _scan_only_prefix = scan_only_prefix;
   170 }
   172 void
   173 SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) {
   174   guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num,
   175              "pre-condition" );
   176   guarantee( _surv_rate[age_in_group] <= 0.00001,
   177              "should only update each slot once" );
   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 }
   189 void
   190 SurvRateGroup::all_surviving_words_recorded(bool propagate) {
   191   if (propagate && _region_num > 0) { // conservative
   192     double surv_rate = _surv_rate_pred[_region_num-1]->last();
   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
   199     for (size_t i = _region_num; i < _stats_arrays_length; ++i) {
   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   }
   206   double accum = 0.0;
   207   double pred = 0.0;
   208   for (size_t i = 0; i < _stats_arrays_length; ++i) {
   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 }
   218 #ifndef PRODUCT
   219 void
   220 SurvRateGroup::print() {
   221   gclog_or_tty->print_cr("Surv Rate Group: %s (%d entries, %d scan-only)",
   222                 _name, _region_num, _scan_only_prefix);
   223   for (size_t i = 0; i < _region_num; ++i) {
   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 }
   231 void
   232 SurvRateGroup::print_surv_rate_summary() {
   233   size_t length = _summary_surv_rates_max_len;
   234   if (length == 0)
   235     return;
   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("  ---------------------------------------------------------");
   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   }
   251   gclog_or_tty->print_cr("  ---------------------------------------------------------");
   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;
   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   }
   272   gclog_or_tty->print_cr("  ---------------------------------------------------------");
   273 }
   274 #endif // PRODUCT

mercurial