2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2018-02-16 12:18:09 +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-08-18 13:59:25 -04:00
|
|
|
#include "gc/shared/satbMarkQueue.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/collectedHeap.hpp"
|
2018-08-14 00:15:56 -04:00
|
|
|
#include "logging/log.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.inline.hpp"
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "oops/oop.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2018-08-14 14:58:14 -04:00
|
|
|
#include "runtime/os.hpp"
|
2015-05-01 17:38:12 -04:00
|
|
|
#include "runtime/safepoint.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/thread.hpp"
|
2017-11-22 17:54:50 -08:00
|
|
|
#include "runtime/threadSMR.hpp"
|
2011-09-22 10:57:37 -07:00
|
|
|
#include "runtime/vmThread.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2015-11-06 16:30:40 -05:00
|
|
|
SATBMarkQueue::SATBMarkQueue(SATBMarkQueueSet* qset, bool permanent) :
|
2015-11-04 13:09:57 -05:00
|
|
|
// SATB queues are only active during marking cycles. We create
|
|
|
|
// them with their active field set to false. If a thread is
|
|
|
|
// created during a cycle and its SATB queue needs to be activated
|
|
|
|
// before the thread starts running, we'll need to set its active
|
2018-08-14 13:16:26 -04:00
|
|
|
// field to true. This must be done in the collector-specific
|
|
|
|
// BarrierSet::on_thread_attach() implementation.
|
2015-11-04 13:09:57 -05:00
|
|
|
PtrQueue(qset, permanent, false /* active */)
|
|
|
|
{ }
|
|
|
|
|
2015-11-06 16:30:40 -05:00
|
|
|
void SATBMarkQueue::flush() {
|
2015-04-15 16:37:57 -04:00
|
|
|
// Filter now to possibly save work later. If filtering empties the
|
|
|
|
// buffer then flush_impl can deallocate the buffer.
|
2012-01-10 18:58:13 -05:00
|
|
|
filter();
|
2014-07-31 11:10:02 +02:00
|
|
|
flush_impl();
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
|
|
|
|
2018-08-01 19:14:04 -04:00
|
|
|
// This method will first apply filtering to the buffer. If filtering
|
|
|
|
// retains a small enough collection in the buffer, we can continue to
|
|
|
|
// use the buffer as-is, instead of enqueueing and replacing it.
|
2012-01-10 18:58:13 -05:00
|
|
|
|
2015-11-06 16:30:40 -05:00
|
|
|
bool SATBMarkQueue::should_enqueue_buffer() {
|
2012-01-10 18:58:13 -05:00
|
|
|
assert(_lock == NULL || _lock->owned_by_self(),
|
|
|
|
"we should have taken the lock before calling this");
|
2011-01-19 09:35:17 -05:00
|
|
|
|
2012-01-10 18:58:13 -05:00
|
|
|
// This method should only be called if there is a non-NULL buffer
|
|
|
|
// that is full.
|
2017-05-08 07:16:10 -04:00
|
|
|
assert(index() == 0, "pre-condition");
|
2012-01-10 18:58:13 -05:00
|
|
|
assert(_buf != NULL, "pre-condition");
|
|
|
|
|
|
|
|
filter();
|
|
|
|
|
2018-08-14 13:16:26 -04:00
|
|
|
SATBMarkQueueSet* satb_qset = static_cast<SATBMarkQueueSet*>(qset());
|
|
|
|
size_t threshold = satb_qset->buffer_enqueue_threshold();
|
|
|
|
// Ensure we'll enqueue completely full buffers.
|
|
|
|
assert(threshold > 0, "enqueue threshold = 0");
|
|
|
|
// Ensure we won't enqueue empty buffers.
|
|
|
|
assert(threshold <= capacity(),
|
|
|
|
"enqueue threshold " SIZE_FORMAT " exceeds capacity " SIZE_FORMAT,
|
|
|
|
threshold, capacity());
|
|
|
|
return index() < threshold;
|
2011-01-19 09:35:17 -05:00
|
|
|
}
|
|
|
|
|
2015-11-06 16:30:40 -05:00
|
|
|
void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) {
|
2015-05-01 17:38:12 -04:00
|
|
|
assert(SafepointSynchronize::is_at_safepoint(),
|
|
|
|
"SATB queues must only be processed at safepoints");
|
2008-06-05 15:57:56 -07:00
|
|
|
if (_buf != NULL) {
|
2017-05-08 07:16:10 -04:00
|
|
|
cl->do_buffer(&_buf[index()], size());
|
|
|
|
reset();
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:58:13 -05:00
|
|
|
#ifndef PRODUCT
|
|
|
|
// Helpful for debugging
|
|
|
|
|
2017-05-08 07:16:10 -04:00
|
|
|
static void print_satb_buffer(const char* name,
|
|
|
|
void** buf,
|
|
|
|
size_t index,
|
|
|
|
size_t capacity) {
|
|
|
|
tty->print_cr(" SATB BUFFER [%s] buf: " PTR_FORMAT " index: " SIZE_FORMAT
|
|
|
|
" capacity: " SIZE_FORMAT,
|
|
|
|
name, p2i(buf), index, capacity);
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
|
|
|
|
2017-05-08 07:16:10 -04:00
|
|
|
void SATBMarkQueue::print(const char* name) {
|
|
|
|
print_satb_buffer(name, _buf, index(), capacity());
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
2017-05-08 07:16:10 -04:00
|
|
|
|
2012-01-10 18:58:13 -05:00
|
|
|
#endif // PRODUCT
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
SATBMarkQueueSet::SATBMarkQueueSet() :
|
2015-04-17 13:49:04 -04:00
|
|
|
PtrQueueSet(),
|
2018-08-14 13:16:26 -04:00
|
|
|
_shared_satb_queue(this, true /* permanent */),
|
|
|
|
_buffer_enqueue_threshold(0)
|
2018-08-01 19:14:04 -04:00
|
|
|
{}
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2018-11-15 19:59:10 -05:00
|
|
|
void SATBMarkQueueSet::initialize(Monitor* cbl_mon,
|
|
|
|
BufferNode::Allocator* allocator,
|
2018-11-28 16:05:48 -05:00
|
|
|
size_t process_completed_buffers_threshold,
|
2018-08-14 13:16:26 -04:00
|
|
|
uint buffer_enqueue_threshold_percentage,
|
2008-06-05 15:57:56 -07:00
|
|
|
Mutex* lock) {
|
2018-11-28 16:05:48 -05:00
|
|
|
PtrQueueSet::initialize(cbl_mon, allocator);
|
|
|
|
set_process_completed_buffers_threshold(process_completed_buffers_threshold);
|
2008-06-05 15:57:56 -07:00
|
|
|
_shared_satb_queue.set_lock(lock);
|
2018-08-14 13:16:26 -04:00
|
|
|
assert(buffer_size() != 0, "buffer size not initialized");
|
|
|
|
// Minimum threshold of 1 ensures enqueuing of completely full buffers.
|
|
|
|
size_t size = buffer_size();
|
|
|
|
size_t enqueue_qty = (size * buffer_enqueue_threshold_percentage) / 100;
|
|
|
|
_buffer_enqueue_threshold = MAX2(size - enqueue_qty, (size_t)1);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2010-03-18 12:14:59 -04:00
|
|
|
#ifdef ASSERT
|
2014-01-10 09:54:25 +01:00
|
|
|
void SATBMarkQueueSet::dump_active_states(bool expected_active) {
|
2016-02-11 08:55:36 +01:00
|
|
|
log_error(gc, verify)("Expected SATB active state: %s", expected_active ? "ACTIVE" : "INACTIVE");
|
|
|
|
log_error(gc, verify)("Actual SATB active states:");
|
|
|
|
log_error(gc, verify)(" Queue set: %s", is_active() ? "ACTIVE" : "INACTIVE");
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-09 22:51:48 +02:00
|
|
|
log_error(gc, verify)(" Thread \"%s\" queue: %s", t->name(), satb_queue_for_thread(t).is_active() ? "ACTIVE" : "INACTIVE");
|
2010-03-18 12:14:59 -04:00
|
|
|
}
|
2016-02-11 08:55:36 +01:00
|
|
|
log_error(gc, verify)(" Shared queue: %s", shared_satb_queue()->is_active() ? "ACTIVE" : "INACTIVE");
|
2010-03-18 12:14:59 -04:00
|
|
|
}
|
|
|
|
|
2014-01-10 09:54:25 +01:00
|
|
|
void SATBMarkQueueSet::verify_active_states(bool expected_active) {
|
|
|
|
// Verify queue set state
|
|
|
|
if (is_active() != expected_active) {
|
|
|
|
dump_active_states(expected_active);
|
|
|
|
guarantee(false, "SATB queue set has an unexpected active state");
|
|
|
|
}
|
2010-03-18 12:14:59 -04:00
|
|
|
|
2014-01-10 09:54:25 +01:00
|
|
|
// Verify thread queue states
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-09 22:51:48 +02:00
|
|
|
if (satb_queue_for_thread(t).is_active() != expected_active) {
|
2014-01-10 09:54:25 +01:00
|
|
|
dump_active_states(expected_active);
|
|
|
|
guarantee(false, "Thread SATB queue has an unexpected active state");
|
|
|
|
}
|
2010-03-18 12:14:59 -04:00
|
|
|
}
|
2014-01-10 09:54:25 +01:00
|
|
|
|
|
|
|
// Verify shared queue state
|
|
|
|
if (shared_satb_queue()->is_active() != expected_active) {
|
|
|
|
dump_active_states(expected_active);
|
|
|
|
guarantee(false, "Shared SATB queue has an unexpected active state");
|
|
|
|
}
|
|
|
|
}
|
2010-03-18 12:14:59 -04:00
|
|
|
#endif // ASSERT
|
|
|
|
|
2014-01-10 09:54:25 +01:00
|
|
|
void SATBMarkQueueSet::set_active_all_threads(bool active, bool expected_active) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
|
2010-03-18 12:14:59 -04:00
|
|
|
#ifdef ASSERT
|
2014-01-10 09:54:25 +01:00
|
|
|
verify_active_states(expected_active);
|
2010-03-18 12:14:59 -04:00
|
|
|
#endif // ASSERT
|
2014-01-10 09:54:25 +01:00
|
|
|
_all_active = active;
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-09 22:51:48 +02:00
|
|
|
satb_queue_for_thread(t).set_active(active);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2014-01-10 09:54:25 +01:00
|
|
|
shared_satb_queue()->set_active(active);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2012-01-10 18:58:13 -05:00
|
|
|
void SATBMarkQueueSet::filter_thread_buffers() {
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-09 22:51:48 +02:00
|
|
|
satb_queue_for_thread(t).filter();
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
|
|
|
shared_satb_queue()->filter();
|
|
|
|
}
|
|
|
|
|
2015-05-01 17:38:12 -04:00
|
|
|
bool SATBMarkQueueSet::apply_closure_to_completed_buffer(SATBBufferClosure* cl) {
|
2009-12-16 15:12:51 -08:00
|
|
|
BufferNode* nd = NULL;
|
2008-06-05 15:57:56 -07:00
|
|
|
{
|
|
|
|
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
|
|
|
|
if (_completed_buffers_head != NULL) {
|
|
|
|
nd = _completed_buffers_head;
|
2009-12-16 15:12:51 -08:00
|
|
|
_completed_buffers_head = nd->next();
|
2008-06-05 15:57:56 -07:00
|
|
|
if (_completed_buffers_head == NULL) _completed_buffers_tail = NULL;
|
|
|
|
_n_completed_buffers--;
|
|
|
|
if (_n_completed_buffers == 0) _process_completed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nd != NULL) {
|
2009-12-16 15:12:51 -08:00
|
|
|
void **buf = BufferNode::make_buffer_from_node(nd);
|
2017-05-08 07:16:10 -04:00
|
|
|
size_t index = nd->index();
|
|
|
|
size_t size = buffer_size();
|
2016-03-10 16:21:46 -05:00
|
|
|
assert(index <= size, "invariant");
|
|
|
|
cl->do_buffer(buf + index, size - index);
|
|
|
|
deallocate_buffer(nd);
|
2008-06-05 15:57:56 -07:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:58:13 -05:00
|
|
|
#ifndef PRODUCT
|
|
|
|
// Helpful for debugging
|
|
|
|
|
|
|
|
#define SATB_PRINTER_BUFFER_SIZE 256
|
|
|
|
|
|
|
|
void SATBMarkQueueSet::print_all(const char* msg) {
|
|
|
|
char buffer[SATB_PRINTER_BUFFER_SIZE];
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
|
|
|
|
|
2015-12-10 14:57:55 +01:00
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("SATB BUFFERS [%s]", msg);
|
2012-01-10 18:58:13 -05:00
|
|
|
|
|
|
|
BufferNode* nd = _completed_buffers_head;
|
|
|
|
int i = 0;
|
|
|
|
while (nd != NULL) {
|
|
|
|
void** buf = BufferNode::make_buffer_from_node(nd);
|
2018-08-14 14:58:14 -04:00
|
|
|
os::snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i);
|
2017-05-08 07:16:10 -04:00
|
|
|
print_satb_buffer(buffer, buf, nd->index(), buffer_size());
|
2012-01-10 18:58:13 -05:00
|
|
|
nd = nd->next();
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-14 14:58:14 -04:00
|
|
|
os::snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
|
2018-08-09 22:51:48 +02:00
|
|
|
satb_queue_for_thread(t).print(buffer);
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
shared_satb_queue()->print("Shared");
|
|
|
|
|
2015-12-10 14:57:55 +01:00
|
|
|
tty->cr();
|
2012-01-10 18:58:13 -05:00
|
|
|
}
|
|
|
|
#endif // PRODUCT
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
void SATBMarkQueueSet::abandon_partial_marking() {
|
2009-12-16 15:12:51 -08:00
|
|
|
BufferNode* buffers_to_delete = NULL;
|
2008-06-05 15:57:56 -07:00
|
|
|
{
|
|
|
|
MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag);
|
|
|
|
while (_completed_buffers_head != NULL) {
|
2009-12-16 15:12:51 -08:00
|
|
|
BufferNode* nd = _completed_buffers_head;
|
|
|
|
_completed_buffers_head = nd->next();
|
|
|
|
nd->set_next(buffers_to_delete);
|
2008-06-05 15:57:56 -07:00
|
|
|
buffers_to_delete = nd;
|
|
|
|
}
|
|
|
|
_completed_buffers_tail = NULL;
|
|
|
|
_n_completed_buffers = 0;
|
2009-07-14 15:40:39 -07:00
|
|
|
DEBUG_ONLY(assert_completed_buffer_list_len_correct_locked());
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
while (buffers_to_delete != NULL) {
|
2009-12-16 15:12:51 -08:00
|
|
|
BufferNode* nd = buffers_to_delete;
|
|
|
|
buffers_to_delete = nd->next();
|
2016-03-10 16:21:46 -05:00
|
|
|
deallocate_buffer(nd);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
|
|
|
|
// So we can safely manipulate these queues.
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
|
2018-08-09 22:51:48 +02:00
|
|
|
satb_queue_for_thread(t).reset();
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2017-11-22 17:54:50 -08:00
|
|
|
shared_satb_queue()->reset();
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|