src/hotspot/share/gc/g1/survRateGroup.cpp
author tschatzl
Wed, 17 Jul 2019 16:33:19 +0200
changeset 55722 5ee183a90e65
parent 51332 c25572739e7c
child 59320 11ff4e485670
permissions -rw-r--r--
8227084: Add timing information for merge heap root preparation Reviewed-by: sangheki, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5350
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    26
#include "gc/g1/g1CollectedHeap.inline.hpp"
33214
5a00fba36171 8137082: Factor out G1 prediction code from G1CollectorPolicy and clean up
tschatzl
parents: 30764
diff changeset
    27
#include "gc/g1/g1Predictions.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    28
#include "gc/g1/heapRegion.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    29
#include "gc/g1/survRateGroup.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33216
diff changeset
    30
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/allocation.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    33
SurvRateGroup::SurvRateGroup() :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    34
  _stats_arrays_length(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    35
  _accum_surv_rate_pred(NULL),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    36
  _last_pred(0.0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    37
  _surv_rate_pred(NULL),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    38
  _all_regions_allocated(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    39
  _region_num(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    40
  _setup_seq_num(0)
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    41
{
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    42
  reset();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
  start_adding_regions();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
12117
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    46
void SurvRateGroup::reset() {
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    47
  _all_regions_allocated = 0;
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    48
  _setup_seq_num         = 0;
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    49
  _last_pred             = 0.0;
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    50
  // the following will set up the arrays with length 1
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    51
  _region_num            = 1;
12117
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    52
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    53
  // The call to stop_adding_regions() will use "new" to refill
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    54
  // the _surv_rate_pred array, so we need to make sure to call
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    55
  // "delete".
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    56
  for (size_t i = 0; i < _stats_arrays_length; ++i) {
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    57
    delete _surv_rate_pred[i];
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    58
  }
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    59
  _stats_arrays_length = 0;
23b52cd6ca73 7152954: G1: Native memory leak during full GCs
brutisso
parents: 7397
diff changeset
    60
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    61
  stop_adding_regions();
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    62
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    63
  // Seed initial _surv_rate_pred and _accum_surv_rate_pred values
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    64
  guarantee( _stats_arrays_length == 1, "invariant" );
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    65
  guarantee( _surv_rate_pred[0] != NULL, "invariant" );
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    66
  const double initial_surv_rate = 0.4;
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    67
  _surv_rate_pred[0]->add(initial_surv_rate);
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    68
  _last_pred = _accum_surv_rate_pred[0] = initial_surv_rate;
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    69
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    70
  _region_num = 0;
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    71
}
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    72
33215
dba714a14246 8139583: Fix formatting in survRateGroup.cpp
tschatzl
parents: 33214
diff changeset
    73
void SurvRateGroup::start_adding_regions() {
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    74
  _setup_seq_num   = _stats_arrays_length;
5350
cccf0925702e 6819061: G1: eliminate serial Other times that are proportional to the collection set length
johnc
parents: 2105
diff changeset
    75
  _region_num      = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
33215
dba714a14246 8139583: Fix formatting in survRateGroup.cpp
tschatzl
parents: 33214
diff changeset
    78
void SurvRateGroup::stop_adding_regions() {
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    79
  if (_region_num > _stats_arrays_length) {
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    80
    _accum_surv_rate_pred = REALLOC_C_HEAP_ARRAY(double, _accum_surv_rate_pred, _region_num, mtGC);
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    81
    _surv_rate_pred = REALLOC_C_HEAP_ARRAY(TruncatedSeq*, _surv_rate_pred, _region_num, mtGC);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    83
    for (size_t i = _stats_arrays_length; i < _region_num; ++i) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
      _surv_rate_pred[i] = new TruncatedSeq(10);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    87
    _stats_arrays_length = _region_num;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
33215
dba714a14246 8139583: Fix formatting in survRateGroup.cpp
tschatzl
parents: 33214
diff changeset
    91
void SurvRateGroup::record_surviving_words(int age_in_group, size_t surv_words) {
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
    92
  guarantee( 0 <= age_in_group && (size_t) age_in_group < _region_num,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
             "pre-condition" );
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
  double surv_rate = (double) surv_words / (double) HeapRegion::GrainWords;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  _surv_rate_pred[age_in_group]->add(surv_rate);
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    97
}
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    98
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
    99
void SurvRateGroup::all_surviving_words_recorded(const G1Predictions& predictor, bool update_predictors) {
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   100
  if (update_predictors) {
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   101
    fill_in_last_surv_rates();
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   102
  }
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   103
  finalize_predictions(predictor);
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   104
}
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   105
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   106
void SurvRateGroup::fill_in_last_surv_rates() {
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   107
  if (_region_num > 0) { // conservative
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   108
    double surv_rate = _surv_rate_pred[_region_num-1]->last();
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   109
    for (size_t i = _region_num; i < _stats_arrays_length; ++i) {
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   110
      _surv_rate_pred[i]->add(surv_rate);
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   111
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   115
void SurvRateGroup::finalize_predictions(const G1Predictions& predictor) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
  double accum = 0.0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  double pred = 0.0;
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1374
diff changeset
   118
  for (size_t i = 0; i < _stats_arrays_length; ++i) {
38185
c432f8466c73 8155634: Clean out old logging and dead code from SurvRateGroup
mgerdin
parents: 35061
diff changeset
   119
    pred = predictor.get_new_prediction(_surv_rate_pred[i]);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
    if (pred > 1.0) pred = 1.0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
    accum += pred;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
    _accum_surv_rate_pred[i] = accum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
  _last_pred = pred;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
}