Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CollectionSetDelegate.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_Tarok
27
*/
28
29
#if !defined(COLLECTIONSETDELEGATE_HPP_)
30
#define COLLECTIONSETDELEGATE_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
35
#include <string.h>
36
37
#include "BaseNonVirtual.hpp"
38
#include "EnvironmentVLHGC.hpp"
39
#include "GCExtensions.hpp"
40
#include "HeapRegionDescriptorVLHGC.hpp"
41
42
class MM_HeapRegionManager;
43
44
class MM_CollectionSetDelegate : public MM_BaseNonVirtual
45
{
46
/* Data Members */
47
public:
48
class SetSelectionData;
49
50
/**
51
* Trace reclaim rate table element.
52
* Contains details about the rate of reclaim based on tracing for a particular region age group.
53
*/
54
class RegionReclaimableStats {
55
public:
56
UDATA _regionCountBefore; /**< Number of regions in the age group before a sweep event */
57
UDATA _regionCountAfter; /**< Number of regions after trace and sweep have concluded */
58
UDATA _regionCountArrayletLeafBefore; /**< Number of regions that are arraylet leafs in the age group before a sweep */
59
UDATA _regionCountArrayletLeafAfter; /**< Number of regions that are arraylet leafs in the age group after a sweep */
60
UDATA _regionCountOverflow; /**< Number of regions which contain objects but are RSCL overflowed */
61
UDATA _regionCountArrayletLeafOverflow; /**< Number of regions which are arraylet leaves but are RSCL overflowed */
62
63
UDATA _regionBytesFreeBefore; /**< Number of free bytes (fragmented) in the age group before a sweep event */
64
UDATA _regionDarkMatterBefore; /**< Number of free bytes (fragmented) in the age group after a trace and sweep have concluded */
65
UDATA _regionBytesFreeAfter; /**< Number of dark matter bytes in the age group before a sweep event */
66
UDATA _regionDarkMatterAfter; /**< Number of dark matter bytes in the age group after a trace and sweep have concluded */
67
68
UDATA _reclaimableRegionCountBefore; /**< Number of regions to be included in the sweep set (includes tracing and recently traced but unswept due to GMP) */
69
UDATA _reclaimableRegionCountAfter; /**< Number of regions in the reclaimable set after having been swept */
70
UDATA _reclaimableRegionCountArrayletLeafBefore; /**< Number of regions that are arraylet leafs in the age group before a sweep */
71
UDATA _reclaimableRegionCountArrayletLeafAfter; /**< Number of regions that are arraylet leafs in the age group after a sweep */
72
73
UDATA _reclaimableBytesConsumedBefore; /**< Number of bytes consumed before a sweep in the set of regions marked as part of the reclaimable set */
74
UDATA _reclaimableBytesConsumedAfter; /**< Number of bytes consumed after a sweep in the set of regions marked as part of the reclaimable set */
75
76
protected:
77
private:
78
79
public:
80
RegionReclaimableStats() {};
81
82
void reset() { memset(this, 0, sizeof(RegionReclaimableStats)); }
83
84
protected:
85
private:
86
};
87
88
/**
89
* Top level class containing all data related to dynamic set selection and core sampling.
90
*/
91
class SetSelectionData {
92
public:
93
UDATA _compactGroup; /**< The compact group that the set represents */
94
MM_HeapRegionDescriptorVLHGC *_regionList; /**< List of regions associated to the compact group (NOTE: valid only during collection set building) */
95
UDATA _regionCount; /**< The number of regions that appear in the region list (NOTE: valid only during collection set building) */
96
97
RegionReclaimableStats _reclaimStats; /**< general reclaim statistics for the age group that are used for calculations and diagnostics */
98
double _rateOfReturn; /**< The fractional percentage of the expected ROR when tracing the entire set of regions at the corresponding age */
99
bool _dynamicSelectionThisCycle; /**< Flag indicating if the age group has regions that were dynamically selected for collection */
100
protected:
101
private:
102
103
public:
104
SetSelectionData()
105
: _compactGroup(0)
106
, _regionList(NULL)
107
, _regionCount(0)
108
, _reclaimStats()
109
, _rateOfReturn(0.0)
110
, _dynamicSelectionThisCycle(false)
111
{}
112
113
/**
114
* Add a region to the age group region list.
115
* Used for fast tracking to regions without having to do a full region search.
116
*/
117
void addRegion(MM_HeapRegionDescriptorVLHGC *region) {
118
region->setDynamicSelectionNext(_regionList);
119
_regionList = region;
120
_regionCount += 1;
121
}
122
123
protected:
124
private:
125
};
126
127
protected:
128
private:
129
MM_GCExtensions *_extensions; /**< A cached pointer to the global extensions */
130
MM_HeapRegionManager *_regionManager; /**< A cached pointer to the global heap region manager */
131
132
SetSelectionData *_setSelectionDataTable; /**< Storage table for set selection statistics and variables (grouped by age) */
133
SetSelectionData **_dynamicSelectionList; /**< Pointer table used for sorting or iterating over candidate dynamic selection elements */
134
135
/* Member Functions */
136
public:
137
/**
138
* Initialize the receiver.
139
* @param env[in] The thread initializing the collector
140
* @return Whether or not the initialization succeeded
141
*/
142
bool initialize(MM_EnvironmentVLHGC *env);
143
144
/**
145
* Tear down the receiver.
146
* @param env[in] The thread tearing down the collector
147
*/
148
void tearDown(MM_EnvironmentVLHGC *env);
149
150
/**
151
* Construct the receiver.
152
*/
153
MM_CollectionSetDelegate(MM_EnvironmentBase *env, MM_HeapRegionManager *manager);
154
155
/**
156
* Build the internal representation of the set of regions that are to be collected for this cycle.
157
* This should only be called during a partial garbage collect.
158
* @param env[in] The main GC thread
159
*/
160
void createRegionCollectionSetForPartialGC(MM_EnvironmentVLHGC *env);
161
162
/**
163
* Delete the internal representation of the set of regions that participated in the collection cycle.
164
* This should only be called during a partial garbage collect.
165
* @param env[in] The main GC thread
166
*/
167
void deleteRegionCollectionSetForPartialGC(MM_EnvironmentVLHGC *env);
168
169
/**
170
* Build the internal representation of the set of regions that are to be collected for this cycle.
171
* This should only be called during a global garbage collect.
172
* @param env[in] The main GC thread
173
*/
174
void createRegionCollectionSetForGlobalGC(MM_EnvironmentVLHGC *env);
175
176
/**
177
* Delete the internal representation of the set of regions that participated in the collection cycle.
178
* This should only be called during a global garbage collect.
179
* @param env[in] The main GC thread
180
*/
181
void deleteRegionCollectionSetForGlobalGC(MM_EnvironmentVLHGC *env);
182
183
/**
184
* Record pre-sweep region information in order to calculate rate of return on tracing for age groups.
185
*/
186
void rateOfReturnCalculationBeforeSweep(MM_EnvironmentVLHGC *env);
187
188
/**
189
* Record post-sweep region information and calculate rate of return on tracing for age groups.
190
*/
191
void rateOfReturnCalculationAfterSweep(MM_EnvironmentVLHGC *env);
192
193
protected:
194
195
private:
196
/**
197
* Include the core set of regions that comprise the nursery into a collection set for a PartialGC.
198
* Find all regions whose age allow them to be counted as part of the nursery and, if the region is collectable (contains objects
199
* and isn't in an RSCL overflow state) add it to the collection set.
200
* @param env[in] The main GC thread
201
* @return The number of regions in the nursery collection set
202
*/
203
UDATA createNurseryCollectionSet(MM_EnvironmentVLHGC *env);
204
205
/**
206
* Support routine to select a number of regions based on a budget to include in the collection set.
207
* 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.
208
* The counting attempts to evenly distribute the selection of regions across all regions in the age group.
209
* @param env[in] The main GC thread
210
* @param budget[in] Number of regions accounted for in the budget
211
* @param setSelectionData[in] Age group set selection data element that contains the list of regions to select from
212
*/
213
UDATA selectRegionsForBudget(MM_EnvironmentVLHGC *env, UDATA budget, SetSelectionData *setSelectionData);
214
215
/**
216
* Include a set of regions, based on rate of return calculations, outside of the nursery for collection set purposes.
217
* Given the total regions in the nursery, select a number of regions outside the nursery for inclusion in the PartialGC collection set.
218
* The selection will be past on historical rate of return (ROR) percentages, regions with higher ROR values being selected first.
219
* @param env[in] The main GC thread
220
* @param nurseryRegionCount[in] Number of regions selected as the core nursery collection set
221
*/
222
void createRateOfReturnCollectionSet(MM_EnvironmentVLHGC *env, UDATA nurseryRegionCount);
223
224
/**
225
* Include a set of regions, base on not being selected for collection and having a high age group population count, for collection set purposes.
226
* Find region age groups that have not participated in nursery or ROR collection set selection, and select a set of regions for collection set
227
* sampling purposes. The aim is to find age groups where collection opportunities might exist (increasing the ROR and being dynamically
228
* selected).
229
* @param env[in] The main GC thread
230
* @param nurseryRegionCount[in] Number of regions selected as the core nursery collection set
231
*/
232
void createCoreSamplingCollectionSet(MM_EnvironmentVLHGC *env, UDATA nurseryRegionCount);
233
234
235
/**
236
* Given the specified region, return the next region.
237
* If the region is NULL, or the last region in the table, return the first region.
238
* @param cursor[in] the current region, or NULL
239
* @return the next region (returning to the first region if the end is reached)
240
*/
241
MM_HeapRegionDescriptorVLHGC* getNextRegion(MM_HeapRegionDescriptorVLHGC* cursor);
242
243
244
};
245
246
#endif /* COLLECTIONSETDELEGATE_HPP_ */
247
248