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

Mon, 24 Mar 2014 15:30:14 +0100

author
tschatzl
date
Mon, 24 Mar 2014 15:30:14 +0100
changeset 6402
191174b49bec
parent 6385
58fc1b1523dc
child 6541
bfdf528be8e8
permissions
-rw-r--r--

8035406: Improve data structure for Code Cache remembered sets
Summary: Change the code cache remembered sets data structure from a GrowableArray to a chunked list of nmethods. This makes the data structure more amenable to parallelization, and decreases freeing time.
Reviewed-by: mgerdin, brutisso

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

mercurial