Tue, 08 Aug 2017 15:57:29 +0800
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 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "gc_implementation/g1/g1MonitoringSupport.hpp" |
aoqi@0 | 27 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
aoqi@0 | 28 | #include "gc_implementation/g1/g1CollectorPolicy.hpp" |
aoqi@0 | 29 | |
aoqi@0 | 30 | G1GenerationCounters::G1GenerationCounters(G1MonitoringSupport* g1mm, |
aoqi@0 | 31 | const char* name, |
aoqi@0 | 32 | int ordinal, int spaces, |
aoqi@0 | 33 | size_t min_capacity, |
aoqi@0 | 34 | size_t max_capacity, |
aoqi@0 | 35 | size_t curr_capacity) |
aoqi@0 | 36 | : GenerationCounters(name, ordinal, spaces, min_capacity, |
aoqi@0 | 37 | max_capacity, curr_capacity), _g1mm(g1mm) { } |
aoqi@0 | 38 | |
aoqi@0 | 39 | // We pad the capacity three times given that the young generation |
aoqi@0 | 40 | // contains three spaces (eden and two survivors). |
aoqi@0 | 41 | G1YoungGenerationCounters::G1YoungGenerationCounters(G1MonitoringSupport* g1mm, |
aoqi@0 | 42 | const char* name) |
aoqi@0 | 43 | : G1GenerationCounters(g1mm, name, 0 /* ordinal */, 3 /* spaces */, |
aoqi@0 | 44 | G1MonitoringSupport::pad_capacity(0, 3) /* min_capacity */, |
aoqi@0 | 45 | G1MonitoringSupport::pad_capacity(g1mm->young_gen_max(), 3), |
aoqi@0 | 46 | G1MonitoringSupport::pad_capacity(0, 3) /* curr_capacity */) { |
aoqi@0 | 47 | if (UsePerfData) { |
aoqi@0 | 48 | update_all(); |
aoqi@0 | 49 | } |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | G1OldGenerationCounters::G1OldGenerationCounters(G1MonitoringSupport* g1mm, |
aoqi@0 | 53 | const char* name) |
aoqi@0 | 54 | : G1GenerationCounters(g1mm, name, 1 /* ordinal */, 1 /* spaces */, |
aoqi@0 | 55 | G1MonitoringSupport::pad_capacity(0) /* min_capacity */, |
aoqi@0 | 56 | G1MonitoringSupport::pad_capacity(g1mm->old_gen_max()), |
aoqi@0 | 57 | G1MonitoringSupport::pad_capacity(0) /* curr_capacity */) { |
aoqi@0 | 58 | if (UsePerfData) { |
aoqi@0 | 59 | update_all(); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | } |
aoqi@0 | 62 | |
aoqi@0 | 63 | void G1YoungGenerationCounters::update_all() { |
aoqi@0 | 64 | size_t committed = |
aoqi@0 | 65 | G1MonitoringSupport::pad_capacity(_g1mm->young_gen_committed(), 3); |
aoqi@0 | 66 | _current_size->set_value(committed); |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | void G1OldGenerationCounters::update_all() { |
aoqi@0 | 70 | size_t committed = |
aoqi@0 | 71 | G1MonitoringSupport::pad_capacity(_g1mm->old_gen_committed()); |
aoqi@0 | 72 | _current_size->set_value(committed); |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h) : |
aoqi@0 | 76 | _g1h(g1h), |
aoqi@0 | 77 | _incremental_collection_counters(NULL), |
aoqi@0 | 78 | _full_collection_counters(NULL), |
aoqi@0 | 79 | _old_collection_counters(NULL), |
aoqi@0 | 80 | _old_space_counters(NULL), |
aoqi@0 | 81 | _young_collection_counters(NULL), |
aoqi@0 | 82 | _eden_counters(NULL), |
aoqi@0 | 83 | _from_counters(NULL), |
aoqi@0 | 84 | _to_counters(NULL), |
aoqi@0 | 85 | |
aoqi@0 | 86 | _overall_reserved(0), |
aoqi@0 | 87 | _overall_committed(0), _overall_used(0), |
aoqi@0 | 88 | _young_region_num(0), |
aoqi@0 | 89 | _young_gen_committed(0), |
aoqi@0 | 90 | _eden_committed(0), _eden_used(0), |
aoqi@0 | 91 | _survivor_committed(0), _survivor_used(0), |
aoqi@0 | 92 | _old_committed(0), _old_used(0) { |
aoqi@0 | 93 | |
aoqi@0 | 94 | _overall_reserved = g1h->max_capacity(); |
aoqi@0 | 95 | recalculate_sizes(); |
aoqi@0 | 96 | |
aoqi@0 | 97 | // Counters for GC collections |
aoqi@0 | 98 | // |
aoqi@0 | 99 | // name "collector.0". In a generational collector this would be the |
aoqi@0 | 100 | // young generation collection. |
aoqi@0 | 101 | _incremental_collection_counters = |
aoqi@0 | 102 | new CollectorCounters("G1 incremental collections", 0); |
aoqi@0 | 103 | // name "collector.1". In a generational collector this would be the |
aoqi@0 | 104 | // old generation collection. |
aoqi@0 | 105 | _full_collection_counters = |
aoqi@0 | 106 | new CollectorCounters("G1 stop-the-world full collections", 1); |
aoqi@0 | 107 | |
aoqi@0 | 108 | // timer sampling for all counters supporting sampling only update the |
aoqi@0 | 109 | // used value. See the take_sample() method. G1 requires both used and |
aoqi@0 | 110 | // capacity updated so sampling is not currently used. It might |
aoqi@0 | 111 | // be sufficient to update all counters in take_sample() even though |
aoqi@0 | 112 | // take_sample() only returns "used". When sampling was used, there |
aoqi@0 | 113 | // were some anomolous values emitted which may have been the consequence |
aoqi@0 | 114 | // of not updating all values simultaneously (i.e., see the calculation done |
aoqi@0 | 115 | // in eden_space_used(), is it possbile that the values used to |
aoqi@0 | 116 | // calculate either eden_used or survivor_used are being updated by |
aoqi@0 | 117 | // the collector when the sample is being done?). |
aoqi@0 | 118 | const bool sampled = false; |
aoqi@0 | 119 | |
aoqi@0 | 120 | // "Generation" and "Space" counters. |
aoqi@0 | 121 | // |
aoqi@0 | 122 | // name "generation.1" This is logically the old generation in |
aoqi@0 | 123 | // generational GC terms. The "1, 1" parameters are for |
aoqi@0 | 124 | // the n-th generation (=1) with 1 space. |
aoqi@0 | 125 | // Counters are created from minCapacity, maxCapacity, and capacity |
aoqi@0 | 126 | _old_collection_counters = new G1OldGenerationCounters(this, "old"); |
aoqi@0 | 127 | |
aoqi@0 | 128 | // name "generation.1.space.0" |
aoqi@0 | 129 | // Counters are created from maxCapacity, capacity, initCapacity, |
aoqi@0 | 130 | // and used. |
aoqi@0 | 131 | _old_space_counters = new HSpaceCounters("space", 0 /* ordinal */, |
aoqi@0 | 132 | pad_capacity(overall_reserved()) /* max_capacity */, |
aoqi@0 | 133 | pad_capacity(old_space_committed()) /* init_capacity */, |
aoqi@0 | 134 | _old_collection_counters); |
aoqi@0 | 135 | |
aoqi@0 | 136 | // Young collection set |
aoqi@0 | 137 | // name "generation.0". This is logically the young generation. |
aoqi@0 | 138 | // The "0, 3" are paremeters for the n-th genertaion (=0) with 3 spaces. |
aoqi@0 | 139 | // See _old_collection_counters for additional counters |
aoqi@0 | 140 | _young_collection_counters = new G1YoungGenerationCounters(this, "young"); |
aoqi@0 | 141 | |
aoqi@0 | 142 | // name "generation.0.space.0" |
aoqi@0 | 143 | // See _old_space_counters for additional counters |
aoqi@0 | 144 | _eden_counters = new HSpaceCounters("eden", 0 /* ordinal */, |
aoqi@0 | 145 | pad_capacity(overall_reserved()) /* max_capacity */, |
aoqi@0 | 146 | pad_capacity(eden_space_committed()) /* init_capacity */, |
aoqi@0 | 147 | _young_collection_counters); |
aoqi@0 | 148 | |
aoqi@0 | 149 | // name "generation.0.space.1" |
aoqi@0 | 150 | // See _old_space_counters for additional counters |
aoqi@0 | 151 | // Set the arguments to indicate that this survivor space is not used. |
aoqi@0 | 152 | _from_counters = new HSpaceCounters("s0", 1 /* ordinal */, |
aoqi@0 | 153 | pad_capacity(0) /* max_capacity */, |
aoqi@0 | 154 | pad_capacity(0) /* init_capacity */, |
aoqi@0 | 155 | _young_collection_counters); |
aoqi@0 | 156 | |
aoqi@0 | 157 | // name "generation.0.space.2" |
aoqi@0 | 158 | // See _old_space_counters for additional counters |
aoqi@0 | 159 | _to_counters = new HSpaceCounters("s1", 2 /* ordinal */, |
aoqi@0 | 160 | pad_capacity(overall_reserved()) /* max_capacity */, |
aoqi@0 | 161 | pad_capacity(survivor_space_committed()) /* init_capacity */, |
aoqi@0 | 162 | _young_collection_counters); |
aoqi@0 | 163 | |
aoqi@0 | 164 | if (UsePerfData) { |
aoqi@0 | 165 | // Given that this survivor space is not used, we update it here |
aoqi@0 | 166 | // once to reflect that its used space is 0 so that we don't have to |
aoqi@0 | 167 | // worry about updating it again later. |
aoqi@0 | 168 | _from_counters->update_used(0); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | } |
aoqi@0 | 171 | |
aoqi@0 | 172 | void G1MonitoringSupport::recalculate_sizes() { |
aoqi@0 | 173 | G1CollectedHeap* g1 = g1h(); |
aoqi@0 | 174 | |
aoqi@0 | 175 | // Recalculate all the sizes from scratch. We assume that this is |
aoqi@0 | 176 | // called at a point where no concurrent updates to the various |
aoqi@0 | 177 | // values we read here are possible (i.e., at a STW phase at the end |
aoqi@0 | 178 | // of a GC). |
aoqi@0 | 179 | |
aoqi@0 | 180 | uint young_list_length = g1->young_list()->length(); |
aoqi@0 | 181 | uint survivor_list_length = g1->g1_policy()->recorded_survivor_regions(); |
aoqi@0 | 182 | assert(young_list_length >= survivor_list_length, "invariant"); |
aoqi@0 | 183 | uint eden_list_length = young_list_length - survivor_list_length; |
aoqi@0 | 184 | // Max length includes any potential extensions to the young gen |
aoqi@0 | 185 | // we'll do when the GC locker is active. |
aoqi@0 | 186 | uint young_list_max_length = g1->g1_policy()->young_list_max_length(); |
aoqi@0 | 187 | assert(young_list_max_length >= survivor_list_length, "invariant"); |
aoqi@0 | 188 | uint eden_list_max_length = young_list_max_length - survivor_list_length; |
aoqi@0 | 189 | |
aoqi@0 | 190 | _overall_used = g1->used_unlocked(); |
aoqi@0 | 191 | _eden_used = (size_t) eden_list_length * HeapRegion::GrainBytes; |
aoqi@0 | 192 | _survivor_used = (size_t) survivor_list_length * HeapRegion::GrainBytes; |
aoqi@0 | 193 | _young_region_num = young_list_length; |
aoqi@0 | 194 | _old_used = subtract_up_to_zero(_overall_used, _eden_used + _survivor_used); |
aoqi@0 | 195 | |
aoqi@0 | 196 | // First calculate the committed sizes that can be calculated independently. |
aoqi@0 | 197 | _survivor_committed = _survivor_used; |
aoqi@0 | 198 | _old_committed = HeapRegion::align_up_to_region_byte_size(_old_used); |
aoqi@0 | 199 | |
aoqi@0 | 200 | // Next, start with the overall committed size. |
aoqi@0 | 201 | _overall_committed = g1->capacity(); |
aoqi@0 | 202 | size_t committed = _overall_committed; |
aoqi@0 | 203 | |
aoqi@0 | 204 | // Remove the committed size we have calculated so far (for the |
aoqi@0 | 205 | // survivor and old space). |
aoqi@0 | 206 | assert(committed >= (_survivor_committed + _old_committed), "sanity"); |
aoqi@0 | 207 | committed -= _survivor_committed + _old_committed; |
aoqi@0 | 208 | |
aoqi@0 | 209 | // Next, calculate and remove the committed size for the eden. |
aoqi@0 | 210 | _eden_committed = (size_t) eden_list_max_length * HeapRegion::GrainBytes; |
aoqi@0 | 211 | // Somewhat defensive: be robust in case there are inaccuracies in |
aoqi@0 | 212 | // the calculations |
aoqi@0 | 213 | _eden_committed = MIN2(_eden_committed, committed); |
aoqi@0 | 214 | committed -= _eden_committed; |
aoqi@0 | 215 | |
aoqi@0 | 216 | // Finally, give the rest to the old space... |
aoqi@0 | 217 | _old_committed += committed; |
aoqi@0 | 218 | // ..and calculate the young gen committed. |
aoqi@0 | 219 | _young_gen_committed = _eden_committed + _survivor_committed; |
aoqi@0 | 220 | |
aoqi@0 | 221 | assert(_overall_committed == |
aoqi@0 | 222 | (_eden_committed + _survivor_committed + _old_committed), |
aoqi@0 | 223 | "the committed sizes should add up"); |
aoqi@0 | 224 | // Somewhat defensive: cap the eden used size to make sure it |
aoqi@0 | 225 | // never exceeds the committed size. |
aoqi@0 | 226 | _eden_used = MIN2(_eden_used, _eden_committed); |
aoqi@0 | 227 | // _survivor_committed and _old_committed are calculated in terms of |
aoqi@0 | 228 | // the corresponding _*_used value, so the next two conditions |
aoqi@0 | 229 | // should hold. |
aoqi@0 | 230 | assert(_survivor_used <= _survivor_committed, "post-condition"); |
aoqi@0 | 231 | assert(_old_used <= _old_committed, "post-condition"); |
aoqi@0 | 232 | } |
aoqi@0 | 233 | |
aoqi@0 | 234 | void G1MonitoringSupport::recalculate_eden_size() { |
aoqi@0 | 235 | G1CollectedHeap* g1 = g1h(); |
aoqi@0 | 236 | |
aoqi@0 | 237 | // When a new eden region is allocated, only the eden_used size is |
aoqi@0 | 238 | // affected (since we have recalculated everything else at the last GC). |
aoqi@0 | 239 | |
aoqi@0 | 240 | uint young_region_num = g1h()->young_list()->length(); |
aoqi@0 | 241 | if (young_region_num > _young_region_num) { |
aoqi@0 | 242 | uint diff = young_region_num - _young_region_num; |
aoqi@0 | 243 | _eden_used += (size_t) diff * HeapRegion::GrainBytes; |
aoqi@0 | 244 | // Somewhat defensive: cap the eden used size to make sure it |
aoqi@0 | 245 | // never exceeds the committed size. |
aoqi@0 | 246 | _eden_used = MIN2(_eden_used, _eden_committed); |
aoqi@0 | 247 | _young_region_num = young_region_num; |
aoqi@0 | 248 | } |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | void G1MonitoringSupport::update_sizes() { |
aoqi@0 | 252 | recalculate_sizes(); |
aoqi@0 | 253 | if (UsePerfData) { |
aoqi@0 | 254 | eden_counters()->update_capacity(pad_capacity(eden_space_committed())); |
aoqi@0 | 255 | eden_counters()->update_used(eden_space_used()); |
aoqi@0 | 256 | // only the to survivor space (s1) is active, so we don't need to |
aoqi@0 | 257 | // update the counteres for the from survivor space (s0) |
aoqi@0 | 258 | to_counters()->update_capacity(pad_capacity(survivor_space_committed())); |
aoqi@0 | 259 | to_counters()->update_used(survivor_space_used()); |
aoqi@0 | 260 | old_space_counters()->update_capacity(pad_capacity(old_space_committed())); |
aoqi@0 | 261 | old_space_counters()->update_used(old_space_used()); |
aoqi@0 | 262 | old_collection_counters()->update_all(); |
aoqi@0 | 263 | young_collection_counters()->update_all(); |
aoqi@0 | 264 | MetaspaceCounters::update_performance_counters(); |
aoqi@0 | 265 | CompressedClassSpaceCounters::update_performance_counters(); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | } |
aoqi@0 | 268 | |
aoqi@0 | 269 | void G1MonitoringSupport::update_eden_size() { |
aoqi@0 | 270 | recalculate_eden_size(); |
aoqi@0 | 271 | if (UsePerfData) { |
aoqi@0 | 272 | eden_counters()->update_used(eden_space_used()); |
aoqi@0 | 273 | } |
aoqi@0 | 274 | } |