Skip to content

Commit c4bc758

Browse files
authored
Reapply "Replace CordbProcess::GetSharedDomain with GetAppDomain" (#117224)
Fix on top of the original: use Assembly as the ID for CordbAssembly instead of DomainAssembly.
1 parent 919597a commit c4bc758

File tree

9 files changed

+50
-166
lines changed

9 files changed

+50
-166
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,14 +4856,12 @@ VMPTR_OBJECTHANDLE DacDbiInterfaceImpl::GetCurrentCustomDebuggerNotification(VMP
48564856
return vmObjHandle;
48574857
}
48584858

4859-
// Return the current appdomain the specified thread is in.
4860-
VMPTR_AppDomain DacDbiInterfaceImpl::GetCurrentAppDomain(VMPTR_Thread vmThread)
4859+
// Return the current appdomain.
4860+
VMPTR_AppDomain DacDbiInterfaceImpl::GetCurrentAppDomain()
48614861
{
48624862
DD_ENTER_MAY_THROW;
48634863

4864-
Thread * pThread = vmThread.GetDacPtr();
48654864
AppDomain * pAppDomain = AppDomain::GetCurrentDomain();
4866-
48674865
VMPTR_AppDomain vmAppDomain = VMPTR_AppDomain::NullPtr();
48684866
vmAppDomain.SetDacTargetPtr(PTR_HOST_TO_TADDR(pAppDomain));
48694867
return vmAppDomain;

src/coreclr/debug/daccess/dacdbiimpl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,8 @@ class DacDbiInterfaceImpl :
822822
// (or a dump was generated while in this callback)
823823
VMPTR_OBJECTHANDLE GetCurrentCustomDebuggerNotification(VMPTR_Thread vmThread);
824824

825-
826-
// Return the current appdomain the specified thread is in.
827-
VMPTR_AppDomain GetCurrentAppDomain(VMPTR_Thread vmThread);
825+
// Return the current appdomain
826+
VMPTR_AppDomain GetCurrentAppDomain();
828827

829828
// Given an assembly ref token and metadata scope (via the DomainAssembly), resolve the assembly.
830829
VMPTR_DomainAssembly ResolveAssembly(VMPTR_DomainAssembly vmScope, mdToken tkAssemblyRef);

src/coreclr/debug/di/module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ CordbModule::CordbModule(
6565
pProcess->GetDAC()->GetDomainAssemblyData(vmDomainAssembly, &dfInfo); // throws
6666

6767
m_pAppDomain = pProcess->LookupOrCreateAppDomain(dfInfo.vmAppDomain);
68+
_ASSERTE(m_pAppDomain == pProcess->GetAppDomain());
6869
m_pAssembly = m_pAppDomain->LookupOrCreateAssembly(dfInfo.vmDomainAssembly);
6970
}
7071
else
7172
{
72-
// Not yet implemented
73-
m_pAppDomain = pProcess->GetSharedAppDomain();
73+
m_pAppDomain = pProcess->GetAppDomain();
7474
m_pAssembly = m_pAppDomain->LookupOrCreateAssembly(modInfo.vmAssembly);
7575
}
7676
#ifdef _DEBUG

src/coreclr/debug/di/process.cpp

Lines changed: 19 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,6 @@ CordbProcess::CordbProcess(ULONG64 clrInstanceId,
921921
m_unmanagedThreads(11),
922922
#endif
923923
m_appDomains(11),
924-
m_sharedAppDomain(0),
925924
m_steppers(11),
926925
m_continueCounter(1),
927926
m_flushCounter(0),
@@ -956,7 +955,6 @@ CordbProcess::CordbProcess(ULONG64 clrInstanceId,
956955
m_iFirstPatch(0),
957956
m_hHelperThread(NULL),
958957
m_dispatchedEvent(DB_IPCE_DEBUGGER_INVALID),
959-
m_pDefaultAppDomain(NULL),
960958
m_hDacModule(hDacModule),
961959
m_pDacPrimitives(NULL),
962960
m_pEventChannel(NULL),
@@ -1059,8 +1057,6 @@ CordbProcess::~CordbProcess()
10591057
// We shouldn't still be in Cordb's list of processes. Unfortunately, our root Cordb object
10601058
// may have already been deleted b/c we're at the mercy of ref-counting, so we can't check.
10611059

1062-
_ASSERTE(m_sharedAppDomain == NULL);
1063-
10641060
m_processMutex.Destroy();
10651061
m_StopGoLock.Destroy();
10661062

@@ -1288,16 +1284,8 @@ void CordbProcess::NeuterChildren()
12881284

12891285
m_userThreads.NeuterAndClear(GetProcessLock());
12901286

1291-
m_pDefaultAppDomain = NULL;
1292-
12931287
// Frees per-appdomain left-side resources. See assumptions above.
12941288
m_appDomains.NeuterAndClear(GetProcessLock());
1295-
if (m_sharedAppDomain != NULL)
1296-
{
1297-
m_sharedAppDomain->Neuter();
1298-
m_sharedAppDomain->InternalRelease();
1299-
m_sharedAppDomain = NULL;
1300-
}
13011289

13021290
m_steppers.NeuterAndClear(GetProcessLock());
13031291

@@ -2306,10 +2294,10 @@ HRESULT CordbProcess::EnumerateHeapRegions(ICorDebugHeapSegmentEnum **ppRegions)
23062294

23072295
HRESULT CordbProcess::GetObject(CORDB_ADDRESS addr, ICorDebugObjectValue **ppObject)
23082296
{
2309-
return this->GetObjectInternal(addr, nullptr, ppObject);
2297+
return this->GetObjectInternal(addr, ppObject);
23102298
}
23112299

2312-
HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, CordbAppDomain* pAppDomainOverride, ICorDebugObjectValue **pObject)
2300+
HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, ICorDebugObjectValue **pObject)
23132301
{
23142302
HRESULT hr = S_OK;
23152303

@@ -2333,7 +2321,7 @@ HRESULT CordbProcess::GetObjectInternal(CORDB_ADDRESS addr, CordbAppDomain* pApp
23332321

23342322
CordbAppDomain *cdbAppDomain = NULL;
23352323
CordbType *pType = NULL;
2336-
hr = GetTypeForObject(addr, pAppDomainOverride, &pType, &cdbAppDomain);
2324+
hr = GetTypeForObject(addr, &pType, &cdbAppDomain);
23372325

23382326
if (SUCCEEDED(hr))
23392327
{
@@ -2441,7 +2429,7 @@ HRESULT CordbProcess::GetTypeForTypeID(COR_TYPEID id, ICorDebugType **ppType)
24412429
GetDAC()->GetObjectExpandedTypeInfoFromID(AllBoxed, VMPTR_AppDomain::NullPtr(), id, &data);
24422430

24432431
CordbType *type = 0;
2444-
hr = CordbType::TypeDataToType(GetSharedAppDomain(), &data, &type);
2432+
hr = CordbType::TypeDataToType(GetAppDomain(), &data, &type);
24452433

24462434
if (SUCCEEDED(hr))
24472435
hr = type->QueryInterface(IID_ICorDebugType, (void**)ppType);
@@ -2569,7 +2557,7 @@ COM_METHOD CordbProcess::EnumerateLoaderHeapMemoryRegions(ICorDebugMemoryRangeEn
25692557
return hr;
25702558
}
25712559

2572-
HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbAppDomain* pAppDomainOverride, CordbType **ppType, CordbAppDomain **pAppDomain)
2560+
HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbType **ppType, CordbAppDomain **pAppDomain)
25732561
{
25742562
VMPTR_AppDomain appDomain;
25752563
VMPTR_Module mod;
@@ -2578,11 +2566,7 @@ HRESULT CordbProcess::GetTypeForObject(CORDB_ADDRESS addr, CordbAppDomain* pAppD
25782566
HRESULT hr = E_FAIL;
25792567
if (GetDAC()->GetAppDomainForObject(addr, &appDomain, &mod, &domainAssembly))
25802568
{
2581-
if (pAppDomainOverride)
2582-
{
2583-
appDomain = pAppDomainOverride->GetADToken();
2584-
}
2585-
CordbAppDomain *cdbAppDomain = appDomain.IsNull() ? GetSharedAppDomain() : LookupOrCreateAppDomain(appDomain);
2569+
CordbAppDomain *cdbAppDomain = appDomain.IsNull() ? GetAppDomain() : LookupOrCreateAppDomain(appDomain);
25862570

25872571
_ASSERTE(cdbAppDomain);
25882572

@@ -5369,19 +5353,6 @@ void CordbProcess::RawDispatchEvent(
53695353
}
53705354
_ASSERTE (pAppDomain != NULL);
53715355

5372-
// See if this is the default AppDomain exiting. This should only happen very late in
5373-
// the shutdown cycle, and so we shouldn't do anything significant with m_pDefaultDomain==NULL.
5374-
// We should try and remove m_pDefaultDomain entirely since we can't count on it always existing.
5375-
if (pAppDomain == m_pDefaultAppDomain)
5376-
{
5377-
m_pDefaultAppDomain = NULL;
5378-
}
5379-
5380-
// Update any threads which were last seen in this AppDomain. We don't
5381-
// get any notification when a thread leaves an AppDomain, so our idea
5382-
// of what AppDomain the thread is in may be out of date.
5383-
UpdateThreadsForAdUnload( pAppDomain );
5384-
53855356
// This will still maintain weak references so we could call Continue.
53865357
AddToNeuterOnContinueList(pAppDomain);
53875358

@@ -8717,19 +8688,23 @@ CordbAppDomain * CordbProcess::LookupOrCreateAppDomain(VMPTR_AppDomain vmAppDoma
87178688
return CacheAppDomain(vmAppDomain);
87188689
}
87198690

8720-
CordbAppDomain * CordbProcess::GetSharedAppDomain()
8691+
CordbAppDomain * CordbProcess::GetAppDomain()
87218692
{
8722-
if (m_sharedAppDomain == NULL)
8693+
// Return the one and only app domain
8694+
HASHFIND find;
8695+
CordbAppDomain* appDomain = m_appDomains.FindFirst(&find);
8696+
if (appDomain != NULL)
87238697
{
8724-
CordbAppDomain *pAD = new CordbAppDomain(this, VMPTR_AppDomain::NullPtr());
8725-
if (InterlockedCompareExchangeT<CordbAppDomain*>(&m_sharedAppDomain, pAD, NULL) != NULL)
8726-
{
8727-
delete pAD;
8728-
}
8729-
m_sharedAppDomain->InternalAddRef();
8698+
const ULONG appDomainId = 1; // DefaultADID in appdomain.hpp
8699+
ULONG32 id;
8700+
HRESULT hr = appDomain->GetID(&id);
8701+
TargetConsistencyCheck(SUCCEEDED(hr) && id == appDomainId);
8702+
return appDomain;
87308703
}
87318704

8732-
return m_sharedAppDomain;
8705+
VMPTR_AppDomain vmAppDomain = GetDAC()->GetCurrentAppDomain();
8706+
appDomain = LookupOrCreateAppDomain(vmAppDomain);
8707+
return appDomain;
87338708
}
87348709

87358710
//---------------------------------------------------------------------------------------
@@ -8765,10 +8740,6 @@ CordbAppDomain * CordbProcess::CacheAppDomain(VMPTR_AppDomain vmAppDomain)
87658740
// The cache will take ownership.
87668741
m_appDomains.AddBaseOrThrow(pAppDomain);
87678742

8768-
// If this assert fires, then it likely means the target is corrupted.
8769-
TargetConsistencyCheck(m_pDefaultAppDomain == NULL);
8770-
m_pDefaultAppDomain = pAppDomain;
8771-
87728743
CordbAppDomain * pReturn = pAppDomain;
87738744
pAppDomain.ClearAndMarkDontNeuter();
87748745

@@ -15263,46 +15234,6 @@ HRESULT CordbProcess::IsReadyForDetach()
1526315234
return S_OK;
1526415235
}
1526515236

15266-
15267-
/*
15268-
* Look for any thread which was last seen in the specified AppDomain.
15269-
* The CordbAppDomain object is about to be neutered due to an AD Unload
15270-
* So the thread must no longer be considered to be in that domain.
15271-
* Note that this is a workaround due to the existence of the (possibly incorrect)
15272-
* cached AppDomain value. Ideally we would remove the cached value entirely
15273-
* and there would be no need for this.
15274-
*
15275-
* @dbgtodo: , appdomain: We should remove CordbThread::m_pAppDomain in the V3 architecture.
15276-
* If we need the thread's current domain, we should get it accurately with DAC.
15277-
*/
15278-
void CordbProcess::UpdateThreadsForAdUnload(CordbAppDomain * pAppDomain)
15279-
{
15280-
INTERNAL_API_ENTRY(this);
15281-
15282-
// If we're doing an AD unload then we should have already seen the ATTACH
15283-
// notification for the default domain.
15284-
//_ASSERTE( m_pDefaultAppDomain != NULL );
15285-
// @dbgtodo appdomain: fix Default domain invariants with DAC-izing Appdomain work.
15286-
15287-
RSLockHolder lockHolder(GetProcessLock());
15288-
15289-
CordbThread* t;
15290-
HASHFIND find;
15291-
15292-
// We don't need to prepopulate here (to collect LS state) because we're just updating RS state.
15293-
for (t = m_userThreads.FindFirst(&find);
15294-
t != NULL;
15295-
t = m_userThreads.FindNext(&find))
15296-
{
15297-
if( t->GetAppDomain() == pAppDomain )
15298-
{
15299-
// This thread cannot actually be in this AppDomain anymore (since it's being
15300-
// unloaded). Reset it to point to the default AppDomain
15301-
t->m_pAppDomain = m_pDefaultAppDomain;
15302-
}
15303-
}
15304-
}
15305-
1530615237
// CordbProcess::LookupClass
1530715238
// Looks up a previously constructed CordbClass instance without creating. May return NULL if the
1530815239
// CordbClass instance doesn't exist.

src/coreclr/debug/di/rsappdomain.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void CordbAppDomain::AssemblyEnumerationCallback(VMPTR_DomainAssembly vmDomainAs
388388
// Cache a new assembly
389389
//
390390
// Arguments:
391-
// vmDomainAssembly - new assembly to add to cache
391+
// vmAssembly - new assembly to add to cache
392392
//
393393
// Return Value:
394394
// Pointer to Assembly in cache.
@@ -398,29 +398,15 @@ void CordbAppDomain::AssemblyEnumerationCallback(VMPTR_DomainAssembly vmDomainAs
398398
// Caller guarantees assembly is not already added.
399399
// Called under the stop-go lock.
400400
//
401-
// Notes:
402-
//
403-
CordbAssembly * CordbAppDomain::CacheAssembly(VMPTR_DomainAssembly vmDomainAssembly)
401+
CordbAssembly * CordbAppDomain::CacheAssembly(VMPTR_Assembly vmAssembly, VMPTR_DomainAssembly vmDomainAssembly)
404402
{
405403
INTERNAL_API_ENTRY(GetProcess());
406404

407-
VMPTR_Assembly vmAssembly;
408-
GetProcess()->GetDAC()->GetAssemblyFromDomainAssembly(vmDomainAssembly, &vmAssembly);
409-
410405
RSInitHolder<CordbAssembly> pAssembly(new CordbAssembly(this, vmAssembly, vmDomainAssembly));
411406

412407
return pAssembly.TransferOwnershipToHash(&m_assemblies);
413408
}
414409

415-
CordbAssembly * CordbAppDomain::CacheAssembly(VMPTR_Assembly vmAssembly)
416-
{
417-
INTERNAL_API_ENTRY(GetProcess());
418-
419-
RSInitHolder<CordbAssembly> pAssembly(new CordbAssembly(this, vmAssembly, VMPTR_DomainAssembly()));
420-
421-
return pAssembly.TransferOwnershipToHash(&m_assemblies);
422-
}
423-
424410
//---------------------------------------------------------------------------------------
425411
//
426412
// Build up cache of assmeblies
@@ -785,7 +771,9 @@ void CordbAppDomain::RemoveAssemblyFromCache(VMPTR_DomainAssembly vmDomainAssemb
785771
{
786772
// This will handle if the assembly is not in the hash.
787773
// This could happen if we attach right before an assembly-unload event.
788-
m_assemblies.RemoveBase(VmPtrToCookie(vmDomainAssembly));
774+
VMPTR_Assembly vmAssembly;
775+
GetProcess()->GetDAC()->GetAssemblyFromDomainAssembly(vmDomainAssembly, &vmAssembly);
776+
m_assemblies.RemoveBase(VmPtrToCookie(vmAssembly));
789777
}
790778

791779
//---------------------------------------------------------------------------------------
@@ -801,15 +789,16 @@ void CordbAppDomain::RemoveAssemblyFromCache(VMPTR_DomainAssembly vmDomainAssemb
801789
//
802790
CordbAssembly * CordbAppDomain::LookupOrCreateAssembly(VMPTR_DomainAssembly vmDomainAssembly)
803791
{
804-
CordbAssembly * pAssembly = m_assemblies.GetBase(VmPtrToCookie(vmDomainAssembly));
792+
VMPTR_Assembly vmAssembly;
793+
GetProcess()->GetDAC()->GetAssemblyFromDomainAssembly(vmDomainAssembly, &vmAssembly);
794+
CordbAssembly * pAssembly = m_assemblies.GetBase(VmPtrToCookie(vmAssembly));
805795
if (pAssembly != NULL)
806796
{
807797
return pAssembly;
808798
}
809-
return CacheAssembly(vmDomainAssembly);
799+
return CacheAssembly(vmAssembly, vmDomainAssembly);
810800
}
811801

812-
813802
//
814803
CordbAssembly * CordbAppDomain::LookupOrCreateAssembly(VMPTR_Assembly vmAssembly)
815804
{
@@ -818,7 +807,7 @@ CordbAssembly * CordbAppDomain::LookupOrCreateAssembly(VMPTR_Assembly vmAssembly
818807
{
819808
return pAssembly;
820809
}
821-
return CacheAssembly(vmAssembly);
810+
return CacheAssembly(vmAssembly, VMPTR_DomainAssembly());
822811
}
823812

824813

src/coreclr/debug/di/rsassembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CordbAssembly::CordbAssembly(CordbAppDomain * pAppDomain,
2929
VMPTR_DomainAssembly vmDomainAssembly)
3030

3131
: CordbBase(pAppDomain->GetProcess(),
32-
vmDomainAssembly.IsNull() ? VmPtrToCookie(vmAssembly) : VmPtrToCookie(vmDomainAssembly),
32+
VmPtrToCookie(vmAssembly),
3333
enumCordbAssembly),
3434
m_vmAssembly(vmAssembly),
3535
m_vmDomainAssembly(vmDomainAssembly),

0 commit comments

Comments
 (0)