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

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 5237
f2110083203d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

jmasa@2821 1 /*
sla@5237 2 * Copyright (c) 2011, 2013, 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@3459 92 // We set this to 0 for all spaces.
tonyp@3176 93 //
tonyp@3176 94 // * Max Capacity
tonyp@3176 95 //
tonyp@3176 96 // For jstat, we set the max capacity of all spaces to heap_capacity,
tonyp@3459 97 // given that we don't always have a reasonable upper bound on how big
tonyp@3459 98 // each space can grow. For the memory pools, we make the max
tonyp@3459 99 // capacity undefined with the exception of the old memory pool for
tonyp@3459 100 // which we make the max capacity same as the max heap capacity.
tonyp@3176 101 //
tonyp@3176 102 // If we had more accurate occupancy / capacity information per
tonyp@3176 103 // region set the above calculations would be greatly simplified and
tonyp@3176 104 // be made more accurate.
tonyp@3176 105 //
tonyp@3176 106 // We update all the above synchronously and we store the results in
tonyp@3176 107 // fields so that we just read said fields when needed. A subtle point
tonyp@3176 108 // is that all the above sizes need to be recalculated when the old
tonyp@3176 109 // gen changes capacity (after a GC or after a humongous allocation)
tonyp@3176 110 // but only the eden occupancy changes when a new eden region is
tonyp@3176 111 // allocated. So, in the latter case we have minimal recalcuation to
tonyp@3176 112 // do which is important as we want to keep the eden region allocation
tonyp@3176 113 // path as low-overhead as possible.
jmasa@2821 114
zgu@3900 115 class G1MonitoringSupport : public CHeapObj<mtGC> {
tonyp@3180 116 friend class VMStructs;
tonyp@3180 117
jmasa@2821 118 G1CollectedHeap* _g1h;
jmasa@2821 119
jmasa@2821 120 // jstat performance counters
tonyp@3337 121 // incremental collections both young and mixed
jmasa@2821 122 CollectorCounters* _incremental_collection_counters;
jmasa@2821 123 // full stop-the-world collections
jmasa@2821 124 CollectorCounters* _full_collection_counters;
jmasa@2821 125 // young collection set counters. The _eden_counters,
jmasa@2821 126 // _from_counters, and _to_counters are associated with
jmasa@2821 127 // this "generational" counter.
jmasa@2821 128 GenerationCounters* _young_collection_counters;
tonyp@3176 129 // old collection set counters. The _old_space_counters
jmasa@2821 130 // below are associated with this "generational" counter.
tonyp@3176 131 GenerationCounters* _old_collection_counters;
jmasa@2821 132 // Counters for the capacity and used for
jmasa@2821 133 // the whole heap
jmasa@2821 134 HSpaceCounters* _old_space_counters;
jmasa@2821 135 // the young collection
jmasa@2821 136 HSpaceCounters* _eden_counters;
jmasa@2821 137 // the survivor collection (only one, _to_counters, is actively used)
jmasa@2821 138 HSpaceCounters* _from_counters;
jmasa@2821 139 HSpaceCounters* _to_counters;
jmasa@2821 140
tonyp@3176 141 // When it's appropriate to recalculate the various sizes (at the
tonyp@3176 142 // end of a GC, when a new eden region is allocated, etc.) we store
tonyp@3176 143 // them here so that we can easily report them when needed and not
tonyp@3176 144 // have to recalculate them every time.
tonyp@3176 145
tonyp@3176 146 size_t _overall_reserved;
tonyp@3176 147 size_t _overall_committed;
tonyp@3176 148 size_t _overall_used;
tonyp@3176 149
tonyp@3713 150 uint _young_region_num;
tonyp@3176 151 size_t _young_gen_committed;
tonyp@3176 152 size_t _eden_committed;
tonyp@3176 153 size_t _eden_used;
tonyp@3176 154 size_t _survivor_committed;
tonyp@3176 155 size_t _survivor_used;
tonyp@3176 156
tonyp@3176 157 size_t _old_committed;
tonyp@3176 158 size_t _old_used;
tonyp@3176 159
tonyp@3176 160 G1CollectedHeap* g1h() { return _g1h; }
tonyp@3176 161
jmasa@2821 162 // It returns x - y if x > y, 0 otherwise.
jmasa@2821 163 // As described in the comment above, some of the inputs to the
jmasa@2821 164 // calculations we have to do are obtained concurrently and hence
jmasa@2821 165 // may be inconsistent with each other. So, this provides a
jmasa@2821 166 // defensive way of performing the subtraction and avoids the value
jmasa@2821 167 // going negative (which would mean a very large result, given that
jmasa@2821 168 // the parameter are size_t).
jmasa@2821 169 static size_t subtract_up_to_zero(size_t x, size_t y) {
jmasa@2821 170 if (x > y) {
jmasa@2821 171 return x - y;
jmasa@2821 172 } else {
jmasa@2821 173 return 0;
jmasa@2821 174 }
jmasa@2821 175 }
jmasa@2821 176
tonyp@3176 177 // Recalculate all the sizes.
tonyp@3176 178 void recalculate_sizes();
tonyp@3176 179 // Recalculate only what's necessary when a new eden region is allocated.
tonyp@3176 180 void recalculate_eden_size();
tonyp@3176 181
jmasa@2821 182 public:
tonyp@3176 183 G1MonitoringSupport(G1CollectedHeap* g1h);
jmasa@2821 184
tonyp@3176 185 // Unfortunately, the jstat tool assumes that no space has 0
tonyp@3176 186 // capacity. In our case, given that each space is logical, it's
tonyp@3176 187 // possible that no regions will be allocated to it, hence to have 0
tonyp@3176 188 // capacity (e.g., if there are no survivor regions, the survivor
tonyp@3176 189 // space has 0 capacity). The way we deal with this is to always pad
tonyp@3176 190 // each capacity value we report to jstat by a very small amount to
tonyp@3176 191 // make sure that it's never zero. Given that we sometimes have to
tonyp@3176 192 // report a capacity of a generation that contains several spaces
tonyp@3176 193 // (e.g., young gen includes one eden, two survivor spaces), the
tonyp@3176 194 // mult parameter is provided in order to adding the appropriate
tonyp@3176 195 // padding multiple times so that the capacities add up correctly.
tonyp@3176 196 static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
tonyp@3176 197 return size_bytes + MinObjAlignmentInBytes * mult;
tonyp@3176 198 }
jmasa@2821 199
tonyp@3176 200 // Recalculate all the sizes from scratch and update all the jstat
tonyp@3176 201 // counters accordingly.
tonyp@3176 202 void update_sizes();
tonyp@3176 203 // Recalculate only what's necessary when a new eden region is
tonyp@3176 204 // allocated and update any jstat counters that need to be updated.
tonyp@3176 205 void update_eden_size();
jmasa@2821 206
jmasa@2821 207 CollectorCounters* incremental_collection_counters() {
jmasa@2821 208 return _incremental_collection_counters;
jmasa@2821 209 }
jmasa@2821 210 CollectorCounters* full_collection_counters() {
jmasa@2821 211 return _full_collection_counters;
jmasa@2821 212 }
tonyp@3176 213 GenerationCounters* young_collection_counters() {
tonyp@3176 214 return _young_collection_counters;
tonyp@3176 215 }
tonyp@3176 216 GenerationCounters* old_collection_counters() {
tonyp@3176 217 return _old_collection_counters;
jmasa@2821 218 }
jmasa@2821 219 HSpaceCounters* old_space_counters() { return _old_space_counters; }
jmasa@2821 220 HSpaceCounters* eden_counters() { return _eden_counters; }
jmasa@2821 221 HSpaceCounters* from_counters() { return _from_counters; }
jmasa@2821 222 HSpaceCounters* to_counters() { return _to_counters; }
jmasa@2821 223
jmasa@2821 224 // Monitoring support used by
jmasa@2821 225 // MemoryService
jmasa@2821 226 // jstat counters
sla@5237 227 // Tracing
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