-
Notifications
You must be signed in to change notification settings - Fork 752
/
Copy pathFlattenedArrayObjectScanner.hpp
256 lines (232 loc) · 10.6 KB
/
FlattenedArrayObjectScanner.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*******************************************************************************
* Copyright (c) 2020, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
#if !defined(FLATTENEDARRAYOBJECTSCANNER_HPP_)
#define FLATTENEDARRAYOBJECTSCANNER_HPP_
#include "j9.h"
#include "j9cfg.h"
#include "modron.h"
#include "objectdescription.h"
#include "ArrayObjectModel.hpp"
#include "GCExtensionsBase.hpp"
#include "HeadlessMixedObjectScanner.hpp"
#include "IndexableObjectScanner.hpp"
class GC_FlattenedArrayObjectScanner : public GC_HeadlessMixedObjectScanner
{
/* Data Members */
private:
MM_EnvironmentBase *_env;
uintptr_t _elementSizeWithoutPadding; /**< Size of the flattened element, without padding */
uintptr_t *_descriptionBasePtr; /**< Pointer to the description base */
#if defined(OMR_GC_LEAF_BITS)
uintptr_t *_leafBasePtr; /**< Pointer to the leaf description base */
#endif /* defined(OMR_GC_LEAF_BITS) */
GC_IndexableObjectScanner _indexableScanner; /**< Used to iterate the array by element */
protected:
public:
/* Methods */
private:
protected:
/**
* @param env The scanning thread environment
* @param arrayPtr pointer to the array to be processed
* @param basePtr pointer to the first contiguous array cell
* @param limitPtr pointer to end of last contiguous array cell
* @param scanPtr pointer to the array cell where scanning will start
* @param endPtr pointer to the array cell where scanning will stop
* @param scanMap The first scan map
* @param elementSize The size of each element, without padding
* @param elementStride The stride of each element, including element padding
* @param flags Scanning context flags
*/
MMINLINE GC_FlattenedArrayObjectScanner(
MM_EnvironmentBase *env
, omrobjectptr_t arrayPtr
, fomrobject_t *basePtr
, fomrobject_t *limitPtr
, fomrobject_t *scanPtr
, fomrobject_t *endPtr
, uintptr_t elementSize
, uintptr_t elementStride
, uintptr_t *descriptionBasePtr
#if defined(OMR_GC_LEAF_BITS)
, uintptr_t *leafBasePtr
#endif /* defined(OMR_GC_LEAF_BITS) */
, uintptr_t flags)
: GC_HeadlessMixedObjectScanner(env, scanPtr, elementSize, flags | GC_ObjectScanner::indexableObject)
, _env(env)
, _elementSizeWithoutPadding(elementSize)
, _descriptionBasePtr(descriptionBasePtr)
#if defined(OMR_GC_LEAF_BITS)
, _leafBasePtr(leafBasePtr)
#endif /* defined(OMR_GC_LEAF_BITS) */
/* Pass 0 for scanMap, as the indexable iterator does not use the scanMap */
, _indexableScanner(env, arrayPtr, basePtr, limitPtr, scanPtr, endPtr, 0, elementStride, flags)
{
_typeId = __FUNCTION__;
}
MMINLINE void
initialize(MM_EnvironmentBase *env)
{
#if defined(OMR_GC_LEAF_BITS)
GC_HeadlessMixedObjectScanner::initialize(env, _descriptionBasePtr, _leafBasePtr);
#else /* defined(OMR_GC_LEAF_BITS) */
GC_HeadlessMixedObjectScanner::initialize(env, _descriptionBasePtr);
#endif /* defined(OMR_GC_LEAF_BITS) */
_indexableScanner.initialize(env);
/* The HeadlessMixedObjectScanner will setNoMoreSlots() causing us
* to miss other elements of the array
*/
setMoreSlots();
}
public:
/**
* @param[in] env The scanning thread environment
* @param[in] objectPtr pointer to the array to be processed
* @param[in] allocSpace pointer to space within which the scanner should be instantiated (in-place)
* @param[in] flags Scanning context flags
* @param[in] splitAmount If >0, the number of elements to include for this scanner instance; if 0, include all elements
* @param[in] startIndex The index of the first element to scan
*/
MMINLINE static GC_FlattenedArrayObjectScanner *
newInstance(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, void *allocSpace, uintptr_t flags, uintptr_t splitAmount, uintptr_t startIndex = 0)
{
GC_FlattenedArrayObjectScanner *objectScanner = (GC_FlattenedArrayObjectScanner *)allocSpace;
GC_ArrayObjectModel *arrayObjectModel = &(env->getExtensions()->indexableObjectModel);
J9Class *clazzPtr = J9GC_J9OBJECT_CLAZZ(objectPtr, env);
J9ArrayClass *j9ArrayClass = (J9ArrayClass *) clazzPtr;
/* TODO are these always the same? */
Assert_MM_true(j9ArrayClass->componentType == j9ArrayClass->leafComponentType);
J9Class *elementClass = j9ArrayClass->componentType;
omrarrayptr_t arrayPtr = (omrarrayptr_t)objectPtr;
uintptr_t sizeInElements = arrayObjectModel->getSizeInElements(arrayPtr);
uintptr_t elementSize = J9_VALUETYPE_FLATTENED_SIZE(elementClass);
uintptr_t elementStride = J9ARRAYCLASS_GET_STRIDE(clazzPtr);
fomrobject_t *basePtr = (fomrobject_t *)arrayObjectModel->getDataPointerForContiguous(arrayPtr);
fomrobject_t *limitPtr = (fomrobject_t *)((uintptr_t)basePtr + (sizeInElements * elementStride));
fomrobject_t *scanPtr = (fomrobject_t *)((uintptr_t)basePtr + (startIndex * elementStride));
fomrobject_t *endPtr = limitPtr;
if (!GC_ObjectScanner::isIndexableObjectNoSplit(flags) && (splitAmount != 0)) {
Assert_MM_unreachable();
endPtr = (fomrobject_t *)((uintptr_t)scanPtr + (splitAmount * elementStride));
if (endPtr > limitPtr) {
endPtr = limitPtr;
}
}
uintptr_t *instanceDescription = elementClass->instanceDescription;
#if defined(OMR_GC_LEAF_BITS)
uintptr_t *leafDescription = elementClass->instanceLeafDescription;
new(objectScanner) GC_FlattenedArrayObjectScanner(env, objectPtr, basePtr, limitPtr, scanPtr, endPtr, elementSize, elementStride, instanceDescription, leafDescription, flags);
#else /* defined(OMR_GC_LEAF_BITS) */
new(objectScanner) GC_FlattenedArrayObjectScanner(env, objectPtr, basePtr, limitPtr, scanPtr, endPtr, elementSize, elementStride, instanceDescription, flags);
#endif /* defined(OMR_GC_LEAF_BITS) */
objectScanner->initialize(env);
if (0 != startIndex) {
objectScanner->clearHeadObjectScanner();
}
return objectScanner;
}
MMINLINE uintptr_t getBytesRemaining() { return sizeof(fomrobject_t) * (_endPtr - _scanPtr); }
/**
* @param env The scanning thread environment
* @param allocSpace pointer to space within which the scanner should be instantiated (in-place)
* @param splitAmount The maximum number of array elements to include
* @return Pointer to split scanner in allocSpace
*/
GC_IndexableObjectScanner *
splitTo(MM_EnvironmentBase *env, void *allocSpace, uintptr_t splitAmount)
{
Assert_MM_unimplemented();
return NULL;
}
/**
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
* increasing significance, and the least significant bit maps to the slot at the returned
* base pointer.
*
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
*/
virtual fomrobject_t *
getNextSlotMap(uintptr_t *slotMap, bool *hasNextSlotMap)
{
fomrobject_t *result = GC_HeadlessMixedObjectScanner::getNextSlotMap(slotMap, hasNextSlotMap);
/* Ignore hasNextSlotMap from HeadLess, we want to always report that there is another element */
*hasNextSlotMap = true;
if (result == NULL) {
/* No more slots in the current element, get the next element of the array */
result = _indexableScanner.nextIndexableElement();
if (result == NULL) {
/* There are no elements in the array */
*hasNextSlotMap = false;
} else {
_mapPtr = result;
_endPtr = (fomrobject_t *)((uintptr_t)_mapPtr + _elementSizeWithoutPadding);
GC_HeadlessMixedObjectScanner::initialize(_env, _descriptionBasePtr, _leafBasePtr);
/* GC_HeadlessMixedObjectScanner::initialize() may setNoMoreSlots(), so set it back to true.
* We must also return (hasNextSlotMap = true) on top of this
*/
setMoreSlots();
}
}
return result;
}
#if defined(OMR_GC_LEAF_BITS)
/**
* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The
* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of
* increasing significance, and the least significant bit maps to the slot at the returned
* base pointer.
*
* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer
* @param[out] leafMap the leaf bit map for the slots contiguous with the returned base pointer
* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last
* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots
*/
virtual fomrobject_t *
getNextSlotMap(uintptr_t *slotMap, uintptr_t *leafMap, bool *hasNextSlotMap)
{
fomrobject_t *result = GC_HeadlessMixedObjectScanner::getNextSlotMap(slotMap, leafMap, hasNextSlotMap);
/* Ignore hasNextSlotMap from HeadLess, we want to always report that there is another element */
*hasNextSlotMap = true;
if (result == NULL) {
/* No more slots in the current element, get the next element of the array */
result = _indexableScanner.nextIndexableElement();
if (result == NULL) {
/* There are no elements in the array */
*hasNextSlotMap = false;
} else {
_mapPtr = result;
_endPtr = (fomrobject_t *)((uintptr_t)_mapPtr + _elementSizeWithoutPadding);
GC_HeadlessMixedObjectScanner::initialize(_env, _descriptionBasePtr, _leafBasePtr);
/* GC_HeadlessMixedObjectScanner::initialize() may setNoMoreSlots(), so set it back to true.
* We must also return (hasNextSlotMap = true) on top of this
*/
setMoreSlots();
}
}
return result;
}
#endif /* defined(OMR_GC_LEAF_BITS) */
};
#endif /* FLATTENEDARRAYOBJECTSCANNER_HPP_ */