Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/ConfigurationDelegate.hpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2017, 2021 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
#ifndef CONFIGURATIONDELEGATE_HPP_
24
#define CONFIGURATIONDELEGATE_HPP_
25
26
#include "j9.h"
27
#include "j9cfg.h"
28
#include "j9consts.h"
29
#include "j9nonbuilder.h"
30
#include "omrgcconsts.h"
31
#include "sizeclasses.h"
32
33
#include "ClassLoaderManager.hpp"
34
#include "ConcurrentGC.hpp"
35
#include "EnvironmentBase.hpp"
36
#include "GCExtensions.hpp"
37
#include "GlobalAllocationManager.hpp"
38
#include "Heap.hpp"
39
#include "HeapRegionDescriptor.hpp"
40
#include "HeapRegionManager.hpp"
41
#include "ObjectAccessBarrier.hpp"
42
#include "ObjectAllocationInterface.hpp"
43
#include "StringTable.hpp"
44
45
#include "OwnableSynchronizerObjectList.hpp"
46
#include "ReferenceObjectList.hpp"
47
#include "UnfinalizedObjectList.hpp"
48
49
typedef struct MM_HeapRegionDescriptorStandardExtension {
50
uintptr_t _maxListIndex; /**< Max index for _*ObjectLists[index] */
51
MM_UnfinalizedObjectList *_unfinalizedObjectLists; /**< An array of lists of unfinalized objects in this region */
52
MM_OwnableSynchronizerObjectList *_ownableSynchronizerObjectLists; /**< An array of lists of ownable synchronizer objects in this region */
53
MM_ReferenceObjectList *_referenceObjectLists; /**< An array of lists of reference objects (i.e. weak/soft/phantom) in this region */
54
} MM_HeapRegionDescriptorStandardExtension;
55
56
class MM_ConfigurationDelegate
57
{
58
/*
59
* Member data and types
60
*/
61
private:
62
static const uintptr_t _maximumDefaultNumberOfGCThreads = 64;
63
const MM_GCPolicy _gcPolicy;
64
65
protected:
66
public:
67
68
/*
69
* Member functions
70
*/
71
private:
72
protected:
73
74
public:
75
bool
76
initialize(MM_EnvironmentBase* env, MM_GCWriteBarrierType writeBarrierType, MM_GCAllocationType allocationType)
77
{
78
/* sync J9 VM arraylet size with OMR VM */
79
OMR_VM* omrVM = env->getOmrVM();
80
J9JavaVM* javaVM = (J9JavaVM*)omrVM->_language_vm;
81
javaVM->arrayletLeafSize = omrVM->_arrayletLeafSize;
82
javaVM->arrayletLeafLogSize = omrVM->_arrayletLeafLogSize;
83
84
/* set write barrier for J9 VM -- catch -Xgc:alwayscallwritebarrier first */
85
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(javaVM);
86
if (extensions->alwaysCallWriteBarrier) {
87
writeBarrierType = gc_modron_wrtbar_always;
88
}
89
90
Assert_MM_true(gc_modron_wrtbar_illegal != writeBarrierType);
91
javaVM->gcWriteBarrierType = writeBarrierType;
92
93
if (extensions->alwaysCallReadBarrier) {
94
/* AlwaysCallReadBarrier takes precedence over other read barrier types */
95
javaVM->gcReadBarrierType = gc_modron_readbar_always;
96
} else if (extensions->isScavengerEnabled() && extensions->isConcurrentScavengerEnabled()) {
97
javaVM->gcReadBarrierType = gc_modron_readbar_range_check;
98
} else if (extensions->isVLHGC() && extensions->isConcurrentCopyForwardEnabled()) {
99
javaVM->gcReadBarrierType = gc_modron_readbar_region_check;
100
} else {
101
javaVM->gcReadBarrierType = gc_modron_readbar_none;
102
}
103
104
/* set allocation type for J9 VM */
105
javaVM->gcAllocationType = allocationType;
106
107
if (!extensions->dynamicClassUnloadingSet) {
108
extensions->dynamicClassUnloading = MM_GCExtensions::DYNAMIC_CLASS_UNLOADING_ON_CLASS_LOADER_CHANGES;
109
}
110
111
/* Enable string constant collection by default if we support class unloading */
112
extensions->collectStringConstants = true;
113
114
/*
115
* note that these are the default thresholds but Realtime Configurations override these values, in their initialize methods
116
* (hence it is key for them to call their super initialize, first)
117
*/
118
#define DYNAMIC_CLASS_UNLOADING_THRESHOLD 6
119
#define DYNAMIC_CLASS_UNLOADING_KICKOFF_THRESHOLD 80000
120
121
if (!extensions->dynamicClassUnloadingThresholdForced) {
122
extensions->dynamicClassUnloadingThreshold = DYNAMIC_CLASS_UNLOADING_THRESHOLD;
123
}
124
if (!extensions->dynamicClassUnloadingKickoffThresholdForced) {
125
extensions->dynamicClassUnloadingKickoffThreshold = DYNAMIC_CLASS_UNLOADING_KICKOFF_THRESHOLD;
126
}
127
return true;
128
}
129
130
void
131
tearDown(MM_EnvironmentBase* env)
132
{
133
J9JavaVM* vm = (J9JavaVM*)env->getOmrVM()->_language_vm;
134
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
135
136
if (NULL != vm->identityHashData) {
137
env->getForge()->free(vm->identityHashData);
138
vm->identityHashData = NULL;
139
}
140
141
if (NULL != extensions->classLoaderManager) {
142
extensions->classLoaderManager->kill(env);
143
extensions->classLoaderManager = NULL;
144
}
145
146
if (NULL != extensions->stringTable) {
147
extensions->stringTable->kill(env);
148
extensions->stringTable = NULL;
149
}
150
}
151
152
OMR_SizeClasses *getSegregatedSizeClasses(MM_EnvironmentBase* env)
153
{
154
J9JavaVM* javaVM = (J9JavaVM*)env->getOmrVM()->_language_vm;
155
return (OMR_SizeClasses*)(javaVM->realtimeSizeClasses);
156
}
157
158
static MM_HeapRegionDescriptorStandardExtension *
159
getHeapRegionDescriptorStandardExtension(MM_EnvironmentBase* env, MM_HeapRegionDescriptor *region)
160
{
161
MM_HeapRegionDescriptorStandardExtension *regionExtension = NULL;
162
if (env->getExtensions()->isStandardGC()) {
163
regionExtension = (MM_HeapRegionDescriptorStandardExtension *)region->_heapRegionDescriptorExtension;
164
}
165
return regionExtension;
166
}
167
168
bool
169
initializeHeapRegionDescriptorExtension(MM_EnvironmentBase* env, MM_HeapRegionDescriptor *region)
170
{
171
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
172
173
if (extensions->isStandardGC()) {
174
uintptr_t listCount = extensions->gcThreadCount;
175
uintptr_t allocSize = sizeof(MM_HeapRegionDescriptorStandardExtension) + (listCount * (sizeof(MM_UnfinalizedObjectList) + sizeof(MM_OwnableSynchronizerObjectList) + sizeof(MM_ReferenceObjectList)));
176
MM_HeapRegionDescriptorStandardExtension *regionExtension = (MM_HeapRegionDescriptorStandardExtension *)env->getForge()->allocate(allocSize, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
177
if (NULL == regionExtension) {
178
return false;
179
}
180
181
regionExtension->_maxListIndex = listCount;
182
regionExtension->_unfinalizedObjectLists = (MM_UnfinalizedObjectList *) ((uintptr_t)regionExtension + sizeof(MM_HeapRegionDescriptorStandardExtension));
183
regionExtension->_ownableSynchronizerObjectLists = (MM_OwnableSynchronizerObjectList *) (regionExtension->_unfinalizedObjectLists + listCount);
184
regionExtension->_referenceObjectLists = (MM_ReferenceObjectList *) (regionExtension->_ownableSynchronizerObjectLists + listCount);
185
186
for (uintptr_t list = 0; list < listCount; list++) {
187
new(&regionExtension->_unfinalizedObjectLists[list]) MM_UnfinalizedObjectList();
188
regionExtension->_unfinalizedObjectLists[list].setNextList(extensions->unfinalizedObjectLists);
189
regionExtension->_unfinalizedObjectLists[list].setPreviousList(NULL);
190
if (NULL != extensions->unfinalizedObjectLists) {
191
extensions->unfinalizedObjectLists->setPreviousList(&regionExtension->_unfinalizedObjectLists[list]);
192
}
193
extensions->unfinalizedObjectLists = &regionExtension->_unfinalizedObjectLists[list];
194
195
new(&regionExtension->_ownableSynchronizerObjectLists[list]) MM_OwnableSynchronizerObjectList();
196
regionExtension->_ownableSynchronizerObjectLists[list].setNextList(extensions->getOwnableSynchronizerObjectLists());
197
regionExtension->_ownableSynchronizerObjectLists[list].setPreviousList(NULL);
198
if (NULL != extensions->getOwnableSynchronizerObjectLists()) {
199
extensions->getOwnableSynchronizerObjectLists()->setPreviousList(&regionExtension->_ownableSynchronizerObjectLists[list]);
200
}
201
extensions->setOwnableSynchronizerObjectLists(&regionExtension->_ownableSynchronizerObjectLists[list]);
202
203
new(&regionExtension->_referenceObjectLists[list]) MM_ReferenceObjectList();
204
}
205
206
region->_heapRegionDescriptorExtension = regionExtension;
207
}
208
209
return true;
210
}
211
212
void
213
teardownHeapRegionDescriptorExtension(MM_EnvironmentBase* env, MM_HeapRegionDescriptor *region)
214
{
215
if (env->getExtensions()->isStandardGC()) {
216
if (NULL != region->_heapRegionDescriptorExtension) {
217
env->getForge()->free(region->_heapRegionDescriptorExtension);
218
region->_heapRegionDescriptorExtension = NULL;
219
}
220
}
221
}
222
223
bool
224
heapInitialized(MM_EnvironmentBase* env)
225
{
226
MM_Heap *heap = env->getExtensions()->getHeap();
227
MM_HeapRegionManager *heapRegionManager = heap->getHeapRegionManager();
228
229
uintptr_t hashSaltCount = 0;
230
uintptr_t hashSaltPolicy = J9_IDENTITY_HASH_SALT_POLICY_NONE;
231
232
switch (_gcPolicy) {
233
case gc_policy_optthruput:
234
case gc_policy_nogc:
235
case gc_policy_optavgpause:
236
case gc_policy_gencon:
237
hashSaltCount = 1;
238
hashSaltPolicy = J9_IDENTITY_HASH_SALT_POLICY_STANDARD;
239
break;
240
case gc_policy_metronome:
241
break;
242
case gc_policy_balanced:
243
hashSaltCount = heapRegionManager->getTableRegionCount();
244
hashSaltPolicy = J9_IDENTITY_HASH_SALT_POLICY_REGION;
245
break;
246
default:
247
Assert_MM_unreachable();
248
break;
249
}
250
251
J9JavaVM* javaVM = (J9JavaVM*)env->getOmrVM()->_language_vm;
252
uintptr_t size = offsetof(J9IdentityHashData, hashSaltTable) + (sizeof(U_32) * hashSaltCount);
253
javaVM->identityHashData = (J9IdentityHashData*)env->getForge()->allocate(size, MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
254
bool result = NULL != javaVM->identityHashData;
255
if (result) {
256
J9IdentityHashData* hashData = javaVM->identityHashData;
257
hashData->hashData1 = UDATA_MAX;
258
hashData->hashData2 = 0;
259
hashData->hashData3 = 0;
260
hashData->hashData4 = 0;
261
hashData->hashSaltPolicy = hashSaltPolicy;
262
switch (hashSaltPolicy) {
263
case J9_IDENTITY_HASH_SALT_POLICY_NONE:
264
break;
265
case J9_IDENTITY_HASH_SALT_POLICY_STANDARD:
266
javaVM->identityHashData->hashSaltTable[J9GC_HASH_SALT_NURSERY_INDEX] = (U_32)convertValueToHash(javaVM, 1421595292 ^ (U_32)(uintptr_t)javaVM);
267
break;
268
case J9_IDENTITY_HASH_SALT_POLICY_REGION:
269
for (uintptr_t index = 0; index < hashSaltCount; index++) {
270
javaVM->identityHashData->hashSaltTable[index] = (U_32)convertValueToHash(javaVM, 1421595292 ^ (U_32)(uintptr_t)heapRegionManager->physicalTableDescriptorForIndex(index));
271
}
272
hashData->hashData1 = (uintptr_t)heap->getHeapBase();
273
hashData->hashData2 = (uintptr_t)heap->getHeapTop();
274
hashData->hashData3 = heapRegionManager->getRegionShift();
275
hashData->hashData4 = hashSaltCount;
276
break;
277
default:
278
result = false;
279
break;
280
}
281
}
282
return result;
283
}
284
285
uint32_t
286
getInitialNumberOfPooledEnvironments(MM_EnvironmentBase* env)
287
{
288
return 0;
289
}
290
291
bool
292
environmentInitialized(MM_EnvironmentBase* env)
293
{
294
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
295
J9VMThread* vmThread = (J9VMThread *)env->getLanguageVMThread();
296
OMR_VM *omrVM = env->getOmrVM();
297
298
/* only assign this parent list if we are going to use it */
299
if (extensions->isStandardGC()) {
300
vmThread->gcRememberedSet.parentList = &extensions->rememberedSet;
301
}
302
303
extensions->accessBarrier->initializeForNewThread(env);
304
305
if ((extensions->isConcurrentMarkEnabled()) && (!extensions->usingSATBBarrier())) {
306
#if defined(OMR_GC_MODRON_CONCURRENT_MARK)
307
vmThread->cardTableVirtualStart = (U_8*)j9gc_incrementalUpdate_getCardTableVirtualStart(omrVM);
308
vmThread->cardTableShiftSize = j9gc_incrementalUpdate_getCardTableShiftValue(omrVM);
309
MM_ConcurrentGC *concurrentGC = (MM_ConcurrentGC *)extensions->getGlobalCollector();
310
if (!extensions->optimizeConcurrentWB || (CONCURRENT_OFF < concurrentGC->getConcurrentGCStats()->getExecutionMode())) {
311
vmThread->privateFlags |= J9_PRIVATE_FLAGS_CONCURRENT_MARK_ACTIVE;
312
}
313
#else
314
Assert_MM_unreachable();
315
#endif /* OMR_GC_MODRON_CONCURRENT_MARK */
316
} else if (extensions->isVLHGC()) {
317
#if defined(OMR_GC_VLHGC)
318
vmThread->cardTableVirtualStart = (U_8 *)j9gc_incrementalUpdate_getCardTableVirtualStart(omrVM);
319
vmThread->cardTableShiftSize = j9gc_incrementalUpdate_getCardTableShiftValue(omrVM);
320
#else
321
Assert_MM_unreachable();
322
#endif /* OMR_GC_VLHGC */
323
} else {
324
vmThread->cardTableVirtualStart = (U_8*)NULL;
325
vmThread->cardTableShiftSize = 0;
326
}
327
328
if (extensions->fvtest_disableInlineAllocation) {
329
env->_objectAllocationInterface->disableCachedAllocations(env);
330
}
331
332
return true;
333
}
334
335
bool canCollectFragmentationStats(MM_EnvironmentBase *env)
336
{
337
J9JavaVM* javaVM = (J9JavaVM*)env->getOmrVM()->_language_vm;
338
/* processing estimate Fragmentation only is on non startup stage to avoid startup regression(fragmentation during startup is not meaningful for the estimation)
339
it is only for jit mode(for int mode javaVM->phase is always J9VM_PHASE_NOT_STARTUP) */
340
return (J9VM_PHASE_NOT_STARTUP == javaVM->phase);
341
}
342
343
uintptr_t getMaxGCThreadCount(MM_EnvironmentBase* env)
344
{
345
return _maximumDefaultNumberOfGCThreads;
346
}
347
348
MM_GCPolicy getGCPolicy() { return _gcPolicy; }
349
350
/**
351
* Constructor.
352
*/
353
MM_ConfigurationDelegate(MM_GCPolicy gcPolicy)
354
: _gcPolicy(gcPolicy)
355
{}
356
};
357
358
#endif /* CONFIGURATIONDELEGATE_HPP_ */
359
360