Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/PointerArrayIterator.hpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2021 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_Structs
27
*/
28
29
#if !defined(POINTERARRAYITERATOR_HPP_)
30
#define POINTERARRAYITERATOR_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
#include "ModronAssertions.h"
35
36
#include "ArrayObjectModel.hpp"
37
#include "Bits.hpp"
38
#include "GCExtensionsBase.hpp"
39
#include "ObjectIteratorState.hpp"
40
#include "PointerArrayletIterator.hpp"
41
#include "PointerContiguousArrayIterator.hpp"
42
#include "SlotObject.hpp"
43
44
/**
45
* Iterate over all slots in a pointer array which contain an object reference
46
* @ingroup GC_Structs
47
*/
48
class GC_PointerArrayIterator
49
{
50
private:
51
bool _contiguous;
52
GC_PointerContiguousArrayIterator _contiguousArrayIterator;
53
GC_PointerArrayletIterator _pointerArrayletIterator; /**< Iterator instance specific for Contiguous (standard) array */
54
55
protected:
56
public:
57
/**
58
* @param objectPtr the array object to be processed
59
*/
60
GC_PointerArrayIterator(J9JavaVM *javaVM, J9Object *objectPtr)
61
: _contiguousArrayIterator(javaVM->omrVM)
62
, _pointerArrayletIterator(javaVM)
63
{
64
initialize(javaVM, objectPtr);
65
}
66
67
GC_PointerArrayIterator(J9JavaVM *javaVM)
68
: _contiguousArrayIterator(javaVM->omrVM)
69
, _pointerArrayletIterator(javaVM)
70
{
71
}
72
73
MMINLINE void initialize(J9JavaVM *javaVM, J9Object *objectPtr)
74
{
75
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(javaVM->omrVM);
76
_contiguous = extensions->indexableObjectModel.isInlineContiguousArraylet((J9IndexableObject *)objectPtr);
77
if (_contiguous) {
78
_contiguousArrayIterator.initialize(objectPtr);
79
} else {
80
_pointerArrayletIterator.initialize(objectPtr);
81
}
82
}
83
84
/**
85
* Restores the iterator state into this class
86
* @param[in] objectIteratorState partially scanned object iterator state
87
*/
88
MMINLINE void restore(GC_ObjectIteratorState *objectIteratorState)
89
{
90
_contiguous = objectIteratorState->_contiguous;
91
if (_contiguous) {
92
_contiguousArrayIterator.restore(objectIteratorState);
93
} else {
94
_pointerArrayletIterator.restore(objectIteratorState);
95
}
96
}
97
98
/**
99
* Saves the partially scanned state of this class
100
* @param[in] objectIteratorState where to store the state
101
*/
102
MMINLINE void save(GC_ObjectIteratorState *objectIteratorState)
103
{
104
if (_contiguous) {
105
_contiguousArrayIterator.save(objectIteratorState);
106
} else {
107
_pointerArrayletIterator.save(objectIteratorState);
108
}
109
objectIteratorState->_contiguous = _contiguous;
110
}
111
112
MMINLINE GC_SlotObject *nextSlot()
113
{
114
GC_SlotObject *slotObject = NULL;
115
if (_contiguous) {
116
slotObject = _contiguousArrayIterator.nextSlot();
117
} else {
118
slotObject = _pointerArrayletIterator.nextSlot();
119
}
120
return slotObject;
121
}
122
123
MMINLINE J9Object *getObject()
124
{
125
J9Object *objectPtr = NULL;
126
if (_contiguous) {
127
objectPtr = _contiguousArrayIterator.getObject();
128
} else {
129
objectPtr = _pointerArrayletIterator.getObject();
130
}
131
return (J9Object *)objectPtr;
132
}
133
134
/**
135
* Gets the current slot's array index.
136
* @return slot number (or zero based array index) of the last call to nextSlot.
137
* @return undefined if nextSlot has yet to be called.
138
*/
139
MMINLINE UDATA getIndex()
140
{
141
UDATA index = 0;
142
if (_contiguous) {
143
index = _contiguousArrayIterator.getIndex();
144
} else {
145
index = _pointerArrayletIterator.getIndex();
146
}
147
return index;
148
}
149
150
MMINLINE void setIndex(UDATA index)
151
{
152
if (_contiguous) {
153
_contiguousArrayIterator.setIndex(index);
154
} else {
155
_pointerArrayletIterator.setIndex(index);
156
}
157
}
158
};
159
160
#endif /* POINTERARRAYITERATOR_HPP_ */
161
162