-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathContractslotScanner.hpp
322 lines (297 loc) · 13.5 KB
/
ContractslotScanner.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*******************************************************************************
* Copyright IBM Corp. and others 1991
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "Base.hpp"
#include "ClassIterator.hpp"
#include "CollectorLanguageInterfaceImpl.hpp"
#include "ConfigurationDelegate.hpp"
#include "EnvironmentBase.hpp"
#include "FinalizableObjectBuffer.hpp"
#include "FinalizableReferenceBuffer.hpp"
#include "FinalizeListManager.hpp"
#include "GCExtensions.hpp"
#include "Heap.hpp"
#include "HeapRegionDescriptorStandard.hpp"
#include "HeapRegionIteratorStandard.hpp"
#include "ModronAssertions.h"
#include "ObjectAccessBarrier.hpp"
#include "OwnableSynchronizerObjectBuffer.hpp"
#include "OwnableSynchronizerObjectList.hpp"
#include "ContinuationObjectBuffer.hpp"
#include "ContinuationObjectList.hpp"
#include "RootScanner.hpp"
#include "RootScannerTypes.h"
#include "UnfinalizedObjectBuffer.hpp"
#include "UnfinalizedObjectList.hpp"
/* All slot scanner for full VM slot walk.
* @copydoc MM_RootScanner
* @ingroup GC_Modron_Base
*/
class MM_ContractSlotScanner : public MM_RootScanner
{
private:
void *_srcBase;
void *_srcTop;
void *_dstBase;
protected:
public:
private:
protected:
public:
MM_ContractSlotScanner(MM_EnvironmentBase *env, void *srcBase, void *srcTop, void *dstBase) :
MM_RootScanner(env, true)
,_srcBase(srcBase)
,_srcTop(srcTop)
,_dstBase(dstBase)
{}
virtual void
doSlot(J9Object **slotPtr)
{
J9Object *objectPtr = *slotPtr;
if (NULL != objectPtr) {
if ((objectPtr >= (J9Object *)_srcBase) && (objectPtr < (J9Object *)_srcTop)) {
objectPtr = (J9Object *)((uintptr_t)objectPtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
*slotPtr = objectPtr;
}
}
}
virtual void
doClass(J9Class *clazz)
{
volatile j9object_t *objectSlotPtr = NULL;
/* walk all object slots */
GC_ClassIterator classIterator(_env, clazz);
while ((objectSlotPtr = classIterator.nextSlot()) != NULL) {
/* discard volatile since we must be in stop-the-world mode */
doSlot((j9object_t *)objectSlotPtr);
}
/* There is no need to walk the J9Class slots since no values within this struct could
* move during a nursery contract.
*/
}
virtual void
scanUnfinalizedObjects(MM_EnvironmentBase *env)
{
reportScanningStarted(RootScannerEntity_UnfinalizedObjects);
/* Only walk MEMORY_TYPE_NEW regions since MEMORY_TYPE_OLD regions would not contain
* any objects that would move during a nursery contract.
*/
MM_HeapRegionDescriptorStandard *region = NULL;
GC_HeapRegionIteratorStandard regionIterator(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
MM_UnfinalizedObjectList *list = ®ionExtension->_unfinalizedObjectLists[i];
list->startUnfinalizedProcessing();
}
}
}
GC_HeapRegionIteratorStandard regionIterator2(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator2.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
MM_UnfinalizedObjectList *list = ®ionExtension->_unfinalizedObjectLists[i];
if (!list->wasEmpty()) {
J9Object *object = list->getPriorList();
while (NULL != object) {
J9Object *movePtr = object;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
object = _extensions->accessBarrier->getFinalizeLink(movePtr);
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
env->getGCEnvironment()->_unfinalizedObjectBuffer->add(env, movePtr);
}
}
}
}
}
/* restore everything to a flushed state before exiting */
env->getGCEnvironment()->_unfinalizedObjectBuffer->flush(env);
reportScanningEnded(RootScannerEntity_UnfinalizedObjects);
}
virtual void
scanOwnableSynchronizerObjects(MM_EnvironmentBase *env)
{
reportScanningStarted(RootScannerEntity_OwnableSynchronizerObjects);
/* Only walk MEMORY_TYPE_NEW regions since MEMORY_TYPE_OLD regions would not contain
* any objects that would move during a nursery contract.
*/
MM_HeapRegionDescriptorStandard *region = NULL;
GC_HeapRegionIteratorStandard regionIterator(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
MM_OwnableSynchronizerObjectList *list = ®ionExtension->_ownableSynchronizerObjectLists[i];
list->startOwnableSynchronizerProcessing();
}
}
}
GC_HeapRegionIteratorStandard regionIterator2(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator2.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
MM_OwnableSynchronizerObjectList *list = ®ionExtension->_ownableSynchronizerObjectLists[i];
if (!list->wasEmpty()) {
J9Object *object = list->getPriorList();
while (NULL != object) {
J9Object *movePtr = object;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
J9Object *next = _extensions->accessBarrier->getOwnableSynchronizerLink(movePtr);
/* the last object in the list pointing itself, after the object moved, the link still points to old object address */
if (object != next) {
object = next;
} else {
/* reach the end of the list */
object = NULL;
}
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
env->getGCEnvironment()->_ownableSynchronizerObjectBuffer->add(env, movePtr);
}
}
}
}
}
/* restore everything to a flushed state before exiting */
env->getGCEnvironment()->_ownableSynchronizerObjectBuffer->flush(env);
reportScanningEnded(RootScannerEntity_OwnableSynchronizerObjects);
}
virtual void
scanContinuationObjects(MM_EnvironmentBase *env)
{
reportScanningStarted(RootScannerEntity_ContinuationObjects);
/* Only walk MEMORY_TYPE_NEW regions since MEMORY_TYPE_OLD regions would not contain
* any objects that would move during a nursery contract.
*/
MM_HeapRegionDescriptorStandard *region = NULL;
GC_HeapRegionIteratorStandard regionIterator(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
regionExtension->_continuationObjectLists[i].startProcessing();
}
}
}
GC_HeapRegionIteratorStandard regionIterator2(env->getExtensions()->heap->getHeapRegionManager());
while (NULL != (region = regionIterator2.nextRegion())) {
if ((MEMORY_TYPE_NEW == (region->getTypeFlags() & MEMORY_TYPE_NEW))) {
MM_HeapRegionDescriptorStandardExtension *regionExtension = MM_ConfigurationDelegate::getHeapRegionDescriptorStandardExtension(env, region);
for (uintptr_t i = 0; i < regionExtension->_maxListIndex; i++) {
MM_ContinuationObjectList *list = ®ionExtension->_continuationObjectLists[i];
if (!list->wasEmpty()) {
J9Object *object = list->getPriorList();
while (NULL != object) {
J9Object *movePtr = object;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
J9Object *next = _extensions->accessBarrier->getContinuationLink(movePtr);
/* the last object in the list pointing itself, after the object moved, the link still points to old object address */
if (object != next) {
object = next;
} else {
/* reach the end of the list */
object = NULL;
}
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
env->getGCEnvironment()->_continuationObjectBuffer->add(env, movePtr);
}
}
}
}
}
/* restore everything to a flushed state before exiting */
env->getGCEnvironment()->_continuationObjectBuffer->flush(env);
reportScanningEnded(RootScannerEntity_ContinuationObjects);
}
#if defined(J9VM_GC_FINALIZATION)
void
doFinalizableObject(J9Object *objectPtr)
{
Assert_MM_unreachable();
}
virtual void
scanFinalizableObjects(MM_EnvironmentBase *env)
{
reportScanningStarted(RootScannerEntity_FinalizableObjects);
GC_FinalizeListManager *finalizeListManager = _extensions->finalizeListManager;
{
GC_FinalizableObjectBuffer objectBuffer(_extensions);
/* walk finalizable objects loaded by the system class loader */
j9object_t systemObject = finalizeListManager->resetSystemFinalizableObjects();
while (NULL != systemObject) {
J9Object *movePtr = systemObject;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
systemObject = _extensions->accessBarrier->getFinalizeLink(movePtr);
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
objectBuffer.add(env, movePtr);
}
objectBuffer.flush(env);
}
{
GC_FinalizableObjectBuffer objectBuffer(_extensions);
/* walk finalizable objects loaded by the all other class loaders */
j9object_t defaultObject = finalizeListManager->resetDefaultFinalizableObjects();
while (NULL != defaultObject) {
J9Object *movePtr = defaultObject;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
defaultObject = _extensions->accessBarrier->getFinalizeLink(movePtr);
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
objectBuffer.add(env, movePtr);
}
objectBuffer.flush(env);
}
{
/* walk reference objects */
GC_FinalizableReferenceBuffer referenceBuffer(_extensions);
j9object_t referenceObject = finalizeListManager->resetReferenceObjects();
while (NULL != referenceObject) {
J9Object *movePtr = referenceObject;
if ((movePtr >= (J9Object *)_srcBase) && (movePtr < (J9Object *)_srcTop)) {
movePtr = (J9Object *)((uintptr_t)movePtr - (uintptr_t)_srcBase + (uintptr_t)_dstBase);
}
/* read the next link out of the moved copy of the object before we add it to the buffer */
referenceObject = _extensions->accessBarrier->getReferenceLink(movePtr);
/* store the object in this thread's buffer. It will be flushed to the appropriate list when necessary. */
referenceBuffer.add(env, movePtr);
}
referenceBuffer.flush(env);
}
reportScanningEnded(RootScannerEntity_FinalizableObjects);
}
#endif /* J9VM_GC_FINALIZATION */
};