From e42429ef1d08b21878b9127e60bb6cfe89089845 Mon Sep 17 00:00:00 2001 From: mikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com> Date: Mon, 31 Jul 2023 13:41:10 -0700 Subject: [PATCH] Gather optimization info through the DAC (#89534) * Going through the DAC to get optimizations * replying to code review suggestions * removing lock from DAC * add asserts to GetILToNativeMapping * remove DB_IPCE_IS_OPTS_DISABLED --- src/coreclr/debug/daccess/dacdbiimpl.cpp | 21 ++++++++++++++ src/coreclr/debug/daccess/dacdbiimpl.h | 1 + src/coreclr/debug/di/rsfunction.cpp | 27 ++++-------------- src/coreclr/debug/ee/debugger.cpp | 28 ------------------- src/coreclr/debug/inc/dacdbiinterface.h | 20 ++++++++++++- src/coreclr/debug/inc/dbgipcevents.h | 5 ---- src/coreclr/debug/inc/dbgipceventtypes.h | 2 -- .../debug/shared/dbgtransportsession.cpp | 7 ----- 8 files changed, 47 insertions(+), 64 deletions(-) diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index 5be32be906bf1a..06ab494079446f 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -7407,6 +7407,27 @@ HRESULT DacDbiInterfaceImpl::GetReJitInfo(VMPTR_MethodDesc vmMethod, CORDB_ADDRE return S_OK; } +HRESULT DacDbiInterfaceImpl::AreOptimizationsDisabled(VMPTR_Module vmModule, mdMethodDef methodTk, OUT BOOL* pOptimizationsDisabled) +{ + DD_ENTER_MAY_THROW; +#ifdef FEATURE_REJIT + PTR_Module pModule = vmModule.GetDacPtr(); + if (pModule == NULL || pOptimizationsDisabled == NULL || TypeFromToken(methodTk) != mdtMethodDef) + { + return E_INVALIDARG; + } + { + CodeVersionManager * pCodeVersionManager = pModule->GetCodeVersionManager(); + ILCodeVersion activeILVersion = pCodeVersionManager->GetActiveILCodeVersion(pModule, methodTk); + *pOptimizationsDisabled = activeILVersion.IsDeoptimized(); + } +#else + pOptimizationsDisabled->SetDacTargetPtr(0); +#endif + + return S_OK; +} + HRESULT DacDbiInterfaceImpl::GetNativeCodeVersionNode(VMPTR_MethodDesc vmMethod, CORDB_ADDRESS codeStartAddress, OUT VMPTR_NativeCodeVersionNode* pVmNativeCodeVersionNode) { DD_ENTER_MAY_THROW; diff --git a/src/coreclr/debug/daccess/dacdbiimpl.h b/src/coreclr/debug/daccess/dacdbiimpl.h index 1562ec204d4cf5..a4ef89438ad066 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.h +++ b/src/coreclr/debug/daccess/dacdbiimpl.h @@ -153,6 +153,7 @@ class DacDbiInterfaceImpl : HRESULT GetReJitInfo(VMPTR_Module vmModule, mdMethodDef methodTk, OUT VMPTR_ReJitInfo* pReJitInfo); HRESULT GetActiveRejitILCodeVersionNode(VMPTR_Module vmModule, mdMethodDef methodTk, OUT VMPTR_ILCodeVersionNode* pVmILCodeVersionNode); HRESULT GetReJitInfo(VMPTR_MethodDesc vmMethod, CORDB_ADDRESS codeStartAddress, OUT VMPTR_ReJitInfo* pReJitInfo); + HRESULT AreOptimizationsDisabled(VMPTR_Module vmModule, mdMethodDef methodTk, OUT BOOL* pOptimizationsDisabled); HRESULT GetNativeCodeVersionNode(VMPTR_MethodDesc vmMethod, CORDB_ADDRESS codeStartAddress, OUT VMPTR_NativeCodeVersionNode* pVmNativeCodeVersionNode); HRESULT GetSharedReJitInfo(VMPTR_ReJitInfo vmReJitInfo, VMPTR_SharedReJitInfo* pSharedReJitInfo); HRESULT GetILCodeVersionNode(VMPTR_NativeCodeVersionNode vmNativeCodeVersionNode, VMPTR_ILCodeVersionNode* pVmILCodeVersionNode); diff --git a/src/coreclr/debug/di/rsfunction.cpp b/src/coreclr/debug/di/rsfunction.cpp index 87a6594bff8423..a911dc6bbbeb8e 100644 --- a/src/coreclr/debug/di/rsfunction.cpp +++ b/src/coreclr/debug/di/rsfunction.cpp @@ -673,27 +673,12 @@ HRESULT CordbFunction::AreOptimizationsDisabled(BOOL *pOptimizationsDisabled) { return E_INVALIDARG; } - - CordbProcess * pProcess = GetProcess(); - RSLockHolder lockHolder(pProcess->GetProcessLock()); - - DebuggerIPCEvent event; - CordbAppDomain * pAppDomain = GetAppDomain(); - _ASSERTE (pAppDomain != NULL); - - pProcess->InitIPCEvent(&event, DB_IPCE_IS_OPTS_DISABLED, true, pAppDomain->GetADToken()); - event.DisableOptData.funcMetadataToken = m_MDToken; - event.DisableOptData.pModule = m_pModule->GetRuntimeModule(); - - lockHolder.Release(); - hr = pProcess->m_cordb->SendIPCEvent(pProcess, &event, sizeof(DebuggerIPCEvent)); - lockHolder.Acquire(); - - _ASSERTE(event.type == DB_IPCE_IS_OPTS_DISABLED_RESULT); - - *pOptimizationsDisabled = event.IsOptsDisabledData.value; - - return event.hr;; + EX_TRY + { + hr = GetProcess()->GetDAC()->AreOptimizationsDisabled(GetModule()->GetRuntimeModule(), GetMetadataToken(), pOptimizationsDisabled); + } + EX_CATCH_HRESULT(hr); + return hr; } // determine whether we have a native-only implementation diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index d0610e1ac91bf5..073d758c81b87c 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -10468,34 +10468,6 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent) } break; - case DB_IPCE_IS_OPTS_DISABLED: - { - Module *pModule = pEvent->DisableOptData.pModule.GetRawPtr(); - mdToken methodDef = pEvent->DisableOptData.funcMetadataToken; - _ASSERTE(TypeFromToken(methodDef) == mdtMethodDef); - - HRESULT hr = E_INVALIDARG; - BOOL deoptimized = FALSE; - EX_TRY - { - hr = IsMethodDeoptimized(pModule, methodDef, &deoptimized); - } - EX_CATCH_HRESULT(hr); - - DebuggerIPCEvent * pIPCResult = m_pRCThread->GetIPCEventReceiveBuffer(); - - InitIPCEvent(pIPCResult, - DB_IPCE_IS_OPTS_DISABLED_RESULT, - g_pEEInterface->GetThread(), - pEvent->vmAppDomain); - - pIPCResult->IsOptsDisabledData.value = deoptimized; - pIPCResult->hr = hr; - - m_pRCThread->SendIPCReply(); - } - break; - case DB_IPCE_BREAKPOINT_ADD: { diff --git a/src/coreclr/debug/inc/dacdbiinterface.h b/src/coreclr/debug/inc/dacdbiinterface.h index ca36f58ff64392..3652d15ef53915 100644 --- a/src/coreclr/debug/inc/dacdbiinterface.h +++ b/src/coreclr/debug/inc/dacdbiinterface.h @@ -2590,7 +2590,25 @@ class IDacDbiInterface // virtual HRESULT GetSharedReJitInfoData(VMPTR_SharedReJitInfo sharedReJitInfo, DacSharedReJitInfo* pData) = 0; - + + // Retrieves a bool indicating whether or not a method's optimizations have been disabled + // defined in Debugger::IsMethodDeoptimized + // + // + // + // Arguments: + // vmModule - The module for the method in question + // methodTk - The method token for the method in question + // pOptimizationsDisabled - [out] A bool indicating whether or not the optimizations on a function are disabled + // + // + // Returns: + // S_OK if no error + // error HRESULTs are possible + // + virtual + HRESULT AreOptimizationsDisabled(VMPTR_Module vmModule, mdMethodDef methodTk, OUT BOOL* pOptimizationsDisabled) = 0; + // Retrieves a bit field indicating which defines were in use when clr was built. This only includes // defines that are specified in the Debugger::_Target_Defines enumeration, which is a small subset of // all defines. diff --git a/src/coreclr/debug/inc/dbgipcevents.h b/src/coreclr/debug/inc/dbgipcevents.h index 4c56df797ab98c..9fe1afd31a54ba 100644 --- a/src/coreclr/debug/inc/dbgipcevents.h +++ b/src/coreclr/debug/inc/dbgipcevents.h @@ -2019,11 +2019,6 @@ struct MSLAYOUT DebuggerIPCEvent VMPTR_Module pModule; } DisableOptData; - struct MSLAYOUT - { - BOOL value; - } IsOptsDisabledData; - struct MSLAYOUT { LSPTR_BREAKPOINT breakpointToken; diff --git a/src/coreclr/debug/inc/dbgipceventtypes.h b/src/coreclr/debug/inc/dbgipceventtypes.h index 9e99e16d44b272..9c3a09afcf9b41 100644 --- a/src/coreclr/debug/inc/dbgipceventtypes.h +++ b/src/coreclr/debug/inc/dbgipceventtypes.h @@ -93,7 +93,6 @@ IPC_EVENT_TYPE1(DB_IPCE_DATA_BREAKPOINT ,0x0160) IPC_EVENT_TYPE1(DB_IPCE_BEFORE_GARBAGE_COLLECTION ,0x0161) IPC_EVENT_TYPE1(DB_IPCE_AFTER_GARBAGE_COLLECTION ,0x0162) IPC_EVENT_TYPE1(DB_IPCE_DISABLE_OPTS_RESULT ,0x0163) -IPC_EVENT_TYPE1(DB_IPCE_IS_OPTS_DISABLED_RESULT ,0x0164) IPC_EVENT_TYPE0(DB_IPCE_RUNTIME_LAST ,0x0165) // The last event from runtime @@ -144,6 +143,5 @@ IPC_EVENT_TYPE2(DB_IPCE_GET_GCHANDLE_INFO ,0x0251) IPC_EVENT_TYPE2(DB_IPCE_RESOLVE_UPDATE_METADATA_1 ,0x0256) IPC_EVENT_TYPE2(DB_IPCE_RESOLVE_UPDATE_METADATA_2 ,0x0257) IPC_EVENT_TYPE2(DB_IPCE_DISABLE_OPTS ,0x0258) -IPC_EVENT_TYPE2(DB_IPCE_IS_OPTS_DISABLED ,0x0259) IPC_EVENT_TYPE0(DB_IPCE_DEBUGGER_LAST ,0x025A) // The last event from the debugger diff --git a/src/coreclr/debug/shared/dbgtransportsession.cpp b/src/coreclr/debug/shared/dbgtransportsession.cpp index 8c1ee39f99d0d6..fa8b06618362d9 100644 --- a/src/coreclr/debug/shared/dbgtransportsession.cpp +++ b/src/coreclr/debug/shared/dbgtransportsession.cpp @@ -2499,13 +2499,6 @@ DWORD DbgTransportSession::GetEventSize(DebuggerIPCEvent *pEvent) break; case DB_IPCE_DISABLE_OPTS: - case DB_IPCE_IS_OPTS_DISABLED: - cbAdditionalSize = sizeof(pEvent->DisableOptData); - break; - - case DB_IPCE_IS_OPTS_DISABLED_RESULT: - cbAdditionalSize = sizeof(pEvent->IsOptsDisabledData); - break; default: printf("Unknown debugger event type: 0x%x\n", (pEvent->type & DB_IPCE_TYPE_MASK));