< prev index next >

src/hotspot/share/gc/g1/survRateGroup.cpp

Print this page
rev 55208 : imported patch 8220089.webrev.0
rev 55209 : imported patch 8220089.webrev.1
rev 55210 : imported patch 8220089.webrev.2
   1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1Predictions.hpp"
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/survRateGroup.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/allocation.hpp"
  32 
  33 SurvRateGroup::SurvRateGroup() :
  34   _stats_arrays_length(0),
  35   _accum_surv_rate_pred(NULL),
  36   _last_pred(0.0),
  37   _surv_rate_pred(NULL),
  38   _all_regions_allocated(0),
  39   _region_num(0),
  40   _setup_seq_num(0)

  41 {
  42   reset();
  43   start_adding_regions();
  44 }
  45 
  46 void SurvRateGroup::reset() {
  47   _all_regions_allocated = 0;
  48   _setup_seq_num         = 0;
  49   _last_pred             = 0.0;
  50   // the following will set up the arrays with length 1
  51   _region_num            = 1;

  52 
  53   // The call to stop_adding_regions() will use "new" to refill
  54   // the _surv_rate_pred array, so we need to make sure to call
  55   // "delete".
  56   for (size_t i = 0; i < _stats_arrays_length; ++i) {
  57     delete _surv_rate_pred[i];
  58   }
  59   _stats_arrays_length = 0;
  60 
  61   stop_adding_regions();
  62 
  63   // Seed initial _surv_rate_pred and _accum_surv_rate_pred values
  64   guarantee( _stats_arrays_length == 1, "invariant" );
  65   guarantee( _surv_rate_pred[0] != NULL, "invariant" );
  66   const double initial_surv_rate = 0.4;
  67   _surv_rate_pred[0]->add(initial_surv_rate);
  68   _last_pred = _accum_surv_rate_pred[0] = initial_surv_rate;
  69 
  70   _region_num = 0;
  71 }
  72 
  73 void SurvRateGroup::start_adding_regions() {
  74   _setup_seq_num   = _stats_arrays_length;
  75   _region_num      = 0;


  76 }
  77 
  78 void SurvRateGroup::stop_adding_regions() {
  79   if (_region_num > _stats_arrays_length) {
  80     _accum_surv_rate_pred = REALLOC_C_HEAP_ARRAY(double, _accum_surv_rate_pred, _region_num, mtGC);
  81     _surv_rate_pred = REALLOC_C_HEAP_ARRAY(TruncatedSeq*, _surv_rate_pred, _region_num, mtGC);
  82 
  83     for (size_t i = _stats_arrays_length; i < _region_num; ++i) {
  84       _surv_rate_pred[i] = new TruncatedSeq(10);
  85     }
  86 
  87     _stats_arrays_length = _region_num;
  88   }
  89 }
  90 
  91 void SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) {
  92   guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num,
  93              "pre-condition" );

  94 
  95   double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords;
  96   _surv_rate_pred[age_in_group]->add(surv_rate);
  97 }
  98 
  99 void SurvRateGroup::all_surviving_words_recorded(const G1Predictions& predictor, bool update_predictors) {
 100   if (update_predictors) {
 101     fill_in_last_surv_rates();
 102   }
 103   finalize_predictions(predictor);
 104 }
 105 
 106 void SurvRateGroup::fill_in_last_surv_rates() {
 107   if (_region_num > 0) { // conservative
 108     double surv_rate = _surv_rate_pred[_region_num-1]->last();
 109     for (size_t i = _region_num; i < _stats_arrays_length; ++i) {
 110       _surv_rate_pred[i]->add(surv_rate);
 111     }
 112   }
 113 }
   1 /*
   2  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/g1/g1CollectedHeap.inline.hpp"
  27 #include "gc/g1/g1Predictions.hpp"
  28 #include "gc/g1/heapRegion.hpp"
  29 #include "gc/g1/survRateGroup.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/allocation.hpp"
  32 
  33 SurvRateGroup::SurvRateGroup() :
  34   _stats_arrays_length(0),
  35   _accum_surv_rate_pred(NULL),
  36   _last_pred(0.0),
  37   _surv_rate_pred(NULL),
  38   _all_regions_allocated(0),
  39   _region_num(0),
  40   _setup_seq_num(0),
  41   _retained_region_num(0)
  42 {
  43   reset();
  44   start_adding_regions();
  45 }
  46 
  47 void SurvRateGroup::reset() {
  48   _all_regions_allocated = 0;
  49   _setup_seq_num         = 0;
  50   _last_pred             = 0.0;
  51   // the following will set up the arrays with length 1
  52   _region_num            = 1;
  53   _retained_region_num   = 0;
  54 
  55   // The call to stop_adding_regions() will use "new" to refill
  56   // the _surv_rate_pred array, so we need to make sure to call
  57   // "delete".
  58   for (size_t i = 0; i < _stats_arrays_length; ++i) {
  59     delete _surv_rate_pred[i];
  60   }
  61   _stats_arrays_length = 0;
  62 
  63   stop_adding_regions();
  64 
  65   // Seed initial _surv_rate_pred and _accum_surv_rate_pred values
  66   guarantee( _stats_arrays_length == 1, "invariant" );
  67   guarantee( _surv_rate_pred[0] != NULL, "invariant" );
  68   const double initial_surv_rate = 0.4;
  69   _surv_rate_pred[0]->add(initial_surv_rate);
  70   _last_pred = _accum_surv_rate_pred[0] = initial_surv_rate;
  71 
  72   _region_num = 0;
  73 }
  74 
  75 void SurvRateGroup::start_adding_regions() {
  76   _setup_seq_num   = _stats_arrays_length;
  77   // Retained region number should be reflected to address actual reused case.
  78   _region_num      = _retained_region_num;
  79   _retained_region_num = 0;
  80 }
  81 
  82 void SurvRateGroup::stop_adding_regions() {
  83   if (_region_num > _stats_arrays_length) {
  84     _accum_surv_rate_pred = REALLOC_C_HEAP_ARRAY(double, _accum_surv_rate_pred, _region_num, mtGC);
  85     _surv_rate_pred = REALLOC_C_HEAP_ARRAY(TruncatedSeq*, _surv_rate_pred, _region_num, mtGC);
  86 
  87     for (size_t i = _stats_arrays_length; i < _region_num; ++i) {
  88       _surv_rate_pred[i] = new TruncatedSeq(10);
  89     }
  90 
  91     _stats_arrays_length = _region_num;
  92   }
  93 }
  94 
  95 void SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) {
  96   guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num,
  97              "Age in group (" PTR_FORMAT ") should be [0, " SIZE_FORMAT "), but it is %d",
  98              p2i(this), _region_num, age_in_group);
  99 
 100   double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords;
 101   _surv_rate_pred[age_in_group]->add(surv_rate);
 102 }
 103 
 104 void SurvRateGroup::all_surviving_words_recorded(const G1Predictions& predictor, bool update_predictors) {
 105   if (update_predictors) {
 106     fill_in_last_surv_rates();
 107   }
 108   finalize_predictions(predictor);
 109 }
 110 
 111 void SurvRateGroup::fill_in_last_surv_rates() {
 112   if (_region_num > 0) { // conservative
 113     double surv_rate = _surv_rate_pred[_region_num-1]->last();
 114     for (size_t i = _region_num; i < _stats_arrays_length; ++i) {
 115       _surv_rate_pred[i]->add(surv_rate);
 116     }
 117   }
 118 }
< prev index next >