Path: blob/master/runtime/gc_vlhgc/CollectionSetDelegate.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2020 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/2223/**24* @file25* @ingroup GC_Modron_Tarok26*/2728#if !defined(COLLECTIONSETDELEGATE_HPP_)29#define COLLECTIONSETDELEGATE_HPP_3031#include "j9.h"32#include "j9cfg.h"3334#include <string.h>3536#include "BaseNonVirtual.hpp"37#include "EnvironmentVLHGC.hpp"38#include "GCExtensions.hpp"39#include "HeapRegionDescriptorVLHGC.hpp"4041class MM_HeapRegionManager;4243class MM_CollectionSetDelegate : public MM_BaseNonVirtual44{45/* Data Members */46public:47class SetSelectionData;4849/**50* Trace reclaim rate table element.51* Contains details about the rate of reclaim based on tracing for a particular region age group.52*/53class RegionReclaimableStats {54public:55UDATA _regionCountBefore; /**< Number of regions in the age group before a sweep event */56UDATA _regionCountAfter; /**< Number of regions after trace and sweep have concluded */57UDATA _regionCountArrayletLeafBefore; /**< Number of regions that are arraylet leafs in the age group before a sweep */58UDATA _regionCountArrayletLeafAfter; /**< Number of regions that are arraylet leafs in the age group after a sweep */59UDATA _regionCountOverflow; /**< Number of regions which contain objects but are RSCL overflowed */60UDATA _regionCountArrayletLeafOverflow; /**< Number of regions which are arraylet leaves but are RSCL overflowed */6162UDATA _regionBytesFreeBefore; /**< Number of free bytes (fragmented) in the age group before a sweep event */63UDATA _regionDarkMatterBefore; /**< Number of free bytes (fragmented) in the age group after a trace and sweep have concluded */64UDATA _regionBytesFreeAfter; /**< Number of dark matter bytes in the age group before a sweep event */65UDATA _regionDarkMatterAfter; /**< Number of dark matter bytes in the age group after a trace and sweep have concluded */6667UDATA _reclaimableRegionCountBefore; /**< Number of regions to be included in the sweep set (includes tracing and recently traced but unswept due to GMP) */68UDATA _reclaimableRegionCountAfter; /**< Number of regions in the reclaimable set after having been swept */69UDATA _reclaimableRegionCountArrayletLeafBefore; /**< Number of regions that are arraylet leafs in the age group before a sweep */70UDATA _reclaimableRegionCountArrayletLeafAfter; /**< Number of regions that are arraylet leafs in the age group after a sweep */7172UDATA _reclaimableBytesConsumedBefore; /**< Number of bytes consumed before a sweep in the set of regions marked as part of the reclaimable set */73UDATA _reclaimableBytesConsumedAfter; /**< Number of bytes consumed after a sweep in the set of regions marked as part of the reclaimable set */7475protected:76private:7778public:79RegionReclaimableStats() {};8081void reset() { memset(this, 0, sizeof(RegionReclaimableStats)); }8283protected:84private:85};8687/**88* Top level class containing all data related to dynamic set selection and core sampling.89*/90class SetSelectionData {91public:92UDATA _compactGroup; /**< The compact group that the set represents */93MM_HeapRegionDescriptorVLHGC *_regionList; /**< List of regions associated to the compact group (NOTE: valid only during collection set building) */94UDATA _regionCount; /**< The number of regions that appear in the region list (NOTE: valid only during collection set building) */9596RegionReclaimableStats _reclaimStats; /**< general reclaim statistics for the age group that are used for calculations and diagnostics */97double _rateOfReturn; /**< The fractional percentage of the expected ROR when tracing the entire set of regions at the corresponding age */98bool _dynamicSelectionThisCycle; /**< Flag indicating if the age group has regions that were dynamically selected for collection */99protected:100private:101102public:103SetSelectionData()104: _compactGroup(0)105, _regionList(NULL)106, _regionCount(0)107, _reclaimStats()108, _rateOfReturn(0.0)109, _dynamicSelectionThisCycle(false)110{}111112/**113* Add a region to the age group region list.114* Used for fast tracking to regions without having to do a full region search.115*/116void addRegion(MM_HeapRegionDescriptorVLHGC *region) {117region->setDynamicSelectionNext(_regionList);118_regionList = region;119_regionCount += 1;120}121122protected:123private:124};125126protected:127private:128MM_GCExtensions *_extensions; /**< A cached pointer to the global extensions */129MM_HeapRegionManager *_regionManager; /**< A cached pointer to the global heap region manager */130131SetSelectionData *_setSelectionDataTable; /**< Storage table for set selection statistics and variables (grouped by age) */132SetSelectionData **_dynamicSelectionList; /**< Pointer table used for sorting or iterating over candidate dynamic selection elements */133134/* Member Functions */135public:136/**137* Initialize the receiver.138* @param env[in] The thread initializing the collector139* @return Whether or not the initialization succeeded140*/141bool initialize(MM_EnvironmentVLHGC *env);142143/**144* Tear down the receiver.145* @param env[in] The thread tearing down the collector146*/147void tearDown(MM_EnvironmentVLHGC *env);148149/**150* Construct the receiver.151*/152MM_CollectionSetDelegate(MM_EnvironmentBase *env, MM_HeapRegionManager *manager);153154/**155* Build the internal representation of the set of regions that are to be collected for this cycle.156* This should only be called during a partial garbage collect.157* @param env[in] The main GC thread158*/159void createRegionCollectionSetForPartialGC(MM_EnvironmentVLHGC *env);160161/**162* Delete the internal representation of the set of regions that participated in the collection cycle.163* This should only be called during a partial garbage collect.164* @param env[in] The main GC thread165*/166void deleteRegionCollectionSetForPartialGC(MM_EnvironmentVLHGC *env);167168/**169* Build the internal representation of the set of regions that are to be collected for this cycle.170* This should only be called during a global garbage collect.171* @param env[in] The main GC thread172*/173void createRegionCollectionSetForGlobalGC(MM_EnvironmentVLHGC *env);174175/**176* Delete the internal representation of the set of regions that participated in the collection cycle.177* This should only be called during a global garbage collect.178* @param env[in] The main GC thread179*/180void deleteRegionCollectionSetForGlobalGC(MM_EnvironmentVLHGC *env);181182/**183* Record pre-sweep region information in order to calculate rate of return on tracing for age groups.184*/185void rateOfReturnCalculationBeforeSweep(MM_EnvironmentVLHGC *env);186187/**188* Record post-sweep region information and calculate rate of return on tracing for age groups.189*/190void rateOfReturnCalculationAfterSweep(MM_EnvironmentVLHGC *env);191192protected:193194private:195/**196* Include the core set of regions that comprise the nursery into a collection set for a PartialGC.197* Find all regions whose age allow them to be counted as part of the nursery and, if the region is collectable (contains objects198* and isn't in an RSCL overflow state) add it to the collection set.199* @param env[in] The main GC thread200* @return The number of regions in the nursery collection set201*/202UDATA createNurseryCollectionSet(MM_EnvironmentVLHGC *env);203204/**205* Support routine to select a number of regions based on a budget to include in the collection set.206* Given a set selection age group and a budget, use an form of counting to select the budgeted number of regions available in the age group.207* The counting attempts to evenly distribute the selection of regions across all regions in the age group.208* @param env[in] The main GC thread209* @param budget[in] Number of regions accounted for in the budget210* @param setSelectionData[in] Age group set selection data element that contains the list of regions to select from211*/212UDATA selectRegionsForBudget(MM_EnvironmentVLHGC *env, UDATA budget, SetSelectionData *setSelectionData);213214/**215* Include a set of regions, based on rate of return calculations, outside of the nursery for collection set purposes.216* Given the total regions in the nursery, select a number of regions outside the nursery for inclusion in the PartialGC collection set.217* The selection will be past on historical rate of return (ROR) percentages, regions with higher ROR values being selected first.218* @param env[in] The main GC thread219* @param nurseryRegionCount[in] Number of regions selected as the core nursery collection set220*/221void createRateOfReturnCollectionSet(MM_EnvironmentVLHGC *env, UDATA nurseryRegionCount);222223/**224* Include a set of regions, base on not being selected for collection and having a high age group population count, for collection set purposes.225* Find region age groups that have not participated in nursery or ROR collection set selection, and select a set of regions for collection set226* sampling purposes. The aim is to find age groups where collection opportunities might exist (increasing the ROR and being dynamically227* selected).228* @param env[in] The main GC thread229* @param nurseryRegionCount[in] Number of regions selected as the core nursery collection set230*/231void createCoreSamplingCollectionSet(MM_EnvironmentVLHGC *env, UDATA nurseryRegionCount);232233234/**235* Given the specified region, return the next region.236* If the region is NULL, or the last region in the table, return the first region.237* @param cursor[in] the current region, or NULL238* @return the next region (returning to the first region if the end is reached)239*/240MM_HeapRegionDescriptorVLHGC* getNextRegion(MM_HeapRegionDescriptorVLHGC* cursor);241242243};244245#endif /* COLLECTIONSETDELEGATE_HPP_ */246247248