src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp

Mon, 21 Jul 2014 09:59:46 +0200

author
tschatzl
date
Mon, 21 Jul 2014 09:59:46 +0200
changeset 7007
7df07d855c8e
parent 6989
e5035defa3c4
child 7051
1f1d373cd044
permissions
-rw-r--r--

8048085: Aborting marking just before remark results in useless additional clearing of the next mark bitmap
Summary: Skip clearing the next bitmap if we just recently aborted since the full GC already clears this bitmap.
Reviewed-by: brutisso

ysr@777 1 /*
hseigel@5784 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 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
stefank@2314 27 #include "gc_implementation/g1/heapRegion.hpp"
stefank@2314 28 #include "gc_implementation/g1/satbQueue.hpp"
stefank@2314 29 #include "runtime/mutexLocker.hpp"
goetz@6911 30 #include "runtime/orderAccess.inline.hpp"
stefank@4299 31 #include "runtime/thread.inline.hpp"
ysr@777 32
ysr@777 33 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
ysr@777 34 int max_covered_regions) :
ysr@777 35 CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
ysr@777 36 {
ysr@777 37 _kind = G1SATBCT;
ysr@777 38 }
ysr@777 39
ysr@777 40
ysr@777 41 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
johnc@2781 42 // Nulls should have been already filtered.
johnc@2781 43 assert(pre_val->is_oop(true), "Error");
johnc@2781 44
tonyp@1752 45 if (!JavaThread::satb_mark_queue_set().is_active()) return;
ysr@777 46 Thread* thr = Thread::current();
ysr@777 47 if (thr->is_Java_thread()) {
ysr@777 48 JavaThread* jt = (JavaThread*)thr;
ysr@777 49 jt->satb_mark_queue().enqueue(pre_val);
ysr@777 50 } else {
brutisso@5341 51 MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
ysr@777 52 JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
ysr@777 53 }
ysr@777 54 }
ysr@777 55
ysr@1280 56 template <class T> void
ysr@1280 57 G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
tonyp@1752 58 if (!JavaThread::satb_mark_queue_set().is_active()) return;
ysr@1280 59 T* elem_ptr = dst;
ysr@1280 60 for (int i = 0; i < count; i++, elem_ptr++) {
ysr@1280 61 T heap_oop = oopDesc::load_heap_oop(elem_ptr);
ysr@1280 62 if (!oopDesc::is_null(heap_oop)) {
ysr@1280 63 enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
ysr@1280 64 }
ysr@777 65 }
ysr@777 66 }
ysr@777 67
mgerdin@6989 68 void G1SATBCardTableModRefBS::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) {
mgerdin@6989 69 if (!dest_uninitialized) {
mgerdin@6989 70 write_ref_array_pre_work(dst, count);
mgerdin@6989 71 }
mgerdin@6989 72 }
mgerdin@6989 73 void G1SATBCardTableModRefBS::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) {
mgerdin@6989 74 if (!dest_uninitialized) {
mgerdin@6989 75 write_ref_array_pre_work(dst, count);
mgerdin@6989 76 }
mgerdin@6989 77 }
mgerdin@6989 78
mgerdin@5811 79 bool G1SATBCardTableModRefBS::mark_card_deferred(size_t card_index) {
mgerdin@5811 80 jbyte val = _byte_map[card_index];
mgerdin@5811 81 // It's already processed
mgerdin@5811 82 if ((val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val()) {
mgerdin@5811 83 return false;
mgerdin@5811 84 }
mgerdin@5860 85
mgerdin@5860 86 if (val == g1_young_gen) {
mgerdin@5860 87 // the card is for a young gen region. We don't need to keep track of all pointers into young
mgerdin@5860 88 return false;
mgerdin@5860 89 }
mgerdin@5860 90
mgerdin@5811 91 // Cached bit can be installed either on a clean card or on a claimed card.
mgerdin@5811 92 jbyte new_val = val;
mgerdin@5811 93 if (val == clean_card_val()) {
mgerdin@5811 94 new_val = (jbyte)deferred_card_val();
mgerdin@5811 95 } else {
mgerdin@5811 96 if (val & claimed_card_val()) {
mgerdin@5811 97 new_val = val | (jbyte)deferred_card_val();
mgerdin@5811 98 }
mgerdin@5811 99 }
mgerdin@5811 100 if (new_val != val) {
mgerdin@5811 101 Atomic::cmpxchg(new_val, &_byte_map[card_index], val);
mgerdin@5811 102 }
mgerdin@5811 103 return true;
mgerdin@5811 104 }
mgerdin@5811 105
mgerdin@5860 106 void G1SATBCardTableModRefBS::g1_mark_as_young(const MemRegion& mr) {
mgerdin@5860 107 jbyte *const first = byte_for(mr.start());
mgerdin@5860 108 jbyte *const last = byte_after(mr.last());
mgerdin@5860 109
pliden@6694 110 // Below we may use an explicit loop instead of memset() because on
pliden@6694 111 // certain platforms memset() can give concurrent readers phantom zeros.
pliden@6694 112 if (UseMemSetInBOT) {
pliden@6694 113 memset(first, g1_young_gen, last - first);
pliden@6694 114 } else {
pliden@6694 115 for (jbyte* i = first; i < last; i++) {
pliden@6694 116 *i = g1_young_gen;
pliden@6694 117 }
pliden@6694 118 }
mgerdin@5860 119 }
mgerdin@5860 120
mgerdin@5860 121 #ifndef PRODUCT
mgerdin@5860 122 void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
mgerdin@5860 123 verify_region(mr, g1_young_gen, true);
mgerdin@5860 124 }
mgerdin@5860 125 #endif
mgerdin@5860 126
ysr@777 127 G1SATBCardTableLoggingModRefBS::
ysr@777 128 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
ysr@777 129 int max_covered_regions) :
ysr@777 130 G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
ysr@777 131 _dcqs(JavaThread::dirty_card_queue_set())
ysr@777 132 {
ysr@777 133 _kind = G1SATBCTLogging;
ysr@777 134 }
ysr@777 135
ysr@777 136 void
ysr@777 137 G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
goetz@6493 138 oop new_val,
goetz@6493 139 bool release) {
mgerdin@5860 140 volatile jbyte* byte = byte_for(field);
mgerdin@5860 141 if (*byte == g1_young_gen) {
mgerdin@5860 142 return;
mgerdin@5860 143 }
mgerdin@5860 144 OrderAccess::storeload();
ysr@777 145 if (*byte != dirty_card) {
ysr@777 146 *byte = dirty_card;
ysr@777 147 Thread* thr = Thread::current();
ysr@777 148 if (thr->is_Java_thread()) {
ysr@777 149 JavaThread* jt = (JavaThread*)thr;
ysr@777 150 jt->dirty_card_queue().enqueue(byte);
ysr@777 151 } else {
ysr@777 152 MutexLockerEx x(Shared_DirtyCardQ_lock,
ysr@777 153 Mutex::_no_safepoint_check_flag);
ysr@777 154 _dcqs.shared_dirty_card_queue()->enqueue(byte);
ysr@777 155 }
ysr@777 156 }
ysr@777 157 }
ysr@777 158
ysr@777 159 void
ysr@777 160 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
ysr@777 161 oop new_val) {
ysr@777 162 uintptr_t field_uint = (uintptr_t)field;
hseigel@5784 163 uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
ysr@777 164 uintptr_t comb = field_uint ^ new_val_uint;
ysr@777 165 comb = comb >> HeapRegion::LogOfHRGrainBytes;
ysr@777 166 if (comb == 0) return;
ysr@777 167 if (new_val == NULL) return;
ysr@777 168 // Otherwise, log it.
ysr@777 169 G1SATBCardTableLoggingModRefBS* g1_bs =
ysr@777 170 (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
ysr@777 171 g1_bs->write_ref_field_work(field, new_val);
ysr@777 172 }
ysr@777 173
ysr@777 174 void
ysr@777 175 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
mgerdin@5860 176 volatile jbyte* byte = byte_for(mr.start());
ysr@777 177 jbyte* last_byte = byte_for(mr.last());
ysr@777 178 Thread* thr = Thread::current();
ysr@777 179 if (whole_heap) {
ysr@777 180 while (byte <= last_byte) {
ysr@777 181 *byte = dirty_card;
ysr@777 182 byte++;
ysr@777 183 }
ysr@777 184 } else {
mgerdin@5860 185 // skip all consecutive young cards
mgerdin@5860 186 for (; byte <= last_byte && *byte == g1_young_gen; byte++);
mgerdin@5860 187
mgerdin@5860 188 if (byte <= last_byte) {
mgerdin@5860 189 OrderAccess::storeload();
mgerdin@5860 190 // Enqueue if necessary.
mgerdin@5860 191 if (thr->is_Java_thread()) {
mgerdin@5860 192 JavaThread* jt = (JavaThread*)thr;
mgerdin@5860 193 for (; byte <= last_byte; byte++) {
mgerdin@5860 194 if (*byte == g1_young_gen) {
mgerdin@5860 195 continue;
mgerdin@5860 196 }
mgerdin@5860 197 if (*byte != dirty_card) {
mgerdin@5860 198 *byte = dirty_card;
mgerdin@5860 199 jt->dirty_card_queue().enqueue(byte);
mgerdin@5860 200 }
ysr@777 201 }
mgerdin@5860 202 } else {
mgerdin@5860 203 MutexLockerEx x(Shared_DirtyCardQ_lock,
mgerdin@5860 204 Mutex::_no_safepoint_check_flag);
mgerdin@5860 205 for (; byte <= last_byte; byte++) {
mgerdin@5860 206 if (*byte == g1_young_gen) {
mgerdin@5860 207 continue;
mgerdin@5860 208 }
mgerdin@5860 209 if (*byte != dirty_card) {
mgerdin@5860 210 *byte = dirty_card;
mgerdin@5860 211 _dcqs.shared_dirty_card_queue()->enqueue(byte);
mgerdin@5860 212 }
ysr@777 213 }
ysr@777 214 }
ysr@777 215 }
ysr@777 216 }
ysr@777 217 }

mercurial