Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/FlattenedContiguousArrayIterator.hpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2021 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
/**
24
* @file
25
* @ingroup GC_Structs
26
*/
27
28
#if !defined(FLATTENEDCONTIGUOUSARRAYITERATOR_HPP_)
29
#define FLATTENEDCONTIGUOUSARRAYITERATOR_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
34
#include "ArrayObjectModel.hpp"
35
#include "GCExtensionsBase.hpp"
36
#include "ObjectIteratorState.hpp"
37
#include "SlotObject.hpp"
38
#include "MixedObjectIterator.hpp"
39
40
class GC_FlattenedContiguousArrayIterator
41
{
42
private:
43
J9IndexableObject *_arrayPtr; /**< pointer to the array object being iterated */
44
GC_MixedObjectIterator _mixedObjectIterator; /**< Object iterator which iterates over field of each element */
45
uintptr_t _elementStride; /**< Size of each element, including padding */
46
fj9object_t *_basePtr; /**< pointer to the first array slot, where element 0 is */
47
fj9object_t *_scanPtr; /**< pointer to the current array element's first slot */
48
fj9object_t *_endPtr; /**< pointer to the array slot where the iteration will terminate */
49
J9Class *_elementClass; /**< Pointer to class of the elements in the flattened array */
50
protected:
51
OMR_VM *_omrVM;
52
public:
53
MMINLINE GC_SlotObject *nextSlot()
54
{
55
/* If no more object slots to scan, returns NULL */
56
GC_SlotObject *result = NULL;
57
if (_scanPtr < _endPtr) {
58
result = _mixedObjectIterator.nextSlot();
59
if (NULL == result) {
60
_scanPtr = (fj9object_t *)(_elementStride + (uintptr_t)_scanPtr);
61
if (_scanPtr < _endPtr) {
62
/* mixedObjectIterator reached end of element. Move the iterator to the beginning of the next element */
63
_mixedObjectIterator.initialize(_omrVM, _elementClass, _scanPtr);
64
result = _mixedObjectIterator.nextSlot();
65
}
66
}
67
}
68
return result;
69
}
70
71
MMINLINE void initialize(J9Object *objectPtr)
72
{
73
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_omrVM);
74
GC_ArrayObjectModel *arrayObjectModel = &(extensions->indexableObjectModel);
75
J9Class *clazzPtr = J9GC_J9OBJECT_CLAZZ(objectPtr, extensions);
76
77
_elementStride = J9ARRAYCLASS_GET_STRIDE(clazzPtr);
78
_basePtr = (fomrobject_t *)arrayObjectModel->getDataPointerForContiguous(_arrayPtr);
79
_scanPtr = _basePtr;
80
_endPtr = (fomrobject_t *)((uintptr_t)_basePtr + (arrayObjectModel->getSizeInElements(_arrayPtr) * _elementStride));
81
_elementClass = ((J9ArrayClass *) clazzPtr)->componentType;
82
83
if (_scanPtr < _endPtr) {
84
_mixedObjectIterator.initialize(_omrVM, _elementClass, _scanPtr);
85
}
86
}
87
88
/**
89
* Gets the current slot's array index.
90
* @return slot number (or zero based array index) of the last call to nextSlot.
91
*/
92
MMINLINE UDATA getIndex()
93
{
94
return ((uintptr_t)_scanPtr - (uintptr_t)_basePtr) / _elementStride;
95
}
96
97
/**
98
* Sets the current slot's array index
99
* @param[in] index index to set scan index to
100
*/
101
MMINLINE void setIndex(UDATA index) {
102
_scanPtr = (fj9object_t *)((uintptr_t)_basePtr + (index * _elementStride));
103
}
104
105
/**
106
* Restores the iterator state into this class
107
* @param[in] objectIteratorState partially scanned object iterator state
108
*/
109
MMINLINE void restore(GC_ObjectIteratorState *objectIteratorState)
110
{
111
_scanPtr = objectIteratorState->_scanPtr;
112
_endPtr = objectIteratorState->_endPtr;
113
}
114
115
/**
116
* Saves the partially scanned state of this class
117
* @param[in] objectIteratorState where to store the state
118
*/
119
MMINLINE void save(GC_ObjectIteratorState *objectIteratorState)
120
{
121
objectIteratorState->_scanPtr = _scanPtr;
122
objectIteratorState->_endPtr = _endPtr;
123
}
124
125
MMINLINE J9Object *getObject()
126
{
127
return (J9Object *)_arrayPtr;
128
}
129
130
GC_FlattenedContiguousArrayIterator(OMR_VM *omrVM, J9Object *objectPtr)
131
: _arrayPtr((J9IndexableObject *)objectPtr)
132
, _mixedObjectIterator(omrVM)
133
, _elementStride(0)
134
, _basePtr(NULL)
135
, _scanPtr(NULL)
136
, _endPtr(NULL)
137
, _elementClass(NULL)
138
, _omrVM(omrVM)
139
{
140
initialize(objectPtr);
141
}
142
};
143
144
#endif /* FLATTENEDCONTIGUOUSARRAYITERATOR_HPP_ */
145
146