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