2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2018-01-10 22:48:27 +01:00
|
|
|
* Copyright (c) 2001, 2018, 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"
|
2018-03-06 08:36:44 +01:00
|
|
|
#include "gc/g1/g1BarrierSet.inline.hpp"
|
2018-02-26 09:34:12 +01:00
|
|
|
#include "gc/g1/g1CardTable.inline.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
|
|
|
#include "gc/g1/heapRegion.hpp"
|
2015-11-06 16:30:40 -05:00
|
|
|
#include "gc/g1/satbMarkQueue.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"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
G1BarrierSet::G1BarrierSet(G1CardTable* card_table) :
|
2018-03-19 07:38:18 +01:00
|
|
|
CardTableBarrierSet(card_table, BarrierSet::FakeRtti(BarrierSet::G1BarrierSet)),
|
2018-03-06 08:36:44 +01:00
|
|
|
_dcqs(JavaThread::dirty_card_queue_set())
|
2015-02-27 19:52:48 -05:00
|
|
|
{ }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::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
|
2018-03-06 08:36:44 +01:00
|
|
|
G1BarrierSet::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) {
|
2014-06-26 13:20:18 +02:00
|
|
|
if (!dest_uninitialized) {
|
|
|
|
write_ref_array_pre_work(dst, count);
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 13:07:44 +01:00
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) {
|
2014-06-26 13:20:18 +02:00
|
|
|
if (!dest_uninitialized) {
|
|
|
|
write_ref_array_pre_work(dst, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::write_ref_field_post_slow(volatile jbyte* byte) {
|
2017-11-20 13:07:44 +01:00
|
|
|
// In the slow path, we know a card is not young
|
2018-02-26 09:34:12 +01:00
|
|
|
assert(*byte != G1CardTable::g1_young_card_val(), "slow path invoked without filtering");
|
2013-10-08 17:35:51 +02:00
|
|
|
OrderAccess::storeload();
|
2018-02-26 09:34:12 +01:00
|
|
|
if (*byte != G1CardTable::dirty_card_val()) {
|
|
|
|
*byte = G1CardTable::dirty_card_val();
|
2008-06-05 15:57:56 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::invalidate(MemRegion mr) {
|
2017-11-23 15:51:06 +01:00
|
|
|
if (mr.is_empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-26 09:34:12 +01:00
|
|
|
volatile jbyte* byte = _card_table->byte_for(mr.start());
|
|
|
|
jbyte* last_byte = _card_table->byte_for(mr.last());
|
2008-06-05 15:57:56 -07:00
|
|
|
Thread* thr = Thread::current();
|
2013-10-08 17:35:51 +02:00
|
|
|
// skip all consecutive young cards
|
2018-02-26 09:34:12 +01:00
|
|
|
for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val(); byte++);
|
2016-11-24 16:48:22 +03:00
|
|
|
|
|
|
|
if (byte <= last_byte) {
|
|
|
|
OrderAccess::storeload();
|
|
|
|
// Enqueue if necessary.
|
|
|
|
if (thr->is_Java_thread()) {
|
|
|
|
JavaThread* jt = (JavaThread*)thr;
|
|
|
|
for (; byte <= last_byte; byte++) {
|
2018-02-26 09:34:12 +01:00
|
|
|
if (*byte == G1CardTable::g1_young_card_val()) {
|
2016-11-24 16:48:22 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-26 09:34:12 +01:00
|
|
|
if (*byte != G1CardTable::dirty_card_val()) {
|
|
|
|
*byte = G1CardTable::dirty_card_val();
|
2016-11-24 16:48:22 +03:00
|
|
|
jt->dirty_card_queue().enqueue(byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MutexLockerEx x(Shared_DirtyCardQ_lock,
|
|
|
|
Mutex::_no_safepoint_check_flag);
|
|
|
|
for (; byte <= last_byte; byte++) {
|
2018-02-26 09:34:12 +01:00
|
|
|
if (*byte == G1CardTable::g1_young_card_val()) {
|
2016-11-24 16:48:22 +03:00
|
|
|
continue;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2018-02-26 09:34:12 +01:00
|
|
|
if (*byte != G1CardTable::dirty_card_val()) {
|
|
|
|
*byte = G1CardTable::dirty_card_val();
|
2016-11-24 16:48:22 +03:00
|
|
|
_dcqs.shared_dirty_card_queue()->enqueue(byte);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 22:48:27 +01:00
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::on_thread_attach(JavaThread* thread) {
|
2018-02-16 12:18:09 +01:00
|
|
|
// This method initializes the SATB and dirty card queues before a
|
|
|
|
// JavaThread is added to the Java thread list. Right now, we don't
|
|
|
|
// have to do anything to the dirty card queue (it should have been
|
|
|
|
// activated when the thread was created), but we have to activate
|
|
|
|
// the SATB queue if the thread is created while a marking cycle is
|
|
|
|
// in progress. The activation / de-activation of the SATB queues at
|
|
|
|
// the beginning / end of a marking cycle is done during safepoints
|
|
|
|
// so we have to make sure this method is called outside one to be
|
|
|
|
// able to safely read the active field of the SATB queue set. Right
|
|
|
|
// now, it is called just before the thread is added to the Java
|
|
|
|
// thread list in the Threads::add() method. That method is holding
|
|
|
|
// the Threads_lock which ensures we are outside a safepoint. We
|
|
|
|
// cannot do the obvious and set the active field of the SATB queue
|
|
|
|
// when the thread is created given that, in some cases, safepoints
|
|
|
|
// might happen between the JavaThread constructor being called and the
|
|
|
|
// thread being added to the Java thread list (an example of this is
|
|
|
|
// when the structure for the DestroyJavaVM thread is created).
|
|
|
|
assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
|
|
|
|
assert(!thread->satb_mark_queue().is_active(), "SATB queue should not be active");
|
|
|
|
assert(thread->satb_mark_queue().is_empty(), "SATB queue should be empty");
|
|
|
|
assert(thread->dirty_card_queue().is_active(), "Dirty card queue should be active");
|
|
|
|
|
|
|
|
// If we are creating the thread during a marking cycle, we should
|
|
|
|
// set the active field of the SATB queue to true.
|
|
|
|
if (thread->satb_mark_queue_set().is_active()) {
|
|
|
|
thread->satb_mark_queue().set_active(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:36:44 +01:00
|
|
|
void G1BarrierSet::on_thread_detach(JavaThread* thread) {
|
2018-02-16 12:18:09 +01:00
|
|
|
// Flush any deferred card marks, SATB buffers and dirty card queue buffers
|
2018-03-19 07:38:18 +01:00
|
|
|
CardTableBarrierSet::on_thread_detach(thread);
|
2018-01-10 22:48:27 +01:00
|
|
|
thread->satb_mark_queue().flush();
|
|
|
|
thread->dirty_card_queue().flush();
|
|
|
|
}
|