Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/AllocationContextTarok.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
/**
24
* @file
25
* @ingroup GC_Modron_Base
26
*/
27
28
#if !defined(ALLOCATIONCONTEXTTAROK_HPP_)
29
#define ALLOCATIONCONTEXTTAROK_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "j9protos.h"
34
#include "modronopt.h"
35
36
#include "AllocationContext.hpp"
37
#include "LightweightNonReentrantLock.hpp"
38
#include "MemorySubSpace.hpp"
39
#include "RegionListTarok.hpp"
40
41
class MM_EnvironmentBase;
42
class MM_HeapRegionDescriptorVLHGC;
43
class MM_HeapRegionManager;
44
class MM_MemorySubSpaceTarok;
45
46
class MM_AllocationContextTarok : public MM_AllocationContext
47
{
48
49
/* Data members / Types */
50
public:
51
enum AllocationContextType {
52
BALANCED = 0 /**< Represents a regular balanced AC */
53
, MULTI_TENANT = 1 /**< Represents a multi-tenant AC */
54
};
55
protected:
56
private:
57
const UDATA _allocationContextNumber; /**< A unique 0-indexed number assigned to this context instance (to be used for indexing into meta-data arrays, etc) */
58
const AllocationContextType _allocationContextType; /**< The type of this AC, set during instantiation and used for instanceof checks **/
59
60
/* Methods */
61
public:
62
63
/**
64
* @return The context number with which this instance was initialized
65
*/
66
UDATA getAllocationContextNumber() { return _allocationContextNumber; }
67
68
/**
69
* @return The type of this allocation context.
70
*/
71
MMINLINE AllocationContextType getAllocationContextType() { return _allocationContextType; }
72
73
/**
74
* Acquire a new region to be placed in the active set of regions from which to allocate.
75
* @param env GC thread.
76
* @return A region descriptor that has been acquired and put into the active to be consumed from rotation.
77
* @note This will immediately move the acquired region from _ownedRegions to _flushedRegions
78
*/
79
virtual MM_HeapRegionDescriptorVLHGC *collectorAcquireRegion(MM_EnvironmentBase *env) = 0;
80
81
/**
82
* Perform an allocate of the given allocationType and return it. Note that the receiver can assume that either the context is locked or the calling thread has exclusive.
83
*
84
* @param[in] env The calling thread
85
* @param[in] objectAllocationInterface The allocation interface through which the original allocation call was initiated (only used by TLH allocations, can be NULL in other cases)
86
* @param[in] allocateDescription The description of the requested allocation
87
* @param[in] allocationType The type of allocation to perform
88
*
89
* @return The result of the allocation (NULL on failure)
90
*/
91
virtual void *lockedAllocate(MM_EnvironmentBase *env, MM_ObjectAllocationInterface *objectAllocationInterface, MM_AllocateDescription *allocateDescription, MM_MemorySubSpace::AllocationType allocationType) = 0;
92
93
/**
94
* Called when the given region has been deemed empty, but is not a FREE region. The receiver is responsible for changing the region type and ensuring that it is appropriately stored.
95
* @param env[in] The calling thread (typically the main GC thread)
96
* @param region[in] The region to recycle
97
*/
98
virtual void recycleRegion(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC *region) = 0;
99
100
/**
101
* Called during tear down of a subspace to discard any regions which comprise the subspace.
102
* The region should be FREE (not IDLE!) on completion of this call.
103
* @param env[in] The calling thread (typically the main GC thread)
104
* @param region[in] The region to tear down
105
*/
106
virtual void tearDownRegion(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region) = 0;
107
108
/**
109
* Called during both expansion and during region recycling (if the region was owned by this context, it will come through this path when
110
* recycled). This method can only accept FREE regions.
111
* @param env[in] The thread which expanded the region or recycled it
112
* @param region[in] The region which should be added to our free list
113
*/
114
virtual void addRegionToFreeList(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region) = 0;
115
116
/**
117
* Reset region count, used by TGC
118
* @param regionType type of the region that we reset the count for
119
*/
120
virtual void resetRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;
121
/**
122
* Increment region count, used by TGC
123
* @param regionType type of the region that we update the count for
124
*/
125
virtual void incRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;
126
127
/**
128
* Return the region count associated with this AC, used by TGC
129
* @param regionType type of the region that we get the count for
130
* @return region count
131
*/
132
virtual UDATA getRegionCount(MM_HeapRegionDescriptor::RegionType regionType) = 0;
133
134
/**
135
* Reset mutator count, used by TGC
136
*/
137
virtual void resetThreadCount() = 0;
138
139
/**
140
* Increment mutator count, used by TGC
141
*/
142
virtual void incThreadCount() = 0;
143
144
/**
145
* Return the mutator count associated with this AC, used by TGC
146
*
147
* @return mutator count
148
*/
149
virtual UDATA getThreadCount() = 0;
150
151
/**
152
* Return the NUMA node with which this AC is associated, or 0 if none
153
*
154
* @return associated NUMA node
155
*/
156
virtual UDATA getNumaNode() = 0;
157
158
/**
159
* Return the amount of free memory currently managed by the context. This value is always accurate (that is, there is no time when it becomes
160
* out of sync with the actual amount of free memory managed by the context).
161
*
162
* @return The free memory managed by the receiver, in bytes.
163
*/
164
virtual UDATA getFreeMemorySize() = 0;
165
166
/**
167
* Return the number of free (empty) regions currently managed by the context. This value is always accurate (that is, there is no time when it becomes
168
* out of sync with the actual number of regions managed by the context).
169
*
170
* @return The count of free regions managed by the receiver.
171
*/
172
virtual UDATA getFreeRegionCount() = 0;
173
174
/**
175
* Called to reset the largest free entry in all the MemoryPoolBumpPointer instances in the regions managed by the receiver.
176
*/
177
virtual void resetLargestFreeEntry() = 0;
178
179
/**
180
* @return The largest free entry out of all the pools managed by the receiver.
181
*/
182
virtual UDATA getLargestFreeEntry() = 0;
183
184
/**
185
* Called to move the given region directly from the receiver and into the target context instance. Note that this method can only
186
* be called in one thread on any instance since it directly manipulates lists across contexts. The caller is responsible for
187
* ensuring that these threading semantics are preserved.
188
* @param region[in] The region to migrate from the receiver
189
* @param newOwner[in] The context to which the given region is being migrated
190
*/
191
virtual void migrateRegionToAllocationContext(MM_HeapRegionDescriptorVLHGC *region, MM_AllocationContextTarok *newOwner) = 0;
192
193
/**
194
* Called by migrateRegionToAllocationContext on the target context receiving the migrated region.
195
* The receiver will insert the migrated context in its list.
196
*
197
* @param region[in] The region to accept
198
*/
199
virtual void acceptMigratingRegion(MM_HeapRegionDescriptorVLHGC *region) = 0;
200
201
/**
202
* This helper merely forwards the resetHeapStatistics call on to all the memory pools owned by the receiver.
203
* @param globalCollect[in] True if this was a global collect (blindly passed through)
204
*/
205
virtual void resetHeapStatistics(bool globalCollect) = 0;
206
207
/**
208
* This helper merely forwards the mergeHeapStats call on to all the memory pools owned by the receiver.
209
* @param heapStats[in/out] The stats structure to receive the merged data (blindly passed through)
210
* @param includeMemoryType[in] The memory space type to use in the merge (blindly passed through)
211
*/
212
virtual void mergeHeapStats(MM_HeapStats *heapStats, UDATA includeMemoryType) = 0;
213
214
/**
215
* Used by TGC to get the count of regions owned by this context. Differentiates between regions node-local to the context and node-foreign.
216
* @param localCount[out] The number of regions owned by the receiver which are bound to the node in which the receiver logically operates
217
* @param foreignCount[out] The number of regions owned by the receiver which are NOT bound to the node in which the receiver logically operates
218
*/
219
virtual void getRegionCount(UDATA *localCount, UDATA *foreignCount) = 0;
220
221
/**
222
* Remove the specified region from the flushed regions list.
223
*
224
* @param region[in] The region to remove from the list
225
*/
226
virtual void removeRegionFromFlushedList(MM_HeapRegionDescriptorVLHGC *region) = 0;
227
228
/**
229
* Set the NUMA affinity for the current thread.
230
* @param env[in] the current thread
231
* @return true upon success, false otherwise
232
*/
233
virtual bool setNumaAffinityForThread(MM_EnvironmentBase *env) = 0;
234
235
/**
236
* Clear the NUMA affinity of the current thread.
237
* Call the thread library to bind the thread to all eligible CPUs.
238
* @param env[in] the current thread
239
* @see MM_RuntimeExecManager
240
*/
241
MMINLINE void clearNumaAffinityForThread(MM_EnvironmentBase *env) { env->setNumaAffinity(NULL, 0); }
242
243
/**
244
* Determines whether or not a region should be migrated to the common context.
245
*
246
* @param env[in] The current GC thread
247
* @param region[in] The VLHGC region
248
*/
249
virtual bool shouldMigrateRegionToCommonContext(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region);
250
251
protected:
252
MM_AllocationContextTarok(UDATA allocationContextNumber, AllocationContextType allocationContextType)
253
: MM_AllocationContext()
254
, _allocationContextNumber(allocationContextNumber)
255
, _allocationContextType(allocationContextType)
256
{
257
_typeId = __FUNCTION__;
258
}
259
260
/**
261
* Replenish the receiver to satisfy the given allocation description and type and then re-attempt the allocation, returning the result.
262
* @note The calling env must own the receiver's _contextLock or have exclusive VM access
263
*
264
* @param env[in] A GC thread (must own either _contextLock or have exclusive access)
265
* @param objectAllocationInterface[in] If this is a TLH allocation request, this will be the interface used to initialize the TLH (is NULL in non-TLH allocations)
266
* @param allocateDescription[in] A description of the allocate
267
* @param allocationType[in] The type of the allocation
268
* @return The base address of the allocation or NULL in the case of failure
269
*/
270
virtual void *lockedReplenishAndAllocate(MM_EnvironmentBase *env, MM_ObjectAllocationInterface *objectAllocationInterface, MM_AllocateDescription *allocateDescription, MM_MemorySubSpace::AllocationType allocationType) = 0;
271
272
/**
273
* Select a region for contraction from the receiver.
274
* The returned region will be region type FREE.
275
* @param env the environment
276
* @return the region to contract, or NULL if none available
277
*/
278
virtual MM_HeapRegionDescriptorVLHGC * selectRegionForContraction(MM_EnvironmentBase *env) = 0;
279
280
private:
281
282
/*
283
* Friends
284
*/
285
/* the MSST is currently responsible for replenishing the ACT so let it reach in to update the regions in the cache */
286
friend class MM_MemorySubSpaceTarok;
287
288
};
289
290
#endif /* ALLOCATIONCONTEXTTAROK_HPP */
291
292