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
267
268
269
270
271
272
273
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#ifndef __GCTOENV_EE_STANDALONE_INL__
#define __GCTOENV_EE_STANDALONE_INL__
#include "gcinterface.h"
// The singular interface instance. All calls in GCToEEInterface
// will be fowarded to this interface instance.
extern IGCToCLR* g_theGCToCLR;
namespace
{
#include "env/gcenv.ee.h"
// A note about this:
// In general, we don't want to pretend to be smarter than the compiler
// and force it to inline things. However, inlining is here is required
// for correctness as it stands today (though it will not always be required).
//
// The reason for this is because:
// 1) This file (and the GCToEEInterface class) define symbols that are inline
// and static, so the symbol GCToEEInterface::XYZ defines a symbol with weak
// linkage when the function is not inlined,
// 2) src/vm/gcenv.ee.cpp all define symbols that are not inline and instance methods
// of GCToEEInterface, with external linkage.
// 3) When it comes time to link the GC and the VM, the linker observes the duplicate
// symbols and discards the one with weak linkage.
// 4) All of the calls within the GC to the functions in this file are replaced by
// the linker to calls to the implementation of a pure virtual IGCToCLR. The
// functions implementing IGCToCLR have an extra argument (this).
// 5) Now, all calls to these functions from within the GC are doomed because of the
// functions that actually get called expect this to be in rdi, where the compiler
// has placed the first argument instead.
//
// For now, by forcing the compiler to inline these functions, the compiler won't actually
// emit symbols for them and we'll avoid the linker havoc.
#ifdef _MSC_VER
#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#endif
// When we are building the GC in a standalone environment, we
// will be dispatching virtually against g_theGCToCLR to call
// into the EE. This class provides an identical API to the existing
// GCToEEInterface, but only forwards the call onto the global
// g_theGCToCLR instance.
ALWAYS_INLINE void GCToEEInterface::SuspendEE(SUSPEND_REASON reason)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->SuspendEE(reason);
}
ALWAYS_INLINE void GCToEEInterface::RestartEE(bool bFinishedGC)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->RestartEE(bFinishedGC);
}
ALWAYS_INLINE void GCToEEInterface::GcScanRoots(promote_func* fn, int condemned, int max_gen, ScanContext* sc)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->GcScanRoots(fn, condemned, max_gen, sc);
}
ALWAYS_INLINE void GCToEEInterface::GcStartWork(int condemned, int max_gen)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->GcStartWork(condemned, max_gen);
}
ALWAYS_INLINE void GCToEEInterface::AfterGcScanRoots(int condemned, int max_gen, ScanContext* sc)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->AfterGcScanRoots(condemned, max_gen, sc);
}
ALWAYS_INLINE void GCToEEInterface::GcBeforeBGCSweepWork()
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->GcBeforeBGCSweepWork();
}
ALWAYS_INLINE void GCToEEInterface::GcDone(int condemned)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->GcDone(condemned);
}
ALWAYS_INLINE bool GCToEEInterface::RefCountedHandleCallbacks(Object * pObject)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->RefCountedHandleCallbacks(pObject);
}
ALWAYS_INLINE void GCToEEInterface::SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->SyncBlockCacheWeakPtrScan(scanProc, lp1, lp2);
}
ALWAYS_INLINE void GCToEEInterface::SyncBlockCacheDemote(int max_gen)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->SyncBlockCacheDemote(max_gen);
}
ALWAYS_INLINE void GCToEEInterface::SyncBlockCachePromotionsGranted(int max_gen)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->SyncBlockCachePromotionsGranted(max_gen);
}
ALWAYS_INLINE bool GCToEEInterface::IsPreemptiveGCDisabled(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->IsPreemptiveGCDisabled(pThread);
}
ALWAYS_INLINE void GCToEEInterface::EnablePreemptiveGC(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->EnablePreemptiveGC(pThread);
}
ALWAYS_INLINE void GCToEEInterface::DisablePreemptiveGC(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DisablePreemptiveGC(pThread);
}
ALWAYS_INLINE gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetAllocContext(pThread);
}
ALWAYS_INLINE bool GCToEEInterface::CatchAtSafePoint(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->CatchAtSafePoint(pThread);
}
ALWAYS_INLINE void GCToEEInterface::GcEnumAllocContexts(enum_alloc_context_func* fn, void* param)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->GcEnumAllocContexts(fn, param);
}
ALWAYS_INLINE Thread* GCToEEInterface::CreateBackgroundThread(GCBackgroundThreadFunction threadStart, void* arg)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->CreateBackgroundThread(threadStart, arg);
}
ALWAYS_INLINE void GCToEEInterface::DiagGCStart(int gen, bool isInduced)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagGCStart(gen, isInduced);
}
ALWAYS_INLINE void GCToEEInterface::DiagUpdateGenerationBounds()
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagUpdateGenerationBounds();
}
ALWAYS_INLINE void GCToEEInterface::DiagGCEnd(size_t index, int gen, int reason, bool fConcurrent)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagGCEnd(index, gen, reason, fConcurrent);
}
ALWAYS_INLINE void GCToEEInterface::DiagWalkFReachableObjects(void* gcContext)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagWalkFReachableObjects(gcContext);
}
ALWAYS_INLINE void GCToEEInterface::DiagWalkSurvivors(void* gcContext)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagWalkSurvivors(gcContext);
}
ALWAYS_INLINE void GCToEEInterface::DiagWalkLOHSurvivors(void* gcContext)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->DiagWalkLOHSurvivors(gcContext);
}
ALWAYS_INLINE void GCToEEInterface::DiagWalkBGCSurvivors(void* gcContext)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->DiagWalkBGCSurvivors(gcContext);
}
ALWAYS_INLINE void GCToEEInterface::StompWriteBarrier(WriteBarrierParameters* args)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->StompWriteBarrier(args);
}
ALWAYS_INLINE void GCToEEInterface::EnableFinalization(bool foundFinalizers)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->EnableFinalization(foundFinalizers);
}
ALWAYS_INLINE void GCToEEInterface::HandleFatalError(unsigned int exitCode)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->HandleFatalError(exitCode);
}
ALWAYS_INLINE bool GCToEEInterface::ShouldFinalizeObjectForUnload(AppDomain* pDomain, Object* obj)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->ShouldFinalizeObjectForUnload(pDomain, obj);
}
ALWAYS_INLINE bool GCToEEInterface::ForceFullGCToBeBlocking()
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->ForceFullGCToBeBlocking();
}
ALWAYS_INLINE bool GCToEEInterface::EagerFinalized(Object* obj)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->EagerFinalized(obj);
}
ALWAYS_INLINE MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetFreeObjectMethodTable();
}
ALWAYS_INLINE bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetBooleanConfigValue(key, value);
}
ALWAYS_INLINE bool GCToEEInterface::GetIntConfigValue(const char* key, int64_t* value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetIntConfigValue(key, value);
}
ALWAYS_INLINE bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
{
assert(g_theGCToCLR != nullptr);
return g_theGCToCLR->GetStringConfigValue(key, value);
}
ALWAYS_INLINE void GCToEEInterface::FreeStringConfigValue(const char* value)
{
assert(g_theGCToCLR != nullptr);
g_theGCToCLR->FreeStringConfigValue(value);
}
#undef ALWAYS_INLINE
} // anonymous namespace
#endif // __GCTOENV_EE_STANDALONE_INL__
|