Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/FinalizeListManager.hpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2019 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
/**
25
* @file
26
* @ingroup GC_Base
27
*/
28
29
#if !defined(FINALIZELISTMANAGER_HPP_)
30
#define FINALIZELISTMANAGER_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
#include "modron.h"
35
36
#if defined(J9VM_GC_FINALIZATION)
37
38
#include "ObjectAccessBarrier.hpp"
39
#include "EnvironmentBase.hpp"
40
#include "GCExtensions.hpp"
41
42
class MM_GCExtensions;
43
class GC_CheckFinalizableList;
44
45
typedef enum GC_FinalizeJobType {
46
FINALIZE_JOB_TYPE_OBJECT = 1,
47
FINALIZE_JOB_TYPE_REFERENCE = 2,
48
FINALIZE_JOB_TYPE_CLASSLOADER = 4
49
} GC_FinalizeJobType;
50
typedef struct GC_FinalizeJob {
51
GC_FinalizeJobType type;
52
union {
53
j9object_t object;
54
j9object_t reference;
55
J9ClassLoader *classLoader;
56
};
57
} GC_FinalizeJob;
58
59
/**
60
* Provides facility for the management of the finalizer queue
61
* @ingroup GC_Base
62
*/
63
class GC_FinalizeListManager : public MM_BaseVirtual
64
{
65
/* Data members */
66
private:
67
MM_GCExtensions *_extensions; /**< a cached pointer to the extensions structure */
68
omrthread_monitor_t _mutex; /**< mutex used to add / remove jobs from the finalize lists */
69
70
j9object_t _systemFinalizableObjects; /**< head of the linked list of objects allocated by the system classloader that need to be finalized */
71
UDATA _systemFinalizableObjectCount; /** count of the system finalizable object */
72
j9object_t _defaultFinalizableObjects; /**< head of the linked list of objects allocated by non system classloaders that need to be finalized */
73
UDATA _defaultFinalizableObjectCount; /** count of the default finalizable object */
74
j9object_t _referenceObjects; /**< head of the linked list of reference objects that need to be enqueued */
75
UDATA _referenceObjectCount; /** count of the reference object */
76
J9ClassLoader *_classLoaders; /**< head of the linked list of unloaded classloaders which have open native libraries */
77
UDATA _classLoaderCount; /** count of the class loaders */
78
protected:
79
public:
80
81
/* Methods */
82
private:
83
protected:
84
/**
85
* Pop the head of the System finalizable list
86
*
87
* @note Must be called while holding this class' _mutex
88
*
89
* @return the current head of the list, or NULL if the list is empty
90
*/
91
j9object_t popSystemFinalizableObject();
92
93
/**
94
* Pop the head of the default finalizable list
95
*
96
* @note Must be called while holding this class' _mutex
97
*
98
* @return the current head of the list, or NULL if the list is empty
99
*/
100
j9object_t popDefaultFinalizableObject();
101
102
/**
103
* Pop the head of the reference enqueue list
104
*
105
* @note Must be called while holding this class' _mutex
106
*
107
* @return the current head of the list, or NULL if the list is empty
108
*/
109
j9object_t popReferenceObject();
110
111
/**
112
* Pop the head of the classloader list
113
*
114
* @note Must be called while holding this class' _mutex
115
*
116
* @return the current head of the list, or NULL if the list is empty
117
*/
118
J9ClassLoader *popClassLoader();
119
120
public:
121
void lock() const;
122
void unlock() const;
123
124
/**
125
* Gets the number of jobs on the queue.
126
* @return The number of jobs on the queue.
127
*/
128
virtual UDATA getJobCount() const
129
{
130
lock();
131
UDATA count = _classLoaderCount + _defaultFinalizableObjectCount + _systemFinalizableObjectCount + _referenceObjectCount;
132
unlock();
133
return count;
134
}
135
136
virtual UDATA getSystemCount() {return _systemFinalizableObjectCount;}
137
virtual UDATA getDefaultCount() {return _defaultFinalizableObjectCount;}
138
MMINLINE UDATA getClassloaderCount() {return _classLoaderCount;}
139
MMINLINE UDATA getReferenceCount() {return _referenceObjectCount;}
140
141
static GC_FinalizeListManager *newInstance(MM_EnvironmentBase *env);
142
virtual void kill(MM_EnvironmentBase *env);
143
bool initialize();
144
void tearDown();
145
146
/**
147
* Add the list of objects to the system finalizable list
148
*
149
* @param head[in] head of the list to add
150
* @param tail[in] tail of the list to add
151
* @param count[in] number of objects in the list to add
152
*/
153
virtual void addSystemFinalizableObjects(j9object_t head, j9object_t tail, UDATA objectCount);
154
/**
155
* Add the list of objects to the default finalizable list
156
*
157
* @param head[in] head of the list to add
158
* @param tail[in] tail of the list to add
159
* @param count[in] number of objects in the list to add
160
*/
161
virtual void addDefaultFinalizableObjects(j9object_t head, j9object_t tail, UDATA objectCount);
162
/**
163
* Add the list of reference objects to the reference list
164
*
165
* @param head[in] head of the list to add
166
* @param tail[in] tail of the list to add
167
* @param count[in] number of objects in the list to add
168
*/
169
void addReferenceObjects(j9object_t head, j9object_t tail, UDATA objectCount);
170
/**
171
* Add the list of classloaders to the classloader list
172
*
173
* @param head[in] head of the list to add
174
* @param tail[in] tail of the list to add
175
* @param count[in] number of objects in the list to add
176
*/
177
void addClassLoaders(J9ClassLoader *head, J9ClassLoader *tail, UDATA Count);
178
179
/**
180
* Return the head of the system finalize list and set the list to NULL
181
*
182
* @return the current head of the list, or NULL if the list is empty
183
*/
184
j9object_t resetSystemFinalizableObjects()
185
{
186
j9object_t value = _systemFinalizableObjects;
187
_systemFinalizableObjects = NULL;
188
_systemFinalizableObjectCount = 0;
189
return value;
190
}
191
/**
192
* Return the head of the default finalize list and set the list to NULL
193
*
194
* @return the current head of the list, or NULL if the list is empty
195
*/
196
j9object_t resetDefaultFinalizableObjects()
197
{
198
j9object_t value = _defaultFinalizableObjects;
199
_defaultFinalizableObjects = NULL;
200
_defaultFinalizableObjectCount = 0;
201
return value;
202
}
203
/**
204
* Return the head of the reference enqueue list and set the list to NULL
205
*
206
* @return the current head of the list, or NULL if the list is empty
207
*/
208
j9object_t resetReferenceObjects()
209
{
210
j9object_t value = _referenceObjects;
211
_referenceObjects = NULL;
212
_referenceObjectCount = 0;
213
return value;
214
}
215
/**
216
* Peek the head of the System finalizable list
217
*
218
* @return the current head of the list, or NULL if the list is empty
219
*/
220
virtual j9object_t peekSystemFinalizableObject()
221
{
222
return _systemFinalizableObjects;
223
}
224
/**
225
* Peek the next System finalizable list object
226
*
227
* @param current[in] the current object to get the next from
228
*
229
* @return the next object of the list, or NULL
230
*/
231
virtual j9object_t peekNextSystemFinalizableObject(j9object_t current)
232
{
233
MM_ObjectAccessBarrier *barrier = _extensions->accessBarrier;
234
return barrier->getFinalizeLink(current);
235
}
236
/**
237
* Peek the head of the default finalizable list
238
*
239
* @return the current head of the list, or NULL if the list is empty
240
*/
241
virtual j9object_t peekDefaultFinalizableObject()
242
{
243
return _defaultFinalizableObjects;
244
}
245
/**
246
* Peek the next of the default finalizable list
247
*
248
* @param current[in] the current object to get the next from
249
*
250
* @return the next object of the list, or NULL
251
*/
252
virtual j9object_t peekNextDefaultFinalizableObject(j9object_t current)
253
{
254
MM_ObjectAccessBarrier *barrier = _extensions->accessBarrier;
255
return barrier->getFinalizeLink(current);
256
}
257
/**
258
* Peek the head of the reference list
259
*
260
* @return the current head of the list, or NULL if the list is empty
261
*/
262
MMINLINE j9object_t peekReferenceObject()
263
{
264
return _referenceObjects;
265
}
266
/**
267
* Peek the next of the reference list
268
*
269
* @param current[in] the current object to get the next from
270
*
271
* @return the next object of the list, or NULL
272
*/
273
MMINLINE j9object_t peekNextReferenceObject(j9object_t current)
274
{
275
MM_ObjectAccessBarrier *barrier = _extensions->accessBarrier;
276
return barrier->getReferenceLink(current);
277
}
278
/**
279
* Peek the head of the classloader list
280
*
281
* @return the current head of the list, or NULL if the list is empty
282
*/
283
MMINLINE J9ClassLoader *peekClassLoader()
284
{
285
return _classLoaders;
286
}
287
/**
288
* Peek the next of the classloader list
289
*
290
* @param current[in] the current classloader to get the next from
291
*
292
* @return the next classloader of the list, or NULL
293
*/
294
MMINLINE J9ClassLoader *peekNextClassLoader(J9ClassLoader *current)
295
{
296
return current->unloadLink;
297
}
298
299
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
300
/**
301
* Pop the first classloader on this off that has a non NULL gcThreadNotification
302
*
303
* @return classLoader the first class loader on the list with a non NULL gcThreadNotification or NULL
304
*/
305
J9ClassLoader *popRequiredClassLoaderForForcedClassLoaderUnload();
306
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
307
308
/**
309
* Determine if any of the lists of objects managed by the receiver are non-empty.
310
* @return true if any of the lists are non-empty, false if they are all empty
311
*/
312
MMINLINE bool isFinalizableObjectProcessingRequired()
313
{
314
bool result = false;
315
if (NULL != peekSystemFinalizableObject()) {
316
result = true;
317
} else if (NULL != peekDefaultFinalizableObject()) {
318
result = true;
319
} else if (NULL != peekReferenceObject()) {
320
result = true;
321
}
322
return result;
323
}
324
325
/**
326
* Pop the next job to process
327
*
328
* @note Must be called while holding this class' _mutex
329
*
330
* @return the next job or NULL
331
*/
332
virtual GC_FinalizeJob *consumeJob(J9VMThread *vmThread, GC_FinalizeJob * job);
333
334
335
/**
336
* Create a FinalizeListManager object
337
*/
338
GC_FinalizeListManager(MM_GCExtensions *extensions) :
339
_extensions(extensions)
340
,_mutex(NULL)
341
,_systemFinalizableObjects(NULL)
342
,_systemFinalizableObjectCount(0)
343
,_defaultFinalizableObjects(NULL)
344
,_defaultFinalizableObjectCount(0)
345
,_referenceObjects(NULL)
346
,_referenceObjectCount(0)
347
,_classLoaders(NULL)
348
,_classLoaderCount(0)
349
{
350
_typeId = __FUNCTION__;
351
};
352
353
/*
354
* Friends
355
*/
356
friend class GC_CheckFinalizableList; /* Temporary until DDR gccheck is updated to iterate multi-tenant finalizable queues */
357
};
358
#endif /* J9VM_GC_FINALIZATION */
359
#endif /* FINALIZELISTMANAGER_HPP_ */
360
361