Path: blob/master/src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp
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#ifndef SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP25#define SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP2627#include "gc/g1/g1CollectionSetCandidates.hpp"28#include "gc/shared/workgroup.hpp"29#include "memory/allocation.hpp"30#include "runtime/globals.hpp"3132class HeapRegion;33class HeapRegionClosure;3435// Set of collection set candidates, i.e. all old gen regions we consider worth36// collecting in the remainder of the current mixed phase. Regions are sorted by decreasing37// gc efficiency.38// Maintains a cursor into the list that specifies the next collection set candidate39// to put into the current collection set.40class G1CollectionSetCandidates : public CHeapObj<mtGC> {41HeapRegion** _regions;42uint _num_regions; // Total number of regions in the collection set candidate set.4344// The sum of bytes that can be reclaimed in the remaining set of collection45// set candidates.46size_t _remaining_reclaimable_bytes;47// The index of the next candidate old region to be considered for48// addition to the current collection set.49uint _front_idx;5051public:52G1CollectionSetCandidates(HeapRegion** regions, uint num_regions, size_t remaining_reclaimable_bytes) :53_regions(regions),54_num_regions(num_regions),55_remaining_reclaimable_bytes(remaining_reclaimable_bytes),56_front_idx(0) { }5758~G1CollectionSetCandidates() {59FREE_C_HEAP_ARRAY(HeapRegion*, _regions);60}6162// Returns the total number of collection set candidate old regions added.63uint num_regions() { return _num_regions; }6465uint cur_idx() const { return _front_idx; }6667HeapRegion* at(uint idx) const {68HeapRegion* res = NULL;69if (idx < _num_regions) {70res = _regions[idx];71assert(res != NULL, "Unexpected NULL HeapRegion at index %u", idx);72}73return res;74}7576// Remove num_regions from the front of the collection set candidate list.77void remove(uint num_regions);78// Remove num_remove regions from the back of the collection set candidate list.79void remove_from_end(uint num_remove, size_t wasted);8081// Iterate over all remaining collection set candidate regions.82void iterate(HeapRegionClosure* cl);83// Iterate over all remaining collectin set candidate regions from the end84// to the beginning of the set.85void iterate_backwards(HeapRegionClosure* cl);8687// Return the number of candidate regions remaining.88uint num_remaining() { return _num_regions - _front_idx; }8990bool is_empty() { return num_remaining() == 0; }9192// Return the amount of reclaimable bytes that may be collected by the remaining93// candidate regions.94size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }9596void verify() const PRODUCT_RETURN;97};9899#endif /* SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP */100101102103