Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/ArrayletLeafIterator.hpp
5990 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(ARRAYLETLEAFITERATOR_HPP_)
29
#define ARRAYLETLEAFITERATOR_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "modron.h"
34
#include "ModronAssertions.h"
35
36
#include "GCExtensionsBase.hpp"
37
#include "SlotObject.hpp"
38
#include "ArrayObjectModel.hpp"
39
#include "ArrayletObjectModel.hpp"
40
41
/**
42
* Defines the interface for iterating over all slots in an object which contain an object reference
43
* @ingroup GC_Structs
44
*/
45
class GC_ArrayletLeafIterator
46
{
47
protected:
48
OMR_VM *const _omrVM;
49
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
50
bool const _compressObjectReferences;
51
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
52
GC_SlotObject _slotObject;
53
J9IndexableObject *_spinePtr; /**< The pointer to the beginning of the actual indexable object (ie: the spine) */
54
GC_ArrayletObjectModel::ArrayLayout _layout; /**< The layout of the arraylet being iterated */
55
fj9object_t *_arrayoid; /**< The pointer to the beginning of the arraylet leaf pointers (that is, the first slot after the object header) */
56
UDATA _numLeafs; /**< The number of leaf pointers beginning at the _arrayoid. This includes inline and out-of-line leaf pointers */
57
UDATA _numLeafsCounted;
58
void *_endOfSpine; /**< Pointer to the first slot AFTER the arraylet spine */
59
60
public:
61
/**
62
* Return back true if object references are compressed
63
* @return true, if object references are compressed
64
*/
65
MMINLINE bool compressObjectReferences() {
66
return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);
67
}
68
69
/**
70
* @return the next leaf reference slot in the arraylet
71
* @return NULL if there are no more reference slots in the object
72
*/
73
MMINLINE GC_SlotObject *nextLeafPointer()
74
{
75
if (_numLeafsCounted < _numLeafs) {
76
_slotObject.writeAddressToSlot(GC_SlotObject::addToSlotAddress(_arrayoid, _numLeafsCounted, compressObjectReferences()));
77
_numLeafsCounted += 1;
78
return &_slotObject;
79
} else {
80
return NULL;
81
}
82
}
83
84
MMINLINE void
85
initialize(J9IndexableObject *objectPtr)
86
{
87
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_omrVM);
88
_spinePtr = objectPtr;
89
_layout = extensions->indexableObjectModel.getArrayLayout(objectPtr);
90
91
/* For a hybrid arraylet spec, this iterator should not be called for a contiguous arraylet */
92
Assert_MM_true(GC_ArrayletObjectModel::InlineContiguous != _layout);
93
94
/* for 0-sized arrays, there is no need to return the fake leaf pointer.
95
* It can potentially be problematic to return this fake leaf pointer as users of
96
* this iterator assume we return valid leaf pointers.
97
*/
98
if (0 == extensions->indexableObjectModel.getSizeInElements(objectPtr)) {
99
_arrayoid = NULL;
100
_numLeafs = 0;
101
} else {
102
_arrayoid = extensions->indexableObjectModel.getArrayoidPointer(objectPtr);
103
_numLeafs = extensions->indexableObjectModel.numArraylets(objectPtr);
104
}
105
_numLeafsCounted = 0;
106
_endOfSpine = ((U_8 *)objectPtr) + extensions->indexableObjectModel.getSizeInBytesWithHeader(objectPtr);
107
}
108
109
MMINLINE UDATA getNumLeafs() { return _numLeafs ; }
110
111
MMINLINE void *getEndOfSpine() { return _endOfSpine ; }
112
113
GC_ArrayletLeafIterator(J9JavaVM *javaVM, J9IndexableObject *objectPtr) :
114
_omrVM(javaVM->omrVM)
115
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
116
, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))
117
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
118
, _slotObject(GC_SlotObject(_omrVM, NULL))
119
{
120
initialize(objectPtr);
121
}
122
};
123
124
#endif /* ARRAYLETLEAFITERATOR_HPP_ */
125
126