Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/ReferenceObjectBuffer.hpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 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
#ifndef REFERENCEOBJECTBUFFER_HPP_
24
#define REFERENCEOBJECTBUFFER_HPP_
25
26
#include "j9.h"
27
#include "j9cfg.h"
28
#include "BaseVirtual.hpp"
29
30
class MM_EnvironmentBase;
31
class MM_HeapRegionDescriptor;
32
class MM_ReferenceObjectList;
33
34
/**
35
* A per-thread buffer of reachable reference objects.
36
* The buffer is periodically flushed to the global list.
37
*/
38
class MM_ReferenceObjectBuffer : public MM_BaseVirtual
39
{
40
private:
41
protected:
42
j9object_t _head; /**< the head of the linked list of reference objects */
43
j9object_t _tail; /**< the tail of the linked list of reference objects */
44
MM_HeapRegionDescriptor* _region; /**< the region in which all buffered objects are located */
45
UDATA _referenceObjectType; /** the type of objects being buffered */
46
UDATA _objectCount; /**< the number of buffered objects */
47
const UDATA _maxObjectCount; /**< the maximum number of objects permitted before a forced flush */
48
public:
49
50
private:
51
52
/**
53
* Reset a flushed buffer to the empty state.
54
*/
55
void reset();
56
57
/**
58
* Determine the type (weak/soft/phantom) of the specified reference object.
59
* @param object[in] the object to examine
60
* @return one of J9AccClassReferenceWeak, J9AccClassReferenceSoft or J9AccClassReferencePhantom
61
*/
62
UDATA getReferenceObjectType(MM_EnvironmentBase* env, j9object_t object);
63
64
protected:
65
66
virtual bool initialize(MM_EnvironmentBase *env) = 0;
67
virtual void tearDown(MM_EnvironmentBase *env) = 0;
68
69
/**
70
* Flush the contents of the buffer to the appropriate global buffers.
71
* Subclasses must override.
72
* @param env[in] the current thread
73
*/
74
virtual void flushImpl(MM_EnvironmentBase* env) = 0;
75
76
public:
77
78
void kill(MM_EnvironmentBase *env);
79
80
/**
81
* Add the specified reference object to the buffer.
82
* @param env[in] the current thread
83
* @param object[in] the object to add
84
* @return true if the addition succeeded, false if the list must be flushed first
85
*/
86
void add(MM_EnvironmentBase* env, j9object_t object);
87
88
/**
89
* Flush the contents of the buffer to the appropriate global buffers.
90
* @param env[in] the current thread
91
*/
92
void flush(MM_EnvironmentBase* env);
93
94
/**
95
* Determine if the buffer is empty.
96
* @return true if there are no objects in the buffer
97
*/
98
bool isEmpty() { return NULL == _head; }
99
100
/**
101
* Construct a new buffer.
102
* @param maxObjectCount the maximum number of objects permitted before a forced flush
103
*/
104
MM_ReferenceObjectBuffer(UDATA maxObjectCount);
105
};
106
107
#endif /* REFERENCEOBJECTBUFFER_HPP_ */
108
109