2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2015-05-13 15:16:06 +02:00
|
|
|
* Copyright (c) 2001, 2015, 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/concurrentG1Refine.hpp"
|
|
|
|
#include "gc/g1/concurrentG1RefineThread.hpp"
|
|
|
|
#include "gc/g1/g1CollectedHeap.inline.hpp"
|
|
|
|
#include "gc/g1/g1HotCardCache.hpp"
|
2013-12-09 08:20:45 +01:00
|
|
|
#include "runtime/java.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2015-09-09 09:19:32 -07:00
|
|
|
ConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h) :
|
2015-10-26 12:22:24 -04:00
|
|
|
_threads(NULL),
|
|
|
|
_sample_thread(NULL),
|
2013-05-09 11:16:39 -07:00
|
|
|
_hot_card_cache(g1h)
|
2008-06-05 15:57:56 -07:00
|
|
|
{
|
2014-01-23 14:47:23 +01:00
|
|
|
// Ergonomically select initial concurrent refinement parameters
|
2010-02-23 23:13:23 -05:00
|
|
|
if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
|
2015-05-22 10:58:16 +02:00
|
|
|
FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, (intx)ParallelGCThreads);
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
2010-02-23 23:13:23 -05:00
|
|
|
set_green_zone(G1ConcRefinementGreenZone);
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2010-02-23 23:13:23 -05:00
|
|
|
if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
|
|
|
|
FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
2010-02-23 23:13:23 -05:00
|
|
|
set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone()));
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2010-02-23 23:13:23 -05:00
|
|
|
if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
|
|
|
|
FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
2010-02-23 23:13:23 -05:00
|
|
|
set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone()));
|
2015-09-09 09:19:32 -07:00
|
|
|
}
|
2013-05-09 11:16:39 -07:00
|
|
|
|
2015-09-09 09:19:32 -07:00
|
|
|
ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h, CardTableEntryClosure* refine_closure, jint* ecode) {
|
|
|
|
ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(g1h);
|
|
|
|
if (cg1r == NULL) {
|
|
|
|
*ecode = JNI_ENOMEM;
|
|
|
|
vm_shutdown_during_initialization("Could not create ConcurrentG1Refine");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cg1r->_n_worker_threads = thread_num();
|
2013-05-09 11:16:39 -07:00
|
|
|
|
2015-09-09 09:19:32 -07:00
|
|
|
cg1r->reset_threshold_step();
|
2009-12-16 15:12:51 -08:00
|
|
|
|
2015-10-26 12:22:24 -04:00
|
|
|
cg1r->_threads = NEW_C_HEAP_ARRAY_RETURN_NULL(ConcurrentG1RefineThread*, cg1r->_n_worker_threads, mtGC);
|
2015-09-09 09:19:32 -07:00
|
|
|
if (cg1r->_threads == NULL) {
|
|
|
|
*ecode = JNI_ENOMEM;
|
|
|
|
vm_shutdown_during_initialization("Could not allocate an array for ConcurrentG1RefineThread");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-05-09 11:16:39 -07:00
|
|
|
|
2014-04-03 17:49:31 +04:00
|
|
|
uint worker_id_offset = DirtyCardQueueSet::num_par_ids();
|
2013-05-09 11:16:39 -07:00
|
|
|
|
2009-12-16 15:12:51 -08:00
|
|
|
ConcurrentG1RefineThread *next = NULL;
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = cg1r->_n_worker_threads - 1; i != UINT_MAX; i--) {
|
2015-09-09 09:19:32 -07:00
|
|
|
ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(cg1r, next, refine_closure, worker_id_offset, i);
|
2009-12-16 15:12:51 -08:00
|
|
|
assert(t != NULL, "Conc refine should have been created");
|
2013-12-09 08:20:45 +01:00
|
|
|
if (t->osthread() == NULL) {
|
2015-09-09 09:19:32 -07:00
|
|
|
*ecode = JNI_ENOMEM;
|
|
|
|
vm_shutdown_during_initialization("Could not create ConcurrentG1RefineThread");
|
|
|
|
return NULL;
|
2013-12-09 08:20:45 +01:00
|
|
|
}
|
|
|
|
|
2015-09-09 09:19:32 -07:00
|
|
|
assert(t->cg1r() == cg1r, "Conc refine thread should refer to this");
|
|
|
|
cg1r->_threads[i] = t;
|
2009-12-16 15:12:51 -08:00
|
|
|
next = t;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2015-10-26 12:22:24 -04:00
|
|
|
|
|
|
|
cg1r->_sample_thread = new G1YoungRemSetSamplingThread();
|
|
|
|
if (cg1r->_sample_thread->osthread() == NULL) {
|
|
|
|
*ecode = JNI_ENOMEM;
|
|
|
|
vm_shutdown_during_initialization("Could not create G1YoungRemSetSamplingThread");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-09 09:19:32 -07:00
|
|
|
*ecode = JNI_OK;
|
|
|
|
return cg1r;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2009-12-16 15:12:51 -08:00
|
|
|
void ConcurrentG1Refine::reset_threshold_step() {
|
2010-02-23 23:13:23 -05:00
|
|
|
if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {
|
2009-12-16 15:12:51 -08:00
|
|
|
_thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);
|
|
|
|
} else {
|
2010-02-23 23:13:23 -05:00
|
|
|
_thread_threshold_step = G1ConcRefinementThresholdStep;
|
2009-05-18 11:52:46 -07:00
|
|
|
}
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
|
2014-08-19 14:09:10 +02:00
|
|
|
void ConcurrentG1Refine::init(G1RegionToSpaceMapper* card_counts_storage) {
|
|
|
|
_hot_card_cache.initialize(card_counts_storage);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2009-05-11 16:30:56 -07:00
|
|
|
void ConcurrentG1Refine::stop() {
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = 0; i < _n_worker_threads; i++) {
|
|
|
|
_threads[i]->stop();
|
2009-05-11 16:30:56 -07:00
|
|
|
}
|
2015-10-26 12:22:24 -04:00
|
|
|
_sample_thread->stop();
|
2009-05-11 16:30:56 -07:00
|
|
|
}
|
|
|
|
|
2009-12-16 15:12:51 -08:00
|
|
|
void ConcurrentG1Refine::reinitialize_threads() {
|
|
|
|
reset_threshold_step();
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = 0; i < _n_worker_threads; i++) {
|
|
|
|
_threads[i]->initialize();
|
2009-12-16 15:12:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
ConcurrentG1Refine::~ConcurrentG1Refine() {
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = 0; i < _n_worker_threads; i++) {
|
|
|
|
delete _threads[i];
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2015-10-26 12:22:24 -04:00
|
|
|
FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads);
|
|
|
|
|
|
|
|
delete _sample_thread;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2009-05-11 16:30:56 -07:00
|
|
|
void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
|
2015-10-26 12:22:24 -04:00
|
|
|
worker_threads_do(tc);
|
|
|
|
tc->do_thread(_sample_thread);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 09:32:06 +02:00
|
|
|
void ConcurrentG1Refine::worker_threads_do(ThreadClosure * tc) {
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = 0; i < worker_thread_num(); i++) {
|
|
|
|
tc->do_thread(_threads[i]);
|
2013-05-28 09:32:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 17:49:31 +04:00
|
|
|
uint ConcurrentG1Refine::thread_num() {
|
2014-09-27 15:11:41 +02:00
|
|
|
return G1ConcRefinementThreads;
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
2009-10-02 16:12:07 -04:00
|
|
|
|
|
|
|
void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
|
2015-10-26 12:22:24 -04:00
|
|
|
for (uint i = 0; i < _n_worker_threads; ++i) {
|
2009-10-02 16:12:07 -04:00
|
|
|
_threads[i]->print_on(st);
|
|
|
|
st->cr();
|
|
|
|
}
|
2015-10-26 12:22:24 -04:00
|
|
|
_sample_thread->print_on(st);
|
|
|
|
st->cr();
|
2013-05-28 09:32:06 +02:00
|
|
|
}
|