-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathConcurrentMarkingDelegate.hpp
316 lines (283 loc) · 11.2 KB
/
ConcurrentMarkingDelegate.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
/*******************************************************************************
* Copyright IBM Corp. and others 2017
*
* 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
*******************************************************************************/
#if !defined(CONCURRENTMARKINGDELEGATE_HPP_)
#define CONCURRENTMARKINGDELEGATE_HPP_
#include "omrcfg.h"
#if defined(OMR_GC_MODRON_CONCURRENT_MARK)
#include "objectdescription.h"
#include "omrgcconsts.h"
#include "omrport.h"
#include "ConcurrentSafepointCallback.hpp"
#include "EnvironmentBase.hpp"
#include "GCExtensionsBase.hpp"
class MM_ConcurrentGC;
class MM_MarkingScheme;
/**
* Provides language-specific support for marking.
*/
class MM_ConcurrentMarkingDelegate
{
/*
* Data members
*/
private:
protected:
GC_ObjectModel *_objectModel;
MM_ConcurrentGC *_collector;
MM_MarkingScheme *_markingScheme;
public:
/* This enum extends ConcurrentStatus with values in the exclusive range (CONCURRENT_ROOT_TRACING,
* CONCURRENT_TRACE_ONLY). ConcurrentStatus extensions allow the client language to define discrete
* units of work that can be executed in parallel by mutator threads when they are called upon to
* do some tracing work to pay an allocation tax. To extract this tax, ConcurrentGC will call
* MM_ConcurrentMarkingDelegate::collectRoots(..., concurrentStatus, ...) with the current tracing
* mode determined by the value returned by MM_ConcurrentMarkingDelegate::getNextTracingMode(). The
* thread that receives the collectRoots() call can check the concurrentStatus value to select and
* execute the appropriate unit of work.
*
* @see ConcurrentStatus (omrgcconsts.h)
* @see MM_ConcurrentMarkingDelegate::getNextTracingMode(uintptr_t)
* @see MM_ConcurrentMarkingDelegate::collectRoots(MM_EnvironmentBase *, uintptr_t, bool *, bool *)
*/
enum {
CONCURRENT_ROOT_TRACING1 = CONCURRENT_ROOT_TRACING + 1
};
/*
* Function members
*/
private:
protected:
public:
/**
* Initialize the delegate.
*
* @param env environment for calling thread
* @param collector pointer to MM_ConcurrentGC (concurrent collector)
* @return true if delegate initialized successfully
*/
bool initialize(MM_EnvironmentBase *env, MM_ConcurrentGC *collector);
/**
* In the case of Weak Consistency platforms we require this method to bring mutator threads to a safe point. A safe
* point is a point at which a GC may occur.
*
* @param[in] env The environment for the calling thread.
* @return An instance of a MM_ConcurrentSafepointCallback instance that can signal all mutator threads and cause them
* to synchronize at a safe point
* @see MM_ConcurrentSafepointCallback
*/
MMINLINE MM_ConcurrentSafepointCallback*
createSafepointCallback(MM_EnvironmentBase *env)
{
return MM_ConcurrentSafepointCallback::newInstance(env);
}
/**
* Concurrent marking component maintains a background helper thread to assist with concurrent marking
* tasks. The delegate may provide a specialized signal handler (and associated argument) to process
* signals raised from this thread.
*
* @param[out] signalHandlerArg receives (nullable) pointer to argument to be passed to signal handler when invoked
* @return a pointer to the signal handler function (or NULL if no signal handler)
*/
MMINLINE omrsig_handler_fn
getProtectedSignalHandler(void **signalHandlerArg)
{
*signalHandlerArg = NULL;
return NULL;
}
/**
* Test whether a GC can be started. Under some circumstances it may be desirable to circumvent continued
* concurrent marking and allow a GC to kick off immediately. In that case this method should return true
* and set the kick off reason.
*
* If this method returns false, the GC cycle may be started immediately. Otherwise, concurrent marking
* will kick off and the GC cycle will be deferred until concurrent marking completes.
*
* @param env the calling thread environment
* @param gcCode the GC code identifying the cause of the GC request
* @param[out] languageKickoffReason set this to the value to be reported as kickoff reson in verbose GC log
* @see J9MMCONSTANT_* (j9nonbuilderr.h) for gcCode values
* @return true if Kickoff can be forced
*/
MMINLINE bool
canForceConcurrentKickoff(MM_EnvironmentBase *env, uintptr_t gcCode, uintptr_t *languageKickoffReason)
{
if (NULL != languageKickoffReason) {
*languageKickoffReason = NO_LANGUAGE_KICKOFF_REASON;
}
return false;
}
/**
* Determine the next unit of tracing work that must be performed during root collection. Each distinct
* value returned represents a discrete unit of language-dependent root collection work. The executionMode
* parameter represents the current tracing mode, the returned valued with be the next tracing mode. The
* first call during a concurrent collection cycle will receive CONCURRENT_ROOT_TRACING as current tracing
* mode. When all language defined values have been returned, this method must return CONCURRENT_TRACE_ONLY
* to indicate that all root objects have been traced.
*
* @param executionMode the current (most recently completed) tracing mode
* @return the next language-defined tracing mode, or CONCURRENT_TRACE_ONLY if all language-defined roots have been traced
* @see MM_ConcurrentMarkingDelegate::collectRoots(MM_EnvironmentBase *, uintptr_t, bool *, bool *)
*/
MMINLINE uintptr_t
getNextTracingMode(uintptr_t executionMode)
{
uintptr_t nextExecutionMode = CONCURRENT_TRACE_ONLY;
switch (executionMode) {
case CONCURRENT_ROOT_TRACING:
nextExecutionMode = CONCURRENT_ROOT_TRACING1;
break;
case CONCURRENT_ROOT_TRACING1:
nextExecutionMode = CONCURRENT_TRACE_ONLY;
break;
default:
Assert_MM_unreachable();
}
return nextExecutionMode;
}
/**
* Trace language-defined roots. The concurrentStatus parameter receives the current tracing mode, which
* will be one of the language-defined tracing modes returned by getNextTracingMode().
*
* @param env the calling thread environment
* @param concurrentStatus the current tracing mode (language-defined ConcurrentStatus enum)
* @param[out] collectedRoots set this to true if all roots were collected
* @param[out] taxPaid set this to true if any roots were collected
* @see MM_ConcurrentMarkingDelegate::getNextTracingMode(uintptr_t)
*/
uintptr_t collectRoots(MM_EnvironmentBase *env, uintptr_t concurrentStatus, bool *collectedRoots, bool *paidTax);
/**
* Informative. This method will be called when concurrent initialization is complete and root tracing
* is about to begin.
*/
MMINLINE void concurrentInitializationComplete(MM_EnvironmentBase *env) { }
/**
* This method will be called to inform all mutator threads that they should trace their own
* thread structures and stacks to mark all thread-referenced and stack-referenced heap objects.
* Stack tracing can be performed only at safe points and this method may be required to request
* an asynchronous callback or otherwise defer this until the receiving thread can safely make
* the call.
*
* @see MM_ConcurrentMarkingDelegate::scanThreadRoots(MM_EnvironmentBase *
*/
MMINLINE void signalThreadsToTraceStacks(MM_EnvironmentBase *env) { }
/**
* Once concurrent tracing has started, mutator threads must activate the appropriate
* write barrier(s) to trigger whenever a reference-value field is updated, until a GC cycle is started.
*/
MMINLINE bool signalThreadsToActivateWriteBarrier(MM_EnvironmentBase *env)
{
return true;
}
/**
* Firstly acquire exclusive VM access, and then signal threads to activate WB.
*/
void acquireExclusiveVMAccessAndSignalThreadsToActivateWriteBarrier(MM_EnvironmentBase *env) {}
/**
* This can be used to optimize the concurrent write barrier(s) by conditioning threads to stop
* triggering barriers once a GC has started.
*/
MMINLINE void signalThreadsToDeactivateWriteBarrier(MM_EnvironmentBase *env) { }
/**
* Informational. Will be called when concurrent tracing has completed and card cleaning has started.
*/
MMINLINE void cardCleaningStarted(MM_EnvironmentBase *env) { }
/**
* This method is called during card cleaning for each object associated with an uncleaned,
* dirty card in the card table. No client actions are necessary but this method may be overridden
* if desired to hook into card cleaning.
*
* @param[in] env The environment for the calling thread.
* @param[in] objectPtr Reference to an object associated with an uncleaned, dirty card.
*/
MMINLINE void processItem(MM_EnvironmentBase *env, omrobjectptr_t objectPtr) { }
/**
* Scan a thread structure and stack frames for roots. Implementation must call
* MM_MarkingScheme::markObject(..) for each heap object reference found on the
* thread's stack or in thread structure.
*
* @param env the thread environment for the thread to be scanned
* @return true if the thread was scanned successfully
*/
MMINLINE bool
scanThreadRoots(MM_EnvironmentBase *env)
{
return true;
}
/**
* Flush any roots held in thread local buffers.
*
* @param env the thread environment for the thread to be flushed
* @return true if any data were flushed, false otherwise
*/
MMINLINE bool
flushThreadRoots(MM_EnvironmentBase *env)
{
return false;
}
/**
* Informational. Will be called if the concurrent collection cycle is aborted.
*/
MMINLINE void abortCollection(MM_EnvironmentBase *env) { }
/**
* Deprecated. Use this default implementation unless otherwise required.
*/
MMINLINE bool
startConcurrentScanning(MM_EnvironmentBase *env, uintptr_t *bytesTraced, bool *collectedRoots)
{
*bytesTraced = 0;
*collectedRoots = false;
return false;
}
MMINLINE bool
setupClassScanning(MM_EnvironmentBase *env)
{
return true;
}
/**
* Deprecated. Use this default implementation unless otherwise required.
*/
MMINLINE void concurrentScanningStarted(MM_EnvironmentBase *env, uintptr_t bytesTraced) { }
/**
* Deprecated. Use this default implementation unless otherwise required.
*/
MMINLINE bool
isConcurrentScanningComplete(MM_EnvironmentBase *env)
{
return true;
}
/**
* Deprecated. Use this default implementation unless otherwise required.
*/
MMINLINE uintptr_t
reportConcurrentScanningMode(MM_EnvironmentBase *env)
{
return 0;
}
/**
* Constructor.
*/
MMINLINE MM_ConcurrentMarkingDelegate()
: _objectModel(NULL)
, _markingScheme(NULL)
{ }
};
#endif /* defined(OMR_GC_MODRON_CONCURRENT_MARK) */
#endif /* CONCURRENTMARKINGDELEGATE_HPP_ */