Path: blob/master/src/hotspot/share/gc/shenandoah/heuristics/shenandoahStaticHeuristics.cpp
40975 views
/*1* Copyright (c) 2018, 2019, Red Hat, Inc. 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"2526#include "gc/shenandoah/heuristics/shenandoahStaticHeuristics.hpp"27#include "gc/shenandoah/shenandoahCollectionSet.hpp"28#include "gc/shenandoah/shenandoahFreeSet.hpp"29#include "gc/shenandoah/shenandoahHeap.inline.hpp"30#include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"31#include "logging/log.hpp"32#include "logging/logTag.hpp"3334ShenandoahStaticHeuristics::ShenandoahStaticHeuristics() : ShenandoahHeuristics() {35SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);36SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);37}3839ShenandoahStaticHeuristics::~ShenandoahStaticHeuristics() {}4041bool ShenandoahStaticHeuristics::should_start_gc() {42ShenandoahHeap* heap = ShenandoahHeap::heap();4344size_t max_capacity = heap->max_capacity();45size_t capacity = heap->soft_max_capacity();46size_t available = heap->free_set()->available();4748// Make sure the code below treats available without the soft tail.49size_t soft_tail = max_capacity - capacity;50available = (available > soft_tail) ? (available - soft_tail) : 0;5152size_t threshold_available = capacity / 100 * ShenandoahMinFreeThreshold;5354if (available < threshold_available) {55log_info(gc)("Trigger: Free (" SIZE_FORMAT "%s) is below minimum threshold (" SIZE_FORMAT "%s)",56byte_size_in_proper_unit(available), proper_unit_for_byte_size(available),57byte_size_in_proper_unit(threshold_available), proper_unit_for_byte_size(threshold_available));58return true;59}60return ShenandoahHeuristics::should_start_gc();61}6263void ShenandoahStaticHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,64RegionData* data, size_t size,65size_t free) {66size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100;6768for (size_t idx = 0; idx < size; idx++) {69ShenandoahHeapRegion* r = data[idx]._region;70if (r->garbage() > threshold) {71cset->add_region(r);72}73}74}757677