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

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

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

mercurial