Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/ArrayletObjectModelBase.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
#if !defined(ARRAYLETOBJECTMODELBASE_)
24
#define ARRAYLETOBJECTMODELBASE_
25
26
#include "j9.h"
27
#include "j9cfg.h"
28
#include "j9consts.h"
29
#include "modron.h"
30
#include "modronopt.h"
31
32
#include "Bits.hpp"
33
#include "Math.hpp"
34
35
class MM_GCExtensionsBase;
36
class MM_MemorySubSpace;
37
38
class GC_ArrayletObjectModelBase
39
{
40
/*
41
* Data members
42
*/
43
private:
44
#if defined(J9VM_GC_ENABLE_DOUBLE_MAP)
45
bool _enableDoubleMapping; /** Allows arraylets to be double mapped */
46
#endif /* J9VM_GC_ENABLE_DOUBLE_MAP */
47
protected:
48
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
49
bool _compressObjectReferences;
50
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
51
OMR_VM *_omrVM; /**< used so that we can pull the arrayletLeafSize and arrayletLeafLogSize for arraylet sizing calculations */
52
void * _arrayletRangeBase; /**< The base heap range of where discontiguous arraylets are allowed. */
53
void * _arrayletRangeTop; /**< The top heap range of where discontiguous arraylets are allowed. */
54
MM_MemorySubSpace * _arrayletSubSpace; /**< The only subspace that is allowed to have discontiguous arraylets. */
55
UDATA _largestDesirableArraySpineSize; /**< A cached copy of the subspace's _largestDesirableArraySpineSize to be used when we don't have access to a subspace. */
56
public:
57
typedef enum ArrayLayout {
58
Illegal = 0,
59
InlineContiguous,
60
Discontiguous,
61
Hybrid
62
} ArrayLayout;
63
64
/*
65
* Function members
66
*/
67
private:
68
protected:
69
virtual bool initialize(MM_GCExtensionsBase *extensions);
70
virtual void tearDown(MM_GCExtensionsBase *extensions);
71
72
/**
73
* Get the spine size without header for an arraylet with these properties
74
* @param layout The layout of the indexable object
75
* @param numberArraylets Number of arraylets for this indexable object
76
* @param dataSize How many elements are in the indexable object
77
* @param alignData Should the data section be aligned
78
* @return spineSize The actual size in byte of the spine
79
*/
80
UDATA
81
getSpineSizeWithoutHeader(ArrayLayout layout, UDATA numberArraylets, UDATA dataSize, bool alignData);
82
83
public:
84
/**
85
* Return back true if object references are compressed
86
* @return true, if object references are compressed
87
*/
88
MMINLINE bool
89
compressObjectReferences()
90
{
91
return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);
92
}
93
94
/**
95
* Returns the size of an indexable object in elements.
96
* @param arrayPtr Pointer to the indexable object whose size is required
97
* @return Size of object in elements
98
*/
99
MMINLINE UDATA
100
getSizeInElements(J9IndexableObject *arrayPtr)
101
{
102
UDATA size = 0;
103
if (compressObjectReferences()) {
104
size = ((J9IndexableObjectContiguousCompressed *)arrayPtr)->size;
105
if (0 == size) {
106
/* Discontiguous */
107
size = ((J9IndexableObjectDiscontiguousCompressed *)arrayPtr)->size;
108
}
109
} else {
110
size = ((J9IndexableObjectContiguousFull *)arrayPtr)->size;
111
if (0 == size) {
112
/* Discontiguous */
113
size = ((J9IndexableObjectDiscontiguousFull *)arrayPtr)->size;
114
}
115
}
116
return size;
117
}
118
119
/**
120
* Sets size in elements of a contiguous indexable object .
121
* @param arrayPtr Pointer to the indexable object whose size is required
122
* @param size Size in elements to set.
123
*/
124
MMINLINE void
125
setSizeInElementsForContiguous(J9IndexableObject *arrayPtr, UDATA size)
126
{
127
if (compressObjectReferences()) {
128
((J9IndexableObjectContiguousCompressed *)arrayPtr)->size = (U_32)size;
129
} else {
130
((J9IndexableObjectContiguousFull *)arrayPtr)->size = (U_32)size;
131
}
132
}
133
134
#if defined(J9VM_GC_ENABLE_DOUBLE_MAP)
135
/**
136
* Sets enable double mapping status. Note that the double map
137
* status value may differ from the requested one in certain
138
* circuntances.
139
*
140
* @param enableDoubleMapping
141
*/
142
MMINLINE void
143
setEnableDoubleMapping(bool enableDoubleMapping)
144
{
145
_enableDoubleMapping = enableDoubleMapping;
146
}
147
148
/**
149
* Returns enable double mapping status
150
*
151
* @return true if double mapping status is set to true, false otherwise.
152
*/
153
MMINLINE bool
154
isDoubleMappingEnabled()
155
{
156
return _enableDoubleMapping;
157
}
158
#endif /* J9VM_GC_ENABLE_DOUBLE_MAP */
159
160
/**
161
* Sets size in elements of a discontiguous indexable object .
162
* @param arrayPtr Pointer to the indexable object whose size is required
163
* @param size Size in elements to set.
164
*/
165
MMINLINE void
166
setSizeInElementsForDiscontiguous(J9IndexableObject *arrayPtr, UDATA size)
167
{
168
if (compressObjectReferences()) {
169
((J9IndexableObjectDiscontiguousCompressed *)arrayPtr)->mustBeZero = 0;
170
((J9IndexableObjectDiscontiguousCompressed *)arrayPtr)->size = (U_32)size;
171
} else {
172
((J9IndexableObjectDiscontiguousFull *)arrayPtr)->mustBeZero = 0;
173
((J9IndexableObjectDiscontiguousFull *)arrayPtr)->size = (U_32)size;
174
}
175
}
176
177
/**
178
* Determines whether or not a spine that represents an object of this
179
* class should have its data section aligned.
180
* @param clazz The class to check alignment for
181
* @return needAlignment Should the data section be aligned
182
*/
183
MMINLINE bool
184
shouldAlignSpineDataSection(J9Class *clazz)
185
{
186
bool needAlignment = false;
187
188
if (compressObjectReferences()) {
189
/* Compressed pointers require that each leaf starts at an appropriately-aligned address
190
* (based on the compressed shift value). If this is not done, compressed leaf pointers
191
* would be unable to reach all of the heap.
192
*/
193
needAlignment = true;
194
#if !defined(J9VM_ENV_DATA64)
195
} else {
196
/* The alignment padding is only required when the size of the spine pointers are
197
* not 8 byte aligned. For example, on a 64-bit non-compressed platform, a single
198
* spine pointer would be 8 byte aligned, whereas on a 32-bit platform, a single
199
* spine pointer would not be 8 byte aligned, and would require additional padding.
200
*/
201
if (OBJECT_HEADER_SHAPE_DOUBLES == J9GC_CLASS_SHAPE(clazz)) {
202
needAlignment = true;
203
}
204
#endif /* !J9VM_ENV_DATA64 */
205
}
206
207
return needAlignment;
208
}
209
210
/**
211
* Get the size in bytes for the arraylet at index in indexable object objPtr
212
* @param objPtr Pointer to an array object
213
* @param index the index in question. 0<=index<numArraylets(objPtr)
214
* @param dataSizeInBytes size of data in an indexable object, in bytes, including leaves, excluding the header.
215
* @param numArraylets total number of arraylets for the given indexable object
216
* @return the size of the indexth arraylet
217
*/
218
MMINLINE UDATA
219
arrayletSize(J9IndexableObject *objPtr, UDATA index, UDATA dataSizeInBytes, UDATA numArraylets)
220
{
221
UDATA arrayletLeafSize = _omrVM->_arrayletLeafSize;
222
if (index < numArraylets - 1) {
223
return arrayletLeafSize;
224
} else {
225
return MM_Math::saturatingSubtract(dataSizeInBytes, index * arrayletLeafSize);
226
}
227
}
228
229
/**
230
* Return the total number of arraylets for an indexable object with a size of dataInSizeByte
231
* @param dataSizeInBytes size of an array in bytes (not elements)
232
* @return the number of arraylets used for an array of dataSizeInBytes bytes
233
*/
234
MMINLINE UDATA
235
numArraylets(UDATA dataSizeInBytes)
236
{
237
UDATA leafSize = _omrVM->_arrayletLeafSize;
238
UDATA numberOfArraylets = 1;
239
if (UDATA_MAX != leafSize) {
240
UDATA leafSizeMask = leafSize - 1;
241
UDATA leafLogSize = _omrVM->_arrayletLeafLogSize;
242
243
/* CMVC 135307 : following logic for calculating the leaf count would not overflow dataSizeInBytes.
244
* the assumption is leaf size is order of 2. It's identical to:
245
* if (dataSizeInBytes % leafSize) is 0
246
* leaf count = dataSizeInBytes >> leafLogSize
247
* else
248
* leaf count = (dataSizeInBytes >> leafLogSize) + 1
249
*/
250
numberOfArraylets = ((dataSizeInBytes >> leafLogSize) + (((dataSizeInBytes & leafSizeMask) + leafSizeMask) >> leafLogSize));
251
}
252
return numberOfArraylets;
253
}
254
255
/**
256
* Expands the heap range in which discontiguous arraylets are allowed.
257
* @param subSpace The subspace of the range in which discontiguous arraylets are allowed.
258
* @param rangeBase The base heap range of where discontiguous arraylets are allowed.
259
* @param rangeTop The top heap range of where discontiguous arraylets are allowed.
260
* @param largestDesirableArraySpineSize The subspace's _largestDesirableArraySpineSize to be used when we don't have access to a subspace.
261
*/
262
void
263
expandArrayletSubSpaceRange(MM_MemorySubSpace* subSpace, void* rangeBase, void* rangeTop, UDATA largestDesirableArraySpineSize);
264
};
265
266
#endif /* ARRAYLETOBJECTMODELBASE_ */
267
268