Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/g1/concurrentG1Refine.cpp
38921 views
/*1* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/g1/concurrentG1Refine.hpp"26#include "gc_implementation/g1/concurrentG1RefineThread.hpp"27#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"28#include "gc_implementation/g1/g1HotCardCache.hpp"29#include "runtime/java.hpp"3031ConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h, CardTableEntryClosure* refine_closure) :32_threads(NULL), _n_threads(0),33_hot_card_cache(g1h)34{35// Ergomonically select initial concurrent refinement parameters36if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {37FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, MAX2<int>(ParallelGCThreads, 1));38}39set_green_zone(G1ConcRefinementGreenZone);4041if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {42FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3);43}44set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone()));4546if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {47FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2);48}49set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone()));5051_n_worker_threads = thread_num();52// We need one extra thread to do the young gen rset size sampling.53_n_threads = _n_worker_threads + 1;5455reset_threshold_step();5657_threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads, mtGC);5859uint worker_id_offset = DirtyCardQueueSet::num_par_ids();6061ConcurrentG1RefineThread *next = NULL;62for (uint i = _n_threads - 1; i != UINT_MAX; i--) {63ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, refine_closure, worker_id_offset, i);64assert(t != NULL, "Conc refine should have been created");65if (t->osthread() == NULL) {66vm_shutdown_during_initialization("Could not create ConcurrentG1RefineThread");67}6869assert(t->cg1r() == this, "Conc refine thread should refer to this");70_threads[i] = t;71next = t;72}73}7475void ConcurrentG1Refine::reset_threshold_step() {76if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) {77_thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1);78} else {79_thread_threshold_step = G1ConcRefinementThresholdStep;80}81}8283void ConcurrentG1Refine::init(G1RegionToSpaceMapper* card_counts_storage) {84_hot_card_cache.initialize(card_counts_storage);85}8687void ConcurrentG1Refine::stop() {88if (_threads != NULL) {89for (uint i = 0; i < _n_threads; i++) {90_threads[i]->stop();91}92}93}9495void ConcurrentG1Refine::reinitialize_threads() {96reset_threshold_step();97if (_threads != NULL) {98for (uint i = 0; i < _n_threads; i++) {99_threads[i]->initialize();100}101}102}103104ConcurrentG1Refine::~ConcurrentG1Refine() {105if (_threads != NULL) {106for (uint i = 0; i < _n_threads; i++) {107delete _threads[i];108}109FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads, mtGC);110}111}112113void ConcurrentG1Refine::threads_do(ThreadClosure *tc) {114if (_threads != NULL) {115for (uint i = 0; i < _n_threads; i++) {116tc->do_thread(_threads[i]);117}118}119}120121void ConcurrentG1Refine::worker_threads_do(ThreadClosure * tc) {122if (_threads != NULL) {123for (uint i = 0; i < worker_thread_num(); i++) {124tc->do_thread(_threads[i]);125}126}127}128129uint ConcurrentG1Refine::thread_num() {130return G1ConcRefinementThreads;131}132133void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const {134for (uint i = 0; i < _n_threads; ++i) {135_threads[i]->print_on(st);136st->cr();137}138}139140ConcurrentG1RefineThread * ConcurrentG1Refine::sampling_thread() const {141return _threads[worker_thread_num()];142}143144145