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