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

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7257
e7d0505c8a30
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
tschatzl@7051 26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
aoqi@0 28 #include "gc_implementation/g1/heapRegion.hpp"
aoqi@0 29 #include "gc_implementation/g1/satbQueue.hpp"
aoqi@0 30 #include "runtime/mutexLocker.hpp"
goetz@6911 31 #include "runtime/orderAccess.inline.hpp"
aoqi@0 32 #include "runtime/thread.inline.hpp"
aoqi@0 33
aoqi@0 34 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
aoqi@0 35 int max_covered_regions) :
aoqi@0 36 CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
aoqi@0 37 {
aoqi@0 38 _kind = G1SATBCT;
aoqi@0 39 }
aoqi@0 40
aoqi@0 41 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
aoqi@0 42 // Nulls should have been already filtered.
aoqi@0 43 assert(pre_val->is_oop(true), "Error");
aoqi@0 44
aoqi@0 45 if (!JavaThread::satb_mark_queue_set().is_active()) return;
aoqi@0 46 Thread* thr = Thread::current();
aoqi@0 47 if (thr->is_Java_thread()) {
aoqi@0 48 JavaThread* jt = (JavaThread*)thr;
aoqi@0 49 jt->satb_mark_queue().enqueue(pre_val);
aoqi@0 50 } else {
aoqi@0 51 MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 52 JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
aoqi@0 53 }
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 template <class T> void
aoqi@0 57 G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
aoqi@0 58 if (!JavaThread::satb_mark_queue_set().is_active()) return;
aoqi@0 59 T* elem_ptr = dst;
aoqi@0 60 for (int i = 0; i < count; i++, elem_ptr++) {
aoqi@0 61 T heap_oop = oopDesc::load_heap_oop(elem_ptr);
aoqi@0 62 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 63 enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
aoqi@0 64 }
aoqi@0 65 }
aoqi@0 66 }
aoqi@0 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
aoqi@0 79 bool G1SATBCardTableModRefBS::mark_card_deferred(size_t card_index) {
aoqi@0 80 jbyte val = _byte_map[card_index];
aoqi@0 81 // It's already processed
aoqi@0 82 if ((val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val()) {
aoqi@0 83 return false;
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 if (val == g1_young_gen) {
aoqi@0 87 // the card is for a young gen region. We don't need to keep track of all pointers into young
aoqi@0 88 return false;
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 // Cached bit can be installed either on a clean card or on a claimed card.
aoqi@0 92 jbyte new_val = val;
aoqi@0 93 if (val == clean_card_val()) {
aoqi@0 94 new_val = (jbyte)deferred_card_val();
aoqi@0 95 } else {
aoqi@0 96 if (val & claimed_card_val()) {
aoqi@0 97 new_val = val | (jbyte)deferred_card_val();
aoqi@0 98 }
aoqi@0 99 }
aoqi@0 100 if (new_val != val) {
aoqi@0 101 Atomic::cmpxchg(new_val, &_byte_map[card_index], val);
aoqi@0 102 }
aoqi@0 103 return true;
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 void G1SATBCardTableModRefBS::g1_mark_as_young(const MemRegion& mr) {
aoqi@0 107 jbyte *const first = byte_for(mr.start());
aoqi@0 108 jbyte *const last = byte_after(mr.last());
aoqi@0 109
aoqi@0 110 // Below we may use an explicit loop instead of memset() because on
aoqi@0 111 // certain platforms memset() can give concurrent readers phantom zeros.
aoqi@0 112 if (UseMemSetInBOT) {
aoqi@0 113 memset(first, g1_young_gen, last - first);
aoqi@0 114 } else {
aoqi@0 115 for (jbyte* i = first; i < last; i++) {
aoqi@0 116 *i = g1_young_gen;
aoqi@0 117 }
aoqi@0 118 }
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 #ifndef PRODUCT
aoqi@0 122 void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
aoqi@0 123 verify_region(mr, g1_young_gen, true);
aoqi@0 124 }
aoqi@0 125 #endif
aoqi@0 126
tschatzl@7257 127 void G1SATBCardTableLoggingModRefBSChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
tschatzl@7257 128 // Default value for a clean card on the card table is -1. So we cannot take advantage of the zero_filled parameter.
tschatzl@7051 129 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
tschatzl@7051 130 _card_table->clear(mr);
tschatzl@7051 131 }
tschatzl@7051 132
aoqi@0 133 G1SATBCardTableLoggingModRefBS::
aoqi@0 134 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
aoqi@0 135 int max_covered_regions) :
aoqi@0 136 G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
tschatzl@7051 137 _dcqs(JavaThread::dirty_card_queue_set()),
tschatzl@7051 138 _listener()
aoqi@0 139 {
aoqi@0 140 _kind = G1SATBCTLogging;
tschatzl@7051 141 _listener.set_card_table(this);
tschatzl@7051 142 }
tschatzl@7051 143
tschatzl@7051 144 void G1SATBCardTableLoggingModRefBS::initialize(G1RegionToSpaceMapper* mapper) {
tschatzl@7051 145 mapper->set_mapping_changed_listener(&_listener);
tschatzl@7051 146
tschatzl@7051 147 _byte_map_size = mapper->reserved().byte_size();
tschatzl@7051 148
tschatzl@7051 149 _guard_index = cards_required(_whole_heap.word_size()) - 1;
tschatzl@7051 150 _last_valid_index = _guard_index - 1;
tschatzl@7051 151
tschatzl@7051 152 HeapWord* low_bound = _whole_heap.start();
tschatzl@7051 153 HeapWord* high_bound = _whole_heap.end();
tschatzl@7051 154
tschatzl@7051 155 _cur_covered_regions = 1;
tschatzl@7051 156 _covered[0] = _whole_heap;
tschatzl@7051 157
tschatzl@7051 158 _byte_map = (jbyte*) mapper->reserved().start();
tschatzl@7051 159 byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
tschatzl@7051 160 assert(byte_for(low_bound) == &_byte_map[0], "Checking start of map");
tschatzl@7051 161 assert(byte_for(high_bound-1) <= &_byte_map[_last_valid_index], "Checking end of map");
tschatzl@7051 162
tschatzl@7051 163 if (TraceCardTableModRefBS) {
tschatzl@7051 164 gclog_or_tty->print_cr("G1SATBCardTableModRefBS::G1SATBCardTableModRefBS: ");
tschatzl@7051 165 gclog_or_tty->print_cr(" "
tschatzl@7051 166 " &_byte_map[0]: " INTPTR_FORMAT
tschatzl@7051 167 " &_byte_map[_last_valid_index]: " INTPTR_FORMAT,
tschatzl@7051 168 p2i(&_byte_map[0]),
tschatzl@7051 169 p2i(&_byte_map[_last_valid_index]));
tschatzl@7051 170 gclog_or_tty->print_cr(" "
tschatzl@7051 171 " byte_map_base: " INTPTR_FORMAT,
tschatzl@7051 172 p2i(byte_map_base));
tschatzl@7051 173 }
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 void
aoqi@0 177 G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
aoqi@0 178 oop new_val,
aoqi@0 179 bool release) {
aoqi@0 180 volatile jbyte* byte = byte_for(field);
aoqi@0 181 if (*byte == g1_young_gen) {
aoqi@0 182 return;
aoqi@0 183 }
aoqi@0 184 OrderAccess::storeload();
aoqi@0 185 if (*byte != dirty_card) {
aoqi@0 186 *byte = dirty_card;
aoqi@0 187 Thread* thr = Thread::current();
aoqi@0 188 if (thr->is_Java_thread()) {
aoqi@0 189 JavaThread* jt = (JavaThread*)thr;
aoqi@0 190 jt->dirty_card_queue().enqueue(byte);
aoqi@0 191 } else {
aoqi@0 192 MutexLockerEx x(Shared_DirtyCardQ_lock,
aoqi@0 193 Mutex::_no_safepoint_check_flag);
aoqi@0 194 _dcqs.shared_dirty_card_queue()->enqueue(byte);
aoqi@0 195 }
aoqi@0 196 }
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 void
aoqi@0 200 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
aoqi@0 201 oop new_val) {
aoqi@0 202 uintptr_t field_uint = (uintptr_t)field;
aoqi@0 203 uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
aoqi@0 204 uintptr_t comb = field_uint ^ new_val_uint;
aoqi@0 205 comb = comb >> HeapRegion::LogOfHRGrainBytes;
aoqi@0 206 if (comb == 0) return;
aoqi@0 207 if (new_val == NULL) return;
aoqi@0 208 // Otherwise, log it.
aoqi@0 209 G1SATBCardTableLoggingModRefBS* g1_bs =
aoqi@0 210 (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
aoqi@0 211 g1_bs->write_ref_field_work(field, new_val);
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 void
aoqi@0 215 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
aoqi@0 216 volatile jbyte* byte = byte_for(mr.start());
aoqi@0 217 jbyte* last_byte = byte_for(mr.last());
aoqi@0 218 Thread* thr = Thread::current();
aoqi@0 219 if (whole_heap) {
aoqi@0 220 while (byte <= last_byte) {
aoqi@0 221 *byte = dirty_card;
aoqi@0 222 byte++;
aoqi@0 223 }
aoqi@0 224 } else {
aoqi@0 225 // skip all consecutive young cards
aoqi@0 226 for (; byte <= last_byte && *byte == g1_young_gen; byte++);
aoqi@0 227
aoqi@0 228 if (byte <= last_byte) {
aoqi@0 229 OrderAccess::storeload();
aoqi@0 230 // Enqueue if necessary.
aoqi@0 231 if (thr->is_Java_thread()) {
aoqi@0 232 JavaThread* jt = (JavaThread*)thr;
aoqi@0 233 for (; byte <= last_byte; byte++) {
aoqi@0 234 if (*byte == g1_young_gen) {
aoqi@0 235 continue;
aoqi@0 236 }
aoqi@0 237 if (*byte != dirty_card) {
aoqi@0 238 *byte = dirty_card;
aoqi@0 239 jt->dirty_card_queue().enqueue(byte);
aoqi@0 240 }
aoqi@0 241 }
aoqi@0 242 } else {
aoqi@0 243 MutexLockerEx x(Shared_DirtyCardQ_lock,
aoqi@0 244 Mutex::_no_safepoint_check_flag);
aoqi@0 245 for (; byte <= last_byte; byte++) {
aoqi@0 246 if (*byte == g1_young_gen) {
aoqi@0 247 continue;
aoqi@0 248 }
aoqi@0 249 if (*byte != dirty_card) {
aoqi@0 250 *byte = dirty_card;
aoqi@0 251 _dcqs.shared_dirty_card_queue()->enqueue(byte);
aoqi@0 252 }
aoqi@0 253 }
aoqi@0 254 }
aoqi@0 255 }
aoqi@0 256 }
aoqi@0 257 }

mercurial