-
Notifications
You must be signed in to change notification settings - Fork 392
/
MemoryPoolAddressOrderedListBase.hpp
266 lines (228 loc) · 9.12 KB
/
MemoryPoolAddressOrderedListBase.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*******************************************************************************
* Copyright (c) 1991, 2021 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(MEMORYPOOLADDRESSORDEREDLISTBASE_HPP_)
#define MEMORYPOOLADDRESSORDEREDLISTBASE_HPP_
#include "omrcfg.h"
//#include "omrcomp.h"
#include "modronopt.h"
#include "HeapLinkedFreeHeader.hpp"
#include "LightweightNonReentrantLock.hpp"
#include "MemoryPool.hpp"
#include "EnvironmentBase.hpp"
#if defined(OMR_VALGRIND_MEMCHECK)
#include "MemcheckWrapper.hpp"
#endif /* defined(OMR_VALGRIND_MEMCHECK) */
class MM_SweepPoolManager;
class MM_SweepPoolState;
/**
* @todo Provide class documentation
* @ingroup GC_Base_Core
*/
class MM_MemoryPoolAddressOrderedListBase : public MM_MemoryPool
{
/*
* Data members
*/
private:
protected:
/* Basic free list support */
MM_LightweightNonReentrantLock _resetLock;
MM_HeapLinkedFreeHeader ** _referenceHeapFreeList;
MM_SweepPoolState* _sweepPoolState; /**< GC Sweep Pool State */
MM_SweepPoolManagerAddressOrderedListBase* _sweepPoolManager; /**< pointer to SweepPoolManager class */
MM_HeapLinkedFreeHeader *_lastFreeEntry; /**< address of the last free entry in the pool; valid after compact; NOT maintained during allocation */
uintptr_t _adjustedBytesForCardAlignment; /* due to Dirty Card Alignment, number of free memory bytes can not be reused as survivor bytes(it should be counted as a part of darkmatter bytes, balanced gc only) */
public:
/*
* Function members
*/
private:
protected:
MMINLINE bool internalRecycleHeapChunk(void *addrBase, void *addrTop, MM_HeapLinkedFreeHeader *next)
{
/* Determine if the heap chunk belongs in the free list */
uintptr_t freeEntrySize = ((uintptr_t)addrTop) - ((uintptr_t)addrBase);
Assert_MM_true((uintptr_t)addrTop >= (uintptr_t)addrBase);
bool const compressed = compressObjectReferences();
#if defined(OMR_VALGRIND_MEMCHECK)
valgrindMakeMemUndefined((uintptr_t) addrBase, freeEntrySize);
#endif /* defined(OMR_VALGRIND_MEMCHECK) */
MM_HeapLinkedFreeHeader *freeEntry = MM_HeapLinkedFreeHeader::fillWithHoles(addrBase, freeEntrySize, compressed);
if ((NULL != freeEntry) && (freeEntrySize >= _minimumFreeEntrySize)) {
Assert_MM_true(freeEntry == addrBase);
Assert_MM_true((NULL == next) || (freeEntry < next));
freeEntry->setNext(next, compressed);
return true;
} else {
return false;
}
}
/**
* set the address of the last free entry in the pool
*/
virtual void setLastFreeEntry(void * addr) { _lastFreeEntry = (MM_HeapLinkedFreeHeader *)addr; }
/**
* get the address of the last free entry in the pool
*/
virtual MM_HeapLinkedFreeHeader *getLastFreeEntry() { return _lastFreeEntry; }
#if defined(OMR_GC_LARGE_OBJECT_AREA)
/**
* Append a free entry to an address ordered list
*
* @param addrBase Low address of memory to be appended
* @param addrTop High address of memory non inclusive)
* @param minimumSize Only append entries of this minimum size
* @param freeListHead Current head of list of free entries
* @param freeListTail Current tail of list of free entries
*
* @return TRUE if free entry appended; FALSE otherwise
*/
MMINLINE bool appendToList(MM_EnvironmentBase* env, void* addrBase, void* addrTop, uintptr_t minimumSize, MM_HeapLinkedFreeHeader*& freeListHead, MM_HeapLinkedFreeHeader*& freeListTail)
{
bool const compressed = compressObjectReferences();
uintptr_t freeEntrySize = ((uint8_t*)addrTop - (uint8_t*)addrBase);
MM_HeapLinkedFreeHeader* freeEntry = MM_HeapLinkedFreeHeader::fillWithHoles(addrBase, freeEntrySize, compressed);
if ((NULL != freeEntry) && (freeEntrySize >= minimumSize)) {
/* If the list is not empty, add the entry to the tail. */
if (NULL != freeListHead) {
Assert_MM_true(freeListTail < freeEntry);
freeListTail->setNext(freeEntry, compressed);
} else {
freeListHead = freeEntry;
}
freeListTail = freeEntry;
return true;
} else {
/* Abandon entry */
return false;
}
}
MMINLINE bool insertToList(MM_EnvironmentBase* env, void* addrBase, void* addrTop, uintptr_t minimumSize, MM_HeapLinkedFreeHeader*& freeListHead, MM_HeapLinkedFreeHeader*& freeListTail)
{
bool const compressed = compressObjectReferences();
uintptr_t freeEntrySize = ((uint8_t*)addrTop - (uint8_t*)addrBase);
MM_HeapLinkedFreeHeader* freeEntry = MM_HeapLinkedFreeHeader::fillWithHoles(addrBase, freeEntrySize, compressed);
if ((NULL != freeEntry) && (freeEntrySize >= minimumSize)) {
/* If the list is not empty, add the entry to the tail. */
if (NULL != freeListHead) {
if (freeListTail < freeEntry) {
freeListTail->setNext(freeEntry, compressed);
freeListTail = freeEntry;
} else {
MM_HeapLinkedFreeHeader* cur = freeListHead;
while (cur > freeEntry) {
cur = cur->getNext(compressed);
}
freeEntry->setNext(cur->getNext(compressed), compressed);
cur->setNext(freeEntry, compressed);
}
} else {
freeListHead = freeEntry;
freeListTail = freeEntry;
}
return true;
} else {
/* Abandon entry */
return false;
}
}
#endif /* OMR_GC_LARGE_OBJECT_AREA */
bool connectInnerMemoryToPool(MM_EnvironmentBase* env, void* address, uintptr_t size, void* previousFreeEntry);
void connectOuterMemoryToPool(MM_EnvironmentBase *env, void *address, uintptr_t size, void *nextFreeEntry);
void connectFinalMemoryToPool(MM_EnvironmentBase *env, void *address, uintptr_t size);
void abandonMemoryInPool(MM_EnvironmentBase *env, void *address, uintptr_t size);
public:
virtual void acquireResetLock(MM_EnvironmentBase* env);
virtual void releaseResetLock(MM_EnvironmentBase* env);
virtual bool createFreeEntry(MM_EnvironmentBase* env, void* addrBase, void* addrTop,
MM_HeapLinkedFreeHeader* previousFreeEntry, MM_HeapLinkedFreeHeader* nextFreeEntry);
virtual bool createFreeEntry(MM_EnvironmentBase* env, void* addrBase, void* addrTop);
MMINLINE bool abandonHeapChunk(void *addrBase, void *addrTop)
{
Assert_MM_true(addrTop >= addrBase);
return internalRecycleHeapChunk(addrBase, addrTop, NULL);
}
MMINLINE MM_SweepPoolState * getSweepPoolState()
{
Assert_MM_true(NULL != _sweepPoolState);
return _sweepPoolState;
}
/**
* Get access to Sweep Pool Manager
* @return pointer to Sweep Pool Manager associated with this pool
* or NULL for superpools
*/
MMINLINE MM_SweepPoolManager *getSweepPoolManager()
{
/*
* This function must be called for leaf pools only
* The failure at this line means that superpool has been used as leaf pool
* or leaf pool has problem with creation (like early initialization)
*/
Assert_MM_true(NULL != _sweepPoolManager);
return (MM_SweepPoolManager*)_sweepPoolManager;
}
virtual void printCurrentFreeList(MM_EnvironmentBase* env, const char* area)=0;
void resetAdjustedBytesForCardAlignment()
{
_adjustedBytesForCardAlignment = 0;
}
/**
* Check, can free memory element be connected to memory pool
*
* @param address free memory start address
* @param size free memory size in bytes
* @return true if free memory element would be accepted
*/
MMINLINE bool canMemoryBeConnectedToPool(MM_EnvironmentBase* env, void* address, uintptr_t size)
{
return size >= getMinimumFreeEntrySize();
}
#if defined(OMR_GC_IDLE_HEAP_MANAGER)
uintptr_t releaseFreeEntryMemoryPages(MM_EnvironmentBase* env, MM_HeapLinkedFreeHeader* freeEntry);
#endif
/**
* Create a MemoryPoolAddressOrderedList object.
*/
MM_MemoryPoolAddressOrderedListBase(MM_EnvironmentBase *env, uintptr_t minimumFreeEntrySize) :
MM_MemoryPool(env, minimumFreeEntrySize)
,_referenceHeapFreeList(NULL)
,_sweepPoolState(NULL)
,_sweepPoolManager(NULL)
,_lastFreeEntry(NULL)
,_adjustedBytesForCardAlignment(0)
{
// _typeId = __FUNCTION__;
};
MM_MemoryPoolAddressOrderedListBase(MM_EnvironmentBase *env, uintptr_t minimumFreeEntrySize, const char *name) :
MM_MemoryPool(env, minimumFreeEntrySize, name)
,_referenceHeapFreeList(NULL)
,_sweepPoolState(NULL)
,_sweepPoolManager(NULL)
,_lastFreeEntry(NULL)
,_adjustedBytesForCardAlignment(0)
{
// _typeId = __FUNCTION__;
};
friend class MM_SweepPoolManagerAddressOrderedListBase;
};
#endif /* MEMORYPOOLADDRESSORDEREDLISTBASE_HPP_ */