For profiling purpose it only cares about condemned ranges; for byref
validation it cares about any object on the heap.
Commit migrated from https://github.com/dotnet/coreclr/commit/
c5bfdd98204d7cb265f633534d593ca9c008ca6b
}
Object*
-GCHeap::GetContainingObject (void *pInteriorPtr)
+GCHeap::GetContainingObject (void *pInteriorPtr, bool fCollectedGenOnly)
{
uint8_t *o = (uint8_t*)pInteriorPtr;
gc_heap* hp = gc_heap::heap_of (o);
- if (o >= hp->lowest_address && o < hp->highest_address)
+
+ uint8_t* lowest = (fCollectedGenOnly ? hp->gc_low : hp->lowest_address);
+ uint8_t* highest = (fCollectedGenOnly ? hp->gc_high : hp->highest_address);
+
+ if (o >= lowest && o < highest)
{
- o = hp->find_object (o, hp->gc_low);
+ o = hp->find_object (o, lowest);
}
else
{
void FixAllocContext (gc_alloc_context* acontext,
BOOL lockp, void* arg, void *heap);
- Object* GetContainingObject(void *pInteriorPtr);
+ Object* GetContainingObject(void *pInteriorPtr, bool fCollectedGenOnly);
#ifdef MULTIPLE_HEAPS
static void AssignHeap (alloc_context* acontext);
// Given an interior pointer, return a pointer to the object
// containing that pointer. This is safe to call only when the EE is suspended.
- virtual Object* GetContainingObject(void* pInteriorPtr) = 0;
+ // When fCollectedGenOnly is true, it only returns the object if it's found in
+ // the generation(s) that are being collected.
+ virtual Object* GetContainingObject(void* pInteriorPtr, bool fCollectedGenOnly) = 0;
/*
===========================================================================
Object *pObj = *ppObject;
if (dwFlags & GC_CALL_INTERIOR)
{
- pObj = GCHeapUtilities::GetGCHeap()->GetContainingObject(pObj);
+ pObj = GCHeapUtilities::GetGCHeap()->GetContainingObject(pObj, true);
+ if (pObj == nullptr)
+ return;
}
ScanRootsHelper(pObj, ppObject, pSC, dwFlags);
#endif // defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)
{
entry = s_ByrefValidationEntries[i];
- Object *pObjUNSAFE = GCHeapUtilities::GetGCHeap()->GetContainingObject(entry.pByref);
+ Object *pObjUNSAFE = GCHeapUtilities::GetGCHeap()->GetContainingObject(entry.pByref, false);
ValidateObjectInternal(pObjUNSAFE, TRUE);
}
}