Skip to content

Commit

Permalink
Remove concept of AppDomains from the GC (dotnet#24536)
Browse files Browse the repository at this point in the history
* Remove concept of AppDomains from the GC
- Leave constructs allowing for multiple handle tables, as scenarios for that have been proposed
- Remove FEATURE_APPDOMAIN_RESOURCE_MONITORING
  • Loading branch information
davidwrighton authored and franksinankaya committed May 30, 2019
1 parent eccbb45 commit 47220d1
Show file tree
Hide file tree
Showing 44 changed files with 43 additions and 1,754 deletions.
6 changes: 0 additions & 6 deletions Documentation/project-docs/clr-configuration-knobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ Name | Description | Type | Class | Default Value | Flags
`ADTakeSnapShot` | Superseded by test hooks | `DWORD` | `INTERNAL` | `0` |
`EnableFullDebug` | Heavy-weight checking for AD boundary violations (AD leaks) | `DWORD` | `INTERNAL` | |

#### ARM Configuration Knobs

Name | Description | Type | Class | Default Value | Flags
-----|-------------|------|-------|---------------|-------
`ARMEnabled` | AppDomain Resource Monitoring. Set to 1 to enable it | `DWORD` | `UNSUPPORTED` | `(DWORD)0` |

#### Assembly Loader Configuration Knobs

Name | Description | Type | Class | Default Value | Flags
Expand Down
1 change: 0 additions & 1 deletion src/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8472,7 +8472,6 @@ StackWalkAction DacStackReferenceWalker::Callback(CrawlFrame *pCF, VOID *pData)

MethodDesc *pMD = pCF->GetFunction();
gcctx->sc->pMD = pMD;
gcctx->sc->pCurrentDomain = pCF->GetAppDomain();

PREGDISPLAY pRD = pCF->GetRegisterSet();
dsc->sp = (TADDR)GetRegdisplaySP(pRD);;
Expand Down
7 changes: 3 additions & 4 deletions src/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5716,8 +5716,7 @@ ULONG DacDbiInterfaceImpl::GetAppDomainIdFromVmObjectHandle(VMPTR_OBJECTHANDLE v
{
DD_ENTER_MAY_THROW;

OBJECTHANDLE handle = (OBJECTHANDLE) vmHandle.GetDacPtr();
return HndGetHandleADIndex(handle).m_dwIndex;
return DefaultADID;
}

// Get the target address from a VMPTR_OBJECTHANDLE, i.e., the handle address
Expand Down Expand Up @@ -7553,7 +7552,7 @@ void DacStackReferenceWalker::GCEnumCallbackDac(LPVOID hCallback, OBJECTREF *pOb
DacGcReference *data = dsc->pWalker->GetNextObject<DacGcReference>(dsc);
if (data != NULL)
{
data->vmDomain.SetDacTargetPtr(dac_cast<PTR_AppDomain>(dsc->pCurrentDomain).GetAddr());
data->vmDomain.SetDacTargetPtr(AppDomain::GetCurrentDomain().GetAddr());
if (obj)
data->pObject = obj | 1;
else if (loc.targetPtr)
Expand Down Expand Up @@ -7589,7 +7588,7 @@ void DacStackReferenceWalker::GCReportCallbackDac(PTR_PTR_Object ppObj, ScanCont
DacGcReference *data = dsc->pWalker->GetNextObject<DacGcReference>(dsc);
if (data != NULL)
{
data->vmDomain.SetDacTargetPtr(dac_cast<PTR_AppDomain>(dsc->pCurrentDomain).GetAddr());
data->vmDomain.SetDacTargetPtr(AppDomain::GetCurrentDomain().GetAddr());
data->objHnd.SetDacTargetPtr(obj);
data->dwType = CorReferenceStack;
data->i64ExtraData = 0;
Expand Down
3 changes: 0 additions & 3 deletions src/debug/daccess/gcinterface.dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ void HndEnumHandles(
GC_DAC_VISIBLE
OBJECTREF HndFetchHandle(OBJECTHANDLE handle);

GC_DAC_VISIBLE
struct ADIndex HndGetHandleADIndex(OBJECTHANDLE handle);

GC_DAC_VISIBLE
uintptr_t HndGetHandleExtraInfo(OBJECTHANDLE handle);

Expand Down
3 changes: 0 additions & 3 deletions src/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Local GC meta-issue: https://github.com/dotnet/coreclr/issues/11518

# https://github.com/dotnet/coreclr/issues/11517
remove_definitions(-DFEATURE_APPDOMAIN_RESOURCE_MONITORING)

# https://github.com/dotnet/coreclr/issues/11516
remove_definitions(-DSTRESS_HEAP)

Expand Down
4 changes: 2 additions & 2 deletions src/gc/env/etmdummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define FireEtwGCMarkHandles(HeapNum, ClrInstanceID) 0
#define FireEtwGCMarkOlderGenerationRoots(HeapNum, ClrInstanceID) 0
#define FireEtwFinalizeObject(TypeID, ObjectID, ClrInstanceID) 0
#define FireEtwSetGCHandle(HandleID, ObjectID, Kind, Generation, AppDomainID, ClrInstanceID) 0
#define FireEtwSetGCHandle(HandleID, ObjectID, Kind, Generation, ClrInstanceID) 0
#define FireEtwDestroyGCHandle(HandleID, ClrInstanceID) 0
#define FireEtwGCSampledObjectAllocationLow(Address, TypeID, ObjectCountForTypeSample, TotalSizeForTypeSample, ClrInstanceID) 0
#define FireEtwPinObjectAtGCTime(HandleID, ObjectID, ObjectSize, TypeName, ClrInstanceID) 0
Expand Down Expand Up @@ -376,7 +376,7 @@
#define FireEtwFailFast(FailFastUserMessage, FailedEIP, OSExitCode, ClrExitCode, ClrInstanceID) 0
#define FireEtwPrvFinalizeObject(TypeID, ObjectID, ClrInstanceID, TypeName) 0
#define FireEtwCCWRefCountChange(HandleID, ObjectID, COMInterfacePointer, NewRefCount, AppDomainID, ClassName, NameSpace, Operation, ClrInstanceID) 0
#define FireEtwPrvSetGCHandle(HandleID, ObjectID, Kind, Generation, AppDomainID, ClrInstanceID) 0
#define FireEtwPrvSetGCHandle(HandleID, ObjectID, Kind, Generation, ClrInstanceID) 0
#define FireEtwPrvDestroyGCHandle(HandleID, ClrInstanceID) 0
#define FireEtwFusionMessageEvent(ClrInstanceID, Prepend, Message) 0
#define FireEtwFusionErrorCodeEvent(ClrInstanceID, Category, ErrorCode) 0
Expand Down
18 changes: 0 additions & 18 deletions src/gc/env/gcenv.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,4 @@ inline bool FitsInU1(uint64_t val)
return val == (uint64_t)(uint8_t)val;
}

// -----------------------------------------------------------------------------------------------------------
//
// AppDomain emulation. The we don't have these in Redhawk so instead we emulate the bare minimum of the API
// touched by the GC/HandleTable and pretend we have precisely one (default) appdomain.
//

#define RH_DEFAULT_DOMAIN_ID 1

struct ADIndex
{
DWORD m_dwIndex;

ADIndex () : m_dwIndex(RH_DEFAULT_DOMAIN_ID) {}
explicit ADIndex (DWORD id) : m_dwIndex(id) {}
BOOL operator==(const ADIndex& ad) const { return m_dwIndex == ad.m_dwIndex; }
BOOL operator!=(const ADIndex& ad) const { return m_dwIndex != ad.m_dwIndex; }
};

#endif // __GCENV_BASE_INCLUDED__
6 changes: 0 additions & 6 deletions src/gc/env/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class GCToEEInterface
static void EnableFinalization(bool foundFinalizers);

static void HandleFatalError(unsigned int exitCode);
static bool ShouldFinalizeObjectForUnload(void* pDomain, Object* obj);
static bool EagerFinalized(Object* obj);
static MethodTable* GetFreeObjectMethodTable();
static bool GetBooleanConfigValue(const char* key, bool* value);
Expand All @@ -85,12 +84,7 @@ class GCToEEInterface
static void WalkAsyncPinned(Object* object, void* context, void(*callback)(Object*, Object*, void*));
static IGCToCLREventSink* EventSink();

static uint32_t GetDefaultDomainIndex();
static void *GetAppDomainAtIndex(uint32_t appDomainIndex);
static bool AppDomainCanAccessHandleTable(uint32_t appDomainID);
static uint32_t GetIndexOfAppDomainBeingUnloaded();
static uint32_t GetTotalNumSizedRefHandles();
static bool AppDomainIsRudeUnload(void *appDomain);

static bool AnalyzeSurvivorsRequested(int condemnedGeneration);
static void AnalyzeSurvivorsFinished(int condemnedGeneration);
Expand Down
169 changes: 0 additions & 169 deletions src/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11528,14 +11528,6 @@ void gc_heap::adjust_limit_clr (uint8_t* start, size_t limit_size, size_t size,
acontext->alloc_bytes += added_bytes;
total_alloc_bytes += added_bytes;

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
if (g_fEnableAppDomainMonitoring)
{
GCToEEInterface::RecordAllocatedBytesForHeap(limit_size, heap_number);
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING


uint8_t* saved_used = 0;

if (seg)
Expand Down Expand Up @@ -12085,13 +12077,6 @@ void gc_heap::bgc_loh_alloc_clr (uint8_t* alloc_start,
{
make_unused_array (alloc_start, size);

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
if (g_fEnableAppDomainMonitoring)
{
GCToEEInterface::RecordAllocatedBytesForHeap(size, heap_number);
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

size_t size_of_array_base = sizeof(ArrayBase);

bgc_alloc_lock->loh_alloc_done_with_index (lock_index);
Expand Down Expand Up @@ -19084,10 +19069,6 @@ gc_heap::scan_background_roots (promote_func* fn, int hn, ScanContext *pSC)

pSC->thread_number = hn;

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
pSC->pCurrentDomain = 0;
#endif

BOOL relocate_p = (fn == &GCHeap::Relocate);

dprintf (3, ("Scanning background mark list"));
Expand Down Expand Up @@ -20295,22 +20276,6 @@ void gc_heap::mark_phase (int condemned_gen_number, BOOL mark_only_p)
// scan for deleted entries in the syncblk cache
GCScan::GcWeakPtrScanBySingleThread (condemned_gen_number, max_generation, &sc);

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
if (g_fEnableAppDomainMonitoring)
{
size_t promoted_all_heaps = 0;
#ifdef MULTIPLE_HEAPS
for (int i = 0; i < n_heaps; i++)
{
promoted_all_heaps += promoted_bytes (i);
}
#else
promoted_all_heaps = promoted_bytes (heap_number);
#endif //MULTIPLE_HEAPS
GCToEEInterface::RecordTotalSurvivedBytes(promoted_all_heaps);
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

#ifdef MULTIPLE_HEAPS

#ifdef MARK_LIST
Expand Down Expand Up @@ -34589,26 +34554,11 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)
hp->pin_object (o, (uint8_t**) ppObject, hp->gc_low, hp->gc_high);
#endif //STRESS_PINNING

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
size_t promoted_size_begin = hp->promoted_bytes (thread);
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

if ((o >= hp->gc_low) && (o < hp->gc_high))
{
hpt->mark_object_simple (&o THREAD_NUMBER_ARG);
}

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
size_t promoted_size_end = hp->promoted_bytes (thread);
if (g_fEnableAppDomainMonitoring)
{
if (sc->pCurrentDomain)
{
GCToEEInterface::RecordSurvivedBytesForHeap((promoted_size_end - promoted_size_begin), thread, sc->pCurrentDomain);
}
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

STRESS_LOG_ROOT_PROMOTE(ppObject, o, o ? header(o)->GetMethodTable() : NULL);
}

Expand Down Expand Up @@ -35544,13 +35494,6 @@ void gc_heap::do_pre_gc()
#endif //BACKGROUND_GC
}
}

#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
if (g_fEnableAppDomainMonitoring)
{
GCToEEInterface::ResetTotalSurvivedBytes();
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING
}

#ifdef GC_CONFIG_DRIVEN
Expand Down Expand Up @@ -35798,13 +35741,6 @@ void gc_heap::do_post_gc()
}

GCHeap::UpdatePostGCCounters();
#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
//if (g_fEnableARM)
//{
// SystemDomain::GetADSurvivedBytes();
//}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

#ifdef STRESS_LOG
STRESS_LOG_GC_END(VolatileLoad(&settings.gc_index),
(uint32_t)settings.condemned_generation,
Expand Down Expand Up @@ -36551,23 +36487,6 @@ size_t GCHeap::GetFinalizablePromotedCount()
#endif //MULTIPLE_HEAPS
}

bool GCHeap::FinalizeAppDomain(void *pDomain, bool fRunFinalizers)
{
#ifdef MULTIPLE_HEAPS
bool foundp = false;
for (int hn = 0; hn < gc_heap::n_heaps; hn++)
{
gc_heap* hp = gc_heap::g_heaps [hn];
if (hp->finalize_queue->FinalizeAppDomain (pDomain, fRunFinalizers))
foundp = true;
}
return foundp;

#else //MULTIPLE_HEAPS
return pGenGCHeap->finalize_queue->FinalizeAppDomain (pDomain, fRunFinalizers);
#endif //MULTIPLE_HEAPS
}

bool GCHeap::ShouldRestartFinalizerWatchDog()
{
// This condition was historically used as part of the condition to detect finalizer thread timeouts
Expand Down Expand Up @@ -36872,88 +36791,6 @@ CFinalize::GetNumberFinalizableObjects()
(g_fFinalizerRunOnShutDown ? m_Array : SegQueue(FinalizerListSeg));
}

BOOL
CFinalize::FinalizeSegForAppDomain (void *pDomain,
BOOL fRunFinalizers,
unsigned int Seg)
{
BOOL finalizedFound = FALSE;
Object** endIndex = SegQueue (Seg);
for (Object** i = SegQueueLimit (Seg)-1; i >= endIndex ;i--)
{
CObjectHeader* obj = (CObjectHeader*)*i;

// Objects are put into the finalization queue before they are complete (ie their methodtable
// may be null) so we must check that the object we found has a method table before checking
// if it has the index we are looking for. If the methodtable is null, it can't be from the
// unloading domain, so skip it.
if (method_table(obj) == NULL)
{
continue;
}

// does the EE actually want us to finalize this object?
if (!GCToEEInterface::ShouldFinalizeObjectForUnload(pDomain, obj))
{
continue;
}

if (!fRunFinalizers || (obj->GetHeader()->GetBits()) & BIT_SBLK_FINALIZER_RUN)
{
//remove the object because we don't want to
//run the finalizer
MoveItem (i, Seg, FreeList);
//Reset the bit so it will be put back on the queue
//if resurrected and re-registered.
obj->GetHeader()->ClrBit (BIT_SBLK_FINALIZER_RUN);
}
else
{
if (method_table(obj)->HasCriticalFinalizer())
{
finalizedFound = TRUE;
MoveItem (i, Seg, CriticalFinalizerListSeg);
}
else
{
if (GCToEEInterface::AppDomainIsRudeUnload(pDomain))
{
MoveItem (i, Seg, FreeList);
}
else
{
finalizedFound = TRUE;
MoveItem (i, Seg, FinalizerListSeg);
}
}
}
}

return finalizedFound;
}

bool
CFinalize::FinalizeAppDomain (void *pDomain, bool fRunFinalizers)
{
bool finalizedFound = false;

unsigned int startSeg = gen_segment (max_generation);

EnterFinalizeLock();

for (unsigned int Seg = startSeg; Seg <= gen_segment (0); Seg++)
{
if (FinalizeSegForAppDomain (pDomain, fRunFinalizers, Seg))
{
finalizedFound = true;
}
}

LeaveFinalizeLock();

return finalizedFound;
}

void
CFinalize::MoveItem (Object** fromIndex,
unsigned int fromSeg,
Expand Down Expand Up @@ -37001,12 +36838,6 @@ CFinalize::GcScanRoots (promote_func* fn, int hn, ScanContext *pSC)
Object* o = *po;
//dprintf (3, ("scan freacheable %Ix", (size_t)o));
dprintf (3, ("scan f %Ix", (size_t)o));
#ifdef FEATURE_APPDOMAIN_RESOURCE_MONITORING
if (g_fEnableAppDomainMonitoring)
{
pSC->pCurrentDomain = GCToEEInterface::GetAppDomainForObject(o);
}
#endif //FEATURE_APPDOMAIN_RESOURCE_MONITORING

(*fn)(po, pSC, 0);
}
Expand Down
Loading

0 comments on commit 47220d1

Please sign in to comment.