Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/heuristics/shenandoahCompactHeuristics.cpp
38922 views
/*1* Copyright (c) 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"2425#include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"26#include "gc_implementation/shenandoah/heuristics/shenandoahCompactHeuristics.hpp"27#include "gc_implementation/shenandoah/shenandoahFreeSet.hpp"28#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"29#include "gc_implementation/shenandoah/shenandoahHeapRegion.inline.hpp"30#include "gc_implementation/shenandoah/shenandoahLogging.hpp"3132ShenandoahCompactHeuristics::ShenandoahCompactHeuristics() : ShenandoahHeuristics() {33SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);34SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);35SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahUncommit);36SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahAlwaysClearSoftRefs);37SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahAllocationThreshold, 10);38SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold, 100);39SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUncommitDelay, 1000);40SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGuaranteedGCInterval, 30000);41SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGarbageThreshold, 10);42}4344bool ShenandoahCompactHeuristics::should_start_gc() const {45ShenandoahHeap* heap = ShenandoahHeap::heap();4647size_t max_capacity = heap->max_capacity();48size_t capacity = heap->soft_max_capacity();49size_t available = heap->free_set()->available();5051// Make sure the code below treats available without the soft tail.52size_t soft_tail = max_capacity - capacity;53available = (available > soft_tail) ? (available - soft_tail) : 0;5455size_t threshold_bytes_allocated = capacity / 100 * ShenandoahAllocationThreshold;56size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;5758if (available < min_threshold) {59log_info(gc)("Trigger: Free (" SIZE_FORMAT "%s) is below minimum threshold (" SIZE_FORMAT "%s)",60byte_size_in_proper_unit(available), proper_unit_for_byte_size(available),61byte_size_in_proper_unit(min_threshold), proper_unit_for_byte_size(min_threshold));62return true;63}6465size_t bytes_allocated = heap->bytes_allocated_since_gc_start();66if (bytes_allocated > threshold_bytes_allocated) {67log_info(gc)("Trigger: Allocated since last cycle (" SIZE_FORMAT "%s) is larger than allocation threshold (" SIZE_FORMAT "%s)",68byte_size_in_proper_unit(bytes_allocated), proper_unit_for_byte_size(bytes_allocated),69byte_size_in_proper_unit(threshold_bytes_allocated), proper_unit_for_byte_size(threshold_bytes_allocated));70return true;71}7273return ShenandoahHeuristics::should_start_gc();74}7576void ShenandoahCompactHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,77RegionData* data, size_t size,78size_t actual_free) {79// Do not select too large CSet that would overflow the available free space80size_t max_cset = actual_free * 3 / 4;8182log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "%s, Max CSet: " SIZE_FORMAT "%s",83byte_size_in_proper_unit(actual_free), proper_unit_for_byte_size(actual_free),84byte_size_in_proper_unit(max_cset), proper_unit_for_byte_size(max_cset));8586size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100;8788size_t live_cset = 0;89for (size_t idx = 0; idx < size; idx++) {90ShenandoahHeapRegion* r = data[idx]._region;91size_t new_cset = live_cset + r->get_live_data_bytes();92if (new_cset < max_cset && r->garbage() > threshold) {93live_cset = new_cset;94cset->add_region(r);95}96}97}9899100