Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CompactGroupPersistentStats.hpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2020 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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-exception
22
*******************************************************************************/
23
24
/**
25
* @file
26
* @ingroup GC_Modron_Standard
27
*/
28
29
#if !defined(COMPACTGROUPPERSISTENTSTATS_HPP_)
30
#define COMPACTGROUPPERSISTENTSTATS_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
#include "modronopt.h"
35
36
class MM_EnvironmentVLHGC;
37
class MM_HeapRegionDescriptorVLHGC;
38
39
/**
40
* Stores globally accessible data on a per-compact-group basis.
41
* @ingroup GC_Modron_Standard
42
*/
43
class MM_CompactGroupPersistentStats
44
{
45
46
47
/* data members */
48
private:
49
protected:
50
public:
51
52
double _historicalSurvivalRate; /**< Historical survival rate of bytes in the corresponding compact group expressed as a percentage in the range [0..1] */
53
double _weightedSurvivalRate; /**< The historical survival rate in the corresponding compact group, weighted to take into consideration older groups in the same context */
54
55
bool _statsHaveBeenUpdatedThisCycle; /** < Indicates whether we have updated the stats shown below yet this cycle. They will be updated only once per cycle */
56
UDATA _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) */
57
UDATA _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) */
58
UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSetForNonEdenFraction; /**< Non-Eden Fraction (in case age group spans over Eden boundary) of _projectedLiveBytesAfterPreviousPGCInCollectedSet. This could be approximation! */
59
UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSet; /**< The projected number of bytes live at the end of previous PGC, for regions selected in this PGC for this compact group */
60
UDATA _projectedLiveBytesAfterPreviousPGCInCollectedSetForEdenFraction; /**< Eden Fraction (in case age group spans over Eden boundary) of _projectedLiveBytesAfterPreviousPGCInCollectedSet */
61
UDATA _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 */
62
UDATA _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) */
63
UDATA _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 */
64
UDATA _measuredLiveBytesAfterCollectInCollectedSet; /**< The number of bytes allocated in the collection set subset in this group at the */
65
volatile 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) */
66
volatile UDATA _measuredBytesCopiedToGroupDuringCopyForward; /**< The total number of bytes measured to be copied to group during a copy-forward */
67
volatile U_64 _measuredAllocationAgeToGroupDuringCopyForward; /**< The total allocation age measured on objects to be copied to group during copy-forward */
68
U_64 _averageAllocationAgeToGroup; /**< Average allocation age for group */
69
U_64 _maxAllocationAge; /**< max allocation age (of an object or region) in this compact group) */
70
/* TODO: lpnguyen group everything into anonymous structs */
71
72
double _projectedInstantaneousSurvivalRate; /**< survivor rate between this and previous age group */
73
double _projectedInstantaneousSurvivalRatePerAgeUnit; /**< fraction of _projectedInstantaneousSurvivalRate, in case age group is a multiple of age units. this is an average of _projectedInstantaneousSurvivalRateThisPGCPerAgeUnit */
74
double _projectedInstantaneousSurvivalRateThisPGCPerAgeUnit; /**< same as _projectedInstantaneousSurvivalRatePerAgeUnit, but for this PGC (not an average over time) */
75
76
77
UDATA _projectedLiveBytes; /** < The sum of projected live bytes of all regions in the compact group */
78
UDATA _liveBytesAbsoluteDeviation; /** < sum of the absolute value _projectedLiveBytesDeviation of every region in the compact group */
79
UDATA _regionCount; /** < count of the number of regions in the compact group */
80
81
UDATA _regionsInRegionCollectionSetForPGC; /** < number of regions in the region collection set for a partial global collection*/
82
83
/* member functions */
84
private:
85
/* Checks if a compactGroup has been collected and set _statsHaveBeenUpdatedThisCycle to true if that is the case.
86
* Also updates some stats (projectedInstantaneousSurvivalRate, historicalSurvivalRate, weightedSurvivalRate) that are dependant on the
87
* live bytes stats if they have not been updated yet.
88
*
89
* @param env[in] the current thread
90
* @param persistentStats[in] an array of MM_CompactGroupPersistentStats with as many elements as there are compact groups
91
*/
92
static void updateStatsAfterCollectionOperation(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
93
94
/**
95
* Update survival rate stats at the end of a PGC. This method depends on the before/after data for the given persistent stats
96
* structure being populated by the component which performed the PGC but then acts on those, generically.
97
* @param env[in] The Main GC thread
98
* @param persistentStats[in] The persistent stats array
99
* @param compactGroup[in] compactGroup for which instantaneousSurvivalRate is calculated
100
*/
101
static void updateProjectedSurvivalRate(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats, UDATA compactGroup);
102
103
/**
104
* Auxiliary function used by updateProjectedSurvivalRate. If an age group is at the boundary of Eden, it returns the size fractions on either sides.
105
* @param env[in] The Main GC thread
106
* @param ageInThisAgeGroup[in] Age-size of the age group
107
* @param ageInThisCompactGroup[in] Age-size of the compact group
108
* @param currentAge[in] Current age of objects in this group
109
* @param edenFractionOfCompactGroup[out]
110
* @param nonEdenFractionOfCompactGroup[out]
111
*/
112
static void calculateAgeGroupFractionsAtEdenBoundary(MM_EnvironmentVLHGC *env, U_64 ageInThisAgeGroup, U_64 *ageInThisCompactGroup, U_64 currentAge, U_64 allocatedSinceLastPGC, U_64 *edenFractionOfCompactGroup, U_64 *nonEdenFractionOfCompactGroup);
113
114
/* Reset live bytes stats. Should be done at the start of every gc cycle.
115
*
116
* @param env[in] The Main GC thread
117
* @param persistentStats[in] The list of per-compact group persistent stats
118
*/
119
static void resetLiveBytesStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
120
121
/*
122
* Init projected live bytes of regions that have been allocated from since previous PGC.
123
* The init value is set to current consumed space (according to memory pool).
124
*
125
* TODO: Create a new class for this as it's not really tied to compact groups
126
* @param env[in] The Main GC thread
127
*/
128
static void initProjectedLiveBytes(MM_EnvironmentVLHGC *env);
129
130
/*
131
* Updates the projectedLiveBytes for all regions by multiplying by their compact group's instantaneous survivor rate
132
*
133
* TODO: Create a new class for this as it's not really tied to compact groups
134
* @param env[in] The Main GC thread
135
*/
136
static void decayProjectedLiveBytesForRegions(MM_EnvironmentVLHGC *env);
137
138
/**
139
* Given the input list of compact group stats with initialized _historicalSurvivalRate fields, initialize the _weightedSurvivalRate fields.
140
* The survival rate is weighted using survival data from older groups to project the future survival rate of the group.
141
* This is used to favour compacting more stable compact groups.
142
*
143
* @param env[in] the current thread
144
* @param persistentStats[in] an array of MM_CompactGroupPersistentStats with as many elements as there are compact groups
145
*/
146
static void deriveWeightedSurvivalRates(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
147
148
/**
149
* Auxiliary function to calculation various values for measured/projected live bytes before current/after previous PGC, invoked for each region in Collection Set
150
* @param env[in] The Main GC thread
151
* @param persistentStats[in] The list of per-compact group persistent stats
152
* @param region[in] The region for which we take measured/projected live bytes values
153
* @param measuredLiveBytes Passing in the actual value for measuredLiveBytes (already calculated by the caller for its own purpose)
154
* @param projectedLiveBytes Passing in the actual value for projectedLiveBytes (already calculated by the caller for its own purpose)
155
*/
156
static void calculateLiveBytesForRegion(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats, UDATA compactGroup, MM_HeapRegionDescriptorVLHGC *region, UDATA measuredLiveBytes, UDATA projectedLiveBytes);
157
158
protected:
159
public:
160
/**
161
* Allocate a list of compact group stats
162
* @param env[in] the current thread
163
* @return an array of MM_CompactGroupPersistentStats, or NULL
164
*/
165
static MM_CompactGroupPersistentStats * allocateCompactGroupPersistentStats(MM_EnvironmentVLHGC *env);
166
167
/**
168
* Free the list of compact group stats
169
* @param env[in] the current thread
170
* @param persistentStats[in] the list to free
171
*/
172
static void killCompactGroupPersistentStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
173
174
/*
175
* Gather information related to bytes in and out of collection set. Run before a copy forward
176
* Stats are only updated on the first collection operation (copy forward,sweep...). This side-steps annoying double-counting of live bytes
177
* between different collection operations (though it possibly lowers our sample set).
178
*
179
* @param env[in] The Main GC thread
180
* @param persistentStats[in] The list of per-compact group persistent stats
181
*/
182
static void updateStatsBeforeCopyForward(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
183
184
/*
185
* Gathers information related to bytes collected by copy forward. Run after a copy forward
186
* Stats are only updated on the first collection operation (copy forward,sweep...). This side-steps annoying double-counting of live bytes
187
* between different collection operations (though it possibly lowers our sample set).
188
*
189
* @param env[in] The Main GC thread
190
* @param persistentStats[in] The list of per-compact group persistent stats
191
*/
192
static void updateStatsAfterCopyForward(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
193
194
/*
195
* Gather information related to bytes in and out of collection set. Run before a sweep
196
* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes
197
* between different collection operations (though it possibly lowers our sample set).
198
*
199
* @param env[in] The Main GC thread
200
* @param persistentStats[in] The list of per-compact group persistent stats
201
*/
202
static void updateStatsBeforeSweep(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
203
204
/*
205
* Gathers information related to bytes collected by copy forward. Run after a sweep
206
* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes
207
* between different collection operations (though it possibly lowers our sample set).
208
*
209
* @param env[in] The Main GC thread
210
* @param persistentStats[in] The list of per-compact group persistent stats
211
*/
212
static void updateStatsAfterSweep(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
213
214
/*
215
* Gather information related to bytes in and out of collection set. Run before a compact
216
* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes
217
* between different collection operations (though it possibly lowers our sample set).
218
*
219
* @param env[in] The Main GC thread
220
* @param persistentStats[in] The list of per-compact group persistent stats
221
*/
222
static void updateStatsBeforeCompact(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
223
224
/*
225
* Gathers information related to bytes collected by copy forward. Run after a compact
226
* Stats are only updated on the first collection operation (copy forward,sweep,compact). This side-steps annoying double-counting of live bytes
227
* between different collection operations (though it possibly lowers our sample set).
228
*
229
* @param env[in] The Main GC thread
230
* @param persistentStats[in] The list of per-compact group persistent stats
231
*/
232
static void updateStatsAfterCompact(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
233
234
/*
235
* Does any book-keeping/updating of stats before any gc operations happen
236
*
237
* @param env[in] The Main GC thread
238
* @param persistentStats[in] The list of per-compact group persistent stats
239
*/
240
static void updateStatsBeforeCollect(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
241
242
/**
243
* Updates projectedLiveBytes, projectedLiveBytesDeviation and regionCount fields by iterating through all regions and updating
244
* their compact group's stats.
245
* @param env[in] The Main GC thread
246
* @param persistentStats[in] The list of per-compact group persistent stats
247
*/
248
static void deriveProjectedLiveBytesStats(MM_EnvironmentVLHGC *env, MM_CompactGroupPersistentStats *persistentStats);
249
250
};
251
252
#endif /* COMPACTGROUPPERSISTENTSTATS_HPP_ */
253
254