Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahCollectorPolicy.cpp
38920 views
/*1* Copyright (c) 2013, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223#include "precompiled.hpp"24#include "gc_interface/gcCause.hpp"25#include "gc_implementation/shared/gcTimer.hpp"26#include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"27#include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp"28#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"29#include "gc_implementation/shenandoah/shenandoahLogging.hpp"30#include "gc_implementation/shenandoah/heuristics/shenandoahHeuristics.hpp"3132ShenandoahCollectorPolicy::ShenandoahCollectorPolicy() :33_success_concurrent_gcs(0),34_success_degenerated_gcs(0),35_success_full_gcs(0),36_alloc_failure_degenerated(0),37_alloc_failure_full(0),38_alloc_failure_degenerated_upgrade_to_full(0),39_explicit_concurrent(0),40_explicit_full(0),41_implicit_concurrent(0),42_implicit_full(0),43_cycle_counter(0) {4445Copy::zero_to_bytes(_degen_points, sizeof(size_t) * ShenandoahHeap::_DEGENERATED_LIMIT);4647ShenandoahHeapRegion::setup_sizes(max_heap_byte_size());4849initialize_all();5051_tracer = new (ResourceObj::C_HEAP, mtGC) ShenandoahTracer();52}5354BarrierSet::Name ShenandoahCollectorPolicy::barrier_set_name() {55return BarrierSet::ShenandoahBarrierSet;56}5758HeapWord* ShenandoahCollectorPolicy::mem_allocate_work(size_t size,59bool is_tlab,60bool* gc_overhead_limit_was_exceeded) {61guarantee(false, "Not using this policy feature yet.");62return NULL;63}6465HeapWord* ShenandoahCollectorPolicy::satisfy_failed_allocation(size_t size, bool is_tlab) {66guarantee(false, "Not using this policy feature yet.");67return NULL;68}6970MetaWord* ShenandoahCollectorPolicy::satisfy_failed_metadata_allocation(ClassLoaderData *loader_data,71size_t size,72Metaspace::MetadataType mdtype) {73MetaWord* result;7475ShenandoahHeap* sh = ShenandoahHeap::heap();7677// Inform metaspace OOM to GC heuristics if class unloading is possible.78ShenandoahHeuristics* h = sh->heuristics();79if (h->can_unload_classes()) {80h->record_metaspace_oom();81}8283// Expand and retry allocation84result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);85if (result != NULL) {86return result;87}8889// Start full GC90sh->collect(GCCause::_shenandoah_metadata_gc_clear_softrefs);9192// Retry allocation93result = loader_data->metaspace_non_null()->allocate(size, mdtype);94if (result != NULL) {95return result;96}9798// Expand and retry allocation99result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype);100if (result != NULL) {101return result;102}103104// Out of memory105return NULL;106}107108void ShenandoahCollectorPolicy::initialize_alignments() {109// This is expected by our algorithm for ShenandoahHeap::heap_region_containing().110size_t align = ShenandoahHeapRegion::region_size_bytes();111if (UseLargePages) {112align = MAX2(align, os::large_page_size());113}114_space_alignment = align;115_heap_alignment = align;116}117118void ShenandoahCollectorPolicy::record_explicit_to_concurrent() {119_explicit_concurrent++;120}121122void ShenandoahCollectorPolicy::record_explicit_to_full() {123_explicit_full++;124}125126void ShenandoahCollectorPolicy::record_implicit_to_concurrent() {127_implicit_concurrent++;128}129130void ShenandoahCollectorPolicy::record_implicit_to_full() {131_implicit_full++;132}133134void ShenandoahCollectorPolicy::record_alloc_failure_to_full() {135_alloc_failure_full++;136}137138void ShenandoahCollectorPolicy::record_alloc_failure_to_degenerated(ShenandoahHeap::ShenandoahDegenPoint point) {139assert(point < ShenandoahHeap::_DEGENERATED_LIMIT, "sanity");140_alloc_failure_degenerated++;141_degen_points[point]++;142}143144void ShenandoahCollectorPolicy::record_degenerated_upgrade_to_full() {145_alloc_failure_degenerated_upgrade_to_full++;146}147148void ShenandoahCollectorPolicy::record_success_concurrent() {149_success_concurrent_gcs++;150}151152void ShenandoahCollectorPolicy::record_success_degenerated() {153_success_degenerated_gcs++;154}155156void ShenandoahCollectorPolicy::record_success_full() {157_success_full_gcs++;158}159160size_t ShenandoahCollectorPolicy::cycle_counter() const {161return _cycle_counter;162}163164void ShenandoahCollectorPolicy::record_cycle_start() {165_cycle_counter++;166}167168void ShenandoahCollectorPolicy::record_shutdown() {169_in_shutdown.set();170}171172bool ShenandoahCollectorPolicy::is_at_shutdown() {173return _in_shutdown.is_set();174}175176void ShenandoahCollectorPolicy::print_gc_stats(outputStream* out) const {177out->print_cr("Under allocation pressure, concurrent cycles may cancel, and either continue cycle");178out->print_cr("under stop-the-world pause or result in stop-the-world Full GC. Increase heap size,");179out->print_cr("tune GC heuristics, set more aggressive pacing delay, or lower allocation rate");180out->print_cr("to avoid Degenerated and Full GC cycles.");181out->cr();182183out->print_cr(SIZE_FORMAT_W(5) " successful concurrent GCs", _success_concurrent_gcs);184out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly", _explicit_concurrent);185out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly", _implicit_concurrent);186out->cr();187188out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs", _success_degenerated_gcs);189out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_degenerated);190for (int c = 0; c < ShenandoahHeap::_DEGENERATED_LIMIT; c++) {191if (_degen_points[c] > 0) {192const char* desc = ShenandoahHeap::degen_point_to_string((ShenandoahHeap::ShenandoahDegenPoint)c);193out->print_cr(" " SIZE_FORMAT_W(5) " happened at %s", _degen_points[c], desc);194}195}196out->print_cr(" " SIZE_FORMAT_W(5) " upgraded to Full GC", _alloc_failure_degenerated_upgrade_to_full);197out->cr();198199out->print_cr(SIZE_FORMAT_W(5) " Full GCs", _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full);200out->print_cr(" " SIZE_FORMAT_W(5) " invoked explicitly", _explicit_full);201out->print_cr(" " SIZE_FORMAT_W(5) " invoked implicitly", _implicit_full);202out->print_cr(" " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_full);203out->print_cr(" " SIZE_FORMAT_W(5) " upgraded from Degenerated GC", _alloc_failure_degenerated_upgrade_to_full);204}205206207