src/share/vm/memory/allocationStats.hpp

changeset 435
a61af66fc99e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/allocationStats.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,136 @@
     1.4 +/*
     1.5 + * Copyright 2001-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +class AllocationStats VALUE_OBJ_CLASS_SPEC {
    1.29 +  // A duration threshold (in ms) used to filter
    1.30 +  // possibly unreliable samples.
    1.31 +  static float _threshold;
    1.32 +
    1.33 +  // We measure the demand between the end of the previous sweep and
    1.34 +  // beginning of this sweep:
    1.35 +  //   Count(end_last_sweep) - Count(start_this_sweep)
    1.36 +  //     + splitBirths(between) - splitDeaths(between)
    1.37 +  // The above number divided by the time since the start [END???] of the
    1.38 +  // previous sweep gives us a time rate of demand for blocks
    1.39 +  // of this size. We compute a padded average of this rate as
    1.40 +  // our current estimate for the time rate of demand for blocks
    1.41 +  // of this size. Similarly, we keep a padded average for the time
    1.42 +  // between sweeps. Our current estimate for demand for blocks of
    1.43 +  // this size is then simply computed as the product of these two
    1.44 +  // estimates.
    1.45 +  AdaptivePaddedAverage _demand_rate_estimate;
    1.46 +
    1.47 +  ssize_t     _desired;          // Estimate computed as described above
    1.48 +  ssize_t     _coalDesired;     // desired +/- small-percent for tuning coalescing
    1.49 +
    1.50 +  ssize_t     _surplus;         // count - (desired +/- small-percent),
    1.51 +                                // used to tune splitting in best fit
    1.52 +  ssize_t     _bfrSurp;         // surplus at start of current sweep
    1.53 +  ssize_t     _prevSweep;       // count from end of previous sweep
    1.54 +  ssize_t     _beforeSweep;     // count from before current sweep
    1.55 +  ssize_t     _coalBirths;      // additional chunks from coalescing
    1.56 +  ssize_t     _coalDeaths;      // loss from coalescing
    1.57 +  ssize_t     _splitBirths;     // additional chunks from splitting
    1.58 +  ssize_t     _splitDeaths;     // loss from splitting
    1.59 +  size_t     _returnedBytes;    // number of bytes returned to list.
    1.60 + public:
    1.61 +  void initialize() {
    1.62 +    AdaptivePaddedAverage* dummy =
    1.63 +      new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,
    1.64 +                                                         CMS_FLSPadding);
    1.65 +    _desired = 0;
    1.66 +    _coalDesired = 0;
    1.67 +    _surplus = 0;
    1.68 +    _bfrSurp = 0;
    1.69 +    _prevSweep = 0;
    1.70 +    _beforeSweep = 0;
    1.71 +    _coalBirths = 0;
    1.72 +    _coalDeaths = 0;
    1.73 +    _splitBirths = 0;
    1.74 +    _splitDeaths = 0;
    1.75 +    _returnedBytes = 0;
    1.76 +  }
    1.77 +
    1.78 +  AllocationStats() {
    1.79 +    initialize();
    1.80 +  }
    1.81 +  // The rate estimate is in blocks per second.
    1.82 +  void compute_desired(size_t count,
    1.83 +                       float inter_sweep_current,
    1.84 +                       float inter_sweep_estimate) {
    1.85 +    // If the latest inter-sweep time is below our granularity
    1.86 +    // of measurement, we may call in here with
    1.87 +    // inter_sweep_current == 0. However, even for suitably small
    1.88 +    // but non-zero inter-sweep durations, we may not trust the accuracy
    1.89 +    // of accumulated data, since it has not been "integrated"
    1.90 +    // (read "low-pass-filtered") long enough, and would be
    1.91 +    // vulnerable to noisy glitches. In such cases, we
    1.92 +    // ignore the current sample and use currently available
    1.93 +    // historical estimates.
    1.94 +    if (inter_sweep_current > _threshold) {
    1.95 +      ssize_t demand = prevSweep() - count + splitBirths() - splitDeaths();
    1.96 +      float rate = ((float)demand)/inter_sweep_current;
    1.97 +      _demand_rate_estimate.sample(rate);
    1.98 +      _desired = (ssize_t)(_demand_rate_estimate.padded_average()
    1.99 +                           *inter_sweep_estimate);
   1.100 +    }
   1.101 +  }
   1.102 +
   1.103 +  ssize_t desired() const { return _desired; }
   1.104 +  ssize_t coalDesired() const { return _coalDesired; }
   1.105 +  void set_coalDesired(ssize_t v) { _coalDesired = v; }
   1.106 +
   1.107 +  ssize_t surplus() const { return _surplus; }
   1.108 +  void set_surplus(ssize_t v) { _surplus = v; }
   1.109 +  void increment_surplus() { _surplus++; }
   1.110 +  void decrement_surplus() { _surplus--; }
   1.111 +
   1.112 +  ssize_t bfrSurp() const { return _bfrSurp; }
   1.113 +  void set_bfrSurp(ssize_t v) { _bfrSurp = v; }
   1.114 +  ssize_t prevSweep() const { return _prevSweep; }
   1.115 +  void set_prevSweep(ssize_t v) { _prevSweep = v; }
   1.116 +  ssize_t beforeSweep() const { return _beforeSweep; }
   1.117 +  void set_beforeSweep(ssize_t v) { _beforeSweep = v; }
   1.118 +
   1.119 +  ssize_t coalBirths() const { return _coalBirths; }
   1.120 +  void set_coalBirths(ssize_t v) { _coalBirths = v; }
   1.121 +  void increment_coalBirths() { _coalBirths++; }
   1.122 +
   1.123 +  ssize_t coalDeaths() const { return _coalDeaths; }
   1.124 +  void set_coalDeaths(ssize_t v) { _coalDeaths = v; }
   1.125 +  void increment_coalDeaths() { _coalDeaths++; }
   1.126 +
   1.127 +  ssize_t splitBirths() const { return _splitBirths; }
   1.128 +  void set_splitBirths(ssize_t v) { _splitBirths = v; }
   1.129 +  void increment_splitBirths() { _splitBirths++; }
   1.130 +
   1.131 +  ssize_t splitDeaths() const { return _splitDeaths; }
   1.132 +  void set_splitDeaths(ssize_t v) { _splitDeaths = v; }
   1.133 +  void increment_splitDeaths() { _splitDeaths++; }
   1.134 +
   1.135 +  NOT_PRODUCT(
   1.136 +    size_t returnedBytes() const { return _returnedBytes; }
   1.137 +    void set_returnedBytes(size_t v) { _returnedBytes = v; }
   1.138 +  )
   1.139 +};

mercurial