Remove AppDomain usage from stack walk and related places (#31708)
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 4 Feb 2020 15:03:47 +0000 (16:03 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2020 15:03:47 +0000 (07:03 -0800)
This is yet another cleanup removal of the AppDomain.

14 files changed:
src/coreclr/src/debug/daccess/dacdbiimplstackwalk.cpp
src/coreclr/src/debug/daccess/stack.cpp
src/coreclr/src/debug/ee/frameinfo.cpp
src/coreclr/src/vm/appdomain.cpp
src/coreclr/src/vm/appdomain.hpp
src/coreclr/src/vm/assembly.cpp
src/coreclr/src/vm/crossgencompile.cpp
src/coreclr/src/vm/debugdebugger.cpp
src/coreclr/src/vm/debughelp.cpp
src/coreclr/src/vm/frames.h
src/coreclr/src/vm/sigformat.cpp
src/coreclr/src/vm/stackwalk.cpp
src/coreclr/src/vm/stackwalk.h
src/coreclr/src/vm/threads.cpp

index 29dce45..c24ce1c 100644 (file)
@@ -538,13 +538,6 @@ void DacDbiInterfaceImpl::EnumerateInternalFrames(VMPTR_Thread
             fpCallback(&frameData, pUserData);
         }
 
-        // update the current appdomain if necessary
-        AppDomain * pRetDomain = pFrame->GetReturnDomain();
-        if (pRetDomain != NULL)
-        {
-            pAppDomain = pRetDomain;
-        }
-
         // move on to the next internal frame
         pFrame = pFrame->Next();
     }
@@ -695,8 +688,7 @@ void DacDbiInterfaceImpl::InitFrameData(StackFrameIterator *   pIter,
     // Since we don't have chains anymore, this can always be false.
     pFrameData->quicklyUnwound = false;
 
-    AppDomain * pAppDomain = pCF->GetAppDomain();
-    pFrameData->vmCurrentAppDomainToken.SetHostPtr(pAppDomain);
+    pFrameData->vmCurrentAppDomainToken.SetHostPtr(AppDomain::GetCurrentDomain());
 
     if (ft == kNativeRuntimeUnwindableStackFrame)
     {
index 67f08a5..57aee6d 100644 (file)
@@ -343,7 +343,7 @@ ClrDataStackWalk::GetFrame(
         RawGetFrameType(&simpleType, &detailedType);
         dataFrame =
             new (nothrow) ClrDataFrame(m_dac, simpleType, detailedType,
-                                       m_frameIter.m_crawl.GetAppDomain(),
+                                       AppDomain::GetCurrentDomain(),
                                        m_frameIter.m_crawl.GetFunction());
         if (!dataFrame)
         {
index b23905d..f718d14 100644 (file)
@@ -769,7 +769,7 @@ void FrameInfo::InitFromStubHelper(
     // Method associated w/a stub will never have a JitManager.
     this->pIJM        = NULL;
     this->MethodToken = METHODTOKEN(NULL, 0);
-    this->currentAppDomain      = pCF->GetAppDomain();
+    this->currentAppDomain      = AppDomain::GetCurrentDomain();
     this->exactGenericArgsToken = NULL;
 
     // Stub frames are mutually exclusive with chain markers.
@@ -1545,7 +1545,7 @@ StackWalkAction DebuggerWalkStackProc(CrawlFrame *pCF, void *data)
 
     // Record the appdomain that the thread was in when it
     // was running code for this frame.
-    d->info.currentAppDomain = pCF->GetAppDomain();
+    d->info.currentAppDomain = AppDomain::GetCurrentDomain();
 
     //  Grab all the info from CrawlFrame that we need to
     //  check for "Am I in an exeption code blob?" now.
index 357115b..3a7a941 100644 (file)
@@ -2260,12 +2260,10 @@ struct CallersDataWithStackMark
     BOOL foundMe;
     MethodDesc* pFoundMethod;
     MethodDesc* pPrevMethod;
-    AppDomain*  pAppDomain;
 };
 
 /*static*/
-MethodDesc* SystemDomain::GetCallersMethod(StackCrawlMark* stackMark,
-                                           AppDomain **ppAppDomain/*=NULL*/)
+MethodDesc* SystemDomain::GetCallersMethod(StackCrawlMark* stackMark)
 
 {
     CONTRACTL
@@ -2286,16 +2284,13 @@ MethodDesc* SystemDomain::GetCallersMethod(StackCrawlMark* stackMark,
     GetThread()->StackWalkFrames(CallersMethodCallbackWithStackMark, &cdata, FUNCTIONSONLY | LIGHTUNWIND);
 
     if(cdata.pFoundMethod) {
-        if (ppAppDomain)
-            *ppAppDomain = cdata.pAppDomain;
         return cdata.pFoundMethod;
     } else
         return NULL;
 }
 
 /*static*/
-MethodTable* SystemDomain::GetCallersType(StackCrawlMark* stackMark,
-                                          AppDomain **ppAppDomain/*=NULL*/)
+MethodTable* SystemDomain::GetCallersType(StackCrawlMark* stackMark)
 
 {
     CONTRACTL
@@ -2314,16 +2309,13 @@ MethodTable* SystemDomain::GetCallersType(StackCrawlMark* stackMark,
     GetThread()->StackWalkFrames(CallersMethodCallbackWithStackMark, &cdata, FUNCTIONSONLY | LIGHTUNWIND);
 
     if(cdata.pFoundMethod) {
-        if (ppAppDomain)
-            *ppAppDomain = cdata.pAppDomain;
         return cdata.pFoundMethod->GetMethodTable();
     } else
         return NULL;
 }
 
 /*static*/
-Module* SystemDomain::GetCallersModule(StackCrawlMark* stackMark,
-                                       AppDomain **ppAppDomain/*=NULL*/)
+Module* SystemDomain::GetCallersModule(StackCrawlMark* stackMark)
 
 {
     CONTRACTL
@@ -2344,8 +2336,6 @@ Module* SystemDomain::GetCallersModule(StackCrawlMark* stackMark,
     GetThread()->StackWalkFrames(CallersMethodCallbackWithStackMark, &cdata, FUNCTIONSONLY | LIGHTUNWIND);
 
     if(cdata.pFoundMethod) {
-        if (ppAppDomain)
-            *ppAppDomain = cdata.pAppDomain;
         return cdata.pFoundMethod->GetModule();
     } else
         return NULL;
@@ -2358,11 +2348,10 @@ struct CallersData
 };
 
 /*static*/
-Assembly* SystemDomain::GetCallersAssembly(StackCrawlMark *stackMark,
-                                           AppDomain **ppAppDomain/*=NULL*/)
+Assembly* SystemDomain::GetCallersAssembly(StackCrawlMark *stackMark)
 {
     WRAPPER_NO_CONTRACT;
-    Module* mod = GetCallersModule(stackMark, ppAppDomain);
+    Module* mod = GetCallersModule(stackMark);
     if (mod)
         return mod->GetAssembly();
     return NULL;
@@ -2393,7 +2382,6 @@ StackWalkAction SystemDomain::CallersMethodCallbackWithStackMark(CrawlFrame* pCf
         {
             // save the current in case it is the one we want
             pCaller->pPrevMethod = pFunc;
-            pCaller->pAppDomain = pCf->GetAppDomain();
             return SWA_CONTINUE;
         }
 
@@ -2457,7 +2445,6 @@ StackWalkAction SystemDomain::CallersMethodCallbackWithStackMark(CrawlFrame* pCf
     if (!pCaller->stackMark)
     {
         pCaller->pFoundMethod = pFunc;
-        pCaller->pAppDomain = pCf->GetAppDomain();
         return SWA_ABORT;
     }
 
@@ -2478,23 +2465,7 @@ StackWalkAction SystemDomain::CallersMethodCallbackWithStackMark(CrawlFrame* pCf
         return SWA_CONTINUE;
     }
 
-    // If remoting is not available, we only set the caller if the crawlframe is from the same domain.
-    // Why? Because if the callerdomain is different from current domain,
-    // there have to be interop/native frames in between.
-    // For example, in the CORECLR, if we find the caller to be in a different domain, then the
-    // call into reflection is due to an unmanaged call into mscorlib. For that
-    // case, the caller really is an INTEROP method.
-    // In general, if the caller is INTEROP, we set the caller/callerdomain to be NULL
-    // (To be precise: they are already NULL and we don't change them).
-    if (pCf->GetAppDomain() == GetAppDomain())
-    // We must either be looking for the caller, or the caller's caller when
-    // we've already found the caller (we used a non-null value in pFoundMethod
-    // simply as a flag, the correct method to return in both case is the
-    // current method).
-    {
-        pCaller->pFoundMethod = pFunc;
-        pCaller->pAppDomain = pCf->GetAppDomain();
-    }
+    pCaller->pFoundMethod = pFunc;
 
     return SWA_ABORT;
 }
index 7aa7e5b..8dd4741 100644 (file)
@@ -2881,10 +2881,10 @@ public:
     //****************************************************************************************
     // Methods used to get the callers module and hence assembly and app domain.
 
-    static MethodDesc* GetCallersMethod(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL);
-    static MethodTable* GetCallersType(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL);
-    static Module* GetCallersModule(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL);
-    static Assembly* GetCallersAssembly(StackCrawlMark* stackMark, AppDomain **ppAppDomain = NULL);
+    static MethodDesc* GetCallersMethod(StackCrawlMark* stackMark);
+    static MethodTable* GetCallersType(StackCrawlMark* stackMark);
+    static Module* GetCallersModule(StackCrawlMark* stackMark);
+    static Assembly* GetCallersAssembly(StackCrawlMark* stackMark);
 
     static bool IsReflectionInvocationMethod(MethodDesc* pMeth);
 
index 4f4553b..7f9c7f7 100644 (file)
@@ -421,8 +421,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs
 
     Assembly *pRetVal = NULL;
 
-    AppDomain  *pCallersDomain;
-    MethodDesc *pmdEmitter = SystemDomain::GetCallersMethod(args->stackMark, &pCallersDomain);
+    MethodDesc *pmdEmitter = SystemDomain::GetCallersMethod(args->stackMark);
 
     // Called either from interop or async delegate invocation. Rejecting because we don't
     // know how to set the correct permission on the new dynamic assembly.
index 7030d9d..697fc48 100644 (file)
@@ -304,7 +304,7 @@ PCODE COMDelegate::GetWrapperInvoke(MethodDesc* pMD)
     return (PCODE)(0x12345);
 }
 
-Assembly * SystemDomain::GetCallersAssembly(StackCrawlMark * stackMark, AppDomain ** ppAppDomain)
+Assembly * SystemDomain::GetCallersAssembly(StackCrawlMark * stackMark)
 {
     return NULL;
 }
index 328e23e..db97baa 100644 (file)
@@ -976,11 +976,6 @@ StackWalkAction DebugStackTrace::GetStackFramesCallback(CrawlFrame* pCf, VOID* d
 
     GetStackFramesData* pData = (GetStackFramesData*)data;
 
-    if (pData->pDomain != pCf->GetAppDomain())
-    {
-        return SWA_CONTINUE;
-    }
-
     if (pData->skip > 0)
     {
         pData->skip--;
index afa3714..885c69b 100644 (file)
@@ -792,7 +792,7 @@ void PrintException(OBJECTREF pObjectRef)
 /*******************************************************************/
 /* sends a current stack trace to the debug window */
 
-const char* FormatSig(MethodDesc* pMD, AppDomain *pDomain, AllocMemTracker *pamTracker);
+const char* FormatSig(MethodDesc* pMD, AllocMemTracker *pamTracker);
 
 struct PrintCallbackData {
     BOOL toStdout;
@@ -845,7 +845,7 @@ StackWalkAction PrintStackTraceCallback(CrawlFrame* pCF, VOID* pData)
                       _TRUNCATE,
                       W("%S %S  "),
                       pMD->GetName(),
-                      FormatSig(pMD, pCF->GetAppDomain(), &dummyAmTracker));
+                      FormatSig(pMD, &dummyAmTracker));
 
         dummyAmTracker.SuppressRelease();
         if (buffLen < 0 )
index 3ba69a5..590d46e 100644 (file)
@@ -488,12 +488,6 @@ public:
         return (ptr != NULL) ? *PTR_PCODE(ptr) : NULL;
     }
 
-    AppDomain *GetReturnDomain()
-    {
-        LIMITED_METHOD_CONTRACT;
-        return NULL;
-    }
-
 #ifndef DACCESS_COMPILE
     virtual Object **GetReturnExecutionContextAddr()
     {
index 7e2c0b9..cc00039 100644 (file)
@@ -637,7 +637,7 @@ const char* FormatSig(MethodDesc * pMD, LoaderHeap * pHeap, AllocMemTracker * pa
 }
 
 /*******************************************************************/
-const char* FormatSig(MethodDesc* pMD, AppDomain *pDomain, AllocMemTracker *pamTracker)
+const char* FormatSig(MethodDesc* pMD, AllocMemTracker *pamTracker)
 {
     CONTRACTL
     {
@@ -646,7 +646,7 @@ const char* FormatSig(MethodDesc* pMD, AppDomain *pDomain, AllocMemTracker *pamT
     }
     CONTRACTL_END;
 
-    return FormatSig(pMD,pDomain->GetLowFrequencyHeap(),pamTracker);
+    return FormatSig(pMD,GetAppDomain()->GetLowFrequencyHeap(),pamTracker);
 }
 #endif
 #endif
index 1cc74c3..0251b05 100644 (file)
@@ -376,9 +376,6 @@ inline void CrawlFrame::GotoNextFrame()
     // Update app domain if this frame caused a transition
     //
 
-    AppDomain *pRetDomain = pFrame->GetReturnDomain();
-    if (pRetDomain != NULL)
-        pAppDomain = pRetDomain;
     pFrame = pFrame->Next();
 
     if (pFrame != FRAME_TOP)
@@ -1248,7 +1245,6 @@ BOOL StackFrameIterator::Init(Thread *    pThread,
     }
 
     m_crawl.pRD = pRegDisp;
-    m_crawl.pAppDomain = pThread->GetDomain(INDEBUG(flags & PROFILER_DO_STACK_SNAPSHOT));
 
     m_codeManFlags = (ICodeManagerFlags)((flags & QUICKUNWIND) ? 0 : UpdateAllRegs);
     m_scanFlag = ExecutionManager::GetScanFlags();
@@ -1342,9 +1338,6 @@ BOOL StackFrameIterator::ResetRegDisp(PREGDISPLAY pRegDisp,
 
     m_crawl.pRD = pRegDisp;
 
-    // we initialize the appdomain to be the current domain, but this nees to be updated below
-    m_crawl.pAppDomain = m_crawl.pThread->GetDomain(INDEBUG(m_flags & PROFILER_DO_STACK_SNAPSHOT));
-
     m_codeManFlags = (ICodeManagerFlags)((m_flags & QUICKUNWIND) ? 0 : UpdateAllRegs);
 
     // make sure the REGDISPLAY is synchronized with the CONTEXT
@@ -2635,16 +2628,6 @@ StackWalkAction StackFrameIterator::NextRaw(void)
             _ASSERTE(!m_crawl.hasFaulted || !m_crawl.isIPadjusted); // both cant be set together
         }
 
-        //
-        // Update app domain if this frame caused a transition.
-        //
-
-        AppDomain *retDomain = m_crawl.pFrame->GetReturnDomain();
-        if (retDomain != NULL)
-        {
-            m_crawl.pAppDomain = retDomain;
-        }
-
         PCODE adr = m_crawl.pFrame->GetReturnAddress();
         _ASSERTE(adr != (PCODE)POISONC);
 
index 8f74db8..44752ba 100644 (file)
@@ -312,13 +312,6 @@ public:
         return flags;
     }
 
-    AppDomain *GetAppDomain()
-    {
-        LIMITED_METHOD_DAC_CONTRACT;
-
-        return pAppDomain;
-    }
-
     /* Is this frame at a safe spot for GC?
      */
     bool IsGcSafe();
@@ -410,6 +403,12 @@ public:
 
     void CheckGSCookies();
 
+    inline Thread* GetThread()
+    {
+        LIMITED_METHOD_CONTRACT;
+        return pThread;
+    }
+
 #if defined(FEATURE_EH_FUNCLETS)
     bool IsFunclet()
     {
@@ -488,7 +487,6 @@ private:
     MethodDesc       *pFunc;
 
     // the rest is only used for "frameless methods"
-    AppDomain        *pAppDomain;
     PREGDISPLAY       pRD; // "thread context"/"virtual register set"
 
     EECodeInfo        codeInfo;
index cd8cb13..da222bc 100644 (file)
@@ -8459,6 +8459,11 @@ Thread::EnumMemoryRegionsWorker(CLRDataEnumMemoryFlags flags)
         DacGetThreadContext(this, &context);
     }
 
+    if (flags != CLRDATA_ENUM_MEM_MINI && flags != CLRDATA_ENUM_MEM_TRIAGE)
+    {
+        AppDomain::GetCurrentDomain()->EnumMemoryRegions(flags, true);
+    }
+
     FillRegDisplay(&regDisp, &context);
     frameIter.Init(this, NULL, &regDisp, 0);
     while (frameIter.IsValid())
@@ -8517,14 +8522,6 @@ Thread::EnumMemoryRegionsWorker(CLRDataEnumMemoryFlags flags)
         PCODE callEnd = GetControlPC(&regDisp);
         DacEnumCodeForStackwalk(callEnd);
 
-        if (flags != CLRDATA_ENUM_MEM_MINI && flags != CLRDATA_ENUM_MEM_TRIAGE)
-        {
-            if (frameIter.m_crawl.GetAppDomain())
-            {
-                frameIter.m_crawl.GetAppDomain()->EnumMemoryRegions(flags, true);
-            }
-        }
-
         // To stackwalk through funceval frames, we need to be sure to preserve the
         // DebuggerModule's m_pRuntimeDomainFile.  This is the only case that doesn't use the current
         // vmDomainFile in code:DacDbiInterfaceImpl::EnumerateInternalFrames.  The following