2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2017-10-18 21:17:46 +02: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"
|
2017-11-06 14:24:31 +01:00
|
|
|
#include "gc/g1/g1ConcurrentRefine.hpp"
|
|
|
|
#include "gc/g1/g1ConcurrentRefineThread.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
2017-07-12 12:26:57 +02:00
|
|
|
#include "gc/g1/g1RemSet.hpp"
|
2017-10-18 21:17:46 +02:00
|
|
|
#include "gc/shared/suspendibleThreadSet.hpp"
|
2015-12-10 14:57:55 +01:00
|
|
|
#include "logging/log.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/resourceArea.hpp"
|
|
|
|
#include "runtime/handles.inline.hpp"
|
|
|
|
#include "runtime/mutexLocker.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr,
|
|
|
|
G1ConcurrentRefineThread *next,
|
|
|
|
uint worker_id_offset,
|
|
|
|
uint worker_id,
|
|
|
|
size_t activate,
|
|
|
|
size_t deactivate) :
|
2008-06-05 15:57:56 -07:00
|
|
|
ConcurrentGCThread(),
|
2009-05-18 11:52:46 -07:00
|
|
|
_worker_id_offset(worker_id_offset),
|
2009-05-11 16:30:56 -07:00
|
|
|
_worker_id(worker_id),
|
|
|
|
_active(false),
|
|
|
|
_next(next),
|
2009-12-16 15:12:51 -08:00
|
|
|
_monitor(NULL),
|
2017-11-06 14:24:31 +01:00
|
|
|
_cr(cr),
|
2016-04-18 14:52:31 -04:00
|
|
|
_vtime_accum(0.0),
|
|
|
|
_activation_threshold(activate),
|
|
|
|
_deactivation_threshold(deactivate)
|
2008-06-05 15:57:56 -07:00
|
|
|
{
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Each thread has its own monitor. The i-th thread is responsible for signaling
|
|
|
|
// to thread i+1 if the number of buffers in the queue exceeds a threshold for this
|
2009-12-16 15:12:51 -08:00
|
|
|
// thread. Monitors are also used to wake up the threads during termination.
|
2015-10-26 12:22:24 -04:00
|
|
|
// The 0th (primary) worker is notified by mutator threads and has a special monitor.
|
|
|
|
if (!is_primary()) {
|
2014-12-11 21:34:43 -05:00
|
|
|
_monitor = new Monitor(Mutex::nonleaf, "Refinement monitor", true,
|
|
|
|
Monitor::_safepoint_check_never);
|
2009-12-16 15:12:51 -08:00
|
|
|
} else {
|
|
|
|
_monitor = DirtyCardQ_CBL_mon;
|
|
|
|
}
|
2014-05-01 05:52:28 -07:00
|
|
|
|
|
|
|
// set name
|
2015-03-05 16:43:26 +01:00
|
|
|
set_name("G1 Refine#%d", worker_id);
|
2016-02-03 09:31:22 -08:00
|
|
|
create_and_start();
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::update_thresholds(size_t activate,
|
2016-04-18 14:52:31 -04:00
|
|
|
size_t deactivate) {
|
|
|
|
assert(deactivate < activate, "precondition");
|
|
|
|
_activation_threshold = activate;
|
|
|
|
_deactivation_threshold = deactivate;
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::wait_for_completed_buffers() {
|
2009-12-16 15:12:51 -08:00
|
|
|
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
|
2016-03-11 16:59:58 -05:00
|
|
|
while (!should_terminate() && !is_active()) {
|
2009-12-16 15:12:51 -08:00
|
|
|
_monitor->wait(Mutex::_no_safepoint_check_flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
bool G1ConcurrentRefineThread::is_active() {
|
2009-12-16 15:12:51 -08:00
|
|
|
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
|
2015-10-26 12:22:24 -04:00
|
|
|
return is_primary() ? dcqs.process_completed_buffers() : _active;
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::activate() {
|
2009-12-16 15:12:51 -08:00
|
|
|
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
|
2015-10-26 12:22:24 -04:00
|
|
|
if (!is_primary()) {
|
2009-12-16 15:12:51 -08:00
|
|
|
set_active(true);
|
|
|
|
} else {
|
|
|
|
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
|
|
|
|
dcqs.set_process_completed(true);
|
|
|
|
}
|
|
|
|
_monitor->notify();
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::deactivate() {
|
2009-12-16 15:12:51 -08:00
|
|
|
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
|
2015-10-26 12:22:24 -04:00
|
|
|
if (!is_primary()) {
|
2009-12-16 15:12:51 -08:00
|
|
|
set_active(false);
|
|
|
|
} else {
|
|
|
|
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
|
|
|
|
dcqs.set_process_completed(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::run_service() {
|
2009-12-16 15:12:51 -08:00
|
|
|
_vtime_start = os::elapsedVTime();
|
|
|
|
|
2016-03-11 16:59:58 -05:00
|
|
|
while (!should_terminate()) {
|
2009-12-16 15:12:51 -08:00
|
|
|
// Wait for work
|
|
|
|
wait_for_completed_buffers();
|
2016-03-11 16:59:58 -05:00
|
|
|
if (should_terminate()) {
|
2009-12-16 15:12:51 -08:00
|
|
|
break;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2009-05-11 16:30:56 -07:00
|
|
|
|
2016-04-18 14:52:31 -04:00
|
|
|
size_t buffers_processed = 0;
|
2016-02-19 15:14:59 -05:00
|
|
|
DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
|
2016-02-26 14:02:39 -05:00
|
|
|
log_debug(gc, refine)("Activated %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
|
2016-04-18 14:52:31 -04:00
|
|
|
_worker_id, _activation_threshold, dcqs.completed_buffers_num());
|
2016-02-19 15:14:59 -05:00
|
|
|
|
2014-04-11 12:29:24 +02:00
|
|
|
{
|
2015-05-11 13:57:30 +02:00
|
|
|
SuspendibleThreadSetJoiner sts_join;
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2016-03-25 15:50:31 -04:00
|
|
|
while (!should_terminate()) {
|
|
|
|
if (sts_join.should_yield()) {
|
|
|
|
sts_join.yield();
|
|
|
|
continue; // Re-check for termination after yield delay.
|
|
|
|
}
|
|
|
|
|
2016-02-26 14:02:39 -05:00
|
|
|
size_t curr_buffer_num = dcqs.completed_buffers_num();
|
2014-04-11 12:29:24 +02:00
|
|
|
// If the number of the buffers falls down into the yellow zone,
|
|
|
|
// that means that the transition period after the evacuation pause has ended.
|
2017-11-06 14:24:31 +01:00
|
|
|
if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= cr()->yellow_zone()) {
|
2014-04-11 12:29:24 +02:00
|
|
|
dcqs.set_completed_queue_padding(0);
|
|
|
|
}
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2014-04-11 12:29:24 +02:00
|
|
|
// Check if we need to activate the next thread.
|
2016-04-18 14:52:31 -04:00
|
|
|
if ((_next != NULL) &&
|
|
|
|
!_next->is_active() &&
|
|
|
|
(curr_buffer_num > _next->_activation_threshold)) {
|
2014-04-11 12:29:24 +02:00
|
|
|
_next->activate();
|
|
|
|
}
|
2016-03-25 15:50:31 -04:00
|
|
|
|
|
|
|
// Process the next buffer, if there are enough left.
|
2017-07-12 12:26:57 +02:00
|
|
|
if (!dcqs.refine_completed_buffer_concurrently(_worker_id + _worker_id_offset, _deactivation_threshold)) {
|
2016-03-25 15:50:31 -04:00
|
|
|
break; // Deactivate, number of buffers fell below threshold.
|
|
|
|
}
|
2016-04-18 14:52:31 -04:00
|
|
|
++buffers_processed;
|
2016-03-25 15:50:31 -04:00
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2016-03-25 15:50:31 -04:00
|
|
|
deactivate();
|
|
|
|
log_debug(gc, refine)("Deactivated %d, off threshold: " SIZE_FORMAT
|
2016-04-18 14:52:31 -04:00
|
|
|
", current: " SIZE_FORMAT ", processed: " SIZE_FORMAT,
|
2016-03-25 15:50:31 -04:00
|
|
|
_worker_id, _deactivation_threshold,
|
2016-04-18 14:52:31 -04:00
|
|
|
dcqs.completed_buffers_num(),
|
|
|
|
buffers_processed);
|
2016-03-25 15:50:31 -04:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
if (os::supports_vtime()) {
|
|
|
|
_vtime_accum = (os::elapsedVTime() - _vtime_start);
|
|
|
|
} else {
|
|
|
|
_vtime_accum = 0.0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 12:22:24 -04:00
|
|
|
|
2016-02-19 15:14:59 -05:00
|
|
|
log_debug(gc, refine)("Stopping %d", _worker_id);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::stop_service() {
|
2015-10-26 12:22:24 -04:00
|
|
|
MutexLockerEx x(_monitor, Mutex::_no_safepoint_check_flag);
|
|
|
|
_monitor->notify();
|
2015-12-10 14:57:55 +01:00
|
|
|
}
|