src/share/vm/gc_implementation/g1/g1MonitoringSupport.hpp

Mon, 07 Nov 2011 22:11:12 -0500

author
tonyp
date
Mon, 07 Nov 2011 22:11:12 -0500
changeset 3268
8aae2050e83e
parent 3180
81aa07130d30
child 3337
41406797186b
permissions
-rw-r--r--

7092309: G1: introduce old region set
Summary: Keep track of all the old regions in the heap with a heap region set.
Reviewed-by: brutisso, johnc

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

mercurial