annotate src/share/vm/gc_implementation/g1/g1MonitoringSupport.hpp @ 2745:81aa07130d30

7097048: G1: extend the G1 SA changes to print per-heap space information Reviewed-by: brutisso, johnc
author tonyp
date Mon, 03 Oct 2011 19:04:14 -0400
parents 8229bd737950
children 41406797186b
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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
jmasa@2386 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
jmasa@2386 27
jmasa@2386 28 #include "gc_implementation/shared/hSpaceCounters.hpp"
jmasa@2386 29
jmasa@2386 30 class G1CollectedHeap;
jmasa@2386 31
tonyp@2741 32 // Class for monitoring logical spaces in G1. It provides data for
tonyp@2741 33 // both G1's jstat counters as well as G1's memory pools.
jmasa@2386 34 //
tonyp@2741 35 // G1 splits the heap into heap regions and each heap region belongs
tonyp@2741 36 // to one of the following categories:
jmasa@2386 37 //
tonyp@2741 38 // * eden : regions that have been allocated since the last GC
tonyp@2741 39 // * survivors : regions with objects that survived the last few GCs
tonyp@2741 40 // * old : long-lived non-humongous regions
tonyp@2741 41 // * humongous : humongous regions
tonyp@2741 42 // * free : free regions
jmasa@2386 43 //
tonyp@2741 44 // The combination of eden and survivor regions form the equivalent of
tonyp@2741 45 // the young generation in the other GCs. The combination of old and
tonyp@2741 46 // humongous regions form the equivalent of the old generation in the
tonyp@2741 47 // other GCs. Free regions do not have a good equivalent in the other
tonyp@2741 48 // GCs given that they can be allocated as any of the other region types.
jmasa@2386 49 //
tonyp@2741 50 // The monitoring tools expect the heap to contain a number of
tonyp@2741 51 // generations (young, old, perm) and each generation to contain a
tonyp@2741 52 // number of spaces (young: eden, survivors, old). Given that G1 does
tonyp@2741 53 // not maintain those spaces physically (e.g., the set of
tonyp@2741 54 // non-contiguous eden regions can be considered as a "logical"
tonyp@2741 55 // space), we'll provide the illusion that those generations and
tonyp@2741 56 // spaces exist. In reality, each generation and space refers to a set
tonyp@2741 57 // of heap regions that are potentially non-contiguous.
jmasa@2386 58 //
tonyp@2741 59 // This class provides interfaces to access the min, current, and max
tonyp@2741 60 // capacity and current occupancy for each of G1's logical spaces and
tonyp@2741 61 // generations we expose to the monitoring tools. Also provided are
tonyp@2741 62 // counters for G1 concurrent collections and stop-the-world full heap
tonyp@2741 63 // collections.
jmasa@2386 64 //
tonyp@2741 65 // Below is a description of how the various sizes are calculated.
jmasa@2386 66 //
tonyp@2741 67 // * Current Capacity
jmasa@2386 68 //
tonyp@2741 69 // - heap_capacity = current heap capacity (e.g., current committed size)
tonyp@2741 70 // - young_gen_capacity = current max young gen target capacity
tonyp@2741 71 // (i.e., young gen target capacity + max allowed expansion capacity)
tonyp@2741 72 // - survivor_capacity = current survivor region capacity
tonyp@2741 73 // - eden_capacity = young_gen_capacity - survivor_capacity
tonyp@2741 74 // - old_capacity = heap_capacity - young_gen_capacity
jmasa@2386 75 //
tonyp@2741 76 // What we do in the above is to distribute the free regions among
tonyp@2741 77 // eden_capacity and old_capacity.
jmasa@2386 78 //
tonyp@2741 79 // * Occupancy
jmasa@2386 80 //
tonyp@2741 81 // - young_gen_used = current young region capacity
tonyp@2741 82 // - survivor_used = survivor_capacity
tonyp@2741 83 // - eden_used = young_gen_used - survivor_used
tonyp@2741 84 // - old_used = overall_used - young_gen_used
jmasa@2386 85 //
tonyp@2741 86 // Unfortunately, we currently only keep track of the number of
tonyp@2741 87 // currently allocated young and survivor regions + the overall used
tonyp@2741 88 // bytes in the heap, so the above can be a little inaccurate.
jmasa@2386 89 //
tonyp@2741 90 // * Min Capacity
tonyp@2741 91 //
tonyp@2741 92 // We set this to 0 for all spaces. We could consider setting the old
tonyp@2741 93 // min capacity to the min capacity of the heap (see 7078465).
tonyp@2741 94 //
tonyp@2741 95 // * Max Capacity
tonyp@2741 96 //
tonyp@2741 97 // For jstat, we set the max capacity of all spaces to heap_capacity,
tonyp@2741 98 // given that we don't always have a reasonably upper bound on how big
tonyp@2741 99 // each space can grow. For the memory pools, we actually make the max
tonyp@2741 100 // capacity undefined. We could consider setting the old max capacity
tonyp@2741 101 // to the max capacity of the heap (see 7078465).
tonyp@2741 102 //
tonyp@2741 103 // If we had more accurate occupancy / capacity information per
tonyp@2741 104 // region set the above calculations would be greatly simplified and
tonyp@2741 105 // be made more accurate.
tonyp@2741 106 //
tonyp@2741 107 // We update all the above synchronously and we store the results in
tonyp@2741 108 // fields so that we just read said fields when needed. A subtle point
tonyp@2741 109 // is that all the above sizes need to be recalculated when the old
tonyp@2741 110 // gen changes capacity (after a GC or after a humongous allocation)
tonyp@2741 111 // but only the eden occupancy changes when a new eden region is
tonyp@2741 112 // allocated. So, in the latter case we have minimal recalcuation to
tonyp@2741 113 // do which is important as we want to keep the eden region allocation
tonyp@2741 114 // path as low-overhead as possible.
jmasa@2386 115
jmasa@2386 116 class G1MonitoringSupport : public CHeapObj {
tonyp@2745 117 friend class VMStructs;
tonyp@2745 118
jmasa@2386 119 G1CollectedHeap* _g1h;
jmasa@2386 120
jmasa@2386 121 // jstat performance counters
jmasa@2386 122 // incremental collections both fully and partially young
jmasa@2386 123 CollectorCounters* _incremental_collection_counters;
jmasa@2386 124 // full stop-the-world collections
jmasa@2386 125 CollectorCounters* _full_collection_counters;
jmasa@2386 126 // young collection set counters. The _eden_counters,
jmasa@2386 127 // _from_counters, and _to_counters are associated with
jmasa@2386 128 // this "generational" counter.
jmasa@2386 129 GenerationCounters* _young_collection_counters;
tonyp@2741 130 // old collection set counters. The _old_space_counters
jmasa@2386 131 // below are associated with this "generational" counter.
tonyp@2741 132 GenerationCounters* _old_collection_counters;
jmasa@2386 133 // Counters for the capacity and used for
jmasa@2386 134 // the whole heap
jmasa@2386 135 HSpaceCounters* _old_space_counters;
jmasa@2386 136 // the young collection
jmasa@2386 137 HSpaceCounters* _eden_counters;
jmasa@2386 138 // the survivor collection (only one, _to_counters, is actively used)
jmasa@2386 139 HSpaceCounters* _from_counters;
jmasa@2386 140 HSpaceCounters* _to_counters;
jmasa@2386 141
tonyp@2741 142 // When it's appropriate to recalculate the various sizes (at the
tonyp@2741 143 // end of a GC, when a new eden region is allocated, etc.) we store
tonyp@2741 144 // them here so that we can easily report them when needed and not
tonyp@2741 145 // have to recalculate them every time.
tonyp@2741 146
tonyp@2741 147 size_t _overall_reserved;
tonyp@2741 148 size_t _overall_committed;
tonyp@2741 149 size_t _overall_used;
tonyp@2741 150
tonyp@2741 151 size_t _young_region_num;
tonyp@2741 152 size_t _young_gen_committed;
tonyp@2741 153 size_t _eden_committed;
tonyp@2741 154 size_t _eden_used;
tonyp@2741 155 size_t _survivor_committed;
tonyp@2741 156 size_t _survivor_used;
tonyp@2741 157
tonyp@2741 158 size_t _old_committed;
tonyp@2741 159 size_t _old_used;
tonyp@2741 160
tonyp@2741 161 G1CollectedHeap* g1h() { return _g1h; }
tonyp@2741 162
jmasa@2386 163 // It returns x - y if x > y, 0 otherwise.
jmasa@2386 164 // As described in the comment above, some of the inputs to the
jmasa@2386 165 // calculations we have to do are obtained concurrently and hence
jmasa@2386 166 // may be inconsistent with each other. So, this provides a
jmasa@2386 167 // defensive way of performing the subtraction and avoids the value
jmasa@2386 168 // going negative (which would mean a very large result, given that
jmasa@2386 169 // the parameter are size_t).
jmasa@2386 170 static size_t subtract_up_to_zero(size_t x, size_t y) {
jmasa@2386 171 if (x > y) {
jmasa@2386 172 return x - y;
jmasa@2386 173 } else {
jmasa@2386 174 return 0;
jmasa@2386 175 }
jmasa@2386 176 }
jmasa@2386 177
tonyp@2741 178 // Recalculate all the sizes.
tonyp@2741 179 void recalculate_sizes();
tonyp@2741 180 // Recalculate only what's necessary when a new eden region is allocated.
tonyp@2741 181 void recalculate_eden_size();
tonyp@2741 182
jmasa@2386 183 public:
tonyp@2741 184 G1MonitoringSupport(G1CollectedHeap* g1h);
jmasa@2386 185
tonyp@2741 186 // Unfortunately, the jstat tool assumes that no space has 0
tonyp@2741 187 // capacity. In our case, given that each space is logical, it's
tonyp@2741 188 // possible that no regions will be allocated to it, hence to have 0
tonyp@2741 189 // capacity (e.g., if there are no survivor regions, the survivor
tonyp@2741 190 // space has 0 capacity). The way we deal with this is to always pad
tonyp@2741 191 // each capacity value we report to jstat by a very small amount to
tonyp@2741 192 // make sure that it's never zero. Given that we sometimes have to
tonyp@2741 193 // report a capacity of a generation that contains several spaces
tonyp@2741 194 // (e.g., young gen includes one eden, two survivor spaces), the
tonyp@2741 195 // mult parameter is provided in order to adding the appropriate
tonyp@2741 196 // padding multiple times so that the capacities add up correctly.
tonyp@2741 197 static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
tonyp@2741 198 return size_bytes + MinObjAlignmentInBytes * mult;
tonyp@2741 199 }
jmasa@2386 200
tonyp@2741 201 // Recalculate all the sizes from scratch and update all the jstat
tonyp@2741 202 // counters accordingly.
tonyp@2741 203 void update_sizes();
tonyp@2741 204 // Recalculate only what's necessary when a new eden region is
tonyp@2741 205 // allocated and update any jstat counters that need to be updated.
tonyp@2741 206 void update_eden_size();
jmasa@2386 207
jmasa@2386 208 CollectorCounters* incremental_collection_counters() {
jmasa@2386 209 return _incremental_collection_counters;
jmasa@2386 210 }
jmasa@2386 211 CollectorCounters* full_collection_counters() {
jmasa@2386 212 return _full_collection_counters;
jmasa@2386 213 }
tonyp@2741 214 GenerationCounters* young_collection_counters() {
tonyp@2741 215 return _young_collection_counters;
tonyp@2741 216 }
tonyp@2741 217 GenerationCounters* old_collection_counters() {
tonyp@2741 218 return _old_collection_counters;
jmasa@2386 219 }
jmasa@2386 220 HSpaceCounters* old_space_counters() { return _old_space_counters; }
jmasa@2386 221 HSpaceCounters* eden_counters() { return _eden_counters; }
jmasa@2386 222 HSpaceCounters* from_counters() { return _from_counters; }
jmasa@2386 223 HSpaceCounters* to_counters() { return _to_counters; }
jmasa@2386 224
jmasa@2386 225 // Monitoring support used by
jmasa@2386 226 // MemoryService
jmasa@2386 227 // jstat counters
jmasa@2386 228
tonyp@2741 229 size_t overall_reserved() { return _overall_reserved; }
tonyp@2741 230 size_t overall_committed() { return _overall_committed; }
tonyp@2741 231 size_t overall_used() { return _overall_used; }
jmasa@2386 232
tonyp@2741 233 size_t young_gen_committed() { return _young_gen_committed; }
tonyp@2741 234 size_t young_gen_max() { return overall_reserved(); }
tonyp@2741 235 size_t eden_space_committed() { return _eden_committed; }
tonyp@2741 236 size_t eden_space_used() { return _eden_used; }
tonyp@2741 237 size_t survivor_space_committed() { return _survivor_committed; }
tonyp@2741 238 size_t survivor_space_used() { return _survivor_used; }
jmasa@2386 239
tonyp@2741 240 size_t old_gen_committed() { return old_space_committed(); }
tonyp@2741 241 size_t old_gen_max() { return overall_reserved(); }
tonyp@2741 242 size_t old_space_committed() { return _old_committed; }
tonyp@2741 243 size_t old_space_used() { return _old_used; }
tonyp@2741 244 };
tonyp@2741 245
tonyp@2741 246 class G1GenerationCounters: public GenerationCounters {
tonyp@2741 247 protected:
tonyp@2741 248 G1MonitoringSupport* _g1mm;
tonyp@2741 249
tonyp@2741 250 public:
tonyp@2741 251 G1GenerationCounters(G1MonitoringSupport* g1mm,
tonyp@2741 252 const char* name, int ordinal, int spaces,
tonyp@2741 253 size_t min_capacity, size_t max_capacity,
tonyp@2741 254 size_t curr_capacity);
tonyp@2741 255 };
tonyp@2741 256
tonyp@2741 257 class G1YoungGenerationCounters: public G1GenerationCounters {
tonyp@2741 258 public:
tonyp@2741 259 G1YoungGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
tonyp@2741 260 virtual void update_all();
tonyp@2741 261 };
tonyp@2741 262
tonyp@2741 263 class G1OldGenerationCounters: public G1GenerationCounters {
tonyp@2741 264 public:
tonyp@2741 265 G1OldGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
tonyp@2741 266 virtual void update_all();
jmasa@2386 267 };
jmasa@2386 268
jmasa@2386 269 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP