Path: blob/master/src/hotspot/share/gc/shenandoah/heuristics/shenandoahCompactHeuristics.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/shenandoahCollectionSet.hpp"27#include "gc/shenandoah/heuristics/shenandoahCompactHeuristics.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"3334ShenandoahCompactHeuristics::ShenandoahCompactHeuristics() : ShenandoahHeuristics() {35SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);36SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);37SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahUncommit);38SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahAlwaysClearSoftRefs);39SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahAllocationThreshold, 10);40SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold, 100);41SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUncommitDelay, 1000);42SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGuaranteedGCInterval, 30000);43SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGarbageThreshold, 10);44}4546bool ShenandoahCompactHeuristics::should_start_gc() {47ShenandoahHeap* heap = ShenandoahHeap::heap();4849size_t max_capacity = heap->max_capacity();50size_t capacity = heap->soft_max_capacity();51size_t available = heap->free_set()->available();5253// Make sure the code below treats available without the soft tail.54size_t soft_tail = max_capacity - capacity;55available = (available > soft_tail) ? (available - soft_tail) : 0;5657size_t threshold_bytes_allocated = capacity / 100 * ShenandoahAllocationThreshold;58size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;5960if (available < min_threshold) {61log_info(gc)("Trigger: Free (" SIZE_FORMAT "%s) is below minimum threshold (" SIZE_FORMAT "%s)",62byte_size_in_proper_unit(available), proper_unit_for_byte_size(available),63byte_size_in_proper_unit(min_threshold), proper_unit_for_byte_size(min_threshold));64return true;65}6667size_t bytes_allocated = heap->bytes_allocated_since_gc_start();68if (bytes_allocated > threshold_bytes_allocated) {69log_info(gc)("Trigger: Allocated since last cycle (" SIZE_FORMAT "%s) is larger than allocation threshold (" SIZE_FORMAT "%s)",70byte_size_in_proper_unit(bytes_allocated), proper_unit_for_byte_size(bytes_allocated),71byte_size_in_proper_unit(threshold_bytes_allocated), proper_unit_for_byte_size(threshold_bytes_allocated));72return true;73}7475return ShenandoahHeuristics::should_start_gc();76}7778void ShenandoahCompactHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,79RegionData* data, size_t size,80size_t actual_free) {81// Do not select too large CSet that would overflow the available free space82size_t max_cset = actual_free * 3 / 4;8384log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "%s, Max CSet: " SIZE_FORMAT "%s",85byte_size_in_proper_unit(actual_free), proper_unit_for_byte_size(actual_free),86byte_size_in_proper_unit(max_cset), proper_unit_for_byte_size(max_cset));8788size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100;8990size_t live_cset = 0;91for (size_t idx = 0; idx < size; idx++) {92ShenandoahHeapRegion* r = data[idx]._region;93size_t new_cset = live_cset + r->get_live_data_bytes();94if (new_cset < max_cset && r->garbage() > threshold) {95live_cset = new_cset;96cset->add_region(r);97}98}99}100101102