Path: blob/master/runtime/gc_vlhgc/CompactGroupPersistentStats.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_Standard26*/2728#if !defined(COMPACTGROUPPERSISTENTSTATS_HPP_)29#define COMPACTGROUPPERSISTENTSTATS_HPP_3031#include "j9.h"32#include "j9cfg.h"33#include "modronopt.h"3435class MM_EnvironmentVLHGC;36class MM_HeapRegionDescriptorVLHGC;3738/**39* Stores globally accessible data on a per-compact-group basis.40* @ingroup GC_Modron_Standard41*/42class MM_CompactGroupPersistentStats43{444546/* data members */47private:48protected:49public:5051double _historicalSurvivalRate; /**< Historical survival rate of bytes in the corresponding compact group expressed as a percentage in the range [0..1] */52double _weightedSurvivalRate; /**< The historical survival rate in the corresponding compact group, weighted to take into consideration older groups in the same context */5354bool _statsHaveBeenUpdatedThisCycle; /** < Indicates whether we have updated the stats shown below yet this cycle. They will be updated only once per cycle */55UDATA _measuredLiveBytesBeforeCollectInCollectedSet; /**< The number of bytes allocated in the collection set subset in this group at the beginning of the collect (both live and dead objects) */56UDATA _projectedLiveBytesBeforeCollectInCollectedSet; /**< The projected number of bytes allocated in the collection set subset in this group at the beginning of the collect (the reason for the projection is that this attempts to account for only live objects) */57UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSetForNonEdenFraction; /**< Non-Eden Fraction (in case age group spans over Eden boundary) of _projectedLiveBytesAfterPreviousPGCInCollectedSet. This could be approximation! */58UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSet; /**< The projected number of bytes live at the end of previous PGC, for regions selected in this PGC for this compact group */59UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSetForEdenFraction; /**< Eden Fraction (in case age group spans over Eden boundary) of _projectedLiveBytesAfterPreviousPGCInCollectedSet */60UDATA _measuredLiveBytesBeforeCollectInGroup; /**< The total number of bytes consumed by all the regions in this compact group before the collect, whether they are in the collection set or not */61UDATA _projectedLiveBytesBeforeCollectInGroup; /**< The projected number of bytes consumed by all the regions in this compact group before the collect, whether they are in the collection set or not (the reason for the projection is that this attempts to account for only live objects) */62UDATA _measuredLiveBytesAfterCollectInGroup; /**< The total number of bytes in a compact group, after a collect, determined by summing the measured bytes not in the collected set and the number of bytes in the collected set, as measured by this collect */63UDATA _measuredLiveBytesAfterCollectInCollectedSet; /**< The number of bytes allocated in the collection set subset in this group at the */64volatile UDATA _measuredBytesCopiedFromGroupDuringCopyForward; /**< The total number of bytes measured to be live during a copy-forward which were copied from this compact group (the destination could be this group or another) */65volatile UDATA _measuredBytesCopiedToGroupDuringCopyForward; /**< The total number of bytes measured to be copied to group during a copy-forward */66volatile U_64 _measuredAllocationAgeToGroupDuringCopyForward; /**< The total allocation age measured on objects to be copied to group during copy-forward */67U_64 _averageAllocationAgeToGroup; /**< Average allocation age for group */68U_64 _maxAllocationAge; /**< max allocation age (of an object or region) in this compact group) */69/* TODO: lpnguyen group everything into anonymous structs */7071double _projectedInstantaneousSurvivalRate; /**< survivor rate between this and previous age group */72double _projectedInstantaneousSurvivalRatePerAgeUnit; /**< fraction of _projectedInstantaneousSurvivalRate, in case age group is a multiple of age units. this is an average of _projectedInstantaneousSurvivalRateThisPGCPerAgeUnit */73double _projectedInstantaneousSurvivalRateThisPGCPerAgeUnit; /**< same as _projectedInstantaneousSurvivalRatePerAgeUnit, but for this PGC (not an average over time) */747576UDATA _projectedLiveBytes; /** < The sum of projected live bytes of all regions in the compact group */77UDATA _liveBytesAbsoluteDeviation; /** < sum of the absolute value _projectedLiveBytesDeviation of every region in the compact group */78UDATA _regionCount; /** < count of the number of regions in the compact group */7980UDATA _regionsInRegionCollectionSetForPGC; /** < number of regions in the region collection set for a partial global collection*/8182/* member functions */83private:84/* Checks if a compactGroup has been collected and set _statsHaveBeenUpdatedThisCycle to true if that is the case.85* Also updates some stats (projectedInstantaneousSurvivalRate, historicalSurvivalRate, weightedSurvivalRate) that are dependant on the86* live bytes stats if they have not been updated yet.87*88* @param env[in] the current thread89* @param persistentStats[in] an array of MM_CompactGroupPersistentStats with as many elements as there are compact groups90*/91static void updateStatsAfterCollectionOperation(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);9293/**94* Update survival rate stats at the end of a PGC. This method depends on the before/after data for the given persistent stats95* structure being populated by the component which performed the PGC but then acts on those, generically.96* @param env[in] The Main GC thread97* @param persistentStats[in] The persistent stats array98* @param compactGroup[in] compactGroup for which instantaneousSurvivalRate is calculated99*/100static void updateProjectedSurvivalRate(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats, UDATA compactGroup);101102/**103* Auxiliary function used by updateProjectedSurvivalRate. If an age group is at the boundary of Eden, it returns the size fractions on either sides.104* @param env[in] The Main GC thread105* @param ageInThisAgeGroup[in] Age-size of the age group106* @param ageInThisCompactGroup[in] Age-size of the compact group107* @param currentAge[in] Current age of objects in this group108* @param edenFractionOfCompactGroup[out]109* @param nonEdenFractionOfCompactGroup[out]110*/111static void calculateAgeGroupFractionsAtEdenBoundary(MM_EnvironmentVLHGC *env, U_64 ageInThisAgeGroup, U_64 *ageInThisCompactGroup, U_64 currentAge, U_64 allocatedSinceLastPGC, U_64 *edenFractionOfCompactGroup, U_64 *nonEdenFractionOfCompactGroup);112113/* Reset live bytes stats. Should be done at the start of every gc cycle.114*115* @param env[in] The Main GC thread116* @param persistentStats[in] The list of per-compact group persistent stats117*/118static void resetLiveBytesStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);119120/*121* Init projected live bytes of regions that have been allocated from since previous PGC.122* The init value is set to current consumed space (according to memory pool).123*124* TODO: Create a new class for this as it's not really tied to compact groups125* @param env[in] The Main GC thread126*/127static void initProjectedLiveBytes(MM_EnvironmentVLHGC *env);128129/*130* Updates the projectedLiveBytes for all regions by multiplying by their compact group's instantaneous survivor rate131*132* TODO: Create a new class for this as it's not really tied to compact groups133* @param env[in] The Main GC thread134*/135static void decayProjectedLiveBytesForRegions(MM_EnvironmentVLHGC *env);136137/**138* Given the input list of compact group stats with initialized _historicalSurvivalRate fields, initialize the _weightedSurvivalRate fields.139* The survival rate is weighted using survival data from older groups to project the future survival rate of the group.140* This is used to favour compacting more stable compact groups.141*142* @param env[in] the current thread143* @param persistentStats[in] an array of MM_CompactGroupPersistentStats with as many elements as there are compact groups144*/145static void deriveWeightedSurvivalRates(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);146147/**148* Auxiliary function to calculation various values for measured/projected live bytes before current/after previous PGC, invoked for each region in Collection Set149* @param env[in] The Main GC thread150* @param persistentStats[in] The list of per-compact group persistent stats151* @param region[in] The region for which we take measured/projected live bytes values152* @param measuredLiveBytes Passing in the actual value for measuredLiveBytes (already calculated by the caller for its own purpose)153* @param projectedLiveBytes Passing in the actual value for projectedLiveBytes (already calculated by the caller for its own purpose)154*/155static void calculateLiveBytesForRegion(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats, UDATA compactGroup, MM_HeapRegionDescriptorVLHGC *region, UDATA measuredLiveBytes, UDATA projectedLiveBytes);156157protected:158public:159/**160* Allocate a list of compact group stats161* @param env[in] the current thread162* @return an array of MM_CompactGroupPersistentStats, or NULL163*/164static MM_CompactGroupPersistentStats * allocateCompactGroupPersistentStats(MM_EnvironmentVLHGC *env);165166/**167* Free the list of compact group stats168* @param env[in] the current thread169* @param persistentStats[in] the list to free170*/171static void killCompactGroupPersistentStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);172173/*174* Gather information related to bytes in and out of collection set. Run before a copy forward175* Stats are only updated on the first collection operation (copy forward,sweep...). This side-steps annoying double-counting of live bytes176* between different collection operations (though it possibly lowers our sample set).177*178* @param env[in] The Main GC thread179* @param persistentStats[in] The list of per-compact group persistent stats180*/181static void updateStatsBeforeCopyForward(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);182183/*184* Gathers information related to bytes collected by copy forward. Run after a copy forward185* Stats are only updated on the first collection operation (copy forward,sweep...). This side-steps annoying double-counting of live bytes186* between different collection operations (though it possibly lowers our sample set).187*188* @param env[in] The Main GC thread189* @param persistentStats[in] The list of per-compact group persistent stats190*/191static void updateStatsAfterCopyForward(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);192193/*194* Gather information related to bytes in and out of collection set. Run before a sweep195* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes196* between different collection operations (though it possibly lowers our sample set).197*198* @param env[in] The Main GC thread199* @param persistentStats[in] The list of per-compact group persistent stats200*/201static void updateStatsBeforeSweep(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);202203/*204* Gathers information related to bytes collected by copy forward. Run after a sweep205* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes206* between different collection operations (though it possibly lowers our sample set).207*208* @param env[in] The Main GC thread209* @param persistentStats[in] The list of per-compact group persistent stats210*/211static void updateStatsAfterSweep(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);212213/*214* Gather information related to bytes in and out of collection set. Run before a compact215* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes216* between different collection operations (though it possibly lowers our sample set).217*218* @param env[in] The Main GC thread219* @param persistentStats[in] The list of per-compact group persistent stats220*/221static void updateStatsBeforeCompact(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);222223/*224* Gathers information related to bytes collected by copy forward. Run after a compact225* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes226* between different collection operations (though it possibly lowers our sample set).227*228* @param env[in] The Main GC thread229* @param persistentStats[in] The list of per-compact group persistent stats230*/231static void updateStatsAfterCompact(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);232233/*234* Does any book-keeping/updating of stats before any gc operations happen235*236* @param env[in] The Main GC thread237* @param persistentStats[in] The list of per-compact group persistent stats238*/239static void updateStatsBeforeCollect(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);240241/**242* Updates projectedLiveBytes, projectedLiveBytesDeviation and regionCount fields by iterating through all regions and updating243* their compact group's stats.244* @param env[in] The Main GC thread245* @param persistentStats[in] The list of per-compact group persistent stats246*/247static void deriveProjectedLiveBytesStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);248249};250251#endif /* COMPACTGROUPPERSISTENTSTATS_HPP_ */252253254