Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/ObjectAccessBarrier.hpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2021 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_Base
26
*/
27
28
#if !defined(OBJECTACCESSBARRIER_HPP_)
29
#define OBJECTACCESSBARRIER_HPP_
30
31
#include "j9.h"
32
#include "j9cfg.h"
33
#include "modron.h"
34
35
#include <string.h>
36
37
#include "AtomicOperations.hpp"
38
#include "GCExtensions.hpp"
39
#include "Heap.hpp"
40
#include "ModronAssertions.h"
41
#include "ObjectModel.hpp"
42
43
/* These macros are temporary during the migration to the new object/indexable
44
* access barrier. Once the 'real' versions can be included these will be removed
45
*/
46
#define J9OAB_MIXEDOBJECT_EA(object, offset, type) (type *)(((U_8 *)(object)) + offset)
47
48
class MM_ObjectAccessBarrier : public MM_BaseVirtual
49
{
50
/* data members */
51
private:
52
protected:
53
MM_GCExtensions *_extensions;
54
MM_Heap *_heap;
55
#if defined(OMR_GC_COMPRESSED_POINTERS)
56
#if defined(OMR_GC_FULL_POINTERS)
57
bool _compressObjectReferences;
58
#endif /* defined(OMR_GC_FULL_POINTERS) */
59
UDATA _compressedPointersShift; /**< the number of bits to shift by when converting between the compressed pointers heap and real heap */
60
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
61
UDATA _referenceLinkOffset; /** Offset within java/lang/ref/Reference of the reference link field */
62
UDATA _ownableSynchronizerLinkOffset; /** Offset within java/util/concurrent/locks/AbstractOwnableSynchronizer of the ownable synchronizer link field */
63
public:
64
65
/* member function */
66
private:
67
/**
68
* Find the finalize link field in the specified object.
69
* @param object[in] the object
70
* @param clazz[in] the class to read the finalizeLinkOffset from
71
* @return a pointer to the finalize link field in the object
72
*/
73
MMINLINE fj9object_t* getFinalizeLinkAddress(j9object_t object, J9Class *clazz)
74
{
75
UDATA fieldOffset = clazz->finalizeLinkOffset;
76
if (0 == fieldOffset) {
77
return NULL;
78
}
79
return (fj9object_t*)((UDATA)object + fieldOffset);
80
}
81
82
protected:
83
virtual bool initialize(MM_EnvironmentBase *env);
84
virtual void tearDown(MM_EnvironmentBase *env);
85
86
/**
87
* Find the finalize link field in the specified object.
88
* @param object[in] the object
89
* @return a pointer to the finalize link field in the object
90
*/
91
MMINLINE fj9object_t* getFinalizeLinkAddress(j9object_t object)
92
{
93
J9Class *clazz = J9GC_J9OBJECT_CLAZZ(object, this);
94
return getFinalizeLinkAddress(object, clazz);
95
}
96
97
/**
98
* Effective address of array slot with a given slot index and slot size
99
* @param array the array for which the calculation is performed
100
* @param index the index of the slot for which address is returned
101
* @param elementSize size of the slot in the array
102
* @return address of the slot with the given index
103
*/
104
MMINLINE void *
105
indexableEffectiveAddress(J9VMThread *vmThread, J9IndexableObject *array, I_32 index, UDATA elementSize)
106
{
107
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(vmThread);
108
109
/* hybrid arraylet */
110
GC_ArrayletObjectModel::ArrayLayout layout = extensions->indexableObjectModel.getArrayLayout(array);
111
if (GC_ArrayletObjectModel::InlineContiguous == layout) {
112
UDATA data = (UDATA)extensions->indexableObjectModel.getDataPointerForContiguous(array);
113
return (void *)(data + (elementSize * (UDATA)index));
114
}
115
116
/* discontiguous arraylet */
117
fj9object_t *arrayoidPointer = extensions->indexableObjectModel.getArrayoidPointer(array);
118
U_32 slotsPerArrayletLeaf = (U_32)(J9VMTHREAD_JAVAVM(vmThread)->arrayletLeafSize / elementSize);
119
U_32 arrayletIndex = (U_32)index / slotsPerArrayletLeaf;
120
U_32 arrayletOffset = (U_32)index % slotsPerArrayletLeaf;
121
UDATA arrayletLeafBase = 0;
122
fj9object_t *arrayletLeafSlot = GC_SlotObject::addToSlotAddress(arrayoidPointer, arrayletIndex, compressObjectReferences());
123
if (compressObjectReferences()) {
124
arrayletLeafBase = (UDATA)convertPointerFromToken(*(U_32*)arrayletLeafSlot);
125
} else {
126
arrayletLeafBase = *(UDATA*)arrayletLeafSlot;
127
}
128
return (void *)(arrayletLeafBase + (elementSize * (UDATA)arrayletOffset));
129
}
130
131
virtual mm_j9object_t readObjectImpl(J9VMThread *vmThread, mm_j9object_t srcObject, fj9object_t *srcAddress, bool isVolatile=false);
132
virtual mm_j9object_t staticReadObjectImpl(J9VMThread *vmThread, J9Class *clazz, j9object_t *srcAddress, bool isVolatile=false);
133
virtual mm_j9object_t readObjectFromInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *srcAddress, bool isVolatile=false);
134
135
virtual void *readAddressImpl(J9VMThread *vmThread, mm_j9object_t srcObject, void **srcAddress, bool isVolatile=false);
136
virtual U_8 readU8Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_8 *srcAddress, bool isVolatile=false);
137
virtual I_8 readI8Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_8 *srcAddress, bool isVolatile=false);
138
virtual U_16 readU16Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_16 *srcAddress, bool isVolatile=false);
139
virtual I_16 readI16Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_16 *srcAddress, bool isVolatile=false);
140
virtual U_32 readU32Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_32 *srcAddress, bool isVolatile=false);
141
virtual I_32 readI32Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_32 *srcAddress, bool isVolatile=false);
142
virtual U_64 readU64Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_64 *srcAddress, bool isVolatile=false);
143
virtual I_64 readI64Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_64 *srcAddress, bool isVolatile=false);
144
145
virtual void storeObjectImpl(J9VMThread *vmThread, mm_j9object_t destObject, fj9object_t *destAddress, mm_j9object_t value, bool isVolatile=false);
146
virtual void staticStoreObjectImpl(J9VMThread *vmThread, J9Class* clazz, j9object_t *destAddress, mm_j9object_t value, bool isVolatile=false);
147
virtual void storeObjectToInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *destAddress, mm_j9object_t value, bool isVolatile=false);
148
149
virtual void storeAddressImpl(J9VMThread *vmThread, mm_j9object_t destObject, void **destAddress, void *value, bool isVolatile=false);
150
virtual void storeU8Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_8 *destAddress, U_8 value, bool isVolatile=false);
151
virtual void storeI8Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_8 *destAddress, I_8 value, bool isVolatile=false);
152
virtual void storeU16Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_16 *destAddress, U_16 value, bool isVolatile=false);
153
virtual void storeI16Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_16 *destAddress, I_16 value, bool isVolatile=false);
154
virtual void storeU32Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_32 *destAddress, U_32 value, bool isVolatile=false);
155
virtual void storeI32Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_32 *destAddress, I_32 value, bool isVolatile=false);
156
virtual void storeU64Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_64 *destAddress, U_64 value, bool isVolatile=false);
157
virtual void storeI64Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_64 *destAddress, I_64 value, bool isVolatile=false);
158
159
void protectIfVolatileBefore(J9VMThread *vmThread, bool isVolatile, bool isRead, bool isWide);
160
void protectIfVolatileAfter(J9VMThread *vmThread, bool isVolatile, bool isRead, bool isWide);
161
void printNativeMethod(J9VMThread* vmThread);
162
163
public:
164
virtual void kill(MM_EnvironmentBase *env);
165
166
virtual J9Object *mixedObjectReadObject(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
167
virtual void *mixedObjectReadAddress(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
168
virtual U_32 mixedObjectReadU32(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
169
virtual I_32 mixedObjectReadI32(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
170
virtual U_64 mixedObjectReadU64(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
171
virtual I_64 mixedObjectReadI64(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile=false);
172
173
virtual void mixedObjectStoreObject(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, J9Object *value, bool isVolatile=false);
174
virtual void mixedObjectStoreAddress(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, void *value, bool isVolatile=false);
175
virtual void mixedObjectStoreU32(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, U_32 value, bool isVolatile=false);
176
virtual void mixedObjectStoreI32(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, I_32 value, bool isVolatile=false);
177
virtual void mixedObjectStoreU64(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, U_64 value, bool isVolatile=false);
178
virtual void mixedObjectStoreI64(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, I_64 value, bool isVolatile=false);
179
180
virtual J9Object *indexableReadObject(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
181
virtual void *indexableReadAddress(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
182
virtual U_8 indexableReadU8(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
183
virtual I_8 indexableReadI8(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
184
virtual U_16 indexableReadU16(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
185
virtual I_16 indexableReadI16(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
186
virtual U_32 indexableReadU32(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
187
virtual I_32 indexableReadI32(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
188
virtual U_64 indexableReadU64(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
189
virtual I_64 indexableReadI64(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile=false);
190
191
virtual void indexableStoreObject(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, J9Object *value, bool isVolatile=false);
192
virtual void indexableStoreAddress(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, void *value, bool isVolatile=false);
193
virtual void indexableStoreU8(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, U_8 value, bool isVolatile=false);
194
virtual void indexableStoreI8(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, I_8 value, bool isVolatile=false);
195
virtual void indexableStoreU16(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, U_16 value, bool isVolatile=false);
196
virtual void indexableStoreI16(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, I_16 value, bool isVolatile=false);
197
virtual void indexableStoreU32(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, U_32 value, bool isVolatile=false);
198
virtual void indexableStoreI32(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, I_32 value, bool isVolatile=false);
199
virtual void indexableStoreU64(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, U_64 value, bool isVolatile=false);
200
virtual void indexableStoreI64(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, I_64 value, bool isVolatile=false);
201
virtual void copyObjectFieldsToFlattenedArrayElement(J9VMThread *vmThread, J9ArrayClass *arrayClazz, j9object_t srcObject, J9IndexableObject *arrayRef, I_32 index);
202
virtual void copyObjectFieldsFromFlattenedArrayElement(J9VMThread *vmThread, J9ArrayClass *arrayClazz, j9object_t destObject, J9IndexableObject *arrayRef, I_32 index);
203
204
enum {
205
ARRAY_COPY_SUCCESSFUL = -1,
206
ARRAY_COPY_NOT_DONE = -2
207
};
208
209
virtual I_32 doCopyContiguousForward(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);
210
virtual I_32 doCopyContiguousBackward(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);
211
virtual I_32 backwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots) { return -2; }
212
virtual I_32 forwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots) { return -2; }
213
214
virtual J9Object *staticReadObject(J9VMThread *vmThread, J9Class *clazz, J9Object **srcSlot, bool isVolatile=false);
215
virtual void *staticReadAddress(J9VMThread *vmThread, J9Class *clazz, void **srcSlot, bool isVolatile=false);
216
virtual U_32 staticReadU32(J9VMThread *vmThread, J9Class *clazz, U_32 *srcSlot, bool isVolatile=false);
217
virtual I_32 staticReadI32(J9VMThread *vmThread, J9Class *clazz, I_32 *srcSlot, bool isVolatile=false);
218
virtual U_64 staticReadU64(J9VMThread *vmThread, J9Class *clazz, U_64 *srcSlot, bool isVolatile=false);
219
virtual I_64 staticReadI64(J9VMThread *vmThread, J9Class *clazz, I_64 *srcSlot, bool isVolatile=false);
220
221
virtual void staticStoreObject(J9VMThread *vmThread, J9Class *clazz, J9Object **destSlot, J9Object *value, bool isVolatile=false);
222
virtual void staticStoreAddress(J9VMThread *vmThread, J9Class *clazz, void **destSlot, void *value, bool isVolatile=false);
223
virtual void staticStoreU32(J9VMThread *vmThread, J9Class *clazz, U_32 *destSlot, U_32 value, bool isVolatile=false);
224
virtual void staticStoreI32(J9VMThread *vmThread, J9Class *clazz, I_32 *destSlot, I_32 value, bool isVolatile=false);
225
virtual void staticStoreU64(J9VMThread *vmThread, J9Class *clazz, U_64 *destSlot, U_64 value, bool isVolatile=false);
226
virtual void staticStoreI64(J9VMThread *vmThread, J9Class *clazz, I_64 *destSlot, I_64 value, bool isVolatile=false);
227
228
virtual U_8 *getArrayObjectDataAddress(J9VMThread *vmThread, J9IndexableObject *arrayObject);
229
virtual j9objectmonitor_t *getLockwordAddress(J9VMThread *vmThread, J9Object *object);
230
virtual void cloneObject(J9VMThread *vmThread, J9Object *srcObject, J9Object *destObject);
231
virtual void copyObjectFields(J9VMThread *vmThread, J9Class *valueClass, J9Object *srcObject, UDATA srcOffset, J9Object *destObject, UDATA destOffset);
232
virtual BOOLEAN structuralCompareFlattenedObjects(J9VMThread *vmThread, J9Class *valueClass, j9object_t lhsObject, j9object_t rhsObject, UDATA startOffset);
233
virtual void cloneIndexableObject(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject);
234
virtual J9Object *asConstantPoolObject(J9VMThread *vmThread, J9Object* toConvert, UDATA allocationFlags);
235
virtual void storeObjectToInternalVMSlot(J9VMThread *vmThread, J9Object** destSlot, J9Object *value);
236
virtual J9Object *readObjectFromInternalVMSlot(J9VMThread *vmThread, J9Object **srcSlot);
237
virtual bool compareAndSwapObject(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *compareObject, J9Object *swapObject);
238
virtual bool staticCompareAndSwapObject(J9VMThread *vmThread, J9Class *destClass, j9object_t *destAddress, J9Object *compareObject, J9Object *swapObject);
239
virtual bool mixedObjectCompareAndSwapInt(J9VMThread *vmThread, J9Object *destObject, UDATA offset, U_32 compareValue, U_32 swapValue);
240
virtual bool staticCompareAndSwapInt(J9VMThread *vmThread, J9Class *destClass, U_32 *destAddress, U_32 compareValue, U_32 swapValue);
241
virtual bool mixedObjectCompareAndSwapLong(J9VMThread *vmThread, J9Object *destObject, UDATA offset, U_64 compareValue, U_64 swapValue);
242
virtual bool staticCompareAndSwapLong(J9VMThread *vmThread, J9Class *destClass, U_64 *destAddress, U_64 compareValue, U_64 swapValue);
243
virtual J9Object *compareAndExchangeObject(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *compareObject, J9Object *swapObject);
244
virtual J9Object *staticCompareAndExchangeObject(J9VMThread *vmThread, J9Class *destClass, j9object_t *destAddress, J9Object *compareObject, J9Object *swapObject);
245
virtual U_32 mixedObjectCompareAndExchangeInt(J9VMThread *vmThread, J9Object *destObject, UDATA offset, U_32 compareValue, U_32 swapValue);
246
virtual U_32 staticCompareAndExchangeInt(J9VMThread *vmThread, J9Class *destClass, U_32 *destAddress, U_32 compareValue, U_32 swapValue);
247
virtual U_64 mixedObjectCompareAndExchangeLong(J9VMThread *vmThread, J9Object *destObject, UDATA offset, U_64 compareValue, U_64 swapValue);
248
virtual U_64 staticCompareAndExchangeLong(J9VMThread *vmThread, J9Class *destClass, U_64 *destAddress, U_64 compareValue, U_64 swapValue);
249
250
virtual void deleteHeapReference(MM_EnvironmentBase *env, J9Object *object) {}
251
252
virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile=false);
253
virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destClass, J9Object **destAddress, J9Object *value, bool isVolatile=false);
254
virtual bool preObjectStore(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile=false);
255
virtual void postObjectStore(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile=false);
256
virtual void postObjectStore(J9VMThread *vmThread, J9Class *destClass, J9Object **destAddress, J9Object *value, bool isVolatile=false);
257
virtual void postObjectStore(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile=false);
258
259
virtual bool postBatchObjectStore(J9VMThread *vmThread, J9Object *destObject, bool isVolatile=false);
260
virtual bool postBatchObjectStore(J9VMThread *vmThread, J9Class *destClass, bool isVolatile=false);
261
262
virtual bool preObjectRead(J9VMThread *vmThread, J9Object *srcObject, fj9object_t *srcAddress);
263
virtual bool preObjectRead(J9VMThread *vmThread, J9Class *srcClass, j9object_t *srcAddress);
264
virtual bool preWeakRootSlotRead(J9VMThread *vmThread, j9object_t *srcAddress);
265
virtual bool preWeakRootSlotRead(J9JavaVM *vm, j9object_t *srcAddress);
266
virtual bool postObjectRead(J9VMThread *vmThread, J9Object *srcObject, fj9object_t *srcAddress);
267
virtual bool postObjectRead(J9VMThread *vmThread, J9Class *srcClass, J9Object **srcAddress);
268
269
/**
270
* Return back true if object references are compressed
271
* @return true, if object references are compressed
272
*/
273
MMINLINE bool
274
compressObjectReferences()
275
{
276
return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);
277
}
278
279
/**
280
* Special barrier for auto-remembering stack-referenced objects. This must be called
281
* in two cases:
282
* 1) an object which was allocated directly into old space.
283
* 2) an object which is being constructed via JNI
284
*
285
* @param vmThread[in] the current thread
286
* @param object[in] the object to be remembered
287
*/
288
virtual void
289
recentlyAllocatedObject(J9VMThread *vmThread, J9Object *object)
290
{
291
/* empty default implementation */
292
};
293
294
/**
295
* Record that the specified class is stored in the specified ClassLoader.
296
* There are three cases in which this must be called:
297
* 1 - when a newly loaded class stored in its defining loader's table
298
* 2 - when a newly loaded array class is stored in its component class's arrayClass field
299
* 3 - when a foreign class is stored in another loader's table
300
*
301
* @param[in] vmThread the current thread
302
* @param[in] destClassLoader the referencing ClassLoader
303
* @param[in] srcClass the referenced class
304
*/
305
virtual void
306
postStoreClassToClassLoader(J9VMThread *vmThread, J9ClassLoader* destClassLoader, J9Class* srcClass)
307
{
308
/* Default behaviour is to do nothing. Only collectors which implement JAZZ 18309 require this barrier. */
309
}
310
311
/**
312
* Converts token (e.g. compressed pointer value) into real heap pointer.
313
* @return the heap pointer value.
314
*
315
* @note this function is not virtual because it must be callable from out-of-process
316
*/
317
MMINLINE mm_j9object_t
318
convertPointerFromToken(fj9object_t token)
319
{
320
mm_j9object_t result = (mm_j9object_t)(uintptr_t)token;
321
#if defined(OMR_GC_COMPRESSED_POINTERS)
322
if (compressObjectReferences()) {
323
result = (mm_j9object_t)((UDATA)token << compressedPointersShift());
324
}
325
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
326
return result;
327
}
328
329
/**
330
* Converts real heap pointer into token (e.g. compressed pointer value).
331
* @return the compressed pointer value.
332
*
333
* @note this function is not virtual because it must be callable from out-of-process
334
*/
335
MMINLINE fj9object_t
336
convertTokenFromPointer(mm_j9object_t pointer)
337
{
338
fj9object_t result = (fj9object_t)(uintptr_t)pointer;
339
#if defined(OMR_GC_COMPRESSED_POINTERS)
340
if (compressObjectReferences()) {
341
result = (fj9object_t)((UDATA)pointer >> compressedPointersShift());
342
}
343
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
344
return result;
345
}
346
347
/**
348
* Returns the value to shift a pointer by when converting between the compressed pointers heap and real heap
349
* @return The shift value.
350
*
351
* @note this function is not virtual because it must be callable from out-of-process
352
*
353
*/
354
MMINLINE UDATA
355
compressedPointersShift()
356
{
357
UDATA shift = 0;
358
#if defined(OMR_GC_COMPRESSED_POINTERS)
359
if (compressObjectReferences()) {
360
shift = _compressedPointersShift;
361
}
362
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
363
return shift;
364
}
365
366
virtual UDATA compressedPointersShadowHeapBase(J9VMThread *vmThread);
367
virtual UDATA compressedPointersShadowHeapTop(J9VMThread *vmThread);
368
virtual void fillArrayOfObjects(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, I_32 count, J9Object *value);
369
370
virtual void initializeForNewThread(MM_EnvironmentBase* env) {};
371
372
/**
373
* Determine the basic hash code for the specified object. This may modify the object. For example, it may
374
* set the HAS_BEEN_HASHED bit in the object's header. Object must not be NULL.
375
*
376
* @param vm[in] the VM
377
* @param object[in] the object to be hashed
378
* @return the persistent, basic hash code for the object
379
*/
380
I_32 getObjectHashCode(J9JavaVM *vm, J9Object *object);
381
382
/**
383
* Set the finalize link field of object to value.
384
* @param object the object to modify
385
* @param value[in] the value to store into the object's finalizeLink field
386
*/
387
void setFinalizeLink(j9object_t object, j9object_t value);
388
389
/**
390
* Fetch the finalize link field of object.
391
* @param object[in] the object to read
392
* @return the value stored in the object's finalizeLink field
393
*/
394
MMINLINE j9object_t getFinalizeLink(j9object_t object)
395
{
396
fj9object_t* finalizeLink = getFinalizeLinkAddress(object);
397
GC_SlotObject slot(_extensions->getOmrVM(), finalizeLink);
398
return slot.readReferenceFromSlot();
399
}
400
401
/**
402
* Fetch the finalize link field of object.
403
* @param object[in] the object to read
404
* @param clazz[in] the class to read the finalizeLinkOffset from
405
* @return the value stored in the object's finalizeLink field
406
*/
407
MMINLINE j9object_t getFinalizeLink(j9object_t object, J9Class *clazz)
408
{
409
fj9object_t* finalizeLink = getFinalizeLinkAddress(object, clazz);
410
GC_SlotObject slot(_extensions->getOmrVM(), finalizeLink);
411
return slot.readReferenceFromSlot();
412
}
413
414
415
/**
416
* Set the reference link field of the specified reference object to value.
417
* @param object the object to modify
418
* @param value the value to store into the object's reference link field
419
*/
420
void setReferenceLink(j9object_t object, j9object_t value);
421
422
/**
423
* Fetch the reference link field of the specified reference object.
424
* @param object the object to read
425
* @return the value stored in the object's reference link field
426
*/
427
j9object_t getReferenceLink(j9object_t object)
428
{
429
UDATA linkOffset = _referenceLinkOffset;
430
fj9object_t *referenceLink = (fj9object_t*)((UDATA)object + linkOffset);
431
GC_SlotObject slot(_extensions->getOmrVM(), referenceLink);
432
return slot.readReferenceFromSlot();
433
}
434
435
/**
436
* Set the ownableSynchronizerLink link field of the specified reference object to value.
437
* @param object the object to modify
438
* @param value the value to store into the object's reference link field
439
*/
440
void setOwnableSynchronizerLink(j9object_t object, j9object_t value);
441
442
/**
443
* Fetch the ownableSynchronizerLink link field of the specified reference object.(for Compact or forwardedObject case)
444
* @param object the object(moved object -- new location) to read
445
* @param originalObject(old location, for checking if it is the last item in the list)
446
* @return the value stored in the object's reference link field
447
*/
448
j9object_t getOwnableSynchronizerLink(j9object_t object, j9object_t originalObject)
449
{
450
UDATA linkOffset = _ownableSynchronizerLinkOffset;
451
fj9object_t *ownableSynchronizerLink = (fj9object_t*)((UDATA)object + linkOffset);
452
GC_SlotObject slot(_extensions->getOmrVM(), ownableSynchronizerLink);
453
j9object_t next = slot.readReferenceFromSlot();
454
if (originalObject == next) {
455
/* reach end of list(last item points to itself), return NULL */
456
next = NULL;
457
}
458
return next;
459
}
460
461
/**
462
* Fetch the ownableSynchronizerLink link field of the specified reference object.
463
* @param object the object to read
464
* @return the value stored in the object's reference link field
465
*/
466
j9object_t getOwnableSynchronizerLink(j9object_t object)
467
{
468
UDATA linkOffset = _ownableSynchronizerLinkOffset;
469
fj9object_t *ownableSynchronizerLink = (fj9object_t*)((UDATA)object + linkOffset);
470
GC_SlotObject slot(_extensions->getOmrVM(), ownableSynchronizerLink);
471
j9object_t next = slot.readReferenceFromSlot();
472
if (object == next) {
473
/* reach end of list(last item points to itself), return NULL */
474
next = NULL;
475
}
476
return next;
477
}
478
479
/**
480
* check if the object in one of OwnableSynchronizerLists
481
* @param object the object pointer
482
* @return the value stored in the object's reference link field
483
* if reference link field == NULL, it means the object isn't in the list
484
*/
485
j9object_t isObjectInOwnableSynchronizerList(j9object_t object)
486
{
487
UDATA linkOffset = _ownableSynchronizerLinkOffset;
488
fj9object_t *ownableSynchronizerLink = (fj9object_t*)((UDATA)object + linkOffset);
489
GC_SlotObject slot(_extensions->getOmrVM(), ownableSynchronizerLink);
490
return slot.readReferenceFromSlot();
491
}
492
493
/**
494
* Implementation of the JNI GetPrimitiveArrayCritical API.
495
* See the JNI spec for full details.
496
*
497
* @param vmThread current J9VMThread (aka JNIEnv)
498
* @param array a JNI reference to the primitive array
499
* @param isCopy NULL, or a pointer to a jboolean that will set to JNI_TRUE if a copy is made
500
* @return a pointer to the array data; this may be a malloc'd copy, or a pointer into the heap
501
*/
502
virtual void* jniGetPrimitiveArrayCritical(J9VMThread* vmThread, jarray array, jboolean *isCopy) = 0;
503
/**
504
* Implementation of the JNI ReleasePrimitiveArrayCritical API.
505
* See the JNI spec for full details.
506
*
507
* @param vmThread current J9VMThread (aka JNIEnv)
508
* @param array a JNI reference to the primitive array
509
* @param elems the pointer returned by GetPrimitiveArrayCritical
510
* @param mode how to handle the data; only valid for copied data
511
*/
512
virtual void jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, jarray array, void * elems, jint mode) = 0;
513
/**
514
* Implementation of the JNI GetStringCritical API.
515
* See the JNI spec for full details.
516
*
517
* @param vmThread current J9VMThread (aka JNIEnv)
518
* @param str a JNI reference to the java/lang/String object
519
* @param isCopy NULL, or a pointer to a jboolean that will set to JNI_TRUE if a copy is made
520
* @return a pointer to the character data; this may be a malloc'd copy, or a pointer into the heap
521
*/
522
virtual const jchar* jniGetStringCritical(J9VMThread* vmThread, jstring str, jboolean *isCopy) = 0;
523
/**
524
* Implementation of the JNI ReleaseStringCritical API.
525
* See the JNI spec for full details.
526
*
527
* @param vmThread current J9VMThread (aka JNIEnv)
528
* @param array a JNI reference to the java/lang/String object
529
* @param elems the pointer returned by GetStringCritical
530
*/
531
virtual void jniReleaseStringCritical(J9VMThread* vmThread, jstring str, const jchar* elems) = 0;
532
/**
533
* Process objects that are forced onto the finalizable list at shutdown.
534
* Called from FinalizerSupport finalizeForcedUnfinalizedToFinalizable
535
*
536
* @param vmThread current J9VMThread (aka JNIEnv)
537
* @param object object forced onto the finalizable list
538
*/
539
virtual void forcedToFinalizableObject(J9VMThread* vmThread, J9Object *object)
540
{
541
/* no-op default implementation */
542
}
543
544
virtual J9Object *referenceGet(J9VMThread *vmThread, J9Object *refObject)
545
{
546
return J9VMJAVALANGREFREFERENCE_REFERENT_VM(vmThread->javaVM, refObject);
547
}
548
549
virtual void referenceReprocess(J9VMThread *vmThread, J9Object *refObject)
550
{
551
/* no-op default implementation */
552
}
553
554
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
555
/**
556
* Check is class alive
557
* Required to prevent visibility of dead classes in incremental GC policies
558
* The real implementation done for Real Time GC
559
* @param javaVM pointer to J9JavaVM
560
* @param classPtr class to check
561
* @return true if class is alive
562
*/
563
virtual bool checkClassLive(J9JavaVM *javaVM, J9Class *classPtr)
564
{
565
return true;
566
}
567
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
568
569
virtual bool checkStringConstantsLive(J9JavaVM *javaVM, j9object_t stringOne, j9object_t stringTwo)
570
{
571
return true;
572
}
573
574
virtual bool checkStringConstantLive(J9JavaVM *javaVM, j9object_t string)
575
{
576
return true;
577
}
578
579
virtual void jniDeleteGlobalReference(J9VMThread *vmThread, J9Object *reference)
580
{
581
/* no-op default implementation */
582
}
583
584
MM_ObjectAccessBarrier(MM_EnvironmentBase *env) : MM_BaseVirtual()
585
, _extensions(NULL)
586
, _heap(NULL)
587
#if defined(OMR_GC_COMPRESSED_POINTERS)
588
#if defined(OMR_GC_FULL_POINTERS)
589
, _compressObjectReferences(false)
590
#endif /* defined(OMR_GC_FULL_POINTERS) */
591
, _compressedPointersShift(0)
592
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
593
, _referenceLinkOffset(UDATA_MAX)
594
, _ownableSynchronizerLinkOffset(UDATA_MAX)
595
{
596
_typeId = __FUNCTION__;
597
}
598
599
friend class MM_ScavengerDelegate;
600
};
601
602
#endif /* OBJECTACCESSBARRIER_HPP_ */
603
604