annotate src/share/vm/gc_implementation/g1/g1MonitoringSupport.cpp @ 2741:8229bd737950

7075646: G1: fix inconsistencies in the monitoring data Summary: Fixed a few inconsistencies in the monitoring data, in particular when reported from jstat. Reviewed-by: jmasa, brutisso, johnc
author tonyp
date Fri, 23 Sep 2011 16:07:49 -0400
parents b52782ae3880
children b5290bf0a9e4
rev   line source
jmasa@2386 1 /*
jmasa@2386 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
jmasa@2386 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jmasa@2386 4 *
jmasa@2386 5 * This code is free software; you can redistribute it and/or modify it
jmasa@2386 6 * under the terms of the GNU General Public License version 2 only, as
jmasa@2386 7 * published by the Free Software Foundation.
jmasa@2386 8 *
jmasa@2386 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jmasa@2386 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jmasa@2386 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jmasa@2386 12 * version 2 for more details (a copy is included in the LICENSE file that
jmasa@2386 13 * accompanied this code).
jmasa@2386 14 *
jmasa@2386 15 * You should have received a copy of the GNU General Public License version
jmasa@2386 16 * 2 along with this work; if not, write to the Free Software Foundation,
jmasa@2386 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jmasa@2386 18 *
jmasa@2386 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jmasa@2386 20 * or visit www.oracle.com if you need additional information or have any
jmasa@2386 21 * questions.
jmasa@2386 22 *
jmasa@2386 23 */
jmasa@2386 24
jmasa@2386 25 #include "precompiled.hpp"
jmasa@2386 26 #include "gc_implementation/g1/g1MonitoringSupport.hpp"
jmasa@2386 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
jmasa@2386 28 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
jmasa@2386 29
tonyp@2741 30 G1GenerationCounters::G1GenerationCounters(G1MonitoringSupport* g1mm,
tonyp@2741 31 const char* name,
tonyp@2741 32 int ordinal, int spaces,
tonyp@2741 33 size_t min_capacity,
tonyp@2741 34 size_t max_capacity,
tonyp@2741 35 size_t curr_capacity)
tonyp@2741 36 : GenerationCounters(name, ordinal, spaces, min_capacity,
tonyp@2741 37 max_capacity, curr_capacity), _g1mm(g1mm) { }
tonyp@2741 38
tonyp@2741 39 // We pad the capacity three times given that the young generation
tonyp@2741 40 // contains three spaces (eden and two survivors).
tonyp@2741 41 G1YoungGenerationCounters::G1YoungGenerationCounters(G1MonitoringSupport* g1mm,
tonyp@2741 42 const char* name)
tonyp@2741 43 : G1GenerationCounters(g1mm, name, 0 /* ordinal */, 3 /* spaces */,
tonyp@2741 44 G1MonitoringSupport::pad_capacity(0, 3) /* min_capacity */,
tonyp@2741 45 G1MonitoringSupport::pad_capacity(g1mm->young_gen_max(), 3),
tonyp@2741 46 G1MonitoringSupport::pad_capacity(0, 3) /* curr_capacity */) {
tonyp@2741 47 update_all();
tonyp@2741 48 }
tonyp@2741 49
tonyp@2741 50 G1OldGenerationCounters::G1OldGenerationCounters(G1MonitoringSupport* g1mm,
tonyp@2741 51 const char* name)
tonyp@2741 52 : G1GenerationCounters(g1mm, name, 1 /* ordinal */, 1 /* spaces */,
tonyp@2741 53 G1MonitoringSupport::pad_capacity(0) /* min_capacity */,
tonyp@2741 54 G1MonitoringSupport::pad_capacity(g1mm->old_gen_max()),
tonyp@2741 55 G1MonitoringSupport::pad_capacity(0) /* curr_capacity */) {
tonyp@2741 56 update_all();
tonyp@2741 57 }
tonyp@2741 58
tonyp@2741 59 void G1YoungGenerationCounters::update_all() {
tonyp@2741 60 size_t committed =
tonyp@2741 61 G1MonitoringSupport::pad_capacity(_g1mm->young_gen_committed(), 3);
tonyp@2741 62 _current_size->set_value(committed);
tonyp@2741 63 }
tonyp@2741 64
tonyp@2741 65 void G1OldGenerationCounters::update_all() {
tonyp@2741 66 size_t committed =
tonyp@2741 67 G1MonitoringSupport::pad_capacity(_g1mm->old_gen_committed());
tonyp@2741 68 _current_size->set_value(committed);
tonyp@2741 69 }
tonyp@2741 70
tonyp@2741 71 G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h) :
jmasa@2386 72 _g1h(g1h),
jmasa@2386 73 _incremental_collection_counters(NULL),
jmasa@2386 74 _full_collection_counters(NULL),
tonyp@2741 75 _old_collection_counters(NULL),
jmasa@2386 76 _old_space_counters(NULL),
jmasa@2386 77 _young_collection_counters(NULL),
jmasa@2386 78 _eden_counters(NULL),
jmasa@2386 79 _from_counters(NULL),
jmasa@2386 80 _to_counters(NULL),
tonyp@2741 81
tonyp@2741 82 _overall_reserved(0),
tonyp@2741 83 _overall_committed(0), _overall_used(0),
tonyp@2741 84 _young_region_num(0),
tonyp@2741 85 _young_gen_committed(0),
tonyp@2741 86 _eden_committed(0), _eden_used(0),
tonyp@2741 87 _survivor_committed(0), _survivor_used(0),
tonyp@2741 88 _old_committed(0), _old_used(0) {
tonyp@2741 89
tonyp@2741 90 _overall_reserved = g1h->max_capacity();
tonyp@2741 91 recalculate_sizes();
tonyp@2741 92
jmasa@2386 93 // Counters for GC collections
jmasa@2386 94 //
jmasa@2386 95 // name "collector.0". In a generational collector this would be the
jmasa@2386 96 // young generation collection.
jmasa@2386 97 _incremental_collection_counters =
jmasa@2386 98 new CollectorCounters("G1 incremental collections", 0);
jmasa@2386 99 // name "collector.1". In a generational collector this would be the
jmasa@2386 100 // old generation collection.
jmasa@2386 101 _full_collection_counters =
jmasa@2386 102 new CollectorCounters("G1 stop-the-world full collections", 1);
jmasa@2386 103
jmasa@2386 104 // timer sampling for all counters supporting sampling only update the
jmasa@2386 105 // used value. See the take_sample() method. G1 requires both used and
jmasa@2386 106 // capacity updated so sampling is not currently used. It might
jmasa@2386 107 // be sufficient to update all counters in take_sample() even though
jmasa@2386 108 // take_sample() only returns "used". When sampling was used, there
jmasa@2386 109 // were some anomolous values emitted which may have been the consequence
jmasa@2386 110 // of not updating all values simultaneously (i.e., see the calculation done
jmasa@2386 111 // in eden_space_used(), is it possbile that the values used to
jmasa@2386 112 // calculate either eden_used or survivor_used are being updated by
jmasa@2386 113 // the collector when the sample is being done?).
jmasa@2386 114 const bool sampled = false;
jmasa@2386 115
jmasa@2386 116 // "Generation" and "Space" counters.
jmasa@2386 117 //
jmasa@2386 118 // name "generation.1" This is logically the old generation in
jmasa@2386 119 // generational GC terms. The "1, 1" parameters are for
jmasa@2386 120 // the n-th generation (=1) with 1 space.
jmasa@2386 121 // Counters are created from minCapacity, maxCapacity, and capacity
tonyp@2741 122 _old_collection_counters = new G1OldGenerationCounters(this, "old");
jmasa@2386 123
jmasa@2386 124 // name "generation.1.space.0"
jmasa@2386 125 // Counters are created from maxCapacity, capacity, initCapacity,
jmasa@2386 126 // and used.
tonyp@2741 127 _old_space_counters = new HSpaceCounters("space", 0 /* ordinal */,
tonyp@2741 128 pad_capacity(overall_reserved()) /* max_capacity */,
tonyp@2741 129 pad_capacity(old_space_committed()) /* init_capacity */,
tonyp@2741 130 _old_collection_counters);
jmasa@2386 131
jmasa@2386 132 // Young collection set
jmasa@2386 133 // name "generation.0". This is logically the young generation.
jmasa@2386 134 // The "0, 3" are paremeters for the n-th genertaion (=0) with 3 spaces.
tonyp@2741 135 // See _old_collection_counters for additional counters
tonyp@2741 136 _young_collection_counters = new G1YoungGenerationCounters(this, "young");
jmasa@2386 137
jmasa@2386 138 // name "generation.0.space.0"
jmasa@2386 139 // See _old_space_counters for additional counters
tonyp@2741 140 _eden_counters = new HSpaceCounters("eden", 0 /* ordinal */,
tonyp@2741 141 pad_capacity(overall_reserved()) /* max_capacity */,
tonyp@2741 142 pad_capacity(eden_space_committed()) /* init_capacity */,
jmasa@2386 143 _young_collection_counters);
jmasa@2386 144
jmasa@2386 145 // name "generation.0.space.1"
jmasa@2386 146 // See _old_space_counters for additional counters
jmasa@2386 147 // Set the arguments to indicate that this survivor space is not used.
tonyp@2741 148 _from_counters = new HSpaceCounters("s0", 1 /* ordinal */,
tonyp@2741 149 pad_capacity(0) /* max_capacity */,
tonyp@2741 150 pad_capacity(0) /* init_capacity */,
jmasa@2386 151 _young_collection_counters);
tonyp@2741 152 // Given that this survivor space is not used, we update it here
tonyp@2741 153 // once to reflect that its used space is 0 so that we don't have to
tonyp@2741 154 // worry about updating it again later.
tonyp@2741 155 _from_counters->update_used(0);
jmasa@2386 156
jmasa@2386 157 // name "generation.0.space.2"
jmasa@2386 158 // See _old_space_counters for additional counters
tonyp@2741 159 _to_counters = new HSpaceCounters("s1", 2 /* ordinal */,
tonyp@2741 160 pad_capacity(overall_reserved()) /* max_capacity */,
tonyp@2741 161 pad_capacity(survivor_space_committed()) /* init_capacity */,
jmasa@2386 162 _young_collection_counters);
jmasa@2386 163 }
jmasa@2386 164
tonyp@2741 165 void G1MonitoringSupport::recalculate_sizes() {
tonyp@2741 166 G1CollectedHeap* g1 = g1h();
tonyp@2741 167
tonyp@2741 168 // Recalculate all the sizes from scratch. We assume that this is
tonyp@2741 169 // called at a point where no concurrent updates to the various
tonyp@2741 170 // values we read here are possible (i.e., at a STW phase at the end
tonyp@2741 171 // of a GC).
tonyp@2741 172
tonyp@2741 173 size_t young_list_length = g1->young_list()->length();
tonyp@2741 174 size_t survivor_list_length = g1->g1_policy()->recorded_survivor_regions();
tonyp@2741 175 assert(young_list_length >= survivor_list_length, "invariant");
tonyp@2741 176 size_t eden_list_length = young_list_length - survivor_list_length;
tonyp@2741 177 // Max length includes any potential extensions to the young gen
tonyp@2741 178 // we'll do when the GC locker is active.
tonyp@2741 179 size_t young_list_max_length = g1->g1_policy()->young_list_max_length();
tonyp@2741 180 assert(young_list_max_length >= survivor_list_length, "invariant");
tonyp@2741 181 size_t eden_list_max_length = young_list_max_length - survivor_list_length;
tonyp@2741 182
tonyp@2741 183 _overall_used = g1->used_unlocked();
tonyp@2741 184 _eden_used = eden_list_length * HeapRegion::GrainBytes;
tonyp@2741 185 _survivor_used = survivor_list_length * HeapRegion::GrainBytes;
tonyp@2741 186 _young_region_num = young_list_length;
tonyp@2741 187 _old_used = subtract_up_to_zero(_overall_used, _eden_used + _survivor_used);
tonyp@2741 188
tonyp@2741 189 // First calculate the committed sizes that can be calculated independently.
tonyp@2741 190 _survivor_committed = _survivor_used;
tonyp@2741 191 _old_committed = HeapRegion::align_up_to_region_byte_size(_old_used);
tonyp@2741 192
tonyp@2741 193 // Next, start with the overall committed size.
tonyp@2741 194 _overall_committed = g1->capacity();
tonyp@2741 195 size_t committed = _overall_committed;
tonyp@2741 196
tonyp@2741 197 // Remove the committed size we have calculated so far (for the
tonyp@2741 198 // survivor and old space).
tonyp@2741 199 assert(committed >= (_survivor_committed + _old_committed), "sanity");
tonyp@2741 200 committed -= _survivor_committed + _old_committed;
tonyp@2741 201
tonyp@2741 202 // Next, calculate and remove the committed size for the eden.
tonyp@2741 203 _eden_committed = eden_list_max_length * HeapRegion::GrainBytes;
tonyp@2741 204 // Somewhat defensive: be robust in case there are inaccuracies in
tonyp@2741 205 // the calculations
tonyp@2741 206 _eden_committed = MIN2(_eden_committed, committed);
tonyp@2741 207 committed -= _eden_committed;
tonyp@2741 208
tonyp@2741 209 // Finally, give the rest to the old space...
tonyp@2741 210 _old_committed += committed;
tonyp@2741 211 // ..and calculate the young gen committed.
tonyp@2741 212 _young_gen_committed = _eden_committed + _survivor_committed;
tonyp@2741 213
tonyp@2741 214 assert(_overall_committed ==
tonyp@2741 215 (_eden_committed + _survivor_committed + _old_committed),
tonyp@2741 216 "the committed sizes should add up");
tonyp@2741 217 // Somewhat defensive: cap the eden used size to make sure it
tonyp@2741 218 // never exceeds the committed size.
tonyp@2741 219 _eden_used = MIN2(_eden_used, _eden_committed);
tonyp@2741 220 // _survivor_committed and _old_committed are calculated in terms of
tonyp@2741 221 // the corresponding _*_used value, so the next two conditions
tonyp@2741 222 // should hold.
tonyp@2741 223 assert(_survivor_used <= _survivor_committed, "post-condition");
tonyp@2741 224 assert(_old_used <= _old_committed, "post-condition");
jmasa@2386 225 }
jmasa@2386 226
tonyp@2741 227 void G1MonitoringSupport::recalculate_eden_size() {
tonyp@2741 228 G1CollectedHeap* g1 = g1h();
jmasa@2386 229
tonyp@2741 230 // When a new eden region is allocated, only the eden_used size is
tonyp@2741 231 // affected (since we have recalculated everything else at the last GC).
jmasa@2386 232
tonyp@2741 233 size_t young_region_num = g1h()->young_list()->length();
tonyp@2741 234 if (young_region_num > _young_region_num) {
tonyp@2741 235 size_t diff = young_region_num - _young_region_num;
tonyp@2741 236 _eden_used += diff * HeapRegion::GrainBytes;
tonyp@2741 237 // Somewhat defensive: cap the eden used size to make sure it
tonyp@2741 238 // never exceeds the committed size.
tonyp@2741 239 _eden_used = MIN2(_eden_used, _eden_committed);
tonyp@2741 240 _young_region_num = young_region_num;
jmasa@2386 241 }
jmasa@2386 242 }
jmasa@2386 243
tonyp@2741 244 void G1MonitoringSupport::update_sizes() {
tonyp@2741 245 recalculate_sizes();
jmasa@2386 246 if (UsePerfData) {
tonyp@2741 247 eden_counters()->update_capacity(pad_capacity(eden_space_committed()));
tonyp@2741 248 eden_counters()->update_used(eden_space_used());
tonyp@2741 249 // only the to survivor space (s1) is active, so we don't need to
tonyp@2741 250 // update the counteres for the from survivor space (s0)
tonyp@2741 251 to_counters()->update_capacity(pad_capacity(survivor_space_committed()));
tonyp@2741 252 to_counters()->update_used(survivor_space_used());
tonyp@2741 253 old_space_counters()->update_capacity(pad_capacity(old_space_committed()));
tonyp@2741 254 old_space_counters()->update_used(old_space_used());
tonyp@2741 255 old_collection_counters()->update_all();
tonyp@2741 256 young_collection_counters()->update_all();
tonyp@2741 257 }
tonyp@2741 258 }
tonyp@2741 259
tonyp@2741 260 void G1MonitoringSupport::update_eden_size() {
tonyp@2741 261 recalculate_eden_size();
tonyp@2741 262 if (UsePerfData) {
jmasa@2386 263 eden_counters()->update_used(eden_space_used());
jmasa@2386 264 }
jmasa@2386 265 }