2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2019-02-13 17:38:14 -05:00
|
|
|
* Copyright (c) 2001, 2019, 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-04-12 08:25:30 +02:00
|
|
|
#include "gc/g1/g1BarrierSet.hpp"
|
2017-11-06 14:24:31 +01:00
|
|
|
#include "gc/g1/g1ConcurrentRefine.hpp"
|
|
|
|
#include "gc/g1/g1ConcurrentRefineThread.hpp"
|
2019-02-13 17:38:14 -05:00
|
|
|
#include "gc/g1/g1DirtyCardQueue.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-23 15:51:06 +01:00
|
|
|
G1ConcurrentRefineThread::G1ConcurrentRefineThread(G1ConcurrentRefine* cr, uint worker_id) :
|
2008-06-05 15:57:56 -07:00
|
|
|
ConcurrentGCThread(),
|
2018-08-08 15:31:06 +02:00
|
|
|
_vtime_start(0.0),
|
|
|
|
_vtime_accum(0.0),
|
2009-05-11 16:30:56 -07:00
|
|
|
_worker_id(worker_id),
|
|
|
|
_active(false),
|
2009-12-16 15:12:51 -08:00
|
|
|
_monitor(NULL),
|
2018-08-08 15:31:06 +02:00
|
|
|
_cr(cr)
|
2008-06-05 15:57:56 -07: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::wait_for_completed_buffers() {
|
2019-04-29 16:01:52 -04:00
|
|
|
MonitorLocker ml(_monitor, Mutex::_no_safepoint_check_flag);
|
2016-03-11 16:59:58 -05:00
|
|
|
while (!should_terminate() && !is_active()) {
|
2019-04-29 16:01:52 -04:00
|
|
|
ml.wait();
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
bool G1ConcurrentRefineThread::is_active() {
|
2019-02-13 17:38:14 -05:00
|
|
|
G1DirtyCardQueueSet& dcqs = G1BarrierSet::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() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MutexLocker 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 {
|
2019-02-13 17:38:14 -05:00
|
|
|
G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
|
2018-12-26 19:24:00 -05:00
|
|
|
dcqs.set_process_completed_buffers(true);
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
_monitor->notify();
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:24:31 +01:00
|
|
|
void G1ConcurrentRefineThread::deactivate() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MutexLocker 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 {
|
2019-02-13 17:38:14 -05:00
|
|
|
G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
|
2018-12-26 19:24:00 -05:00
|
|
|
dcqs.set_process_completed_buffers(false);
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2017-11-23 15:51:06 +01:00
|
|
|
log_debug(gc, refine)("Activated worker %d, on threshold: " SIZE_FORMAT ", current: " SIZE_FORMAT,
|
|
|
|
_worker_id, _cr->activation_threshold(_worker_id),
|
2018-04-12 08:25:30 +02:00
|
|
|
G1BarrierSet::dirty_card_queue_set().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.
|
|
|
|
}
|
|
|
|
|
2017-11-23 15:51:06 +01:00
|
|
|
if (!_cr->do_refinement_step(_worker_id)) {
|
|
|
|
break;
|
2016-03-25 15:50:31 -04:00
|
|
|
}
|
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();
|
2017-11-23 15:51:06 +01:00
|
|
|
log_debug(gc, refine)("Deactivated worker %d, off threshold: " SIZE_FORMAT
|
2016-04-18 14:52:31 -04:00
|
|
|
", current: " SIZE_FORMAT ", processed: " SIZE_FORMAT,
|
2017-11-23 15:51:06 +01:00
|
|
|
_worker_id, _cr->deactivation_threshold(_worker_id),
|
2018-04-12 08:25:30 +02:00
|
|
|
G1BarrierSet::dirty_card_queue_set().completed_buffers_num(),
|
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
|
|
|
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() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MutexLocker x(_monitor, Mutex::_no_safepoint_check_flag);
|
2015-10-26 12:22:24 -04:00
|
|
|
_monitor->notify();
|
2015-12-10 14:57:55 +01:00
|
|
|
}
|