src/hotspot/share/gc/shared/adaptiveSizePolicy.cpp
author stuefe
Tue, 26 Nov 2019 16:21:29 +0100
branchstuefe-new-metaspace-branch
changeset 59272 54750b448264
parent 54264 41af8d0546bc
permissions -rw-r--r--
Metadatatype back to metaspace.hpp to reduce patch size
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54085
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
     2
 * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
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: 5343
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
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: 30585
diff changeset
    26
#include "gc/shared/adaptiveSizePolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30585
diff changeset
    27
#include "gc/shared/gcCause.hpp"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
    28
#include "gc/shared/gcUtil.inline.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
    29
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/timer.hpp"
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
elapsedTimer AdaptiveSizePolicy::_minor_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
elapsedTimer AdaptiveSizePolicy::_major_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// The throughput goal is implemented as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// gc_cost_ratio is the ratio
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//      application cost / gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// For example a gc_cost_ratio of 4 translates into a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// throughput goal of .80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                       size_t init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                                       size_t init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                       double gc_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
                                       uint gc_cost_ratio) :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49047
diff changeset
    47
    _throughput_goal(1.0 - double(1.0 / (1.0 + (double) gc_cost_ratio))),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _eden_size(init_eden_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _promo_size(init_promo_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    _survivor_size(init_survivor_size),
54264
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    51
    _avg_minor_pause(new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    52
    _avg_minor_interval(new AdaptiveWeightedAverage(AdaptiveTimeWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    53
    _avg_minor_gc_cost(new AdaptiveWeightedAverage(AdaptiveTimeWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    54
    _avg_major_interval(new AdaptiveWeightedAverage(AdaptiveTimeWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    55
    _avg_major_gc_cost(new AdaptiveWeightedAverage(AdaptiveTimeWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    56
    _avg_young_live(new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    57
    _avg_eden_live(new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    58
    _avg_old_live(new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    59
    _avg_survived(new AdaptivePaddedAverage(AdaptiveSizePolicyWeight, SurvivorPadding)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    60
    _avg_pretenured(new AdaptivePaddedNoZeroDevAverage(AdaptiveSizePolicyWeight, SurvivorPadding)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    61
    _minor_pause_old_estimator(new LinearLeastSquareFit(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    62
    _minor_pause_young_estimator(new LinearLeastSquareFit(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    63
    _minor_collection_estimator(new LinearLeastSquareFit(AdaptiveSizePolicyWeight)),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    64
    _major_collection_estimator(new LinearLeastSquareFit(AdaptiveSizePolicyWeight)),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _latest_minor_mutator_interval_seconds(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _threshold_tolerance_percent(1.0 + ThresholdTolerance/100.0),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49047
diff changeset
    67
    _gc_pause_goal_sec(gc_pause_goal_sec),
54264
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    68
    _young_gen_policy_is_ready(false),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    69
    _change_young_gen_for_min_pauses(0),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    70
    _change_old_gen_for_maj_pauses(0),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    71
    _change_old_gen_for_throughput(0),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    72
    _change_young_gen_for_throughput(0),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    73
    _increment_tenuring_threshold_for_gc_cost(false),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    74
    _decrement_tenuring_threshold_for_gc_cost(false),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    75
    _decrement_tenuring_threshold_for_survivor_limit(false),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    76
    _decrease_for_footprint(0),
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 54085
diff changeset
    77
    _decide_at_full_gc(0),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _young_gen_change_for_minor_throughput(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _old_gen_change_for_major_throughput(0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Start the timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
bool AdaptiveSizePolicy::tenuring_threshold_change() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return decrement_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
         increment_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
         decrement_tenuring_threshold_for_survivor_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
void AdaptiveSizePolicy::minor_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Save most recent collection time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  _latest_minor_mutator_interval_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void AdaptiveSizePolicy::update_minor_pause_young_estimator(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    double minor_pause_in_ms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _minor_pause_young_estimator->update(eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void AdaptiveSizePolicy::minor_collection_end(GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Update the pause time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
31032
8e72621ca186 8072913: [REDO] GCCause should distinguish jcmd GC.run from System.gc()
ysuenaga
parents: 30876
diff changeset
   111
  if (!GCCause::is_user_requested_gc(gc_cause) ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    double minor_pause_in_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    double minor_pause_in_ms = minor_pause_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    _avg_minor_pause->sample(minor_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    double collection_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    if ((_latest_minor_mutator_interval_seconds > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        (minor_pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      collection_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        minor_pause_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      _avg_minor_gc_cost->sample(collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      _avg_minor_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // The policy does not have enough data until at least some
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   133
    // young collections have been done.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    _young_gen_policy_is_ready =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    // Calculate variables used to estimate pause time vs. gen sizes
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   138
    double eden_size_in_mbytes = ((double)_eden_size) / ((double)M);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    update_minor_pause_young_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    update_minor_pause_old_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   142
    log_trace(gc, ergo)("AdaptiveSizePolicy::minor_collection_end: minor gc cost: %f  average: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   143
                        collection_cost, _avg_minor_gc_cost->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   144
    log_trace(gc, ergo)("  minor pause: %f minor period %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   145
                        minor_pause_in_ms, _latest_minor_mutator_interval_seconds * MILLIUNITS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    // Calculate variable used to estimate collection cost vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    assert(collection_cost >= 0.0, "Expected to be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Interval times use this timer to measure the mutator time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Reset the timer after the GC pause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   158
size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden, uint percent_change) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  size_t eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  eden_heap_delta = cur_eden / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  return eden_increment(cur_eden, YoungGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
size_t AdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  size_t eden_heap_delta = eden_increment(cur_eden) /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   174
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo, uint percent_change) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  size_t promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  promo_heap_delta = cur_promo / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
size_t AdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  size_t promo_heap_delta = promo_increment(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
double AdaptiveSizePolicy::time_since_major_gc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  _major_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  double result = _major_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
// Linear decay of major gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
double AdaptiveSizePolicy::decaying_major_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  double major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  double major_gc_cost_average = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  double decayed_major_gc_cost = major_gc_cost_average;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  if(time_since_major_gc() > 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    decayed_major_gc_cost = major_gc_cost() *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      (((double) AdaptiveSizeMajorGCDecayTimeScale) * major_interval)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      / time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // The decayed cost should always be smaller than the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // average cost but the vagaries of finite arithmetic could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  // produce a larger value in decayed_major_gc_cost so protect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // against that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return MIN2(major_gc_cost_average, decayed_major_gc_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// Use a value of the major gc cost that has been decayed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
// by the factor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
//      average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
//        time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// if the average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// is less than time-since-last-major-gc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// In cases where there are initial major gc's that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
// are of a relatively high cost but no later major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// gc's, the total gc cost can remain high because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// the major gc cost remains unchanged (since there are no major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// gc's).  In such a situation the value of the unchanging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
// major gc cost can keep the mutator throughput below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
// the goal when in fact the major gc cost is becoming diminishingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// small.  Use the decaying gc cost only to decide whether to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// adjust for throughput.  Using it also to determine the adjustment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// to be made for throughput also seems reasonable but there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// no test case to use to decide if it is the right thing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// don't do it yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
double AdaptiveSizePolicy::decaying_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  double decayed_major_gc_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  double avg_major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  if (UseAdaptiveSizeDecayMajorGCCost &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      (avg_major_interval > 0.00)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    double time_since_last_major_gc = time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // Decay the major gc cost?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (time_since_last_major_gc >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      // Decay using the time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      decayed_major_gc_cost = decaying_major_gc_cost();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   251
      log_trace(gc, ergo)("decaying_gc_cost: major interval average: %f  time since last major gc: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   252
                    avg_major_interval, time_since_last_major_gc);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   253
      log_trace(gc, ergo)("  major gc cost: %f  decayed major gc cost: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   254
                    major_gc_cost(), decayed_major_gc_cost);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
void AdaptiveSizePolicy::clear_generation_free_space_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  set_change_young_gen_for_min_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  set_change_old_gen_for_maj_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  set_change_old_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  set_change_young_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  set_decrease_for_footprint(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  set_decide_at_full_gc(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
54085
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   272
class AdaptiveSizePolicyTimeOverheadTester: public GCOverheadTester {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   273
  double _gc_cost;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   274
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   275
 public:
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   276
  AdaptiveSizePolicyTimeOverheadTester(double gc_cost) : _gc_cost(gc_cost) {}
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   277
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   278
  bool is_exceeded() {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   279
    return _gc_cost > (GCTimeLimit / 100.0);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   280
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   281
};
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   282
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   283
class AdaptiveSizePolicySpaceOverheadTester: public GCOverheadTester {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   284
  size_t _eden_live;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   285
  size_t _max_old_gen_size;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   286
  size_t _max_eden_size;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   287
  size_t _promo_size;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   288
  double _avg_eden_live;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   289
  double _avg_old_live;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   290
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   291
 public:
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   292
  AdaptiveSizePolicySpaceOverheadTester(size_t eden_live,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   293
                                        size_t max_old_gen_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   294
                                        size_t max_eden_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   295
                                        size_t promo_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   296
                                        double avg_eden_live,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   297
                                        double avg_old_live) :
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   298
    _eden_live(eden_live),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   299
    _max_old_gen_size(max_old_gen_size),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   300
    _max_eden_size(max_eden_size),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   301
    _promo_size(promo_size),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   302
    _avg_eden_live(avg_eden_live),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   303
    _avg_old_live(avg_old_live) {}
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   304
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   305
  bool is_exceeded() {
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   306
    // _max_eden_size is the upper limit on the size of eden based on
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   307
    // the maximum size of the young generation and the sizes
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   308
    // of the survivor space.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   309
    // The question being asked is whether the space being recovered by
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   310
    // a collection is low.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   311
    // free_in_eden is the free space in eden after a collection and
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   312
    // free_in_old_gen is the free space in the old generation after
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   313
    // a collection.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   314
    //
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   315
    // Use the minimum of the current value of the live in eden
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   316
    // or the average of the live in eden.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   317
    // If the current value drops quickly, that should be taken
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   318
    // into account (i.e., don't trigger if the amount of free
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   319
    // space has suddenly jumped up).  If the current is much
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   320
    // higher than the average, use the average since it represents
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   321
    // the longer term behavior.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   322
    const size_t live_in_eden =
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   323
      MIN2(_eden_live, (size_t)_avg_eden_live);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   324
    const size_t free_in_eden = _max_eden_size > live_in_eden ?
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   325
      _max_eden_size - live_in_eden : 0;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   326
    const size_t free_in_old_gen = (size_t)(_max_old_gen_size - _avg_old_live);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   327
    const size_t total_free_limit = free_in_old_gen + free_in_eden;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   328
    const size_t total_mem = _max_old_gen_size + _max_eden_size;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   329
    const double free_limit_ratio = GCHeapFreeLimit / 100.0;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   330
    const double mem_free_limit = total_mem * free_limit_ratio;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   331
    const double mem_free_old_limit = _max_old_gen_size * free_limit_ratio;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   332
    const double mem_free_eden_limit = _max_eden_size * free_limit_ratio;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   333
    size_t promo_limit = (size_t)(_max_old_gen_size - _avg_old_live);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   334
    // But don't force a promo size below the current promo size. Otherwise,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   335
    // the promo size will shrink for no good reason.
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   336
    promo_limit = MAX2(promo_limit, _promo_size);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   337
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   338
    log_trace(gc, ergo)(
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   339
          "AdaptiveSizePolicySpaceOverheadTester::is_exceeded:"
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   340
          " promo_limit: " SIZE_FORMAT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   341
          " max_eden_size: " SIZE_FORMAT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   342
          " total_free_limit: " SIZE_FORMAT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   343
          " max_old_gen_size: " SIZE_FORMAT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   344
          " max_eden_size: " SIZE_FORMAT
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   345
          " mem_free_limit: " SIZE_FORMAT,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   346
          promo_limit, _max_eden_size, total_free_limit,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   347
          _max_old_gen_size, _max_eden_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   348
          (size_t)mem_free_limit);
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   349
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   350
    return free_in_old_gen < (size_t)mem_free_old_limit &&
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   351
           free_in_eden < (size_t)mem_free_eden_limit;
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   352
  }
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   353
};
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   354
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   355
void AdaptiveSizePolicy::check_gc_overhead_limit(
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   356
                                          size_t eden_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   357
                                          size_t max_old_gen_size,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   358
                                          size_t max_eden_size,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   359
                                          bool   is_full_gc,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   360
                                          GCCause::Cause gc_cause,
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
   361
                                          SoftRefPolicy* soft_ref_policy) {
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   362
54085
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   363
  AdaptiveSizePolicyTimeOverheadTester time_overhead(gc_cost());
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   364
  AdaptiveSizePolicySpaceOverheadTester space_overhead(eden_live,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   365
                                                       max_old_gen_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   366
                                                       max_eden_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   367
                                                       _promo_size,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   368
                                                       avg_eden_live()->average(),
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   369
                                                       avg_old_live()->average());
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   370
  _overhead_checker.check_gc_overhead_limit(&time_overhead,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   371
                                            &space_overhead,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   372
                                            is_full_gc,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   373
                                            gc_cause,
ab87b06dfdc0 8212206: Refactor AdaptiveSizePolicy to separate out code related to GC overhead
manc
parents: 52904
diff changeset
   374
                                            soft_ref_policy);
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   375
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   378
bool AdaptiveSizePolicy::print() const {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   379
  assert(UseAdaptiveSizePolicy, "UseAdaptiveSizePolicy need to be enabled.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   381
  if (!log_is_enabled(Debug, gc, ergo)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   382
    return false;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   383
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // Print goal for which action is needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  char* action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  bool change_for_pause = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  if ((change_old_gen_for_maj_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
         decrease_old_gen_for_maj_pauses_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
         decrease_young_gen_for_min_pauses_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    action = (char*) " *** pause time goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    change_for_pause = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  } else if ((change_old_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
               increase_old_gen_for_throughput_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
            (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
               increase_young_gen_for_througput_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    action = (char*) " *** throughput goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  } else if (decrease_for_footprint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    action = (char*) " *** reduced footprint ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    // No actions were taken.  This can legitimately be the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // situation if not enough data has been gathered to make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    // decisions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // Pauses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // Currently the size of the old gen is only adjusted to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // change the major pause times.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  char* young_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  char* tenured_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  char* shrink_msg = (char*) "(attempted to shrink)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  char* grow_msg = (char*) "(attempted to grow)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  char* no_change_msg = (char*) "(no change)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      decrease_young_gen_for_min_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    young_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  if (change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  // Throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    assert(change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
           increase_young_gen_for_througput_true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
           "Both generations should be growing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    tenured_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  } else if (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
             increase_young_gen_for_througput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    // Only the young generation may grow at start up (before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    // enough full collections have been done to grow the old generation).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  // Minimum footprint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  if (decrease_for_footprint() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   451
  log_debug(gc, ergo)("UseAdaptiveSizePolicy actions to meet %s", action);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   452
  log_debug(gc, ergo)("                       GC overhead (%%)");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   453
  log_debug(gc, ergo)("    Young generation:     %7.2f\t  %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   454
                      100.0 * avg_minor_gc_cost()->average(), young_gen_action);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   455
  log_debug(gc, ergo)("    Tenured generation:   %7.2f\t  %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   456
                      100.0 * avg_major_gc_cost()->average(), tenured_gen_action);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   460
void AdaptiveSizePolicy::print_tenuring_threshold( uint new_tenuring_threshold_arg) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // Tenuring threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  if (decrement_tenuring_threshold_for_survivor_limit()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   463
    log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to avoid survivor space overflow) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  } else if (decrement_tenuring_threshold_for_gc_cost()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   465
    log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to balance GC costs) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  } else if (increment_tenuring_threshold_for_gc_cost()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   467
    log_debug(gc, ergo)("Tenuring threshold: (attempted to increase to balance GC costs) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    assert(!tenuring_threshold_change(), "(no change was attempted)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
}