[Tizen] Unify dnetmemoryenumlib terms to match the codebase (#291)
[platform/upstream/coreclr.git] / src / vm / vars.cpp
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 //
5 // vars.cpp - Global Var definitions
6 //
7
8
9
10 #include "common.h"
11 #include "vars.hpp"
12 #include "cordbpriv.h"
13 #include "eeprofinterfaces.h"
14 #include "bbsweep.h"
15
16 #ifndef DACCESS_COMPILE
17 //
18 // Allow use of native images?
19 //
20 bool g_fAllowNativeImages = true;
21
22 //
23 // Default install library
24 //
25 const WCHAR g_pwBaseLibrary[]     = CoreLibName_IL_W;
26 const WCHAR g_pwBaseLibraryName[] = CoreLibName_W;
27 const char g_psBaseLibrary[]      = CoreLibName_IL_A;
28 const char g_psBaseLibraryName[]  = CoreLibName_A;
29 const char g_psBaseLibrarySatelliteAssemblyName[]  = CoreLibSatelliteName_A;
30
31 Volatile<LONG>       g_TrapReturningThreads;
32
33 HINSTANCE            g_pMSCorEE;
34 BBSweep              g_BBSweep;
35
36 #ifdef _DEBUG
37 // next two variables are used to enforce an ASSERT in Thread::DbgFindThread
38 // that does not allow g_TrapReturningThreads to creep up unchecked.
39 Volatile<LONG>       g_trtChgStamp = 0;
40 Volatile<LONG>       g_trtChgInFlight = 0;
41
42 const char *         g_ExceptionFile;   // Source of the last thrown exception (COMPLUSThrow())
43 DWORD                g_ExceptionLine;   // ... ditto ...
44 void *               g_ExceptionEIP;    // Managed EIP of the last guy to call JITThrow.
45 #endif // _DEBUG
46 void *               g_LastAccessViolationEIP;  // The EIP of the place we last threw an AV.   Used to diagnose stress issues.  
47
48 #endif // #ifndef DACCESS_COMPILE
49 GPTR_IMPL(IdDispenser,       g_pThinLockThreadIdDispenser);
50
51 GPTR_IMPL(IdDispenser,       g_pModuleIndexDispenser);
52
53 IBCLogger                    g_IBCLogger;
54
55 // For [<I1, etc. up to and including [Object
56 GARY_IMPL(PTR_ArrayTypeDesc, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX);
57
58 GPTR_IMPL(EEConfig, g_pConfig);     // configuration data (from the registry)
59
60 GPTR_IMPL(MethodTable,      g_pObjectClass);
61 GPTR_IMPL(MethodTable,      g_pRuntimeTypeClass);
62 GPTR_IMPL(MethodTable,      g_pCanonMethodTableClass);  // System.__Canon
63 GPTR_IMPL(MethodTable,      g_pStringClass);
64 #ifdef FEATURE_UTF8STRING
65 GPTR_IMPL(MethodTable,      g_pUtf8StringClass);
66 #endif // FEATURE_UTF8STRING
67 GPTR_IMPL(MethodTable,      g_pArrayClass);
68 GPTR_IMPL(MethodTable,      g_pSZArrayHelperClass);
69 GPTR_IMPL(MethodTable,      g_pNullableClass);
70 GPTR_IMPL(MethodTable,      g_pByReferenceClass);
71 GPTR_IMPL(MethodTable,      g_pExceptionClass);
72 GPTR_IMPL(MethodTable,      g_pThreadAbortExceptionClass);
73 GPTR_IMPL(MethodTable,      g_pOutOfMemoryExceptionClass);
74 GPTR_IMPL(MethodTable,      g_pStackOverflowExceptionClass);
75 GPTR_IMPL(MethodTable,      g_pExecutionEngineExceptionClass);
76 GPTR_IMPL(MethodTable,      g_pDelegateClass);
77 GPTR_IMPL(MethodTable,      g_pMulticastDelegateClass);
78 GPTR_IMPL(MethodTable,      g_pValueTypeClass);
79 GPTR_IMPL(MethodTable,      g_pEnumClass);
80 GPTR_IMPL(MethodTable,      g_pThreadClass);
81 GPTR_IMPL(MethodTable,      g_pFreeObjectMethodTable);
82 GPTR_IMPL(MethodTable,      g_pOverlappedDataClass);
83
84 GPTR_IMPL(MethodTable,      g_TypedReferenceMT);
85
86 GPTR_IMPL(MethodTable,      g_pByteArrayMT);
87
88 #ifdef FEATURE_COMINTEROP
89 GPTR_IMPL(MethodTable,      g_pBaseCOMObject);
90 GPTR_IMPL(MethodTable,      g_pBaseRuntimeClass);
91 #endif
92
93 #ifdef FEATURE_ICASTABLE
94 GPTR_IMPL(MethodTable,      g_pICastableInterface);
95 #endif // FEATURE_ICASTABLE
96
97
98 GPTR_IMPL(MethodDesc,       g_pExecuteBackoutCodeHelperMethod);
99
100 GPTR_IMPL(MethodDesc,       g_pObjectFinalizerMD);
101
102 GPTR_IMPL(Thread,g_pFinalizerThread);
103 GPTR_IMPL(Thread,g_pSuspensionThread);
104
105 // Global SyncBlock cache
106 GPTR_IMPL(SyncTableEntry,g_pSyncTable);
107
108 #ifdef STRESS_LOG
109 GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog);
110 #endif
111
112 #ifdef FEATURE_COMINTEROP
113 // Global RCW cleanup list
114 GPTR_IMPL(RCWCleanupList,g_pRCWCleanupList);
115 #endif // FEATURE_COMINTEROP
116
117 #ifdef FEATURE_INTEROP_DEBUGGING
118 GVAL_IMPL_INIT(DWORD, g_debuggerWordTLSIndex, TLS_OUT_OF_INDEXES);
119 #endif
120 GVAL_IMPL_INIT(DWORD, g_TlsIndex, TLS_OUT_OF_INDEXES);
121
122 #ifndef DACCESS_COMPILE
123
124 // <TODO> @TODO - PROMOTE. </TODO>
125 OBJECTHANDLE         g_pPreallocatedOutOfMemoryException;
126 OBJECTHANDLE         g_pPreallocatedStackOverflowException;
127 OBJECTHANDLE         g_pPreallocatedExecutionEngineException;
128 OBJECTHANDLE         g_pPreallocatedRudeThreadAbortException;
129 OBJECTHANDLE         g_pPreallocatedThreadAbortException;
130 OBJECTHANDLE         g_pPreallocatedSentinelObject;
131 OBJECTHANDLE         g_pPreallocatedBaseException;
132
133 // 
134 //
135 // Global System Info
136 //
137 SYSTEM_INFO g_SystemInfo;
138
139 // Configurable constants used across our spin locks
140 // Initialization here is necessary so that we have meaningful values before the runtime is started
141 // These initial values were selected to match the defaults, but anything reasonable is close enough
142 SpinConstants g_SpinConstants = { 
143     50,        // dwInitialDuration 
144     40000,     // dwMaximumDuration - ideally (20000 * max(2, numProc))
145     3,         // dwBackoffFactor
146     10,        // dwRepetitions
147     0          // dwMonitorSpinCount
148 };
149
150 // support for Event Tracing for Windows (ETW)
151 ETW::CEtwTracer * g_pEtwTracer = NULL;
152
153 #endif // #ifndef DACCESS_COMPILE
154
155 //
156 // Support for the COM+ Debugger.
157 //
158 GPTR_IMPL(DebugInterface,     g_pDebugInterface);
159 // A managed debugger may set this flag to high from out of process.
160 GVAL_IMPL_INIT(DWORD,         g_CORDebuggerControlFlags, DBCF_NORMAL_OPERATION);
161
162 #ifdef DEBUGGING_SUPPORTED
163 GPTR_IMPL(EEDbgInterfaceImpl, g_pEEDbgInterfaceImpl);
164 #endif // DEBUGGING_SUPPORTED
165
166 #if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
167 // Profiling support
168 HINSTANCE           g_pDebuggerDll = NULL;
169
170 GVAL_IMPL(ProfControlBlock, g_profControlBlock);
171 #endif // defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
172
173 #ifndef DACCESS_COMPILE
174
175 // Global default for Concurrent GC. The default is value is 1
176 int g_IGCconcurrent = 1;
177
178 int g_IGCHoardVM = 0;
179
180 #ifdef GCTRIMCOMMIT
181
182 int g_IGCTrimCommit = 0;
183
184 #endif
185
186 BOOL g_fEnableETW = FALSE;
187
188 //
189 // Global state variable indicating if the EE is in its init phase.
190 //
191 bool g_fEEInit = false;
192
193 //
194 // Global state variables indicating which stage of shutdown we are in
195 //
196
197 #endif // #ifndef DACCESS_COMPILE
198
199 // See comments at code:EEShutDown for details on how and why this gets set.  Use
200 // code:IsAtProcessExit to read this.
201 GVAL_IMPL(bool, g_fProcessDetach);
202
203 GVAL_IMPL_INIT(DWORD, g_fEEShutDown, 0);
204
205 #ifndef FEATURE_PAL
206 GVAL_IMPL(SIZE_T, g_runtimeLoadedBaseAddress);
207 GVAL_IMPL(SIZE_T, g_runtimeVirtualSize);
208 #endif // !FEATURE_PAL
209
210 #ifndef DACCESS_COMPILE
211
212 Volatile<LONG> g_fForbidEnterEE = false;
213 bool g_fManagedAttach = false;
214 bool g_fNoExceptions = false;
215 #ifdef FEATURE_COMINTEROP
216 bool g_fShutDownCOM = false;
217 #endif //FEATURE_COMINTEROP
218
219 DWORD g_FinalizerWaiterStatus = 0;
220
221 //
222 // Do we own the lifetime of the process, ie. is it an EXE?
223 //
224 bool g_fWeControlLifetime = false;
225
226 #ifdef _DEBUG
227 // The following should only be used for assertions.  (Famous last words).
228 bool dbg_fDrasticShutdown = false;
229 #endif
230 bool g_fInControlC = false;
231
232 //
233 //
234 // IJW needs the shim HINSTANCE
235 //
236 HINSTANCE g_hInstShim = NULL;
237
238 #endif // #ifndef DACCESS_COMPILE
239
240 #ifdef DACCESS_COMPILE
241
242 void OBJECTHANDLE_EnumMemoryRegions(OBJECTHANDLE handle)
243 {
244     SUPPORTS_DAC;
245     PTR_TADDR ref = PTR_TADDR(handle);
246     if (ref.IsValid())
247     {
248         ref.EnumMem();
249         
250         PTR_Object obj = PTR_Object(*ref);
251         if (obj.IsValid())
252         {
253             obj->EnumMemoryRegions();
254         }
255     }
256 }
257
258 void OBJECTREF_EnumMemoryRegions(OBJECTREF ref)
259 {
260     if (ref.IsValid())
261     {
262         ref->EnumMemoryRegions();
263     }
264 }
265
266 #endif // #ifdef DACCESS_COMPILE
267
268 #ifndef DACCESS_COMPILE
269 //
270 // We need the following to be the compiler's notion of volatile.
271 //
272 extern "C" RAW_KEYWORD(volatile) const GSCookie s_gsCookie = 0;
273
274 #else
275 __GlobalVal< GSCookie > s_gsCookie(&g_dacGlobals.dac__s_gsCookie);
276 #endif //!DACCESS_COMPILE
277
278 //==============================================================================
279