Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_modron_startup/mmhelpers.cpp
5985 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_Startup
27
*/
28
29
#include <string.h>
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "j9comp.h"
34
#include "j9consts.h"
35
#include "j9modron.h"
36
#include "ModronAssertions.h"
37
#include "omr.h"
38
#include "omrcfg.h"
39
#include "VerboseGCInterface.h"
40
41
#if defined(J9VM_GC_FINALIZATION)
42
#include "FinalizeListManager.hpp"
43
#endif /* J9VM_GC_FINALIZATION */
44
#include "GCExtensions.hpp"
45
#include "GlobalCollector.hpp"
46
#include "Heap.hpp"
47
#include "HeapRegionManager.hpp"
48
#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)
49
#include "HeapRegionStateTable.hpp"
50
#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */
51
#include "MemorySpace.hpp"
52
#include "MemorySubSpace.hpp"
53
54
extern "C" {
55
extern J9MemoryManagerFunctions MemoryManagerFunctions;
56
extern void initializeVerboseFunctionTableWithDummies(J9MemoryManagerVerboseInterface *table);
57
58
/**
59
* sets the mode where TLH pages are zeroed
60
* @param flag if non zero, TLH page zeroing will be enabled
61
*/
62
#if defined(J9VM_GC_BATCH_CLEAR_TLH)
63
void
64
allocateZeroedTLHPages(J9JavaVM *javaVM, UDATA flag)
65
{
66
MM_GCExtensions::getExtensions(javaVM)->batchClearTLH = (flag != 0) ? 1 : 0;
67
}
68
69
/**
70
* checks if zeroing TLH pages is enabled
71
*/
72
UDATA
73
isAllocateZeroedTLHPagesEnabled(J9JavaVM *javaVM)
74
{
75
return MM_GCExtensions::getExtensions(javaVM)->batchClearTLH;
76
}
77
#endif /* J9VM_GC_BATCH_CLEAR_TLH */
78
79
UDATA
80
isStaticObjectAllocateFlags(J9JavaVM *javaVM)
81
{
82
return 1;
83
}
84
85
/**
86
* Depending on the configuration (scav or not) returns the object allocate flags
87
* @return OBJECT_HEADER_OLD or 0
88
*/
89
UDATA
90
getStaticObjectAllocateFlags(J9JavaVM *javaVM)
91
{
92
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
93
UDATA result = extensions->heap->getDefaultMemorySpace()->getDefaultMemorySubSpace()->getObjectFlags();
94
95
/* No static flags supposed to be set for flags in clazz slot */
96
Assert_MM_true(0 == result);
97
98
return result;
99
}
100
101
/**
102
* Query JIT string de-duplication strategy
103
*/
104
I_32
105
j9gc_get_jit_string_dedup_policy(J9JavaVM *javaVM)
106
{
107
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
108
if (MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_UNDEFINED == extensions->stringDedupPolicy) {
109
MM_GCExtensions::JitStringDeDupPolicy result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_DISABLED;
110
if (extensions->isStandardGC()) {
111
result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_FAVOUR_LOWER;
112
#if defined(J9VM_GC_MODRON_SCAVENGER)
113
if (extensions->scavengerEnabled) {
114
if (!extensions->dynamicNewSpaceSizing) {
115
result = MM_GCExtensions::J9_JIT_STRING_DEDUP_POLICY_FAVOUR_HIGHER;
116
}
117
}
118
#endif /* J9VM_GC_MODRON_SCAVENGER */
119
}
120
return (I_32) result;
121
} else {
122
return (I_32) extensions->stringDedupPolicy;
123
}
124
}
125
126
/**
127
* Query if scavenger is enabled
128
* @return 1 if scavenger enabled, 0 otherwise
129
*/
130
UDATA
131
j9gc_scavenger_enabled(J9JavaVM *javaVM)
132
{
133
#if defined(J9VM_GC_MODRON_SCAVENGER)
134
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
135
return extensions->scavengerEnabled ? 1 : 0;
136
#else /* J9VM_GC_MODRON_SCAVENGER */
137
return 0;
138
#endif /* J9VM_GC_MODRON_SCAVENGER */
139
}
140
141
UDATA
142
j9gc_concurrent_scavenger_enabled(J9JavaVM *javaVM)
143
{
144
return MM_GCExtensions::getExtensions(javaVM)->isConcurrentScavengerEnabled() ? 1 : 0;
145
}
146
147
UDATA
148
j9gc_software_read_barrier_enabled(J9JavaVM *javaVM)
149
{
150
return MM_GCExtensions::getExtensions(javaVM)->isSoftwareRangeCheckReadBarrierEnabled() ? 1 : 0;
151
}
152
153
/**
154
* Query if hot reference field is reqired for scavenger dynamicBreadthFirstScanOrdering
155
* @return true if scavenger dynamicBreadthFirstScanOrdering is enabled, 0 otherwise
156
*/
157
BOOLEAN
158
j9gc_hot_reference_field_required(J9JavaVM *javaVM)
159
{
160
#if defined(J9VM_GC_MODRON_SCAVENGER) || defined(OMR_GC_VLHGC)
161
return MM_GCExtensions::OMR_GC_SCAVENGER_SCANORDERING_DYNAMIC_BREADTH_FIRST == MM_GCExtensions::getExtensions(javaVM)->scavengerScanOrdering;
162
#else /* J9VM_GC_MODRON_SCAVENGER || OMR_GC_VLHGC */
163
return FALSE;
164
#endif /* defined(J9VM_GC_MODRON_SCAVENGER) || defined(OMR_GC_VLHGC) */
165
}
166
167
/**
168
* Query for the max hot field list length that a class is allowed to have.
169
* Valid if dynamicBreadthFirstScanOrdering is enabled.
170
*/
171
uint32_t
172
j9gc_max_hot_field_list_length(J9JavaVM *javaVM)
173
{
174
return MM_GCExtensions::getExtensions(javaVM)->maxHotFieldListLength;
175
}
176
177
/**
178
* Depending on the configuration (scav vs concurr etc) returns the type of the write barrier
179
* @return write barrier type
180
*/
181
UDATA
182
j9gc_modron_getWriteBarrierType(J9JavaVM *javaVM)
183
{
184
Assert_MM_true(j9gc_modron_wrtbar_illegal != javaVM->gcWriteBarrierType);
185
return javaVM->gcWriteBarrierType;
186
}
187
188
/**
189
* Depending on the configuration returns the type of the read barrier
190
* @return read barrier type
191
*/
192
UDATA
193
j9gc_modron_getReadBarrierType(J9JavaVM *javaVM)
194
{
195
Assert_MM_true(j9gc_modron_readbar_illegal != javaVM->gcReadBarrierType);
196
return javaVM->gcReadBarrierType;
197
}
198
199
/**
200
* Is the JIT allowed to inline allocations?
201
* @return non-zero if inline allocation is allowed, 0 otherwise
202
*/
203
UDATA
204
j9gc_jit_isInlineAllocationSupported(J9JavaVM *javaVM)
205
{
206
return 1;
207
}
208
209
#if defined(J9VM_GC_FINALIZATION)
210
/**
211
* Return the number of objects currently on the finalize queue.
212
* This is to support a Java 5.0 API that allows java code to query this number.
213
* @return number of objects pending finalization
214
*/
215
UDATA
216
j9gc_get_objects_pending_finalization_count(J9JavaVM *javaVM)
217
{
218
return MM_GCExtensions::getExtensions(javaVM)->finalizeListManager->getJobCount();
219
}
220
#endif /* J9VM_GC_FINALIZATION */
221
222
UDATA
223
j9gc_ext_is_marked(J9JavaVM *javaVM, J9Object *objectPtr)
224
{
225
return MM_GCExtensions::getExtensions(javaVM)->getGlobalCollector()->isMarked(objectPtr);
226
}
227
228
UDATA
229
j9gc_modron_isFeatureSupported(J9JavaVM *javaVM, UDATA feature)
230
{
231
J9GCFeatureType typedFeature = (J9GCFeatureType) feature;
232
UDATA featureSupported = FALSE;
233
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
234
235
if (j9gc_modron_feature_inline_reference_get == typedFeature) {
236
if (extensions->isMetronomeGC()) {
237
featureSupported = FALSE;
238
} else {
239
featureSupported = TRUE;
240
}
241
}
242
return featureSupported;
243
}
244
245
/**
246
* Used for checking the value of some piece of externally visible information (instead of adding new API to request every kind of
247
* information when each would have roughly the same shape). The key parameter is of type "J9GCConfigurationKey" (presented as
248
* UDATA due to Builder compatibility fears). If the given key is found, the resulting value is stored into "value" as whatever
249
* type the key defines and TRUE is returned. FALSE is returned and value is untouched if the key is invalid for this configuration
250
* and an unreachable assertion is thrown if the key is unknown.
251
* @param javaVM[in] The JavaVM
252
* @param key[in] An enumerated constant representing the configuration key to query
253
* @param value[out] The value the configuration holds for the given key (actual pointer type is key-defined)
254
* @return TRUE if the key was found and value was populated, FALSE if the key is invalid for this configuration and an unreachable
255
* assertion is thrown if the key is unknown
256
*/
257
UDATA
258
j9gc_modron_getConfigurationValueForKey(J9JavaVM *javaVM, UDATA key, void *value)
259
{
260
UDATA keyFound = FALSE;
261
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
262
263
switch (key) {
264
case j9gc_modron_configuration_none:
265
/* this is the "safe" invalid value - just return false */
266
keyFound = FALSE;
267
break;
268
case j9gc_modron_configuration_heapAddressToCardAddressShift:
269
#if defined (J9VM_GC_HEAP_CARD_TABLE)
270
if (NULL != extensions->cardTable) {
271
*((UDATA *)value) = CARD_SIZE_SHIFT;
272
keyFound = TRUE;
273
} else {
274
/* this is an invalid (but understood) call if there is no card table */
275
keyFound = FALSE;
276
}
277
#else /* defined (J9VM_GC_HEAP_CARD_TABLE) */
278
keyFound = FALSE;
279
#endif /* defined (J9VM_GC_HEAP_CARD_TABLE) */
280
break;
281
case j9gc_modron_configuration_heapBaseForBarrierRange0_isVariable:
282
if (extensions->isVLHGC()) {
283
*((UDATA *)value) = FALSE;
284
keyFound = TRUE;
285
} else if (extensions->isStandardGC()) {
286
*((UDATA *)value) = FALSE;
287
keyFound = TRUE;
288
} else {
289
keyFound = FALSE;
290
}
291
break;
292
case j9gc_modron_configuration_activeCardTableBase_isVariable:
293
if (extensions->isVLHGC()) {
294
*((UDATA *)value) = FALSE;
295
keyFound = TRUE;
296
} else if (extensions->isStandardGC()) {
297
*((UDATA *)value) = FALSE;
298
keyFound = TRUE;
299
} else {
300
keyFound = FALSE;
301
}
302
break;
303
case j9gc_modron_configuration_heapSizeForBarrierRange0_isVariable:
304
if (extensions->isVLHGC()) {
305
*((UDATA *)value) = FALSE;
306
keyFound = TRUE;
307
} else if (extensions->isStandardGC()) {
308
if (extensions->minOldSpaceSize == extensions->maxOldSpaceSize) {
309
*((UDATA *)value) = FALSE;
310
} else {
311
*((UDATA *)value) = TRUE;
312
}
313
keyFound = TRUE;
314
} else {
315
keyFound = FALSE;
316
}
317
break;
318
case j9gc_modron_configuration_minimumObjectSize:
319
#if defined(J9VM_GC_MINIMUM_OBJECT_SIZE)
320
*((UDATA *)value) = J9_GC_MINIMUM_OBJECT_SIZE;
321
keyFound = TRUE;
322
#else
323
keyFound = FALSE;
324
#endif /* defined(J9VM_GC_MINIMUM_OBJECT_SIZE) */
325
break;
326
case j9gc_modron_configuration_objectAlignment:
327
*((UDATA *)value) = extensions->getObjectAlignmentInBytes();
328
keyFound = TRUE;
329
break;
330
case j9gc_modron_configuration_allocationType:
331
Assert_MM_true(j9gc_modron_allocation_type_illegal != javaVM->gcAllocationType);
332
*((UDATA *)value) = javaVM->gcAllocationType;
333
keyFound = TRUE;
334
break;
335
case j9gc_modron_configuration_discontiguousArraylets:
336
*((UDATA *)value) = (UDATA_MAX != extensions->getOmrVM()->_arrayletLeafSize) ? TRUE : FALSE;
337
keyFound = TRUE;
338
break;
339
case j9gc_modron_configuration_gcThreadCount:
340
*((UDATA *)value) = extensions->gcThreadCount;
341
keyFound = TRUE;
342
break;
343
case j9gc_modron_configuration_compressObjectReferences:
344
*((UDATA *)value) = extensions->compressObjectReferences();
345
keyFound = TRUE;
346
break;
347
case j9gc_modron_configuration_heapRegionShift:
348
if (extensions->isVLHGC()) {
349
*((UDATA *)value) = extensions->heapRegionManager->getRegionShift();
350
keyFound = TRUE;
351
} else {
352
*((UDATA *)value) = 0;
353
keyFound = FALSE;
354
}
355
break;
356
case j9gc_modron_configuration_heapRegionStateTable:
357
#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)
358
if (extensions->isConcurrentCopyForwardEnabled()) {
359
*((UDATA *)value) = (UDATA) extensions->heapRegionStateTable->getTable();
360
keyFound = TRUE;
361
} else {
362
*((UDATA *)value) = 0;
363
keyFound = FALSE;
364
}
365
#else /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */
366
*((UDATA *)value) = 0;
367
keyFound = FALSE;
368
#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */
369
370
break;
371
default:
372
/* key is either invalid or unknown for this configuration - should not have been requested */
373
Assert_MM_unreachable();
374
}
375
return keyFound;
376
}
377
378
} /* extern "C" */
379
380