2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2017-08-23 14:52:55 -04:00
|
|
|
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
|
2008-06-05 15:57:56 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2008-06-05 15:57:56 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
2016-01-18 10:25:41 +01:00
|
|
|
#include "gc/g1/g1SATBCardTableModRefBS.inline.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/heapRegion.hpp"
|
2015-11-06 16:30:40 -05:00
|
|
|
#include "gc/g1/satbMarkQueue.hpp"
|
2015-08-31 13:06:01 -04:00
|
|
|
#include "gc/shared/memset_with_concurrent_readers.hpp"
|
2015-12-10 14:57:55 +01:00
|
|
|
#include "logging/log.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "oops/oop.inline.hpp"
|
2016-08-21 20:56:37 -04:00
|
|
|
#include "runtime/atomic.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2014-04-29 15:17:27 +02:00
|
|
|
#include "runtime/orderAccess.inline.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2015-02-27 19:52:48 -05:00
|
|
|
G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(
|
|
|
|
MemRegion whole_heap,
|
|
|
|
const BarrierSet::FakeRtti& fake_rtti) :
|
|
|
|
CardTableModRefBS(whole_heap, fake_rtti.add_tag(BarrierSet::G1SATBCT))
|
|
|
|
{ }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
|
2011-04-07 09:53:20 -07:00
|
|
|
// Nulls should have been already filtered.
|
2017-08-23 14:52:55 -04:00
|
|
|
assert(oopDesc::is_oop(pre_val, true), "Error");
|
2011-04-07 09:53:20 -07:00
|
|
|
|
2010-03-18 12:14:59 -04:00
|
|
|
if (!JavaThread::satb_mark_queue_set().is_active()) return;
|
2008-06-05 15:57:56 -07:00
|
|
|
Thread* thr = Thread::current();
|
|
|
|
if (thr->is_Java_thread()) {
|
|
|
|
JavaThread* jt = (JavaThread*)thr;
|
|
|
|
jt->satb_mark_queue().enqueue(pre_val);
|
|
|
|
} else {
|
2013-06-30 21:42:07 +02:00
|
|
|
MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
|
2008-06-05 15:57:56 -07:00
|
|
|
JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-14 15:40:39 -07:00
|
|
|
template <class T> void
|
|
|
|
G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
|
2010-03-18 12:14:59 -04:00
|
|
|
if (!JavaThread::satb_mark_queue_set().is_active()) return;
|
2009-07-14 15:40:39 -07:00
|
|
|
T* elem_ptr = dst;
|
|
|
|
for (int i = 0; i < count; i++, elem_ptr++) {
|
|
|
|
T heap_oop = oopDesc::load_heap_oop(elem_ptr);
|
|
|
|
if (!oopDesc::is_null(heap_oop)) {
|
|
|
|
enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 13:20:18 +02:00
|
|
|
void G1SATBCardTableModRefBS::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) {
|
|
|
|
if (!dest_uninitialized) {
|
|
|
|
write_ref_array_pre_work(dst, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void G1SATBCardTableModRefBS::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) {
|
|
|
|
if (!dest_uninitialized) {
|
|
|
|
write_ref_array_pre_work(dst, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:46:29 +02:00
|
|
|
bool G1SATBCardTableModRefBS::mark_card_deferred(size_t card_index) {
|
|
|
|
jbyte val = _byte_map[card_index];
|
|
|
|
// It's already processed
|
|
|
|
if ((val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-08 17:35:51 +02:00
|
|
|
|
2013-09-24 14:46:29 +02:00
|
|
|
// Cached bit can be installed either on a clean card or on a claimed card.
|
|
|
|
jbyte new_val = val;
|
|
|
|
if (val == clean_card_val()) {
|
|
|
|
new_val = (jbyte)deferred_card_val();
|
|
|
|
} else {
|
|
|
|
if (val & claimed_card_val()) {
|
|
|
|
new_val = val | (jbyte)deferred_card_val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (new_val != val) {
|
|
|
|
Atomic::cmpxchg(new_val, &_byte_map[card_index], val);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-08 17:35:51 +02:00
|
|
|
void G1SATBCardTableModRefBS::g1_mark_as_young(const MemRegion& mr) {
|
|
|
|
jbyte *const first = byte_for(mr.start());
|
|
|
|
jbyte *const last = byte_after(mr.last());
|
|
|
|
|
2015-08-31 13:06:01 -04:00
|
|
|
memset_with_concurrent_readers(first, g1_young_gen, last - first);
|
2013-10-08 17:35:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
|
|
|
|
verify_region(mr, g1_young_gen, true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-09 11:40:11 +02:00
|
|
|
void G1SATBCardTableLoggingModRefBSChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
|
|
|
|
// Default value for a clean card on the card table is -1. So we cannot take advantage of the zero_filled parameter.
|
2014-08-19 14:09:10 +02:00
|
|
|
MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
|
|
|
|
_card_table->clear(mr);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
G1SATBCardTableLoggingModRefBS::
|
2014-11-18 10:36:42 +01:00
|
|
|
G1SATBCardTableLoggingModRefBS(MemRegion whole_heap) :
|
2015-02-27 19:52:48 -05:00
|
|
|
G1SATBCardTableModRefBS(whole_heap, BarrierSet::FakeRtti(G1SATBCTLogging)),
|
2014-08-19 14:09:10 +02:00
|
|
|
_dcqs(JavaThread::dirty_card_queue_set()),
|
|
|
|
_listener()
|
2008-06-05 15:57:56 -07:00
|
|
|
{
|
2014-08-19 14:09:10 +02:00
|
|
|
_listener.set_card_table(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void G1SATBCardTableLoggingModRefBS::initialize(G1RegionToSpaceMapper* mapper) {
|
|
|
|
mapper->set_mapping_changed_listener(&_listener);
|
|
|
|
|
|
|
|
_byte_map_size = mapper->reserved().byte_size();
|
|
|
|
|
|
|
|
_guard_index = cards_required(_whole_heap.word_size()) - 1;
|
|
|
|
_last_valid_index = _guard_index - 1;
|
|
|
|
|
|
|
|
HeapWord* low_bound = _whole_heap.start();
|
|
|
|
HeapWord* high_bound = _whole_heap.end();
|
|
|
|
|
|
|
|
_cur_covered_regions = 1;
|
|
|
|
_covered[0] = _whole_heap;
|
|
|
|
|
|
|
|
_byte_map = (jbyte*) mapper->reserved().start();
|
|
|
|
byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
|
|
|
|
assert(byte_for(low_bound) == &_byte_map[0], "Checking start of map");
|
|
|
|
assert(byte_for(high_bound-1) <= &_byte_map[_last_valid_index], "Checking end of map");
|
|
|
|
|
2015-12-10 14:57:55 +01:00
|
|
|
log_trace(gc, barrier)("G1SATBCardTableModRefBS::G1SATBCardTableModRefBS: ");
|
|
|
|
log_trace(gc, barrier)(" &_byte_map[0]: " INTPTR_FORMAT " &_byte_map[_last_valid_index]: " INTPTR_FORMAT,
|
|
|
|
p2i(&_byte_map[0]), p2i(&_byte_map[_last_valid_index]));
|
|
|
|
log_trace(gc, barrier)(" byte_map_base: " INTPTR_FORMAT, p2i(byte_map_base));
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
G1SATBCardTableLoggingModRefBS::write_ref_field_work(void* field,
|
2013-12-02 10:26:14 +01:00
|
|
|
oop new_val,
|
|
|
|
bool release) {
|
2013-10-08 17:35:51 +02:00
|
|
|
volatile jbyte* byte = byte_for(field);
|
|
|
|
if (*byte == g1_young_gen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OrderAccess::storeload();
|
2008-06-05 15:57:56 -07:00
|
|
|
if (*byte != dirty_card) {
|
|
|
|
*byte = dirty_card;
|
|
|
|
Thread* thr = Thread::current();
|
|
|
|
if (thr->is_Java_thread()) {
|
|
|
|
JavaThread* jt = (JavaThread*)thr;
|
|
|
|
jt->dirty_card_queue().enqueue(byte);
|
|
|
|
} else {
|
|
|
|
MutexLockerEx x(Shared_DirtyCardQ_lock,
|
|
|
|
Mutex::_no_safepoint_check_flag);
|
|
|
|
_dcqs.shared_dirty_card_queue()->enqueue(byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-24 16:48:22 +03:00
|
|
|
G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr) {
|
2013-10-08 17:35:51 +02:00
|
|
|
volatile jbyte* byte = byte_for(mr.start());
|
2008-06-05 15:57:56 -07:00
|
|
|
jbyte* last_byte = byte_for(mr.last());
|
|
|
|
Thread* thr = Thread::current();
|
2013-10-08 17:35:51 +02:00
|
|
|
// skip all consecutive young cards
|
2016-11-24 16:48:22 +03:00
|
|
|
for (; byte <= last_byte && *byte == g1_young_gen; byte++);
|
|
|
|
|
|
|
|
if (byte <= last_byte) {
|
|
|
|
OrderAccess::storeload();
|
|
|
|
// Enqueue if necessary.
|
|
|
|
if (thr->is_Java_thread()) {
|
|
|
|
JavaThread* jt = (JavaThread*)thr;
|
|
|
|
for (; byte <= last_byte; byte++) {
|
|
|
|
if (*byte == g1_young_gen) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*byte != dirty_card) {
|
|
|
|
*byte = dirty_card;
|
|
|
|
jt->dirty_card_queue().enqueue(byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MutexLockerEx x(Shared_DirtyCardQ_lock,
|
|
|
|
Mutex::_no_safepoint_check_flag);
|
|
|
|
for (; byte <= last_byte; byte++) {
|
|
|
|
if (*byte == g1_young_gen) {
|
|
|
|
continue;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2016-11-24 16:48:22 +03:00
|
|
|
if (*byte != dirty_card) {
|
|
|
|
*byte = dirty_card;
|
|
|
|
_dcqs.shared_dirty_card_queue()->enqueue(byte);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|