2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2015-05-13 15:16:06 +02:00
|
|
|
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
|
2008-06-05 15:57:56 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2008-06-05 15:57:56 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
2015-10-15 10:07:28 +02:00
|
|
|
#include "gc/g1/g1Predictions.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/heapRegion.hpp"
|
|
|
|
#include "gc/g1/survRateGroup.hpp"
|
2015-12-10 14:57:55 +01:00
|
|
|
#include "logging/log.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2016-04-27 16:20:05 +02:00
|
|
|
SurvRateGroup::SurvRateGroup() :
|
2018-08-08 15:31:06 +02:00
|
|
|
_stats_arrays_length(0),
|
|
|
|
_accum_surv_rate_pred(NULL),
|
|
|
|
_last_pred(0.0),
|
|
|
|
_surv_rate_pred(NULL),
|
|
|
|
_all_regions_allocated(0),
|
|
|
|
_region_num(0),
|
|
|
|
_setup_seq_num(0)
|
|
|
|
{
|
2009-02-06 01:38:50 +03:00
|
|
|
reset();
|
2008-06-05 15:57:56 -07:00
|
|
|
start_adding_regions();
|
|
|
|
}
|
|
|
|
|
2012-03-13 21:12:53 +01:00
|
|
|
void SurvRateGroup::reset() {
|
2009-02-06 01:38:50 +03:00
|
|
|
_all_regions_allocated = 0;
|
|
|
|
_setup_seq_num = 0;
|
|
|
|
_last_pred = 0.0;
|
|
|
|
// the following will set up the arrays with length 1
|
|
|
|
_region_num = 1;
|
2012-03-13 21:12:53 +01:00
|
|
|
|
|
|
|
// The call to stop_adding_regions() will use "new" to refill
|
|
|
|
// the _surv_rate_pred array, so we need to make sure to call
|
|
|
|
// "delete".
|
|
|
|
for (size_t i = 0; i < _stats_arrays_length; ++i) {
|
|
|
|
delete _surv_rate_pred[i];
|
|
|
|
}
|
|
|
|
_stats_arrays_length = 0;
|
|
|
|
|
2009-02-06 01:38:50 +03:00
|
|
|
stop_adding_regions();
|
2016-04-27 16:20:05 +02:00
|
|
|
|
|
|
|
// Seed initial _surv_rate_pred and _accum_surv_rate_pred values
|
2009-02-06 01:38:50 +03:00
|
|
|
guarantee( _stats_arrays_length == 1, "invariant" );
|
|
|
|
guarantee( _surv_rate_pred[0] != NULL, "invariant" );
|
2016-04-27 16:20:05 +02:00
|
|
|
const double initial_surv_rate = 0.4;
|
|
|
|
_surv_rate_pred[0]->add(initial_surv_rate);
|
|
|
|
_last_pred = _accum_surv_rate_pred[0] = initial_surv_rate;
|
|
|
|
|
2009-02-06 01:38:50 +03:00
|
|
|
_region_num = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-15 10:12:17 +02:00
|
|
|
void SurvRateGroup::start_adding_regions() {
|
2009-02-06 01:38:50 +03:00
|
|
|
_setup_seq_num = _stats_arrays_length;
|
2010-04-22 10:02:38 -07:00
|
|
|
_region_num = 0;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2015-10-15 10:12:17 +02:00
|
|
|
void SurvRateGroup::stop_adding_regions() {
|
2009-02-06 01:38:50 +03:00
|
|
|
if (_region_num > _stats_arrays_length) {
|
2016-04-27 16:20:05 +02:00
|
|
|
_accum_surv_rate_pred = REALLOC_C_HEAP_ARRAY(double, _accum_surv_rate_pred, _region_num, mtGC);
|
|
|
|
_surv_rate_pred = REALLOC_C_HEAP_ARRAY(TruncatedSeq*, _surv_rate_pred, _region_num, mtGC);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-02-06 01:38:50 +03:00
|
|
|
for (size_t i = _stats_arrays_length; i < _region_num; ++i) {
|
2008-06-05 15:57:56 -07:00
|
|
|
_surv_rate_pred[i] = new TruncatedSeq(10);
|
|
|
|
}
|
|
|
|
|
2009-02-06 01:38:50 +03:00
|
|
|
_stats_arrays_length = _region_num;
|
2012-03-13 21:12:53 +01:00
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2015-10-15 10:12:17 +02:00
|
|
|
void SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) {
|
2009-02-06 01:38:50 +03:00
|
|
|
guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num,
|
2008-06-05 15:57:56 -07:00
|
|
|
"pre-condition" );
|
|
|
|
|
|
|
|
double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords;
|
|
|
|
_surv_rate_pred[age_in_group]->add(surv_rate);
|
2016-04-27 16:20:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurvRateGroup::all_surviving_words_recorded(const G1Predictions& predictor, bool update_predictors) {
|
|
|
|
if (update_predictors) {
|
|
|
|
fill_in_last_surv_rates();
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2016-04-27 16:20:05 +02:00
|
|
|
finalize_predictions(predictor);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2016-04-27 16:20:05 +02:00
|
|
|
void SurvRateGroup::fill_in_last_surv_rates() {
|
|
|
|
if (_region_num > 0) { // conservative
|
2009-02-06 01:38:50 +03:00
|
|
|
double surv_rate = _surv_rate_pred[_region_num-1]->last();
|
|
|
|
for (size_t i = _region_num; i < _stats_arrays_length; ++i) {
|
2008-06-05 15:57:56 -07:00
|
|
|
_surv_rate_pred[i]->add(surv_rate);
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 16:20:05 +02:00
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2016-04-27 16:20:05 +02:00
|
|
|
void SurvRateGroup::finalize_predictions(const G1Predictions& predictor) {
|
2008-06-05 15:57:56 -07:00
|
|
|
double accum = 0.0;
|
|
|
|
double pred = 0.0;
|
2009-02-06 01:38:50 +03:00
|
|
|
for (size_t i = 0; i < _stats_arrays_length; ++i) {
|
2016-04-27 16:20:05 +02:00
|
|
|
pred = predictor.get_new_prediction(_surv_rate_pred[i]);
|
2008-06-05 15:57:56 -07:00
|
|
|
if (pred > 1.0) pred = 1.0;
|
|
|
|
accum += pred;
|
|
|
|
_accum_surv_rate_pred[i] = accum;
|
|
|
|
}
|
|
|
|
_last_pred = pred;
|
|
|
|
}
|