0N/A/*
0N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#include "precompiled.hpp"
392N/A#include "gc_implementation/g1/concurrentG1Refine.hpp"
392N/A#include "gc_implementation/g1/concurrentG1RefineThread.hpp"
392N/A#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
392N/A#include "gc_implementation/g1/g1HotCardCache.hpp"
392N/A
392N/AConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h) :
392N/A _threads(NULL), _n_threads(0),
392N/A _hot_card_cache(g1h)
392N/A{
392N/A // Ergomonically select initial concurrent refinement parameters
271N/A if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
89N/A FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, MAX2<int>(ParallelGCThreads, 1));
0N/A }
0N/A set_green_zone(G1ConcRefinementGreenZone);
0N/A
0N/A if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
0N/A FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);
0N/A }
0N/A set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone()));
0N/A
0N/A if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
0N/A FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);
0N/A }
0N/A set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone()));
202N/A
202N/A _n_worker_threads = thread_num();
202N/A // We need one extra thread to do the young gen rset size sampling.
0N/A _n_threads = _n_worker_threads + 1;
0N/A
0N/A reset_threshold_step();
0N/A
0N/A _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads, mtGC);
0N/A
99N/A int worker_id_offset = (int)DirtyCardQueueSet::num_par_ids();
0N/A
0N/A ConcurrentG1RefineThread *next = NULL;
0N/A for (int i = _n_threads - 1; i >= 0; i--) {
0N/A ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, worker_id_offset, i);
0N/A assert(t != NULL, "Conc refine should have been created");
0N/A assert(t->cg1r() == this, "Conc refine thread should refer to this");
0N/A _threads[i] = t;
0N/A next = t;
0N/A }
0N/A}
0N/A
0N/Avoid ConcurrentG1Refine::reset_threshold_step() {
0N/A if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {
0N/A _thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);
0N/A } else {
0N/A _thread_threshold_step = G1ConcRefinementThresholdStep;
271N/A }
0N/A}
0N/A
0N/Avoid ConcurrentG1Refine::init() {
0N/A _hot_card_cache.initialize();
0N/A}
0N/A
0N/Avoid ConcurrentG1Refine::stop() {
0N/A if (_threads != NULL) {
89N/A for (int i = 0; i < _n_threads; i++) {
0N/A _threads[i]->stop();
202N/A }
271N/A }
0N/A}
89N/A
271N/Avoid ConcurrentG1Refine::reinitialize_threads() {
0N/A reset_threshold_step();
0N/A if (_threads != NULL) {
0N/A for (int i = 0; i < _n_threads; i++) {
_threads[i]->initialize();
}
}
}
ConcurrentG1Refine::~ConcurrentG1Refine() {
if (_threads != NULL) {
for (int i = 0; i < _n_threads; i++) {
delete _threads[i];
}
FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads, mtGC);
}
}
void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {
if (_threads != NULL) {
for (int i = 0; i < _n_threads; i++) {
tc->do_thread(_threads[i]);
}
}
}
int ConcurrentG1Refine::thread_num() {
int n_threads = (G1ConcRefinementThreads > 0) ? G1ConcRefinementThreads
: ParallelGCThreads;
return MAX2<int>(n_threads, 1);
}
void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {
for (int i = 0; i < _n_threads; ++i) {
_threads[i]->print_on(st);
st->cr();
}
}