Skip to content

Remove GetDomain functions on assorted method/type/assembly classes which are always in the single app domain #98135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4389,20 +4389,8 @@ ClrDataAccess::TranslateExceptionRecordToNotification(

if(DACNotify::ParseJITNotification(exInfo, methodDescPtr, nativeCodeLocation))
{
// Try and find the right appdomain
MethodDesc* methodDesc = PTR_MethodDesc(methodDescPtr);
BaseDomain* baseDomain = methodDesc->GetDomain();
AppDomain* appDomain = NULL;

if (baseDomain->IsAppDomain())
{
appDomain = PTR_AppDomain(PTR_HOST_TO_TADDR(baseDomain));
}
else
{
// Find a likely domain, because it's the shared domain.
appDomain = AppDomain::GetCurrentDomain();
}
AppDomain* appDomain = AppDomain::GetCurrentDomain();

pubMethodInst =
new (nothrow) ClrDataMethodInstance(this,
Expand Down Expand Up @@ -4453,20 +4441,8 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
TADDR methodDescPtr;
if (DACNotify::ParseExceptionCatcherEnterNotification(exInfo, methodDescPtr, catcherNativeOffset))
{
// Try and find the right appdomain
MethodDesc* methodDesc = PTR_MethodDesc(methodDescPtr);
BaseDomain* baseDomain = methodDesc->GetDomain();
AppDomain* appDomain = NULL;

if (baseDomain->IsAppDomain())
{
appDomain = PTR_AppDomain(PTR_HOST_TO_TADDR(baseDomain));
}
else
{
// Find a likely domain, because it's the shared domain.
appDomain = AppDomain::GetCurrentDomain();
}
AppDomain* appDomain = AppDomain::GetCurrentDomain();

pubMethodInst =
new (nothrow) ClrDataMethodInstance(this,
Expand Down Expand Up @@ -7978,7 +7954,7 @@ void DacStackReferenceWalker::GCEnumCallback(LPVOID hCallback, OBJECTREF *pObjec
{
CORDB_ADDRESS fixed_obj = 0;
HRESULT hr = dsc->pWalker->mHeap.ListNearObjects((CORDB_ADDRESS)obj, NULL, &fixed_obj, NULL);

// Interior pointers need not lie on the manage heap at all. When this happens, ListNearObjects
// will return E_FAIL. In this case, we need to be sure to not include this stack slot in our
// enumeration because ICorDebug expects every location enumerated by this API to point to a
Expand Down
42 changes: 9 additions & 33 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,9 +1787,6 @@ void DacDbiInterfaceImpl::GetInstantiationFieldInfo (VMPTR_DomainAssembly
{
DD_ENTER_MAY_THROW;

DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr();
_ASSERTE(pDomainAssembly != NULL);
AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();
TypeHandle thExact;
TypeHandle thApprox;

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

pFieldList->Alloc(GetTotalFieldCount(thApprox));

CollectFields(thExact, thApprox, pAppDomain, pFieldList);
CollectFields(thExact, thApprox, AppDomain::GetCurrentDomain(), pFieldList);

} // DacDbiInterfaceImpl::GetInstantiationFieldInfo

Expand Down Expand Up @@ -3559,16 +3556,15 @@ HRESULT DacDbiInterfaceImpl::GetDelegateTargetObject(
{
PTR_Object pRemoteTargetObj = OBJECTREFToObject(pDelObj->GetTarget());
ppTargetObj->SetDacTargetPtr(pRemoteTargetObj.GetAddr());
ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(pRemoteTargetObj->GetGCSafeMethodTable()->GetDomain()->AsAppDomain()));
break;
}

default:
ppTargetObj->SetDacTargetPtr(NULL);
ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(pDelObj->GetGCSafeMethodTable()->GetDomain()->AsAppDomain()));
break;
}

ppTargetAppDomain->SetDacTargetPtr(dac_cast<TADDR>(AppDomain::GetCurrentDomain()));
return hr;
}

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

Module* pModule = currentElement.pFunc->GetModule();
BaseDomain* pBaseDomain = currentElement.pFunc->GetAssembly()->GetDomain();

AppDomain* pDomain = NULL;
DomainAssembly* pDomainAssembly = NULL;

pDomain = pBaseDomain->AsAppDomain();

AppDomain* pDomain = AppDomain::GetCurrentDomain();
_ASSERTE(pDomain != NULL);

pDomainAssembly = pModule->GetDomainAssembly();
Module* pModule = currentElement.pFunc->GetModule();
DomainAssembly* pDomainAssembly = pModule->GetDomainAssembly();
_ASSERTE(pDomainAssembly != NULL);

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

AppDomain * pAppDomain = pDomainAssembly->GetAppDomain();

pTargetRefInfo->vmDomainAssembly.SetDacTargetPtr(PTR_HOST_TO_TADDR(pTargetModule->GetDomainAssembly()));
pTargetRefInfo->typeToken = targetTypeDef;
}
Expand Down Expand Up @@ -4381,11 +4369,10 @@ void DacDbiInterfaceImpl::GetDomainAssemblyData(VMPTR_DomainAssembly vmDomainAss
ZeroMemory(pData, sizeof(*pData));

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

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

// Implement IDacDbiInterface::GetModuleData
Expand Down Expand Up @@ -4525,7 +4512,6 @@ VMPTR_DomainAssembly DacDbiInterfaceImpl::ResolveAssembly(


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

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

PTR_Object obj(TO_TADDR(addr));
MethodTable *mt = obj->GetMethodTable();

PTR_Module module = mt->GetModule();
PTR_Assembly assembly = module->GetAssembly();
BaseDomain *baseDomain = assembly->GetDomain();

if (baseDomain->IsAppDomain())
{
pAppDomain->SetDacTargetPtr(PTR_HOST_TO_TADDR(baseDomain->AsAppDomain()));
pModule->SetDacTargetPtr(PTR_HOST_TO_TADDR(module));
pDomainAssembly->SetDacTargetPtr(PTR_HOST_TO_TADDR(module->GetDomainAssembly()));
}
else
{
return false;
}
pAppDomain->SetDacTargetPtr(PTR_HOST_TO_TADDR(AppDomain::GetCurrentDomain()));
pModule->SetDacTargetPtr(PTR_HOST_TO_TADDR(module));
pDomainAssembly->SetDacTargetPtr(PTR_HOST_TO_TADDR(module->GetDomainAssembly()));

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,7 @@ ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS cdBaseDomainPtr, CLRDATA_ADDRESS

assemblyData->AssemblyPtr = HOST_CDADDR(pAssembly);
assemblyData->ClassLoader = HOST_CDADDR(pAssembly->GetLoader());
assemblyData->ParentDomain = HOST_CDADDR(pAssembly->GetDomain());
assemblyData->ParentDomain = HOST_CDADDR(AppDomain::GetCurrentDomain());
assemblyData->isDynamic = pAssembly->IsDynamic();
assemblyData->ModuleCount = 0;
assemblyData->isDomainNeutral = FALSE;
Expand Down
9 changes: 2 additions & 7 deletions src/coreclr/debug/daccess/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2497,14 +2497,9 @@ ClrDataModule::GetFlags(
}

PTR_Assembly pAssembly = m_module->GetAssembly();
PTR_BaseDomain pBaseDomain = pAssembly->GetDomain();
if (pBaseDomain->IsAppDomain())
if (pAssembly == AppDomain::GetCurrentDomain()->GetRootAssembly())
{
PTR_AppDomain pAppDomain = pBaseDomain->AsAppDomain();
if (pAssembly == pAppDomain->GetRootAssembly())
{
(*flags) |= CLRDATA_MODULE_IS_MAIN_MODULE;
}
(*flags) |= CLRDATA_MODULE_IS_MAIN_MODULE;
}
status = S_OK;
}
Expand Down
24 changes: 11 additions & 13 deletions src/coreclr/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5134,8 +5134,8 @@ DebuggerModule * Debugger::LookupOrCreateModule(DomainAssembly * pDomainAssembly
{
_ASSERTE(pDomainAssembly != NULL);
LOG((LF_CORDB, LL_INFO1000, "D::LOCM df=%p\n", pDomainAssembly));
DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetModule(), pDomainAssembly->GetAppDomain());
LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetModule(), pDomainAssembly->GetAppDomain(), pDModule));
DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetModule(), AppDomain::GetCurrentDomain());
LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetModule(), AppDomain::GetCurrentDomain(), pDModule));
_ASSERTE(pDModule != NULL);
_ASSERTE(pDModule->GetDomainAssembly() == pDomainAssembly);

Expand Down Expand Up @@ -5249,7 +5249,7 @@ DebuggerModule* Debugger::AddDebuggerModule(DomainAssembly * pDomainAssembly)
DebuggerDataLockHolder chInfo(this);

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

HRESULT hr = CheckInitModuleTable();
IfFailThrow(hr);
Expand Down Expand Up @@ -6268,10 +6268,8 @@ void Debugger::SendEnCUpdateEvent(DebuggerIPCEventType eventType,
event->EnCUpdate.classMetadataToken = classToken;

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

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

m_pRCThread->SendIPCEvent();
Expand Down Expand Up @@ -9236,7 +9234,7 @@ void Debugger::LoadAssembly(DomainAssembly * pDomainAssembly)
return;

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

if (!CORDebuggerAttached())
{
Expand All @@ -9254,7 +9252,7 @@ void Debugger::LoadAssembly(DomainAssembly * pDomainAssembly)
InitIPCEvent(ipce,
DB_IPCE_LOAD_ASSEMBLY,
pThread,
pDomainAssembly->GetAppDomain());
AppDomain::GetCurrentDomain());

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

Expand Down Expand Up @@ -9292,7 +9290,7 @@ void Debugger::UnloadAssembly(DomainAssembly * pDomainAssembly)
return;

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

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

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

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

_ASSERTE(bp != NULL);
}
Expand Down Expand Up @@ -13098,7 +13096,7 @@ HRESULT Debugger::RemapComplete(MethodDesc* pMD, TADDR addr, SIZE_T nativeOffset
bp = new (interopsafe, nothrow) DebuggerEnCBreakpoint( nativeOffset,
pJitInfo,
DebuggerEnCBreakpoint::REMAP_COMPLETE,
(AppDomain *)pMD->GetModule()->GetDomain());
AppDomain::GetCurrentDomain());
if (bp == NULL)
{
_ASSERTE(!"Debugger doesn't handle OOM");
Expand Down
Loading