Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CopyForwardCompactGroup.hpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2022 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
/**
25
* @file
26
* @ingroup GC_Modron_Standard
27
*/
28
29
#if !defined(COPYFORWARDCOMPACTGROUP_HPP_)
30
#define COPYFORWARDCOMPACTGROUP_HPP_
31
32
#include "j9.h"
33
#include "j9cfg.h"
34
#include "modronopt.h"
35
36
#include "GCExtensions.hpp"
37
#include "MemoryPool.hpp"
38
#include "EnvironmentVLHGC.hpp"
39
#include "HeapRegionDescriptorVLHGC.hpp"
40
#include "HeapRegionManager.hpp"
41
42
class MM_CopyScanCacheVLHGC;
43
class MM_LightweightNonReentrantLock;
44
45
/**
46
* Structure used to record per-thread data for each compact group in CopyForwardScheme.
47
* @ingroup GC_Modron_Standard
48
*/
49
class MM_CopyForwardCompactGroup
50
{
51
/* data members */
52
private:
53
MM_HeapRegionManager *_regionManager; /**< Region manager for the heap instance */
54
protected:
55
public:
56
MM_CopyScanCacheVLHGC *_copyCache; /**< The copy cache in this compact group for the owning thread */
57
MM_LightweightNonReentrantLock *_copyCacheLock; /**< The lock associated with the list this copy cache belongs to */
58
void *_TLHRemainderBase; /**< base pointers of the last unused TLH copy cache, that might be reused on next copy refresh */
59
void *_TLHRemainderTop; /**< top pointers of the last unused TLH copy cache, that might be reused on next copy refresh */
60
void *_DFCopyBase; /**< The base address of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */
61
void *_DFCopyAlloc; /**< The alloc pointer of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */
62
void *_DFCopyTop; /**< The top address of the inlined "copy cache" used by CopyForwardSchemeDepthFirst */
63
UDATA _failedAllocateSize; /**< Smallest size of allocate request that we failed in this compact group */
64
65
/* statistics */
66
struct MM_CopyForwardCompactGroupStats {
67
UDATA _copiedObjects; /**< The number of objects copied into survivor regions for this compact group by the owning thread (i.e. objects copied TO or WITHIN this compact group) */
68
UDATA _copiedBytes; /**< The number of bytes copied into survivor regions for this compact group by the owning thread */
69
UDATA _liveObjects; /**< The number of live objects found in evacuate regions for this compact group by the owning thread (i.e. objects copied FROM or WITHIN this compact group) */
70
UDATA _liveBytes; /**< The number of live bytes found in evacuate regions for this compact group by the owning thread */
71
UDATA _scannedObjects; /**< The number of objects scanned in abort recovery/nonEvacuated regions in this compact group */
72
UDATA _scannedBytes; /**< The number of objects scanned in abort recovery/nonEvacuated regions in this compact group */
73
};
74
75
MM_CopyForwardCompactGroupStats _edenStats; /**< Data about objects from Eden regions */
76
MM_CopyForwardCompactGroupStats _nonEdenStats; /**< Data about objects from non-Eden regions */
77
78
UDATA _failedCopiedObjects; /**< The number of objects which the owning thread failed to copy in this compact group */
79
UDATA _failedCopiedBytes; /**< The number of bytes which the owning thread failed to copy in this compact group */
80
UDATA _freeMemoryMeasured; /**< The number of bytes which were wasted while this thread was working with the given _copyCache (due to alignment, etc) which is needs to save back into the pool when giving up the cache */
81
UDATA _discardedBytes; /**< The number of bytes discarded in survivor regions for this compact group by the owning thread due to incompletely filled copy caches and other inefficiencies */
82
UDATA _TLHRemainderCount; /**< number of TLHRemainders has been created for the compact group during the copyforward */
83
U_64 _allocationAge; /**< Average allocation age for this compact group */
84
85
/* Mark map rebuilding cache values for the active MM_CopyScanCacheVLHGC associated with this group */
86
UDATA _markMapAtomicHeadSlotIndex; /**< Slot index of head which requires atomic update into the mark map (if any) */
87
UDATA _markMapAtomicTailSlotIndex; /**< Slot index of tail which requires atomic update into the mark map (if any) */
88
UDATA _markMapPGCSlotIndex; /**< Cached slot index for previous (PGC) mark map */
89
UDATA _markMapPGCBitMask; /**< Cached bit map mask being build for previous (PGC) mark map */
90
UDATA _markMapGMPSlotIndex; /**< Cached slot index for next (GMP) mark map */
91
UDATA _markMapGMPBitMask; /**< Cached bit map mask being build for previous (GMP) mark map */
92
93
void initialize(MM_EnvironmentVLHGC *env) {
94
_copyCache = NULL;
95
_copyCacheLock = NULL;
96
_TLHRemainderBase = NULL;
97
_TLHRemainderTop = NULL;
98
_DFCopyBase = NULL;
99
_DFCopyAlloc = NULL;
100
_DFCopyTop = NULL;
101
_failedAllocateSize = UDATA_MAX;
102
_edenStats._copiedObjects = 0;
103
_edenStats._copiedBytes = 0;
104
_edenStats._liveObjects = 0;
105
_edenStats._liveBytes = 0;
106
_edenStats._scannedObjects = 0;
107
_edenStats._scannedBytes = 0;
108
_nonEdenStats._copiedObjects = 0;
109
_nonEdenStats._copiedBytes = 0;
110
_nonEdenStats._liveObjects = 0;
111
_nonEdenStats._liveBytes = 0;
112
_nonEdenStats._scannedObjects = 0;
113
_nonEdenStats._scannedBytes = 0;
114
_failedCopiedObjects = 0;
115
_failedCopiedBytes = 0;
116
_freeMemoryMeasured = 0;
117
_discardedBytes = 0;
118
_TLHRemainderCount = 0;
119
_allocationAge = 0;
120
_markMapAtomicHeadSlotIndex = 0;
121
_markMapAtomicTailSlotIndex = 0;
122
_markMapPGCSlotIndex = 0;
123
_markMapPGCBitMask = 0;
124
_markMapGMPSlotIndex = 0;
125
_markMapGMPBitMask = 0;
126
_regionManager = MM_GCExtensions::getExtensions(env)->heapRegionManager;
127
}
128
129
/* function members */
130
private:
131
protected:
132
public:
133
MMINLINE void resetTLHRemainder()
134
{
135
_TLHRemainderBase = NULL;
136
_TLHRemainderTop = NULL;
137
}
138
139
MMINLINE void setTLHRemainder(void* base, void* top)
140
{
141
_TLHRemainderBase = base;
142
_TLHRemainderTop = top;
143
_TLHRemainderCount += 1;
144
}
145
146
MMINLINE uintptr_t getTLHRemainderSize()
147
{
148
return ((uintptr_t)_TLHRemainderTop - (uintptr_t)_TLHRemainderBase);
149
}
150
151
MMINLINE void discardTLHRemainder(MM_EnvironmentVLHGC* env)
152
{
153
if (NULL != _TLHRemainderBase) {
154
discardTLHRemainder(env, _TLHRemainderBase, _TLHRemainderTop);
155
resetTLHRemainder();
156
} else {
157
Assert_MM_true(NULL == _TLHRemainderTop);
158
}
159
}
160
161
MMINLINE void discardTLHRemainder(MM_EnvironmentVLHGC* env, void* base, void* top)
162
{
163
/* make it a walkable hole */
164
env->_cycleState->_activeSubSpace->abandonHeapChunk(base, top);
165
MM_HeapRegionDescriptorVLHGC *region = (MM_HeapRegionDescriptorVLHGC*)_regionManager->tableDescriptorForAddress(base);
166
discardHeapChunk(base, top, region);
167
}
168
169
MMINLINE void recycleTLHRemainder(MM_EnvironmentVLHGC* env)
170
{
171
if (NULL != _TLHRemainderBase) {
172
/* make it a walkable hole */
173
env->_cycleState->_activeSubSpace->abandonHeapChunk(_TLHRemainderBase, _TLHRemainderTop);
174
MM_HeapRegionDescriptorVLHGC *region = (MM_HeapRegionDescriptorVLHGC*)_regionManager->tableDescriptorForAddress(_TLHRemainderBase);
175
region->getMemoryPool()->recycleHeapChunk(env, _TLHRemainderBase, _TLHRemainderTop);
176
resetTLHRemainder();
177
} else {
178
Assert_MM_true(NULL == _TLHRemainderTop);
179
}
180
}
181
182
MMINLINE void discardHeapChunk(void* base, void* top, MM_HeapRegionDescriptorVLHGC* region)
183
{
184
uintptr_t discardSize = ((uintptr_t)top - (uintptr_t)base);
185
_discardedBytes += discardSize;
186
region->getMemoryPool()->incrementDarkMatterBytesAtomic(discardSize);
187
}
188
};
189
190
#endif /* COPYFORWARDCOMPACTGROUP_HPP_ */
191
192