Skip to content

Commit 21e92cb

Browse files
tomeksowijkotas
andauthored
GC-report all associated LoaderAllocators (#110856)
* Report all LoaderAllocators associated with an interior pointer * Remove IsInRange's unused out parameter * Remove assertion for at least one valid LoaderAllocator object ref --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent 8f284ee commit 21e92cb

File tree

8 files changed

+65
-68
lines changed

8 files changed

+65
-68
lines changed

src/coreclr/inc/utilcode.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,11 +3104,11 @@ class RangeList
31043104
return this->RemoveRangesWorker(id);
31053105
}
31063106

3107-
BOOL IsInRange(TADDR address, TADDR *pID = NULL)
3107+
BOOL IsInRange(TADDR address)
31083108
{
31093109
SUPPORTS_DAC;
31103110

3111-
return this->IsInRangeWorker(address, pID);
3111+
return this->IsInRangeWorker(address);
31123112
}
31133113

31143114
#ifndef DACCESS_COMPILE
@@ -3125,7 +3125,32 @@ class RangeList
31253125
virtual void RemoveRangesWorker(void *id) { }
31263126
#endif // !DACCESS_COMPILE
31273127

3128-
virtual BOOL IsInRangeWorker(TADDR address, TADDR *pID = NULL);
3128+
virtual BOOL IsInRangeWorker(TADDR address);
3129+
3130+
template<class F>
3131+
void ForEachInRangeWorker(TADDR address, F func) const
3132+
{
3133+
CONTRACTL
3134+
{
3135+
INSTANCE_CHECK;
3136+
NOTHROW;
3137+
FORBID_FAULT;
3138+
GC_NOTRIGGER;
3139+
}
3140+
CONTRACTL_END
3141+
3142+
SUPPORTS_DAC;
3143+
3144+
for (const RangeListBlock* b = &m_starterBlock; b != nullptr; b = b->next)
3145+
{
3146+
for (const Range r : b->ranges)
3147+
{
3148+
if (r.id != (TADDR)nullptr && address >= r.start && address < r.end)
3149+
func(r.id);
3150+
}
3151+
}
3152+
}
3153+
31293154

31303155
#ifdef DACCESS_COMPILE
31313156
void EnumMemoryRegions(enum CLRDataEnumMemoryFlags flags);

src/coreclr/utilcode/loaderheap.cpp

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void RangeList::RemoveRangesWorker(void *id)
209209

210210
#endif // #ifndef DACCESS_COMPILE
211211

212-
BOOL RangeList::IsInRangeWorker(TADDR address, TADDR *pID /* = NULL */)
212+
BOOL RangeList::IsInRangeWorker(TADDR address)
213213
{
214214
CONTRACTL
215215
{
@@ -222,46 +222,15 @@ BOOL RangeList::IsInRangeWorker(TADDR address, TADDR *pID /* = NULL */)
222222

223223
SUPPORTS_DAC;
224224

225-
RangeListBlock* b = &m_starterBlock;
226-
Range* r = b->ranges;
227-
Range* rEnd = r + RANGE_COUNT;
228-
229-
//
230-
// Look for a matching element
231-
//
232-
233-
while (TRUE)
225+
for (const RangeListBlock* b = &m_starterBlock; b != nullptr; b = b->next)
234226
{
235-
while (r < rEnd)
227+
for (const Range r : b->ranges)
236228
{
237-
if (r->id != (TADDR)NULL &&
238-
address >= r->start
239-
&& address < r->end)
240-
{
241-
if (pID != NULL)
242-
{
243-
*pID = r->id;
244-
}
229+
if (r.id != (TADDR)nullptr && address >= r.start && address < r.end)
245230
return TRUE;
246-
}
247-
r++;
248231
}
249-
250-
//
251-
// If there are no more blocks, we're done.
252-
//
253-
254-
if (b->next == NULL)
255-
return FALSE;
256-
257-
//
258-
// Next block.
259-
//
260-
261-
b = b->next;
262-
r = b->ranges;
263-
rEnd = r + RANGE_COUNT;
264232
}
233+
return FALSE;
265234
}
266235

267236
#ifdef DACCESS_COMPILE

src/coreclr/vm/assemblyspec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, Assembly *pAss
872872

873873
abHolder.SuppressRelease();
874874

875-
STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreAssembly): Add cached entry (%p) with PEAssembly %p",entry,pAssembly->GetPEAssembly());
875+
STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreAssembly): Add cached entry (%p) with PEAssembly %p\n",entry,pAssembly->GetPEAssembly());
876876
RETURN TRUE;
877877
}
878878
else
@@ -1022,7 +1022,7 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE
10221022
m_map.InsertValue(key, entry);
10231023
abHolder.SuppressRelease();
10241024

1025-
STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreException): Add cached entry (%p) with exception %p",entry,pEx);
1025+
STRESS_LOG2(LF_CLASSLOADER,LL_INFO10,"StorePEAssembly (StoreException): Add cached entry (%p) with exception %p\n",entry,pEx);
10261026
RETURN TRUE;
10271027
}
10281028
else

src/coreclr/vm/gcenv.ee.common.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,14 @@ void GcReportLoaderAllocator(promote_func* fn, ScanContext* sc, LoaderAllocator
213213
if (pLoaderAllocator != NULL && pLoaderAllocator->IsCollectible())
214214
{
215215
Object *refCollectionObject = OBJECTREFToObject(pLoaderAllocator->GetExposedObject());
216+
if (refCollectionObject != NULL)
217+
{
218+
INDEBUG(Object *oldObj = refCollectionObject;)
219+
fn(&refCollectionObject, sc, CHECK_APP_DOMAIN);
216220

217-
#ifdef _DEBUG
218-
Object *oldObj = refCollectionObject;
219-
#endif
220-
221-
_ASSERTE(refCollectionObject != NULL);
222-
fn(&refCollectionObject, sc, CHECK_APP_DOMAIN);
223-
224-
// We are reporting the location of a local variable, assert it doesn't change.
225-
_ASSERTE(oldObj == refCollectionObject);
221+
// We are reporting the location of a local variable, assert it doesn't change.
222+
_ASSERTE(oldObj == refCollectionObject);
223+
}
226224
}
227225
}
228226

src/coreclr/vm/loaderallocator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,17 +2141,17 @@ void LoaderAllocator::AssociateMemoryWithLoaderAllocator(BYTE *start, const BYTE
21412141
}
21422142

21432143
/* static */
2144-
PTR_LoaderAllocator LoaderAllocator::GetAssociatedLoaderAllocator_Unsafe(TADDR ptr)
2144+
void LoaderAllocator::GcReportAssociatedLoaderAllocators_Unsafe(TADDR ptr, promote_func* fn, ScanContext* sc)
21452145
{
21462146
LIMITED_METHOD_CONTRACT;
21472147

21482148
GlobalLoaderAllocator* pGlobalAllocator = (GlobalLoaderAllocator*)SystemDomain::GetGlobalLoaderAllocator();
2149-
LoaderAllocator* pLoaderAllocator;
2150-
if (pGlobalAllocator->m_memoryAssociations.IsInRangeWorker_Unlocked(ptr, reinterpret_cast<TADDR *>(&pLoaderAllocator)))
2151-
{
2152-
return pLoaderAllocator;
2153-
}
2154-
return NULL;
2149+
pGlobalAllocator->m_memoryAssociations.ForEachInRangeWorker_Unlocked(ptr,
2150+
[fn, sc](TADDR laAddr)
2151+
{
2152+
GcReportLoaderAllocator(fn, sc, (LoaderAllocator*)laAddr);
2153+
}
2154+
);
21552155
}
21562156

21572157

src/coreclr/vm/loaderallocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CodeRangeMapRangeList : public RangeList
159159
#endif // DACCESS_COMPILE
160160
}
161161

162-
virtual BOOL IsInRangeWorker(TADDR address, TADDR *pID = NULL)
162+
virtual BOOL IsInRangeWorker(TADDR address)
163163
{
164164
WRAPPER_NO_CONTRACT;
165165
RangeSection *pRS = ExecutionManager::FindCodeRange(address, ExecutionManager::ScanReaderLock);
@@ -570,7 +570,7 @@ class LoaderAllocator
570570

571571
// This function may only be called while the runtime is suspended
572572
// As it does not lock around access to a RangeList
573-
static PTR_LoaderAllocator GetAssociatedLoaderAllocator_Unsafe(TADDR ptr);
573+
static void GcReportAssociatedLoaderAllocators_Unsafe(TADDR ptr, promote_func* fn, ScanContext* sc);
574574

575575
static void AssociateMemoryWithLoaderAllocator(BYTE *start, const BYTE *end, LoaderAllocator* pLoaderAllocator);
576576
static void RemoveMemoryToLoaderAllocatorAssociation(LoaderAllocator* pLoaderAllocator);

src/coreclr/vm/lockedrangelist.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ class LockedRangeList : public RangeList
2424
LIMITED_METHOD_CONTRACT;
2525
}
2626

27-
BOOL IsInRangeWorker_Unlocked(TADDR address, TADDR *pID = NULL)
27+
BOOL IsInRangeWorker_Unlocked(TADDR address)
2828
{
2929
WRAPPER_NO_CONTRACT;
3030
SUPPORTS_DAC;
31-
return RangeList::IsInRangeWorker(address, pID);
31+
return RangeList::IsInRangeWorker(address);
32+
}
33+
34+
template<class F>
35+
void ForEachInRangeWorker_Unlocked(TADDR address, F func) const
36+
{
37+
WRAPPER_NO_CONTRACT;
38+
SUPPORTS_DAC;
39+
return RangeList::ForEachInRangeWorker(address, func);
3240
}
3341

3442
protected:
@@ -47,12 +55,12 @@ class LockedRangeList : public RangeList
4755
RangeList::RemoveRangesWorker(id);
4856
}
4957

50-
virtual BOOL IsInRangeWorker(TADDR address, TADDR *pID = NULL)
58+
virtual BOOL IsInRangeWorker(TADDR address)
5159
{
5260
WRAPPER_NO_CONTRACT;
5361
SUPPORTS_DAC;
5462
SimpleReadLockHolder lh(&m_RangeListRWLock);
55-
return RangeList::IsInRangeWorker(address, pID);
63+
return RangeList::IsInRangeWorker(address);
5664
}
5765

5866
SimpleRWLock m_RangeListRWLock;

src/coreclr/vm/siginfo.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,12 +5145,9 @@ void PromoteCarefully(promote_func fn,
51455145

51465146
if (sc->promotion)
51475147
{
5148-
LoaderAllocator*pLoaderAllocator = LoaderAllocator::GetAssociatedLoaderAllocator_Unsafe(PTR_TO_TADDR(*ppObj));
5149-
if (pLoaderAllocator != NULL)
5150-
{
5151-
GcReportLoaderAllocator(fn, sc, pLoaderAllocator);
5152-
}
5148+
LoaderAllocator::GcReportAssociatedLoaderAllocators_Unsafe(PTR_TO_TADDR(*ppObj), fn, sc);
51535149
}
5150+
51545151
#endif // !defined(DACCESS_COMPILE)
51555152

51565153
(*fn) (ppObj, sc, flags);

0 commit comments

Comments
 (0)