Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_api/HeapRootScanner.hpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2021 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
#if !defined(HEAPROOTSCANNER_HPP_)
23
#define HEAPROOTSCANNER_HPP_
24
25
#include "j9.h"
26
#include "j9cfg.h"
27
28
#include "BaseVirtual.hpp"
29
30
#include "Debug.hpp"
31
#include "EnvironmentBase.hpp"
32
#include "GCExtensions.hpp"
33
#include "HeapIteratorAPI.h"
34
#include "ModronTypes.hpp"
35
36
class MM_HeapRootScanner : public MM_BaseVirtual
37
{
38
protected:
39
MM_GCExtensions *_extensions;
40
J9JavaVM *_javaVM;
41
42
bool _stringTableAsRoot; /**< Treat the string table as a hard root */
43
bool _singleThread; /**< Should the iterator operate in single threaded mode */
44
45
bool _nurseryReferencesOnly; /**< Should the iterator only scan structures that currently contain nursery references */
46
bool _nurseryReferencesPossibly; /**< Should the iterator only scan structures that may contain nursery references */
47
bool _includeStackFrameClassReferences; /**< Should the iterator include Classes which have a method running on the stack */
48
#if defined(J9VM_GC_MODRON_SCAVENGER)
49
bool _includeRememberedSetReferences; /**< Should the iterator include references in the Remembered Set (if applicable) */
50
#endif /* J9VM_GC_MODRON_SCAVENGER */
51
bool _classDataAsRoots; /**< Should all classes (and class loaders) be treated as roots. Default true, should set to false when class unloading */
52
bool _includeJVMTIObjectTagTables; /**< Should the iterator include the JVMTIObjectTagTables. Default true, should set to false when doing JVMTI object walks */
53
bool _trackVisibleStackFrameDepth; /**< Should the stack walker be told to track the visible frame depth. Default false, should set to true when doing JVMTI walks that report stack slots */
54
55
RootScannerEntity _scanningEntity; /**< The root scanner entity that is currently being scanned. Defaults to RootScannerEntity_None. */
56
RootScannerEntity _lastScannedEntity; /**< The root scanner entity that was last scanned. Defaults to RootScannerEntity_None. */
57
58
RootScannerEntityReachability _scanningEntityReachability;/**< Reachability of the root scanner entity that is currently being scanned. */
59
60
/**
61
* Sets the currently scanned root entity to scanningEntity. This is mainly for
62
* debug purposes.
63
* @param scanningEntity The entity for which scanning has begun.
64
*/
65
MMINLINE void
66
reportScanningStarted(RootScannerEntity scanningEntity)
67
{
68
/* Ensures reportScanningEnded was called previously. */
69
assume0(RootScannerEntity_None == _scanningEntity);
70
_scanningEntity = scanningEntity;
71
}
72
73
/**
74
* Sets the currently scanned root entity to scanningEntity. This is mainly for
75
* debug purposes.
76
* @param scanningEntity The entity for which scanning has begun.
77
*/
78
MMINLINE void
79
setReachability(RootScannerEntityReachability reachability)
80
{
81
_scanningEntityReachability = reachability;
82
}
83
84
/**
85
* Sets the currently scanned root entity to None and sets the last scanned root
86
* entity to scannedEntity. This is mainly for debug purposes.
87
* @param scannedEntity The entity for which scanning has ended.
88
*/
89
MMINLINE void
90
reportScanningEnded(RootScannerEntity scannedEntity)
91
{
92
/* Ensures scanning ended for the currently scanned entity. */
93
assume0(_scanningEntity == scannedEntity);
94
_lastScannedEntity = _scanningEntity;
95
_scanningEntity = RootScannerEntity_None;
96
_scanningEntityReachability = RootScannerEntityReachability_None;
97
}
98
99
public:
100
MM_HeapRootScanner(J9JavaVM* javaVM, bool singleThread = false) :
101
_extensions(MM_GCExtensions::getExtensions(javaVM)),
102
_javaVM(javaVM),
103
_stringTableAsRoot(true),
104
_singleThread(singleThread),
105
_nurseryReferencesOnly(false),
106
_nurseryReferencesPossibly(false),
107
_includeStackFrameClassReferences(true),
108
#if defined(J9VM_GC_MODRON_SCAVENGER)
109
_includeRememberedSetReferences(false),
110
#endif /* J9VM_GC_MODRON_SCAVENGER */
111
_classDataAsRoots(true),
112
_includeJVMTIObjectTagTables(true),
113
_trackVisibleStackFrameDepth(false),
114
_scanningEntity(RootScannerEntity_None),
115
_lastScannedEntity(RootScannerEntity_None)
116
{
117
_typeId = __FUNCTION__;
118
}
119
120
#if defined(J9VM_GC_MODRON_SCAVENGER)
121
/** Set whether the iterator will only scan structures which contain nursery references */
122
void setNurseryReferencesOnly(bool nurseryReferencesOnly) {
123
_nurseryReferencesOnly = nurseryReferencesOnly;
124
}
125
126
/** Set whether the iterator will only scan structures which may contain nursery references */
127
void setNurseryReferencesPossibly(bool nurseryReferencesPossibly) {
128
_nurseryReferencesPossibly = nurseryReferencesPossibly;
129
}
130
131
/** Set whether the iterator will scan the remembered set references (if applicable to the scan type) */
132
void setIncludeRememberedSetReferences(bool includeRememberedSetReferences) {
133
_includeRememberedSetReferences = includeRememberedSetReferences;
134
}
135
#endif /* J9VM_GC_MODRON_SCAVENGER */
136
137
/** Set whether the iterator will scan stack frames for the classes of running methods */
138
void setIncludeStackFrameClassReferences(bool includeStackFrameClassReferences) {
139
_includeStackFrameClassReferences = includeStackFrameClassReferences;
140
}
141
142
#if defined(J9VM_OPT_JVMTI)
143
/** Set whether the iterator will scan the JVMTIObjectTagTables (if applicable to the scan type) */
144
void setIncludeJVMTIObjectTagTables(bool includeJVMTIObjectTagTables) {
145
_includeJVMTIObjectTagTables = includeJVMTIObjectTagTables;
146
}
147
#endif /* J9VM_OPT_JVMTI */
148
149
/** Set whether the iterator will scan the JVMTIObjectTagTables (if applicable to the scan type) */
150
void setTrackVisibleStackFrameDepth(bool trackVisibleStackFrameDepth) {
151
_trackVisibleStackFrameDepth = trackVisibleStackFrameDepth;
152
}
153
154
/** General object slot handler to be reimplemented by specializing class. This handler is called for every reference to a J9Object. */
155
virtual void doSlot(J9Object** slotPtr) = 0;
156
157
/** General class slot handler to be reimplemented by specializing class. This handler is called for every reference to a J9Class. */
158
virtual void doClassSlot(J9Class *classPtr);
159
160
/** General class handler to be reimplemented by specializing class. This handler is called once per class. */
161
virtual void doClass(J9Class *clazz) = 0;
162
163
virtual void doObject(J9Object* slotPtr) = 0;
164
165
#if defined(J9VM_GC_MODRON_SCAVENGER)
166
virtual void scanRememberedSet();
167
#endif /* J9VM_GC_MODRON_SCAVENGER */
168
169
virtual void scanClasses();
170
virtual void scanVMClassSlots();
171
172
virtual bool scanOneThread(J9VMThread* walkThread);
173
174
virtual void scanClassLoaders();
175
virtual void scanThreads();
176
#if defined(J9VM_GC_FINALIZATION)
177
void scanFinalizableObjects();
178
virtual void scanUnfinalizedObjects();
179
#endif /* J9VM_GC_FINALIZATION */
180
/**
181
* @todo Provide function documentation
182
*
183
* @NOTE this code is not thread safe and assumes it is called in a single threaded
184
* manner.
185
*
186
* @NOTE this can only be used as a READ-ONLY version of the ownableSynchronizerObjectList.
187
* If you need to modify elements with-in the list you will need to provide your own functionality.
188
* See MM_MarkingScheme::scanOwnableSynchronizerObjects(MM_EnvironmentStandard *env) as an example
189
* which modifies elements with-in the list.
190
*/
191
virtual void scanOwnableSynchronizerObjects();
192
void scanStringTable();
193
void scanJNIGlobalReferences();
194
void scanJNIWeakGlobalReferences();
195
196
virtual void scanMonitorReferences();
197
198
#if defined(J9VM_OPT_JVMTI)
199
void scanJVMTIObjectTagTables();
200
#endif /* J9VM_OPT_JVMTI */
201
202
virtual void doClassLoader(J9ClassLoader *classLoader);
203
204
#if defined(J9VM_GC_FINALIZATION)
205
virtual void doFinalizableObject(J9Object *objectPtr);
206
virtual void doUnfinalizedObject(J9Object *objectPtr);
207
#endif /* J9VM_GC_FINALIZATION */
208
/**
209
* @todo Provide function documentation
210
*/
211
virtual void doOwnableSynchronizerObject(J9Object *objectPtr);
212
213
virtual void doMonitorReference(J9ObjectMonitor *objectMonitor, GC_HashTableIterator *monitorReferenceIterator);
214
215
virtual void doJNIWeakGlobalReference(J9Object **slotPtr);
216
virtual void doJNIGlobalReferenceSlot(J9Object **slotPtr, GC_JNIGlobalReferenceIterator *jniGlobalReferenceIterator);
217
218
#if defined(J9VM_GC_MODRON_SCAVENGER)
219
virtual void doRememberedSetSlot(J9Object **slotPtr, GC_RememberedSetSlotIterator *rememberedSetSlotIterator);
220
#endif /* defined(J9VM_GC_MODRON_SCAVENGER) */
221
222
#if defined(J9VM_OPT_JVMTI)
223
virtual void doJVMTIObjectTagSlot(J9Object **slotPtr, GC_JVMTIObjectTagTableIterator *objectTagTableIterator);
224
#endif /* J9VM_OPT_JVMTI */
225
226
virtual void doStringTableSlot(J9Object **slotPtr, GC_StringTableIterator *stringTableIterator);
227
virtual void doVMClassSlot(J9Class *classPtr);
228
virtual void doVMThreadSlot(J9Object **slotPtr, GC_VMThreadIterator *vmThreadIterator);
229
};
230
231
232
#endif /* HEAPROOTSCANNER_HPP_ */
233
234