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// Interface between the GC and EE
5//
6
7#ifndef __GCENV_EE_H__
8#define __GCENV_EE_H__
9
10#include "gcinterface.h"
11
12class GCToEEInterface
13{
14public:
15 static void SuspendEE(SUSPEND_REASON reason);
16 static void RestartEE(bool bFinishedGC); //resume threads.
17
18 //
19 // The GC roots enumeration callback
20 //
21 static void GcScanRoots(promote_func* fn, int condemned, int max_gen, ScanContext* sc);
22
23 //
24 // Callbacks issues during GC that the execution engine can do its own bookeeping
25 //
26
27 // start of GC call back - single threaded
28 static void GcStartWork(int condemned, int max_gen);
29
30 //EE can perform post stack scanning action, while the
31 // user threads are still suspended
32 static void AfterGcScanRoots(int condemned, int max_gen, ScanContext* sc);
33
34 // Called before BGC starts sweeping, the heap is walkable
35 static void GcBeforeBGCSweepWork();
36
37 // post-gc callback.
38 static void GcDone(int condemned);
39
40 // Promote refcounted handle callback
41 static bool RefCountedHandleCallbacks(Object * pObject);
42
43 // Sync block cache management
44 static void SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
45 static void SyncBlockCacheDemote(int max_gen);
46 static void SyncBlockCachePromotionsGranted(int max_gen);
47 static uint32_t GetActiveSyncBlockCount();
48
49 // Thread functions
50 static bool IsPreemptiveGCDisabled();
51 static bool EnablePreemptiveGC();
52 static void DisablePreemptiveGC();
53 static Thread* GetThread();
54
55 static gc_alloc_context * GetAllocContext();
56
57 static void GcEnumAllocContexts(enum_alloc_context_func* fn, void* param);
58
59 static uint8_t* GetLoaderAllocatorObjectForGC(Object* pObject);
60
61 // Diagnostics methods.
62 static void DiagGCStart(int gen, bool isInduced);
63 static void DiagUpdateGenerationBounds();
64 static void DiagGCEnd(size_t index, int gen, int reason, bool fConcurrent);
65 static void DiagWalkFReachableObjects(void* gcContext);
66 static void DiagWalkSurvivors(void* gcContext);
67 static void DiagWalkLOHSurvivors(void* gcContext);
68 static void DiagWalkBGCSurvivors(void* gcContext);
69 static void StompWriteBarrier(WriteBarrierParameters* args);
70
71 static void EnableFinalization(bool foundFinalizers);
72
73 static void HandleFatalError(unsigned int exitCode);
74 static bool ShouldFinalizeObjectForUnload(void* pDomain, Object* obj);
75 static bool EagerFinalized(Object* obj);
76 static MethodTable* GetFreeObjectMethodTable();
77 static bool GetBooleanConfigValue(const char* key, bool* value);
78 static bool GetIntConfigValue(const char* key, int64_t* value);
79 static bool GetStringConfigValue(const char* key, const char** value);
80 static void FreeStringConfigValue(const char* key);
81 static bool IsGCThread();
82 static bool WasCurrentThreadCreatedByGC();
83 static bool CreateThread(void (*threadStart)(void*), void* arg, bool is_suspendable, const char* name);
84 static void WalkAsyncPinnedForPromotion(Object* object, ScanContext* sc, promote_func* callback);
85 static void WalkAsyncPinned(Object* object, void* context, void(*callback)(Object*, Object*, void*));
86 static IGCToCLREventSink* EventSink();
87
88 static uint32_t GetDefaultDomainIndex();
89 static void *GetAppDomainAtIndex(uint32_t appDomainIndex);
90 static bool AppDomainCanAccessHandleTable(uint32_t appDomainID);
91 static uint32_t GetIndexOfAppDomainBeingUnloaded();
92 static uint32_t GetTotalNumSizedRefHandles();
93 static bool AppDomainIsRudeUnload(void *appDomain);
94
95 static bool AnalyzeSurvivorsRequested(int condemnedGeneration);
96 static void AnalyzeSurvivorsFinished(int condemnedGeneration);
97
98 static void VerifySyncTableEntry();
99};
100
101#endif // __GCENV_EE_H__
102