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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP
aoqi@0 27
aoqi@0 28 #include "utilities/macros.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "utilities/globalDefinitions.hpp"
aoqi@0 31 #include "gc_implementation/shared/gcUtil.hpp"
aoqi@0 32
aoqi@0 33 class AllocationStats VALUE_OBJ_CLASS_SPEC {
aoqi@0 34 // A duration threshold (in ms) used to filter
aoqi@0 35 // possibly unreliable samples.
aoqi@0 36 static float _threshold;
aoqi@0 37
aoqi@0 38 // We measure the demand between the end of the previous sweep and
aoqi@0 39 // beginning of this sweep:
aoqi@0 40 // Count(end_last_sweep) - Count(start_this_sweep)
aoqi@0 41 // + split_births(between) - split_deaths(between)
aoqi@0 42 // The above number divided by the time since the end of the
aoqi@0 43 // previous sweep gives us a time rate of demand for blocks
aoqi@0 44 // of this size. We compute a padded average of this rate as
aoqi@0 45 // our current estimate for the time rate of demand for blocks
aoqi@0 46 // of this size. Similarly, we keep a padded average for the time
aoqi@0 47 // between sweeps. Our current estimate for demand for blocks of
aoqi@0 48 // this size is then simply computed as the product of these two
aoqi@0 49 // estimates.
aoqi@0 50 AdaptivePaddedAverage _demand_rate_estimate;
aoqi@0 51
aoqi@0 52 ssize_t _desired; // Demand stimate computed as described above
aoqi@0 53 ssize_t _coal_desired; // desired +/- small-percent for tuning coalescing
aoqi@0 54
aoqi@0 55 ssize_t _surplus; // count - (desired +/- small-percent),
aoqi@0 56 // used to tune splitting in best fit
aoqi@0 57 ssize_t _bfr_surp; // surplus at start of current sweep
aoqi@0 58 ssize_t _prev_sweep; // count from end of previous sweep
aoqi@0 59 ssize_t _before_sweep; // count from before current sweep
aoqi@0 60 ssize_t _coal_births; // additional chunks from coalescing
aoqi@0 61 ssize_t _coal_deaths; // loss from coalescing
aoqi@0 62 ssize_t _split_births; // additional chunks from splitting
aoqi@0 63 ssize_t _split_deaths; // loss from splitting
aoqi@0 64 size_t _returned_bytes; // number of bytes returned to list.
aoqi@0 65 public:
aoqi@0 66 void initialize(bool split_birth = false) {
aoqi@0 67 AdaptivePaddedAverage* dummy =
aoqi@0 68 new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,
aoqi@0 69 CMS_FLSPadding);
aoqi@0 70 _desired = 0;
aoqi@0 71 _coal_desired = 0;
aoqi@0 72 _surplus = 0;
aoqi@0 73 _bfr_surp = 0;
aoqi@0 74 _prev_sweep = 0;
aoqi@0 75 _before_sweep = 0;
aoqi@0 76 _coal_births = 0;
aoqi@0 77 _coal_deaths = 0;
aoqi@0 78 _split_births = (split_birth ? 1 : 0);
aoqi@0 79 _split_deaths = 0;
aoqi@0 80 _returned_bytes = 0;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 AllocationStats() {
aoqi@0 84 initialize();
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 // The rate estimate is in blocks per second.
aoqi@0 88 void compute_desired(size_t count,
aoqi@0 89 float inter_sweep_current,
aoqi@0 90 float inter_sweep_estimate,
aoqi@0 91 float intra_sweep_estimate) {
aoqi@0 92 // If the latest inter-sweep time is below our granularity
aoqi@0 93 // of measurement, we may call in here with
aoqi@0 94 // inter_sweep_current == 0. However, even for suitably small
aoqi@0 95 // but non-zero inter-sweep durations, we may not trust the accuracy
aoqi@0 96 // of accumulated data, since it has not been "integrated"
aoqi@0 97 // (read "low-pass-filtered") long enough, and would be
aoqi@0 98 // vulnerable to noisy glitches. In such cases, we
aoqi@0 99 // ignore the current sample and use currently available
aoqi@0 100 // historical estimates.
aoqi@0 101 assert(prev_sweep() + split_births() + coal_births() // "Total Production Stock"
aoqi@0 102 >= split_deaths() + coal_deaths() + (ssize_t)count, // "Current stock + depletion"
aoqi@0 103 "Conservation Principle");
aoqi@0 104 if (inter_sweep_current > _threshold) {
aoqi@0 105 ssize_t demand = prev_sweep() - (ssize_t)count + split_births() + coal_births()
aoqi@0 106 - split_deaths() - coal_deaths();
aoqi@0 107 assert(demand >= 0,
aoqi@0 108 err_msg("Demand (" SSIZE_FORMAT ") should be non-negative for "
aoqi@0 109 PTR_FORMAT " (size=" SIZE_FORMAT ")",
aoqi@0 110 demand, p2i(this), count));
aoqi@0 111 // Defensive: adjust for imprecision in event counting
aoqi@0 112 if (demand < 0) {
aoqi@0 113 demand = 0;
aoqi@0 114 }
aoqi@0 115 float old_rate = _demand_rate_estimate.padded_average();
aoqi@0 116 float rate = ((float)demand)/inter_sweep_current;
aoqi@0 117 _demand_rate_estimate.sample(rate);
aoqi@0 118 float new_rate = _demand_rate_estimate.padded_average();
aoqi@0 119 ssize_t old_desired = _desired;
aoqi@0 120 float delta_ise = (CMSExtrapolateSweep ? intra_sweep_estimate : 0.0);
aoqi@0 121 _desired = (ssize_t)(new_rate * (inter_sweep_estimate + delta_ise));
aoqi@0 122 if (PrintFLSStatistics > 1) {
aoqi@0 123 gclog_or_tty->print_cr(
aoqi@0 124 "demand: " SSIZE_FORMAT ", old_rate: %f, current_rate: %f, new_rate: %f, old_desired: " SSIZE_FORMAT ", new_desired: " SSIZE_FORMAT,
aoqi@0 125 demand, old_rate, rate, new_rate, old_desired, _desired);
aoqi@0 126 }
aoqi@0 127 }
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 ssize_t desired() const { return _desired; }
aoqi@0 131 void set_desired(ssize_t v) { _desired = v; }
aoqi@0 132
aoqi@0 133 ssize_t coal_desired() const { return _coal_desired; }
aoqi@0 134 void set_coal_desired(ssize_t v) { _coal_desired = v; }
aoqi@0 135
aoqi@0 136 ssize_t surplus() const { return _surplus; }
aoqi@0 137 void set_surplus(ssize_t v) { _surplus = v; }
aoqi@0 138 void increment_surplus() { _surplus++; }
aoqi@0 139 void decrement_surplus() { _surplus--; }
aoqi@0 140
aoqi@0 141 ssize_t bfr_surp() const { return _bfr_surp; }
aoqi@0 142 void set_bfr_surp(ssize_t v) { _bfr_surp = v; }
aoqi@0 143 ssize_t prev_sweep() const { return _prev_sweep; }
aoqi@0 144 void set_prev_sweep(ssize_t v) { _prev_sweep = v; }
aoqi@0 145 ssize_t before_sweep() const { return _before_sweep; }
aoqi@0 146 void set_before_sweep(ssize_t v) { _before_sweep = v; }
aoqi@0 147
aoqi@0 148 ssize_t coal_births() const { return _coal_births; }
aoqi@0 149 void set_coal_births(ssize_t v) { _coal_births = v; }
aoqi@0 150 void increment_coal_births() { _coal_births++; }
aoqi@0 151
aoqi@0 152 ssize_t coal_deaths() const { return _coal_deaths; }
aoqi@0 153 void set_coal_deaths(ssize_t v) { _coal_deaths = v; }
aoqi@0 154 void increment_coal_deaths() { _coal_deaths++; }
aoqi@0 155
aoqi@0 156 ssize_t split_births() const { return _split_births; }
aoqi@0 157 void set_split_births(ssize_t v) { _split_births = v; }
aoqi@0 158 void increment_split_births() { _split_births++; }
aoqi@0 159
aoqi@0 160 ssize_t split_deaths() const { return _split_deaths; }
aoqi@0 161 void set_split_deaths(ssize_t v) { _split_deaths = v; }
aoqi@0 162 void increment_split_deaths() { _split_deaths++; }
aoqi@0 163
aoqi@0 164 NOT_PRODUCT(
aoqi@0 165 size_t returned_bytes() const { return _returned_bytes; }
aoqi@0 166 void set_returned_bytes(size_t v) { _returned_bytes = v; }
aoqi@0 167 )
aoqi@0 168 };
aoqi@0 169
aoqi@0 170 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP

mercurial