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

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 7257
e7d0505c8a30
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

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"
tschatzl@7051 26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@2314 27 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
stefank@2314 28 #include "gc_implementation/g1/heapRegion.hpp"
stefank@2314 29 #include "gc_implementation/g1/satbQueue.hpp"
stefank@2314 30 #include "runtime/mutexLocker.hpp"
goetz@6911 31 #include "runtime/orderAccess.inline.hpp"
stefank@4299 32 #include "runtime/thread.inline.hpp"
ysr@777 33
ysr@777 34 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
ysr@777 35 int max_covered_regions) :
ysr@777 36 CardTableModRefBSForCTRS(whole_heap, max_covered_regions)
ysr@777 37 {
ysr@777 38 _kind = G1SATBCT;
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
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
ysr@777 133 G1SATBCardTableLoggingModRefBS::
ysr@777 134 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
ysr@777 135 int max_covered_regions) :
ysr@777 136 G1SATBCardTableModRefBS(whole_heap, max_covered_regions),
tschatzl@7051 137 _dcqs(JavaThread::dirty_card_queue_set()),
tschatzl@7051 138 _listener()
ysr@777 139 {
ysr@777 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 }
ysr@777 174 }
ysr@777 175
ysr@777 176 void
ysr@777 177 G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
goetz@6493 178 oop new_val,
goetz@6493 179 bool release) {
mgerdin@5860 180 volatile jbyte* byte = byte_for(field);
mgerdin@5860 181 if (*byte == g1_young_gen) {
mgerdin@5860 182 return;
mgerdin@5860 183 }
mgerdin@5860 184 OrderAccess::storeload();
ysr@777 185 if (*byte != dirty_card) {
ysr@777 186 *byte = dirty_card;
ysr@777 187 Thread* thr = Thread::current();
ysr@777 188 if (thr->is_Java_thread()) {
ysr@777 189 JavaThread* jt = (JavaThread*)thr;
ysr@777 190 jt->dirty_card_queue().enqueue(byte);
ysr@777 191 } else {
ysr@777 192 MutexLockerEx x(Shared_DirtyCardQ_lock,
ysr@777 193 Mutex::_no_safepoint_check_flag);
ysr@777 194 _dcqs.shared_dirty_card_queue()->enqueue(byte);
ysr@777 195 }
ysr@777 196 }
ysr@777 197 }
ysr@777 198
ysr@777 199 void
ysr@777 200 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
ysr@777 201 oop new_val) {
ysr@777 202 uintptr_t field_uint = (uintptr_t)field;
hseigel@5784 203 uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
ysr@777 204 uintptr_t comb = field_uint ^ new_val_uint;
ysr@777 205 comb = comb >> HeapRegion::LogOfHRGrainBytes;
ysr@777 206 if (comb == 0) return;
ysr@777 207 if (new_val == NULL) return;
ysr@777 208 // Otherwise, log it.
ysr@777 209 G1SATBCardTableLoggingModRefBS* g1_bs =
ysr@777 210 (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
ysr@777 211 g1_bs->write_ref_field_work(field, new_val);
ysr@777 212 }
ysr@777 213
ysr@777 214 void
ysr@777 215 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
mgerdin@5860 216 volatile jbyte* byte = byte_for(mr.start());
ysr@777 217 jbyte* last_byte = byte_for(mr.last());
ysr@777 218 Thread* thr = Thread::current();
ysr@777 219 if (whole_heap) {
ysr@777 220 while (byte <= last_byte) {
ysr@777 221 *byte = dirty_card;
ysr@777 222 byte++;
ysr@777 223 }
ysr@777 224 } else {
mgerdin@5860 225 // skip all consecutive young cards
mgerdin@5860 226 for (; byte <= last_byte && *byte == g1_young_gen; byte++);
mgerdin@5860 227
mgerdin@5860 228 if (byte <= last_byte) {
mgerdin@5860 229 OrderAccess::storeload();
mgerdin@5860 230 // Enqueue if necessary.
mgerdin@5860 231 if (thr->is_Java_thread()) {
mgerdin@5860 232 JavaThread* jt = (JavaThread*)thr;
mgerdin@5860 233 for (; byte <= last_byte; byte++) {
mgerdin@5860 234 if (*byte == g1_young_gen) {
mgerdin@5860 235 continue;
mgerdin@5860 236 }
mgerdin@5860 237 if (*byte != dirty_card) {
mgerdin@5860 238 *byte = dirty_card;
mgerdin@5860 239 jt->dirty_card_queue().enqueue(byte);
mgerdin@5860 240 }
ysr@777 241 }
mgerdin@5860 242 } else {
mgerdin@5860 243 MutexLockerEx x(Shared_DirtyCardQ_lock,
mgerdin@5860 244 Mutex::_no_safepoint_check_flag);
mgerdin@5860 245 for (; byte <= last_byte; byte++) {
mgerdin@5860 246 if (*byte == g1_young_gen) {
mgerdin@5860 247 continue;
mgerdin@5860 248 }
mgerdin@5860 249 if (*byte != dirty_card) {
mgerdin@5860 250 *byte = dirty_card;
mgerdin@5860 251 _dcqs.shared_dirty_card_queue()->enqueue(byte);
mgerdin@5860 252 }
ysr@777 253 }
ysr@777 254 }
ysr@777 255 }
ysr@777 256 }
ysr@777 257 }

mercurial