Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/GlobalAllocationManagerTarok.hpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2019 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
#if !defined(GLOBALALLOCATIONMANAGERTAROK_HPP_)
26
#define GLOBALALLOCATIONMANAGERTAROK_HPP_
27
28
#include "j9.h"
29
#include "j9cfg.h"
30
#include "j9protos.h"
31
#include "j9consts.h"
32
#include "modronopt.h"
33
34
#include "GlobalAllocationManager.hpp"
35
36
#include "AllocationContextBalanced.hpp"
37
#include "AllocationContextTarok.hpp"
38
#include "GCExtensions.hpp"
39
#include "LightweightNonReentrantLock.hpp"
40
#include "MemoryPool.hpp"
41
#include "RuntimeExecManager.hpp"
42
43
class MM_AllocationContextBalanced;
44
class MM_EnvironmentBase;
45
class MM_HeapRegionDescriptorVLHGC;
46
class MM_MemorySubSpaceTarok;
47
class MM_RegionListTarok;
48
49
class MM_GlobalAllocationManagerTarok : public MM_GlobalAllocationManager
50
{
51
/* Data members & types */
52
public:
53
protected:
54
private:
55
MM_AllocationContextBalanced **_perNodeContextSets; /**< an array which is extensions->numaNodes elements long, containing the "first" AllocationContextVLHGC in each corresponding per-node circular list */
56
57
MM_RuntimeExecManager _runtimeExecManager; /**< A helper object used to intercept Runtime.exec() and manage affinity to workaround limitations on Linux */
58
59
60
friend class MM_RuntimeExecManager;
61
62
/* Methods */
63
public:
64
static MM_GlobalAllocationManagerTarok *newInstance(MM_EnvironmentBase *env);
65
virtual void kill(MM_EnvironmentBase *env);
66
virtual bool acquireAllocationContext(MM_EnvironmentBase *env);
67
virtual void releaseAllocationContext(MM_EnvironmentBase *env);
68
virtual void printAllocationContextStats(MM_EnvironmentBase *env, UDATA eventNum, J9HookInterface** hookInterface);
69
/**
70
* Called after the receiver and the subspace have been initialized to request that the receiver build the allocation contexts
71
* it will manager over the course of the run. The subspace is required because the allocation contexts need to know which
72
* subspace logically "owns" its memory.
73
* @param env[in] The current thread (this is the thread bootstrapping the VM)
74
* @param subspace[in] The subspace which logically owns the memory managed by the contexts the receiver is called to create
75
* @return Whether or not all the contexts were successfully initialized
76
*/
77
bool initializeAllocationContexts(MM_EnvironmentBase *env, MM_MemorySubSpaceTarok *subspace);
78
79
/**
80
* @return The actual free memory size of all the regions managed by the contexts under the receiver
81
*/
82
UDATA getActualFreeMemorySize();
83
/**
84
* @return The approximate free memory size of all the regions managed by the contexts under the receiver
85
*/
86
UDATA getApproximateFreeMemorySize();
87
88
/**
89
* Return the number of free (empty) regions managed by the contexts under the receiver.
90
*
91
* @return The count of free regions managed by the contexts under the receiver.
92
*/
93
UDATA getFreeRegionCount();
94
95
/**
96
* Forwarded to the all the MemoryPoolBumpPointer instances managed by the contexts under the receiver
97
*/
98
void resetLargestFreeEntry();
99
/**
100
* Expands into the given region by finding an AllocationContextTarok to manage it. Once this method returns, the given region will
101
* be managed by a context.
102
* @param env[in] The thread performing the expansion
103
* @param region[in] The region which was just expanded
104
*/
105
void expand(MM_EnvironmentBase *env, MM_HeapRegionDescriptorVLHGC *region);
106
/**
107
* @return The largest free entry of all the regions managed by the contexts under the receiver
108
*/
109
UDATA getLargestFreeEntry();
110
111
/**
112
* This helper merely forwards the resetHeapStatistics call on to all the AllocationContextTarok instances owned by the receiver.
113
* @param globalCollect[in] True if this was a global collect (blindly passed through)
114
*/
115
void resetHeapStatistics(bool globalCollect);
116
117
/**
118
* This helper merely forwards the mergeHeapStats call on to all the AllocationContextTarok instances owned by the receiver.
119
* @param heapStats[in/out] The stats structure to receive the merged data (blindly passed through)
120
* @param includeMemoryType[in] The memory space type to use in the merge (blindly passed through)
121
*/
122
void mergeHeapStats(MM_HeapStats *heapStats, UDATA includeMemoryType);
123
124
/**
125
* Get the total number of allocation contexts including the non-managed ones if any.
126
* @return the total allocation context count.
127
*/
128
MMINLINE UDATA getTotalAllocationContextCount()
129
{
130
UDATA totalCount = _managedAllocationContextCount;
131
return totalCount;
132
}
133
134
/**
135
* Get the total number of managed allocation contexts, not including the non-managed ones if any.
136
* @return the managed allocation context count.
137
*/
138
MMINLINE UDATA getManagedAllocationContextCount()
139
{
140
return _managedAllocationContextCount;
141
}
142
143
/**
144
* @param extensions[in] The global GC extensions
145
* @return The ideal number of total allocation contexts (managed + non-managed) with which the receiver assumes it is working
146
*/
147
static UDATA calculateIdealTotalContextCount(MM_GCExtensions *extensions);
148
149
/**
150
* @param extensions[in] The global GC extensions
151
* @return The ideal number of managed allocation contexts with which the receiver assumes it is working
152
*/
153
static UDATA calculateIdealManagedContextCount(MM_GCExtensionsBase *extensions);
154
155
virtual MM_AllocationContextTarok *getAllocationContextByIndex(UDATA index) {
156
157
return (MM_AllocationContextTarok *)MM_GlobalAllocationManager::getAllocationContextByIndex(index);
158
}
159
160
161
162
/**
163
* Find the allocation context for the specified NUMA node.
164
* @param numaNode the NUMA node to search for
165
* @return the associated context
166
*/
167
MM_AllocationContextBalanced *getAllocationContextForNumaNode(UDATA numaNode);
168
169
170
protected:
171
bool initialize(MM_EnvironmentBase *env);
172
virtual void tearDown(MM_EnvironmentBase *env);
173
MM_GlobalAllocationManagerTarok(MM_EnvironmentBase *env)
174
: MM_GlobalAllocationManager(env)
175
, _perNodeContextSets(NULL)
176
, _runtimeExecManager(env)
177
{
178
_typeId = __FUNCTION__;
179
};
180
private:
181
182
/**
183
* Determine if the current thread should be a common thread (non-affinitized) .
184
*
185
* @param env[in] the current thread
186
* @return true if the thread should be treated as common, false otherwise
187
*/
188
bool shouldIdentifyThreadAsCommon(MM_EnvironmentBase *env);
189
190
};
191
192
#endif /* GLOBALALLOCATIONMANAGERTAROK_HPP_ */
193
194