hotspot/src/share/vm/gc_implementation/shared/adaptiveSizePolicy.cpp
author brutisso
Mon, 21 Nov 2011 07:47:34 +0100
changeset 11170 7663e46f3a54
parent 7397 5b173b4ca846
child 11174 fccee5238e70
permissions -rw-r--r--
7110718: -XX:MarkSweepAlwaysCompactCount=0 crashes the JVM Summary: Interpret MarkSweepAlwaysCompactCount < 1 as never do full compaction Reviewed-by: ysr, tonyp, jmasa, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
     2
 * Copyright (c) 2004, 2010, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/shared/adaptiveSizePolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "gc_interface/gcCause.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/collectorPolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "utilities/ostream.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
elapsedTimer AdaptiveSizePolicy::_minor_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
elapsedTimer AdaptiveSizePolicy::_major_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// The throughput goal is implemented as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// gc_cost_ratio is the ratio
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//      application cost / gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// For example a gc_cost_ratio of 4 translates into a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// throughput goal of .80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
                                       size_t init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                       size_t init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                                       double gc_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                       uint gc_cost_ratio) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    _eden_size(init_eden_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    _promo_size(init_promo_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    _survivor_size(init_survivor_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _gc_pause_goal_sec(gc_pause_goal_sec),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    _throughput_goal(1.0 - double(1.0 / (1.0 + (double) gc_cost_ratio))),
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    51
    _gc_overhead_limit_exceeded(false),
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    52
    _print_gc_overhead_limit_would_be_exceeded(false),
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    53
    _gc_overhead_limit_count(0),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _latest_minor_mutator_interval_seconds(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _threshold_tolerance_percent(1.0 + ThresholdTolerance/100.0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    _young_gen_change_for_minor_throughput(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _old_gen_change_for_major_throughput(0) {
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    58
  assert(AdaptiveSizePolicyGCTimeLimitThreshold > 0,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    59
    "No opportunity to clear SoftReferences before GC overhead limit");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _avg_minor_pause    =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _avg_minor_gc_cost  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _avg_major_gc_cost  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _avg_young_live     = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _avg_old_live       = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _avg_eden_live      = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _avg_survived       = new AdaptivePaddedAverage(AdaptiveSizePolicyWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                                                  SurvivorPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _avg_pretenured     = new AdaptivePaddedNoZeroDevAverage(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                                                  AdaptiveSizePolicyWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                                                  SurvivorPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _minor_pause_old_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _minor_pause_young_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _minor_collection_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _major_collection_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Start the timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _young_gen_policy_is_ready = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
bool AdaptiveSizePolicy::tenuring_threshold_change() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  return decrement_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
         increment_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
         decrement_tenuring_threshold_for_survivor_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void AdaptiveSizePolicy::minor_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Save most recent collection time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _latest_minor_mutator_interval_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void AdaptiveSizePolicy::update_minor_pause_young_estimator(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    double minor_pause_in_ms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _minor_pause_young_estimator->update(eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void AdaptiveSizePolicy::minor_collection_end(GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Update the pause time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    double minor_pause_in_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    double minor_pause_in_ms = minor_pause_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    _avg_minor_pause->sample(minor_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    double collection_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if ((_latest_minor_mutator_interval_seconds > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        (minor_pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      collection_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        minor_pause_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      _avg_minor_gc_cost->sample(collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      _avg_minor_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    // The policy does not have enough data until at least some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    // minor collections have been done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    _young_gen_policy_is_ready =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // Calculate variables used to estimate pause time vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    update_minor_pause_young_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    update_minor_pause_old_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      gclog_or_tty->print("AdaptiveSizePolicy::minor_collection_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        "minor gc cost: %f  average: %f", collection_cost,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        _avg_minor_gc_cost->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      gclog_or_tty->print_cr("  minor pause: %f minor period %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        minor_pause_in_ms,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        _latest_minor_mutator_interval_seconds * MILLIUNITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    // Calculate variable used to estimate collection cost vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    assert(collection_cost >= 0.0, "Expected to be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Interval times use this timer to measure the mutator time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Reset the timer after the GC pause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _minor_timer.start();
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_increment(size_t cur_eden,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                                            uint percent_change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  size_t eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  eden_heap_delta = cur_eden / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  return eden_increment(cur_eden, YoungGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
size_t AdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  size_t eden_heap_delta = eden_increment(cur_eden) /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                                             uint percent_change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  size_t promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  promo_heap_delta = cur_promo / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
size_t AdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  size_t promo_heap_delta = promo_increment(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
double AdaptiveSizePolicy::time_since_major_gc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  _major_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  double result = _major_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// Linear decay of major gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
double AdaptiveSizePolicy::decaying_major_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  double major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  double major_gc_cost_average = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  double decayed_major_gc_cost = major_gc_cost_average;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if(time_since_major_gc() > 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    decayed_major_gc_cost = major_gc_cost() *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      (((double) AdaptiveSizeMajorGCDecayTimeScale) * major_interval)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      / time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // The decayed cost should always be smaller than the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // average cost but the vagaries of finite arithmetic could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // produce a larger value in decayed_major_gc_cost so protect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // against that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  return MIN2(major_gc_cost_average, decayed_major_gc_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// Use a value of the major gc cost that has been decayed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// by the factor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
//      average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//        time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// if the average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// is less than time-since-last-major-gc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
// In cases where there are initial major gc's that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// are of a relatively high cost but no later major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// gc's, the total gc cost can remain high because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
// the major gc cost remains unchanged (since there are no major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
// gc's).  In such a situation the value of the unchanging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// major gc cost can keep the mutator throughput below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// the goal when in fact the major gc cost is becoming diminishingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// small.  Use the decaying gc cost only to decide whether to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// adjust for throughput.  Using it also to determine the adjustment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// to be made for throughput also seems reasonable but there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// no test case to use to decide if it is the right thing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// don't do it yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
double AdaptiveSizePolicy::decaying_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  double decayed_major_gc_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  double avg_major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  if (UseAdaptiveSizeDecayMajorGCCost &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      (avg_major_interval > 0.00)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    double time_since_last_major_gc = time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    // Decay the major gc cost?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    if (time_since_last_major_gc >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      // Decay using the time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      decayed_major_gc_cost = decaying_major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        gclog_or_tty->print_cr("\ndecaying_gc_cost: major interval average:"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          " %f  time since last major gc: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          avg_major_interval, time_since_last_major_gc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        gclog_or_tty->print_cr("  major gc cost: %f  decayed major gc cost: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
          major_gc_cost(), decayed_major_gc_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
void AdaptiveSizePolicy::clear_generation_free_space_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  set_change_young_gen_for_min_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  set_change_old_gen_for_maj_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  set_change_old_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  set_change_young_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  set_decrease_for_footprint(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  set_decide_at_full_gc(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   287
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
   288
                                          size_t young_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   289
                                          size_t eden_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   290
                                          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
   291
                                          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
   292
                                          bool   is_full_gc,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   293
                                          GCCause::Cause gc_cause,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   294
                                          CollectorPolicy* collector_policy) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   295
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   296
  // Ignore explicit GC's.  Exiting here does not set the flag and
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   297
  // does not reset the count.  Updating of the averages for system
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   298
  // GC's is still controlled by UseAdaptiveSizePolicyWithSystemGC.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   299
  if (GCCause::is_user_requested_gc(gc_cause) ||
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   300
      GCCause::is_serviceability_requested_gc(gc_cause)) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   301
    return;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   302
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   303
  // eden_limit is the upper limit on the size of eden based on
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   304
  // the maximum size of the young generation and the sizes
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   305
  // of the survivor space.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   306
  // The question being asked is whether the gc costs are high
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   307
  // and the space being recovered by a collection is low.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   308
  // free_in_young_gen is the free space in the young generation
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   309
  // after a collection and promo_live is the free space in the old
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   310
  // generation after a collection.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   311
  //
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   312
  // Use the minimum of the current value of the live in the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   313
  // young gen or the average of the live in the young gen.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   314
  // If the current value drops quickly, that should be taken
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   315
  // into account (i.e., don't trigger if the amount of free
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   316
  // space has suddenly jumped up).  If the current is much
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   317
  // higher than the average, use the average since it represents
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   318
  // the longer term behavor.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   319
  const size_t live_in_eden =
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   320
    MIN2(eden_live, (size_t) avg_eden_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   321
  const size_t free_in_eden = max_eden_size > live_in_eden ?
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   322
    max_eden_size - live_in_eden : 0;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   323
  const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   324
  const size_t total_free_limit = free_in_old_gen + free_in_eden;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   325
  const size_t total_mem = max_old_gen_size + max_eden_size;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   326
  const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   327
  const double mem_free_old_limit = max_old_gen_size * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   328
  const double mem_free_eden_limit = max_eden_size * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   329
  const double gc_cost_limit = GCTimeLimit/100.0;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   330
  size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   331
  // But don't force a promo size below the current promo size. Otherwise,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   332
  // the promo size will shrink for no good reason.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   333
  promo_limit = MAX2(promo_limit, _promo_size);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   334
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   335
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   336
  if (PrintAdaptiveSizePolicy && (Verbose ||
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   337
      (free_in_old_gen < (size_t) mem_free_old_limit &&
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   338
       free_in_eden < (size_t) mem_free_eden_limit))) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   339
    gclog_or_tty->print_cr(
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   340
          "PSAdaptiveSizePolicy::compute_generation_free_space limits:"
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   341
          " promo_limit: " SIZE_FORMAT
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   342
          " max_eden_size: " SIZE_FORMAT
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   343
          " total_free_limit: " SIZE_FORMAT
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   344
          " max_old_gen_size: " SIZE_FORMAT
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   345
          " max_eden_size: " SIZE_FORMAT
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   346
          " mem_free_limit: " SIZE_FORMAT,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   347
          promo_limit, max_eden_size, total_free_limit,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   348
          max_old_gen_size, max_eden_size,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   349
          (size_t) mem_free_limit);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   350
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   351
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   352
  bool print_gc_overhead_limit_would_be_exceeded = false;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   353
  if (is_full_gc) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   354
    if (gc_cost() > gc_cost_limit &&
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   355
      free_in_old_gen < (size_t) mem_free_old_limit &&
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   356
      free_in_eden < (size_t) mem_free_eden_limit) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   357
      // Collections, on average, are taking too much time, and
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   358
      //      gc_cost() > gc_cost_limit
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   359
      // we have too little space available after a full gc.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   360
      //      total_free_limit < mem_free_limit
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   361
      // where
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   362
      //   total_free_limit is the free space available in
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   363
      //     both generations
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   364
      //   total_mem is the total space available for allocation
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   365
      //     in both generations (survivor spaces are not included
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   366
      //     just as they are not included in eden_limit).
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   367
      //   mem_free_limit is a fraction of total_mem judged to be an
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   368
      //     acceptable amount that is still unused.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   369
      // The heap can ask for the value of this variable when deciding
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   370
      // whether to thrown an OutOfMemory error.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   371
      // Note that the gc time limit test only works for the collections
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   372
      // of the young gen + tenured gen and not for collections of the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   373
      // permanent gen.  That is because the calculation of the space
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   374
      // freed by the collection is the free space in the young gen +
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   375
      // tenured gen.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   376
      // At this point the GC overhead limit is being exceeded.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   377
      inc_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   378
      if (UseGCOverheadLimit) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   379
        if (gc_overhead_limit_count() >=
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   380
            AdaptiveSizePolicyGCTimeLimitThreshold){
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   381
          // All conditions have been met for throwing an out-of-memory
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   382
          set_gc_overhead_limit_exceeded(true);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   383
          // Avoid consecutive OOM due to the gc time limit by resetting
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   384
          // the counter.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   385
          reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   386
        } else {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   387
          // The required consecutive collections which exceed the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   388
          // GC time limit may or may not have been reached. We
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   389
          // are approaching that condition and so as not to
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   390
          // throw an out-of-memory before all SoftRef's have been
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   391
          // cleared, set _should_clear_all_soft_refs in CollectorPolicy.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   392
          // The clearing will be done on the next GC.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   393
          bool near_limit = gc_overhead_limit_near();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   394
          if (near_limit) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   395
            collector_policy->set_should_clear_all_soft_refs(true);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   396
            if (PrintGCDetails && Verbose) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   397
              gclog_or_tty->print_cr("  Nearing GC overhead limit, "
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   398
                "will be clearing all SoftReference");
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   399
            }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   400
          }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   401
        }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   402
      }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   403
      // Set this even when the overhead limit will not
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   404
      // cause an out-of-memory.  Diagnostic message indicating
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   405
      // that the overhead limit is being exceeded is sometimes
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   406
      // printed.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   407
      print_gc_overhead_limit_would_be_exceeded = true;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   408
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   409
    } else {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   410
      // Did not exceed overhead limits
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   411
      reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   412
    }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   413
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   414
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   415
  if (UseGCOverheadLimit && PrintGCDetails && Verbose) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   416
    if (gc_overhead_limit_exceeded()) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   417
      gclog_or_tty->print_cr("      GC is exceeding overhead limit "
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   418
        "of %d%%", GCTimeLimit);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   419
      reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   420
    } else if (print_gc_overhead_limit_would_be_exceeded) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   421
      assert(gc_overhead_limit_count() > 0, "Should not be printing");
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   422
      gclog_or_tty->print_cr("      GC would exceed overhead limit "
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   423
        "of %d%% %d consecutive time(s)",
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   424
        GCTimeLimit, gc_overhead_limit_count());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   425
    }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   426
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   427
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
bool AdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  //  Should only be used with adaptive size policy turned on.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // Otherwise, there may be variables that are undefined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  if (!UseAdaptiveSizePolicy) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // Print goal for which action is needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  char* action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  bool change_for_pause = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  if ((change_old_gen_for_maj_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
         decrease_old_gen_for_maj_pauses_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
         decrease_young_gen_for_min_pauses_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    action = (char*) " *** pause time goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    change_for_pause = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  } else if ((change_old_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
               increase_old_gen_for_throughput_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
            (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
               increase_young_gen_for_througput_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    action = (char*) " *** throughput goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  } else if (decrease_for_footprint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    action = (char*) " *** reduced footprint ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    // No actions were taken.  This can legitimately be the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    // situation if not enough data has been gathered to make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    // decisions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // Pauses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // Currently the size of the old gen is only adjusted to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // change the major pause times.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  char* young_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  char* tenured_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  char* shrink_msg = (char*) "(attempted to shrink)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  char* grow_msg = (char*) "(attempted to grow)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  char* no_change_msg = (char*) "(no change)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  if (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      decrease_young_gen_for_min_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    young_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  if (change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  // Throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    assert(change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
           increase_young_gen_for_througput_true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
           "Both generations should be growing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    tenured_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  } else if (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
             increase_young_gen_for_througput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    // Only the young generation may grow at start up (before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    // enough full collections have been done to grow the old generation).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // Minimum footprint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (decrease_for_footprint() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  st->print_cr("    UseAdaptiveSizePolicy actions to meet %s", action);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  st->print_cr("                       GC overhead (%%)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  st->print_cr("    Young generation:     %7.2f\t  %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    100.0 * avg_minor_gc_cost()->average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    young_gen_action);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  st->print_cr("    Tenured generation:   %7.2f\t  %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    100.0 * avg_major_gc_cost()->average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    tenured_gen_action);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
bool AdaptiveSizePolicy::print_adaptive_size_policy_on(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
                                            outputStream* st,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
                                            int tenuring_threshold_arg) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  if (!AdaptiveSizePolicy::print_adaptive_size_policy_on(st)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // Tenuring threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  bool tenuring_threshold_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  if (decrement_tenuring_threshold_for_survivor_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    st->print("    Tenuring threshold:    (attempted to decrease to avoid"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
              " survivor space overflow) = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  } else if (decrement_tenuring_threshold_for_gc_cost()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    st->print("    Tenuring threshold:    (attempted to decrease to balance"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
              " GC costs) = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  } else if (increment_tenuring_threshold_for_gc_cost()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    st->print("    Tenuring threshold:    (attempted to increase to balance"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
              " GC costs) = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    tenuring_threshold_changed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    assert(!tenuring_threshold_change(), "(no change was attempted)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  if (tenuring_threshold_changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    st->print_cr("%d", tenuring_threshold_arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
}