hotspot/src/share/vm/gc/parallel/psAdaptiveSizePolicy.cpp
author stefank
Wed, 05 Jul 2017 11:33:17 +0200
changeset 46625 edefffab74e2
parent 46619 a3919f5e8d2b
permissions -rw-r--r--
8183552: Move align functions to align.hpp Reviewed-by: stuefe, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
40903
efb9ac3b77ce 8163860: Convert TestOldFreeSpaceCalculation_test to GTest
kzhaldyb
parents: 37466
diff changeset
     2
 * Copyright (c) 2002, 2016, 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: 29798
diff changeset
    26
#include "gc/parallel/parallelScavengeHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    27
#include "gc/parallel/psAdaptiveSizePolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    28
#include "gc/parallel/psGCAdaptivePolicyCounters.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    29
#include "gc/parallel/psScavenge.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    30
#include "gc/shared/collectorPolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    31
#include "gc/shared/gcCause.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29798
diff changeset
    32
#include "gc/shared/gcPolicyCounters.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
    33
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/timer.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    35
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#include <math.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                                           size_t init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                                           size_t init_survivor_size,
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
    42
                                           size_t space_alignment,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                           double gc_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                                           double gc_minor_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                           uint gc_cost_ratio) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
     AdaptiveSizePolicy(init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                        init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                        init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                        gc_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                        gc_cost_ratio),
21560
b3ae3ba25ebb 8026853: Prepare GC code for collector policy regression fix
jwilhelm
parents: 20317
diff changeset
    51
     _collection_cost_margin_fraction(AdaptiveSizePolicyCollectionCostMargin / 100.0),
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
    52
     _space_alignment(space_alignment),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
     _live_at_last_full_gc(init_promo_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
     _gc_minor_pause_goal_sec(gc_minor_pause_goal_sec),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
     _latest_major_mutator_interval_seconds(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
     _young_gen_change_for_major_pause_count(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Sizing policy statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _avg_major_pause    =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _avg_major_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _avg_base_footprint = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  _major_pause_old_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _major_pause_young_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _major_collection_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _young_gen_size_increment_supplement = YoungGenerationSizeSupplement;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _old_gen_size_increment_supplement = TenuredGenerationSizeSupplement;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Start the timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _old_gen_policy_is_ready = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    81
size_t PSAdaptiveSizePolicy::calculate_free_based_on_live(size_t live, uintx ratio_as_percentage) {
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    82
  // We want to calculate how much free memory there can be based on the
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    83
  // amount of live data currently in the old gen. Using the formula:
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    84
  // ratio * (free + live) = free
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    85
  // Some equation solving later we get:
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    86
  // free = (live * ratio) / (1 - ratio)
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    87
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    88
  const double ratio = ratio_as_percentage / 100.0;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    89
  const double ratio_inverse = 1.0 - ratio;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    90
  const double tmp = live * ratio;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    91
  size_t free = (size_t)(tmp / ratio_inverse);
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    92
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    93
  return free;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    94
}
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    95
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    96
size_t PSAdaptiveSizePolicy::calculated_old_free_size_in_bytes() const {
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    97
  size_t free_size = (size_t)(_promo_size + avg_promoted()->padded_average());
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    98
  size_t live = ParallelScavengeHeap::heap()->old_gen()->used_in_bytes();
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
    99
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   100
  if (MinHeapFreeRatio != 0) {
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   101
    size_t min_free = calculate_free_based_on_live(live, MinHeapFreeRatio);
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   102
    free_size = MAX2(free_size, min_free);
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   103
  }
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   104
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   105
  if (MaxHeapFreeRatio != 100) {
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   106
    size_t max_free = calculate_free_based_on_live(live, MaxHeapFreeRatio);
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   107
    free_size = MIN2(max_free, free_size);
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   108
  }
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   109
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   110
  return free_size;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   111
}
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22551
diff changeset
   112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void PSAdaptiveSizePolicy::major_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _major_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Save most recent collection time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  _latest_major_mutator_interval_seconds = _major_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  _major_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void PSAdaptiveSizePolicy::update_minor_pause_old_estimator(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    double minor_pause_in_ms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  double promo_size_in_mbytes = ((double)_promo_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  _minor_pause_old_estimator->update(promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
void PSAdaptiveSizePolicy::major_collection_end(size_t amount_live,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // Update the pause time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _major_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
31634
0aa645cd8cc3 7012980: PSOldGen is increased if there is no space in Metaspace
jmasa
parents: 31359
diff changeset
   134
  if (should_update_promo_stats(gc_cause)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    double major_pause_in_seconds = _major_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    double major_pause_in_ms = major_pause_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    _avg_major_pause->sample(major_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    double collection_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    if ((_latest_major_mutator_interval_seconds > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        (major_pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        _latest_major_mutator_interval_seconds + major_pause_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      collection_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        major_pause_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      avg_major_gc_cost()->sample(collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      _avg_major_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    // Calculate variables used to estimate pause time vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    double promo_size_in_mbytes = ((double)_promo_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    _major_pause_old_estimator->update(promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      major_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    _major_pause_young_estimator->update(eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      major_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   163
    log_trace(gc, ergo)("psAdaptiveSizePolicy::major_collection_end: major gc cost: %f  average: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   164
                        collection_cost,avg_major_gc_cost()->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   165
    log_trace(gc, ergo)("  major pause: %f major period %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   166
                        major_pause_in_ms, _latest_major_mutator_interval_seconds * MILLIUNITS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    // Calculate variable used to estimate collection cost vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    assert(collection_cost >= 0.0, "Expected to be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _major_collection_estimator->update(promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Update the amount live at the end of a full GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  _live_at_last_full_gc = amount_live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // The policy does not have enough data until at least some major collections
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // have been done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if (_avg_major_pause->count() >= AdaptiveSizePolicyReadyThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    _old_gen_policy_is_ready = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Interval times use this timer to measure the interval that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // the mutator runs.  Reset after the GC pause has been measured.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  _major_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// If the remaining free space in the old generation is less that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// that expected to be needed by the next collection, do a full
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// collection now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
bool PSAdaptiveSizePolicy::should_full_GC(size_t old_free_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // A similar test is done in the scavenge's should_attempt_scavenge().  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // this is changed, decide if that test should also be changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  bool result = padded_average_promoted_in_bytes() > (float) old_free_in_bytes;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   197
  log_trace(gc, ergo)("%s after scavenge average_promoted " SIZE_FORMAT " padded_average_promoted " SIZE_FORMAT " free in old gen " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   198
                      result ? "Full" : "No full",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   199
                      (size_t) average_promoted_in_bytes(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   200
                      (size_t) padded_average_promoted_in_bytes(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   201
                      old_free_in_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
void PSAdaptiveSizePolicy::clear_generation_free_space_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  AdaptiveSizePolicy::clear_generation_free_space_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  set_change_old_gen_for_min_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  set_change_young_gen_for_maj_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// If this is not a full GC, only test and modify the young generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
17842
0d11fa49f81f 8007762: Rename a bunch of methods in size policy across collectors
tamao
parents: 17393
diff changeset
   216
void PSAdaptiveSizePolicy::compute_generations_free_space(
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   217
                                           size_t young_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   218
                                           size_t eden_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   219
                                           size_t old_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   220
                                           size_t cur_eden,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   221
                                           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
   222
                                           size_t max_eden_size,
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   223
                                           bool   is_full_gc) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   224
  compute_eden_space_size(young_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   225
                          eden_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   226
                          cur_eden,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   227
                          max_eden_size,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   228
                          is_full_gc);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   229
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   230
  compute_old_gen_free_space(old_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   231
                             cur_eden,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   232
                             max_old_gen_size,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   233
                             is_full_gc);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   234
}
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   235
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   236
void PSAdaptiveSizePolicy::compute_eden_space_size(
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   237
                                           size_t young_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   238
                                           size_t eden_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   239
                                           size_t cur_eden,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   240
                                           size_t max_eden_size,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   241
                                           bool   is_full_gc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // Update statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Time statistics are updated as we go, update footprint stats here
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 7397
diff changeset
   245
  _avg_base_footprint->sample(BaseFootPrintEstimate);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  avg_young_live()->sample(young_live);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  avg_eden_live()->sample(eden_live);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   248
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   249
  // This code used to return if the policy was not ready , i.e.,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   250
  // policy_is_ready() returning false.  The intent was that
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   251
  // decisions below needed major collection times and so could
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   252
  // not be made before two major collections.  A consequence was
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   253
  // adjustments to the young generation were not done until after
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   254
  // two major collections even if the minor collections times
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   255
  // exceeded the requested goals.  Now let the young generation
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   256
  // adjust for the minor collection times.  Major collection times
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   257
  // will be zero for the first collection and will naturally be
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   258
  // ignored.  Tenured generation adjustments are only made at the
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   259
  // full collections so until the second major collection has
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   260
  // been reached, no tenured generation adjustments will be made.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   261
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   262
  // Until we know better, desired promotion size uses the last calculation
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   263
  size_t desired_promo_size = _promo_size;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   264
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   265
  // Start eden at the current value.  The desired value that is stored
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   266
  // in _eden_size is not bounded by constraints of the heap and can
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   267
  // run away.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   268
  //
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   269
  // As expected setting desired_eden_size to the current
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   270
  // value of desired_eden_size as a starting point
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   271
  // caused desired_eden_size to grow way too large and caused
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   272
  // an overflow down stream.  It may have improved performance in
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   273
  // some case but is dangerous.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   274
  size_t desired_eden_size = cur_eden;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   275
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   276
  // Cache some values. There's a bit of work getting these, so
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   277
  // we might save a little time.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   278
  const double major_cost = major_gc_cost();
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   279
  const double minor_cost = minor_gc_cost();
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   280
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   281
  // This method sets the desired eden size.  That plus the
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   282
  // desired survivor space sizes sets the desired young generation
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   283
  // size.  This methods does not know what the desired survivor
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   284
  // size is but expects that other policy will attempt to make
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   285
  // the survivor sizes compatible with the live data in the
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   286
  // young generation.  This limit is an estimate of the space left
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   287
  // in the young generation after the survivor spaces have been
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   288
  // subtracted out.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   289
  size_t eden_limit = max_eden_size;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   290
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31634
diff changeset
   291
  const double gc_cost_limit = GCTimeLimit / 100.0;
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   292
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   293
  // Which way should we go?
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   294
  // if pause requirement is not met
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   295
  //   adjust size of any generation with average paus exceeding
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   296
  //   the pause limit.  Adjust one pause at a time (the larger)
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   297
  //   and only make adjustments for the major pause at full collections.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   298
  // else if throughput requirement not met
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   299
  //   adjust the size of the generation with larger gc time.  Only
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   300
  //   adjust one generation at a time.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   301
  // else
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   302
  //   adjust down the total heap size.  Adjust down the larger of the
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   303
  //   generations.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   304
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   305
  // Add some checks for a threshold for a change.  For example,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   306
  // a change less than the necessary alignment is probably not worth
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   307
  // attempting.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   308
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   309
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   310
  if ((_avg_minor_pause->padded_average() > gc_pause_goal_sec()) ||
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   311
      (_avg_major_pause->padded_average() > gc_pause_goal_sec())) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   312
    //
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   313
    // Check pauses
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   314
    //
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   315
    // Make changes only to affect one of the pauses (the larger)
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   316
    // at a time.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   317
    adjust_eden_for_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   318
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   319
  } else if (_avg_minor_pause->padded_average() > gc_minor_pause_goal_sec()) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   320
    // Adjust only for the minor pause time goal
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   321
    adjust_eden_for_minor_pause_time(is_full_gc, &desired_eden_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   322
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   323
  } else if(adjusted_mutator_cost() < _throughput_goal) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   324
    // This branch used to require that (mutator_cost() > 0.0 in 1.4.2.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   325
    // This sometimes resulted in skipping to the minimize footprint
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   326
    // code.  Change this to try and reduce GC time if mutator time is
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   327
    // negative for whatever reason.  Or for future consideration,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   328
    // bail out of the code if mutator time is negative.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   329
    //
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   330
    // Throughput
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   331
    //
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   332
    assert(major_cost >= 0.0, "major cost is < 0.0");
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   333
    assert(minor_cost >= 0.0, "minor cost is < 0.0");
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   334
    // Try to reduce the GC times.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   335
    adjust_eden_for_throughput(is_full_gc, &desired_eden_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   336
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   337
  } else {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   338
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   339
    // Be conservative about reducing the footprint.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   340
    //   Do a minimum number of major collections first.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   341
    //   Have reasonable averages for major and minor collections costs.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   342
    if (UseAdaptiveSizePolicyFootprintGoal &&
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   343
        young_gen_policy_is_ready() &&
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   344
        avg_major_gc_cost()->average() >= 0.0 &&
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   345
        avg_minor_gc_cost()->average() >= 0.0) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   346
      size_t desired_sum = desired_eden_size + desired_promo_size;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   347
      desired_eden_size = adjust_eden_for_footprint(desired_eden_size, desired_sum);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   348
    }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   349
  }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   350
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   351
  // Note we make the same tests as in the code block below;  the code
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   352
  // seems a little easier to read with the printing in another block.
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   353
  if (desired_eden_size > eden_limit) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   354
    log_debug(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   355
          "PSAdaptiveSizePolicy::compute_eden_space_size limits:"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   356
          " desired_eden_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   357
          " old_eden_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   358
          " eden_limit: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   359
          " cur_eden: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   360
          " max_eden_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   361
          " avg_young_live: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   362
          desired_eden_size, _eden_size, eden_limit, cur_eden,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   363
          max_eden_size, (size_t)avg_young_live()->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   364
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   365
  if (gc_cost() > gc_cost_limit) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   366
    log_debug(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   367
          "PSAdaptiveSizePolicy::compute_eden_space_size: gc time limit"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   368
          " gc_cost: %f "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   369
          " GCTimeLimit: " UINTX_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   370
          gc_cost(), GCTimeLimit);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   371
  }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   372
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   373
  // Align everything and make a final limit check
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   374
  desired_eden_size  = align_up(desired_eden_size, _space_alignment);
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
   375
  desired_eden_size  = MAX2(desired_eden_size, _space_alignment);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   376
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   377
  eden_limit  = align_down(eden_limit, _space_alignment);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   378
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   379
  // And one last limit check, now that we've aligned things.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   380
  if (desired_eden_size > eden_limit) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   381
    // If the policy says to get a larger eden but
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   382
    // is hitting the limit, don't decrease eden.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   383
    // This can lead to a general drifting down of the
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   384
    // eden size.  Let the tenuring calculation push more
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   385
    // into the old gen.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   386
    desired_eden_size = MAX2(eden_limit, cur_eden);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   387
  }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   388
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   389
  log_debug(gc, ergo)("PSAdaptiveSizePolicy::compute_eden_space_size: costs minor_time: %f major_cost: %f mutator_cost: %f throughput_goal: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   390
             minor_gc_cost(), major_gc_cost(), mutator_cost(), _throughput_goal);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   391
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   392
  log_trace(gc, ergo)("Minor_pause: %f major_pause: %f minor_interval: %f major_interval: %fpause_goal: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   393
                      _avg_minor_pause->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   394
                      _avg_major_pause->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   395
                      _avg_minor_interval->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   396
                      _avg_major_interval->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   397
                      gc_pause_goal_sec());
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   398
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   399
  log_debug(gc, ergo)("Live_space: " SIZE_FORMAT " free_space: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   400
                      live_space(), free_space());
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   401
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   402
  log_trace(gc, ergo)("Base_footprint: " SIZE_FORMAT " avg_young_live: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   403
                      (size_t)_avg_base_footprint->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   404
                      (size_t)avg_young_live()->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   405
                      (size_t)avg_old_live()->average());
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   406
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   407
  log_debug(gc, ergo)("Old eden_size: " SIZE_FORMAT " desired_eden_size: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   408
                      _eden_size, desired_eden_size);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   409
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   410
  set_eden_size(desired_eden_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   411
}
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   412
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   413
void PSAdaptiveSizePolicy::compute_old_gen_free_space(
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   414
                                           size_t old_live,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   415
                                           size_t cur_eden,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   416
                                           size_t max_old_gen_size,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   417
                                           bool   is_full_gc) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   418
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   419
  // Update statistics
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   420
  // Time statistics are updated as we go, update footprint stats here
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  if (is_full_gc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    // old_live is only accurate after a full gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    avg_old_live()->sample(old_live);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  // This code used to return if the policy was not ready , i.e.,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  // policy_is_ready() returning false.  The intent was that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  // decisions below needed major collection times and so could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  // not be made before two major collections.  A consequence was
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  // adjustments to the young generation were not done until after
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  // two major collections even if the minor collections times
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // exceeded the requested goals.  Now let the young generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // adjust for the minor collection times.  Major collection times
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  // will be zero for the first collection and will naturally be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  // ignored.  Tenured generation adjustments are only made at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // full collections so until the second major collection has
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  // been reached, no tenured generation adjustments will be made.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  // Until we know better, desired promotion size uses the last calculation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  size_t desired_promo_size = _promo_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  // Start eden at the current value.  The desired value that is stored
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  // in _eden_size is not bounded by constraints of the heap and can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // run away.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  // As expected setting desired_eden_size to the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // value of desired_eden_size as a starting point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  // caused desired_eden_size to grow way too large and caused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  // an overflow down stream.  It may have improved performance in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  // some case but is dangerous.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  size_t desired_eden_size = cur_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // Cache some values. There's a bit of work getting these, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  // we might save a little time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  const double major_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  const double minor_cost = minor_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  // Limits on our growth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // But don't force a promo size below the current promo size. Otherwise,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  // the promo size will shrink for no good reason.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  promo_limit = MAX2(promo_limit, _promo_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  const double gc_cost_limit = GCTimeLimit/100.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  // Which way should we go?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // if pause requirement is not met
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  //   adjust size of any generation with average paus exceeding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  //   the pause limit.  Adjust one pause at a time (the larger)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  //   and only make adjustments for the major pause at full collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // else if throughput requirement not met
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  //   adjust the size of the generation with larger gc time.  Only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  //   adjust one generation at a time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  // else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  //   adjust down the total heap size.  Adjust down the larger of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  //   generations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 21561
diff changeset
   479
  // Add some checks for a threshold for a change.  For example,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  // a change less than the necessary alignment is probably not worth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  // attempting.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  if ((_avg_minor_pause->padded_average() > gc_pause_goal_sec()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      (_avg_major_pause->padded_average() > gc_pause_goal_sec())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    // Check pauses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    // Make changes only to affect one of the pauses (the larger)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    // at a time.
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   490
    if (is_full_gc) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   491
      set_decide_at_full_gc(decide_at_full_gc_true);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   492
      adjust_promo_for_pause_time(is_full_gc, &desired_promo_size, &desired_eden_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   493
    }
33227
b00ec45f8c2c 8139277: Remove ScavengeWithObjectsInToSpace, ParallelOldGCSplitALot, ParallelOldGCSplitInterval, PSAdjustTenuredGenForMinorPause and PSAdjustYoungGenForMajorPause
david
parents: 32623
diff changeset
   494
  } else if (adjusted_mutator_cost() < _throughput_goal) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    // This branch used to require that (mutator_cost() > 0.0 in 1.4.2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    // This sometimes resulted in skipping to the minimize footprint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    // code.  Change this to try and reduce GC time if mutator time is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    // negative for whatever reason.  Or for future consideration,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    // bail out of the code if mutator time is negative.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    // Throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    assert(major_cost >= 0.0, "major cost is < 0.0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    assert(minor_cost >= 0.0, "minor cost is < 0.0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    // Try to reduce the GC times.
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   506
    if (is_full_gc) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   507
      set_decide_at_full_gc(decide_at_full_gc_true);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   508
      adjust_promo_for_throughput(is_full_gc, &desired_promo_size);
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   509
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    // Be conservative about reducing the footprint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    //   Do a minimum number of major collections first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    //   Have reasonable averages for major and minor collections costs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    if (UseAdaptiveSizePolicyFootprintGoal &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
        young_gen_policy_is_ready() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        avg_major_gc_cost()->average() >= 0.0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
        avg_minor_gc_cost()->average() >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      if (is_full_gc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
        set_decide_at_full_gc(decide_at_full_gc_true);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   521
        size_t desired_sum = desired_eden_size + desired_promo_size;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   522
        desired_promo_size = adjust_promo_for_footprint(desired_promo_size, desired_sum);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  // Note we make the same tests as in the code block below;  the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // seems a little easier to read with the printing in another block.
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   529
  if (desired_promo_size > promo_limit)  {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   530
    // "free_in_old_gen" was the original value for used for promo_limit
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   531
    size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   532
    log_debug(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   533
          "PSAdaptiveSizePolicy::compute_old_gen_free_space limits:"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   534
          " desired_promo_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   535
          " promo_limit: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   536
          " free_in_old_gen: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   537
          " max_old_gen_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   538
          " avg_old_live: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   539
          desired_promo_size, promo_limit, free_in_old_gen,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   540
          max_old_gen_size, (size_t) avg_old_live()->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   541
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   542
  if (gc_cost() > gc_cost_limit) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   543
    log_debug(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   544
          "PSAdaptiveSizePolicy::compute_old_gen_free_space: gc time limit"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   545
          " gc_cost: %f "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   546
          " GCTimeLimit: " UINTX_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   547
          gc_cost(), GCTimeLimit);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  // Align everything and make a final limit check
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   551
  desired_promo_size = align_up(desired_promo_size, _space_alignment);
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
   552
  desired_promo_size = MAX2(desired_promo_size, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   554
  promo_limit = align_down(promo_limit, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  // And one last limit check, now that we've aligned things.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  desired_promo_size = MIN2(desired_promo_size, promo_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   559
  // Timing stats
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   560
  log_debug(gc, ergo)("PSAdaptiveSizePolicy::compute_old_gen_free_space: costs minor_time: %f major_cost: %f  mutator_cost: %f throughput_goal: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   561
             minor_gc_cost(), major_gc_cost(), mutator_cost(), _throughput_goal);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   562
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   563
  log_trace(gc, ergo)("Minor_pause: %f major_pause: %f minor_interval: %f major_interval: %f pause_goal: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   564
                      _avg_minor_pause->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   565
                      _avg_major_pause->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   566
                      _avg_minor_interval->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   567
                      _avg_major_interval->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   568
                      gc_pause_goal_sec());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   570
  // Footprint stats
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   571
  log_debug(gc, ergo)("Live_space: " SIZE_FORMAT " free_space: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   572
                      live_space(), free_space());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   574
  log_trace(gc, ergo)("Base_footprint: " SIZE_FORMAT " avg_young_live: " SIZE_FORMAT " avg_old_live: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   575
                      (size_t)_avg_base_footprint->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   576
                      (size_t)avg_young_live()->average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   577
                      (size_t)avg_old_live()->average());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   579
  log_debug(gc, ergo)("Old promo_size: " SIZE_FORMAT " desired_promo_size: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   580
                      _promo_size, desired_promo_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  set_promo_size(desired_promo_size);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   583
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
void PSAdaptiveSizePolicy::decay_supplemental_growth(bool is_full_gc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  // Decay the supplemental increment?  Decay the supplement growth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  // factor even if it is not used.  It is only meant to give a boost
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  // to the initial growth and if it is not used, then it was not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  if (is_full_gc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    // Don't wait for the threshold value for the major collections.  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    // here, the supplemental growth term was used and should decay.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    if ((_avg_major_pause->count() % TenuredGenerationSizeSupplementDecay)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
        == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
      _old_gen_size_increment_supplement =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
        _old_gen_size_increment_supplement >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    if ((_avg_minor_pause->count() >= AdaptiveSizePolicyReadyThreshold) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
        (_avg_minor_pause->count() % YoungGenerationSizeSupplementDecay) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
      _young_gen_size_increment_supplement =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
        _young_gen_size_increment_supplement >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   607
void PSAdaptiveSizePolicy::adjust_eden_for_minor_pause_time(bool is_full_gc,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   608
    size_t* desired_eden_size_ptr) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   609
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  // Adjust the young generation size to reduce pause time of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  // of collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  // The AdaptiveSizePolicyInitializingSteps test is not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  // here.  It has not seemed to be needed but perhaps should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  // be added for consistency.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  if (minor_pause_young_estimator()->decrement_will_decrease()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
        // reduce eden size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    set_change_young_gen_for_min_pauses(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
          decrease_young_gen_for_min_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    *desired_eden_size_ptr = *desired_eden_size_ptr -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      eden_decrement_aligned_down(*desired_eden_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      // EXPERIMENTAL ADJUSTMENT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
      // Only record that the estimator indicated such an action.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      // *desired_eden_size_ptr = *desired_eden_size_ptr + eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      set_change_young_gen_for_min_pauses(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
          increase_young_gen_for_min_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   631
void PSAdaptiveSizePolicy::adjust_promo_for_pause_time(bool is_full_gc,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
                                             size_t* desired_promo_size_ptr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
                                             size_t* desired_eden_size_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  size_t promo_heap_delta = 0;
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   636
  // Add some checks for a threshold for a change.  For example,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // a change less than the required alignment is probably not worth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // attempting.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
33227
b00ec45f8c2c 8139277: Remove ScavengeWithObjectsInToSpace, ParallelOldGCSplitALot, ParallelOldGCSplitInterval, PSAdjustTenuredGenForMinorPause and PSAdjustYoungGenForMajorPause
david
parents: 32623
diff changeset
   640
  if (_avg_minor_pause->padded_average() <= _avg_major_pause->padded_average() && is_full_gc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    // Adjust for the major pause time only at full gc's because the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    // affects of a change can only be seen at full gc's.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    // Reduce old generation size to reduce pause?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    if (major_pause_old_estimator()->decrement_will_decrease()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
      // reduce old generation size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      set_change_old_gen_for_maj_pauses(decrease_old_gen_for_maj_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
      promo_heap_delta = promo_decrement_aligned_down(*desired_promo_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      *desired_promo_size_ptr = _promo_size - promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
      // EXPERIMENTAL ADJUSTMENT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
      // Only record that the estimator indicated such an action.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      // *desired_promo_size_ptr = _promo_size +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
      //   promo_increment_aligned_up(*desired_promo_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      set_change_old_gen_for_maj_pauses(increase_old_gen_for_maj_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    }
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   657
  }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   658
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   659
  log_trace(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   660
    "PSAdaptiveSizePolicy::adjust_promo_for_pause_time "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   661
    "adjusting gen sizes for major pause (avg %f goal %f). "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   662
    "desired_promo_size " SIZE_FORMAT " promo delta " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   663
    _avg_major_pause->average(), gc_pause_goal_sec(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   664
    *desired_promo_size_ptr, promo_heap_delta);
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   665
}
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   666
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   667
void PSAdaptiveSizePolicy::adjust_eden_for_pause_time(bool is_full_gc,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   668
                                             size_t* desired_promo_size_ptr,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   669
                                             size_t* desired_eden_size_ptr) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   670
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   671
  size_t eden_heap_delta = 0;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   672
  // Add some checks for a threshold for a change.  For example,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   673
  // a change less than the required alignment is probably not worth
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   674
  // attempting.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   675
  if (_avg_minor_pause->padded_average() > _avg_major_pause->padded_average()) {
33227
b00ec45f8c2c 8139277: Remove ScavengeWithObjectsInToSpace, ParallelOldGCSplitALot, ParallelOldGCSplitInterval, PSAdjustTenuredGenForMinorPause and PSAdjustYoungGenForMajorPause
david
parents: 32623
diff changeset
   676
    adjust_eden_for_minor_pause_time(is_full_gc, desired_eden_size_ptr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   678
  log_trace(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   679
    "PSAdaptiveSizePolicy::adjust_eden_for_pause_time "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   680
    "adjusting gen sizes for major pause (avg %f goal %f). "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   681
    "desired_eden_size " SIZE_FORMAT " eden delta " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   682
    _avg_major_pause->average(), gc_pause_goal_sec(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   683
    *desired_eden_size_ptr, eden_heap_delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   686
void PSAdaptiveSizePolicy::adjust_promo_for_throughput(bool is_full_gc,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   687
                                             size_t* desired_promo_size_ptr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   689
  // Add some checks for a threshold for a change.  For example,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  // a change less than the required alignment is probably not worth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  // attempting.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  if ((gc_cost() + mutator_cost()) == 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   697
  log_trace(gc, ergo)("PSAdaptiveSizePolicy::adjust_promo_for_throughput(is_full: %d, promo: " SIZE_FORMAT "): mutator_cost %f  major_gc_cost %f minor_gc_cost %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   698
                      is_full_gc, *desired_promo_size_ptr, mutator_cost(), major_gc_cost(), minor_gc_cost());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // Tenured generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  if (is_full_gc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    // Calculate the change to use for the tenured gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    size_t scaled_promo_heap_delta = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    // Can the increment to the generation be scaled?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    if (gc_cost() >= 0.0 && major_gc_cost() >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
      size_t promo_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
        promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      double scale_by_ratio = major_gc_cost() / gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      scaled_promo_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
        (size_t) (scale_by_ratio * (double) promo_heap_delta);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   711
      log_trace(gc, ergo)("Scaled tenured increment: " SIZE_FORMAT " by %f down to " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   712
                          promo_heap_delta, scale_by_ratio, scaled_promo_heap_delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    } else if (major_gc_cost() >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
      // Scaling is not going to work.  If the major gc time is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      // larger, give it a full increment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      if (major_gc_cost() >= minor_gc_cost()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
        scaled_promo_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
          promo_increment_with_supplement_aligned_up(*desired_promo_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
      // Don't expect to get here but it's ok if it does
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
      // in the product build since the delta will be 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
      // and nothing will change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      assert(false, "Unexpected value for gc costs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    switch (AdaptiveSizeThroughPutPolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
        // Early in the run the statistics might not be good.  Until
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
        // a specific number of collections have been, use the heuristic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
        // that a larger generation size means lower collection costs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
        if (major_collection_estimator()->increment_will_decrease() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
           (_old_gen_change_for_major_throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
            <= AdaptiveSizePolicyInitializingSteps)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
          // Increase tenured generation size to reduce major collection cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
          if ((*desired_promo_size_ptr + scaled_promo_heap_delta) >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
              *desired_promo_size_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
            *desired_promo_size_ptr = _promo_size + scaled_promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
          set_change_old_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
              increase_old_gen_for_throughput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
              _old_gen_change_for_major_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
          // EXPERIMENTAL ADJUSTMENT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
          // Record that decreasing the old gen size would decrease
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
          // the major collection cost but don't do it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
          // *desired_promo_size_ptr = _promo_size -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
          //   promo_decrement_aligned_down(*desired_promo_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
          set_change_old_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
                decrease_old_gen_for_throughput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
        // Simplest strategy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        if ((*desired_promo_size_ptr + scaled_promo_heap_delta) >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
            *desired_promo_size_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
          *desired_promo_size_ptr = *desired_promo_size_ptr +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
            scaled_promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
        set_change_old_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
          increase_old_gen_for_throughput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        _old_gen_change_for_major_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   766
    log_trace(gc, ergo)("Adjusting tenured gen for throughput (avg %f goal %f). desired_promo_size " SIZE_FORMAT " promo_delta " SIZE_FORMAT ,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   767
                        mutator_cost(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   768
                        _throughput_goal,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   769
                        *desired_promo_size_ptr, scaled_promo_heap_delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  }
17393
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   771
}
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   772
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   773
void PSAdaptiveSizePolicy::adjust_eden_for_throughput(bool is_full_gc,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   774
                                             size_t* desired_eden_size_ptr) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   775
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   776
  // Add some checks for a threshold for a change.  For example,
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   777
  // a change less than the required alignment is probably not worth
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   778
  // attempting.
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   779
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   780
  if ((gc_cost() + mutator_cost()) == 0.0) {
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   781
    return;
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   782
  }
7e99f263902c 8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents: 13925
diff changeset
   783
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   784
  log_trace(gc, ergo)("PSAdaptiveSizePolicy::adjust_eden_for_throughput(is_full: %d, cur_eden: " SIZE_FORMAT "): mutator_cost %f  major_gc_cost %f minor_gc_cost %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   785
                      is_full_gc, *desired_eden_size_ptr, mutator_cost(), major_gc_cost(), minor_gc_cost());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  // Young generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  size_t scaled_eden_heap_delta = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  // Can the increment to the generation be scaled?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  if (gc_cost() >= 0.0 && minor_gc_cost() >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    size_t eden_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
      eden_increment_with_supplement_aligned_up(*desired_eden_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    double scale_by_ratio = minor_gc_cost() / gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    assert(scale_by_ratio <= 1.0 && scale_by_ratio >= 0.0, "Scaling is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    scaled_eden_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      (size_t) (scale_by_ratio * (double) eden_heap_delta);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   797
    log_trace(gc, ergo)("Scaled eden increment: " SIZE_FORMAT " by %f down to " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   798
                        eden_heap_delta, scale_by_ratio, scaled_eden_heap_delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  } else if (minor_gc_cost() >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    // Scaling is not going to work.  If the minor gc time is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    // larger, give it a full increment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    if (minor_gc_cost() > major_gc_cost()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
      scaled_eden_heap_delta =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
        eden_increment_with_supplement_aligned_up(*desired_eden_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    // Don't expect to get here but it's ok if it does
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    // in the product build since the delta will be 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    // and nothing will change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    assert(false, "Unexpected value for gc costs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  // Use a heuristic for some number of collections to give
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  // the averages time to settle down.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  switch (AdaptiveSizeThroughPutPolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
      if (minor_collection_estimator()->increment_will_decrease() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
        (_young_gen_change_for_minor_throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
          <= AdaptiveSizePolicyInitializingSteps)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
        // Expand young generation size to reduce frequency of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
        // of collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
        if ((*desired_eden_size_ptr + scaled_eden_heap_delta) >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
            *desired_eden_size_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
          *desired_eden_size_ptr =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
            *desired_eden_size_ptr + scaled_eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
        set_change_young_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
          increase_young_gen_for_througput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
        _young_gen_change_for_minor_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
        // EXPERIMENTAL ADJUSTMENT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
        // Record that decreasing the young gen size would decrease
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
        // the minor collection cost but don't do it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
        // *desired_eden_size_ptr = _eden_size -
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
        //   eden_decrement_aligned_down(*desired_eden_size_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
        set_change_young_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
          decrease_young_gen_for_througput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
      if ((*desired_eden_size_ptr + scaled_eden_heap_delta) >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
          *desired_eden_size_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
        *desired_eden_size_ptr =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
          *desired_eden_size_ptr + scaled_eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      set_change_young_gen_for_throughput(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
        increase_young_gen_for_througput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      _young_gen_change_for_minor_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   851
    log_trace(gc, ergo)("Adjusting eden for throughput (avg %f goal %f). desired_eden_size " SIZE_FORMAT " eden delta " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   852
                        mutator_cost(), _throughput_goal, *desired_eden_size_ptr, scaled_eden_heap_delta);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
size_t PSAdaptiveSizePolicy::adjust_promo_for_footprint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    size_t desired_promo_size, size_t desired_sum) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  assert(desired_promo_size <= desired_sum, "Inconsistent parameters");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  set_decrease_for_footprint(decrease_old_gen_for_footprint_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  size_t change = promo_decrement(desired_promo_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  change = scale_down(change, desired_promo_size, desired_sum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  size_t reduced_size = desired_promo_size - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   865
  log_trace(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   866
    "AdaptiveSizePolicy::adjust_promo_for_footprint "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   867
    "adjusting tenured gen for footprint. "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   868
    "starting promo size " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   869
    " reduced promo size " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   870
    " promo delta " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   871
    desired_promo_size, reduced_size, change );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  assert(reduced_size <= desired_promo_size, "Inconsistent result");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  return reduced_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
size_t PSAdaptiveSizePolicy::adjust_eden_for_footprint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  size_t desired_eden_size, size_t desired_sum) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  assert(desired_eden_size <= desired_sum, "Inconsistent parameters");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  set_decrease_for_footprint(decrease_young_gen_for_footprint_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  size_t change = eden_decrement(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  change = scale_down(change, desired_eden_size, desired_sum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  size_t reduced_size = desired_eden_size - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   887
  log_trace(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   888
    "AdaptiveSizePolicy::adjust_eden_for_footprint "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   889
    "adjusting eden for footprint. "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   890
    " starting eden size " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   891
    " reduced eden size " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   892
    " eden delta " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
   893
    desired_eden_size, reduced_size, change);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  assert(reduced_size <= desired_eden_size, "Inconsistent result");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  return reduced_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
// Scale down "change" by the factor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
//      part / total
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
// Don't align the results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
size_t PSAdaptiveSizePolicy::scale_down(size_t change,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
                                        double part,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
                                        double total) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  assert(part <= total, "Inconsistent input");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  size_t reduced_change = change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  if (total > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    double fraction =  part / total;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    reduced_change = (size_t) (fraction * (double) change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  assert(reduced_change <= change, "Inconsistent result");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  return reduced_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
                                            uint percent_change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  size_t eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  eden_heap_delta = cur_eden / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
size_t PSAdaptiveSizePolicy::eden_increment(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  return eden_increment(cur_eden, YoungGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
size_t PSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  size_t result = eden_increment(cur_eden, YoungGenerationSizeIncrement);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   929
  return align_up(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
size_t PSAdaptiveSizePolicy::eden_increment_aligned_down(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  size_t result = eden_increment(cur_eden);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   934
  return align_down(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
size_t PSAdaptiveSizePolicy::eden_increment_with_supplement_aligned_up(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  size_t result = eden_increment(cur_eden,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    YoungGenerationSizeIncrement + _young_gen_size_increment_supplement);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   941
  return align_up(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
size_t PSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  size_t eden_heap_delta = eden_decrement(cur_eden);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   946
  return align_down(eden_heap_delta, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
size_t PSAdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  size_t eden_heap_delta = eden_increment(cur_eden) /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
                                             uint percent_change) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  size_t promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  promo_heap_delta = cur_promo / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
size_t PSAdaptiveSizePolicy::promo_increment(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
size_t PSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   968
  return align_up(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
size_t PSAdaptiveSizePolicy::promo_increment_aligned_down(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  size_t result =  promo_increment(cur_promo, TenuredGenerationSizeIncrement);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   973
  return align_down(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
size_t PSAdaptiveSizePolicy::promo_increment_with_supplement_aligned_up(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  size_t result =  promo_increment(cur_promo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    TenuredGenerationSizeIncrement + _old_gen_size_increment_supplement);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   980
  return align_up(result, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
size_t PSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  size_t promo_heap_delta = promo_decrement(cur_promo);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   985
  return align_down(promo_heap_delta, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
size_t PSAdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  size_t promo_heap_delta = promo_increment(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
13925
37f75ba502b1 8000351: Tenuring threshold should be unsigned
jwilhelm
parents: 13728
diff changeset
   994
uint PSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
                                             bool is_survivor_overflow,
13925
37f75ba502b1 8000351: Tenuring threshold should be unsigned
jwilhelm
parents: 13728
diff changeset
   996
                                             uint tenuring_threshold,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
                                             size_t survivor_limit) {
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
   998
  assert(survivor_limit >= _space_alignment,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
         "survivor_limit too small");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1000
  assert(is_aligned(survivor_limit, _space_alignment),
46618
d503911aa948 8178489: Make align functions more type safe and consistent
stefank
parents: 40903
diff changeset
  1001
         "survivor_limit not aligned");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
  // This method is called even if the tenuring threshold and survivor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  // spaces are not adjusted so that the averages are sampled above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  if (!UsePSAdaptiveSurvivorSizePolicy ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      !young_gen_policy_is_ready()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    return tenuring_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  // We'll decide whether to increase or decrease the tenuring
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  // threshold based partly on the newly computed survivor size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  // (if we hit the maximum limit allowed, we'll always choose to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  // decrement the threshold).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  bool incr_tenuring_threshold = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  bool decr_tenuring_threshold = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  set_decrement_tenuring_threshold_for_gc_cost(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  set_increment_tenuring_threshold_for_gc_cost(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  set_decrement_tenuring_threshold_for_survivor_limit(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  if (!is_survivor_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    // Keep running averages on how much survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    // We use the tenuring threshold to equalize the cost of major
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    // and minor collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    // ThresholdTolerance is used to indicate how sensitive the
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 21561
diff changeset
  1027
    // tenuring threshold is to differences in cost between the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    // collection types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // Get the times of interest. This involves a little work, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    // we cache the values here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    const double major_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    const double minor_cost = minor_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    if (minor_cost > major_cost * _threshold_tolerance_percent) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
      // Minor times are getting too long;  lower the threshold so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
      // less survives and more is promoted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
      decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
      set_decrement_tenuring_threshold_for_gc_cost(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    } else if (major_cost > minor_cost * _threshold_tolerance_percent) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
      // Major times are too long, so we want less promotion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
      incr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
      set_increment_tenuring_threshold_for_gc_cost(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    // Survivor space overflow occurred, so promoted and survived are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    // not accurate. We'll make our best guess by combining survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    // and promoted and count them as survivors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
    // We'll lower the tenuring threshold to see if we can correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    // things. Also, set the survivor size conservatively. We're
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    // trying to avoid many overflows from occurring if defnew size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    // is just too small.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  // The padded average also maintains a deviation from the average;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  // we use this to see how good of an estimate we have of what survived.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  // We're trying to pad the survivor size as little as possible without
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  // overflowing the survivor spaces.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
  1063
  size_t target_size = align_up((size_t)_avg_survived->padded_average(),
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
  1064
                                     _space_alignment);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
  1065
  target_size = MAX2(target_size, _space_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  if (target_size > survivor_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    // Target size is bigger than we can handle. Let's also reduce
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    // the tenuring threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    target_size = survivor_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    set_decrement_tenuring_threshold_for_survivor_limit(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  // Finally, increment or decrement the tenuring threshold, as decided above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  // We test for decrementing first, as we might have hit the target size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
  // limit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  if (decr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    if (tenuring_threshold > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
      tenuring_threshold--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  } else if (incr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    if (tenuring_threshold < MaxTenuringThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
      tenuring_threshold++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  // We keep a running average of the amount promoted which is used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  // to decide when we should collect the old generation (when
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  // the amount of old gen free space is less than what we expect to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  // promote).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1093
  log_trace(gc, ergo)("avg_survived: %f  avg_deviation: %f", _avg_survived->average(), _avg_survived->deviation());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1094
  log_debug(gc, ergo)("avg_survived_padded_avg: %f", _avg_survived->padded_average());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1096
  log_trace(gc, ergo)("avg_promoted_avg: %f  avg_promoted_dev: %f", avg_promoted()->average(), avg_promoted()->deviation());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1097
  log_debug(gc, ergo)("avg_promoted_padded_avg: %f  avg_pretenured_padded_avg: %f  tenuring_thresh: %d  target_size: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1098
                      avg_promoted()->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1099
                      _avg_pretenured->padded_average(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1100
                      tenuring_threshold, target_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  set_survivor_size(target_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  return tenuring_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
void PSAdaptiveSizePolicy::update_averages(bool is_survivor_overflow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
                                           size_t survived,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
                                           size_t promoted) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  // Update averages
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  if (!is_survivor_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
    // Keep running averages on how much survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
    _avg_survived->sample(survived);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
    size_t survived_guess = survived + promoted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
    _avg_survived->sample(survived_guess);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  }
31359
e9d8d21c21f3 7169803: Usage of pretenured value is not correct
david
parents: 31032
diff changeset
  1118
  avg_promoted()->sample(promoted);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1120
  log_trace(gc, ergo)("AdaptiveSizePolicy::update_averages:  survived: "  SIZE_FORMAT "  promoted: "  SIZE_FORMAT "  overflow: %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1121
                      survived, promoted, is_survivor_overflow ? "true" : "false");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1124
bool PSAdaptiveSizePolicy::print() const {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1125
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1126
  if (!UseAdaptiveSizePolicy) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1127
    return false;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1128
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1130
  if (AdaptiveSizePolicy::print()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1131
    AdaptiveSizePolicy::print_tenuring_threshold(PSScavenge::tenuring_threshold());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1132
    return true;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1133
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33227
diff changeset
  1135
  return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
}