Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/HeadlessMixedObjectScanner.hpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2019, 2020 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
#if !defined(HEADLESSMIXEDOBJECTSCANNER_HPP_)
24
#define HEADLESSMIXEDOBJECTSCANNER_HPP_
25
26
#include "j9.h"
27
28
#include "ObjectScanner.hpp"
29
30
class GC_HeadlessMixedObjectScanner : public GC_ObjectScanner
31
{
32
/* Data Members */
33
private:
34
35
protected:
36
fomrobject_t *_endPtr; /**< end scan pointer */
37
fomrobject_t *_mapPtr; /**< pointer to first slot in current scan segment */
38
uintptr_t *_descriptionPtr; /**< current description pointer */
39
#if defined(J9VM_GC_LEAF_BITS)
40
uintptr_t *_leafPtr; /**< current leaf description pointer */
41
#endif /* J9VM_GC_LEAF_BITS */
42
43
public:
44
45
/* Member Functions */
46
private:
47
48
protected:
49
50
public:
51
52
/**
53
* @param env The scanning thread environment
54
* @param scanPtr Pointer to the start of the object
55
* @param size The instance size
56
* @param flags Scanning context flags
57
*/
58
MMINLINE GC_HeadlessMixedObjectScanner(MM_EnvironmentBase *env, fomrobject_t *scanPtr, uintptr_t size, uintptr_t flags)
59
: GC_ObjectScanner(env, scanPtr, 0, flags)
60
, _endPtr((fomrobject_t *)((uintptr_t)scanPtr + size))
61
, _mapPtr(scanPtr)
62
, _descriptionPtr(NULL)
63
#if defined(J9VM_GC_LEAF_BITS)
64
, _leafPtr(NULL)
65
#endif /* J9VM_GC_LEAF_BITS */
66
{
67
_typeId = __FUNCTION__;
68
}
69
70
MMINLINE void
71
initialize(MM_EnvironmentBase *env, uintptr_t *descriptionPtr, uintptr_t *leafPtr)
72
{
73
GC_ObjectScanner::initialize(env);
74
75
/* Initialize the slot map from description bits */
76
_scanMap = (uintptr_t)descriptionPtr;
77
#if defined(J9VM_GC_LEAF_BITS)
78
_leafMap = (uintptr_t)leafPtr;
79
#endif /* J9VM_GC_LEAF_BITS */
80
if (_scanMap & 1) {
81
_scanMap >>= 1;
82
_descriptionPtr = NULL;
83
#if defined(J9VM_GC_LEAF_BITS)
84
_leafMap >>= 1;
85
_leafPtr = NULL;
86
#endif /* J9VM_GC_LEAF_BITS */
87
setNoMoreSlots();
88
} else {
89
_descriptionPtr = (uintptr_t *)_scanMap;
90
_scanMap = *_descriptionPtr;
91
_descriptionPtr += 1;
92
#if defined(J9VM_GC_LEAF_BITS)
93
_leafPtr = (uintptr_t *)_leafMap;
94
_leafMap = *_leafPtr;
95
_leafPtr += 1;
96
#endif /* J9VM_GC_LEAF_BITS */
97
}
98
}
99
100
MMINLINE void
101
initialize(MM_EnvironmentBase *env, uintptr_t *descriptionPtr)
102
{
103
initialize(env, descriptionPtr, NULL);
104
}
105
106
MMINLINE uintptr_t getBytesRemaining() { return (uintptr_t)_endPtr - (uintptr_t)_scanPtr; }
107
108
/**
109
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
110
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
111
* increasing significance, and the least significant bit maps to the slot at the returned
112
* base pointer.
113
*
114
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
115
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
116
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
117
*/
118
virtual fomrobject_t *
119
getNextSlotMap(uintptr_t *slotMap, bool *hasNextSlotMap)
120
{
121
bool const compressed = compressObjectReferences();
122
fomrobject_t *result = NULL;
123
*slotMap = 0;
124
*hasNextSlotMap = false;
125
_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);
126
while (_endPtr > _mapPtr) {
127
*slotMap = *_descriptionPtr;
128
_descriptionPtr += 1;
129
if (0 != *slotMap) {
130
*hasNextSlotMap = _bitsPerScanMap < GC_SlotObject::subtractSlotAddresses(_endPtr, _mapPtr, compressed);
131
result = _mapPtr;
132
break;
133
}
134
_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);
135
}
136
return result;
137
}
138
139
#if defined(J9VM_GC_LEAF_BITS)
140
/**
141
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
142
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
143
* increasing significance, and the least significant bit maps to the slot at the returned
144
* base pointer.
145
*
146
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
147
* @param[out] leafMap the leaf bit map for the slots contiguous with the returned base pointer
148
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
149
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
150
*/
151
virtual fomrobject_t *
152
getNextSlotMap(uintptr_t *slotMap, uintptr_t *leafMap, bool *hasNextSlotMap)
153
{
154
bool const compressed = compressObjectReferences();
155
fomrobject_t *result = NULL;
156
*slotMap = 0;
157
*leafMap = 0;
158
*hasNextSlotMap = false;
159
_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);
160
while (_endPtr > _mapPtr) {
161
*slotMap = *_descriptionPtr;
162
_descriptionPtr += 1;
163
*leafMap = *_leafPtr;
164
_leafPtr += 1;
165
if (0 != *slotMap) {
166
*hasNextSlotMap = _bitsPerScanMap < GC_SlotObject::subtractSlotAddresses(_endPtr, _mapPtr, compressed);
167
result = _mapPtr;
168
break;
169
}
170
_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);
171
}
172
return result;
173
}
174
#endif /* J9VM_GC_LEAF_BITS */
175
};
176
177
#endif /* HEADLESSMIXEDOBJECTSCANNER_HPP_ */
178