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

Tue, 29 Apr 2014 15:17:27 +0200

author
goetz
date
Tue, 29 Apr 2014 15:17:27 +0200
changeset 6911
ce8f6bb717c9
parent 6680
78bbf4d43a14
child 6926
d7e2d5f2846b
permissions
-rw-r--r--

8042195: Introduce umbrella header orderAccess.inline.hpp.
Reviewed-by: dholmes, kvn, stefank, twisti

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"
tschatzl@6541 32 #include "gc_implementation/g1/g1RemSet.inline.hpp"
mgerdin@5860 33 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
brutisso@6385 34 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
tonyp@2469 35 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
goetz@6911 36 #include "runtime/orderAccess.inline.hpp"
stefank@2314 37 #include "utilities/taskqueue.hpp"
stefank@2314 38
ysr@777 39 // Inline functions for G1CollectedHeap
ysr@777 40
tschatzl@6541 41 // Return the region with the given index. It assumes the index is valid.
tschatzl@6541 42 inline HeapRegion* G1CollectedHeap::region_at(uint index) const { return _hrs.at(index); }
tschatzl@6541 43
tonyp@2963 44 template <class T>
ysr@777 45 inline HeapRegion*
tonyp@2963 46 G1CollectedHeap::heap_region_containing(const T addr) const {
tonyp@2963 47 HeapRegion* hr = _hrs.addr_to_region((HeapWord*) addr);
ysr@777 48 // hr can be null if addr in perm_gen
ysr@777 49 if (hr != NULL && hr->continuesHumongous()) {
ysr@777 50 hr = hr->humongous_start_region();
ysr@777 51 }
ysr@777 52 return hr;
ysr@777 53 }
ysr@777 54
tonyp@2963 55 template <class T>
ysr@777 56 inline HeapRegion*
tonyp@2963 57 G1CollectedHeap::heap_region_containing_raw(const T addr) const {
tonyp@2963 58 assert(_g1_reserved.contains((const void*) addr), "invariant");
tonyp@2963 59 HeapRegion* res = _hrs.addr_to_region_unsafe((HeapWord*) addr);
ysr@777 60 return res;
ysr@777 61 }
ysr@777 62
goetz@6911 63 inline void G1CollectedHeap::reset_gc_time_stamp() {
goetz@6911 64 _gc_time_stamp = 0;
goetz@6911 65 OrderAccess::fence();
goetz@6911 66 // Clear the cached CSet starting regions and time stamps.
goetz@6911 67 // Their validity is dependent on the GC timestamp.
goetz@6911 68 clear_cset_start_regions();
goetz@6911 69 }
goetz@6911 70
goetz@6911 71 inline void G1CollectedHeap::increment_gc_time_stamp() {
goetz@6911 72 ++_gc_time_stamp;
goetz@6911 73 OrderAccess::fence();
goetz@6911 74 }
goetz@6911 75
tschatzl@6541 76 inline void G1CollectedHeap::old_set_remove(HeapRegion* hr) {
tschatzl@6541 77 _old_set.remove(hr);
tschatzl@6541 78 }
tschatzl@6541 79
ysr@777 80 inline bool G1CollectedHeap::obj_in_cs(oop obj) {
tonyp@2963 81 HeapRegion* r = _hrs.addr_to_region((HeapWord*) obj);
ysr@777 82 return r != NULL && r->in_collection_set();
ysr@777 83 }
ysr@777 84
tonyp@2315 85 inline HeapWord*
tonyp@2715 86 G1CollectedHeap::attempt_allocation(size_t word_size,
mgerdin@4853 87 unsigned int* gc_count_before_ret,
mgerdin@4853 88 int* gclocker_retry_count_ret) {
tonyp@2715 89 assert_heap_not_locked_and_not_at_safepoint();
tonyp@2715 90 assert(!isHumongous(word_size), "attempt_allocation() should not "
tonyp@2715 91 "be called for humongous allocation requests");
ysr@777 92
tonyp@2715 93 HeapWord* result = _mutator_alloc_region.attempt_allocation(word_size,
tonyp@2715 94 false /* bot_updates */);
tonyp@2715 95 if (result == NULL) {
mgerdin@4853 96 result = attempt_allocation_slow(word_size,
mgerdin@4853 97 gc_count_before_ret,
mgerdin@4853 98 gclocker_retry_count_ret);
tonyp@2715 99 }
tonyp@2715 100 assert_heap_not_locked();
tonyp@2315 101 if (result != NULL) {
tonyp@2315 102 dirty_young_block(result, word_size);
tonyp@2315 103 }
tonyp@2715 104 return result;
tonyp@2454 105 }
tonyp@2454 106
tonyp@3028 107 inline HeapWord* G1CollectedHeap::survivor_attempt_allocation(size_t
tonyp@3028 108 word_size) {
tonyp@3028 109 assert(!isHumongous(word_size),
tonyp@3028 110 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 111
tonyp@3028 112 HeapWord* result = _survivor_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 113 false /* bot_updates */);
tonyp@3028 114 if (result == NULL) {
tonyp@3028 115 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 116 result = _survivor_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 117 false /* bot_updates */);
tonyp@3028 118 }
tonyp@3028 119 if (result != NULL) {
tonyp@3028 120 dirty_young_block(result, word_size);
tonyp@3028 121 }
tonyp@3028 122 return result;
tonyp@3028 123 }
tonyp@3028 124
tonyp@3028 125 inline HeapWord* G1CollectedHeap::old_attempt_allocation(size_t word_size) {
tonyp@3028 126 assert(!isHumongous(word_size),
tonyp@3028 127 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 128
tonyp@3028 129 HeapWord* result = _old_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 130 true /* bot_updates */);
tonyp@3028 131 if (result == NULL) {
tonyp@3028 132 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 133 result = _old_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 134 true /* bot_updates */);
tonyp@3028 135 }
tonyp@3028 136 return result;
tonyp@3028 137 }
tonyp@3028 138
tonyp@2315 139 // It dirties the cards that cover the block so that so that the post
tonyp@2315 140 // write barrier never queues anything when updating objects on this
tonyp@2315 141 // block. It is assumed (and in fact we assert) that the block
tonyp@2315 142 // belongs to a young region.
tonyp@2315 143 inline void
tonyp@2315 144 G1CollectedHeap::dirty_young_block(HeapWord* start, size_t word_size) {
tonyp@2315 145 assert_heap_not_locked();
tonyp@2315 146
tonyp@2315 147 // Assign the containing region to containing_hr so that we don't
tonyp@2315 148 // have to keep calling heap_region_containing_raw() in the
tonyp@2315 149 // asserts below.
tonyp@2315 150 DEBUG_ONLY(HeapRegion* containing_hr = heap_region_containing_raw(start);)
tonyp@2315 151 assert(containing_hr != NULL && start != NULL && word_size > 0,
tonyp@2315 152 "pre-condition");
tonyp@2315 153 assert(containing_hr->is_in(start), "it should contain start");
tonyp@2315 154 assert(containing_hr->is_young(), "it should be young");
tonyp@2315 155 assert(!containing_hr->isHumongous(), "it should not be humongous");
tonyp@2315 156
tonyp@2315 157 HeapWord* end = start + word_size;
tonyp@2315 158 assert(containing_hr->is_in(end - 1), "it should also contain end - 1");
tonyp@2315 159
tonyp@2315 160 MemRegion mr(start, end);
mgerdin@5860 161 g1_barrier_set()->g1_mark_as_young(mr);
ysr@777 162 }
ysr@777 163
jcoomes@2064 164 inline RefToScanQueue* G1CollectedHeap::task_queue(int i) const {
ysr@777 165 return _task_queues->queue(i);
ysr@777 166 }
ysr@777 167
johnc@4016 168 inline bool G1CollectedHeap::isMarkedPrev(oop obj) const {
ysr@777 169 return _cm->prevMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 170 }
ysr@777 171
ysr@777 172 inline bool G1CollectedHeap::isMarkedNext(oop obj) const {
ysr@777 173 return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 174 }
stefank@2314 175
tschatzl@6541 176
tschatzl@6541 177 // This is a fast test on whether a reference points into the
tschatzl@6541 178 // collection set or not. Assume that the reference
tschatzl@6541 179 // points into the heap.
tschatzl@6541 180 inline bool G1CollectedHeap::in_cset_fast_test(oop obj) {
tschatzl@6541 181 assert(_in_cset_fast_test != NULL, "sanity");
drchase@6680 182 assert(_g1_committed.contains((HeapWord*) obj), err_msg("Given reference outside of heap, is "PTR_FORMAT, p2i((HeapWord*)obj)));
tschatzl@6541 183 // no need to subtract the bottom of the heap from obj,
tschatzl@6541 184 // _in_cset_fast_test is biased
tschatzl@6541 185 uintx index = cast_from_oop<uintx>(obj) >> HeapRegion::LogOfHRGrainBytes;
tschatzl@6541 186 bool ret = _in_cset_fast_test[index];
tschatzl@6541 187 // let's make sure the result is consistent with what the slower
tschatzl@6541 188 // test returns
tschatzl@6541 189 assert( ret || !obj_in_cs(obj), "sanity");
tschatzl@6541 190 assert(!ret || obj_in_cs(obj), "sanity");
tschatzl@6541 191 return ret;
tschatzl@6541 192 }
tschatzl@6541 193
johnc@4016 194 #ifndef PRODUCT
johnc@4016 195 // Support for G1EvacuationFailureALot
johnc@4016 196
johnc@4016 197 inline bool
johnc@4016 198 G1CollectedHeap::evacuation_failure_alot_for_gc_type(bool gcs_are_young,
johnc@4016 199 bool during_initial_mark,
johnc@4016 200 bool during_marking) {
johnc@4016 201 bool res = false;
johnc@4016 202 if (during_marking) {
johnc@4016 203 res |= G1EvacuationFailureALotDuringConcMark;
johnc@4016 204 }
johnc@4016 205 if (during_initial_mark) {
johnc@4016 206 res |= G1EvacuationFailureALotDuringInitialMark;
johnc@4016 207 }
johnc@4016 208 if (gcs_are_young) {
johnc@4016 209 res |= G1EvacuationFailureALotDuringYoungGC;
johnc@4016 210 } else {
johnc@4016 211 // GCs are mixed
johnc@4016 212 res |= G1EvacuationFailureALotDuringMixedGC;
johnc@4016 213 }
johnc@4016 214 return res;
johnc@4016 215 }
johnc@4016 216
johnc@4016 217 inline void
johnc@4016 218 G1CollectedHeap::set_evacuation_failure_alot_for_current_gc() {
johnc@4016 219 if (G1EvacuationFailureALot) {
johnc@4016 220 // Note we can't assert that _evacuation_failure_alot_for_current_gc
johnc@4016 221 // is clear here. It may have been set during a previous GC but that GC
johnc@4016 222 // did not copy enough objects (i.e. G1EvacuationFailureALotCount) to
johnc@4016 223 // trigger an evacuation failure and clear the flags and and counts.
johnc@4016 224
johnc@4016 225 // Check if we have gone over the interval.
johnc@4016 226 const size_t gc_num = total_collections();
johnc@4016 227 const size_t elapsed_gcs = gc_num - _evacuation_failure_alot_gc_number;
johnc@4016 228
johnc@4016 229 _evacuation_failure_alot_for_current_gc = (elapsed_gcs >= G1EvacuationFailureALotInterval);
johnc@4016 230
johnc@4016 231 // Now check if G1EvacuationFailureALot is enabled for the current GC type.
johnc@4016 232 const bool gcs_are_young = g1_policy()->gcs_are_young();
johnc@4016 233 const bool during_im = g1_policy()->during_initial_mark_pause();
johnc@4016 234 const bool during_marking = mark_in_progress();
johnc@4016 235
johnc@4016 236 _evacuation_failure_alot_for_current_gc &=
johnc@4016 237 evacuation_failure_alot_for_gc_type(gcs_are_young,
johnc@4016 238 during_im,
johnc@4016 239 during_marking);
johnc@4016 240 }
johnc@4016 241 }
johnc@4016 242
johnc@4016 243 inline bool
johnc@4016 244 G1CollectedHeap::evacuation_should_fail() {
johnc@4016 245 if (!G1EvacuationFailureALot || !_evacuation_failure_alot_for_current_gc) {
johnc@4016 246 return false;
johnc@4016 247 }
johnc@4016 248 // G1EvacuationFailureALot is in effect for current GC
johnc@4016 249 // Access to _evacuation_failure_alot_count is not atomic;
johnc@4016 250 // the value does not have to be exact.
johnc@4016 251 if (++_evacuation_failure_alot_count < G1EvacuationFailureALotCount) {
johnc@4016 252 return false;
johnc@4016 253 }
johnc@4016 254 _evacuation_failure_alot_count = 0;
johnc@4016 255 return true;
johnc@4016 256 }
johnc@4016 257
johnc@4016 258 inline void G1CollectedHeap::reset_evacuation_should_fail() {
johnc@4016 259 if (G1EvacuationFailureALot) {
johnc@4016 260 _evacuation_failure_alot_gc_number = total_collections();
johnc@4016 261 _evacuation_failure_alot_count = 0;
johnc@4016 262 _evacuation_failure_alot_for_current_gc = false;
johnc@4016 263 }
johnc@4016 264 }
johnc@4016 265 #endif // #ifndef PRODUCT
johnc@4016 266
tschatzl@6541 267 inline bool G1CollectedHeap::is_in_young(const oop obj) {
tschatzl@6541 268 HeapRegion* hr = heap_region_containing(obj);
tschatzl@6541 269 return hr != NULL && hr->is_young();
tschatzl@6541 270 }
tschatzl@6541 271
tschatzl@6541 272 // We don't need barriers for initializing stores to objects
tschatzl@6541 273 // in the young gen: for the SATB pre-barrier, there is no
tschatzl@6541 274 // pre-value that needs to be remembered; for the remembered-set
tschatzl@6541 275 // update logging post-barrier, we don't maintain remembered set
tschatzl@6541 276 // information for young gen objects.
tschatzl@6541 277 inline bool G1CollectedHeap::can_elide_initializing_store_barrier(oop new_obj) {
tschatzl@6541 278 return is_in_young(new_obj);
tschatzl@6541 279 }
tschatzl@6541 280
tschatzl@6541 281 inline bool G1CollectedHeap::is_obj_dead(const oop obj) const {
tschatzl@6541 282 const HeapRegion* hr = heap_region_containing(obj);
tschatzl@6541 283 if (hr == NULL) {
tschatzl@6541 284 if (obj == NULL) return false;
tschatzl@6541 285 else return true;
tschatzl@6541 286 }
tschatzl@6541 287 else return is_obj_dead(obj, hr);
tschatzl@6541 288 }
tschatzl@6541 289
tschatzl@6541 290 inline bool G1CollectedHeap::is_obj_ill(const oop obj) const {
tschatzl@6541 291 const HeapRegion* hr = heap_region_containing(obj);
tschatzl@6541 292 if (hr == NULL) {
tschatzl@6541 293 if (obj == NULL) return false;
tschatzl@6541 294 else return true;
tschatzl@6541 295 }
tschatzl@6541 296 else return is_obj_ill(obj, hr);
tschatzl@6541 297 }
tschatzl@6541 298
tschatzl@6541 299 template <class T> inline void G1ParScanThreadState::immediate_rs_update(HeapRegion* from, T* p, int tid) {
tschatzl@6541 300 if (!from->is_survivor()) {
tschatzl@6541 301 _g1_rem->par_write_ref(from, p, tid);
tschatzl@6541 302 }
tschatzl@6541 303 }
tschatzl@6541 304
tschatzl@6541 305 template <class T> void G1ParScanThreadState::update_rs(HeapRegion* from, T* p, int tid) {
tschatzl@6541 306 if (G1DeferredRSUpdate) {
tschatzl@6541 307 deferred_rs_update(from, p, tid);
tschatzl@6541 308 } else {
tschatzl@6541 309 immediate_rs_update(from, p, tid);
tschatzl@6541 310 }
tschatzl@6541 311 }
tschatzl@6541 312
tschatzl@6541 313
tschatzl@6541 314 inline void G1ParScanThreadState::do_oop_partial_array(oop* p) {
tschatzl@6541 315 assert(has_partial_array_mask(p), "invariant");
tschatzl@6541 316 oop from_obj = clear_partial_array_mask(p);
tschatzl@6541 317
tschatzl@6541 318 assert(Universe::heap()->is_in_reserved(from_obj), "must be in heap.");
tschatzl@6541 319 assert(from_obj->is_objArray(), "must be obj array");
tschatzl@6541 320 objArrayOop from_obj_array = objArrayOop(from_obj);
tschatzl@6541 321 // The from-space object contains the real length.
tschatzl@6541 322 int length = from_obj_array->length();
tschatzl@6541 323
tschatzl@6541 324 assert(from_obj->is_forwarded(), "must be forwarded");
tschatzl@6541 325 oop to_obj = from_obj->forwardee();
tschatzl@6541 326 assert(from_obj != to_obj, "should not be chunking self-forwarded objects");
tschatzl@6541 327 objArrayOop to_obj_array = objArrayOop(to_obj);
tschatzl@6541 328 // We keep track of the next start index in the length field of the
tschatzl@6541 329 // to-space object.
tschatzl@6541 330 int next_index = to_obj_array->length();
tschatzl@6541 331 assert(0 <= next_index && next_index < length,
tschatzl@6541 332 err_msg("invariant, next index: %d, length: %d", next_index, length));
tschatzl@6541 333
tschatzl@6541 334 int start = next_index;
tschatzl@6541 335 int end = length;
tschatzl@6541 336 int remainder = end - start;
tschatzl@6541 337 // We'll try not to push a range that's smaller than ParGCArrayScanChunk.
tschatzl@6541 338 if (remainder > 2 * ParGCArrayScanChunk) {
tschatzl@6541 339 end = start + ParGCArrayScanChunk;
tschatzl@6541 340 to_obj_array->set_length(end);
tschatzl@6541 341 // Push the remainder before we process the range in case another
tschatzl@6541 342 // worker has run out of things to do and can steal it.
tschatzl@6541 343 oop* from_obj_p = set_partial_array_mask(from_obj);
tschatzl@6541 344 push_on_queue(from_obj_p);
tschatzl@6541 345 } else {
tschatzl@6541 346 assert(length == end, "sanity");
tschatzl@6541 347 // We'll process the final range for this object. Restore the length
tschatzl@6541 348 // so that the heap remains parsable in case of evacuation failure.
tschatzl@6541 349 to_obj_array->set_length(end);
tschatzl@6541 350 }
tschatzl@6541 351 _scanner.set_region(_g1h->heap_region_containing_raw(to_obj));
tschatzl@6541 352 // Process indexes [start,end). It will also process the header
tschatzl@6541 353 // along with the first chunk (i.e., the chunk with start == 0).
tschatzl@6541 354 // Note that at this point the length field of to_obj_array is not
tschatzl@6541 355 // correct given that we are using it to keep track of the next
tschatzl@6541 356 // start index. oop_iterate_range() (thankfully!) ignores the length
tschatzl@6541 357 // field and only relies on the start / end parameters. It does
tschatzl@6541 358 // however return the size of the object which will be incorrect. So
tschatzl@6541 359 // we have to ignore it even if we wanted to use it.
tschatzl@6541 360 to_obj_array->oop_iterate_range(&_scanner, start, end);
tschatzl@6541 361 }
tschatzl@6541 362
tschatzl@6541 363 template <class T> inline void G1ParScanThreadState::deal_with_reference(T* ref_to_scan) {
tschatzl@6541 364 if (!has_partial_array_mask(ref_to_scan)) {
tschatzl@6541 365 // Note: we can use "raw" versions of "region_containing" because
tschatzl@6541 366 // "obj_to_scan" is definitely in the heap, and is not in a
tschatzl@6541 367 // humongous region.
tschatzl@6541 368 HeapRegion* r = _g1h->heap_region_containing_raw(ref_to_scan);
tschatzl@6541 369 do_oop_evac(ref_to_scan, r);
tschatzl@6541 370 } else {
tschatzl@6541 371 do_oop_partial_array((oop*)ref_to_scan);
tschatzl@6541 372 }
tschatzl@6541 373 }
tschatzl@6541 374
tschatzl@6541 375 inline void G1ParScanThreadState::deal_with_reference(StarTask ref) {
tschatzl@6541 376 assert(verify_task(ref), "sanity");
tschatzl@6541 377 if (ref.is_narrow()) {
tschatzl@6541 378 deal_with_reference((narrowOop*)ref);
tschatzl@6541 379 } else {
tschatzl@6541 380 deal_with_reference((oop*)ref);
tschatzl@6541 381 }
tschatzl@6541 382 }
tschatzl@6541 383
stefank@2314 384 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP

mercurial