Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/FinalizableObjectBuffer.hpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2014 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(FINALIZABLEOBJECTBUFFER_HPP_)
30
#define FINALIZABLEOBJECTBUFFER_HPP_
31
32
#include "j9.h"
33
34
#include "FinalizeListManager.hpp"
35
#include "ObjectAccessBarrier.hpp"
36
37
class GC_FinalizableObjectBuffer
38
{
39
private:
40
j9object_t _systemHead; /**< the head of the linked list of finalizable objects loaded by the system class loader */
41
j9object_t _systemTail; /**< the tail of the linked list of unfinalized objects loaded by the system class loader */
42
UDATA _systemObjectCount; /**< the number of buffered objects loaded by the system class loader */
43
j9object_t _defaultHead; /**< the head of the linked list of unfinalized objects not loaded by the system class loader */
44
j9object_t _defaultTail; /**< the tail of the linked list of unfinalized objects not loaded by the system class loader */
45
UDATA _defaultObjectCount; /**< the number of buffered objects not loaded by the system class loader */
46
MM_GCExtensions * const _extensions; /**< a cached pointer to the extensions structure */
47
J9ClassLoader* const _systemClassLoader;
48
protected:
49
public:
50
51
private:
52
void addSystemObject(MM_EnvironmentBase* env, j9object_t object) {
53
if (NULL == _systemHead) {
54
Assert_MM_true(NULL == _systemTail);
55
Assert_MM_true(0 == _systemObjectCount);
56
_extensions->accessBarrier->setFinalizeLink(object, NULL);
57
_systemHead = object;
58
_systemTail = object;
59
_systemObjectCount = 1;
60
} else {
61
Assert_MM_true(NULL != _systemTail);
62
Assert_MM_true(0 != _systemObjectCount);
63
_extensions->accessBarrier->setFinalizeLink(object, _systemHead);
64
_systemHead = object;
65
_systemObjectCount += 1;
66
}
67
}
68
69
void addDefaultObject(MM_EnvironmentBase* env, j9object_t object) {
70
if (NULL == _defaultHead) {
71
_extensions->accessBarrier->setFinalizeLink(object, NULL);
72
_defaultHead = object;
73
_defaultTail = object;
74
_defaultObjectCount = 1;
75
} else {
76
_extensions->accessBarrier->setFinalizeLink(object, _defaultHead);
77
_defaultHead = object;
78
_defaultObjectCount += 1;
79
}
80
}
81
protected:
82
public:
83
/**
84
* Add the specified unfinalized object to the buffer.
85
* @param env[in] the current thread
86
* @param object[in] the object to add
87
*/
88
virtual void add(MM_EnvironmentBase* env, j9object_t object)
89
{
90
if (_systemClassLoader == (J9OBJECT_CLAZZ((J9VMThread *)env->getOmrVMThread()->_language_vmthread, object)->classLoader)) {
91
addSystemObject(env, object);
92
} else {
93
addDefaultObject(env, object);
94
}
95
}
96
97
void flush(MM_EnvironmentBase* env)
98
{
99
GC_FinalizeListManager *finalizeListManager = _extensions->finalizeListManager;
100
if (NULL != _systemHead) {
101
finalizeListManager->addSystemFinalizableObjects(_systemHead, _systemTail, _systemObjectCount);
102
_systemHead = NULL;
103
_systemTail = NULL;
104
_systemObjectCount = 0;
105
}
106
if (NULL != _defaultHead) {
107
finalizeListManager->addDefaultFinalizableObjects(_defaultHead, _defaultTail, _defaultObjectCount);
108
_defaultHead = NULL;
109
_defaultTail = NULL;
110
_defaultObjectCount = 0;
111
}
112
}
113
114
/**
115
* Construct a new buffer.
116
* @param extensions[in] the GC extensions
117
*/
118
GC_FinalizableObjectBuffer(MM_GCExtensions *extensions) :
119
_systemHead(NULL)
120
,_systemTail(NULL)
121
,_systemObjectCount(0)
122
,_defaultHead(NULL)
123
,_defaultTail(NULL)
124
,_defaultObjectCount(0)
125
,_extensions(extensions)
126
,_systemClassLoader(((J9JavaVM *)extensions->getOmrVM()->_language_vm)->systemClassLoader)
127
{}
128
};
129
#endif /* FINALIZABLEOBJECTBUFFER_HPP_ */
130
131