src/share/vm/gc_implementation/g1/g1CollectedHeap.inline.hpp

Tue, 19 Aug 2014 10:50:27 +0200

author
tschatzl
date
Tue, 19 Aug 2014 10:50:27 +0200
changeset 7050
6701abbc4441
parent 7049
eec72fa4b108
child 7091
a8ea2f110d87
permissions
-rw-r--r--

8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
Summary: Let HeapRegionSeq manage the heap region and auxiliary data to decrease the amount of responsibilities of G1CollectedHeap, and encapsulate this work from other code.
Reviewed-by: jwilhelm, jmasa, mgerdin, brutisso

ysr@777 1 /*
drchase@6680 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/g1/concurrentMark.hpp"
stefank@2314 29 #include "gc_implementation/g1/g1CollectedHeap.hpp"
tonyp@2715 30 #include "gc_implementation/g1/g1AllocRegion.inline.hpp"
tonyp@2315 31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
mgerdin@5860 32 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
brutisso@6385 33 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
tonyp@2469 34 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
goetz@6911 35 #include "runtime/orderAccess.inline.hpp"
stefank@2314 36 #include "utilities/taskqueue.hpp"
stefank@2314 37
ysr@777 38 // Inline functions for G1CollectedHeap
ysr@777 39
tschatzl@6541 40 // Return the region with the given index. It assumes the index is valid.
tschatzl@6541 41 inline HeapRegion* G1CollectedHeap::region_at(uint index) const { return _hrs.at(index); }
tschatzl@6541 42
tschatzl@7010 43 inline uint G1CollectedHeap::addr_to_region(HeapWord* addr) const {
tschatzl@7010 44 assert(is_in_reserved(addr),
tschatzl@7010 45 err_msg("Cannot calculate region index for address "PTR_FORMAT" that is outside of the heap ["PTR_FORMAT", "PTR_FORMAT")",
tschatzl@7010 46 p2i(addr), p2i(_reserved.start()), p2i(_reserved.end())));
tschatzl@7010 47 return (uint)(pointer_delta(addr, _reserved.start(), sizeof(uint8_t)) >> HeapRegion::LogOfHRGrainBytes);
tschatzl@7010 48 }
tschatzl@7010 49
tschatzl@7050 50 inline HeapWord* G1CollectedHeap::bottom_addr_for_region(uint index) const {
tschatzl@7050 51 return _hrs.reserved().start() + index * HeapRegion::GrainWords;
tschatzl@7050 52 }
tschatzl@7050 53
tonyp@2963 54 template <class T>
tschatzl@7050 55 inline HeapRegion* G1CollectedHeap::heap_region_containing_raw(const T addr) const {
brutisso@7049 56 assert(addr != NULL, "invariant");
tschatzl@7050 57 assert(is_in_g1_reserved((const void*) addr),
brutisso@7049 58 err_msg("Address "PTR_FORMAT" is outside of the heap ranging from ["PTR_FORMAT" to "PTR_FORMAT")",
tschatzl@7050 59 p2i((void*)addr), p2i(g1_reserved().start()), p2i(g1_reserved().end())));
brutisso@7049 60 return _hrs.addr_to_region((HeapWord*) addr);
ysr@777 61 }
ysr@777 62
tonyp@2963 63 template <class T>
tschatzl@7050 64 inline HeapRegion* G1CollectedHeap::heap_region_containing(const T addr) const {
brutisso@7049 65 HeapRegion* hr = heap_region_containing_raw(addr);
brutisso@7049 66 if (hr->continuesHumongous()) {
brutisso@7049 67 return hr->humongous_start_region();
brutisso@7049 68 }
brutisso@7049 69 return hr;
ysr@777 70 }
ysr@777 71
goetz@6911 72 inline void G1CollectedHeap::reset_gc_time_stamp() {
goetz@6911 73 _gc_time_stamp = 0;
goetz@6911 74 OrderAccess::fence();
goetz@6911 75 // Clear the cached CSet starting regions and time stamps.
goetz@6911 76 // Their validity is dependent on the GC timestamp.
goetz@6911 77 clear_cset_start_regions();
goetz@6911 78 }
goetz@6911 79
goetz@6911 80 inline void G1CollectedHeap::increment_gc_time_stamp() {
goetz@6911 81 ++_gc_time_stamp;
goetz@6911 82 OrderAccess::fence();
goetz@6911 83 }
goetz@6911 84
tschatzl@6541 85 inline void G1CollectedHeap::old_set_remove(HeapRegion* hr) {
tschatzl@6541 86 _old_set.remove(hr);
tschatzl@6541 87 }
tschatzl@6541 88
ysr@777 89 inline bool G1CollectedHeap::obj_in_cs(oop obj) {
tonyp@2963 90 HeapRegion* r = _hrs.addr_to_region((HeapWord*) obj);
ysr@777 91 return r != NULL && r->in_collection_set();
ysr@777 92 }
ysr@777 93
tschatzl@7050 94 inline HeapWord* G1CollectedHeap::attempt_allocation(size_t word_size,
tschatzl@7050 95 unsigned int* gc_count_before_ret,
tschatzl@7050 96 int* gclocker_retry_count_ret) {
tonyp@2715 97 assert_heap_not_locked_and_not_at_safepoint();
tonyp@2715 98 assert(!isHumongous(word_size), "attempt_allocation() should not "
tonyp@2715 99 "be called for humongous allocation requests");
ysr@777 100
tonyp@2715 101 HeapWord* result = _mutator_alloc_region.attempt_allocation(word_size,
tonyp@2715 102 false /* bot_updates */);
tonyp@2715 103 if (result == NULL) {
mgerdin@4853 104 result = attempt_allocation_slow(word_size,
mgerdin@4853 105 gc_count_before_ret,
mgerdin@4853 106 gclocker_retry_count_ret);
tonyp@2715 107 }
tonyp@2715 108 assert_heap_not_locked();
tonyp@2315 109 if (result != NULL) {
tonyp@2315 110 dirty_young_block(result, word_size);
tonyp@2315 111 }
tonyp@2715 112 return result;
tonyp@2454 113 }
tonyp@2454 114
tonyp@3028 115 inline HeapWord* G1CollectedHeap::survivor_attempt_allocation(size_t
tonyp@3028 116 word_size) {
tonyp@3028 117 assert(!isHumongous(word_size),
tonyp@3028 118 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 119
tonyp@3028 120 HeapWord* result = _survivor_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 121 false /* bot_updates */);
tonyp@3028 122 if (result == NULL) {
tonyp@3028 123 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 124 result = _survivor_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 125 false /* bot_updates */);
tonyp@3028 126 }
tonyp@3028 127 if (result != NULL) {
tonyp@3028 128 dirty_young_block(result, word_size);
tonyp@3028 129 }
tonyp@3028 130 return result;
tonyp@3028 131 }
tonyp@3028 132
tonyp@3028 133 inline HeapWord* G1CollectedHeap::old_attempt_allocation(size_t word_size) {
tonyp@3028 134 assert(!isHumongous(word_size),
tonyp@3028 135 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 136
tonyp@3028 137 HeapWord* result = _old_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 138 true /* bot_updates */);
tonyp@3028 139 if (result == NULL) {
tonyp@3028 140 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 141 result = _old_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 142 true /* bot_updates */);
tonyp@3028 143 }
tonyp@3028 144 return result;
tonyp@3028 145 }
tonyp@3028 146
tonyp@2315 147 // It dirties the cards that cover the block so that so that the post
tonyp@2315 148 // write barrier never queues anything when updating objects on this
tonyp@2315 149 // block. It is assumed (and in fact we assert) that the block
tonyp@2315 150 // belongs to a young region.
tonyp@2315 151 inline void
tonyp@2315 152 G1CollectedHeap::dirty_young_block(HeapWord* start, size_t word_size) {
tonyp@2315 153 assert_heap_not_locked();
tonyp@2315 154
tonyp@2315 155 // Assign the containing region to containing_hr so that we don't
tonyp@2315 156 // have to keep calling heap_region_containing_raw() in the
tonyp@2315 157 // asserts below.
tonyp@2315 158 DEBUG_ONLY(HeapRegion* containing_hr = heap_region_containing_raw(start);)
brutisso@7049 159 assert(word_size > 0, "pre-condition");
tonyp@2315 160 assert(containing_hr->is_in(start), "it should contain start");
tonyp@2315 161 assert(containing_hr->is_young(), "it should be young");
tonyp@2315 162 assert(!containing_hr->isHumongous(), "it should not be humongous");
tonyp@2315 163
tonyp@2315 164 HeapWord* end = start + word_size;
tonyp@2315 165 assert(containing_hr->is_in(end - 1), "it should also contain end - 1");
tonyp@2315 166
tonyp@2315 167 MemRegion mr(start, end);
mgerdin@5860 168 g1_barrier_set()->g1_mark_as_young(mr);
ysr@777 169 }
ysr@777 170
jcoomes@2064 171 inline RefToScanQueue* G1CollectedHeap::task_queue(int i) const {
ysr@777 172 return _task_queues->queue(i);
ysr@777 173 }
ysr@777 174
johnc@4016 175 inline bool G1CollectedHeap::isMarkedPrev(oop obj) const {
ysr@777 176 return _cm->prevMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 177 }
ysr@777 178
ysr@777 179 inline bool G1CollectedHeap::isMarkedNext(oop obj) const {
ysr@777 180 return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 181 }
stefank@2314 182
tschatzl@6541 183 // This is a fast test on whether a reference points into the
tschatzl@6541 184 // collection set or not. Assume that the reference
tschatzl@6541 185 // points into the heap.
tschatzl@7010 186 inline bool G1CollectedHeap::is_in_cset(oop obj) {
tschatzl@7010 187 bool ret = _in_cset_fast_test.is_in_cset((HeapWord*)obj);
tschatzl@6541 188 // let's make sure the result is consistent with what the slower
tschatzl@6541 189 // test returns
tschatzl@6541 190 assert( ret || !obj_in_cs(obj), "sanity");
tschatzl@6541 191 assert(!ret || obj_in_cs(obj), "sanity");
tschatzl@6541 192 return ret;
tschatzl@6541 193 }
tschatzl@6541 194
tschatzl@7010 195 bool G1CollectedHeap::is_in_cset_or_humongous(const oop obj) {
tschatzl@7010 196 return _in_cset_fast_test.is_in_cset_or_humongous((HeapWord*)obj);
tschatzl@7010 197 }
tschatzl@7010 198
tschatzl@7010 199 G1CollectedHeap::in_cset_state_t G1CollectedHeap::in_cset_state(const oop obj) {
tschatzl@7010 200 return _in_cset_fast_test.at((HeapWord*)obj);
tschatzl@7010 201 }
tschatzl@7010 202
tschatzl@7010 203 void G1CollectedHeap::register_humongous_region_with_in_cset_fast_test(uint index) {
tschatzl@7010 204 _in_cset_fast_test.set_humongous(index);
tschatzl@7010 205 }
tschatzl@7010 206
johnc@4016 207 #ifndef PRODUCT
johnc@4016 208 // Support for G1EvacuationFailureALot
johnc@4016 209
johnc@4016 210 inline bool
johnc@4016 211 G1CollectedHeap::evacuation_failure_alot_for_gc_type(bool gcs_are_young,
johnc@4016 212 bool during_initial_mark,
johnc@4016 213 bool during_marking) {
johnc@4016 214 bool res = false;
johnc@4016 215 if (during_marking) {
johnc@4016 216 res |= G1EvacuationFailureALotDuringConcMark;
johnc@4016 217 }
johnc@4016 218 if (during_initial_mark) {
johnc@4016 219 res |= G1EvacuationFailureALotDuringInitialMark;
johnc@4016 220 }
johnc@4016 221 if (gcs_are_young) {
johnc@4016 222 res |= G1EvacuationFailureALotDuringYoungGC;
johnc@4016 223 } else {
johnc@4016 224 // GCs are mixed
johnc@4016 225 res |= G1EvacuationFailureALotDuringMixedGC;
johnc@4016 226 }
johnc@4016 227 return res;
johnc@4016 228 }
johnc@4016 229
johnc@4016 230 inline void
johnc@4016 231 G1CollectedHeap::set_evacuation_failure_alot_for_current_gc() {
johnc@4016 232 if (G1EvacuationFailureALot) {
johnc@4016 233 // Note we can't assert that _evacuation_failure_alot_for_current_gc
johnc@4016 234 // is clear here. It may have been set during a previous GC but that GC
johnc@4016 235 // did not copy enough objects (i.e. G1EvacuationFailureALotCount) to
johnc@4016 236 // trigger an evacuation failure and clear the flags and and counts.
johnc@4016 237
johnc@4016 238 // Check if we have gone over the interval.
johnc@4016 239 const size_t gc_num = total_collections();
johnc@4016 240 const size_t elapsed_gcs = gc_num - _evacuation_failure_alot_gc_number;
johnc@4016 241
johnc@4016 242 _evacuation_failure_alot_for_current_gc = (elapsed_gcs >= G1EvacuationFailureALotInterval);
johnc@4016 243
johnc@4016 244 // Now check if G1EvacuationFailureALot is enabled for the current GC type.
johnc@4016 245 const bool gcs_are_young = g1_policy()->gcs_are_young();
johnc@4016 246 const bool during_im = g1_policy()->during_initial_mark_pause();
johnc@4016 247 const bool during_marking = mark_in_progress();
johnc@4016 248
johnc@4016 249 _evacuation_failure_alot_for_current_gc &=
johnc@4016 250 evacuation_failure_alot_for_gc_type(gcs_are_young,
johnc@4016 251 during_im,
johnc@4016 252 during_marking);
johnc@4016 253 }
johnc@4016 254 }
johnc@4016 255
tschatzl@7050 256 inline bool G1CollectedHeap::evacuation_should_fail() {
johnc@4016 257 if (!G1EvacuationFailureALot || !_evacuation_failure_alot_for_current_gc) {
johnc@4016 258 return false;
johnc@4016 259 }
johnc@4016 260 // G1EvacuationFailureALot is in effect for current GC
johnc@4016 261 // Access to _evacuation_failure_alot_count is not atomic;
johnc@4016 262 // the value does not have to be exact.
johnc@4016 263 if (++_evacuation_failure_alot_count < G1EvacuationFailureALotCount) {
johnc@4016 264 return false;
johnc@4016 265 }
johnc@4016 266 _evacuation_failure_alot_count = 0;
johnc@4016 267 return true;
johnc@4016 268 }
johnc@4016 269
johnc@4016 270 inline void G1CollectedHeap::reset_evacuation_should_fail() {
johnc@4016 271 if (G1EvacuationFailureALot) {
johnc@4016 272 _evacuation_failure_alot_gc_number = total_collections();
johnc@4016 273 _evacuation_failure_alot_count = 0;
johnc@4016 274 _evacuation_failure_alot_for_current_gc = false;
johnc@4016 275 }
johnc@4016 276 }
johnc@4016 277 #endif // #ifndef PRODUCT
johnc@4016 278
tschatzl@6541 279 inline bool G1CollectedHeap::is_in_young(const oop obj) {
brutisso@7049 280 if (obj == NULL) {
brutisso@7049 281 return false;
brutisso@7049 282 }
brutisso@7049 283 return heap_region_containing(obj)->is_young();
tschatzl@6541 284 }
tschatzl@6541 285
tschatzl@6541 286 // We don't need barriers for initializing stores to objects
tschatzl@6541 287 // in the young gen: for the SATB pre-barrier, there is no
tschatzl@6541 288 // pre-value that needs to be remembered; for the remembered-set
tschatzl@6541 289 // update logging post-barrier, we don't maintain remembered set
tschatzl@6541 290 // information for young gen objects.
tschatzl@6541 291 inline bool G1CollectedHeap::can_elide_initializing_store_barrier(oop new_obj) {
tschatzl@6541 292 return is_in_young(new_obj);
tschatzl@6541 293 }
tschatzl@6541 294
tschatzl@6541 295 inline bool G1CollectedHeap::is_obj_dead(const oop obj) const {
brutisso@7049 296 if (obj == NULL) {
brutisso@7049 297 return false;
tschatzl@6541 298 }
brutisso@7049 299 return is_obj_dead(obj, heap_region_containing(obj));
tschatzl@6541 300 }
tschatzl@6541 301
tschatzl@6541 302 inline bool G1CollectedHeap::is_obj_ill(const oop obj) const {
brutisso@7049 303 if (obj == NULL) {
brutisso@7049 304 return false;
tschatzl@6541 305 }
brutisso@7049 306 return is_obj_ill(obj, heap_region_containing(obj));
tschatzl@6541 307 }
tschatzl@6541 308
tschatzl@7010 309 inline void G1CollectedHeap::set_humongous_is_live(oop obj) {
tschatzl@7010 310 uint region = addr_to_region((HeapWord*)obj);
tschatzl@7010 311 // We not only set the "live" flag in the humongous_is_live table, but also
tschatzl@7010 312 // reset the entry in the _in_cset_fast_test table so that subsequent references
tschatzl@7010 313 // to the same humongous object do not go into the slow path again.
tschatzl@7010 314 // This is racy, as multiple threads may at the same time enter here, but this
tschatzl@7010 315 // is benign.
tschatzl@7010 316 // During collection we only ever set the "live" flag, and only ever clear the
tschatzl@7010 317 // entry in the in_cset_fast_table.
tschatzl@7010 318 // We only ever evaluate the contents of these tables (in the VM thread) after
tschatzl@7010 319 // having synchronized the worker threads with the VM thread, or in the same
tschatzl@7010 320 // thread (i.e. within the VM thread).
tschatzl@7010 321 if (!_humongous_is_live.is_live(region)) {
tschatzl@7010 322 _humongous_is_live.set_live(region);
tschatzl@7010 323 _in_cset_fast_test.clear_humongous(region);
tschatzl@7010 324 }
tschatzl@7010 325 }
tschatzl@7010 326
stefank@2314 327 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP

mercurial