annotate src/share/vm/gc_implementation/shared/allocationStats.hpp @ 3775:f75137faa7fe

6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle") Summary: Fix assert and adjust demand volume computation by adding missing factor. Reviewed-by: jmasa, tonyp
author ysr
date Mon, 20 Jun 2011 09:42:26 -0700
parents c69b1043dfb1
children f69a5d43dc19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2186
diff changeset
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #ifndef SERIALGC
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "gc_implementation/shared/gcUtil.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "utilities/globalDefinitions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 class AllocationStats VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // A duration threshold (in ms) used to filter
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // possibly unreliable samples.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 static float _threshold;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // We measure the demand between the end of the previous sweep and
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // beginning of this sweep:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Count(end_last_sweep) - Count(start_this_sweep)
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // + splitBirths(between) - splitDeaths(between)
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
43 // The above number divided by the time since the end of the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // previous sweep gives us a time rate of demand for blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // of this size. We compute a padded average of this rate as
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // our current estimate for the time rate of demand for blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // of this size. Similarly, we keep a padded average for the time
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // between sweeps. Our current estimate for demand for blocks of
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // this size is then simply computed as the product of these two
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // estimates.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 AdaptivePaddedAverage _demand_rate_estimate;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
53 ssize_t _desired; // Demand stimate computed as described above
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ssize_t _coalDesired; // desired +/- small-percent for tuning coalescing
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 ssize_t _surplus; // count - (desired +/- small-percent),
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // used to tune splitting in best fit
a61af66fc99e Initial load
duke
parents:
diff changeset
58 ssize_t _bfrSurp; // surplus at start of current sweep
a61af66fc99e Initial load
duke
parents:
diff changeset
59 ssize_t _prevSweep; // count from end of previous sweep
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ssize_t _beforeSweep; // count from before current sweep
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ssize_t _coalBirths; // additional chunks from coalescing
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ssize_t _coalDeaths; // loss from coalescing
a61af66fc99e Initial load
duke
parents:
diff changeset
63 ssize_t _splitBirths; // additional chunks from splitting
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ssize_t _splitDeaths; // loss from splitting
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
65 size_t _returnedBytes; // number of bytes returned to list.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public:
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
67 void initialize(bool split_birth = false) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
68 AdaptivePaddedAverage* dummy =
a61af66fc99e Initial load
duke
parents:
diff changeset
69 new (&_demand_rate_estimate) AdaptivePaddedAverage(CMS_FLSWeight,
a61af66fc99e Initial load
duke
parents:
diff changeset
70 CMS_FLSPadding);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _desired = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _coalDesired = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _surplus = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _bfrSurp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _prevSweep = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _beforeSweep = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _coalBirths = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 _coalDeaths = 0;
3256
c69b1043dfb1 7036482: clear argument is redundant and unused in cardtable methods
ysr
parents: 2426
diff changeset
79 _splitBirths = (split_birth ? 1 : 0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _splitDeaths = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _returnedBytes = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 AllocationStats() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
87
0
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // The rate estimate is in blocks per second.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void compute_desired(size_t count,
a61af66fc99e Initial load
duke
parents:
diff changeset
90 float inter_sweep_current,
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
91 float inter_sweep_estimate,
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
92 float intra_sweep_estimate) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // If the latest inter-sweep time is below our granularity
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // of measurement, we may call in here with
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // inter_sweep_current == 0. However, even for suitably small
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // but non-zero inter-sweep durations, we may not trust the accuracy
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // of accumulated data, since it has not been "integrated"
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // (read "low-pass-filtered") long enough, and would be
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // vulnerable to noisy glitches. In such cases, we
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // ignore the current sample and use currently available
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // historical estimates.
3775
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
102 assert(prevSweep() + splitBirths() + coalBirths() // "Total Production Stock"
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
103 >= splitDeaths() + coalDeaths() + (ssize_t)count, // "Current stock + depletion"
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
104 "Conservation Principle");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (inter_sweep_current > _threshold) {
3775
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
106 ssize_t demand = prevSweep() - (ssize_t)count + splitBirths() + coalBirths()
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
107 - splitDeaths() - coalDeaths();
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
108 assert(demand >= 0,
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
109 err_msg("Demand (" SSIZE_FORMAT ") should be non-negative for "
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
110 PTR_FORMAT " (size=" SIZE_FORMAT ")",
f75137faa7fe 6916968: CMS: freeList.cpp:304 assert(_allocation_stats.prevSweep() + ..., "Conservation Principle")
ysr
parents: 3256
diff changeset
111 demand, this, count));
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
112 // Defensive: adjust for imprecision in event counting
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
113 if (demand < 0) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
114 demand = 0;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
115 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
116 float old_rate = _demand_rate_estimate.padded_average();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 float rate = ((float)demand)/inter_sweep_current;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 _demand_rate_estimate.sample(rate);
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
119 float new_rate = _demand_rate_estimate.padded_average();
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
120 ssize_t old_desired = _desired;
2186
e49cfa28f585 6999988: CMS: Increased fragmentation leading to promotion failure after CR#6631166 got implemented
ysr
parents: 1972
diff changeset
121 float delta_ise = (CMSExtrapolateSweep ? intra_sweep_estimate : 0.0);
e49cfa28f585 6999988: CMS: Increased fragmentation leading to promotion failure after CR#6631166 got implemented
ysr
parents: 1972
diff changeset
122 _desired = (ssize_t)(new_rate * (inter_sweep_estimate + delta_ise));
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
123 if (PrintFLSStatistics > 1) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
124 gclog_or_tty->print_cr("demand: %d, old_rate: %f, current_rate: %f, new_rate: %f, old_desired: %d, new_desired: %d",
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
125 demand, old_rate, rate, new_rate, old_desired, _desired);
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
126 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ssize_t desired() const { return _desired; }
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
131 void set_desired(ssize_t v) { _desired = v; }
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
132
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ssize_t coalDesired() const { return _coalDesired; }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 void set_coalDesired(ssize_t v) { _coalDesired = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 ssize_t surplus() const { return _surplus; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void set_surplus(ssize_t v) { _surplus = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void increment_surplus() { _surplus++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void decrement_surplus() { _surplus--; }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 ssize_t bfrSurp() const { return _bfrSurp; }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void set_bfrSurp(ssize_t v) { _bfrSurp = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 ssize_t prevSweep() const { return _prevSweep; }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void set_prevSweep(ssize_t v) { _prevSweep = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 ssize_t beforeSweep() const { return _beforeSweep; }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 void set_beforeSweep(ssize_t v) { _beforeSweep = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 ssize_t coalBirths() const { return _coalBirths; }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void set_coalBirths(ssize_t v) { _coalBirths = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void increment_coalBirths() { _coalBirths++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 ssize_t coalDeaths() const { return _coalDeaths; }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 void set_coalDeaths(ssize_t v) { _coalDeaths = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void increment_coalDeaths() { _coalDeaths++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 ssize_t splitBirths() const { return _splitBirths; }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void set_splitBirths(ssize_t v) { _splitBirths = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void increment_splitBirths() { _splitBirths++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 ssize_t splitDeaths() const { return _splitDeaths; }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void set_splitDeaths(ssize_t v) { _splitDeaths = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void increment_splitDeaths() { _splitDeaths++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 NOT_PRODUCT(
a61af66fc99e Initial load
duke
parents:
diff changeset
165 size_t returnedBytes() const { return _returnedBytes; }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 void set_returnedBytes(size_t v) { _returnedBytes = v; }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 )
a61af66fc99e Initial load
duke
parents:
diff changeset
168 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
169
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
170 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ALLOCATIONSTATS_HPP