hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
author goetz
Thu, 26 Jun 2014 16:05:15 +0200
changeset 25468 5331df506290
parent 24941 4ebbe176a7b1
permissions -rw-r--r--
8048241: Introduce umbrella header os.inline.hpp and clean up includes Reviewed-by: coleenp, dholmes, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24941
diff changeset
     2
 * Copyright (c) 2004, 2014, 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: 5035
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5035
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: 5035
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "gc_implementation/shared/gcStats.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/defNewGeneration.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/genCollectedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/thread.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24941
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
elapsedTimer CMSAdaptiveSizePolicy::_concurrent_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
elapsedTimer CMSAdaptiveSizePolicy::_STW_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Defined if the granularity of the time measurements is potentially too large.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#define CLOCK_GRANULARITY_TOO_LARGE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
CMSAdaptiveSizePolicy::CMSAdaptiveSizePolicy(size_t init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                                             size_t init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                                             size_t init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                                             double max_gc_minor_pause_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
                                             double max_gc_pause_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                                             uint gc_cost_ratio) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  AdaptiveSizePolicy(init_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                     init_promo_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
                     init_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                     max_gc_pause_sec,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                     gc_cost_ratio) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  clear_internal_time_intervals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _processor_count = os::active_processor_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
5035
0e498c4df637 6928081: G1: rename parameters common with CMS
jmasa
parents: 1
diff changeset
    54
  if (CMSConcurrentMTEnabled && (ConcGCThreads > 1)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    assert(_processor_count > 0, "Processor count is suspect");
5035
0e498c4df637 6928081: G1: rename parameters common with CMS
jmasa
parents: 1
diff changeset
    56
    _concurrent_processor_count = MIN2((uint) ConcGCThreads,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                                       (uint) _processor_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _concurrent_processor_count = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _avg_concurrent_time  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _avg_concurrent_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _avg_concurrent_gc_cost = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _avg_initial_pause    = new AdaptivePaddedAverage(AdaptiveTimeWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                                    PausePadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _avg_remark_pause     = new AdaptivePaddedAverage(AdaptiveTimeWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                                                    PausePadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _avg_cms_STW_time     = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _avg_cms_STW_gc_cost  = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  _avg_cms_free         = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  _avg_cms_free_at_sweep = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _avg_cms_promo        = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Mark-sweep-compact
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _avg_msc_pause        = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _avg_msc_interval     = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _avg_msc_gc_cost      = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Mark-sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _avg_ms_pause = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  _avg_ms_interval      = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  _avg_ms_gc_cost       = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Variables that estimate pause times as a function of generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  _remark_pause_old_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _initial_pause_old_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _remark_pause_young_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  _initial_pause_young_estimator =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Alignment comes from that used in ReservedSpace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _generation_alignment = os::vm_allocation_granularity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Start the concurrent timer here so that the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // concurrent_phases_begin() measures a finite mutator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // time.  A finite mutator time is used to determine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // if a concurrent collection has been started.  If this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // proves to be a problem, use some explicit flag to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // signal that a concurrent collection has been started.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
double CMSAdaptiveSizePolicy::concurrent_processor_fraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // For now assume no other daemon threads are taking alway
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // cpu's from the application.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return ((double) _concurrent_processor_count / (double) _processor_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
double CMSAdaptiveSizePolicy::concurrent_collection_cost(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                                                  double interval_in_seconds) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  //  When the precleaning and sweeping phases use multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // threads, change one_processor_fraction to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // concurrent_processor_fraction().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  double one_processor_fraction = 1.0 / ((double) processor_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  double concurrent_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    collection_cost(_latest_cms_concurrent_marking_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                interval_in_seconds) * concurrent_processor_fraction() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    collection_cost(_latest_cms_concurrent_precleaning_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                interval_in_seconds) * one_processor_fraction +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    collection_cost(_latest_cms_concurrent_sweeping_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                interval_in_seconds) * one_processor_fraction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      "\nCMSAdaptiveSizePolicy::scaled_concurrent_collection_cost(%f) "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      "_latest_cms_concurrent_marking_cost %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      "_latest_cms_concurrent_precleaning_cost %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      "_latest_cms_concurrent_sweeping_cost %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      "concurrent_processor_fraction %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      "concurrent_cost %f ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      interval_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      collection_cost(_latest_cms_concurrent_marking_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        interval_in_seconds),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      collection_cost(_latest_cms_concurrent_precleaning_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        interval_in_seconds),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      collection_cost(_latest_cms_concurrent_sweeping_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        interval_in_seconds),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      concurrent_processor_fraction(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      concurrent_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return concurrent_cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
double CMSAdaptiveSizePolicy::concurrent_collection_time() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  double latest_cms_sum_concurrent_phases_time_secs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    _latest_cms_concurrent_marking_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    _latest_cms_concurrent_precleaning_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    _latest_cms_concurrent_sweeping_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  return latest_cms_sum_concurrent_phases_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
double CMSAdaptiveSizePolicy::scaled_concurrent_collection_time() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  //  When the precleaning and sweeping phases use multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // threads, change one_processor_fraction to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // concurrent_processor_fraction().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  double one_processor_fraction = 1.0 / ((double) processor_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  double latest_cms_sum_concurrent_phases_time_secs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    _latest_cms_concurrent_marking_time_secs * concurrent_processor_fraction() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    _latest_cms_concurrent_precleaning_time_secs * one_processor_fraction +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    _latest_cms_concurrent_sweeping_time_secs * one_processor_fraction ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      "\nCMSAdaptiveSizePolicy::scaled_concurrent_collection_time "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      "_latest_cms_concurrent_marking_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      "_latest_cms_concurrent_precleaning_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      "_latest_cms_concurrent_sweeping_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      "concurrent_processor_fraction %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      "latest_cms_sum_concurrent_phases_time_secs %f ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      _latest_cms_concurrent_marking_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      _latest_cms_concurrent_precleaning_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      _latest_cms_concurrent_sweeping_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      concurrent_processor_fraction(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      latest_cms_sum_concurrent_phases_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  return latest_cms_sum_concurrent_phases_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
void CMSAdaptiveSizePolicy::update_minor_pause_old_estimator(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    double minor_pause_in_ms) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Get the equivalent of the free space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // that is available for promotions in the CMS generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // and use that to update _minor_pause_old_estimator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // Don't implement this until it is needed. A warning is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // printed if _minor_pause_old_estimator is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void CMSAdaptiveSizePolicy::concurrent_marking_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    gclog_or_tty->print(": concurrent_marking_begin ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  //  Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  _latest_cms_collection_end_to_collection_start_secs = _concurrent_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::concurrent_marking_begin: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    "mutator time %f", _latest_cms_collection_end_to_collection_start_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void CMSAdaptiveSizePolicy::concurrent_marking_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::concurrent_marking_end()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  _latest_cms_concurrent_marking_time_secs = _concurrent_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    gclog_or_tty->print_cr("\n CMSAdaptiveSizePolicy::concurrent_marking_end"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      ":concurrent marking time (s) %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      _latest_cms_concurrent_marking_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
void CMSAdaptiveSizePolicy::concurrent_precleaning_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      "CMSAdaptiveSizePolicy::concurrent_precleaning_begin()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
void CMSAdaptiveSizePolicy::concurrent_precleaning_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::concurrent_precleaning_end()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // May be set again by a second call during the same collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  _latest_cms_concurrent_precleaning_time_secs = _concurrent_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    gclog_or_tty->print_cr("\n CMSAdaptiveSizePolicy::concurrent_precleaning_end"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      ":concurrent precleaning time (s) %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      _latest_cms_concurrent_precleaning_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
void CMSAdaptiveSizePolicy::concurrent_sweeping_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      "CMSAdaptiveSizePolicy::concurrent_sweeping_begin()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
void CMSAdaptiveSizePolicy::concurrent_sweeping_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::concurrent_sweeping_end()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  _latest_cms_concurrent_sweeping_time_secs = _concurrent_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    gclog_or_tty->print_cr("\n CMSAdaptiveSizePolicy::concurrent_sweeping_end"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      ":concurrent sweeping time (s) %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      _latest_cms_concurrent_sweeping_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
void CMSAdaptiveSizePolicy::concurrent_phases_end(GCCause::Cause gc_cause,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
                                                  size_t cur_eden,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
                                                  size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    gclog_or_tty->print(": concurrent_phases_end ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // Update the concurrent timer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    avg_cms_free()->sample(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    double latest_cms_sum_concurrent_phases_time_secs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      concurrent_collection_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    _avg_concurrent_time->sample(latest_cms_sum_concurrent_phases_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // Total interval for collection.  May not be valid.  Tests
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // below determine whether to use this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    gclog_or_tty->print_cr("\nCMSAdaptiveSizePolicy::concurrent_phases_end \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      "_latest_cms_reset_end_to_initial_mark_start_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      "_latest_cms_initial_mark_start_to_end_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      "_latest_cms_remark_start_to_end_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      "_latest_cms_concurrent_marking_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      "_latest_cms_concurrent_precleaning_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      "_latest_cms_concurrent_sweeping_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      "latest_cms_sum_concurrent_phases_time_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      "_latest_cms_collection_end_to_collection_start_secs %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      "concurrent_processor_fraction %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      _latest_cms_reset_end_to_initial_mark_start_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      _latest_cms_initial_mark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      _latest_cms_remark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      _latest_cms_concurrent_marking_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      _latest_cms_concurrent_precleaning_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      _latest_cms_concurrent_sweeping_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      latest_cms_sum_concurrent_phases_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      _latest_cms_collection_end_to_collection_start_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      concurrent_processor_fraction());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      _latest_cms_remark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      latest_cms_sum_concurrent_phases_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      _latest_cms_collection_end_to_collection_start_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    assert(interval_in_seconds >= 0.0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      "Bad interval between cms collections");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    avg_concurrent_interval()->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    // STW costs (initial and remark pauses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    assert(_latest_cms_initial_mark_start_to_end_time_secs >= 0.0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      "Bad initial mark pause");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    assert(_latest_cms_remark_start_to_end_time_secs >= 0.0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      "Bad remark pause");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    double STW_time_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
      _latest_cms_remark_start_to_end_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    double STW_collection_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    if (interval_in_seconds > 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      // cost for the STW phases of the concurrent collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      STW_collection_cost = STW_time_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      avg_cms_STW_gc_cost()->sample(STW_collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      gclog_or_tty->print("cmsAdaptiveSizePolicy::STW_collection_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
        "STW gc cost: %f  average: %f", STW_collection_cost,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        avg_cms_STW_gc_cost()->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      gclog_or_tty->print_cr("  STW pause: %f (ms) STW period %f (ms)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
        (double) STW_time_in_seconds * MILLIUNITS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        (double) interval_in_seconds * MILLIUNITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    double concurrent_cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    if (latest_cms_sum_concurrent_phases_time_secs > 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      concurrent_cost = concurrent_collection_cost(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      avg_concurrent_gc_cost()->sample(concurrent_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      // Average this ms cost into all the other types gc costs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        gclog_or_tty->print("cmsAdaptiveSizePolicy::concurrent_phases_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
          "concurrent gc cost: %f  average: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
          concurrent_cost,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
          _avg_concurrent_gc_cost->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        gclog_or_tty->print_cr("  concurrent time: %f (ms) cms period %f (ms)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
          " processor fraction: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
          latest_cms_sum_concurrent_phases_time_secs * MILLIUNITS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
          interval_in_seconds * MILLIUNITS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
          concurrent_processor_fraction());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    double total_collection_cost = STW_collection_cost + concurrent_cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    avg_major_gc_cost()->sample(total_collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    // Gather information for estimating future behavior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    double initial_pause_in_ms = _latest_cms_initial_mark_start_to_end_time_secs * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    double remark_pause_in_ms = _latest_cms_remark_start_to_end_time_secs * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    double cur_promo_size_in_mbytes = ((double)cur_promo)/((double)M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    initial_pause_old_estimator()->update(cur_promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      initial_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    remark_pause_old_estimator()->update(cur_promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      remark_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    major_collection_estimator()->update(cur_promo_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      total_collection_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    // This estimate uses the average eden size.  It could also
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    // have used the latest eden size.  Which is better?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    double cur_eden_size_in_mbytes = ((double)cur_eden)/((double) M);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    initial_pause_young_estimator()->update(cur_eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      initial_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    remark_pause_young_estimator()->update(cur_eden_size_in_mbytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
      remark_pause_in_ms);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  clear_internal_time_intervals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  set_first_after_collection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // The concurrent phases keeps track of it's own mutator interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  // with this timer.  This allows the stop-the-world phase to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  // be included in the mutator time so that the stop-the-world time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  // is not double counted.  Reset and start it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // The mutator time between STW phases does not include the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // concurrent collection time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
void CMSAdaptiveSizePolicy::checkpoint_roots_initial_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  //  Update the interval time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  _latest_cms_reset_end_to_initial_mark_start_secs = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  // Reset for the initial mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
void CMSAdaptiveSizePolicy::checkpoint_roots_initial_end(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    _latest_cms_initial_mark_start_to_end_time_secs = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    avg_initial_pause()->sample(_latest_cms_initial_mark_start_to_end_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      gclog_or_tty->print(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        "cmsAdaptiveSizePolicy::checkpoint_roots_initial_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        "initial pause: %f ", _latest_cms_initial_mark_start_to_end_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
void CMSAdaptiveSizePolicy::checkpoint_roots_final_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  _latest_cms_initial_mark_end_to_remark_start_secs = _STW_timer.seconds();
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   458
  // Start accumulating time for the remark in the STW timer.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
void CMSAdaptiveSizePolicy::checkpoint_roots_final_end(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    // Total initial mark pause + remark pause.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    _latest_cms_remark_start_to_end_time_secs = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    double STW_time_in_seconds = _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      _latest_cms_remark_start_to_end_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    double STW_time_in_ms = STW_time_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    avg_remark_pause()->sample(_latest_cms_remark_start_to_end_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    // Sample total for initial mark + remark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    avg_cms_STW_time()->sample(STW_time_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      gclog_or_tty->print("cmsAdaptiveSizePolicy::checkpoint_roots_final_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
        "remark pause: %f", _latest_cms_remark_start_to_end_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  // Don't start the STW times here because the concurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  // sweep and reset has not happened.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  //  Keep the old comment above in case I don't understand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  // what is going on but now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  // Start the STW timer because it is used by ms_collection_begin()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  // and ms_collection_end() to get the sweep time if a MS is being
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  // done in the foreground.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
void CMSAdaptiveSizePolicy::msc_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    gclog_or_tty->print(": msc_collection_begin ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  _latest_cms_msc_end_to_msc_start_time_secs = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::msc_collection_begin: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      "mutator time %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      _latest_cms_msc_end_to_msc_start_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  avg_msc_interval()->sample(_latest_cms_msc_end_to_msc_start_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
void CMSAdaptiveSizePolicy::msc_collection_end(GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    gclog_or_tty->print(": msc_collection_end ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
        UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    double msc_pause_in_seconds = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    if ((_latest_cms_msc_end_to_msc_start_time_secs > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        (msc_pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      avg_msc_pause()->sample(msc_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      double mutator_time_in_seconds = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      if (_latest_cms_collection_end_to_collection_start_secs == 0.0) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   529
        // This assertion may fail because of time stamp granularity.
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   530
        // Comment it out and investigate it at a later time.  The large
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        // time stamp granularity occurs on some older linux systems.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
#ifndef CLOCK_GRANULARITY_TOO_LARGE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
        assert((_latest_cms_concurrent_marking_time_secs == 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
               (_latest_cms_concurrent_precleaning_time_secs == 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
               (_latest_cms_concurrent_sweeping_time_secs == 0.0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
          "There should not be any concurrent time");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
        // A concurrent collection did not start.  Mutator time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        // between collections comes from the STW MSC timer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
        mutator_time_in_seconds = _latest_cms_msc_end_to_msc_start_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
        // The concurrent collection did start so count the mutator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        // time to the start of the concurrent collection.  In this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        // case the _latest_cms_msc_end_to_msc_start_time_secs measures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
        // the time between the initial mark or remark and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
        // start of the MSC.  That has no real meaning.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
        mutator_time_in_seconds = _latest_cms_collection_end_to_collection_start_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      double latest_cms_sum_concurrent_phases_time_secs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        concurrent_collection_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
        mutator_time_in_seconds +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
        _latest_cms_remark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        latest_cms_sum_concurrent_phases_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
        msc_pause_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
      if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
        gclog_or_tty->print_cr("  interval_in_seconds %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
          "     mutator_time_in_seconds %f \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
          "     _latest_cms_initial_mark_start_to_end_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
          "     _latest_cms_remark_start_to_end_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
          "     latest_cms_sum_concurrent_phases_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
          "     msc_pause_in_seconds %f\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
          interval_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
          mutator_time_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
          _latest_cms_initial_mark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
          _latest_cms_remark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
          latest_cms_sum_concurrent_phases_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
          msc_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      // The concurrent cost is wasted cost but it should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      // included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      double concurrent_cost = concurrent_collection_cost(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
      // Initial mark and remark, also wasted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      double STW_time_in_seconds = _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
        _latest_cms_remark_start_to_end_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      double STW_collection_cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
        collection_cost(STW_time_in_seconds, interval_in_seconds) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
        concurrent_cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
        gclog_or_tty->print_cr(" msc_collection_end:\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
          "_latest_cms_collection_end_to_collection_start_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
          "_latest_cms_msc_end_to_msc_start_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
          "_latest_cms_initial_mark_start_to_end_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
          "_latest_cms_remark_start_to_end_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
          "latest_cms_sum_concurrent_phases_time_secs %f\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
          _latest_cms_collection_end_to_collection_start_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
          _latest_cms_msc_end_to_msc_start_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
          _latest_cms_initial_mark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
          _latest_cms_remark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
          latest_cms_sum_concurrent_phases_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
        gclog_or_tty->print_cr(" msc_collection_end: \n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
          "latest_cms_sum_concurrent_phases_time_secs %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
          "STW_time_in_seconds %f\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
          "msc_pause_in_seconds %f\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
          latest_cms_sum_concurrent_phases_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
          STW_time_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
          msc_pause_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      double cost = concurrent_cost + STW_collection_cost +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
        collection_cost(msc_pause_in_seconds, interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
      _avg_msc_gc_cost->sample(cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      // Average this ms cost into all the other types gc costs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      avg_major_gc_cost()->sample(cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
      _avg_msc_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
        gclog_or_tty->print("cmsAdaptiveSizePolicy::msc_collection_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
          "MSC gc cost: %f  average: %f", cost,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
          _avg_msc_gc_cost->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
        double msc_pause_in_ms = msc_pause_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
        gclog_or_tty->print_cr("  MSC pause: %f (ms) MSC period %f (ms)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
          msc_pause_in_ms, (double) interval_in_seconds * MILLIUNITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  clear_internal_time_intervals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  // Can this call be put into the epilogue?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  set_first_after_collection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  // The concurrent phases keeps track of it's own mutator interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  // with this timer.  This allows the stop-the-world phase to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  // be included in the mutator time so that the stop-the-world time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // is not double counted.  Reset and start it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
void CMSAdaptiveSizePolicy::ms_collection_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    gclog_or_tty->print(": ms_collection_begin ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  _latest_cms_ms_end_to_ms_start = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::ms_collection_begin: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      "mutator time %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      _latest_cms_ms_end_to_ms_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  avg_ms_interval()->sample(_STW_timer.seconds());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
void CMSAdaptiveSizePolicy::ms_collection_end(GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    gclog_or_tty->print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    gclog_or_tty->print(": ms_collection_end ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
        UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    // The MS collection is a foreground collection that does all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    // the parts of a mostly concurrent collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    // For this collection include the cost of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    //  initial mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    //  remark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    //  all concurrent time (scaled down by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    //    concurrent_processor_fraction).  Some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    //    may be zero if the baton was passed before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    //    it was reached.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    //    concurrent marking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    //    sweeping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    //    resetting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    //  STW after baton was passed (STW_in_foreground_in_seconds)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    double STW_in_foreground_in_seconds = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    double latest_cms_sum_concurrent_phases_time_secs =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      concurrent_collection_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    if (PrintAdaptiveSizePolicy && Verbose) {
22775
52bc5222f5f1 8026849: Fix typos in the GC code, part 2
jwilhelm
parents: 22551
diff changeset
   692
      gclog_or_tty->print_cr("\nCMSAdaptiveSizePolicy::ms_collection_end "
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        "STW_in_foreground_in_seconds %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
        "_latest_cms_initial_mark_start_to_end_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        "_latest_cms_remark_start_to_end_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
        "latest_cms_sum_concurrent_phases_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
        "_latest_cms_ms_marking_start_to_end_time_secs %f "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
        "_latest_cms_ms_end_to_ms_start %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
        STW_in_foreground_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        _latest_cms_initial_mark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
        _latest_cms_remark_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
        latest_cms_sum_concurrent_phases_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
        _latest_cms_ms_marking_start_to_end_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
        _latest_cms_ms_end_to_ms_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    double STW_marking_in_seconds = _latest_cms_initial_mark_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      _latest_cms_remark_start_to_end_time_secs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
#ifndef CLOCK_GRANULARITY_TOO_LARGE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    assert(_latest_cms_ms_marking_start_to_end_time_secs == 0.0 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
           latest_cms_sum_concurrent_phases_time_secs == 0.0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
           "marking done twice?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    double ms_time_in_seconds = STW_marking_in_seconds +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      STW_in_foreground_in_seconds +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      _latest_cms_ms_marking_start_to_end_time_secs +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
      scaled_concurrent_collection_time();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    avg_ms_pause()->sample(ms_time_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    // Use the STW costs from the initial mark and remark plus
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    // the cost of the concurrent phase to calculate a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    // collection cost.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    double cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    if ((_latest_cms_ms_end_to_ms_start > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
        (ms_time_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
      double interval_in_seconds =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
        _latest_cms_ms_end_to_ms_start + ms_time_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
        gclog_or_tty->print_cr("\n ms_time_in_seconds  %f  "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
          "latest_cms_sum_concurrent_phases_time_secs %f  "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
          "interval_in_seconds %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
          ms_time_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
          latest_cms_sum_concurrent_phases_time_secs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
          interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      cost = collection_cost(ms_time_in_seconds, interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      _avg_ms_gc_cost->sample(cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      // Average this ms cost into all the other types gc costs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      avg_major_gc_cost()->sample(cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      // Sample for performance counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      _avg_ms_interval->sample(interval_in_seconds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      gclog_or_tty->print("cmsAdaptiveSizePolicy::ms_collection_end: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
        "MS gc cost: %f  average: %f", cost, _avg_ms_gc_cost->average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      double ms_time_in_ms = ms_time_in_seconds * MILLIUNITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
      gclog_or_tty->print_cr("  MS pause: %f (ms) MS period %f (ms)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        ms_time_in_ms,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
        _latest_cms_ms_end_to_ms_start * MILLIUNITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  // Consider putting this code (here to end) into a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  // method for convenience.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  clear_internal_time_intervals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  set_first_after_collection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  // The concurrent phases keeps track of it's own mutator interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  // with this timer.  This allows the stop-the-world phase to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  // be included in the mutator time so that the stop-the-world time
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  // is not double counted.  Reset and start it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  _concurrent_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
void CMSAdaptiveSizePolicy::clear_internal_time_intervals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  _latest_cms_reset_end_to_initial_mark_start_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  _latest_cms_initial_mark_end_to_remark_start_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  _latest_cms_collection_end_to_collection_start_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  _latest_cms_concurrent_marking_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  _latest_cms_concurrent_precleaning_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  _latest_cms_concurrent_sweeping_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  _latest_cms_msc_end_to_msc_start_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  _latest_cms_ms_end_to_ms_start = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  _latest_cms_remark_start_to_end_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  _latest_cms_initial_mark_start_to_end_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  _latest_cms_ms_marking_start_to_end_time_secs = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
void CMSAdaptiveSizePolicy::clear_generation_free_space_flags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  AdaptiveSizePolicy::clear_generation_free_space_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  set_change_young_gen_for_maj_pauses(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
void CMSAdaptiveSizePolicy::concurrent_phases_resume() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    gclog_or_tty->stamp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::concurrent_phases_resume()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
double CMSAdaptiveSizePolicy::time_since_major_gc() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  _concurrent_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  double time_since_cms_gc = _concurrent_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  _concurrent_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  double time_since_STW_gc = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  return MIN2(time_since_cms_gc, time_since_STW_gc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
double CMSAdaptiveSizePolicy::major_gc_interval_average_for_decay() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  double cms_interval = _avg_concurrent_interval->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  double msc_interval = _avg_msc_interval->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  double ms_interval = _avg_ms_interval->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  return MAX3(cms_interval, msc_interval, ms_interval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
double CMSAdaptiveSizePolicy::cms_gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  return avg_major_gc_cost()->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
void CMSAdaptiveSizePolicy::ms_collection_marking_begin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  _STW_timer.stop();
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
   828
  // Start accumulating time for the marking in the STW timer.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
void CMSAdaptiveSizePolicy::ms_collection_marking_end(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    GCCause::Cause gc_cause) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  _STW_timer.stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  if (gc_cause != GCCause::_java_lang_system_gc ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
      UseAdaptiveSizePolicyWithSystemGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    _latest_cms_ms_marking_start_to_end_time_secs = _STW_timer.seconds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      gclog_or_tty->print_cr("CMSAdaptiveSizePolicy::"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
        "msc_collection_marking_end: mutator time %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
        _latest_cms_ms_marking_start_to_end_time_secs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  _STW_timer.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  _STW_timer.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
double CMSAdaptiveSizePolicy::gc_cost() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  double cms_gen_cost = cms_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  double result =  MIN2(1.0, minor_gc_cost() + cms_gen_cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  assert(result >= 0.0, "Both minor and major costs are non-negative");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
// Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
double CMSAdaptiveSizePolicy::collection_cost(double pause_in_seconds,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
                                              double interval_in_seconds) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  // Cost of collection (unit-less)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  double cost = 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  if ((interval_in_seconds > 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
      (pause_in_seconds > 0.0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    cost =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
      pause_in_seconds / interval_in_seconds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  return cost;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
size_t CMSAdaptiveSizePolicy::adjust_eden_for_pause_time(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  size_t change = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  size_t desired_eden = cur_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  // reduce eden size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  change = eden_decrement_aligned_down(cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  desired_eden = cur_eden - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
      "CMSAdaptiveSizePolicy::adjust_eden_for_pause_time "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
      "adjusting eden for pause time. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      " starting eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      " reduced eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
      " eden delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      cur_eden, desired_eden, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  return desired_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
size_t CMSAdaptiveSizePolicy::adjust_eden_for_throughput(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  size_t desired_eden = cur_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  set_change_young_gen_for_throughput(increase_young_gen_for_througput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  size_t change = eden_increment_aligned_up(cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  size_t scaled_change = scale_by_gen_gc_cost(change, minor_gc_cost());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  if (cur_eden + scaled_change > cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    desired_eden = cur_eden + scaled_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  _young_gen_change_for_minor_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      "CMSAdaptiveSizePolicy::adjust_eden_for_throughput "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      "adjusting eden for throughput. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
      " starting eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      " increased eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      " eden delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      cur_eden, desired_eden, scaled_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  return desired_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
size_t CMSAdaptiveSizePolicy::adjust_eden_for_footprint(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  set_decrease_for_footprint(decrease_young_gen_for_footprint_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  size_t change = eden_decrement(cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  size_t desired_eden_size = cur_eden - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
      "CMSAdaptiveSizePolicy::adjust_eden_for_footprint "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
      "adjusting eden for footprint. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
      " starting eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      " reduced eden size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
      " eden delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      cur_eden, desired_eden_size, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  return desired_eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
// The eden and promo versions should be combined if possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
// They are the same except that the sizes of the decrement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
// and increment are different for eden and promo.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
size_t CMSAdaptiveSizePolicy::eden_decrement_aligned_down(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  size_t delta = eden_decrement(cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  return align_size_down(delta, generation_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
size_t CMSAdaptiveSizePolicy::eden_increment_aligned_up(size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  size_t delta = eden_increment(cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  return align_size_up(delta, generation_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
size_t CMSAdaptiveSizePolicy::promo_decrement_aligned_down(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  size_t delta = promo_decrement(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  return align_size_down(delta, generation_alignment());
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 CMSAdaptiveSizePolicy::promo_increment_aligned_up(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  size_t delta = promo_increment(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  return align_size_up(delta, generation_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
17842
0d11fa49f81f 8007762: Rename a bunch of methods in size policy across collectors
tamao
parents: 13925
diff changeset
   961
void CMSAdaptiveSizePolicy::compute_eden_space_size(size_t cur_eden,
0d11fa49f81f 8007762: Rename a bunch of methods in size policy across collectors
tamao
parents: 13925
diff changeset
   962
                                                    size_t max_eden_size)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  size_t desired_eden_size = cur_eden;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  size_t eden_limit = max_eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  // Printout input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  if (PrintGC && PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    gclog_or_tty->print_cr(
17842
0d11fa49f81f 8007762: Rename a bunch of methods in size policy across collectors
tamao
parents: 13925
diff changeset
   970
      "CMSAdaptiveSizePolicy::compute_eden_space_size: "
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
      "cur_eden " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  // Used for diagnostics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  clear_generation_free_space_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  if (_avg_minor_pause->padded_average() > gc_pause_goal_sec()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    if (minor_pause_young_estimator()->decrement_will_decrease()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      // If the minor pause is too long, shrink the young gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
      set_change_young_gen_for_min_pauses(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
        decrease_young_gen_for_min_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      desired_eden_size = adjust_eden_for_pause_time(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  } else if ((avg_remark_pause()->padded_average() > gc_pause_goal_sec()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
             (avg_initial_pause()->padded_average() > gc_pause_goal_sec())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    // The remark or initial pauses are not meeting the goal.  Should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    // the generation be shrunk?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    if (get_and_clear_first_after_collection() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
        ((avg_remark_pause()->padded_average() > gc_pause_goal_sec() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
          remark_pause_young_estimator()->decrement_will_decrease()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
         (avg_initial_pause()->padded_average() > gc_pause_goal_sec() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
          initial_pause_young_estimator()->decrement_will_decrease()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
       set_change_young_gen_for_maj_pauses(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
         decrease_young_gen_for_maj_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
      // If the remark or initial pause is too long and this is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
      // first young gen collection after a cms collection, shrink
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
      // the young gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      desired_eden_size = adjust_eden_for_pause_time(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    // If not the first young gen collection after a cms collection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    // don't do anything.  In this case an adjustment has already
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    // been made and the results of the adjustment has not yet been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    // measured.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  } else if ((minor_gc_cost() >= 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
             (adjusted_mutator_cost() < _throughput_goal)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    desired_eden_size = adjust_eden_for_throughput(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    desired_eden_size = adjust_eden_for_footprint(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  if (PrintGC && PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    gclog_or_tty->print_cr(
17842
0d11fa49f81f 8007762: Rename a bunch of methods in size policy across collectors
tamao
parents: 13925
diff changeset
  1016
      "CMSAdaptiveSizePolicy::compute_eden_space_size limits:"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
      " desired_eden_size: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
      " old_eden_size: " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
      desired_eden_size, cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  set_eden_size(desired_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
size_t CMSAdaptiveSizePolicy::adjust_promo_for_pause_time(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  size_t change = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  size_t desired_promo = cur_promo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  // Move this test up to caller like the adjust_eden_for_pause_time()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  // call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  if ((AdaptiveSizePausePolicy == 0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
      ((avg_remark_pause()->padded_average() > gc_pause_goal_sec()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
      (avg_initial_pause()->padded_average() > gc_pause_goal_sec()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    set_change_old_gen_for_maj_pauses(decrease_old_gen_for_maj_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    change = promo_decrement_aligned_down(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    desired_promo = cur_promo - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  } else if ((AdaptiveSizePausePolicy > 0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
      (((avg_remark_pause()->padded_average() > gc_pause_goal_sec()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
       remark_pause_old_estimator()->decrement_will_decrease()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
      ((avg_initial_pause()->padded_average() > gc_pause_goal_sec()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
       initial_pause_old_estimator()->decrement_will_decrease()))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    set_change_old_gen_for_maj_pauses(decrease_old_gen_for_maj_pauses_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    change = promo_decrement_aligned_down(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    desired_promo = cur_promo - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  if ((change != 0) &&PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
      "CMSAdaptiveSizePolicy::adjust_promo_for_pause_time "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
      "adjusting promo for pause time. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
      " starting promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
      " reduced promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
      " promo delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
      cur_promo, desired_promo, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  return desired_promo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
// Try to share this with PS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
size_t CMSAdaptiveSizePolicy::scale_by_gen_gc_cost(size_t base_change,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
                                                  double gen_gc_cost) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  // Calculate the change to use for the tenured gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  size_t scaled_change = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  // Can the increment to the generation be scaled?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  if (gc_cost() >= 0.0 && gen_gc_cost >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
    double scale_by_ratio = gen_gc_cost / gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    scaled_change =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      (size_t) (scale_by_ratio * (double) base_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
      gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
        "Scaled tenured increment: " SIZE_FORMAT " by %f down to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
          SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
        base_change, scale_by_ratio, scaled_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  } else if (gen_gc_cost >= 0.0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    // Scaling is not going to work.  If the major gc time is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    // larger than the other GC costs, give it a full increment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    if (gen_gc_cost >= (gc_cost() - gen_gc_cost)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
      scaled_change = base_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    // Don't expect to get here but it's ok if it does
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
    // in the product build since the delta will be 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    // and nothing will change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    assert(false, "Unexpected value for gc costs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  return scaled_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
size_t CMSAdaptiveSizePolicy::adjust_promo_for_throughput(size_t cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  size_t desired_promo = cur_promo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  set_change_old_gen_for_throughput(increase_old_gen_for_throughput_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  size_t change = promo_increment_aligned_up(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  size_t scaled_change = scale_by_gen_gc_cost(change, major_gc_cost());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  if (cur_promo + scaled_change > cur_promo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    desired_promo = cur_promo + scaled_change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  _old_gen_change_for_major_throughput++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
      "CMSAdaptiveSizePolicy::adjust_promo_for_throughput "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
      "adjusting promo for throughput. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
      " starting promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
      " increased promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
      " promo delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
      cur_promo, desired_promo, scaled_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  return desired_promo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
size_t CMSAdaptiveSizePolicy::adjust_promo_for_footprint(size_t cur_promo,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
                                                         size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  set_decrease_for_footprint(decrease_young_gen_for_footprint_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  size_t change = promo_decrement(cur_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  size_t desired_promo_size = cur_promo - change;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
      "CMSAdaptiveSizePolicy::adjust_promo_for_footprint "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
      "adjusting promo for footprint. "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      " starting promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
      " reduced promo size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      " promo delta " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      cur_promo, desired_promo_size, change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  return desired_promo_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
void CMSAdaptiveSizePolicy::compute_tenured_generation_free_space(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
                                size_t cur_tenured_free,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
                                size_t max_tenured_available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
                                size_t cur_eden) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  // This can be bad if the desired value grows/shrinks without
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  // any connection to the read free space
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  size_t desired_promo_size = promo_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  size_t tenured_limit = max_tenured_available;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
  // Printout input
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
  if (PrintGC && PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      "CMSAdaptiveSizePolicy::compute_tenured_generation_free_space: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      "cur_tenured_free " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      " max_tenured_available " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
      cur_tenured_free, max_tenured_available);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  // Used for diagnostics
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  clear_generation_free_space_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
  set_decide_at_full_gc(decide_at_full_gc_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  if (avg_remark_pause()->padded_average() > gc_pause_goal_sec() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
      avg_initial_pause()->padded_average() > gc_pause_goal_sec()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
    desired_promo_size = adjust_promo_for_pause_time(cur_tenured_free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  } else if (avg_minor_pause()->padded_average() > gc_pause_goal_sec()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    // Nothing to do since the minor collections are too large and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    // this method only deals with the cms generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  } else if ((cms_gc_cost() >= 0.0) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
             (adjusted_mutator_cost() < _throughput_goal)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
    desired_promo_size = adjust_promo_for_throughput(cur_tenured_free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    desired_promo_size = adjust_promo_for_footprint(cur_tenured_free,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
                                                    cur_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  if (PrintGC && PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
    gclog_or_tty->print_cr(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
      "CMSAdaptiveSizePolicy::compute_tenured_generation_free_space limits:"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
      " desired_promo_size: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
      " old_promo_size: " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
      desired_promo_size, cur_tenured_free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  set_promo_size(desired_promo_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
13925
37f75ba502b1 8000351: Tenuring threshold should be unsigned
jwilhelm
parents: 10565
diff changeset
  1187
uint CMSAdaptiveSizePolicy::compute_survivor_space_size_and_threshold(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
                                             bool is_survivor_overflow,
13925
37f75ba502b1 8000351: Tenuring threshold should be unsigned
jwilhelm
parents: 10565
diff changeset
  1189
                                             uint tenuring_threshold,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
                                             size_t survivor_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  assert(survivor_limit >= generation_alignment(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
         "survivor_limit too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  assert((size_t)align_size_down(survivor_limit, generation_alignment())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
         == survivor_limit, "survivor_limit not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  // Change UsePSAdaptiveSurvivorSizePolicy -> UseAdaptiveSurvivorSizePolicy?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  if (!UsePSAdaptiveSurvivorSizePolicy ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
      !young_gen_policy_is_ready()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    return tenuring_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  // We'll decide whether to increase or decrease the tenuring
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  // threshold based partly on the newly computed survivor size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  // (if we hit the maximum limit allowed, we'll always choose to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  // decrement the threshold).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  bool incr_tenuring_threshold = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
  bool decr_tenuring_threshold = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
  set_decrement_tenuring_threshold_for_gc_cost(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
  set_increment_tenuring_threshold_for_gc_cost(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  set_decrement_tenuring_threshold_for_survivor_limit(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
  if (!is_survivor_overflow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    // Keep running averages on how much survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    // We use the tenuring threshold to equalize the cost of major
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    // and minor collections.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    // ThresholdTolerance is used to indicate how sensitive the
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 17842
diff changeset
  1219
    // tenuring threshold is to differences in cost between the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    // collection types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    // Get the times of interest. This involves a little work, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    // we cache the values here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    const double major_cost = major_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    const double minor_cost = minor_gc_cost();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    if (minor_cost > major_cost * _threshold_tolerance_percent) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
      // Minor times are getting too long;  lower the threshold so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
      // less survives and more is promoted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
      decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
      set_decrement_tenuring_threshold_for_gc_cost(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    } else if (major_cost > minor_cost * _threshold_tolerance_percent) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
      // Major times are too long, so we want less promotion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
      incr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
      set_increment_tenuring_threshold_for_gc_cost(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    // Survivor space overflow occurred, so promoted and survived are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
    // not accurate. We'll make our best guess by combining survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    // and promoted and count them as survivors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    // We'll lower the tenuring threshold to see if we can correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    // things. Also, set the survivor size conservatively. We're
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    // trying to avoid many overflows from occurring if defnew size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    // is just too small.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  // The padded average also maintains a deviation from the average;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  // we use this to see how good of an estimate we have of what survived.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  // We're trying to pad the survivor size as little as possible without
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  // overflowing the survivor spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  size_t target_size = align_size_up((size_t)_avg_survived->padded_average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
                                     generation_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  target_size = MAX2(target_size, generation_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  if (target_size > survivor_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    // Target size is bigger than we can handle. Let's also reduce
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    // the tenuring threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    target_size = survivor_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    decr_tenuring_threshold = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    set_decrement_tenuring_threshold_for_survivor_limit(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  // Finally, increment or decrement the tenuring threshold, as decided above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  // We test for decrementing first, as we might have hit the target size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
  // limit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  if (decr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    if (tenuring_threshold > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
      tenuring_threshold--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  } else if (incr_tenuring_threshold && !(AlwaysTenure || NeverTenure)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    if (tenuring_threshold < MaxTenuringThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
      tenuring_threshold++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
  // We keep a running average of the amount promoted which is used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
  // to decide when we should collect the old generation (when
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  // the amount of old gen free space is less than what we expect to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
  // promote).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    // A little more detail if Verbose is on
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    if (Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
      gclog_or_tty->print( "  avg_survived: %f"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
                  "  avg_deviation: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
                  _avg_survived->average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
                  _avg_survived->deviation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    gclog_or_tty->print( "  avg_survived_padded_avg: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
                _avg_survived->padded_average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
    if (Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
      gclog_or_tty->print( "  avg_promoted_avg: %f"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
                  "  avg_promoted_dev: %f",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
                  gch->gc_stats(1)->avg_promoted()->average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
                  gch->gc_stats(1)->avg_promoted()->deviation());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    gclog_or_tty->print( "  avg_promoted_padded_avg: %f"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
                "  avg_pretenured_padded_avg: %f"
13925
37f75ba502b1 8000351: Tenuring threshold should be unsigned
jwilhelm
parents: 10565
diff changeset
  1307
                "  tenuring_thresh: %u"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
                "  target_size: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
                "  survivor_limit: " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
                gch->gc_stats(1)->avg_promoted()->padded_average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
                _avg_pretenured->padded_average(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
                tenuring_threshold, target_size, survivor_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    gclog_or_tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  set_survivor_size(target_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  return tenuring_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
bool CMSAdaptiveSizePolicy::get_and_clear_first_after_collection() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  bool result = _first_after_collection;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  _first_after_collection = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
bool CMSAdaptiveSizePolicy::print_adaptive_size_policy_on(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
                                                    outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
24941
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1330
  if (!UseAdaptiveSizePolicy) {
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1331
    return false;
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1332
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  GenCollectedHeap* gch = GenCollectedHeap::heap();
24941
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1335
  Generation* young = gch->get_gen(0);
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1336
  DefNewGeneration* def_new = young->as_DefNewGeneration();
4ebbe176a7b1 8042298: Remove the names gen0 and gen1 from the GC code
jwilhelm
parents: 22876
diff changeset
  1337
  return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
                                         st,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
                                         def_new->tenuring_threshold());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
}