forked from eclipse-openj9/openj9-omr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectModel.hpp
229 lines (202 loc) · 6.47 KB
/
ObjectModel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
* Copyright (c) 1991, 2016 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
#if !defined(OBJECTMODEL_HPP_)
#define OBJECTMODEL_HPP_
/*
* @ddr_namespace: default
*/
#include "ModronAssertions.h"
#include "modronbase.h"
#include "objectdescription.h"
#include "Bits.hpp"
#include "HeapLinkedFreeHeader.hpp"
class MM_MM_AllocateInitialization;
class MM_EnvironmentBase;
class MM_GCExtensionsBase;
#define J9_GC_OBJECT_ALIGNMENT_IN_BYTES 0x8
/**
* Provides information for a given object.
* @ingroup GC_Base
*/
class GC_ObjectModel
{
/*
* Member data and types
*/
private:
uintptr_t _objectAlignmentInBytes; /**< Cached copy of object alignment for getting object alignment for adjusting for alignment */
uintptr_t _objectAlignmentShift; /**< Cached copy of object alignment shift, must be log2(_objectAlignmentInBytes) */
protected:
public:
/*
* Member functions
*/
private:
protected:
public:
/**
* Initialize the receiver, a new instance of GC_ObjectModel
*
* @return true on success, false on failure
*/
bool
initialize(MM_GCExtensionsBase *extensions)
{
return true;
}
void tearDown(MM_GCExtensionsBase *extensions) {}
MMINLINE uintptr_t
adjustSizeInBytes(uintptr_t sizeInBytes)
{
sizeInBytes = (sizeInBytes + (_objectAlignmentInBytes - 1)) & (uintptr_t)~(_objectAlignmentInBytes - 1);
#if defined(OMR_GC_MINIMUM_OBJECT_SIZE)
if (sizeInBytes < OMR_MINIMUM_OBJECT_SIZE) {
sizeInBytes = OMR_MINIMUM_OBJECT_SIZE;
}
#endif /* OMR_GC_MINIMUM_OBJECT_SIZE */
return sizeInBytes;
}
/**
* This method must be implemented to initialize the object header for a new allocation
* of heap memory. The MM_AllocateInitialization instance provided allows access to the
* MM_AllocateDescription instance used to allocate the heap memory and language-specific
* metadata required to initialize the object header.
*
* @param[in] env Pointer to environment for calling thread.
* @param[in] allocatedBytes Pointer to allocated heap space
* @param[in] allocateInitialization Pointer to the allocation metadata
*/
omrobjectptr_t
initializeAllocation(MM_EnvironmentBase *env, void *allocatedBytes, MM_AllocateInitialization *allocateInitialization)
{
#error GC_ObjectModel::initializeAllocation() must be implemented.
}
/**
* Returns TRUE if an object is dead, FALSE otherwise.
* @param objectPtr Pointer to an object
* @return TRUE if an object is dead, FALSE otherwise
*/
MMINLINE bool
isDeadObject(void *objectPtr)
{
return 0 != (*((uintptr_t *)objectPtr) & J9_GC_OBJ_HEAP_HOLE_MASK);
}
/**
* Returns TRUE if an object is a dead single slot object, FALSE otherwise.
* @param objectPtr Pointer to an object
* @return TRUE if an object is a dead single slot object, FALSE otherwise
*/
MMINLINE bool
isSingleSlotDeadObject(omrobjectptr_t objectPtr)
{
return J9_GC_SINGLE_SLOT_HOLE == (*((uintptr_t *)objectPtr) & J9_GC_OBJ_HEAP_HOLE_MASK);
}
/**
* Returns the size, in bytes, of a single slot dead object.
* @param objectPtr Pointer to an object
* @return The size, in bytes, of a single slot dead object
*/
MMINLINE uintptr_t
getSizeInBytesSingleSlotDeadObject(omrobjectptr_t objectPtr)
{
return sizeof(uintptr_t);
}
/**
* Returns the size, in bytes, of a multi-slot dead object.
* @param objectPtr Pointer to an object
* @return The size, in bytes, of a multi-slot dead object
*/
MMINLINE uintptr_t getSizeInBytesMultiSlotDeadObject(omrobjectptr_t objectPtr)
{
return MM_HeapLinkedFreeHeader::getHeapLinkedFreeHeader(objectPtr)->getSize();
}
/**
* Returns the size in bytes of a dead object.
* @param objectPtr Pointer to an object
* @return The size in byts of a dead object
*/
MMINLINE uintptr_t
getSizeInBytesDeadObject(omrobjectptr_t objectPtr)
{
if(isSingleSlotDeadObject(objectPtr)) {
return getSizeInBytesSingleSlotDeadObject(objectPtr);
}
return getSizeInBytesMultiSlotDeadObject(objectPtr);
}
MMINLINE uintptr_t
getConsumedSizeInBytesWithHeader(omrobjectptr_t objectPtr)
{
return adjustSizeInBytes(getSizeInBytesWithHeader(objectPtr));
}
MMINLINE uintptr_t
getSizeInBytesWithHeader(omrobjectptr_t objectPtr)
{
#error provide an implementation of how big objects are including any header data associated with each object
}
#if defined(OMR_GC_MODRON_SCAVENGER)
/**
* Returns TRUE if an object is remembered, FALSE otherwise.
* @param objectPtr Pointer to an object
* @return TRUE if an object is remembered, FALSE otherwise
*/
MMINLINE bool
isRemembered(omrobjectptr_t objectPtr)
{
return false;
}
#endif /* OMR_GC_MODRON_SCAVENGER */
/**
* Set run-time Object Alignment in the heap value
* Function exists because we can only determine it is way after ObjectModel is init
*/
MMINLINE void
setObjectAlignmentInBytes(uintptr_t objectAlignmentInBytes)
{
_objectAlignmentInBytes = objectAlignmentInBytes;
}
/**
* Set run-time Object Alignment Shift value
* Function exists because we can only determine it is way after ObjectModel is init
*/
MMINLINE void
setObjectAlignmentShift(uintptr_t objectAlignmentShift)
{
_objectAlignmentShift = objectAlignmentShift;
}
/**
* Get run-time Object Alignment in the heap value
*/
MMINLINE uintptr_t
getObjectAlignmentInBytes()
{
return _objectAlignmentInBytes;
}
/**
* Get run-time Object Alignment Shift value
*/
MMINLINE uintptr_t
getObjectAlignmentShift()
{
return _objectAlignmentShift;
}
};
#endif /* OBJECTMODEL_HPP_ */