Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CopyForwardScheme.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2022 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_Standard
26
*/
27
28
#if !defined(COPYFORWARDSCHEME_HPP_)
29
#define COPYFORWARDSCHEME_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "modronopt.h"
34
35
#include "BaseNonVirtual.hpp"
36
37
#include "CopyScanCacheListVLHGC.hpp"
38
#include "EnvironmentVLHGC.hpp"
39
#include "GCExtensions.hpp"
40
#include "ModronTypes.hpp"
41
42
class GC_SlotObject;
43
class MM_AllocationContextTarok;
44
class MM_CardCleaner;
45
class MM_CopyForwardCompactGroup;
46
class MM_CopyForwardGMPCardCleaner;
47
class MM_CopyForwardNoGMPCardCleaner;
48
class MM_CopyForwardVerifyScanner;
49
class MM_ForwardedHeader;
50
class MM_ParallelDispatcher;
51
class MM_HeapRegionManager;
52
class MM_HeapRegionDescriptorVLHGC;
53
class MM_InterRegionRememberedSet;
54
class MM_MarkMap;
55
class MM_MemoryPoolAddressOrderedList;
56
class MM_ReferenceStats;
57
58
/* Forward declaration of classes defined within the cpp */
59
class MM_CopyForwardSchemeAbortScanner;
60
class MM_CopyForwardSchemeRootScanner;
61
class MM_CopyForwardSchemeRootClearer;
62
class MM_CopyForwardSchemeTask;
63
64
/**
65
* Copy Forward scheme used for highly mobile partial collection operations.
66
* @ingroup GC_Modron_Standard
67
*/
68
class MM_CopyForwardScheme : public MM_BaseNonVirtual
69
{
70
private:
71
J9JavaVM *_javaVM;
72
MM_GCExtensions *_extensions;
73
74
enum ScanReason {
75
SCAN_REASON_NONE = 0, /**< Indicates there is no item for scan */
76
SCAN_REASON_PACKET = 1, /**< Indicates the object being scanned came from a work packet */
77
SCAN_REASON_COPYSCANCACHE = 2,
78
SCAN_REASON_DIRTY_CARD = 3, /**< Indicates the object being scanned was found in a dirty card */
79
SCAN_REASON_OVERFLOWED_REGION = 4, /**< Indicates the object being scanned was in an overflowed region */
80
};
81
82
MM_HeapRegionManager *_regionManager; /**< Region manager for the heap instance */
83
MM_InterRegionRememberedSet *_interRegionRememberedSet; /**< A cached pointer to the inter-region reference tracking mechanism */
84
85
class MM_ReservedRegionListHeader {
86
/* Fields */
87
public:
88
enum { MAX_SUBLISTS = 8 }; /* arbitrary value for maximum split */
89
struct Sublist {
90
MM_HeapRegionDescriptorVLHGC *_head; /**< Head of the reserved regions list */
91
MM_LightweightNonReentrantLock _lock; /**< Lock for reserved regions list */
92
volatile UDATA _cacheAcquireCount; /**< The number of times threads acquired caches from this list */
93
UDATA _cacheAcquireBytes; /**< The number of bytes acquired for caches from this list */
94
} _sublists[MAX_SUBLISTS];
95
UDATA _evacuateRegionCount; /**< The number of evacuate regions in this group */
96
UDATA _maxSublistCount; /**< The highest value _sublistCount is permitted to reach in this group */
97
volatile UDATA _sublistCount; /**< The number of active sublists in this list */
98
MM_HeapRegionDescriptorVLHGC *_freeMemoryCandidates; /**< A linked list of regions in this compact group which have free memory */
99
MM_LightweightNonReentrantLock _freeMemoryCandidatesLock; /**< Lock to protect _freeMemoryCandidates */
100
UDATA _freeMemoryCandidateCount; /**< The number of regions in the _freeMemoryCandidates list */ protected:
101
private:
102
/* Methods */
103
public:
104
protected:
105
private:
106
};
107
MM_ReservedRegionListHeader *_reservedRegionList; /**< List of reserved regions during a copy forward operation */
108
UDATA _compactGroupMaxCount; /**< The maximum number of compact groups that exist in the system */
109
110
UDATA _phantomReferenceRegionsToProcess; /**< A count, for verification purposes, of the number of regions to be processed for phantom references */
111
112
UDATA _minCacheSize; /**< Minimum size in bytes that will be returned as a general purpose cache area */
113
UDATA _maxCacheSize; /**< Maximum size in bytes that will be requested for a general purpose cache area */
114
115
MM_ParallelDispatcher *_dispatcher;
116
117
MM_CopyScanCacheListVLHGC _cacheFreeList; /**< Caches which are not bound to heap memory and available to be populated */
118
MM_CopyScanCacheListVLHGC *_cacheScanLists; /**< An array of per-node caches which contains objects still to be scanned (1+node_count elements in array)*/
119
UDATA _scanCacheListSize; /**< The number of entries in _cacheScanLists */
120
volatile UDATA _scanCacheWaitCount; /**< The number of threads currently sleeping on _scanCacheMonitor, awaiting scan cache work */
121
omrthread_monitor_t _scanCacheMonitor; /**< Used when waiting on work on any of the _cacheScanLists */
122
123
volatile UDATA* _workQueueWaitCountPtr; /**< The number of threads currently sleeping on *_workQueueMonitorPtr, awaiting scan cache work or work from packets*/
124
omrthread_monitor_t* _workQueueMonitorPtr; /**< Used when waiting on work on any of the _cacheScanLists or workPackets*/
125
126
volatile UDATA _doneIndex; /**< Incremented when _cacheScanLists are empty and we want all threads to fall out of *_workQueueMonitorPtr */
127
128
MM_MarkMap *_markMap; /**< Cached reference to the previous mark map */
129
130
void *_heapBase; /**< Cached base pointer of heap */
131
void *_heapTop; /**< Cached top pointer of heap */
132
133
volatile bool _abortFlag; /**< Flag indicating whether the current copy forward cycle should be aborted due to insufficient heap to complete */
134
bool _abortInProgress; /**< Flag indicating that the copy forward mechanism is now operating in abort mode, which is attempting to secure integrity of the heap to continue execution */
135
136
UDATA _regionCountCannotBeEvacuated; /**<The number of regions, which can not be copyforward in collectionSet */
137
UDATA _regionCountReservedNonEvacuated; /** the number of regions need to set Mark only in order to try to avoid abort case */
138
139
UDATA _cacheLineAlignment; /**< The number of bytes per cache line which is used to determine which boundaries in memory represent the beginning of a cache line */
140
141
bool _clearableProcessingStarted; /**< Flag indicating that clearable processing had been started during this cycle (used for abort purposes) */
142
143
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
144
bool _dynamicClassUnloadingEnabled; /**< Local cached value from cycle state for performance reasons (TODO: Reevaluate) */
145
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
146
bool _collectStringConstantsEnabled; /**< Local cached value which determines whether string constants are roots */
147
148
bool _tracingEnabled; /**< Temporary variable to enable tracing of activity */
149
MM_AllocationContextTarok *_commonContext; /**< The common context is used as an opaque token to represent cases where we don't want to relocate objects during NUMA-aware copy-forward since relocating to the common context is currently disabled */
150
MM_CopyForwardCompactGroup *_compactGroupBlock; /**< A block of MM_CopyForwardCompactGroup structs which is subdivided among the GC threads */
151
UDATA _arraySplitSize; /**< The number of elements to be scanned in each array chunk (this determines the degree of parallelization) */
152
153
UDATA _regionSublistContentionThreshold /**< The number of threads which must be contending on the same region sublist for us to decide that another sublist should be created to alleviate contention (reset at the beginning of every CopyForward task) */;
154
155
volatile bool _failedToExpand; /**< Record if we've failed to expand in this collection already, in order to avoid repeated expansion attempts */
156
bool _shouldScanFinalizableObjects; /**< Set to true at the beginning of a collection if there are any pending finalizable objects */
157
const UDATA _objectAlignmentInBytes; /**< Run-time objects alignment in bytes */
158
159
UDATA *_compressedSurvivorTable; /**< start address of compressed survivor table (1 bit presents CARD_SIZE of Heap) */
160
161
protected:
162
public:
163
private:
164
165
/* Temporary verification functions */
166
void verifyDumpObjectDetails(MM_EnvironmentVLHGC *env, const char *title, J9Object *object);
167
void verifyCopyForwardResult(MM_EnvironmentVLHGC *env);
168
bool verifyIsPointerInSurvivor(MM_EnvironmentVLHGC *env, J9Object *object);
169
bool verifyIsPointerInEvacute(MM_EnvironmentVLHGC *env, J9Object *object);
170
void verifyObject(MM_EnvironmentVLHGC *env, J9Object *objectPtr);
171
void verifyMixedObjectSlots(MM_EnvironmentVLHGC *env, J9Object *objectPtr);
172
void verifyReferenceObjectSlots(MM_EnvironmentVLHGC *env, J9Object *objectPtr);
173
void verifyPointerArrayObjectSlots(MM_EnvironmentVLHGC *env, J9Object *objectPtr);
174
void verifyClassObjectSlots(MM_EnvironmentVLHGC *env, J9Object *classObject);
175
void verifyClassLoaderObjectSlots(MM_EnvironmentVLHGC *env, J9Object *classLoaderObject);
176
void verifyExternalState(MM_EnvironmentVLHGC *env);
177
friend class MM_CopyForwardVerifyScanner;
178
179
/**
180
* Called to retire a copy cache once a thread no longer wants to use it as a copy destination.
181
* @param env[in] A GC thread
182
* @param compactGroup The index of the compact group whose thread-local copy cache should be deleted
183
* @return the copy cache which was affected
184
*/
185
MM_CopyScanCacheVLHGC * stopCopyingIntoCache(MM_EnvironmentVLHGC *env, UDATA compactGroup);
186
187
/*
188
* Called to update a region's projected live bytes with the bytes copied by the copy scan cache.
189
* @param env[in] A GC thread
190
* @param cache[in] The copy cache to update a region's live bytes from
191
*/
192
void updateProjectedLiveBytesFromCopyScanCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache);
193
194
/**
195
* Discard any remaining memory in the specified copy cache, returning it to the pool if possible, and updating
196
* memory statistics. The implementation will attempt to return any unused portion of the cache to the owning pool
197
* if possible (and will internally lock to corresponding region list to ensure that the allocation pointer can be
198
* updated safely). The copy cache flag is unset. Additionally, the top of the cache will be updated to reflect
199
* that no further allocation is possible if the excess at the top of the cache was successfully returned to the
200
* pool.
201
* @param env[in] A GC thread
202
* @param cache[in] The copy cache to retire
203
* @param cacheLock[in] The lock associated with the cache's owning list
204
* @param wastedMemory[in] The number of bytes of memory which couldn't be used in the allocated portion of the copy cache and should be considered free memory when flushed back to the pool
205
*/
206
void discardRemainingCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache, MM_LightweightNonReentrantLock *cacheLock, UDATA wastedMemory);
207
208
/**
209
* Determine whether the object pointer is found within the heap proper.
210
* @return Boolean indicating if the object pointer is within the heap boundaries.
211
*/
212
MMINLINE bool isHeapObject(J9Object* objectPtr)
213
{
214
return ((_heapBase <= (U_8 *)objectPtr) && (_heapTop > (U_8 *)objectPtr));
215
}
216
217
/**
218
* Determine whether the object is live relying on survivor/evacuate region flags and mark map. null object is considered marked.
219
* @return Boolean true if object is live
220
*/
221
bool isLiveObject(J9Object *objectPtr);
222
223
/**
224
* Determine whether string constants should be treated as clearable.
225
* @return Boolean indicating if strings constants are clearable.
226
*/
227
MMINLINE bool isCollectStringConstantsEnabled() { return _collectStringConstantsEnabled; };
228
229
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
230
/**
231
* Determine whether class unloading is enabled this collection cycle.
232
* @return Boolean indicating if class unloading is enabled this cycle.
233
*/
234
MMINLINE bool isDynamicClassUnloadingEnabled() { return _dynamicClassUnloadingEnabled; };
235
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
236
237
/**
238
* Determine whether the copy forward abort flag is raised or not.
239
* @return boolean indicating the start of the copy forward abort flag.
240
*/
241
MMINLINE bool abortFlagRaised() { return _abortFlag; }
242
243
/**
244
* Clear the abort copy forward flag.
245
*/
246
MMINLINE void clearAbortFlag() { _abortFlag = false; }
247
248
/**
249
* Raise the abort copy forward flag.
250
* @param env GC thread.
251
*/
252
MMINLINE void raiseAbortFlag(MM_EnvironmentVLHGC *env);
253
254
/**
255
* Reinitializes the cache with the given base address, top address, as a copy cache. Also updates the mark map cache values in the env's
256
* CopyForwardCompactGroup for the given cache.
257
* @param env[in] The thread taking ownership of the cache
258
* @param cache[in] cache to be reinitialized
259
* @param base[in] base address of cache
260
* @param top[in] top address of cache
261
* @param compactGroup the compact group to which the cache belongs
262
*/
263
MMINLINE void reinitCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache, void *base, void *top, UDATA compactGroup);
264
265
/**
266
* Reinitializes the cache with the array and next scan index as an array split cache.
267
* @param env[in] The thread taking ownership of the cache
268
* @param cache[in] cache to be reinitialized
269
* @param array[in] The array to scan
270
* @param nextIndex[in] The next index in the array to scan
271
*/
272
MMINLINE void reinitArraySplitCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache, J9IndexableObject *array, UDATA nextIndex);
273
274
MM_CopyScanCacheVLHGC *getFreeCache(MM_EnvironmentVLHGC *env);
275
/**
276
* Adds the given newCacheEntry to the free cache list.
277
* @note The implementation will lock the list prior to modification.
278
* @param env current GC thread.
279
* @param newCacheEntry[in] The entry to add to cacheList
280
*/
281
void addCacheEntryToFreeCacheList(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *newCacheEntry);
282
/**
283
* Adds the given newCacheEntry to the scan cache list and will notify any waiting threads if the list was empty prior to adding newCacheEntry.
284
* @note The implementation will lock the list prior to modification.
285
* @param env current GC thread.
286
* @param newCacheEntry[in] The entry to add to cacheList
287
*/
288
void addCacheEntryToScanCacheListAndNotify(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *newCacheEntry);
289
290
void flushCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache);
291
bool clearCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache);
292
293
/**
294
* add OwnableSynchronizerObject in the buffer if reason == SCAN_REASON_COPYSCANCACHE || SCAN_REASON_PACKET
295
* and call scanMixedObjectSlots().
296
*
297
* @param env current GC thread.
298
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
299
* @param objectPtr current object being scanned.
300
* @param reason to scan (dirty card, packet, scan cache, overflow)
301
*/
302
MMINLINE void scanOwnableSynchronizerObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, ScanReason reason);
303
304
/**
305
* Called whenever a ownable synchronizer object is scaned during CopyForwardScheme. Places the object on the thread-specific buffer of gc work thread.
306
* @param env -- current thread environment
307
* @param object -- The object of type or subclass of java.util.concurrent.locks.AbstractOwnableSynchronizer.
308
*/
309
MMINLINE void addOwnableSynchronizerObjectInList(MM_EnvironmentVLHGC *env, j9object_t object);
310
311
/**
312
* Scan the slots of a mixed object.
313
* Copy and forward all relevant slots values found in the object.
314
* @param env current GC thread.
315
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
316
* @param objectPtr current object being scanned.
317
* @param reason to scan (dirty card, packet, scan cache, overflow)
318
*/
319
void scanMixedObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, ScanReason reason);
320
/**
321
* Scan the slots of a reference mixed object.
322
* Copy and forward all relevant slots values found in the object.
323
* @param env current GC thread.
324
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
325
* @param objectPtr current object being scanned.
326
* @param reason to scan (dirty card, packet, scan cache, overflow) *
327
*/
328
void scanReferenceObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, ScanReason reason);
329
330
/**
331
* Called by the root scanner to scan all WeakReference objects discovered by the mark phase,
332
* clearing and enqueuing them if necessary.
333
* @param env[in] the current thread
334
*/
335
void scanWeakReferenceObjects(MM_EnvironmentVLHGC *env);
336
337
/**
338
* Called by the root scanner to scan all SoftReference objects discovered by the mark phase,
339
* clearing and enqueuing them if necessary.
340
* @param env[in] the current thread
341
*/
342
void scanSoftReferenceObjects(MM_EnvironmentVLHGC *env);
343
344
/**
345
* Called by the root scanner to scan all PhantomReference objects discovered by the mark phase,
346
* clearing and enqueuing them if necessary.
347
* @param env[in] the current thread
348
*/
349
void scanPhantomReferenceObjects(MM_EnvironmentVLHGC *env);
350
351
/**
352
* Set region as survivor. Also set the special state if region was created by phantom reference processing.
353
* @param env[in] the current thread
354
* @param region[in] region to set as survivor
355
* @param freshSurvivor[in] if true, it is survivor region from free region
356
*/
357
void setRegionAsSurvivor(MM_EnvironmentVLHGC* env, MM_HeapRegionDescriptorVLHGC *region, bool freshSurvivor);
358
359
/**
360
* Process the list of reference objects recorded in the specified list.
361
* References with unmarked referents are cleared and optionally enqueued.
362
* SoftReferences have their ages incremented.
363
* @param env[in] the current thread
364
* @param region[in] the region all the objects in the list belong to
365
* @param headOfList[in] the first object in the linked list
366
* @param referenceStats copy forward stats substructure to be updated
367
*/
368
void processReferenceList(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC* region, J9Object* headOfList, MM_ReferenceStats *referenceStats);
369
370
/**
371
* Walk the list of reference objects recorded in the specified list, changing them to the REMEMBERED state.
372
* @param env[in] the current thread
373
* @param headOfList[in] the first object in the linked list
374
*/
375
void rememberReferenceList(MM_EnvironmentVLHGC *env, J9Object* headOfList);
376
377
/**
378
* Walk all regions in the evacuate set in parallel, remembering any objects on their reference
379
* lists so that they may be restored at the end of the PGC.
380
* @param env[in] the current thread
381
*/
382
void rememberReferenceListsFromExternalCycle(MM_EnvironmentVLHGC *env);
383
384
/**
385
* Call rememberReferenceList() for each of the weak, soft and phantom lists in referenceObjectList, then reset them.
386
* @param env[in] the current thread
387
* @param region[in] region which lists to remember and reset
388
*/
389
void rememberAndResetReferenceLists(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC *region);
390
391
/**
392
* Partially scan the slots of a pointer array object.
393
* This is only called during abort phase (workstack driven). Otherwise, scanPointerArrayObjectSlotsSplit() is used.
394
* Create a new packet work item to allow other threads to complete scanning of the array while this scan proceeds.
395
* @param env current GC thread.
396
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
397
* @param arrayPtr current array being scanned.
398
* @param reason to scan (dirty card, packet, scan cache, overflow)
399
*/
400
void scanPointerArrayObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9IndexableObject *arrayPtr, ScanReason reason);
401
402
/**
403
* Partially scan the slots of a pointer array object.
404
* Copy and forward all relevant slots values found in the object.
405
* Create a new scan cache to allow other threads to complete scanning of the array while this scan proceeds.
406
* @param env current GC thread.
407
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
408
* @param arrayPtr current array being scanned.
409
* @param startIndex the index to start from
410
* @param currentSplitUnitOnly[in] do only current array split work unit; do not push the rest of array on the work stack
411
* @return number of slots scanned
412
*/
413
UDATA scanPointerArrayObjectSlotsSplit(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9IndexableObject *arrayPtr, UDATA startIndex, bool currentSplitUnitOnly = false);
414
415
/**
416
* For the given object and current starting index, determine the number of slots being scanned now, and create a work unit for the rest of the array.
417
* Works for both copy-scan cache and workstack driven phases.
418
* @param env[in] the current thread
419
* @param arrayPtr[in] current array object being scanned.
420
* @param startIndex[in] starting index for the current split scan
421
* @param currentSplitUnitOnly[in] do only current array split work unit; do not push the rest of array on the work stack*
422
* @return the number of the slots to be scanned for the current split
423
*/
424
UDATA createNextSplitArrayWorkUnit(MM_EnvironmentVLHGC *env, J9IndexableObject *arrayPtr, UDATA startIndex, bool currentSplitUnitOnly = false);
425
426
/**
427
* Scan the slots of a java.lang.Class object.
428
* Copy and forward all relevant slots values found in the object, as well
429
* as those found in the backing J9Class structure.
430
* @param env current GC thread.
431
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
432
* @param objectPtr current object being scanned.
433
* @param reason to scan (dirty card, packet, scan cache, overflow)
434
*/
435
void scanClassObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *classObject, ScanReason reason = SCAN_REASON_COPYSCANCACHE);
436
/**
437
* Scan the slots of a java.lang.ClassLoader object.
438
* Copy and forward all relevant slots values found in the object, as well
439
* as those found in the backing J9ClassLoader structure.
440
* @param env current GC thread.
441
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
442
* @param objectPtr current object being scanned.
443
* @param reason to scan (dirty card, packet, scan cache, overflow)
444
*/
445
void scanClassLoaderObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *classLoaderObject, ScanReason reason = SCAN_REASON_COPYSCANCACHE);
446
447
/**
448
* Determine whether the object is in evacuate memory or not.
449
* @param objectPtr[in] Object pointer whose properties are being examined.
450
* @return true if the object is found in evacuate memory, false otherwise.
451
*/
452
MMINLINE bool isObjectInEvacuateMemory(J9Object *objectPtr);
453
MMINLINE bool isObjectInEvacuateMemoryNoCheck(J9Object *objectPtr);
454
455
/**
456
* Determine whether the object is in survivor memory or not.
457
* @param objectPtr[in] Object pointer whose properties are being examined.
458
* @return true if the object is found in survivor memory, false otherwise.
459
*/
460
MMINLINE bool isObjectInSurvivorMemory(J9Object *objectPtr);
461
462
/**
463
* Determine whether the object is in evacuate/survivor memory or not.
464
* @param objectPtr[in] Object pointer whose properties are being examined.
465
* @return true if the object is found in evacuate/survivor memory, false otherwise.
466
*/
467
MMINLINE bool isObjectInNurseryMemory(J9Object *objectPtr);
468
469
/**
470
* Remove any remaining regions from the reserved allocation list.
471
* @param env GC thread.
472
*/
473
void clearReservedRegionLists(MM_EnvironmentVLHGC *env);
474
475
/**
476
* Acquire an empty region for use as a survivor area during copy and forward.
477
* @param env GC thread.
478
* @param regionList Internally managed region list to which the region should be assigned to.
479
* @param compactGroup Compact group for acquired region
480
* @return the newly acquired region or NULL if no region was available
481
*/
482
MM_HeapRegionDescriptorVLHGC *acquireEmptyRegion(MM_EnvironmentVLHGC *env, MM_ReservedRegionListHeader::Sublist *regionList, UDATA compactGroup);
483
484
/**
485
* Inserts newRegion into the given regionList. The implementation assumes that the calling thread can modify regionList without locking
486
* it so the callsite either needs to have locked the list or be single-threaded.
487
* @param env[in] The GC thread
488
* @param regionList[in] The region list to which the implementation will add newRegion (call site must ensure that no other thread is able to view this until the method returns)
489
* @param newRegion[in] The region which the implementation must add to regionList (the implementation assumes that newRegion is not already in a region list)
490
*/
491
void insertRegionIntoLockedList(MM_EnvironmentVLHGC *env, MM_ReservedRegionListHeader::Sublist *regionList, MM_HeapRegionDescriptorVLHGC *newRegion);
492
493
/**
494
* Release a region as it is deemed to be full and no longer useful.
495
* @param env GC thread.
496
* @param regionList Internally managed region list from which the region should be removed from.
497
* @param region The region to release.
498
*/
499
void releaseRegion(MM_EnvironmentVLHGC *env, MM_ReservedRegionListHeader::Sublist *regionList, MM_HeapRegionDescriptorVLHGC *region);
500
501
/**
502
* Insert the specified free memory candidate into the candidate list. The implementation assumes that the calling thread can modify
503
* regionList without locking it so the callsite either needs to have locked the list or be single-threaded.
504
* @param env[in] The GC thread
505
* @param regionList[in] The region list to which Region should be added as a candidate
506
* @param region[in] The region to add
507
*/
508
void insertFreeMemoryCandidate(MM_EnvironmentVLHGC* env, MM_ReservedRegionListHeader* regionList, MM_HeapRegionDescriptorVLHGC *region);
509
510
/**
511
* Remove the specified free memory candidate from the candidate list. The implementation assumes that the calling thread can modify
512
* regionList without locking it so the callsite either needs to have locked the list or be single-threaded.
513
* @param env[in] The GC thread
514
* @param regionList[in] The region list which Region belongs to
515
* @param region[in] The region to remove
516
*/
517
void removeFreeMemoryCandidate(MM_EnvironmentVLHGC* env, MM_ReservedRegionListHeader* regionList, MM_HeapRegionDescriptorVLHGC *region);
518
519
/**
520
* Reserve memory for an object to be copied to survivor space.
521
* @param env[in] GC thread.
522
* @param compactGroup The compact group number that the object should be associated with.
523
* @param objectSize Size in bytes to be reserved (precisely, no more or less) for the object to be copied.
524
* @param listLock[out] Returns the lock associated with the returned memory
525
* @return a pointer to the storage reserved for allocation, or NULL on failure.
526
*/
527
void *reserveMemoryForObject(MM_EnvironmentVLHGC *env, uintptr_t compactGroup, uintptr_t objectSize, MM_LightweightNonReentrantLock** listLock);
528
529
/**
530
* Reserve memory for a general cache to be used as the copy destination of a survivor space.
531
* @param env[in] GC thread.
532
* @param compactGroup The compact group number that the cache should be associated with.
533
* @param maxCacheSize The max (give or take) size of the cache being requested.
534
* @param addrBase[out] Location to store the base address of the cache that is acquired.
535
* @param addrTop[out] local to store the top address of the cache that is acquired.
536
* @param listLock[out] Returns the lock associated with the returned memory
537
* @return true if the cache was allocated, false otherwise.
538
*/
539
bool reserveMemoryForCache(MM_EnvironmentVLHGC *env, uintptr_t compactGroup, uintptr_t maxCacheSize, void **addrBase, void **addrTop, MM_LightweightNonReentrantLock** listLock);
540
541
/**
542
* Creates a new chunk of scan caches by using heap memory and attaches them to the free cache list.
543
* @param env[in] A GC thread
544
* @return A new cache entry if the allocation of scan caches succeeded, NULL otherwise
545
*/
546
MM_CopyScanCacheVLHGC * createScanCacheForOverflowInHeap(MM_EnvironmentVLHGC *env);
547
548
/**
549
* Reserve the specified number of bytes to accommodate an object copy.
550
* @param env The GC thread requesting the heap memory to be allocated.
551
* @param objectToEvacuate Object being copied.
552
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
553
* @param objectReserveSizeInBytes Amount of bytes to be reserved (can be greater than the original object size) for copying.
554
* @return a CopyScanCache which contains the reserved memory or NULL if the reserve was not successful.
555
*/
556
MMINLINE MM_CopyScanCacheVLHGC *reserveMemoryForCopy(MM_EnvironmentVLHGC *env, J9Object *objectToEvacuate, MM_AllocationContextTarok *reservingContext, uintptr_t objectReserveSizeInBytes);
557
558
void flushCaches(MM_CopyScanCacheVLHGC *cache);
559
560
/**
561
* Called at the end of the copy forward operation to flush any remaining data from copy caches and return them to the free list.
562
* @param env[in] the thread whose copy caches should be flushed
563
*/
564
void addCopyCachesToFreeList(MM_EnvironmentVLHGC *env);
565
566
J9Object *updateForwardedPointer(J9Object *objectPtr);
567
568
/**
569
* Checks to see if there is any scan work in the given list.
570
* @param scanCacheList[in] The list to check
571
* @return True if there is work available in the given list
572
*/
573
bool isScanCacheWorkAvailable(MM_CopyScanCacheListVLHGC *scanCacheList);
574
/**
575
* Checks to see if there is any scan work in any of the lists.
576
* @return True if any scan lists contain work
577
*/
578
bool isAnyScanCacheWorkAvailable();
579
580
/**
581
* Checks to see if there is any scan work in any of scanCacheLists or workPackets
582
* it is only for CopyForwardHybrid mode
583
* @return True if there is any scan work
584
*/
585
bool isAnyScanWorkAvailable(MM_EnvironmentVLHGC *env);
586
587
/**
588
* Return the next available survivor (destination) copy scan cache that has work available for scanning.
589
* @param env GC thread.
590
* @return a copy scan cache to be scanned, or NULL if none are available.
591
*/
592
MM_CopyScanCacheVLHGC *getSurvivorCacheForScan(MM_EnvironmentVLHGC *env);
593
594
/**
595
* Tries to find next scan work from both scanCache and workPackets
596
* return SCAN_REASON_NONE if there is no scan work
597
* @param env[in] The GC thread
598
* @param preferredNumaNode[in] The NUMA node number where the caller would prefer to find a scan cache
599
* @return possible return value(SCAN_REASON_NONE, SCAN_REASON_COPYSCANCACHE, SCAN_REASON_PACKET)
600
*/
601
ScanReason getNextWorkUnit(MM_EnvironmentVLHGC *env, UDATA preferredNumaNode);
602
603
/**
604
* @param env[in] The GC thread
605
* @param preferredNumaNode[in] The NUMA node number where the caller would prefer to find a scan cache
606
* @return possible return value(SCAN_REASON_NONE, SCAN_REASON_COPYSCANCACHE, SCAN_REASON_PACKET)
607
*/
608
ScanReason getNextWorkUnitNoWait(MM_EnvironmentVLHGC *env, UDATA preferredNumaNode);
609
610
/**
611
* Tries to find a scan cache from the specified NUMA node or return SCAN_REASON_NONE if there was no work available on that node
612
* @return possible return value(SCAN_REASON_NONE, SCAN_REASON_COPYSCANCACHE)
613
*/
614
ScanReason getNextWorkUnitOnNode(MM_EnvironmentVLHGC *env, UDATA numaNode);
615
616
/**
617
* Complete scanning in Copy-Forward fashion (consume&produce CopyScanCaches)
618
* If abort happens midway through all produced work is pushed on Marking WorkStack
619
* @param env[in] The GC thread
620
*/
621
void completeScan(MM_EnvironmentVLHGC *env);
622
/**
623
* Complete scanning in Marking fashion (consume&produce on WorkStack)
624
* @param env[in] The GC thread
625
*/
626
void completeScanForAbort(MM_EnvironmentVLHGC *env);
627
/**
628
* Rescan all objects in the specified overflowed region.
629
*/
630
void cleanOverflowedRegion(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC *region, U_8 flagToClean);
631
/**
632
* Handling of Work Packets overflow case
633
* Active STW Card Based Overflow Handler only.
634
* For other types of STW Overflow Handlers always return false
635
* @param env[in] The main GC thread
636
* @return true if overflow flag is set
637
*/
638
bool handleOverflow(MM_EnvironmentVLHGC *env);
639
640
/**
641
* Check if Work Packets overflow
642
* @return true if overflow flag is set
643
*/
644
bool isWorkPacketsOverflow(MM_EnvironmentVLHGC *env);
645
646
void completeScanCache(MM_EnvironmentVLHGC *env);
647
/**
648
* complete scan works from _workStack
649
* only for CopyForward Hybrid mode
650
*/
651
void completeScanWorkPacket(MM_EnvironmentVLHGC *env);
652
653
/**
654
* Scans all the slots of the given object. Used only in copy-scan cache driven phase.
655
* @param env[in] the current thread
656
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
657
* @param objectPtr[in] current object being scanned
658
* @param reason[in] reason to scan (dirty card, packet, scan cache, overflow)
659
*/
660
MMINLINE void scanObject(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, ScanReason reason);
661
662
/**
663
* Update scan for abort phase (workstack phase)
664
* @param env[in] the current thread
665
* @param objectPtr[in] current object being scanned.
666
* @param reason[in] reason to scan (dirty card, packet, scan cache, overflow)
667
*/
668
MMINLINE void updateScanStats(MM_EnvironmentVLHGC *env, J9Object *objectPtr, ScanReason reason);
669
670
MMINLINE UDATA scanToCopyDistance(MM_CopyScanCacheVLHGC* cache);
671
MMINLINE bool bestCacheForScanning(MM_CopyScanCacheVLHGC* copyCache, MM_CopyScanCacheVLHGC** scanCache);
672
673
/**
674
* Calculates whether to change the current cache being scanned for a copy cache, deciding
675
* between one of the two copy caches available, using bestCacheForScanning.
676
*
677
* On entry, nextScanCache should contain the current scan cache. On exit, it may contain
678
* the updated scan cache to use next.
679
*
680
* @param nextScanCache the current scan cache, which may be updated on exit.
681
* @return true if the nextScanCache has been updated with the best cache to scan.
682
*/
683
MMINLINE bool aliasToCopyCache(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC** nextScanCache);
684
685
/**
686
* Scans the slots of a MixedObject, remembering objects as required. Scanning is interrupted
687
* as soon as there is a copy cache that is preferred to the current scan cache. This is returned
688
* in nextScanCache.
689
*
690
* @note <an iterator>.nextSlot() is one of the hottest methods in scavenging, so
691
* it needs to be inlined as much as possible, but we also need to store that iterator state in the
692
* copy/scan cache. Using the local (ie stack or register) instance of the class (through the default
693
* constructor) allows the compiler to inline the virtual method. Using a pointer from the copy/scan
694
* cache to the abstract class ObjectIterator would not allow the compiler to inline. Hence the
695
* Iterator member functions restore and save.
696
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
697
* @param scanCache current cache being scanned
698
* @param objectPtr current object being scanned
699
* @param hasPartiallyScannedObject whether current object has been partially scanned already
700
* @param nextScanCache the updated scanCache after re-aliasing.
701
* @return whether current object is still only partially scanned
702
*/
703
MMINLINE bool incrementalScanMixedObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_CopyScanCacheVLHGC* scanCache, J9Object *objectPtr,
704
bool hasPartiallyScannedObject, MM_CopyScanCacheVLHGC** nextScanCache);
705
/**
706
* Scans the slots of a java.lang.Class object, remembering objects as required.
707
* This scan will visit both the object itself (as a mixed object) as well as the backing J9Class structure.
708
* Scanning is interrupted as soon as there is a copy cache that is preferred to the current scan cache.
709
* This is returned in nextScanCache.
710
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
711
* @note The current implementation will not interrupt, completing the scan of the object before returning.
712
* @see MM_CopyForwardScheme:incrementalScanMixedObjectSlots
713
*/
714
MMINLINE bool incrementalScanClassObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_CopyScanCacheVLHGC* scanCache, J9Object *objectPtr,
715
bool hasPartiallyScannedObject, MM_CopyScanCacheVLHGC** nextScanCache);
716
/**
717
* Scans the slots of a java.lang.ClassLoader object, remembering objects as required.
718
* This scan will visit both the object itself (as a mixed object) as well as the backing J9ClassLoader structure.
719
* Scanning is interrupted as soon as there is a copy cache that is preferred to the current scan cache.
720
* This is returned in nextScanCache.
721
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
722
* @note The current implementation will not interrupt, completing the scan of the object before returning.
723
* @see MM_CopyForwardScheme:incrementalScanMixedObjectSlots
724
*/
725
MMINLINE bool incrementalScanClassLoaderObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_CopyScanCacheVLHGC* scanCache, J9Object *objectPtr,
726
bool hasPartiallyScannedObject, MM_CopyScanCacheVLHGC** nextScanCache);
727
/**
728
* Scans the slots of a PointerArrayObject, remembering objects as required. Scanning is interrupted
729
* as soon as there is a copy cache that is preferred to the current scan cache. This is returned
730
* in nextScanCache.
731
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
732
* @see MM_CopyForwardScheme:incrementalScanMixedObjectSlots
733
*/
734
MMINLINE bool incrementalScanPointerArrayObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_CopyScanCacheVLHGC* scanCache, J9Object *objectPtr,
735
bool hasPartiallyScannedObject, MM_CopyScanCacheVLHGC** nextScanCache);
736
/**
737
* Scans the slots of a ReferenceObject, remembering objects as required. Scanning is interrupted
738
* as soon as there is a copy cache that is preferred to the current scan cache. This is returned
739
* in nextScanCache.
740
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
741
* @see MM_CopyForwardScheme:incrementalScanMixedObjectSlots
742
*/
743
MMINLINE bool incrementalScanReferenceObjectSlots(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_CopyScanCacheVLHGC* scanCache, J9Object *objectPtr,
744
bool hasPartiallyScannedObject, MM_CopyScanCacheVLHGC** nextScanCache);
745
/**
746
* Scans the objects to scan in the env->_scanCache.
747
* Slots are scanned until there is an opportunity to alias the scan cache to a copy cache. When
748
* this happens, scanning is interrupted and the present scan cache is either pushed onto the scan
749
* list or "deferred" in thread-local storage. Deferring is done to reduce contention due to the
750
* increased need to change scan cache. If the cache is scanned completely without interruption
751
* the cache is flushed at the end.
752
*/
753
void incrementalScanCacheBySlot(MM_EnvironmentVLHGC *env);
754
755
#if defined(J9VM_GC_FINALIZATION)
756
/**
757
* Scan all unfinalized objects in the collection set.
758
* @param env[in] the current thread
759
*/
760
void scanUnfinalizedObjects(MM_EnvironmentVLHGC *env);
761
762
void scanFinalizableObjects(MM_EnvironmentVLHGC *env);
763
764
/**
765
* Helper method called by scanFinalizableObjects to scan
766
* a list of finalizable objects.
767
*
768
* @param env[in] the current thread
769
* @param headObject[in] the object at the head of the list
770
*/
771
void scanFinalizableList(MM_EnvironmentVLHGC *env, j9object_t headObject);
772
#endif /* J9VM_GC_FINALIZATION */
773
774
/**
775
* Clear the cycle's mark map for all regions that are part of the evacuate set.
776
* @param env GC thread.
777
*/
778
void clearMarkMapForPartialCollect(MM_EnvironmentVLHGC *env);
779
/**
780
* Clear the cycle's card table for all regions that are part of the evacuate set, if GMP in progress.
781
* Called only, if regions are completely evacuated (no abort)
782
* @param env GC thread.
783
*/
784
void clearCardTableForPartialCollect(MM_EnvironmentVLHGC *env);
785
786
void workThreadGarbageCollect(MM_EnvironmentVLHGC *env);
787
788
/**
789
* Update the given slot to point at the new location of the object, after copying the object if it was not already.
790
* Attempt to copy (either flip or tenure) the object and install a forwarding pointer at the new location. The object
791
* may have already been copied. In either case, update the slot to point at the new location of the object.
792
*
793
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
794
* @param objectPtr[in] Object being scanned.
795
* @param slotObject the slot to be copied or updated
796
* @return true if copy succeeded (or no copying was involved)
797
*/
798
MMINLINE bool copyAndForward(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, volatile j9object_t* slot);
799
800
/**
801
* Update the given slot to point at the new location of the object, after copying the object if it was not already.
802
* Attempt to copy (either flip or tenure) the object and install a forwarding pointer at the new location. The object
803
* may have already been copied. In either case, update the slot to point at the new location of the object.
804
*
805
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
806
* @param objectPtr[in] Object being scanned.
807
* @param slot the slot to be copied or updated
808
* @param leafType true if slotObject is leaf Object
809
* @return true if copy succeeded (or no copying was involved)
810
*/
811
MMINLINE bool copyAndForward(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr, GC_SlotObject *slotObject, bool leafType = false);
812
813
/**
814
* Update the given slot to point at the new location of the object, after copying the object if it was not already.
815
* Attempt to copy (either flip or tenure) the object and install a forwarding pointer at the new location. The object
816
* may have already been copied. In either case, update the slot to point at the new location of the object.
817
*
818
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
819
* @param objectPtr[in] Array object being scanned.
820
* @param startIndex[in] First index of the sub (split)array being scanned.
821
* @param slotObject the slot to be copied or updated
822
* @return true if copy succeeded (or no copying was involved)
823
*/
824
MMINLINE bool copyAndForwardPointerArray(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9IndexableObject *arrayPtr, UDATA startIndex, GC_SlotObject *slotObject);
825
826
827
/**
828
* Update the given slot to point at the new location of the object, after copying the object if it was not already.
829
* Attempt to copy (either flip or tenure) the object and install a forwarding pointer at the new location. The object
830
* may have already been copied. In either case, update the slot to point at the new location of the object.
831
*
832
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
833
* @param objectPtrIndirect the slot to be copied or updated
834
* @param leafType true if the slot is leaf Object
835
* @return true if copy succeeded (or no copying was involved)
836
*/
837
MMINLINE bool copyAndForward(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, volatile j9object_t* objectPtrIndirect, bool leafType = false);
838
839
/**
840
* If class unloading is enabled, copy the specified object's class object and remember the object as an instance.
841
* @param env[in] the current thread
842
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
843
* @param objectPtr[in] the object whose class should be copied
844
* @return true if copy succeeded (or no copying was involved)
845
*/
846
MMINLINE bool copyAndForwardObjectClass(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr);
847
848
/**
849
* Answer the new location of an object after it has been copied and forwarded.
850
* Attempt to copy and forward the given object header between the evacuate and survivor areas. If the object has already
851
* been copied, or the copy is successful, return the updated information. If the copy is not successful due to insufficient
852
* heap memory, return the original object pointer and raise the "abort" flag.
853
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
854
* @param leafType true if the object is leaf object, default = false
855
* @note This routine can set the abort flag for a copy forward.
856
* @note This will respect any alignment requirements due to hot fields etc.
857
* @return an object pointer representing the new location of the object, or the original object pointer on failure.
858
*/
859
J9Object *copy(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, MM_ForwardedHeader* forwardedHeader, bool leafType = false);
860
861
862
/* Depth copy the hot fields of an object.
863
* @param forwardedHeader - forwarded header of an object
864
* @param destinationObjectPtr - destinationObjectPtr of the object described by the forwardedHeader
865
*/
866
MMINLINE void depthCopyHotFields(MM_EnvironmentVLHGC *env, J9Class *clazz, J9Object *destinationObjectPtr, MM_AllocationContextTarok *reservingContext);
867
868
/* Copy the hot field of an object.
869
* Valid if scavenger dynamicBreadthScanOrdering is enabled.
870
* @param destinationObjectPtr - the object who's hot field will be copied
871
* @param offset - the object field offset of the hot field to be copied
872
*/
873
MMINLINE void copyHotField(MM_EnvironmentVLHGC *env, J9Object *destinationObjectPtr, U_8 offset, MM_AllocationContextTarok *reservingContext);
874
/**
875
* Push any remaining cached mark map data out before the copy scan cache is released.
876
* @param env GC thread.
877
* @param cache Location of cached mark map data to push out.
878
*/
879
void flushCacheMarkMap(MM_EnvironmentVLHGC *env, MM_CopyScanCacheVLHGC *cache);
880
881
/**
882
* Update the mark map information (PGC or GMP) for a given copy scan cache.
883
* @param env GC thread.
884
* @param markMap Mark map to update (if necessary).
885
* @param object Heap object reference whose bit in the mark map should be updated.
886
* @param slotIndexIndirect Indirect pointer to the cached slot index to examine and update.
887
* @param bitMaskIndirect Indirect pointer to the cached bit mask to use for updating.
888
* @param atomicHeadSlotIndex Slot index of mark map where the update must be atomic.
889
* @param atomicTailSlotIndex Slot index of mark map where the update must be atomic.
890
*/
891
MMINLINE void updateMarkMapCache(MM_EnvironmentVLHGC *env, MM_MarkMap *markMap, J9Object *object,
892
UDATA *slotIndexIndirect, UDATA *bitMaskIndirect, UDATA atomicHeadSlotIndex, UDATA atomicTailSlotIndex);
893
894
/**
895
* Update any mark maps and transfer card table data as appropriate for a successful copy.
896
* @param env GC thread.
897
* @param srcObject Source object that was copy forwarded.
898
* @param dstObject Destination object that was copy forwarded to.
899
* @param dstCache Destination copy scan cache for the forwarded object.
900
*/
901
MMINLINE void updateMarkMapAndCardTableOnCopy(MM_EnvironmentVLHGC *env, J9Object *srcObject, J9Object *dstObject, MM_CopyScanCacheVLHGC *dstCache);
902
903
/**
904
* Determine whether a copy forward cycle that has been started did complete successfully.
905
* @return true if the copy forward cycle completed successfully, false otherwise.
906
*/
907
bool copyForwardCompletedSuccessfully(MM_EnvironmentVLHGC *env);
908
909
/**
910
* Used by the logic which relocates objects to different NUMA nodes by looking up the context which owns a given "source" address in the heap.
911
* @param address[in] A heap address for which the receiver will look up the owning context (must be in the heap)
912
* @return The allocation context which owns the region within which address exists
913
*/
914
MMINLINE MM_AllocationContextTarok *getContextForHeapAddress(void *address);
915
916
/**
917
* Determine the desired copy cache size for the specified compact group for the current thread.
918
* The size is chosen to balance the opposing problems of fragmentation and contention.
919
*
920
* @param env[in] the current thread
921
* @param compactGroup the compact group to calculate the size for
922
* @return the desired copy cache size, in bytes
923
*/
924
UDATA getDesiredCopyCacheSize(MM_EnvironmentVLHGC *env, UDATA compactGroup);
925
926
/**
927
* Set the specified free memory candidate region to be a survivor region.
928
* 1. Update its free memory in preparation for copying objects into it
929
* 2. Prepare its reference lists for processing
930
* The caller is responsible for calling rememberAndResetReferenceLists() on the list once it's released all locks.
931
* @param env[in] the current thread
932
* @param region[in] the free memory region to convert
933
*/
934
void convertFreeMemoryCandidateToSurvivorRegion(MM_EnvironmentVLHGC* env, MM_HeapRegionDescriptorVLHGC *region);
935
936
/**
937
* Scan the root set, copying-and-forwarding any objects found.
938
* @param env[in] the current thread
939
*/
940
void scanRoots(MM_EnvironmentVLHGC* env);
941
942
#if defined(J9VM_GC_LEAF_BITS)
943
/**
944
* Copy any leaf children of the specified object.
945
* @param env[in] the current thread
946
* @param reservingContext[in] The context to which we would prefer to copy any objects discovered in this method
947
* @param objectPtr[in] the object whose children should be copied
948
*/
949
void copyLeafChildren(MM_EnvironmentVLHGC* env, MM_AllocationContextTarok *reservingContext, J9Object* objectPtr);
950
#endif /* J9VM_GC_LEAF_BITS */
951
952
/**
953
* Calculate estimation for allocation age based on compact group and set it to the merged region
954
* @param[in] env The current thread
955
* @param[in] region The region to adjust age to
956
*/
957
void setAllocationAgeForMergedRegion(MM_EnvironmentVLHGC* env, MM_HeapRegionDescriptorVLHGC *region);
958
959
/**
960
* check if the Object in jni critical region
961
*/
962
bool isObjectInNoEvacuationRegions(MM_EnvironmentVLHGC *env, J9Object *objectPtr);
963
964
bool randomDecideForceNonEvacuatedRegion(UDATA ratio);
965
966
/**
967
* Iterate the slot reference and parse and pass leaf bit of the reference to copy forward
968
* to avoid to push leaf object to work stack in case the reference need to be marked instead of copied.
969
*/
970
MMINLINE bool iterateAndCopyforwardSlotReference(MM_EnvironmentVLHGC *env, MM_AllocationContextTarok *reservingContext, J9Object *objectPtr);
971
972
void verifyObjectsInRange(MM_EnvironmentVLHGC *env, UDATA *lowAddress, UDATA *highAddress);
973
void verifyChunkSlotsAndMapSlotsInRange(MM_EnvironmentVLHGC *env, UDATA *lowAddress, UDATA *highAddress);
974
void checkConsistencyGMPMapAndPGCMap(MM_EnvironmentVLHGC *env, MM_HeapRegionDescriptorVLHGC *region, UDATA *lowAddress, UDATA *highAddress);
975
void cleanOverflowInRange(MM_EnvironmentVLHGC *env, UDATA *lowAddress, UDATA *highAddress);
976
977
MMINLINE bool isCompressedSurvivor(void *heapAddr);
978
MMINLINE void setCompressedSurvivorCards(MM_EnvironmentVLHGC *env, void *startHeapAddress, void *endHeapAddress);
979
MMINLINE void cleanCompressedSurvivorCardTable(MM_EnvironmentVLHGC *env);
980
981
protected:
982
983
MM_CopyForwardScheme(MM_EnvironmentVLHGC *env, MM_HeapRegionManager *manager);
984
985
/**
986
* Initialize the receivers internal support structures and state.
987
* @param env[in] Main thread.
988
*/
989
bool initialize(MM_EnvironmentVLHGC *env);
990
991
/**
992
* Clean up the receivers internal support structures and state.
993
* @param env[in] Main thread.
994
*/
995
void tearDown(MM_EnvironmentVLHGC *env);
996
997
void mainSetupForCopyForward(MM_EnvironmentVLHGC *env);
998
void mainCleanupForCopyForward(MM_EnvironmentVLHGC *env);
999
void workerSetupForCopyForward(MM_EnvironmentVLHGC *env);
1000
1001
void clearGCStats(MM_EnvironmentVLHGC *env);
1002
1003
/**
1004
* Merge the current threads copy forward stats into the global copy forward stats.
1005
*/
1006
void mergeGCStats(MM_EnvironmentVLHGC *env);
1007
1008
/**
1009
* After successful copy forward cycle, update leaf region base pointers to newly copied spine locations and
1010
* recycle any with spines remaining in evacuate space.
1011
*/
1012
void updateLeafRegions(MM_EnvironmentVLHGC *env);
1013
1014
/**
1015
* Before a copy forward operation, perform any pre processing required on regions.
1016
*/
1017
void preProcessRegions(MM_EnvironmentVLHGC *env);
1018
1019
/**
1020
* After successful copy forward operation, perform any post processing required on regions.
1021
*/
1022
void postProcessRegions(MM_EnvironmentVLHGC *env);
1023
1024
/**
1025
* Clean cards for the purpose of finding "roots" into the collection set.
1026
* @param env A GC thread involved in the cleaning.
1027
*/
1028
void cleanCardTable(MM_EnvironmentVLHGC *env);
1029
1030
/**
1031
* Helper routine to clean cards during a partial collection for the purpose of finding "roots" into the collection set.
1032
* @param env A GC thread involved in the cleaning.
1033
* @param cardCleaner Card handling instance to manage state transition and actions.
1034
*/
1035
void cleanCardTableForPartialCollect(MM_EnvironmentVLHGC *env, MM_CardCleaner *cardCleaner);
1036
1037
/**
1038
* Update or delete any external cycle object data that was involved in the collection set.
1039
* This routine will clear the external mark map for the collection set (if successful) or adjust the map on moved objects (abort) and
1040
* remove any dead objects from external cycle work packets. It will also update (forward) any work packet pointers which have survived
1041
* the collection. The responsibility of setting the external cycle mark map survivor bits and updating cards lies with object copying.
1042
*/
1043
void updateOrDeleteObjectsFromExternalCycle(MM_EnvironmentVLHGC *env);
1044
1045
/**
1046
* Scans the marked objects in the [lowAddress..highAddress) range. If rememberedObjectsOnly is set, we will further constrain
1047
* this scanned set by only scanning objects in the range which have the OBJECT_HEADER_REMEMBERED bit set. The receiver uses
1048
* its _markMap to determine which objects in the range are marked.
1049
*
1050
* @param env[in] A GC thread (note that this method could be called by multiple threads, in parallel, but on disjoint address ranges)
1051
* @param lowAddress[in] The heap address where the receiver will begin walking objects
1052
* @param highAddress[in] The heap address after the last address we will potentially find a live object
1053
* @param rememberedObjectsOnly If true, the receiver only scans remembered live objects in the range. If false, it scans all live objects in the range
1054
* @return true if all the objects in the given range were scanned without causing an abort
1055
*/
1056
bool scanObjectsInRange(MM_EnvironmentVLHGC *env, void *lowAddress, void *highAddress, bool rememberedObjectsOnly);
1057
1058
/**
1059
* Checks whether the suggestedContext passed in is a preferred allocation context for
1060
* object relocation. If so the same context is returned if not the object's original context
1061
* is returned.
1062
* @param[in] suggestedContext The allocation context we intended to copy the object into
1063
* @param[in] objectPtr A pointer to the object being copied
1064
* @return The reservingContext or the object's owning context if the suggestedContext is not a preferred object relocation context
1065
*/
1066
MMINLINE MM_AllocationContextTarok *getPreferredAllocationContext(MM_AllocationContextTarok *suggestedContext, J9Object *objectPtr);
1067
1068
public:
1069
1070
static MM_CopyForwardScheme *newInstance(MM_EnvironmentVLHGC *env, MM_HeapRegionManager *manager);
1071
void kill(MM_EnvironmentVLHGC *env);
1072
1073
/**
1074
* Pre Copy Forward process. Clear GC stats, pre process regions and perform any main-specific setup
1075
*/
1076
void copyForwardPreProcess(MM_EnvironmentVLHGC *env);
1077
1078
/**
1079
* Post Copy Forward process. Sets persistent flag indicating if copy forward collection was successful or not.
1080
*/
1081
void copyForwardPostProcess(MM_EnvironmentVLHGC *env);
1082
1083
/**
1084
* Run a copy forward collection operation on the already determined collection set.
1085
* @param env[in] Main thread.
1086
*/
1087
void copyForwardCollectionSet(MM_EnvironmentVLHGC *env);
1088
1089
/**
1090
* Return true if CopyForward is running under Hybrid mode
1091
*/
1092
bool isHybrid(MM_EnvironmentVLHGC *env)
1093
{
1094
return (0 != _regionCountCannotBeEvacuated);
1095
}
1096
1097
void setReservedNonEvacuatedRegions(UDATA regionCount)
1098
{
1099
_regionCountReservedNonEvacuated = regionCount;
1100
}
1101
1102
#if defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD)
1103
/**
1104
* Run concurrent copy forward collection increment. Contrary to regular copyForwardCollectionSet(),
1105
* this method will be called twice for each PGC cycle (whenever concurrent copy forward is
1106
* enabled), once for initial STW increment and once for the final STW increment. For each of
1107
* those increments isConcurrentCycleInProgress state/value will get updated. For initial increment,
1108
* it will change from false to true causing only preProcess step to be performed, and for the
1109
* final increment it will change from true to false causing only postProcess step to be performed.
1110
*
1111
* @param env[in] Main thread.
1112
*/
1113
void concurrentCopyForwardCollectionSet(MM_EnvironmentVLHGC *env);
1114
#endif /* defined(OMR_GC_VLHGC_CONCURRENT_COPY_FORWARD) */
1115
1116
/**
1117
* True if concurrent CopyForward cycle is active at any point (STW or concurrent
1118
* task active, or even short gaps between STW and concurrent tasks). Equivalent to
1119
* isConcurrentCycleInProgress() from Scavenger
1120
*/
1121
MMINLINE bool isConcurrentCycleInProgress() {
1122
/* Unimplemented */
1123
return false;
1124
}
1125
1126
void abandonTLHRemainders(MM_EnvironmentVLHGC *env);
1127
1128
friend class MM_CopyForwardGMPCardCleaner;
1129
friend class MM_CopyForwardNoGMPCardCleaner;
1130
friend class MM_CopyForwardSchemeTask;
1131
friend class MM_CopyForwardSchemeRootScanner;
1132
friend class MM_CopyForwardSchemeRootClearer;
1133
friend class MM_CopyForwardSchemeAbortScanner;
1134
};
1135
1136
#endif /* COPYFORWARDSCHEME_HPP_ */
1137
1138