src/share/vm/gc_implementation/shared/allocationStats.hpp

Tue, 13 Apr 2010 13:52:10 -0700

author
jmasa
date
Tue, 13 Apr 2010 13:52:10 -0700
changeset 1822
0bfd3fb24150
parent 1580
e018e6884bd8
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes

duke@435 1 /*
xdono@631 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class AllocationStats VALUE_OBJ_CLASS_SPEC {
duke@435 26 // A duration threshold (in ms) used to filter
duke@435 27 // possibly unreliable samples.
duke@435 28 static float _threshold;
duke@435 29
duke@435 30 // We measure the demand between the end of the previous sweep and
duke@435 31 // beginning of this sweep:
duke@435 32 // Count(end_last_sweep) - Count(start_this_sweep)
duke@435 33 // + splitBirths(between) - splitDeaths(between)
ysr@1580 34 // The above number divided by the time since the end of the
duke@435 35 // previous sweep gives us a time rate of demand for blocks
duke@435 36 // of this size. We compute a padded average of this rate as
duke@435 37 // our current estimate for the time rate of demand for blocks
duke@435 38 // of this size. Similarly, we keep a padded average for the time
duke@435 39 // between sweeps. Our current estimate for demand for blocks of
duke@435 40 // this size is then simply computed as the product of these two
duke@435 41 // estimates.
duke@435 42 AdaptivePaddedAverage _demand_rate_estimate;
duke@435 43
ysr@1580 44 ssize_t _desired; // Demand stimate computed as described above
duke@435 45 ssize_t _coalDesired; // desired +/- small-percent for tuning coalescing
duke@435 46
duke@435 47 ssize_t _surplus; // count - (desired +/- small-percent),
duke@435 48 // used to tune splitting in best fit
duke@435 49 ssize_t _bfrSurp; // surplus at start of current sweep
duke@435 50 ssize_t _prevSweep; // count from end of previous sweep
duke@435 51 ssize_t _beforeSweep; // count from before current sweep
duke@435 52 ssize_t _coalBirths; // additional chunks from coalescing
duke@435 53 ssize_t _coalDeaths; // loss from coalescing
duke@435 54 ssize_t _splitBirths; // additional chunks from splitting
duke@435 55 ssize_t _splitDeaths; // loss from splitting
ysr@1580 56 size_t _returnedBytes; // number of bytes returned to list.
duke@435 57 public:
ysr@1580 58 void initialize(bool split_birth = false) {
duke@435 59 AdaptivePaddedAverage* dummy =
duke@435 60 new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,
duke@435 61 CMS_FLSPadding);
duke@435 62 _desired = 0;
duke@435 63 _coalDesired = 0;
duke@435 64 _surplus = 0;
duke@435 65 _bfrSurp = 0;
duke@435 66 _prevSweep = 0;
duke@435 67 _beforeSweep = 0;
duke@435 68 _coalBirths = 0;
duke@435 69 _coalDeaths = 0;
ysr@1580 70 _splitBirths = split_birth? 1 : 0;
duke@435 71 _splitDeaths = 0;
duke@435 72 _returnedBytes = 0;
duke@435 73 }
duke@435 74
duke@435 75 AllocationStats() {
duke@435 76 initialize();
duke@435 77 }
ysr@1580 78
duke@435 79 // The rate estimate is in blocks per second.
duke@435 80 void compute_desired(size_t count,
duke@435 81 float inter_sweep_current,
ysr@1580 82 float inter_sweep_estimate,
ysr@1580 83 float intra_sweep_estimate) {
duke@435 84 // If the latest inter-sweep time is below our granularity
duke@435 85 // of measurement, we may call in here with
duke@435 86 // inter_sweep_current == 0. However, even for suitably small
duke@435 87 // but non-zero inter-sweep durations, we may not trust the accuracy
duke@435 88 // of accumulated data, since it has not been "integrated"
duke@435 89 // (read "low-pass-filtered") long enough, and would be
duke@435 90 // vulnerable to noisy glitches. In such cases, we
duke@435 91 // ignore the current sample and use currently available
duke@435 92 // historical estimates.
ysr@1580 93 // XXX NEEDS TO BE FIXED
ysr@1580 94 // assert(prevSweep() + splitBirths() >= splitDeaths() + (ssize_t)count, "Conservation Principle");
ysr@1580 95 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ysr@1580 96 // "Total Stock" "Not used at this block size"
duke@435 97 if (inter_sweep_current > _threshold) {
ysr@1580 98 ssize_t demand = prevSweep() - (ssize_t)count + splitBirths() - splitDeaths();
ysr@1580 99 // XXX NEEDS TO BE FIXED
ysr@1580 100 // assert(demand >= 0, "Demand should be non-negative");
ysr@1580 101 // Defensive: adjust for imprecision in event counting
ysr@1580 102 if (demand < 0) {
ysr@1580 103 demand = 0;
ysr@1580 104 }
ysr@1580 105 float old_rate = _demand_rate_estimate.padded_average();
duke@435 106 float rate = ((float)demand)/inter_sweep_current;
duke@435 107 _demand_rate_estimate.sample(rate);
ysr@1580 108 float new_rate = _demand_rate_estimate.padded_average();
ysr@1580 109 ssize_t old_desired = _desired;
ysr@1580 110 _desired = (ssize_t)(new_rate * (inter_sweep_estimate
ysr@1580 111 + CMSExtrapolateSweep
ysr@1580 112 ? intra_sweep_estimate
ysr@1580 113 : 0.0));
ysr@1580 114 if (PrintFLSStatistics > 1) {
ysr@1580 115 gclog_or_tty->print_cr("demand: %d, old_rate: %f, current_rate: %f, new_rate: %f, old_desired: %d, new_desired: %d",
ysr@1580 116 demand, old_rate, rate, new_rate, old_desired, _desired);
ysr@1580 117 }
duke@435 118 }
duke@435 119 }
duke@435 120
duke@435 121 ssize_t desired() const { return _desired; }
ysr@447 122 void set_desired(ssize_t v) { _desired = v; }
ysr@447 123
duke@435 124 ssize_t coalDesired() const { return _coalDesired; }
duke@435 125 void set_coalDesired(ssize_t v) { _coalDesired = v; }
duke@435 126
duke@435 127 ssize_t surplus() const { return _surplus; }
duke@435 128 void set_surplus(ssize_t v) { _surplus = v; }
duke@435 129 void increment_surplus() { _surplus++; }
duke@435 130 void decrement_surplus() { _surplus--; }
duke@435 131
duke@435 132 ssize_t bfrSurp() const { return _bfrSurp; }
duke@435 133 void set_bfrSurp(ssize_t v) { _bfrSurp = v; }
duke@435 134 ssize_t prevSweep() const { return _prevSweep; }
duke@435 135 void set_prevSweep(ssize_t v) { _prevSweep = v; }
duke@435 136 ssize_t beforeSweep() const { return _beforeSweep; }
duke@435 137 void set_beforeSweep(ssize_t v) { _beforeSweep = v; }
duke@435 138
duke@435 139 ssize_t coalBirths() const { return _coalBirths; }
duke@435 140 void set_coalBirths(ssize_t v) { _coalBirths = v; }
duke@435 141 void increment_coalBirths() { _coalBirths++; }
duke@435 142
duke@435 143 ssize_t coalDeaths() const { return _coalDeaths; }
duke@435 144 void set_coalDeaths(ssize_t v) { _coalDeaths = v; }
duke@435 145 void increment_coalDeaths() { _coalDeaths++; }
duke@435 146
duke@435 147 ssize_t splitBirths() const { return _splitBirths; }
duke@435 148 void set_splitBirths(ssize_t v) { _splitBirths = v; }
duke@435 149 void increment_splitBirths() { _splitBirths++; }
duke@435 150
duke@435 151 ssize_t splitDeaths() const { return _splitDeaths; }
duke@435 152 void set_splitDeaths(ssize_t v) { _splitDeaths = v; }
duke@435 153 void increment_splitDeaths() { _splitDeaths++; }
duke@435 154
duke@435 155 NOT_PRODUCT(
duke@435 156 size_t returnedBytes() const { return _returnedBytes; }
duke@435 157 void set_returnedBytes(size_t v) { _returnedBytes = v; }
duke@435 158 )
duke@435 159 };

mercurial