Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/PointerArrayletInlineLeafIterator.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(POINTERARRAYLETINLINELEAFITERATOR_HPP_)
29
#define POINTERARRAYLETINLINELEAFITERATOR_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "ModronAssertions.h"
34
35
#include "ArrayObjectModel.hpp"
36
#include "Bits.hpp"
37
#include "GCExtensionsBase.hpp"
38
#include "ObjectIteratorState.hpp"
39
#include "SlotObject.hpp"
40
41
/**
42
* Iterate over all slots in a pointer array's inline leaf which contain an object reference (will iterate over nothing if the object is fully discontiguous)
43
* @ingroup GC_Structs
44
*/
45
class GC_PointerArrayletInlineLeafIterator
46
{
47
/* Data Members */
48
private:
49
GC_SlotObject _slotObject; /**< Create own SlotObject class to provide output */
50
UDATA _arrayletLeafSize; /* The size of an arraylet leaf */
51
UDATA _fobjectsPerLeaf; /* The number of fj9object_t's per leaf */
52
fj9object_t * _currentArrayletBaseAddress; /* The base address of the current arraylet */
53
UDATA _currentArrayletOffset; /* The offset to the _index'ed item from the currentArrayletBaseAddress */
54
UDATA _elementsStillToRead; /**< The number of elements this iterator is still expecting to return */
55
J9JavaVM *_javaVM; /**< The JavaVM */
56
protected:
57
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
58
bool const _compressObjectReferences;
59
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
60
public:
61
62
/* Member Functions */
63
private:
64
protected:
65
public:
66
/**
67
* Return back true if object references are compressed
68
* @return true, if object references are compressed
69
*/
70
MMINLINE bool compressObjectReferences() {
71
return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);
72
}
73
74
MMINLINE void initialize(J9Object *objectPtr) {
75
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_javaVM->omrVM);
76
77
J9IndexableObject *arrayPtr = (J9IndexableObject *)objectPtr;
78
79
/* Set current and end scan pointers */
80
UDATA index = extensions->indexableObjectModel.getSizeInElements(arrayPtr);
81
if(0 == index) {
82
_currentArrayletOffset = 0;
83
_currentArrayletBaseAddress = NULL;
84
_elementsStillToRead = 0;
85
} else {
86
UDATA currentArrayletIndex = ((U_32)index-1) / _fobjectsPerLeaf; /* The index of the arraylet containing _index */
87
_currentArrayletOffset = ((U_32)index-1) % _fobjectsPerLeaf; /* The offset of _index in the current arraylet */
88
89
fj9object_t *arrayoidPointer = extensions->indexableObjectModel.getArrayoidPointer(arrayPtr);
90
GC_SlotObject arrayletBaseSlotObject(_javaVM->omrVM, GC_SlotObject::addToSlotAddress(arrayoidPointer, currentArrayletIndex, compressObjectReferences()));
91
_currentArrayletBaseAddress = (fj9object_t *)arrayletBaseSlotObject.readReferenceFromSlot();
92
_elementsStillToRead = index % _fobjectsPerLeaf;
93
}
94
}
95
96
MMINLINE GC_SlotObject *nextSlot()
97
{
98
GC_SlotObject *slotObject = NULL;
99
100
if (_elementsStillToRead > 0) {
101
_slotObject.writeAddressToSlot(GC_SlotObject::addToSlotAddress(_currentArrayletBaseAddress, _currentArrayletOffset, compressObjectReferences()));
102
103
_elementsStillToRead -= 1;
104
_currentArrayletOffset -= 1;
105
106
slotObject = &_slotObject;
107
}
108
return slotObject;
109
}
110
111
GC_PointerArrayletInlineLeafIterator(J9JavaVM *javaVM)
112
: _slotObject(GC_SlotObject(javaVM->omrVM, NULL))
113
, _javaVM(javaVM)
114
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
115
, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))
116
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
117
{
118
_arrayletLeafSize = _javaVM->arrayletLeafSize;
119
_fobjectsPerLeaf = _arrayletLeafSize / J9JAVAVM_REFERENCE_SIZE(javaVM);
120
}
121
122
/**
123
* @param objectPtr the array object to be processed
124
*/
125
GC_PointerArrayletInlineLeafIterator(J9JavaVM *javaVM, J9Object *objectPtr)
126
: _slotObject(GC_SlotObject(javaVM->omrVM, NULL))
127
, _javaVM(javaVM)
128
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
129
, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))
130
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
131
{
132
_arrayletLeafSize = _javaVM->arrayletLeafSize;
133
_fobjectsPerLeaf = _arrayletLeafSize / J9JAVAVM_REFERENCE_SIZE(javaVM);
134
initialize(objectPtr);
135
}
136
};
137
138
#endif /* POINTERARRAYLETINLINELEAFITERATOR_HPP_ */
139
140