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