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