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

Tue, 08 Oct 2013 17:35:51 +0200

author
mgerdin
date
Tue, 08 Oct 2013 17:35:51 +0200
changeset 5860
69944b868a32
parent 5811
d55c004e1d4d
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8014555: G1: Memory ordering problem with Conc refinement and card marking
Summary: Add a StoreLoad barrier in the G1 post-barrier to fix a race with concurrent refinement. Also-reviewed-by: martin.doerr@sap.com
Reviewed-by: iveresov, tschatzl, brutisso, roland, kvn

ysr@777 1 /*
johnc@4016 2 * Copyright (c) 2001, 2012, 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"
tonyp@2469 33 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@2314 34 #include "utilities/taskqueue.hpp"
stefank@2314 35
ysr@777 36 // Inline functions for G1CollectedHeap
ysr@777 37
tonyp@2963 38 template <class T>
ysr@777 39 inline HeapRegion*
tonyp@2963 40 G1CollectedHeap::heap_region_containing(const T addr) const {
tonyp@2963 41 HeapRegion* hr = _hrs.addr_to_region((HeapWord*) addr);
ysr@777 42 // hr can be null if addr in perm_gen
ysr@777 43 if (hr != NULL && hr->continuesHumongous()) {
ysr@777 44 hr = hr->humongous_start_region();
ysr@777 45 }
ysr@777 46 return hr;
ysr@777 47 }
ysr@777 48
tonyp@2963 49 template <class T>
ysr@777 50 inline HeapRegion*
tonyp@2963 51 G1CollectedHeap::heap_region_containing_raw(const T addr) const {
tonyp@2963 52 assert(_g1_reserved.contains((const void*) addr), "invariant");
tonyp@2963 53 HeapRegion* res = _hrs.addr_to_region_unsafe((HeapWord*) addr);
ysr@777 54 return res;
ysr@777 55 }
ysr@777 56
ysr@777 57 inline bool G1CollectedHeap::obj_in_cs(oop obj) {
tonyp@2963 58 HeapRegion* r = _hrs.addr_to_region((HeapWord*) obj);
ysr@777 59 return r != NULL && r->in_collection_set();
ysr@777 60 }
ysr@777 61
tonyp@2315 62 inline HeapWord*
tonyp@2715 63 G1CollectedHeap::attempt_allocation(size_t word_size,
mgerdin@4853 64 unsigned int* gc_count_before_ret,
mgerdin@4853 65 int* gclocker_retry_count_ret) {
tonyp@2715 66 assert_heap_not_locked_and_not_at_safepoint();
tonyp@2715 67 assert(!isHumongous(word_size), "attempt_allocation() should not "
tonyp@2715 68 "be called for humongous allocation requests");
ysr@777 69
tonyp@2715 70 HeapWord* result = _mutator_alloc_region.attempt_allocation(word_size,
tonyp@2715 71 false /* bot_updates */);
tonyp@2715 72 if (result == NULL) {
mgerdin@4853 73 result = attempt_allocation_slow(word_size,
mgerdin@4853 74 gc_count_before_ret,
mgerdin@4853 75 gclocker_retry_count_ret);
tonyp@2715 76 }
tonyp@2715 77 assert_heap_not_locked();
tonyp@2315 78 if (result != NULL) {
tonyp@2315 79 dirty_young_block(result, word_size);
tonyp@2315 80 }
tonyp@2715 81 return result;
tonyp@2454 82 }
tonyp@2454 83
tonyp@3028 84 inline HeapWord* G1CollectedHeap::survivor_attempt_allocation(size_t
tonyp@3028 85 word_size) {
tonyp@3028 86 assert(!isHumongous(word_size),
tonyp@3028 87 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 88
tonyp@3028 89 HeapWord* result = _survivor_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 90 false /* bot_updates */);
tonyp@3028 91 if (result == NULL) {
tonyp@3028 92 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 93 result = _survivor_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 94 false /* bot_updates */);
tonyp@3028 95 }
tonyp@3028 96 if (result != NULL) {
tonyp@3028 97 dirty_young_block(result, word_size);
tonyp@3028 98 }
tonyp@3028 99 return result;
tonyp@3028 100 }
tonyp@3028 101
tonyp@3028 102 inline HeapWord* G1CollectedHeap::old_attempt_allocation(size_t word_size) {
tonyp@3028 103 assert(!isHumongous(word_size),
tonyp@3028 104 "we should not be seeing humongous-size allocations in this path");
tonyp@3028 105
tonyp@3028 106 HeapWord* result = _old_gc_alloc_region.attempt_allocation(word_size,
tonyp@3028 107 true /* bot_updates */);
tonyp@3028 108 if (result == NULL) {
tonyp@3028 109 MutexLockerEx x(FreeList_lock, Mutex::_no_safepoint_check_flag);
tonyp@3028 110 result = _old_gc_alloc_region.attempt_allocation_locked(word_size,
tonyp@3028 111 true /* bot_updates */);
tonyp@3028 112 }
tonyp@3028 113 return result;
tonyp@3028 114 }
tonyp@3028 115
tonyp@2315 116 // It dirties the cards that cover the block so that so that the post
tonyp@2315 117 // write barrier never queues anything when updating objects on this
tonyp@2315 118 // block. It is assumed (and in fact we assert) that the block
tonyp@2315 119 // belongs to a young region.
tonyp@2315 120 inline void
tonyp@2315 121 G1CollectedHeap::dirty_young_block(HeapWord* start, size_t word_size) {
tonyp@2315 122 assert_heap_not_locked();
tonyp@2315 123
tonyp@2315 124 // Assign the containing region to containing_hr so that we don't
tonyp@2315 125 // have to keep calling heap_region_containing_raw() in the
tonyp@2315 126 // asserts below.
tonyp@2315 127 DEBUG_ONLY(HeapRegion* containing_hr = heap_region_containing_raw(start);)
tonyp@2315 128 assert(containing_hr != NULL && start != NULL && word_size > 0,
tonyp@2315 129 "pre-condition");
tonyp@2315 130 assert(containing_hr->is_in(start), "it should contain start");
tonyp@2315 131 assert(containing_hr->is_young(), "it should be young");
tonyp@2315 132 assert(!containing_hr->isHumongous(), "it should not be humongous");
tonyp@2315 133
tonyp@2315 134 HeapWord* end = start + word_size;
tonyp@2315 135 assert(containing_hr->is_in(end - 1), "it should also contain end - 1");
tonyp@2315 136
tonyp@2315 137 MemRegion mr(start, end);
mgerdin@5860 138 g1_barrier_set()->g1_mark_as_young(mr);
ysr@777 139 }
ysr@777 140
jcoomes@2064 141 inline RefToScanQueue* G1CollectedHeap::task_queue(int i) const {
ysr@777 142 return _task_queues->queue(i);
ysr@777 143 }
ysr@777 144
johnc@4016 145 inline bool G1CollectedHeap::isMarkedPrev(oop obj) const {
ysr@777 146 return _cm->prevMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 147 }
ysr@777 148
ysr@777 149 inline bool G1CollectedHeap::isMarkedNext(oop obj) const {
ysr@777 150 return _cm->nextMarkBitMap()->isMarked((HeapWord *)obj);
ysr@777 151 }
stefank@2314 152
johnc@4016 153 #ifndef PRODUCT
johnc@4016 154 // Support for G1EvacuationFailureALot
johnc@4016 155
johnc@4016 156 inline bool
johnc@4016 157 G1CollectedHeap::evacuation_failure_alot_for_gc_type(bool gcs_are_young,
johnc@4016 158 bool during_initial_mark,
johnc@4016 159 bool during_marking) {
johnc@4016 160 bool res = false;
johnc@4016 161 if (during_marking) {
johnc@4016 162 res |= G1EvacuationFailureALotDuringConcMark;
johnc@4016 163 }
johnc@4016 164 if (during_initial_mark) {
johnc@4016 165 res |= G1EvacuationFailureALotDuringInitialMark;
johnc@4016 166 }
johnc@4016 167 if (gcs_are_young) {
johnc@4016 168 res |= G1EvacuationFailureALotDuringYoungGC;
johnc@4016 169 } else {
johnc@4016 170 // GCs are mixed
johnc@4016 171 res |= G1EvacuationFailureALotDuringMixedGC;
johnc@4016 172 }
johnc@4016 173 return res;
johnc@4016 174 }
johnc@4016 175
johnc@4016 176 inline void
johnc@4016 177 G1CollectedHeap::set_evacuation_failure_alot_for_current_gc() {
johnc@4016 178 if (G1EvacuationFailureALot) {
johnc@4016 179 // Note we can't assert that _evacuation_failure_alot_for_current_gc
johnc@4016 180 // is clear here. It may have been set during a previous GC but that GC
johnc@4016 181 // did not copy enough objects (i.e. G1EvacuationFailureALotCount) to
johnc@4016 182 // trigger an evacuation failure and clear the flags and and counts.
johnc@4016 183
johnc@4016 184 // Check if we have gone over the interval.
johnc@4016 185 const size_t gc_num = total_collections();
johnc@4016 186 const size_t elapsed_gcs = gc_num - _evacuation_failure_alot_gc_number;
johnc@4016 187
johnc@4016 188 _evacuation_failure_alot_for_current_gc = (elapsed_gcs >= G1EvacuationFailureALotInterval);
johnc@4016 189
johnc@4016 190 // Now check if G1EvacuationFailureALot is enabled for the current GC type.
johnc@4016 191 const bool gcs_are_young = g1_policy()->gcs_are_young();
johnc@4016 192 const bool during_im = g1_policy()->during_initial_mark_pause();
johnc@4016 193 const bool during_marking = mark_in_progress();
johnc@4016 194
johnc@4016 195 _evacuation_failure_alot_for_current_gc &=
johnc@4016 196 evacuation_failure_alot_for_gc_type(gcs_are_young,
johnc@4016 197 during_im,
johnc@4016 198 during_marking);
johnc@4016 199 }
johnc@4016 200 }
johnc@4016 201
johnc@4016 202 inline bool
johnc@4016 203 G1CollectedHeap::evacuation_should_fail() {
johnc@4016 204 if (!G1EvacuationFailureALot || !_evacuation_failure_alot_for_current_gc) {
johnc@4016 205 return false;
johnc@4016 206 }
johnc@4016 207 // G1EvacuationFailureALot is in effect for current GC
johnc@4016 208 // Access to _evacuation_failure_alot_count is not atomic;
johnc@4016 209 // the value does not have to be exact.
johnc@4016 210 if (++_evacuation_failure_alot_count < G1EvacuationFailureALotCount) {
johnc@4016 211 return false;
johnc@4016 212 }
johnc@4016 213 _evacuation_failure_alot_count = 0;
johnc@4016 214 return true;
johnc@4016 215 }
johnc@4016 216
johnc@4016 217 inline void G1CollectedHeap::reset_evacuation_should_fail() {
johnc@4016 218 if (G1EvacuationFailureALot) {
johnc@4016 219 _evacuation_failure_alot_gc_number = total_collections();
johnc@4016 220 _evacuation_failure_alot_count = 0;
johnc@4016 221 _evacuation_failure_alot_for_current_gc = false;
johnc@4016 222 }
johnc@4016 223 }
johnc@4016 224 #endif // #ifndef PRODUCT
johnc@4016 225
stefank@2314 226 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTEDHEAP_INLINE_HPP

mercurial