Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_realtime/RealtimeGC.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2020 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_Metronome
26
*/
27
28
#if !defined(REALTIMEGC_HPP_)
29
#define REALTIMEGC_HPP_
30
31
#include "CycleState.hpp"
32
#include "GCExtensionsBase.hpp"
33
#include "GlobalCollector.hpp"
34
#include "HeapRegionList.hpp"
35
#include "IncrementalOverflow.hpp"
36
#include "MemorySubSpace.hpp"
37
#include "MemoryPoolSegregated.hpp"
38
#include "MetronomeDelegate.hpp"
39
#include "omrmodroncore.h"
40
#include "OMRVMInterface.hpp"
41
#include "Scheduler.hpp"
42
#include "WorkPacketsRealtime.hpp"
43
44
class MM_ParallelDispatcher;
45
class MM_EnvironmentBase;
46
class MM_MemorySubSpaceMetronome;
47
class MM_RealtimeMarkingScheme;
48
class MM_SweepSchemeRealtime;
49
class MM_FreeHeapRegionList;
50
51
/**
52
* @todo Provide class documentation
53
* @ingroup GC_Metronome
54
*/
55
class MM_RealtimeGC : public MM_GlobalCollector
56
{
57
/*
58
* Data members
59
*/
60
protected:
61
OMR_VM *_vm;
62
MM_GCExtensionsBase *_extensions;
63
64
private:
65
intptr_t _currentGCThreadPriority;
66
bool _previousCycleBelowTrigger;
67
bool _sweepingArraylets;
68
69
uintptr_t _gcPhase; /**< What gc phase are we currently in? */
70
71
MM_CycleState _cycleState; /**< Embedded cycle state to be used as the main cycle state for GC activity */
72
73
bool _moreTracingRequired; /**< Is used to decide if there needs to be another pass of the tracing loop. */
74
75
protected:
76
MM_RealtimeMarkingScheme *_markingScheme; /**< The marking scheme used to mark objects. */
77
MM_SweepSchemeRealtime *_sweepScheme; /**< The sweep scheme used to sweep objects for MemoryPoolSegregated. */
78
79
public:
80
MM_MemoryPoolSegregated *_memoryPool;
81
MM_MemorySubSpaceMetronome *_memorySubSpace;
82
bool _allowGrowth;
83
MM_OSInterface *_osInterface;
84
MM_Scheduler *_sched;
85
86
bool _fixHeapForWalk;
87
float _avgPercentFreeHeapAfterCollect;
88
MM_WorkPacketsRealtime *_workPackets;
89
90
bool _stopTracing;
91
MM_MetronomeDelegate _realtimeDelegate;
92
93
/*
94
* Function members
95
*/
96
private:
97
protected:
98
virtual void internalPreCollect(MM_EnvironmentBase *env, MM_MemorySubSpace *subSpace, MM_AllocateDescription *allocDescription, U_32 gcCode);
99
virtual void internalPostCollect(MM_EnvironmentBase *env, MM_MemorySubSpace *subSpace);
100
virtual bool internalGarbageCollect(MM_EnvironmentBase *env, MM_MemorySubSpace *subSpace, MM_AllocateDescription *allocDescription);
101
102
void reportMarkStart(MM_EnvironmentBase *env);
103
void reportMarkEnd(MM_EnvironmentBase *env);
104
void reportSweepStart(MM_EnvironmentBase *env);
105
void reportSweepEnd(MM_EnvironmentBase *env);
106
void reportGCStart(MM_EnvironmentBase *env);
107
void reportGCEnd(MM_EnvironmentBase *env);
108
109
public:
110
void mainSetupForGC(MM_EnvironmentBase *env);
111
void mainCleanupAfterGC(MM_EnvironmentBase *env);
112
void doAuxiliaryGCWork(MM_EnvironmentBase *env); /* Wake up finalizer thread. Discard segments freed by class unloading. */
113
void incrementalCollect(MM_EnvironmentRealtime *env);
114
115
virtual void *createSweepPoolState(MM_EnvironmentBase *env, MM_MemoryPool *memoryPool)
116
{
117
/*
118
* This function does nothing and is designed to have implementation of abstract in GlobalCollector,
119
* but must return non-NULL value to pass initialization - so, return "this"
120
*/
121
return this;
122
}
123
124
virtual void deleteSweepPoolState(MM_EnvironmentBase *env, void *sweepPoolState)
125
{
126
/*
127
* This function does nothing and is designed to have implementation of abstract in GlobalCollector
128
*/
129
}
130
131
void traceAll(MM_EnvironmentBase *env);
132
133
void clearGCStats();
134
void mergeGCStats(MM_EnvironmentBase *env);
135
136
void reportSyncGCStart(MM_EnvironmentBase *env, GCReason reason, uintptr_t reasonParameter);
137
void reportSyncGCEnd(MM_EnvironmentBase *env);
138
void reportGCCycleStart(MM_EnvironmentBase *env);
139
void reportGCCycleEnd(MM_EnvironmentBase *env);
140
void reportGCCycleFinalIncrementEnding(MM_EnvironmentBase *env);
141
142
void flushCachesForGC(MM_EnvironmentBase *env) {
143
/* we do not want to flush caches for each increment, unless there is a reason to walk the heap
144
* (for instance, fillFromOverflow requires heap be walkable) */
145
if (_workPackets->getIncrementalOverflowHandler()->isOverflowThisGCCycle()) {
146
GC_OMRVMInterface::flushCachesForGC(env);
147
}
148
}
149
150
/**
151
* helper function that determines if non-deterministic sweep is enabled
152
*/
153
bool shouldPerformNonDeterministicSweep()
154
{
155
return (_extensions->nonDeterministicSweep && !isCollectorSweepingArraylets());
156
}
157
158
virtual uintptr_t getVMStateID() { return OMRVMSTATE_GC_COLLECTOR_METRONOME; };
159
160
static MM_RealtimeGC *newInstance(MM_EnvironmentBase *env);
161
virtual void kill(MM_EnvironmentBase *env);
162
bool initialize(MM_EnvironmentBase *env);
163
void tearDown(MM_EnvironmentBase *env);
164
uintptr_t verbose(MM_EnvironmentBase *env);
165
uintptr_t gcCount() { return _extensions->globalGCStats.gcCount; }
166
167
MMINLINE bool isBarrierEnabled() { return (_gcPhase == GC_PHASE_ROOT || _gcPhase == GC_PHASE_TRACE || _gcPhase == GC_PHASE_CONCURRENT_TRACE); }
168
169
MMINLINE bool isCollectorIdle() { return (_gcPhase == GC_PHASE_IDLE); }
170
MMINLINE bool isCollectorRootMarking() { return (_gcPhase == GC_PHASE_ROOT); }
171
MMINLINE bool isCollectorTracing() { return (_gcPhase == GC_PHASE_TRACE); }
172
MMINLINE bool isCollectorUnloadingClassLoaders() { return (_gcPhase == GC_PHASE_UNLOADING_CLASS_LOADERS); }
173
MMINLINE bool isCollectorSweeping() { return (_gcPhase == GC_PHASE_SWEEP); }
174
MMINLINE bool isCollectorConcurrentTracing() { return (_gcPhase == GC_PHASE_CONCURRENT_TRACE); }
175
MMINLINE bool isCollectorConcurrentSweeping() { return (_gcPhase == GC_PHASE_CONCURRENT_SWEEP); }
176
MMINLINE bool isCollectorSweepingArraylets() { return _sweepingArraylets; }
177
MMINLINE bool isFixHeapForWalk() { return _fixHeapForWalk; }
178
179
MMINLINE void setCollectorIdle() { _gcPhase = GC_PHASE_IDLE; _sched->_gcPhaseSet |= GC_PHASE_IDLE; }
180
MMINLINE void setCollectorRootMarking() { _gcPhase = GC_PHASE_ROOT; _sched->_gcPhaseSet |= GC_PHASE_ROOT; }
181
MMINLINE void setCollectorTracing() { _gcPhase = GC_PHASE_TRACE; _sched->_gcPhaseSet |= GC_PHASE_TRACE; }
182
MMINLINE void setCollectorUnloadingClassLoaders() { _gcPhase = GC_PHASE_UNLOADING_CLASS_LOADERS; _sched->_gcPhaseSet |= GC_PHASE_UNLOADING_CLASS_LOADERS; }
183
MMINLINE void setCollectorSweeping() { _gcPhase = GC_PHASE_SWEEP; _sched->_gcPhaseSet |= GC_PHASE_SWEEP; }
184
MMINLINE void setCollectorConcurrentTracing() { _gcPhase = GC_PHASE_CONCURRENT_TRACE; _sched->_gcPhaseSet |= GC_PHASE_CONCURRENT_TRACE; }
185
MMINLINE void setCollectorConcurrentSweeping() { _gcPhase = GC_PHASE_CONCURRENT_SWEEP; _sched->_gcPhaseSet |= GC_PHASE_CONCURRENT_SWEEP; }
186
MMINLINE void setCollectorSweepingArraylets(bool sweepingArraylets) { _sweepingArraylets = sweepingArraylets; }
187
MMINLINE void setFixHeapForWalk(bool fixHeapForWalk) { _fixHeapForWalk = fixHeapForWalk; }
188
MMINLINE bool isPreviousCycleBelowTrigger() { return _previousCycleBelowTrigger; }
189
MMINLINE void setPreviousCycleBelowTrigger(bool previousCycleBelowTrigger) { _previousCycleBelowTrigger = previousCycleBelowTrigger; }
190
191
virtual void setupForGC(MM_EnvironmentBase *env);
192
virtual bool collectorStartup(MM_GCExtensionsBase* extensions);
193
virtual void collectorShutdown(MM_GCExtensionsBase *extensions);
194
void setMemoryPool(MM_MemoryPoolSegregated *memoryPool) { _memoryPool = memoryPool; }
195
void setMemorySubSpace(MM_MemorySubSpaceMetronome *memorySubSpace) { _memorySubSpace = memorySubSpace; }
196
197
virtual bool heapAddRange(MM_EnvironmentBase *env, MM_MemorySubSpace *subspace, uintptr_t size, void *lowAddress, void *highAddress);
198
virtual bool heapRemoveRange(
199
MM_EnvironmentBase *env, MM_MemorySubSpace *subspace, uintptr_t size, void *lowAddress, void *highAddress,
200
void *lowValidAddress, void *highValidAddress);
201
202
void workerSetupForGC(MM_EnvironmentBase *env);
203
void allThreadsAllocateUnmarked(MM_EnvironmentBase *env);
204
/**
205
* Helper function that flushes cached per-context full regions to the global region pool.
206
* Currently called before debug function showPages for calculating region pool stats.
207
*/
208
void flushCachedFullRegions(MM_EnvironmentBase *env);
209
virtual void setGCThreadPriority(OMR_VMThread *vmThread, uintptr_t priority);
210
/* Create the access barrier */
211
MM_WorkPacketsRealtime* allocateWorkPackets(MM_EnvironmentBase *env);
212
/* Create an EventTypeSpaceVersion object for TuningFork tracing */
213
void completeMarking(MM_EnvironmentRealtime* env);
214
virtual bool condYield(MM_EnvironmentBase *env, U_64 timeSlackNanoSec);
215
virtual bool shouldYield(MM_EnvironmentBase *env);
216
virtual void yield(MM_EnvironmentBase *env);
217
void enableWriteBarrier(MM_EnvironmentBase* env);
218
void disableWriteBarrier(MM_EnvironmentBase* env);
219
void enableDoubleBarrier(MM_EnvironmentBase* env);
220
void disableDoubleBarrierOnThread(MM_EnvironmentBase* env, OMR_VMThread *vmThread);
221
void disableDoubleBarrier(MM_EnvironmentBase* env);
222
223
void flushRememberedSet(MM_EnvironmentRealtime *env);
224
225
MM_RealtimeMarkingScheme *getMarkingScheme() { return _markingScheme; }
226
MM_SweepSchemeRealtime *getSweepScheme() { return _sweepScheme; }
227
MM_MetronomeDelegate *getRealtimeDelegate() { return &_realtimeDelegate; }
228
229
virtual bool isMarked(void *objectPtr);
230
231
MM_RealtimeGC(MM_EnvironmentBase *env)
232
: MM_GlobalCollector()
233
, _vm(env->getOmrVM())
234
, _extensions(env->getExtensions())
235
, _currentGCThreadPriority(-1)
236
, _previousCycleBelowTrigger(true)
237
, _sweepingArraylets(false)
238
, _cycleState()
239
, _moreTracingRequired(false)
240
, _markingScheme(NULL)
241
, _sweepScheme(NULL)
242
, _memoryPool(NULL)
243
, _memorySubSpace(NULL)
244
, _osInterface(NULL)
245
, _sched(NULL)
246
, _fixHeapForWalk(false)
247
, _avgPercentFreeHeapAfterCollect(0)
248
, _workPackets(NULL)
249
, _stopTracing(false)
250
, _realtimeDelegate(env)
251
{
252
_typeId = __FUNCTION__;
253
_realtimeDelegate._realtimeGC = this;
254
}
255
256
/*
257
* Friends
258
*/
259
friend class MM_MemoryPoolSegregated;
260
friend class MM_Scheduler;
261
friend class MM_MetronomeDelegate;
262
};
263
264
#endif /* REALTIMEGC_HPP_ */
265
266