Remove always defined FEATURE_CORECLR
[platform/upstream/coreclr.git] / src / vm / appdomain.inl
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 **
6 ** Header:  AppDomain.i
7 ** 
8
9 **
10 ** Purpose: Implements AppDomain (loader domain) architecture
11 ** inline functions
12 **
13 **
14 ===========================================================*/
15 #ifndef _APPDOMAIN_I
16 #define _APPDOMAIN_I
17
18 #ifndef DACCESS_COMPILE
19
20 #include "appdomain.hpp"
21
22 inline void AppDomain::SetUnloadInProgress(AppDomain *pThis)
23 {
24     WRAPPER_NO_CONTRACT;
25
26     SystemDomain::System()->SetUnloadInProgress(pThis);
27 }
28
29 inline void AppDomain::SetUnloadComplete(AppDomain *pThis)
30 {
31     GCX_COOP();
32
33     SystemDomain::System()->SetUnloadComplete();
34 }
35
36 inline  void AppDomain::EnterContext(Thread* pThread, Context* pCtx,ContextTransitionFrame *pFrame)
37 {
38     CONTRACTL
39     {
40         GC_NOTRIGGER;
41         MODE_COOPERATIVE;
42         PRECONDITION(CheckPointer(pThread));
43         PRECONDITION(CheckPointer(pCtx));
44         PRECONDITION(CheckPointer(pFrame));
45         PRECONDITION(pCtx->GetDomain()==this);
46     }
47     CONTRACTL_END;
48     pThread->EnterContextRestricted(pCtx,pFrame);
49 };
50
51
52 inline AppDomainFromIDHolder::~AppDomainFromIDHolder()
53 {
54     WRAPPER_NO_CONTRACT;
55 #ifdef _DEBUG
56     if(m_bAcquired)
57         Release();
58 #endif    
59 }
60
61 inline void AppDomainFromIDHolder::Release()
62 {
63     //do not use real contract here!
64     WRAPPER_NO_CONTRACT;
65 #ifdef _DEBUG
66     if(m_bAcquired)
67     {
68         if (m_type==SyncType_GC)
69 #ifdef ENABLE_CONTRACTS_IMPL
70         {
71             if (GetThread())
72             {
73                 STRESS_LOG1(LF_APPDOMAIN, LL_INFO10000, "AppDomainFromIDHolder::Assign is allowing GC - %08x",this);
74                 GetThread()->EndForbidGC();
75             }
76             else
77             {
78                 if (!IsGCThread())
79                 {
80                     _ASSERTE(!"Should not be called from a non GC thread");
81                 }
82             }
83         }
84 #else
85             m_pDomain=NULL;
86 #endif
87         else
88         if (m_type==SyncType_ADLock)
89             SystemDomain::m_SystemDomainCrst.SetCantLeave(FALSE);
90         else
91         {
92             _ASSERTE(!"Unknown type");        
93         }
94         m_pDomain=NULL;
95         m_bAcquired=FALSE;
96     }
97 #endif
98 }
99
100 inline void AppDomainFromIDHolder::Assign(ADID id, BOOL bUnsafePoint)
101 {
102     //do not use real contract here!
103     WRAPPER_NO_CONTRACT;
104     TESTHOOKCALL(AppDomainCanBeUnloaded(id.m_dwId, bUnsafePoint));
105 #ifdef _DEBUG
106     m_bChecked=FALSE;
107     if (m_type==SyncType_GC)
108     {
109 #ifdef ENABLE_CONTRACTS_IMPL
110         if (GetThread())
111         {
112             _ASSERTE(GetThread()->PreemptiveGCDisabled());
113             STRESS_LOG1(LF_APPDOMAIN, LL_INFO10000, "AppDomainFromIDHolder::Assign is forbidding GC - %08x",this);
114             GetThread()->BeginForbidGC(__FILE__, __LINE__);
115         }
116         else
117         {
118             if (!IsGCThread())
119             {
120                 _ASSERTE(!"Should not be called from a non GC thread");
121             }
122         }
123 #endif
124     }
125     else
126     if (m_type==SyncType_ADLock)    
127     {
128         _ASSERTE(SystemDomain::m_SystemDomainCrst.OwnedByCurrentThread());
129         SystemDomain::m_SystemDomainCrst.SetCantLeave(TRUE);
130     }
131     else
132     {
133         _ASSERT(!"NI");
134     }
135
136     m_bAcquired=TRUE;
137  #endif
138     m_pDomain=SystemDomain::GetAppDomainAtId(id);
139
140 }
141
142
143
144 inline void AppDomainFromIDHolder::ThrowIfUnloaded()
145 {
146     STATIC_CONTRACT_THROWS;
147     if (IsUnloaded())
148     {
149         COMPlusThrow(kAppDomainUnloadedException);
150     }
151 #ifdef _DEBUG
152     m_bChecked=TRUE;
153 #endif
154 }
155
156 inline AppDomain* AppDomainFromIDHolder::operator ->()
157 {
158     LIMITED_METHOD_CONTRACT;
159     _ASSERTE(m_bChecked && m_bAcquired);    
160     return m_pDomain;
161 }
162
163 inline DomainAssembly* AppDomain::FindDomainAssembly(Assembly* assembly)
164 {
165     CONTRACTL
166     {
167         GC_NOTRIGGER;
168         MODE_COOPERATIVE;
169         PRECONDITION(CheckPointer(assembly));
170     }
171     CONTRACTL_END;
172     return assembly->FindDomainAssembly(this);    
173 };
174
175 inline BOOL AppDomain::IsRunningIn(Thread* pThread)
176 {
177     WRAPPER_NO_CONTRACT;
178     if (IsDefaultDomain()) 
179         return TRUE;
180     return pThread->IsRunningIn(this, NULL)!=NULL;
181 }
182
183
184
185 inline void AppDomain::AddMemoryPressure()
186 {
187     STANDARD_VM_CONTRACT;
188     m_MemoryPressure=EstimateSize();
189     GCInterface::AddMemoryPressure(m_MemoryPressure);
190 }
191
192 inline void AppDomain::RemoveMemoryPressure()
193 {
194     WRAPPER_NO_CONTRACT;
195
196     GCInterface::RemoveMemoryPressure(m_MemoryPressure);
197 }
198
199 #endif // DACCESS_COMPILE
200
201 inline void AppDomain::SetAppDomainManagerInfo(LPCWSTR szAssemblyName, LPCWSTR szTypeName, EInitializeNewDomainFlags dwInitializeDomainFlags)
202 {
203     CONTRACTL
204     {
205         THROWS;
206         GC_NOTRIGGER;
207         MODE_ANY;
208     }
209     CONTRACTL_END;
210     m_AppDomainManagerAssembly=szAssemblyName;
211     m_AppDomainManagerType=szTypeName;
212     m_dwAppDomainManagerInitializeDomainFlags = dwInitializeDomainFlags;
213 }
214
215 inline BOOL AppDomain::HasAppDomainManagerInfo()
216 {
217     WRAPPER_NO_CONTRACT;
218     return !m_AppDomainManagerAssembly.IsEmpty() && !m_AppDomainManagerType.IsEmpty();
219 }
220
221 inline LPCWSTR AppDomain::GetAppDomainManagerAsm()
222 {
223     WRAPPER_NO_CONTRACT;
224     return m_AppDomainManagerAssembly;
225 }
226
227
228 inline LPCWSTR AppDomain::GetAppDomainManagerType()
229 {
230     WRAPPER_NO_CONTRACT;
231     return m_AppDomainManagerType;
232 }
233
234
235 inline EInitializeNewDomainFlags AppDomain::GetAppDomainManagerInitializeNewDomainFlags()
236 {
237     LIMITED_METHOD_CONTRACT;
238     return m_dwAppDomainManagerInitializeDomainFlags;
239 }
240
241 inline AppDomain::PathIterator AppDomain::IterateNativeDllSearchDirectories()
242 {
243     WRAPPER_NO_CONTRACT;
244     PathIterator i;
245     i.m_i = m_NativeDllSearchDirectories.Iterate();
246     return i;
247 }
248
249 inline BOOL AppDomain::HasNativeDllSearchDirectories()
250 {
251     WRAPPER_NO_CONTRACT;
252     return m_NativeDllSearchDirectories.GetCount() !=0;
253 }
254
255
256 inline BOOL AppDomain::CanReversePInvokeEnter()
257 {
258     LIMITED_METHOD_CONTRACT;
259     return m_ReversePInvokeCanEnter;
260 }
261
262 inline void AppDomain::SetReversePInvokeCannotEnter()
263 {
264     LIMITED_METHOD_CONTRACT;
265     m_ReversePInvokeCanEnter=FALSE;
266 }
267
268 inline bool AppDomain::MustForceTrivialWaitOperations()
269 {
270     LIMITED_METHOD_CONTRACT;
271     return m_ForceTrivialWaitOperations;
272 }
273
274 inline void AppDomain::SetForceTrivialWaitOperations()
275 {
276     LIMITED_METHOD_CONTRACT;
277     m_ForceTrivialWaitOperations = true;
278 }
279
280 inline PTR_LoaderHeap AppDomain::GetHighFrequencyHeap()
281 {
282     WRAPPER_NO_CONTRACT;    
283     return GetLoaderAllocator()->GetHighFrequencyHeap();
284 }
285
286 inline PTR_LoaderHeap AppDomain::GetLowFrequencyHeap()
287 {
288     WRAPPER_NO_CONTRACT;    
289     return GetLoaderAllocator()->GetLowFrequencyHeap();
290 }
291
292 inline PTR_LoaderHeap AppDomain::GetStubHeap()
293 {
294     WRAPPER_NO_CONTRACT;    
295     return GetLoaderAllocator()->GetStubHeap();
296 }
297
298 inline PTR_LoaderAllocator AppDomain::GetLoaderAllocator()
299 {
300     WRAPPER_NO_CONTRACT;
301     return PTR_LoaderAllocator(PTR_HOST_MEMBER_TADDR(AppDomain,this,m_LoaderAllocator));
302 }
303
304 /* static */
305 inline DWORD DomainLocalModule::DynamicEntry::GetOffsetOfDataBlob() 
306 {
307     LIMITED_METHOD_CONTRACT;
308     _ASSERTE(DWORD(offsetof(NormalDynamicEntry, m_pDataBlob)) == offsetof(NormalDynamicEntry, m_pDataBlob));
309     return (DWORD)offsetof(NormalDynamicEntry, m_pDataBlob);
310 }
311
312
313 #endif  // _APPDOMAIN_I
314