Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/ClassLoaderRememberedSet.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2020 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
/**
24
* @file
25
* @ingroup gc_vlhgc
26
*/
27
28
#if !defined(CLASSLOADERREMEMBEREDSET_HPP)
29
#define CLASSLOADERREMEMBEREDSET_HPP
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "modron.h"
34
#include "pool_api.h"
35
#include "ModronAssertions.h"
36
37
#include "BaseVirtual.hpp"
38
#include "LightweightNonReentrantLock.hpp"
39
#include "GCExtensions.hpp"
40
41
class MM_EnvironmentBase;
42
class MM_HeapRegionDescriptor;
43
class MM_HeapRegionManager;
44
struct J9Pool;
45
46
class MM_ClassLoaderRememberedSet : public MM_BaseVirtual
47
{
48
private:
49
MM_GCExtensions * const _extensions; /**< cached pointer to the extensions structure */
50
MM_HeapRegionManager * const _regionManager; /** cached pointer to the region manager */
51
UDATA const _bitVectorSize; /**< The size of each bit vector in UDATAs */
52
J9Pool *_bitVectorPool; /**< A pool of bit vectors to associate with J9ClassLoaders */
53
MM_LightweightNonReentrantLock _lock; /**< A lock to protect _bitVectorPool */
54
UDATA * _bitsToClear; /**< A bit vector which is built up before a garbage collection */
55
56
private:
57
MM_ClassLoaderRememberedSet(MM_EnvironmentBase* env);
58
59
/**
60
* Allocation helper for J9Pool.
61
*/
62
static void * poolAllocateHelper(void* userData, U_32 size, const char* callSite, U_32 memoryCategory, U_32 type, U_32* doInit);
63
64
/**
65
* Deallocation helper for J9Pool.
66
*/
67
static void poolFreeHelper(void* userData, void* address, U_32 type);
68
69
/**
70
* Upgrade the specified class loader from a single remembered region to a full bit vector.
71
* If a bit vector can't be installed, set the loader to overflowed.
72
* @param env[in] the current thread
73
* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot
74
*/
75
void installBitVector(MM_EnvironmentBase* env, volatile UDATA *gcRememberedSetAddress);
76
77
/**
78
* Atomically set the specified bit in the specified bit vector.
79
* @param env[in] the current thread
80
* @param bitVector[in] the bitVector to modify
81
* @param bit the index of the bit to set
82
*/
83
void setBit(MM_EnvironmentBase* env, volatile UDATA* bitVector, UDATA bit);
84
85
/**
86
* Determine if the specified gcRememberedSet field value represents an overflowed set.
87
* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field
88
* @return true if the remembered set is overflowed
89
*/
90
MMINLINE bool isOverflowedRemememberedSet(UDATA rememberedSet) { return UDATA_MAX == rememberedSet; }
91
92
/**
93
* Determine if the specified gcRememberedSet field value represents a tagged region index.
94
* Note that overflowed class loaders will return true!
95
* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field
96
* @return true if the remembered set is a tagged region index (or overflowed), false otherwise
97
*/
98
MMINLINE bool isTaggedRegionIndex(UDATA rememberedSet) { return 1 == (1 & rememberedSet); }
99
100
/**
101
* Convert the specified region index into a tagged value suitable to be stored in the gcRememberedSet field.
102
* @param regionIndex the index to store
103
* @return the tagged version of the index
104
*/
105
MMINLINE UDATA asTaggedRegionIndex(UDATA regionIndex) { return (regionIndex << 1) | 1; }
106
107
/**
108
* Convert a tagged region index back to the actual value
109
* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field
110
* @return the region index it represents
111
*/
112
MMINLINE UDATA asUntaggedRegionIndex(UDATA rememberedSet) { return rememberedSet >> 1; }
113
114
/**
115
* Determine if the specified bit is set in the specified bit vector.
116
* @param env[in] the current thread
117
* @param bitVector[in] the bit vector to test
118
* @param bit the index of the bit to test
119
* @return true if the bit is set, false otherwise
120
*/
121
bool isBitSet(MM_EnvironmentBase* env, volatile UDATA* bitVector, UDATA bit);
122
123
/**
124
* Implementation helper for rememberInstance() based on region index.
125
*
126
* @param env[in] the current thread
127
* @param regionIndex[in] the region index to remember
128
* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot
129
*/
130
void rememberRegionInternal(MM_EnvironmentBase* env, UDATA regionIndex, volatile UDATA *gcRememberedSetAddress);
131
132
/**
133
* Implementation helper for isRemembered().
134
*
135
* @param env[in] the current thread
136
* @param gcRememberedSet[in] gcRememberedSet slot
137
*/
138
bool isRememberedInternal(MM_EnvironmentBase *env, UDATA gcRememberedSet);
139
140
/**
141
* Implementation helper for isRemembered() based on region index.
142
*
143
* @param env[in] the current thread
144
* @param regionIndex[in] the region index to remember
145
* @param gcRememberedSet[in] gcRememberedSet slot
146
*/
147
bool isRegionRemembered(MM_EnvironmentBase *env, UDATA regionIndex, UDATA gcRememberedSet);
148
149
/**
150
* Implementation helper for killRememberedSet().
151
*
152
* @param env[in] the current thread
153
* @param gcRememberedSet[in] gcRememberedSet slot
154
*/
155
void killRememberedSetInternal(MM_EnvironmentBase *env, UDATA gcRememberedSet);
156
157
/**
158
* Implementation helper for clearRememberedSets().
159
*
160
* @param env[in] the current thread
161
* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot
162
*/
163
void clearRememberedSetsInternal(MM_EnvironmentBase *env, volatile UDATA *gcRememberedSetAddress);
164
165
protected:
166
public:
167
static MM_ClassLoaderRememberedSet *newInstance(MM_EnvironmentBase* env);
168
virtual void kill(MM_EnvironmentBase *env);
169
170
/*
171
* Initialize ClassLoaderRememberedSet
172
*/
173
bool initialize(MM_EnvironmentBase* env);
174
175
/*
176
* Teardown ClassLoaderRememberedSet
177
*/
178
virtual void tearDown(MM_EnvironmentBase* env);
179
180
/**
181
* Update the remembered set data for the specified object's class loader to record the object.
182
*
183
* The object's region and class loader are identified, and the relationship between them is recorded in the class loader.
184
*
185
* @param env[in] the current thread
186
* @param object[in] the object to remember
187
*/
188
void rememberInstance(MM_EnvironmentBase* env, J9Object* object);
189
190
/**
191
* Determine if there are any instances of classes defined by specified class loader.
192
* @param env[in] the current thread
193
* @param classLoader[in] the loader to examine
194
* @return true if there are instances (or the loader is overflowed), false otherwise
195
*/
196
bool isRemembered(MM_EnvironmentBase *env, J9ClassLoader *classLoader);
197
198
/**
199
* Determine if there are instances of anonymous class defined.
200
* @param env[in] the current thread
201
* @param clazz[in] the anonymous class to examine
202
* @return true if there are instances, false otherwise
203
*/
204
bool isClassRemembered(MM_EnvironmentBase *env, J9Class *clazz);
205
206
/**
207
* Determine if the specified object is remembered in its class loader.
208
* @note This is intended primarily for verification
209
* @param env[in] the current thread
210
* @param object[in] the object to test
211
* @return true if the object is properly remembered
212
*/
213
bool isInstanceRemembered(MM_EnvironmentBase *env, J9Object* object);
214
215
/**
216
* Delete any resources associated with the remembered set for the specified class loader.
217
* @param env[in] the current thread
218
* @param classLoader[in] the loader to modify
219
*/
220
void killRememberedSet(MM_EnvironmentBase *env, J9ClassLoader *classLoader);
221
222
/**
223
* Called before a partial GC to initialize the preserved regions bit vector.
224
* All bits are 1 (preserved) once this call completes.
225
* See also #prepareToClearRememberedSetForRegion() and #clearRememberedSets()
226
* @param env[in] the current thread
227
*/
228
void resetRegionsToClear(MM_EnvironmentBase *env);
229
230
/**
231
* Ensure that the remembered bits for the specified region will be cleared when #clearRememberedSets() is called.
232
* This may safely be called from multiple threads.
233
* @param env[in] the current thread
234
* @param region[in] a region which is part of the collection set and should be cleared
235
*/
236
void prepareToClearRememberedSetForRegion(MM_EnvironmentBase *env, MM_HeapRegionDescriptor *region);
237
238
/**
239
* Called before a partial GC to clear remembered sets in all class loaders for regions
240
* which have been marked using #prepareToClearRememberedSetForRegion()
241
* @param env[in] the current thread
242
*/
243
void clearRememberedSets(MM_EnvironmentBase *env);
244
245
/**
246
* Called by the main thread before a GC cycle to perform any setup required before a collection.
247
* @param env[in] the current thread
248
*/
249
void setupBeforeGC(MM_EnvironmentBase *env);
250
};
251
252
#endif /* CLASSLOADERREMEMBEREDSET_HPP */
253
254