Path: blob/master/src/hotspot/share/gc/g1/g1CollectionSetCandidates.cpp
40957 views
/*1* Copyright (c) 2019, 2021, 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/g1/g1CollectionSetCandidates.hpp"26#include "gc/g1/g1CollectionSetChooser.hpp"27#include "gc/g1/heapRegion.inline.hpp"2829void G1CollectionSetCandidates::remove(uint num_regions) {30assert(num_regions <= num_remaining(), "Trying to remove more regions (%u) than available (%u)", num_regions, num_remaining());31for (uint i = 0; i < num_regions; i++) {32_remaining_reclaimable_bytes -= at(_front_idx)->reclaimable_bytes();33_front_idx++;34}35}3637void G1CollectionSetCandidates::remove_from_end(uint num_remove, size_t wasted) {38assert(num_remove <= num_remaining(), "trying to remove more regions than remaining");3940#ifdef ASSERT41size_t reclaimable = 0;4243for (uint i = 0; i < num_remove; i++) {44uint cur_idx = _num_regions - i - 1;45reclaimable += at(cur_idx)->reclaimable_bytes();46// Make sure we crash if we access it.47_regions[cur_idx] = NULL;48}4950assert(reclaimable == wasted, "Recalculated reclaimable inconsistent");51#endif52_num_regions -= num_remove;53_remaining_reclaimable_bytes -= wasted;54}5556void G1CollectionSetCandidates::iterate(HeapRegionClosure* cl) {57for (uint i = _front_idx; i < _num_regions; i++) {58HeapRegion* r = _regions[i];59if (cl->do_heap_region(r)) {60cl->set_incomplete();61break;62}63}64}6566void G1CollectionSetCandidates::iterate_backwards(HeapRegionClosure* cl) {67for (uint i = _num_regions; i > _front_idx; i--) {68HeapRegion* r = _regions[i - 1];69if (cl->do_heap_region(r)) {70cl->set_incomplete();71break;72}73}74}7576#ifndef PRODUCT77void G1CollectionSetCandidates::verify() const {78guarantee(_front_idx <= _num_regions, "Index: %u Num_regions: %u", _front_idx, _num_regions);79uint idx = _front_idx;80size_t sum_of_reclaimable_bytes = 0;81HeapRegion *prev = NULL;82for (; idx < _num_regions; idx++) {83HeapRegion *cur = _regions[idx];84guarantee(cur != NULL, "Regions after _front_idx %u cannot be NULL but %u is", _front_idx, idx);85// The first disjunction filters out regions with objects that were explicitly86// pinned after being added to the collection set candidates. Archive regions87// should never have been added to the collection set though.88guarantee((cur->is_pinned() && !cur->is_archive()) ||89G1CollectionSetChooser::should_add(cur),90"Region %u should be eligible for addition.", cur->hrm_index());91if (prev != NULL) {92guarantee(prev->gc_efficiency() >= cur->gc_efficiency(),93"GC efficiency for region %u: %1.4f smaller than for region %u: %1.4f",94prev->hrm_index(), prev->gc_efficiency(), cur->hrm_index(), cur->gc_efficiency());95}96sum_of_reclaimable_bytes += cur->reclaimable_bytes();97prev = cur;98}99guarantee(sum_of_reclaimable_bytes == _remaining_reclaimable_bytes,100"Inconsistent remaining_reclaimable bytes, remaining " SIZE_FORMAT " calculated " SIZE_FORMAT,101_remaining_reclaimable_bytes, sum_of_reclaimable_bytes);102}103#endif // !PRODUCT104105106