Skip to content

Commit c37e13f

Browse files
authored
Remove GetDomain functions on assorted method/type/assembly classes which are always in the single app domain (#98135)
- Remove `GetDomain` functions on `MethodDesc`, `MethodTable`, `TypeDesc`, and `TypeHandle`. They always return the single current app domain. - Remove `GetDomain` functions and variables on `Assembly`, `DomainAssembly`, and `Module`. The actual domain they are constructed with is always the single current app domain.
1 parent e3b9b7e commit c37e13f

35 files changed

+115
-385
lines changed

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,20 +4389,8 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
43894389

43904390
if(DACNotify::ParseJITNotification(exInfo, methodDescPtr, nativeCodeLocation))
43914391
{
4392-
// Try and find the right appdomain
43934392
MethodDesc* methodDesc = PTR_MethodDesc(methodDescPtr);
4394-
BaseDomain* baseDomain = methodDesc->GetDomain();
4395-
AppDomain* appDomain = NULL;
4396-
4397-
if (baseDomain->IsAppDomain())
4398-
{
4399-
appDomain = PTR_AppDomain(PTR_HOST_TO_TADDR(baseDomain));
4400-
}
4401-
else
4402-
{
4403-
// Find a likely domain, because it's the shared domain.
4404-
appDomain = AppDomain::GetCurrentDomain();
4405-
}
4393+
AppDomain* appDomain = AppDomain::GetCurrentDomain();
44064394

44074395
pubMethodInst =
44084396
new (nothrow) ClrDataMethodInstance(this,
@@ -4453,20 +4441,8 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
44534441
TADDR methodDescPtr;
44544442
if (DACNotify::ParseExceptionCatcherEnterNotification(exInfo, methodDescPtr, catcherNativeOffset))
44554443
{
4456-
// Try and find the right appdomain
44574444
MethodDesc* methodDesc = PTR_MethodDesc(methodDescPtr);
4458-
BaseDomain* baseDomain = methodDesc->GetDomain();
4459-
AppDomain* appDomain = NULL;
4460-
4461-
if (baseDomain->IsAppDomain())
4462-
{
4463-
appDomain = PTR_AppDomain(PTR_HOST_TO_TADDR(baseDomain));
4464-
}
4465-
else
4466-
{
4467-
// Find a likely domain, because it's the shared domain.
4468-
appDomain = AppDomain::GetCurrentDomain();
4469-
}
4445+
AppDomain* appDomain = AppDomain::GetCurrentDomain();
44704446

44714447
pubMethodInst =
44724448
new (nothrow) ClrDataMethodInstance(this,
@@ -7978,7 +7954,7 @@ void DacStackReferenceWalker::GCEnumCallback(LPVOID hCallback, OBJECTREF *pObjec
79787954
{
79797955
CORDB_ADDRESS fixed_obj = 0;
79807956
HRESULT hr = dsc->pWalker->mHeap.ListNearObjects((CORDB_ADDRESS)obj, NULL, &fixed_obj, NULL);
7981-
7957+
79827958
// Interior pointers need not lie on the manage heap at all. When this happens, ListNearObjects
79837959
// will return E_FAIL. In this case, we need to be sure to not include this stack slot in our
79847960
// enumeration because ICorDebug expects every location enumerated by this API to point to a

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,9 +1787,6 @@ void DacDbiInterfaceImpl::GetInstantiationFieldInfo (VMPTR_DomainAssembly
17871787
{
17881788
DD_ENTER_MAY_THROW;
17891789

1790-
DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr();
1791-
_ASSERTE(pDomainAssembly != NULL);
1792-
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
17931790
TypeHandle thExact;
17941791
TypeHandle thApprox;
17951792

@@ -1799,7 +1796,7 @@ void DacDbiInterfaceImpl::GetInstantiationFieldInfo (VMPTR_DomainAssembly
17991796

18001797
pFieldList->Alloc(GetTotalFieldCount(thApprox));
18011798

1802-
CollectFields(thExact, thApprox, pAppDomain, pFieldList);
1799+
CollectFields(thExact, thApprox, AppDomain::GetCurrentDomain(), pFieldList);
18031800

18041801
} // DacDbiInterfaceImpl::GetInstantiationFieldInfo
18051802

@@ -3559,16 +3556,15 @@ HRESULT DacDbiInterfaceImpl::GetDelegateTargetObject(
35593556
{
35603557
PTR_Object pRemoteTargetObj = OBJECTREFToObject(pDelObj->GetTarget());
35613558
ppTargetObj->SetDacTargetPtr(pRemoteTargetObj.GetAddr());
3562-
ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(pRemoteTargetObj->GetGCSafeMethodTable()->GetDomain()->AsAppDomain()));
35633559
break;
35643560
}
35653561

35663562
default:
35673563
ppTargetObj->SetDacTargetPtr(NULL);
3568-
ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(pDelObj->GetGCSafeMethodTable()->GetDomain()->AsAppDomain()));
35693564
break;
35703565
}
35713566

3567+
ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(AppDomain::GetCurrentDomain()));
35723568
return hr;
35733569
}
35743570

@@ -3735,17 +3731,11 @@ void DacDbiInterfaceImpl::GetStackFramesFromException(VMPTR_Object vmObject, Dac
37353731
DebugStackTrace::DebugStackTraceElement const& currentElement = stackFramesData.pElements[index];
37363732
DacExceptionCallStackData& currentFrame = dacStackFrames[index];
37373733

3738-
Module* pModule = currentElement.pFunc->GetModule();
3739-
BaseDomain* pBaseDomain = currentElement.pFunc->GetAssembly()->GetDomain();
3740-
3741-
AppDomain* pDomain = NULL;
3742-
DomainAssembly* pDomainAssembly = NULL;
3743-
3744-
pDomain = pBaseDomain->AsAppDomain();
3745-
3734+
AppDomain* pDomain = AppDomain::GetCurrentDomain();
37463735
_ASSERTE(pDomain != NULL);
37473736

3748-
pDomainAssembly = pModule->GetDomainAssembly();
3737+
Module* pModule = currentElement.pFunc->GetModule();
3738+
DomainAssembly* pDomainAssembly = pModule->GetDomainAssembly();
37493739
_ASSERTE(pDomainAssembly != NULL);
37503740

37513741
currentFrame.vmAppDomain.SetHostPtr(pDomain);
@@ -4130,8 +4120,6 @@ void DacDbiInterfaceImpl::ResolveTypeReference(const TypeRefData * pTypeRefInfo,
41304120
_ASSERTE(pTargetModule != NULL);
41314121
_ASSERTE( TypeFromToken(targetTypeDef) == mdtTypeDef );
41324122

4133-
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
4134-
41354123
pTargetRefInfo->vmDomainAssembly.SetDacTargetPtr(PTR_HOST_TO_TADDR(pTargetModule->GetDomainAssembly()));
41364124
pTargetRefInfo->typeToken = targetTypeDef;
41374125
}
@@ -4381,11 +4369,10 @@ void DacDbiInterfaceImpl::GetDomainAssemblyData(VMPTR_DomainAssembly vmDomainAss
43814369
ZeroMemory(pData, sizeof(*pData));
43824370

43834371
DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr();
4384-
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
43854372

43864373
// @dbgtodo - is this efficient DAC usage (perhaps a dac-cop rule)? Are we round-tripping the pointer?
43874374
pData->vmDomainAssembly.SetHostPtr(pDomainAssembly);
4388-
pData->vmAppDomain.SetHostPtr(pAppDomain);
4375+
pData->vmAppDomain.SetHostPtr(AppDomain::GetCurrentDomain());
43894376
}
43904377

43914378
// Implement IDacDbiInterface::GetModuleData
@@ -4525,7 +4512,6 @@ VMPTR_DomainAssembly DacDbiInterfaceImpl::ResolveAssembly(
45254512

45264513

45274514
DomainAssembly * pDomainAssembly = vmScope.GetDacPtr();
4528-
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
45294515
Module * pModule = pDomainAssembly->GetModule();
45304516

45314517
VMPTR_DomainAssembly vmDomainAssembly = VMPTR_DomainAssembly::NullPtr();
@@ -7045,21 +7031,11 @@ bool DacDbiInterfaceImpl::GetAppDomainForObject(CORDB_ADDRESS addr, OUT VMPTR_Ap
70457031

70467032
PTR_Object obj(TO_TADDR(addr));
70477033
MethodTable *mt = obj->GetMethodTable();
7048-
70497034
PTR_Module module = mt->GetModule();
7050-
PTR_Assembly assembly = module->GetAssembly();
7051-
BaseDomain *baseDomain = assembly->GetDomain();
70527035

7053-
if (baseDomain->IsAppDomain())
7054-
{
7055-
pAppDomain->SetDacTargetPtr(PTR_HOST_TO_TADDR(baseDomain->AsAppDomain()));
7056-
pModule->SetDacTargetPtr(PTR_HOST_TO_TADDR(module));
7057-
pDomainAssembly->SetDacTargetPtr(PTR_HOST_TO_TADDR(module->GetDomainAssembly()));
7058-
}
7059-
else
7060-
{
7061-
return false;
7062-
}
7036+
pAppDomain->SetDacTargetPtr(PTR_HOST_TO_TADDR(AppDomain::GetCurrentDomain()));
7037+
pModule->SetDacTargetPtr(PTR_HOST_TO_TADDR(module));
7038+
pDomainAssembly->SetDacTargetPtr(PTR_HOST_TO_TADDR(module->GetDomainAssembly()));
70637039

70647040
return true;
70657041
}

src/coreclr/debug/daccess/request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS cdBaseDomainPtr, CLRDATA_ADDRESS
25782578

25792579
assemblyData->AssemblyPtr = HOST_CDADDR(pAssembly);
25802580
assemblyData->ClassLoader = HOST_CDADDR(pAssembly->GetLoader());
2581-
assemblyData->ParentDomain = HOST_CDADDR(pAssembly->GetDomain());
2581+
assemblyData->ParentDomain = HOST_CDADDR(AppDomain::GetCurrentDomain());
25822582
assemblyData->isDynamic = pAssembly->IsDynamic();
25832583
assemblyData->ModuleCount = 0;
25842584
assemblyData->isDomainNeutral = FALSE;

src/coreclr/debug/daccess/task.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,14 +2497,9 @@ ClrDataModule::GetFlags(
24972497
}
24982498

24992499
PTR_Assembly pAssembly = m_module->GetAssembly();
2500-
PTR_BaseDomain pBaseDomain = pAssembly->GetDomain();
2501-
if (pBaseDomain->IsAppDomain())
2500+
if (pAssembly == AppDomain::GetCurrentDomain()->GetRootAssembly())
25022501
{
2503-
PTR_AppDomain pAppDomain = pBaseDomain->AsAppDomain();
2504-
if (pAssembly == pAppDomain->GetRootAssembly())
2505-
{
2506-
(*flags) |= CLRDATA_MODULE_IS_MAIN_MODULE;
2507-
}
2502+
(*flags) |= CLRDATA_MODULE_IS_MAIN_MODULE;
25082503
}
25092504
status = S_OK;
25102505
}

src/coreclr/debug/ee/debugger.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5134,8 +5134,8 @@ DebuggerModule * Debugger::LookupOrCreateModule(DomainAssembly * pDomainAssembly
51345134
{
51355135
_ASSERTE(pDomainAssembly != NULL);
51365136
LOG((LF_CORDB, LL_INFO1000, "D::LOCM df=%p\n", pDomainAssembly));
5137-
DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetModule(), pDomainAssembly->GetAppDomain());
5138-
LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetModule(), pDomainAssembly->GetAppDomain(), pDModule));
5137+
DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetModule(), AppDomain::GetCurrentDomain());
5138+
LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetModule(), AppDomain::GetCurrentDomain(), pDModule));
51395139
_ASSERTE(pDModule != NULL);
51405140
_ASSERTE(pDModule->GetDomainAssembly() == pDomainAssembly);
51415141

@@ -5249,7 +5249,7 @@ DebuggerModule* Debugger::AddDebuggerModule(DomainAssembly * pDomainAssembly)
52495249
DebuggerDataLockHolder chInfo(this);
52505250

52515251
Module * pRuntimeModule = pDomainAssembly->GetModule();
5252-
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
5252+
AppDomain * pAppDomain = AppDomain::GetCurrentDomain();
52535253

52545254
HRESULT hr = CheckInitModuleTable();
52555255
IfFailThrow(hr);
@@ -6268,10 +6268,8 @@ void Debugger::SendEnCUpdateEvent(DebuggerIPCEventType eventType,
62686268
event->EnCUpdate.classMetadataToken = classToken;
62696269

62706270
_ASSERTE(pModule);
6271-
// we don't support shared assemblies, so must have an appdomain
6272-
_ASSERTE(pModule->GetDomain()->IsAppDomain());
62736271

6274-
DebuggerModule * pDModule = LookupOrCreateModule(pModule, pModule->GetDomain()->AsAppDomain());
6272+
DebuggerModule * pDModule = LookupOrCreateModule(pModule, AppDomain::GetCurrentDomain());
62756273
event->EnCUpdate.vmDomainAssembly.SetRawPtr((pDModule ? pDModule->GetDomainAssembly() : NULL));
62766274

62776275
m_pRCThread->SendIPCEvent();
@@ -9236,7 +9234,7 @@ void Debugger::LoadAssembly(DomainAssembly * pDomainAssembly)
92369234
return;
92379235

92389236
LOG((LF_CORDB, LL_INFO100, "D::LA: Load Assembly Asy:0x%p AD:0x%p which:%s\n",
9239-
pDomainAssembly, pDomainAssembly->GetAppDomain(), pDomainAssembly->GetAssembly()->GetDebugName() ));
9237+
pDomainAssembly, AppDomain::GetCurrentDomain(), pDomainAssembly->GetAssembly()->GetDebugName() ));
92409238

92419239
if (!CORDebuggerAttached())
92429240
{
@@ -9254,7 +9252,7 @@ void Debugger::LoadAssembly(DomainAssembly * pDomainAssembly)
92549252
InitIPCEvent(ipce,
92559253
DB_IPCE_LOAD_ASSEMBLY,
92569254
pThread,
9257-
pDomainAssembly->GetAppDomain());
9255+
AppDomain::GetCurrentDomain());
92589256

92599257
ipce->AssemblyData.vmDomainAssembly.SetRawPtr(pDomainAssembly);
92609258

@@ -9292,7 +9290,7 @@ void Debugger::UnloadAssembly(DomainAssembly * pDomainAssembly)
92929290
return;
92939291

92949292
LOG((LF_CORDB, LL_INFO100, "D::UA: Unload Assembly Asy:0x%p AD:0x%p which:%s\n",
9295-
pDomainAssembly, pDomainAssembly->GetAppDomain(), pDomainAssembly->GetAssembly()->GetDebugName() ));
9293+
pDomainAssembly, AppDomain::GetCurrentDomain(), pDomainAssembly->GetAssembly()->GetDebugName() ));
92969294

92979295
Thread *thread = g_pEEInterface->GetThread();
92989296
// Note that the debugger lock is reentrant, so we may or may not hold it already.
@@ -9304,7 +9302,7 @@ void Debugger::UnloadAssembly(DomainAssembly * pDomainAssembly)
93049302
InitIPCEvent(ipce,
93059303
DB_IPCE_UNLOAD_ASSEMBLY,
93069304
thread,
9307-
pDomainAssembly->GetAppDomain());
9305+
AppDomain::GetCurrentDomain());
93089306
ipce->AssemblyData.vmDomainAssembly.SetRawPtr(pDomainAssembly);
93099307

93109308
SendSimpleIPCEventAndBlock();
@@ -9411,7 +9409,7 @@ void Debugger::LoadModule(Module* pRuntimeModule,
94119409
// We should simply things when we actually get rid of DebuggerModule, possibly by just passing the
94129410
// DomainAssembly around.
94139411
_ASSERTE(module->GetDomainAssembly() == pDomainAssembly);
9414-
_ASSERTE(module->GetAppDomain() == pDomainAssembly->GetAppDomain());
9412+
_ASSERTE(module->GetAppDomain() == AppDomain::GetCurrentDomain());
94159413
_ASSERTE(module->GetRuntimeModule() == pDomainAssembly->GetModule());
94169414

94179415
// Send a load module event to the Right Side.
@@ -12937,7 +12935,7 @@ HRESULT Debugger::UpdateFunction(MethodDesc* pMD, SIZE_T encVersion)
1293712935
bp = new (interopsafe) DebuggerEnCBreakpoint( offset,
1293812936
pJitInfo,
1293912937
DebuggerEnCBreakpoint::REMAP_PENDING,
12940-
(AppDomain *)pModule->GetDomain());
12938+
AppDomain::GetCurrentDomain());
1294112939

1294212940
_ASSERTE(bp != NULL);
1294312941
}
@@ -13098,7 +13096,7 @@ HRESULT Debugger::RemapComplete(MethodDesc* pMD, TADDR addr, SIZE_T nativeOffset
1309813096
bp = new (interopsafe, nothrow) DebuggerEnCBreakpoint( nativeOffset,
1309913097
pJitInfo,
1310013098
DebuggerEnCBreakpoint::REMAP_COMPLETE,
13101-
(AppDomain *)pMD->GetModule()->GetDomain());
13099+
AppDomain::GetCurrentDomain());
1310213100
if (bp == NULL)
1310313101
{
1310413102
_ASSERTE(!"Debugger doesn't handle OOM");

0 commit comments

Comments
 (0)