hotspot/src/share/vm/gc_implementation/shared/allocationStats.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 4574 b2d5b0975515
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
diff changeset
     2
 * Copyright (c) 2001, 2008, 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: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
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: 4574
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class AllocationStats VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
  // A duration threshold (in ms) used to filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  // possibly unreliable samples.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  static float _threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // We measure the demand between the end of the previous sweep and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  // beginning of this sweep:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  //   Count(end_last_sweep) - Count(start_this_sweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  //     + splitBirths(between) - splitDeaths(between)
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    34
  // The above number divided by the time since the end of the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // previous sweep gives us a time rate of demand for blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // of this size. We compute a padded average of this rate as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // our current estimate for the time rate of demand for blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // of this size. Similarly, we keep a padded average for the time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // between sweeps. Our current estimate for demand for blocks of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // this size is then simply computed as the product of these two
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // estimates.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  AdaptivePaddedAverage _demand_rate_estimate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    44
  ssize_t     _desired;         // Demand stimate computed as described above
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ssize_t     _coalDesired;     // desired +/- small-percent for tuning coalescing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  ssize_t     _surplus;         // count - (desired +/- small-percent),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                                // used to tune splitting in best fit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  ssize_t     _bfrSurp;         // surplus at start of current sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  ssize_t     _prevSweep;       // count from end of previous sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ssize_t     _beforeSweep;     // count from before current sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  ssize_t     _coalBirths;      // additional chunks from coalescing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  ssize_t     _coalDeaths;      // loss from coalescing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  ssize_t     _splitBirths;     // additional chunks from splitting
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  ssize_t     _splitDeaths;     // loss from splitting
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    56
  size_t      _returnedBytes;   // number of bytes returned to list.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    58
  void initialize(bool split_birth = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    AdaptivePaddedAverage* dummy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
                                                         CMS_FLSPadding);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _desired = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _coalDesired = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    _surplus = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _bfrSurp = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _prevSweep = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    _beforeSweep = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    _coalBirths = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    _coalDeaths = 0;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    70
    _splitBirths = split_birth? 1 : 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    _splitDeaths = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _returnedBytes = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  AllocationStats() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    78
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // The rate estimate is in blocks per second.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void compute_desired(size_t count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                       float inter_sweep_current,
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    82
                       float inter_sweep_estimate,
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    83
                       float intra_sweep_estimate) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // If the latest inter-sweep time is below our granularity
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // of measurement, we may call in here with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    // inter_sweep_current == 0. However, even for suitably small
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // but non-zero inter-sweep durations, we may not trust the accuracy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    // of accumulated data, since it has not been "integrated"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // (read "low-pass-filtered") long enough, and would be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // vulnerable to noisy glitches. In such cases, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    // ignore the current sample and use currently available
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // historical estimates.
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    93
    // XXX NEEDS TO BE FIXED
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    94
    // assert(prevSweep() + splitBirths() >= splitDeaths() + (ssize_t)count, "Conservation Principle");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    95
    //     ^^^^^^^^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    96
    //     "Total Stock"                  "Not used at this block size"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (inter_sweep_current > _threshold) {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    98
      ssize_t demand = prevSweep() - (ssize_t)count + splitBirths() - splitDeaths();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    99
      // XXX NEEDS TO BE FIXED
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   100
      // assert(demand >= 0, "Demand should be non-negative");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   101
      // Defensive: adjust for imprecision in event counting
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   102
      if (demand < 0) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   103
        demand = 0;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   104
      }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   105
      float old_rate = _demand_rate_estimate.padded_average();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      float rate = ((float)demand)/inter_sweep_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      _demand_rate_estimate.sample(rate);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   108
      float new_rate = _demand_rate_estimate.padded_average();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   109
      ssize_t old_desired = _desired;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   110
      _desired = (ssize_t)(new_rate * (inter_sweep_estimate
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   111
                                       + CMSExtrapolateSweep
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   112
                                         ? intra_sweep_estimate
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   113
                                         : 0.0));
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   114
      if (PrintFLSStatistics > 1) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   115
        gclog_or_tty->print_cr("demand: %d, old_rate: %f, current_rate: %f, new_rate: %f, old_desired: %d, new_desired: %d",
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   116
                                demand,     old_rate,     rate,             new_rate,     old_desired,     _desired);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   117
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  ssize_t desired() const { return _desired; }
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   122
  void set_desired(ssize_t v) { _desired = v; }
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   123
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  ssize_t coalDesired() const { return _coalDesired; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  void set_coalDesired(ssize_t v) { _coalDesired = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  ssize_t surplus() const { return _surplus; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void set_surplus(ssize_t v) { _surplus = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  void increment_surplus() { _surplus++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  void decrement_surplus() { _surplus--; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  ssize_t bfrSurp() const { return _bfrSurp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void set_bfrSurp(ssize_t v) { _bfrSurp = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  ssize_t prevSweep() const { return _prevSweep; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  void set_prevSweep(ssize_t v) { _prevSweep = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  ssize_t beforeSweep() const { return _beforeSweep; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  void set_beforeSweep(ssize_t v) { _beforeSweep = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  ssize_t coalBirths() const { return _coalBirths; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void set_coalBirths(ssize_t v) { _coalBirths = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  void increment_coalBirths() { _coalBirths++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  ssize_t coalDeaths() const { return _coalDeaths; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  void set_coalDeaths(ssize_t v) { _coalDeaths = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  void increment_coalDeaths() { _coalDeaths++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  ssize_t splitBirths() const { return _splitBirths; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  void set_splitBirths(ssize_t v) { _splitBirths = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  void increment_splitBirths() { _splitBirths++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  ssize_t splitDeaths() const { return _splitDeaths; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  void set_splitDeaths(ssize_t v) { _splitDeaths = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  void increment_splitDeaths() { _splitDeaths++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    size_t returnedBytes() const { return _returnedBytes; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    void set_returnedBytes(size_t v) { _returnedBytes = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
};