src/hotspot/share/gc/shared/adaptiveSizePolicy.cpp
author shade
Wed, 06 Jun 2018 10:32:59 +0200
branchepsilon-gc-branch
changeset 56675 483d23cdc9e5
parent 49047 8f004146e407
child 51332 c25572739e7c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 35061
diff changeset
     2
 * Copyright (c) 2004, 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: 30585
diff changeset
    26
#include "gc/shared/adaptiveSizePolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30585
diff changeset
    27
#include "gc/shared/collectorPolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30585
diff changeset
    28
#include "gc/shared/gcCause.hpp"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
    29
#include "gc/shared/gcUtil.inline.hpp"
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
    30
#include "gc/shared/softRefPolicy.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30585
diff changeset
    31
#include "gc/shared/workgroup.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
    32
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/ostream.hpp"
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
elapsedTimer AdaptiveSizePolicy::_minor_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
elapsedTimer AdaptiveSizePolicy::_major_timer;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    38
bool AdaptiveSizePolicy::_debug_perturbation = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// The throughput goal is implemented as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//      _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// gc_cost_ratio is the ratio
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//      application cost / gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// For example a gc_cost_ratio of 4 translates into a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// throughput goal of .80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                                       size_t init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                                       size_t init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                       double gc_pause_goal_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
                                       uint gc_cost_ratio) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _eden_size(init_eden_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _promo_size(init_promo_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _survivor_size(init_survivor_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    _gc_pause_goal_sec(gc_pause_goal_sec),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    _throughput_goal(1.0 - double(1.0 / (1.0 + (double) gc_cost_ratio))),
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    57
    _gc_overhead_limit_exceeded(false),
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    58
    _print_gc_overhead_limit_would_be_exceeded(false),
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    59
    _gc_overhead_limit_count(0),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _latest_minor_mutator_interval_seconds(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    _threshold_tolerance_percent(1.0 + ThresholdTolerance/100.0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _young_gen_change_for_minor_throughput(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _old_gen_change_for_major_throughput(0) {
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    64
  assert(AdaptiveSizePolicyGCTimeLimitThreshold > 0,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
    65
    "No opportunity to clear SoftReferences before GC overhead limit");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _avg_minor_pause    =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _avg_minor_gc_cost  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _avg_major_gc_cost  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _avg_young_live     = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _avg_old_live       = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  _avg_eden_live      = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _avg_survived       = new AdaptivePaddedAverage(AdaptiveSizePolicyWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                                                  SurvivorPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _avg_pretenured     = new AdaptivePaddedNoZeroDevAverage(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                                                  AdaptiveSizePolicyWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                                                  SurvivorPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _minor_pause_old_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _minor_pause_young_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _minor_collection_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _major_collection_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Start the timers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _young_gen_policy_is_ready = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    97
//  If the number of GC threads was set on the command line,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    98
// use it.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    99
//  Else
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   100
//    Calculate the number of GC threads based on the number of Java threads.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   101
//    Calculate the number of GC threads based on the size of the heap.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   102
//    Use the larger.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   103
30585
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   104
uint AdaptiveSizePolicy::calc_default_active_workers(uintx total_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   105
                                                     const uintx min_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   106
                                                     uintx active_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   107
                                                     uintx application_workers) {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   108
  // If the user has specifically set the number of
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   109
  // GC threads, use them.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   110
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   111
  // If the user has turned off using a dynamic number of GC threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   112
  // or the users has requested a specific number, set the active
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   113
  // number of workers to all the workers.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   114
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   115
  uintx new_active_workers = total_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   116
  uintx prev_active_workers = active_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   117
  uintx active_workers_by_JT = 0;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   118
  uintx active_workers_by_heap_size = 0;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   119
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   120
  // Always use at least min_workers but use up to
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   121
  // GCThreadsPerJavaThreads * application threads.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   122
  active_workers_by_JT =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   123
    MAX2((uintx) GCWorkersPerJavaThread * application_workers,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   124
         min_workers);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   125
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   126
  // Choose a number of GC threads based on the current size
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   127
  // of the heap.  This may be complicated because the size of
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   128
  // the heap depends on factors such as the throughput goal.
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   129
  // Still a large heap should be collected by more GC threads.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   130
  active_workers_by_heap_size =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   131
      MAX2((size_t) 2U, Universe::heap()->capacity() / HeapSizePerGCThread);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   132
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   133
  uintx max_active_workers =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   134
    MAX2(active_workers_by_JT, active_workers_by_heap_size);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   135
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 35061
diff changeset
   136
  new_active_workers = MIN2(max_active_workers, (uintx) total_workers);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   137
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   138
  // Increase GC workers instantly but decrease them more
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   139
  // slowly.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   140
  if (new_active_workers < prev_active_workers) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   141
    new_active_workers =
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   142
      MAX2(min_workers, (prev_active_workers + new_active_workers) / 2);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   143
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   144
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   145
  // Check once more that the number of workers is within the limits.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   146
  assert(min_workers <= total_workers, "Minimum workers not consistent with total workers");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   147
  assert(new_active_workers >= min_workers, "Minimum workers not observed");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   148
  assert(new_active_workers <= total_workers, "Total workers not observed");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   149
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   150
  if (ForceDynamicNumberOfGCThreads) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   151
    // Assume this is debugging and jiggle the number of GC threads.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   152
    if (new_active_workers == prev_active_workers) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   153
      if (new_active_workers < total_workers) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   154
        new_active_workers++;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   155
      } else if (new_active_workers > min_workers) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   156
        new_active_workers--;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   157
      }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   158
    }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   159
    if (new_active_workers == total_workers) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   160
      if (_debug_perturbation) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   161
        new_active_workers =  min_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   162
      }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   163
      _debug_perturbation = !_debug_perturbation;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   164
    }
30876
44a71334fd94 8080876: Replace unnecessary MAX2(ParallelGCThreads, 1) calls with ParallelGCThreads
stefank
parents: 30764
diff changeset
   165
    assert((new_active_workers <= ParallelGCThreads) &&
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   166
           (new_active_workers >= min_workers),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   167
      "Jiggled active workers too much");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   168
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   169
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 35061
diff changeset
   170
  log_trace(gc, task)("GCTaskManager::calc_default_active_workers() : "
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   171
     "active_workers(): " UINTX_FORMAT "  new_active_workers: " UINTX_FORMAT "  "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   172
     "prev_active_workers: " UINTX_FORMAT "\n"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   173
     " active_workers_by_JT: " UINTX_FORMAT "  active_workers_by_heap_size: " UINTX_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   174
     active_workers, new_active_workers, prev_active_workers,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   175
     active_workers_by_JT, active_workers_by_heap_size);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   176
  assert(new_active_workers > 0, "Always need at least 1");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   177
  return new_active_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   178
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   179
30585
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   180
uint AdaptiveSizePolicy::calc_active_workers(uintx total_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   181
                                             uintx active_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   182
                                             uintx application_workers) {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   183
  // If the user has specifically set the number of
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   184
  // GC threads, use them.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   185
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   186
  // If the user has turned off using a dynamic number of GC threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   187
  // or the users has requested a specific number, set the active
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   188
  // number of workers to all the workers.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   189
30585
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   190
  uint new_active_workers;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   191
  if (!UseDynamicNumberOfGCThreads ||
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   192
     (!FLAG_IS_DEFAULT(ParallelGCThreads) && !ForceDynamicNumberOfGCThreads)) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   193
    new_active_workers = total_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   194
  } else {
30573
a0bd2a51cdb3 8076995: gc/ergonomics/TestDynamicNumberOfGCThreads.java failed with java.lang.RuntimeException: 'new_active_workers' missing from stdout/stderr
drwhite
parents: 24092
diff changeset
   195
    uintx min_workers = (total_workers == 1) ? 1 : 2;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   196
    new_active_workers = calc_default_active_workers(total_workers,
30573
a0bd2a51cdb3 8076995: gc/ergonomics/TestDynamicNumberOfGCThreads.java failed with java.lang.RuntimeException: 'new_active_workers' missing from stdout/stderr
drwhite
parents: 24092
diff changeset
   197
                                                     min_workers,
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   198
                                                     active_workers,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   199
                                                     application_workers);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   200
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   201
  assert(new_active_workers > 0, "Always need at least 1");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   202
  return new_active_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   203
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   204
30585
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   205
uint AdaptiveSizePolicy::calc_active_conc_workers(uintx total_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   206
                                                  uintx active_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   207
                                                  uintx application_workers) {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   208
  if (!UseDynamicNumberOfGCThreads ||
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   209
     (!FLAG_IS_DEFAULT(ConcGCThreads) && !ForceDynamicNumberOfGCThreads)) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   210
    return ConcGCThreads;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   211
  } else {
30585
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   212
    uint no_of_gc_threads = calc_default_active_workers(total_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   213
                                                        1, /* Minimum number of workers */
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   214
                                                        active_workers,
12f312d694cd 6407976: GC worker number should be unsigned
eistepan
parents: 30573
diff changeset
   215
                                                        application_workers);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   216
    return no_of_gc_threads;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   217
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   218
}
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   219
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
bool AdaptiveSizePolicy::tenuring_threshold_change() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  return decrement_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
         increment_tenuring_threshold_for_gc_cost() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
         decrement_tenuring_threshold_for_survivor_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
void AdaptiveSizePolicy::minor_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Save most recent collection time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  _latest_minor_mutator_interval_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
void AdaptiveSizePolicy::update_minor_pause_young_estimator(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    double minor_pause_in_ms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  _minor_pause_young_estimator->update(eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
void AdaptiveSizePolicy::minor_collection_end(GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // Update the pause time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  _minor_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
31032
8e72621ca186 8072913: [REDO] GCCause should distinguish jcmd GC.run from System.gc()
ysuenaga
parents: 30876
diff changeset
   246
  if (!GCCause::is_user_requested_gc(gc_cause) ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    double minor_pause_in_seconds = _minor_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    double minor_pause_in_ms = minor_pause_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    _avg_minor_pause->sample(minor_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    double collection_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    if ((_latest_minor_mutator_interval_seconds > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        (minor_pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      collection_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        minor_pause_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      _avg_minor_gc_cost->sample(collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      _avg_minor_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    // The policy does not have enough data until at least some
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   268
    // young collections have been done.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    _young_gen_policy_is_ready =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    // Calculate variables used to estimate pause time vs. gen sizes
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   273
    double eden_size_in_mbytes = ((double)_eden_size) / ((double)M);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    update_minor_pause_young_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    update_minor_pause_old_estimator(minor_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   277
    log_trace(gc, ergo)("AdaptiveSizePolicy::minor_collection_end: minor gc cost: %f  average: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   278
                        collection_cost, _avg_minor_gc_cost->average());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   279
    log_trace(gc, ergo)("  minor pause: %f minor period %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   280
                        minor_pause_in_ms, _latest_minor_mutator_interval_seconds * MILLIUNITS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    // Calculate variable used to estimate collection cost vs. gen sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    assert(collection_cost >= 0.0, "Expected to be non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // Interval times use this timer to measure the mutator time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // Reset the timer after the GC pause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  _minor_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  _minor_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   293
size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden, uint percent_change) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  size_t eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  eden_heap_delta = cur_eden / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  return eden_increment(cur_eden, YoungGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
size_t AdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  size_t eden_heap_delta = eden_increment(cur_eden) /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  return eden_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31032
diff changeset
   309
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo, uint percent_change) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  size_t promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  promo_heap_delta = cur_promo / 100 * percent_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
size_t AdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  size_t promo_heap_delta = promo_increment(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  return promo_heap_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
double AdaptiveSizePolicy::time_since_major_gc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  _major_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  double result = _major_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  _major_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
// Linear decay of major gc cost
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
double AdaptiveSizePolicy::decaying_major_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  double major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  double major_gc_cost_average = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  double decayed_major_gc_cost = major_gc_cost_average;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  if(time_since_major_gc() > 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    decayed_major_gc_cost = major_gc_cost() *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      (((double) AdaptiveSizeMajorGCDecayTimeScale) * major_interval)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      / time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // The decayed cost should always be smaller than the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // average cost but the vagaries of finite arithmetic could
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  // produce a larger value in decayed_major_gc_cost so protect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  // against that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  return MIN2(major_gc_cost_average, decayed_major_gc_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
// Use a value of the major gc cost that has been decayed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
// by the factor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
//      average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
//        time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
// if the average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
// is less than time-since-last-major-gc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
// In cases where there are initial major gc's that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
// are of a relatively high cost but no later major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
// gc's, the total gc cost can remain high because
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
// the major gc cost remains unchanged (since there are no major
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
// gc's).  In such a situation the value of the unchanging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
// major gc cost can keep the mutator throughput below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
// the goal when in fact the major gc cost is becoming diminishingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
// small.  Use the decaying gc cost only to decide whether to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// adjust for throughput.  Using it also to determine the adjustment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// to be made for throughput also seems reasonable but there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// no test case to use to decide if it is the right thing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
// don't do it yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
double AdaptiveSizePolicy::decaying_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  double decayed_major_gc_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  double avg_major_interval = major_gc_interval_average_for_decay();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (UseAdaptiveSizeDecayMajorGCCost &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      (avg_major_interval > 0.00)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    double time_since_last_major_gc = time_since_major_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    // Decay the major gc cost?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    if (time_since_last_major_gc >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      // Decay using the time-since-last-major-gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      decayed_major_gc_cost = decaying_major_gc_cost();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   386
      log_trace(gc, ergo)("decaying_gc_cost: major interval average: %f  time since last major gc: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   387
                    avg_major_interval, time_since_last_major_gc);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   388
      log_trace(gc, ergo)("  major gc cost: %f  decayed major gc cost: %f",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   389
                    major_gc_cost(), decayed_major_gc_cost);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
void AdaptiveSizePolicy::clear_generation_free_space_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  set_change_young_gen_for_min_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  set_change_old_gen_for_maj_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  set_change_old_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  set_change_young_gen_for_throughput(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  set_decrease_for_footprint(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  set_decide_at_full_gc(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   407
void AdaptiveSizePolicy::check_gc_overhead_limit(
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   408
                                          size_t young_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   409
                                          size_t eden_live,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   410
                                          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
   411
                                          size_t max_eden_size,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   412
                                          bool   is_full_gc,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   413
                                          GCCause::Cause gc_cause,
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
   414
                                          SoftRefPolicy* soft_ref_policy) {
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   415
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   416
  // Ignore explicit GC's.  Exiting here does not set the flag and
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   417
  // does not reset the count.  Updating of the averages for system
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   418
  // GC's is still controlled by UseAdaptiveSizePolicyWithSystemGC.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   419
  if (GCCause::is_user_requested_gc(gc_cause) ||
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   420
      GCCause::is_serviceability_requested_gc(gc_cause)) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   421
    return;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   422
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   423
  // eden_limit is the upper limit on the size of eden based on
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   424
  // the maximum size of the young generation and the sizes
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   425
  // of the survivor space.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   426
  // The question being asked is whether the gc costs are high
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   427
  // and the space being recovered by a collection is low.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   428
  // free_in_young_gen is the free space in the young generation
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   429
  // after a collection and promo_live is the free space in the old
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   430
  // generation after a collection.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   431
  //
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   432
  // Use the minimum of the current value of the live in the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   433
  // young gen or the average of the live in the young gen.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   434
  // If the current value drops quickly, that should be taken
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   435
  // into account (i.e., don't trigger if the amount of free
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   436
  // space has suddenly jumped up).  If the current is much
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   437
  // higher than the average, use the average since it represents
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   438
  // the longer term behavior.
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   439
  const size_t live_in_eden =
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   440
    MIN2(eden_live, (size_t) avg_eden_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   441
  const size_t free_in_eden = max_eden_size > live_in_eden ?
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   442
    max_eden_size - live_in_eden : 0;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   443
  const size_t free_in_old_gen = (size_t)(max_old_gen_size - avg_old_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   444
  const size_t total_free_limit = free_in_old_gen + free_in_eden;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   445
  const size_t total_mem = max_old_gen_size + max_eden_size;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   446
  const double mem_free_limit = total_mem * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   447
  const double mem_free_old_limit = max_old_gen_size * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   448
  const double mem_free_eden_limit = max_eden_size * (GCHeapFreeLimit/100.0);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   449
  const double gc_cost_limit = GCTimeLimit/100.0;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   450
  size_t promo_limit = (size_t)(max_old_gen_size - avg_old_live()->average());
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   451
  // But don't force a promo size below the current promo size. Otherwise,
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   452
  // the promo size will shrink for no good reason.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   453
  promo_limit = MAX2(promo_limit, _promo_size);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   454
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   455
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   456
  log_trace(gc, ergo)(
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   457
        "PSAdaptiveSizePolicy::check_gc_overhead_limit:"
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   458
        " promo_limit: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   459
        " max_eden_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   460
        " total_free_limit: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   461
        " max_old_gen_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   462
        " max_eden_size: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   463
        " mem_free_limit: " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   464
        promo_limit, max_eden_size, total_free_limit,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   465
        max_old_gen_size, max_eden_size,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   466
        (size_t) mem_free_limit);
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   467
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   468
  bool print_gc_overhead_limit_would_be_exceeded = false;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   469
  if (is_full_gc) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   470
    if (gc_cost() > gc_cost_limit &&
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   471
      free_in_old_gen < (size_t) mem_free_old_limit &&
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   472
      free_in_eden < (size_t) mem_free_eden_limit) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   473
      // Collections, on average, are taking too much time, and
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   474
      //      gc_cost() > gc_cost_limit
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   475
      // we have too little space available after a full gc.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   476
      //      total_free_limit < mem_free_limit
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   477
      // where
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   478
      //   total_free_limit is the free space available in
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   479
      //     both generations
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   480
      //   total_mem is the total space available for allocation
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   481
      //     in both generations (survivor spaces are not included
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   482
      //     just as they are not included in eden_limit).
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   483
      //   mem_free_limit is a fraction of total_mem judged to be an
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   484
      //     acceptable amount that is still unused.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   485
      // The heap can ask for the value of this variable when deciding
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   486
      // whether to thrown an OutOfMemory error.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   487
      // Note that the gc time limit test only works for the collections
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   488
      // of the young gen + tenured gen and not for collections of the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   489
      // permanent gen.  That is because the calculation of the space
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   490
      // freed by the collection is the free space in the young gen +
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   491
      // tenured gen.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   492
      // At this point the GC overhead limit is being exceeded.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   493
      inc_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   494
      if (UseGCOverheadLimit) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   495
        if (gc_overhead_limit_count() >=
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   496
            AdaptiveSizePolicyGCTimeLimitThreshold){
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   497
          // All conditions have been met for throwing an out-of-memory
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   498
          set_gc_overhead_limit_exceeded(true);
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   499
          // Avoid consecutive OOM due to the gc time limit by resetting
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   500
          // the counter.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   501
          reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   502
        } else {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   503
          // The required consecutive collections which exceed the
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   504
          // GC time limit may or may not have been reached. We
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   505
          // are approaching that condition and so as not to
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   506
          // throw an out-of-memory before all SoftRef's have been
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   507
          // cleared, set _should_clear_all_soft_refs in CollectorPolicy.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   508
          // The clearing will be done on the next GC.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   509
          bool near_limit = gc_overhead_limit_near();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   510
          if (near_limit) {
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents: 48157
diff changeset
   511
            soft_ref_policy->set_should_clear_all_soft_refs(true);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   512
            log_trace(gc, ergo)("Nearing GC overhead limit, will be clearing all SoftReference");
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   513
          }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   514
        }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   515
      }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   516
      // Set this even when the overhead limit will not
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   517
      // cause an out-of-memory.  Diagnostic message indicating
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   518
      // that the overhead limit is being exceeded is sometimes
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   519
      // printed.
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   520
      print_gc_overhead_limit_would_be_exceeded = true;
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   521
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   522
    } else {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   523
      // Did not exceed overhead limits
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   524
      reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   525
    }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   526
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   527
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   528
  if (UseGCOverheadLimit) {
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   529
    if (gc_overhead_limit_exceeded()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   530
      log_trace(gc, ergo)("GC is exceeding overhead limit of " UINTX_FORMAT "%%", GCTimeLimit);
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   531
      reset_gc_overhead_limit_count();
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   532
    } else if (print_gc_overhead_limit_would_be_exceeded) {
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   533
      assert(gc_overhead_limit_count() > 0, "Should not be printing");
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   534
      log_trace(gc, ergo)("GC would exceed overhead limit of " UINTX_FORMAT "%% %d consecutive time(s)",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   535
                          GCTimeLimit, gc_overhead_limit_count());
5343
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   536
    }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   537
  }
95a5c4b89273 6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents: 1
diff changeset
   538
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   541
bool AdaptiveSizePolicy::print() const {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   542
  assert(UseAdaptiveSizePolicy, "UseAdaptiveSizePolicy need to be enabled.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   544
  if (!log_is_enabled(Debug, gc, ergo)) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   545
    return false;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   546
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // Print goal for which action is needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  char* action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  bool change_for_pause = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  if ((change_old_gen_for_maj_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
         decrease_old_gen_for_maj_pauses_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
         decrease_young_gen_for_min_pauses_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    action = (char*) " *** pause time goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    change_for_pause = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  } else if ((change_old_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
               increase_old_gen_for_throughput_true) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
            (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
               increase_young_gen_for_througput_true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    action = (char*) " *** throughput goal ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  } else if (decrease_for_footprint()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    action = (char*) " *** reduced footprint ***";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    // No actions were taken.  This can legitimately be the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    // situation if not enough data has been gathered to make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    // decisions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // Pauses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  // Currently the size of the old gen is only adjusted to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // change the major pause times.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  char* young_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  char* tenured_gen_action = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  char* shrink_msg = (char*) "(attempted to shrink)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  char* grow_msg = (char*) "(attempted to grow)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  char* no_change_msg = (char*) "(no change)";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  if (change_young_gen_for_min_pauses() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      decrease_young_gen_for_min_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    young_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  if (change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  } else if (change_for_pause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  // Throughput
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    assert(change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
           increase_young_gen_for_througput_true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
           "Both generations should be growing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    tenured_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  } else if (change_young_gen_for_throughput() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
             increase_young_gen_for_througput_true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    // Only the young generation may grow at start up (before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    // enough full collections have been done to grow the old generation).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    young_gen_action = grow_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    tenured_gen_action = no_change_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  // Minimum footprint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  if (decrease_for_footprint() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    young_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    tenured_gen_action = shrink_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   614
  log_debug(gc, ergo)("UseAdaptiveSizePolicy actions to meet %s", action);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   615
  log_debug(gc, ergo)("                       GC overhead (%%)");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   616
  log_debug(gc, ergo)("    Young generation:     %7.2f\t  %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   617
                      100.0 * avg_minor_gc_cost()->average(), young_gen_action);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   618
  log_debug(gc, ergo)("    Tenured generation:   %7.2f\t  %s",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   619
                      100.0 * avg_major_gc_cost()->average(), tenured_gen_action);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   623
void AdaptiveSizePolicy::print_tenuring_threshold( uint new_tenuring_threshold_arg) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  // Tenuring threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  if (decrement_tenuring_threshold_for_survivor_limit()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   626
    log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to avoid survivor space overflow) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  } else if (decrement_tenuring_threshold_for_gc_cost()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   628
    log_debug(gc, ergo)("Tenuring threshold: (attempted to decrease to balance GC costs) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  } else if (increment_tenuring_threshold_for_gc_cost()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   630
    log_debug(gc, ergo)("Tenuring threshold: (attempted to increase to balance GC costs) = %u", new_tenuring_threshold_arg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    assert(!tenuring_threshold_change(), "(no change was attempted)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
}