-
Notifications
You must be signed in to change notification settings - Fork 751
/
Copy pathRealtimeMarkingSchemeRootClearer.hpp
299 lines (254 loc) · 10.4 KB
/
RealtimeMarkingSchemeRootClearer.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
/*******************************************************************************
* Copyright IBM Corp. and others 2019
*
* 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
*******************************************************************************/
/**
* @file
* @ingroup GC_Metronome
*/
#if !defined(REALTIMEROOTCLEARER_HPP_)
#define REALTIMEROOTCLEARER_HPP_
#include "j9.h"
#include "j9cfg.h"
#include "modronopt.h"
#include "EnvironmentRealtime.hpp"
#include "RealtimeRootScanner.hpp"
#include "RealtimeGC.hpp"
#include "RealtimeMarkingScheme.hpp"
/**
* This scanner will mark objects that pass through its doSlot.
*/
class MM_RealtimeMarkingSchemeRootClearer : public MM_RealtimeRootScanner
{
/* Data members / types */
public:
protected:
private:
/* Methods */
public:
/**
* Simple chained constructor.
*/
MM_RealtimeMarkingSchemeRootClearer(MM_EnvironmentRealtime *env, MM_RealtimeGC *realtimeGC) :
MM_RealtimeRootScanner(env, realtimeGC)
{
_typeId = __FUNCTION__;
}
/**
* This should not be called
*/
virtual void
doSlot(J9Object **slot)
{
Assert_MM_unreachable();
}
/**
* This scanner can be instantiated so we must give it a name.
*/
virtual const char*
scannerName()
{
return "Clearable";
}
/**
* Destroys unmarked monitors.
*/
virtual void
doMonitorReference(J9ObjectMonitor *objectMonitor, GC_HashTableIterator *monitorReferenceIterator)
{
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor*)objectMonitor->monitor;
if (!_markingScheme->isMarked((J9Object *)monitor->userData)) {
monitorReferenceIterator->removeSlot();
/* We must call objectMonitorDestroy (as opposed to omrthread_monitor_destroy) when the
* monitor is not internal to the GC */
_javaVM->internalVMFunctions->objectMonitorDestroy(_javaVM, (J9VMThread *)_env->getLanguageVMThread(), (omrthread_monitor_t)monitor);
}
}
/**
* Wraps the MM_RootScanner::scanMonitorReferences method to disable yielding during the scan.
* @see MM_RootScanner::scanMonitorReferences()
*/
virtual void
scanMonitorReferences(MM_EnvironmentBase *envBase)
{
MM_EnvironmentRealtime *env = (MM_EnvironmentRealtime *)envBase;
/* @NOTE For SRT and MT to play together this needs to be investigated */
if (_singleThread || J9MODRON_HANDLE_NEXT_WORK_UNIT(env)) {
reportScanningStarted(RootScannerEntity_MonitorReferences);
J9ObjectMonitor *objectMonitor = NULL;
J9MonitorTableListEntry *monitorTableList = _javaVM->monitorTableList;
while (NULL != monitorTableList) {
J9HashTable *table = monitorTableList->monitorTable;
if (NULL != table) {
GC_HashTableIterator iterator(table);
iterator.disableTableGrowth();
while (NULL != (objectMonitor = (J9ObjectMonitor *)iterator.nextSlot())) {
doMonitorReference(objectMonitor, &iterator);
if (shouldYieldFromMonitorScan()) {
yield();
}
}
iterator.enableTableGrowth();
}
monitorTableList = monitorTableList->next;
}
reportScanningEnded(RootScannerEntity_MonitorReferences);
}
}
virtual CompletePhaseCode scanMonitorReferencesComplete(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_MonitorReferenceObjectsComplete);
_javaVM->internalVMFunctions->objectMonitorDestroyComplete(_javaVM, (J9VMThread *)env->getLanguageVMThread());
reportScanningEnded(RootScannerEntity_MonitorReferenceObjectsComplete);
return complete_phase_OK;
}
virtual void scanWeakReferenceObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_WeakReferenceObjects);
_realtimeGC->getRealtimeDelegate()->scanWeakReferenceObjects(env);
reportScanningEnded(RootScannerEntity_WeakReferenceObjects);
}
virtual CompletePhaseCode scanWeakReferencesComplete(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_WeakReferenceObjectsComplete);
if (env->_currentTask->synchronizeGCThreadsAndReleaseMain(env, UNIQUE_ID)) {
env->_cycleState->_referenceObjectOptions |= MM_CycleState::references_clear_weak;
env->_currentTask->releaseSynchronizedGCThreads(env);
}
reportScanningEnded(RootScannerEntity_WeakReferenceObjectsComplete);
return complete_phase_OK;
}
virtual void scanSoftReferenceObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_SoftReferenceObjects);
_realtimeGC->getRealtimeDelegate()->scanSoftReferenceObjects(env);
reportScanningEnded(RootScannerEntity_SoftReferenceObjects);
}
virtual CompletePhaseCode scanSoftReferencesComplete(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_SoftReferenceObjectsComplete);
if (env->_currentTask->synchronizeGCThreadsAndReleaseMain(env, UNIQUE_ID)) {
env->_cycleState->_referenceObjectOptions |= MM_CycleState::references_clear_soft;
env->_currentTask->releaseSynchronizedGCThreads(env);
}
reportScanningEnded(RootScannerEntity_SoftReferenceObjectsComplete);
return complete_phase_OK;
}
virtual void scanPhantomReferenceObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_PhantomReferenceObjects);
_realtimeGC->getRealtimeDelegate()->scanPhantomReferenceObjects(env);
reportScanningEnded(RootScannerEntity_PhantomReferenceObjects);
}
virtual CompletePhaseCode scanPhantomReferencesComplete(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_PhantomReferenceObjectsComplete);
if (env->_currentTask->synchronizeGCThreadsAndReleaseMain(env, UNIQUE_ID)) {
env->_cycleState->_referenceObjectOptions |= MM_CycleState::references_clear_phantom;
env->_currentTask->releaseSynchronizedGCThreads(env);
}
/* phantom reference processing may resurrect objects - scan them now */
_realtimeGC->completeMarking(MM_EnvironmentRealtime::getEnvironment(env));
reportScanningEnded(RootScannerEntity_PhantomReferenceObjectsComplete);
return complete_phase_OK;
}
#if defined(J9VM_GC_FINALIZATION)
/**
* Wraps the MM_RootScanner::scanUnfinalizedObjects method to disable yielding during the scan
* then yield after scanning.
* @see MM_RootScanner::scanUnfinalizedObjects()
*/
virtual void
scanUnfinalizedObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_UnfinalizedObjects);
/* allow the marking scheme to handle this */
_realtimeGC->getRealtimeDelegate()->scanUnfinalizedObjects(env);
reportScanningEnded(RootScannerEntity_UnfinalizedObjects);
}
virtual CompletePhaseCode scanUnfinalizedObjectsComplete(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_UnfinalizedObjectsComplete);
/* ensure that all unfinalized processing is complete before we start marking additional objects */
env->_currentTask->synchronizeGCThreads(env, UNIQUE_ID);
_realtimeGC->completeMarking(env);
reportScanningEnded(RootScannerEntity_UnfinalizedObjectsComplete);
return complete_phase_OK;
}
virtual void doFinalizableObject(j9object_t object) {
Assert_MM_unreachable();
}
#endif /* J9VM_GC_FINALIZATION */
virtual void
scanOwnableSynchronizerObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_OwnableSynchronizerObjects);
/* allow the marking scheme to handle this */
_realtimeGC->getRealtimeDelegate()->scanOwnableSynchronizerObjects(env);
reportScanningEnded(RootScannerEntity_OwnableSynchronizerObjects);
}
virtual void
scanContinuationObjects(MM_EnvironmentBase *envBase) {
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
reportScanningStarted(RootScannerEntity_ContinuationObjects);
/* allow the marking scheme to handle this */
_realtimeGC->getRealtimeDelegate()->scanContinuationObjects(env);
reportScanningEnded(RootScannerEntity_ContinuationObjects);
}
/**
* Wraps the MM_RootScanner::scanJNIWeakGlobalReferences method to disable yielding during the scan.
* @see MM_RootScanner::scanJNIWeakGlobalReferences()
*/
virtual void
scanJNIWeakGlobalReferences(MM_EnvironmentBase *envBase)
{
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envBase);
env->disableYield();
MM_RootScanner::scanJNIWeakGlobalReferences(env);
env->enableYield();
}
/**
* Clears slots holding unmarked objects.
*/
virtual void
doJNIWeakGlobalReference(J9Object **slotPtr)
{
J9Object *objectPtr = *slotPtr;
if (objectPtr && !_markingScheme->isMarked(objectPtr)) {
*slotPtr = NULL;
}
}
#if defined(J9VM_OPT_JVMTI)
/**
* Clears slots holding unmarked objects.
*/
virtual void
doJVMTIObjectTagSlot(J9Object **slotPtr, GC_JVMTIObjectTagTableIterator *objectTagTableIterator)
{
J9Object *objectPtr = *slotPtr;
if (objectPtr && !_markingScheme->isMarked(objectPtr)) {
*slotPtr = NULL;
}
}
#endif /* J9VM_OPT_JVMTI */
protected:
private:
};
#endif /* REALTIMEROOTCLEARER_HPP_ */