Skip to content

Commit 01765be

Browse files
committed
Fix up global continuation lists instead of rebuilding for compaction
Once continuation Object is constructed, the Object would be added in global continuation lists and the "dead" Object would be collected by GC, since logically compaction would not collect any continuation Object in the list, so we piggyback heap fix up to rebuild the list to reduce the extra cycle to walk the old list for fixing up. But between the Object is created and added into the list, GC could be triggered and find the live Object, which has not be added in the list, it could cause a circular linklist case, so changing fix up the existing list instead of rebuilding the list for compaction. Signed-off-by: Lin Hu <linhu@ca.ibm.com>
1 parent 55c52ff commit 01765be

7 files changed

+70
-28
lines changed

runtime/gc_glue_java/CompactDelegate.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include "MarkMap.hpp"
3232
#include "OwnableSynchronizerObjectBuffer.hpp"
3333
#include "OwnableSynchronizerObjectList.hpp"
34-
#include "ContinuationObjectBuffer.hpp"
35-
#include "ContinuationObjectList.hpp"
3634
#include "PointerContiguousArrayIterator.hpp"
3735

3836
#if defined(OMR_GC_MODRON_COMPACTION)
@@ -132,8 +130,6 @@ MM_CompactDelegate::workerCleanupAfterGC(MM_EnvironmentBase *env)
132130
{
133131
/* flush ownable synchronizer object buffer after rebuild the ownableSynchronizerObjectList during fixupObjects */
134132
env->getGCEnvironment()->_ownableSynchronizerObjectBuffer->flush(env);
135-
/* flush continuation object buffer after rebuild the continuationObjectList during fixupObjects */
136-
env->getGCEnvironment()->_continuationObjectBuffer->flush(env);
137133
}
138134

139135
void
@@ -146,7 +142,6 @@ MM_CompactDelegate::mainSetupForGC(MM_EnvironmentBase *env)
146142
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
147143
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
148144
regionExtension->_ownableSynchronizerObjectLists[i].startOwnableSynchronizerProcessing();
149-
regionExtension->_continuationObjectLists[i].startProcessing();
150145
}
151146
}
152147
}

runtime/gc_glue_java/CompactSchemeFixupObject.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "MixedObjectIterator.hpp"
3333
#include "ObjectAccessBarrier.hpp"
3434
#include "OwnableSynchronizerObjectBuffer.hpp"
35-
#include "ContinuationObjectBuffer.hpp"
3635
#include "VMHelpers.hpp"
3736
#include "ParallelDispatcher.hpp"
3837
#include "PointerContiguousArrayIterator.hpp"
@@ -126,12 +125,6 @@ MM_CompactSchemeFixupObject::addOwnableSynchronizerObjectInList(MM_EnvironmentBa
126125
}
127126
}
128127

129-
MMINLINE void
130-
MM_CompactSchemeFixupObject::addContinuationObjectInList(MM_EnvironmentBase *env, omrobjectptr_t objectPtr)
131-
{
132-
env->getGCEnvironment()->_continuationObjectBuffer->add(env, objectPtr);
133-
}
134-
135128
void
136129
MM_CompactSchemeFixupObject::fixupObject(MM_EnvironmentStandard *env, omrobjectptr_t objectPtr)
137130
{
@@ -158,7 +151,6 @@ MM_CompactSchemeFixupObject::fixupObject(MM_EnvironmentStandard *env, omrobjectp
158151
fixupMixedObject(objectPtr);
159152
break;
160153
case GC_ObjectModel::SCAN_CONTINUATION_OBJECT:
161-
addContinuationObjectInList(env, objectPtr);
162154
fixupContinuationObject(env, objectPtr);
163155
break;
164156
case GC_ObjectModel::SCAN_FLATTENED_ARRAY_OBJECT:

runtime/gc_glue_java/CompactSchemeFixupObject.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ class MM_CompactSchemeFixupObject {
8282
* @param object -- The object of type or subclass of java.util.concurrent.locks.AbstractOwnableSynchronizer.
8383
*/
8484
MMINLINE void addOwnableSynchronizerObjectInList(MM_EnvironmentBase *env, omrobjectptr_t objectPtr);
85-
86-
MMINLINE void addContinuationObjectInList(MM_EnvironmentBase *env, omrobjectptr_t objectPtr);
8785
};
8886

8987
typedef struct StackIteratorData4CompactSchemeFixupObject {

runtime/gc_glue_java/CompactSchemeFixupRoots.cpp

+47-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2001, 2020 IBM Corp. and others
2+
* Copyright (c) 2001, 2022 IBM Corp. and others
33
*
44
* This program and the accompanying materials are made available under
55
* the terms of the Eclipse Public License 2.0 which accompanies this
@@ -36,6 +36,8 @@
3636
#include "Task.hpp"
3737
#include "UnfinalizedObjectBuffer.hpp"
3838
#include "UnfinalizedObjectList.hpp"
39+
#include "ContinuationObjectBuffer.hpp"
40+
#include "ContinuationObjectList.hpp"
3941

4042

4143
#if defined(J9VM_GC_FINALIZATION)
@@ -97,7 +99,7 @@ MM_CompactSchemeFixupRoots::fixupUnfinalizedObjects(MM_EnvironmentBase *env)
9799
GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());
98100
while(NULL != (region = regionIterator.nextRegion())) {
99101
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
100-
for (UDATA i = 0; i < regionExtension->_maxListIndex; i++) {
102+
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
101103
MM_UnfinalizedObjectList *list = &regionExtension->_unfinalizedObjectLists[i];
102104
list->startUnfinalizedProcessing();
103105
}
@@ -108,7 +110,7 @@ MM_CompactSchemeFixupRoots::fixupUnfinalizedObjects(MM_EnvironmentBase *env)
108110
GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());
109111
while(NULL != (region = regionIterator.nextRegion())) {
110112
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
111-
for (UDATA i = 0; i < regionExtension->_maxListIndex; i++) {
113+
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
112114
MM_UnfinalizedObjectList *list = &regionExtension->_unfinalizedObjectLists[i];
113115
if (!list->wasEmpty()) {
114116
if(J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {
@@ -129,3 +131,45 @@ MM_CompactSchemeFixupRoots::fixupUnfinalizedObjects(MM_EnvironmentBase *env)
129131
env->getGCEnvironment()->_unfinalizedObjectBuffer->flush(env);
130132
}
131133
#endif /* J9VM_GC_FINALIZATION */
134+
135+
136+
void
137+
MM_CompactSchemeFixupRoots::fixupContinuationObjects(MM_EnvironmentBase *env)
138+
{
139+
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
140+
if (env->_currentTask->synchronizeGCThreadsAndReleaseMain(env, UNIQUE_ID)) {
141+
MM_HeapRegionDescriptorStandard *region = NULL;
142+
GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());
143+
while(NULL != (region = regionIterator.nextRegion())) {
144+
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
145+
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
146+
MM_ContinuationObjectList *list = &regionExtension->_continuationObjectLists[i];
147+
list->startProcessing();
148+
}
149+
}
150+
env->_currentTask->releaseSynchronizedGCThreads(env);
151+
}
152+
MM_HeapRegionDescriptorStandard *region = NULL;
153+
GC_HeapRegionIteratorStandard regionIterator(extensions->getHeap()->getHeapRegionManager());
154+
while(NULL != (region = regionIterator.nextRegion())) {
155+
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
156+
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
157+
MM_ContinuationObjectList *list = &regionExtension->_continuationObjectLists[i];
158+
if (!list->wasEmpty()) {
159+
if(J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {
160+
omrobjectptr_t object = list->getPriorList();
161+
while (NULL != object) {
162+
omrobjectptr_t forwardedPtr = _compactScheme->getForwardingPtr(object);
163+
/* read the next link out of the moved copy of the object before we add it to the buffer */
164+
object = extensions->accessBarrier->getContinuationLink(forwardedPtr);
165+
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
166+
env->getGCEnvironment()->_continuationObjectBuffer->add(env, forwardedPtr);
167+
}
168+
}
169+
}
170+
}
171+
}
172+
173+
/* restore everything to a flushed state before exiting */
174+
env->getGCEnvironment()->_continuationObjectBuffer->flush(env);
175+
}

runtime/gc_glue_java/CompactSchemeFixupRoots.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class MM_CompactSchemeFixupRoots : public MM_RootScanner {
7373
virtual void scanUnfinalizedObjects(MM_EnvironmentBase *env) {
7474
/* allow the compact scheme to handle this */
7575
reportScanningStarted(RootScannerEntity_UnfinalizedObjects);
76-
MM_CompactSchemeFixupObject fixupObject(env, _compactScheme);
7776
fixupUnfinalizedObjects(env);
7877
reportScanningEnded(RootScannerEntity_UnfinalizedObjects);
7978
}
@@ -87,7 +86,6 @@ class MM_CompactSchemeFixupRoots : public MM_RootScanner {
8786
virtual void scanFinalizableObjects(MM_EnvironmentBase *env) {
8887
if (_singleThread || J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {
8988
reportScanningStarted(RootScannerEntity_FinalizableObjects);
90-
MM_CompactSchemeFixupObject fixupObject(env, _compactScheme);
9189
fixupFinalizableObjects(env);
9290
reportScanningEnded(RootScannerEntity_FinalizableObjects);
9391
}
@@ -99,13 +97,17 @@ class MM_CompactSchemeFixupRoots : public MM_RootScanner {
9997
}
10098

10199
virtual void scanContinuationObjects(MM_EnvironmentBase *env) {
102-
/* empty, move continuation processing in fixupObject */
100+
/* allow the compact scheme to handle this */
101+
reportScanningStarted(RootScannerEntity_ContinuationObjects);
102+
fixupContinuationObjects(env);
103+
reportScanningEnded(RootScannerEntity_ContinuationObjects);
103104
}
104105

105106
private:
106107
#if defined(J9VM_GC_FINALIZATION)
107108
void fixupFinalizableObjects(MM_EnvironmentBase *env);
108109
void fixupUnfinalizedObjects(MM_EnvironmentBase *env);
109110
#endif
111+
void fixupContinuationObjects(MM_EnvironmentBase *env);
110112
};
111113
#endif /* FIXUPROOTS_HPP_ */

runtime/gc_vlhgc/WriteOnceCompactor.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "ClassLoaderIterator.hpp"
4444
#include "ClassLoaderRememberedSet.hpp"
4545
#include "CompactGroupManager.hpp"
46+
#include "ContinuationObjectBuffer.hpp"
47+
#include "ContinuationObjectList.hpp"
4648
#include "VMHelpers.hpp"
4749
#include "WriteOnceCompactor.hpp"
4850
#include "Debug.hpp"
@@ -558,7 +560,6 @@ MM_WriteOnceCompactor::compact(MM_EnvironmentVLHGC *env)
558560
env->_compactVLHGCStats._moveStartTime = timeTemp;
559561
moveObjects(env);
560562
env->getGCEnvironment()->_ownableSynchronizerObjectBuffer->flush(env);
561-
env->getGCEnvironment()->_continuationObjectBuffer->flush(env);
562563
/* Note: moveObjects implicitly synchronizes threads */
563564
timeTemp = j9time_hires_clock();
564565
env->_compactVLHGCStats._moveEndTime = timeTemp;
@@ -1456,7 +1457,6 @@ MM_WriteOnceCompactor::fixupObject(MM_EnvironmentVLHGC* env, J9Object *objectPtr
14561457
fixupMixedObject(env, objectPtr, cache);
14571458
break;
14581459
case GC_ObjectModel::SCAN_CONTINUATION_OBJECT:
1459-
addContinuationObjectInList(env, objectPtr);
14601460
fixupContinuationObject(env, objectPtr, cache);
14611461
break;
14621462
case GC_ObjectModel::SCAN_CLASS_OBJECT:
@@ -2041,11 +2041,27 @@ MM_WriteOnceCompactor::fixupArrayletLeafRegionContentsAndObjectLists(MM_Environm
20412041
}
20422042
}
20432043
}
2044+
if (!region->getContinuationObjectList()->wasEmpty()) {
2045+
if (J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {
2046+
J9Object *pointer = region->getContinuationObjectList()->getPriorList();
2047+
while (NULL != pointer) {
2048+
Assert_MM_true(region->isAddressInRegion(pointer));
2049+
J9Object* forwardedPtr = getForwardingPtr(pointer);
2050+
2051+
/* read the next link out of the moved copy of the object before we add it to the buffer */
2052+
pointer = _extensions->accessBarrier->getContinuationLink(forwardedPtr);
2053+
2054+
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
2055+
env->getGCEnvironment()->_continuationObjectBuffer->add(env, forwardedPtr);
2056+
}
2057+
}
2058+
}
20442059
}
20452060
}
20462061

20472062
/* restore everything to a flushed state before exiting */
20482063
env->getGCEnvironment()->_unfinalizedObjectBuffer->flush(env);
2064+
env->getGCEnvironment()->_continuationObjectBuffer->flush(env);
20492065
}
20502066

20512067
void

runtime/gc_vlhgc/WriteOnceCompactor.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,6 @@ class MM_WriteOnceCompactor : public MM_BaseVirtual
514514
}
515515
}
516516

517-
MMINLINE void addContinuationObjectInList(MM_EnvironmentVLHGC *env, J9Object *objectPtr)
518-
{
519-
((MM_ContinuationObjectBufferVLHGC*) env->getGCEnvironment()->_continuationObjectBuffer)->addForOnlyCompactedRegion(env, objectPtr);
520-
}
521-
522517
#if defined(J9VM_GC_FINALIZATION)
523518
void fixupFinalizableObjects(MM_EnvironmentVLHGC *env);
524519

0 commit comments

Comments
 (0)