-
Notifications
You must be signed in to change notification settings - Fork 392
/
ConfigurationGenerational.cpp
269 lines (229 loc) · 11 KB
/
ConfigurationGenerational.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*******************************************************************************
* Copyright (c) 1991, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
/**
* @file
* @ingroup GC_Modron_Standard
*/
#include "MemorySpacesAPI.h"
#include "ModronAssertions.h"
#if defined(OMR_GC_MODRON_SCAVENGER)
#include "ConfigurationGenerational.hpp"
#include "EnvironmentStandard.hpp"
#include "GCExtensionsBase.hpp"
#include "HeapSplit.hpp"
#include "MemoryPool.hpp"
#include "MemoryPoolAddressOrderedList.hpp"
#include "MemorySpace.hpp"
#include "MemorySubSpaceFlat.hpp"
#include "MemorySubSpaceGenerational.hpp"
#include "MemorySubSpaceGeneric.hpp"
#include "MemorySubSpaceSemiSpace.hpp"
#include "PhysicalArenaVirtualMemory.hpp"
#include "PhysicalSubArenaVirtualMemoryFlat.hpp"
#include "PhysicalSubArenaVirtualMemorySemiSpace.hpp"
#include "Scavenger.hpp"
MM_Configuration *
MM_ConfigurationGenerational::newInstance(MM_EnvironmentBase *env)
{
MM_ConfigurationGenerational *configuration;
configuration = (MM_ConfigurationGenerational *) env->getForge()->allocate(sizeof(MM_ConfigurationGenerational), OMR::GC::AllocationCategory::FIXED, OMR_GET_CALLSITE());
if(NULL != configuration) {
new(configuration) MM_ConfigurationGenerational(env);
if(!configuration->initialize(env)) {
configuration->kill(env);
configuration = NULL;
}
}
return configuration;
}
void
MM_ConfigurationGenerational::tearDown(MM_EnvironmentBase* env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
/* Set pointer to scavenger in extensions to NULL
* before Scavenger is teared down as part of clean up of defaultMemorySpace
* in MM_Configuration::tearDown. */
extensions->scavenger = NULL;
MM_ConfigurationStandard::tearDown(env);
}
bool
MM_ConfigurationGenerational::initialize(MM_EnvironmentBase* env)
{
MM_GCExtensionsBase* extensions = env->getExtensions();
if (!extensions->dnssExpectedRatioMaximum._wasSpecified) {
extensions->dnssExpectedRatioMaximum._valueSpecified = 0.05;
}
if (!extensions->dnssExpectedRatioMinimum._wasSpecified) {
extensions->dnssExpectedRatioMinimum._valueSpecified = 0.01;
}
return MM_ConfigurationStandard::initialize(env);
}
MM_MemorySubSpaceSemiSpace *
MM_ConfigurationGenerational::createSemiSpace(MM_EnvironmentBase *envBase, MM_Heap *heap, MM_Scavenger *scavenger, MM_InitializationParameters *parameters, UDATA numaNode)
{
MM_EnvironmentStandard *env = MM_EnvironmentStandard::getEnvironment(envBase);
MM_GCExtensionsBase *ext = env->getExtensions();
MM_MemorySubSpaceSemiSpace *memorySubSpaceSemiSpace = NULL;
MM_MemoryPoolAddressOrderedList *memoryPoolAllocate = NULL, *memoryPoolSurvivor = NULL;
MM_MemorySubSpaceGeneric *memorySubSpaceGenericAllocate = NULL, *memorySubSpaceGenericSurvivor = NULL;
MM_PhysicalSubArenaVirtualMemorySemiSpace *physicalSubArenaSemiSpace = NULL;
UDATA minimumFreeEntrySize = ext->getMinimumFreeEntrySize();
/* Create Sweep Pool Manager for Nursery if we can not use manager created for Tenure */
if (!createSweepPoolManagerAddressOrderedList(env)) {
return NULL;
}
/* allocate space */
if(NULL == (memoryPoolAllocate = MM_MemoryPoolAddressOrderedList::newInstance(env, minimumFreeEntrySize, "Allocate/Survivor1"))) {
return NULL;
}
if(NULL == (memorySubSpaceGenericAllocate = MM_MemorySubSpaceGeneric::newInstance(env, memoryPoolAllocate, NULL, false, parameters->_minimumNewSpaceSize / 2, parameters->_initialNewSpaceSize / 2, parameters->_maximumNewSpaceSize, MEMORY_TYPE_NEW, 0))) {
memoryPoolAllocate->kill(env);
return NULL;
}
/* survivor space */
if(NULL == (memoryPoolSurvivor = MM_MemoryPoolAddressOrderedList::newInstance(env, minimumFreeEntrySize, "Allocate/Survivor2"))) {
memorySubSpaceGenericAllocate->kill(env);
return NULL;
}
if(NULL == (memorySubSpaceGenericSurvivor = MM_MemorySubSpaceGeneric::newInstance(env, memoryPoolSurvivor, NULL, false, parameters->_minimumNewSpaceSize / 2, parameters->_initialNewSpaceSize / 2, parameters->_maximumNewSpaceSize, MEMORY_TYPE_NEW, 0))) {
memoryPoolSurvivor->kill(env);
memorySubSpaceGenericAllocate->kill(env);
return NULL;
}
if(NULL == (physicalSubArenaSemiSpace = MM_PhysicalSubArenaVirtualMemorySemiSpace::newInstance(envBase, heap))) {
memorySubSpaceGenericAllocate->kill(env);
memorySubSpaceGenericSurvivor->kill(env);
return NULL;
}
physicalSubArenaSemiSpace->setNumaNode(numaNode);
if(NULL == (memorySubSpaceSemiSpace = MM_MemorySubSpaceSemiSpace::newInstance(env, scavenger, physicalSubArenaSemiSpace, memorySubSpaceGenericAllocate, memorySubSpaceGenericSurvivor, false, parameters->_minimumNewSpaceSize, parameters->_initialNewSpaceSize, parameters->_maximumNewSpaceSize))) {
memorySubSpaceGenericAllocate->kill(env);
memorySubSpaceGenericSurvivor->kill(env);
physicalSubArenaSemiSpace->kill(env);
return NULL;
}
return memorySubSpaceSemiSpace;
}
MM_MemorySpace *
MM_ConfigurationGenerational::createDefaultMemorySpace(MM_EnvironmentBase *envBase, MM_Heap *heap, MM_InitializationParameters *parameters)
{
MM_MemoryPool *memoryPoolOld = NULL;
MM_MemorySubSpaceGeneric *memorySubSpaceGenericOld = NULL;
MM_PhysicalSubArenaVirtualMemoryFlat *physicalSubArenaFlat = NULL;
MM_MemorySubSpaceFlat *memorySubSpaceOld = NULL;
MM_Scavenger *scavenger = NULL;
MM_MemorySubSpaceGenerational *memorySubSpaceGenerational = NULL;
MM_MemorySubSpace *memorySubSpaceNew = NULL;
MM_PhysicalArenaVirtualMemory *physicalArena = NULL;
MM_EnvironmentStandard *env = MM_EnvironmentStandard::getEnvironment(envBase);
MM_GCExtensionsBase *ext = env->getExtensions();
/* first we do the structures that correspond to the "old area" */
if(NULL == (memoryPoolOld = createMemoryPool(env, true))) {
return NULL;
}
if(NULL == (memorySubSpaceGenericOld = MM_MemorySubSpaceGeneric::newInstance(env, memoryPoolOld, NULL, false, parameters->_minimumOldSpaceSize, parameters->_initialOldSpaceSize, parameters->_maximumOldSpaceSize, MEMORY_TYPE_OLD, 0))) {
memoryPoolOld->kill(env);
return NULL;
}
if(NULL == (physicalSubArenaFlat = MM_PhysicalSubArenaVirtualMemoryFlat::newInstance(env, heap))) {
memorySubSpaceGenericOld->kill(env);
return NULL;
}
if(NULL == (memorySubSpaceOld = MM_MemorySubSpaceFlat::newInstance(env, physicalSubArenaFlat, memorySubSpaceGenericOld, false, parameters->_minimumOldSpaceSize, parameters->_initialOldSpaceSize, parameters->_maximumOldSpaceSize, MEMORY_TYPE_OLD, 0))) {
physicalSubArenaFlat->kill(env);
memorySubSpaceGenericOld->kill(env);
return NULL;
}
/* then we build "new-space" - note that if we fail during this we must remember to kill() the oldspace we created */
/* join them with a semispace */
if(NULL == (scavenger = MM_Scavenger::newInstance(env, ext->heapRegionManager))) {
memorySubSpaceOld->kill(env);
return NULL;
}
if(NULL == (memorySubSpaceNew = createSemiSpace(env, heap, scavenger, parameters))) {
memorySubSpaceOld->kill(env);
}
/* then we join newspace and oldspace together */;
if(NULL == (memorySubSpaceGenerational = MM_MemorySubSpaceGenerational::newInstance(envBase, memorySubSpaceNew, memorySubSpaceOld, true, parameters->_minimumSpaceSize, parameters->_minimumNewSpaceSize, parameters->_initialNewSpaceSize, parameters->_maximumNewSpaceSize, parameters->_minimumOldSpaceSize, parameters->_initialOldSpaceSize, parameters->_maximumOldSpaceSize, parameters->_maximumSpaceSize))) {
memorySubSpaceNew->kill(env);
memorySubSpaceOld->kill(env);
return NULL;
}
if(NULL == (physicalArena = MM_PhysicalArenaVirtualMemory::newInstance(env, heap))) {
memorySubSpaceGenerational->kill(env);
return NULL;
}
/* register the scavenger in GCExtensionsBase */
ext->scavenger = scavenger;
return MM_MemorySpace::newInstance(env, heap, physicalArena, memorySubSpaceGenerational, parameters, MEMORY_SPACE_NAME_GENERATIONAL, MEMORY_SPACE_DESCRIPTION_GENERATIONAL);
}
/**
* Gencon can run in a split-heap virtual memory heap so see if the options for that have been set here or defer to our super
*/
MM_Heap *
MM_ConfigurationGenerational::createHeapWithManager(MM_EnvironmentBase *env, UDATA heapBytesRequested, MM_HeapRegionManager *regionManager)
{
MM_GCExtensionsBase *extensions = env->getExtensions();
MM_Heap *heap = NULL;
#if defined(OMR_GC_MODRON_SCAVENGER)
/* gencon supports split heaps so check that flag here when deciding what kind of MM_Heap to create */
if (extensions->enableSplitHeap) {
UDATA lowSize = extensions->oldSpaceSize;
UDATA highSize = extensions->newSpaceSize;
Assert_MM_true((lowSize + highSize) == heapBytesRequested);
heap = MM_HeapSplit::newInstance(env, extensions->heapAlignment, lowSize, highSize, regionManager);
/* FUTURE: if this heap is NULL, we could try again with the arguments in the other order but that would require that we
* set and "inverted" flag in the extensions and check that in the PSA attach code when determining attachment policy.
* May allow more versatile use cases of the split heaps, though.
*/
} else
#endif /* OMR_GC_MODRON_SCAVENGER */
{
heap = MM_ConfigurationStandard::createHeapWithManager(env, heapBytesRequested, regionManager);
}
return heap;
}
void
MM_ConfigurationGenerational::defaultMemorySpaceAllocated(MM_GCExtensionsBase *extensions, void* defaultMemorySpace)
{
MM_Configuration::defaultMemorySpaceAllocated(extensions, defaultMemorySpace);
/*
* Assume that the nursery is always at the top of the heap.
* Assume that the nursery was allocated with the expected minNewSpaceSize
*/
U_8* nurseryTop = (U_8*)extensions->getHeap()->getHeapTop();
U_8* nurseryStart = nurseryTop - extensions->minNewSpaceSize;
/* we can guarantee that the nursery is the topmost object space */
extensions->setGuaranteedNurseryRange(nurseryStart, (void*)UDATA_MAX);
}
uintptr_t
MM_ConfigurationGenerational::calculateDefaultRegionSize(MM_EnvironmentBase *env)
{
uintptr_t regionSize = STANDARD_REGION_SIZE_BYTES;
MM_GCExtensionsBase *extensions = env->getExtensions();
if (extensions->isConcurrentScavengerHWSupported()) {
/* set region size based at concurrentScavengerPageSectionSize */
regionSize = extensions->getConcurrentScavengerPageSectionSize();
}
return regionSize;
}
#endif /* defined(OMR_GC_MODRON_SCAVENGER) */