Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_realtime/RealtimeAccessBarrier.hpp
5986 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
#if !defined(REALTIMEACCESSBARRIER_HPP_)
25
#define REALTIMEACCESSBARRIER_HPP_
26
27
#include "j9.h"
28
#include "j9cfg.h"
29
30
#if defined(J9VM_GC_REALTIME)
31
32
#include "Metronome.hpp"
33
#include "ObjectAccessBarrier.hpp"
34
#include "RememberedSetSATB.hpp"
35
36
class MM_EnvironmentBase;
37
class MM_EnvironmentRealtime;
38
class MM_RealtimeMarkingScheme;
39
class MM_RealtimeGC;
40
41
/**
42
* Base access barrier for the realtime collectors.
43
* The realtime collectors may use objects during a GC phase, and relies on the
44
* access barrier to ensure that mutator threads only ever see objects in their
45
* new location. This is implemented using a forwarding pointer in each object
46
* that normally points to the object itself, but after an object has been
47
* moved, points to the new location. This class also implements the snapshot
48
* at the beginning barrier that remembers overwritten values.
49
*/
50
51
class MM_RealtimeAccessBarrier : public MM_ObjectAccessBarrier
52
{
53
/* Data members & types */
54
public:
55
protected:
56
MM_RealtimeMarkingScheme *_markingScheme;
57
MM_RealtimeGC *_realtimeGC;
58
59
private:
60
bool _doubleBarrierActive; /**< Global indicator that the double barrier is active. New threads will be set to double barrier mode if this falg is true. */
61
62
/* Methods */
63
public:
64
/* Constructors & destructors */
65
MM_RealtimeAccessBarrier(MM_EnvironmentBase *env) :
66
MM_ObjectAccessBarrier(env),
67
_markingScheme(NULL),
68
_realtimeGC(NULL)
69
{
70
_typeId = __FUNCTION__;
71
}
72
73
/* Inherited from MM_ObjectAccessBarrier */
74
virtual J9Object* referenceGet(J9VMThread *vmThread, J9Object *refObject);
75
virtual void referenceReprocess(J9VMThread *vmThread, J9Object *refObject);
76
77
virtual void jniDeleteGlobalReference(J9VMThread *vmThread, J9Object *reference);
78
virtual void stringConstantEscaped(J9VMThread *vmThread, J9Object *stringConst);
79
virtual void deleteHeapReference(MM_EnvironmentBase *env, J9Object *object);
80
81
virtual void storeObjectToInternalVMSlot(J9VMThread *vmThread, J9Object** destSlot, J9Object *value);
82
83
virtual void* jniGetPrimitiveArrayCritical(J9VMThread* vmThread, jarray array, jboolean *isCopy);
84
virtual void jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, jarray array, void * elems, jint mode);
85
virtual const jchar* jniGetStringCritical(J9VMThread* vmThread, jstring str, jboolean *isCopy);
86
virtual void jniReleaseStringCritical(J9VMThread* vmThread, jstring str, const jchar* elems);
87
88
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
89
/**
90
* Check is class alive
91
* Required to prevent visibility of dead classes in incremental GC policies
92
* Check is J9_GC_CLASS_LOADER_DEAD flag set for classloader and try to mark
93
* class loader object if bit is not set to force class to be alive
94
* @param javaVM pointer to J9JavaVM
95
* @param classPtr class to check
96
* @return true if class is alive
97
*/
98
virtual bool checkClassLive(J9JavaVM *javaVM, J9Class *classPtr);
99
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
100
101
protected:
102
/* Constructors & destructors */
103
virtual bool initialize(MM_EnvironmentBase *env);
104
virtual void tearDown(MM_EnvironmentBase *env);
105
virtual void kill(MM_EnvironmentBase *env);
106
107
/* Inherited from MM_ObjectAccessBarrier */
108
virtual mm_j9object_t readObjectFromInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *srcAddress, bool isVolatile=false);
109
110
/* New methods */
111
void validateWriteBarrier(J9VMThread *vmThread, J9Object *dstObject, fj9object_t *dstAddress, J9Object *srcObject);
112
virtual void rememberObjectImpl(MM_EnvironmentBase *env, J9Object *object);
113
114
private:
115
/* New methods */
116
void rememberObject(MM_EnvironmentBase *env, J9Object *object);
117
void rememberObjectIfBarrierEnabled(J9VMThread *vmThread, J9Object* object);
118
119
bool preObjectStoreInternal(J9VMThread *vmThread, J9Object *destClass, J9Object **destAddress, J9Object *value, bool isVolatile);
120
bool preObjectStoreInternal(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile);
121
bool preObjectStoreInternal(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile);
122
123
MMINLINE bool isBarrierActive(MM_EnvironmentBase* env)
124
{
125
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
126
return !extensions->sATBBarrierRememberedSet->isGlobalFragmentIndexPreserved();
127
}
128
129
MMINLINE bool isDoubleBarrierActiveOnThread(J9VMThread *vmThread)
130
{
131
/* The double barrier is enabled in realtime by setting the threads remembered set fragment index
132
* to the special value, this ensures the JIT will go out-of line. We can determine if the double
133
* barrier is active simply by checking if the fragment index corresponds to the special value.
134
*/
135
return (J9GC_REMEMBERED_SET_RESERVED_INDEX == vmThread->sATBBarrierRememberedSetFragment.localFragmentIndex);
136
}
137
138
bool markAndScanContiguousArray(MM_EnvironmentRealtime *env, J9IndexableObject *objectPtr);
139
void scanContiguousArray(MM_EnvironmentRealtime *env, J9IndexableObject *objectPtr);
140
141
public:
142
static MM_RealtimeAccessBarrier *newInstance(MM_EnvironmentBase *env);
143
MMINLINE void setDoubleBarrierActive() { _doubleBarrierActive = true; }
144
MMINLINE void setDoubleBarrierInactive() { _doubleBarrierActive = false; }
145
MMINLINE bool isDoubleBarrierActive() { return _doubleBarrierActive; }
146
void setDoubleBarrierActiveOnThread(MM_EnvironmentBase* env);
147
void setDoubleBarrierInactiveOnThread(MM_EnvironmentBase* env);
148
virtual void initializeForNewThread(MM_EnvironmentBase* env);
149
150
virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destObject, fj9object_t *destAddress, J9Object *value, bool isVolatile=false);
151
virtual bool preObjectStore(J9VMThread *vmThread, J9Object *destClass, J9Object **destAddress, J9Object *value, bool isVolatile=false);
152
virtual bool preObjectStore(J9VMThread *vmThread, J9Object **destAddress, J9Object *value, bool isVolatile=false);
153
154
virtual I_32 backwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);
155
virtual I_32 forwardReferenceArrayCopyIndex(J9VMThread *vmThread, J9IndexableObject *srcObject, J9IndexableObject *destObject, I_32 srcIndex, I_32 destIndex, I_32 lengthInSlots);
156
157
virtual bool checkStringConstantsLive(J9JavaVM *javaVM, j9object_t stringOne, j9object_t stringTwo);
158
virtual bool checkStringConstantLive(J9JavaVM *javaVM, j9object_t string);
159
160
/**
161
* Remember objects that are forced onto the finalizable list at shutdown.
162
* Called from FinalizerSupport finalizeForcedUnfinalizedToFinalizable
163
*
164
* @param vmThread current J9VMThread (aka JNIEnv)
165
* @param object object forced onto the finalizable list
166
*/
167
virtual void forcedToFinalizableObject(J9VMThread* vmThread, J9Object *object);
168
169
private:
170
void printClass(J9JavaVM *javaVM, J9Class* clazz);
171
};
172
173
#endif /* J9VM_GC_REALTIME */
174
175
#endif /*REALTIMEACCESSBARRIER_HPP_*/
176
177