Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/FinalizableReferenceBuffer.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(FINALIZABLEREFERENCEBUFFER_HPP_)
30
#define FINALIZABLEREFERENCEBUFFER_HPP_
31
32
#include "j9.h"
33
34
#include "ObjectAccessBarrier.hpp"
35
#include "FinalizeListManager.hpp"
36
37
class GC_FinalizableReferenceBuffer
38
{
39
private:
40
j9object_t _head; /**< the head of the linked list of reference objects */
41
j9object_t _tail; /**< the tail of the linked list of reference objects */
42
UDATA _count; /**< the number of buffered objects */
43
MM_GCExtensions * const _extensions; /**< a cached pointer to the extensions structure */
44
protected:
45
public:
46
47
private:
48
protected:
49
public:
50
/**
51
* Add the specified reference object to the buffer.
52
* @param env[in] the current thread
53
* @param object[in] the object to add
54
*/
55
void add(MM_EnvironmentBase* env, j9object_t object)
56
{
57
if (NULL == _head) {
58
Assert_MM_true(NULL == _tail);
59
Assert_MM_true(0 == _count);
60
_extensions->accessBarrier->setReferenceLink(object, NULL);
61
_head = object;
62
_tail = object;
63
_count = 1;
64
} else {
65
Assert_MM_true(NULL != _tail);
66
Assert_MM_true(0 != _count);
67
_extensions->accessBarrier->setReferenceLink(object, _head);
68
_head = object;
69
_count += 1;
70
}
71
}
72
73
void flush(MM_EnvironmentBase* env)
74
{
75
if (NULL != _head) {
76
Assert_MM_true(NULL != _tail);
77
Assert_MM_true(0 != _count);
78
GC_FinalizeListManager *finalizeListManager = _extensions->finalizeListManager;
79
finalizeListManager->addReferenceObjects(_head, _tail, _count);
80
_head = NULL;
81
_tail = NULL;
82
_count = 0;
83
}
84
}
85
86
/**
87
* Construct a new buffer.
88
* @param extensions[in] the GC extensions
89
*/
90
GC_FinalizableReferenceBuffer(MM_GCExtensions *extensions) :
91
_head(NULL)
92
,_tail(NULL)
93
,_count(0)
94
,_extensions(extensions)
95
{}
96
};
97
#endif /* FINALIZABLEREFERENCEBUFFER_HPP_ */
98
99