-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathObjectModel.hpp
231 lines (200 loc) · 5.65 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
230
231
/*******************************************************************************
*
* (c) Copyright IBM Corp. 1991, 2016
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0 and
* Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* Contributors:
* Multiple authors (IBM Corp.) - initial implementation and documentation
*******************************************************************************/
#if !defined(OBJECTMODEL_HPP_)
#define OBJECTMODEL_HPP_
#include "ModronAssertions.h"
#include "modronbase.h"
#include "objectdescription.h"
#include "HeapLinkedFreeHeader.hpp"
class MM_GCExtensionsBase;
#define J9_GC_OBJECT_ALIGNMENT_IN_BYTES 0x8
#define J9_GC_MINIMUM_OBJECT_SIZE 0x10
/**
* 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 < J9_GC_MINIMUM_OBJECT_SIZE) {
sizeInBytes = J9_GC_MINIMUM_OBJECT_SIZE;
}
#endif /* OMR_GC_MINIMUM_OBJECT_SIZE */
return sizeInBytes;
}
/**
* 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
getConsumedSizeInSlotsWithHeader(omrobjectptr_t objectPtr)
{
Assert_MM_unimplemented();
return 0;
}
MMINLINE uintptr_t
getConsumedSizeInBytesWithHeader(omrobjectptr_t objectPtr)
{
return getSizeInBytesWithHeader(objectPtr);
}
MMINLINE uintptr_t
getConsumedSizeInBytesWithHeaderForMove(omrobjectptr_t objectPtr)
{
return getConsumedSizeInBytesWithHeader(objectPtr);
}
MMINLINE uintptr_t
getSizeInBytesWithHeader(omrobjectptr_t objectPtr)
{
uintptr_t *header = (uintptr_t *)objectPtr;
return *header;
}
MMINLINE void
setObjectSize(omrobjectptr_t objectPtr, uintptr_t size)
{
uintptr_t *header = (uintptr_t *)objectPtr;
*header = size;
}
MMINLINE void
preMove(OMR_VMThread* vmThread, omrobjectptr_t objectPtr)
{
/* do nothing */
}
MMINLINE void
postMove(OMR_VMThread* vmThread, omrobjectptr_t objectPtr)
{
/* do nothing */
}
/**
* 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;
}
/**
* 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_ */