From 067fb998b2928fcb8a59faa2e7687d8e59daac11 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 13 Aug 2025 13:15:05 -0700 Subject: [PATCH 1/4] Fix the debugger data to be more reasonable for the interpreter --- src/coreclr/debug/daccess/daccess.cpp | 9 +++++---- src/coreclr/debug/daccess/dacdbiimpl.cpp | 5 +++-- src/coreclr/debug/daccess/enummem.cpp | 2 +- src/coreclr/debug/daccess/request.cpp | 2 +- src/coreclr/debug/daccess/task.cpp | 5 +++-- src/coreclr/vm/codeversion.cpp | 6 +++--- src/coreclr/vm/dllimport.cpp | 4 ++-- src/coreclr/vm/eedbginterfaceimpl.cpp | 4 ++-- src/coreclr/vm/encee.cpp | 2 +- src/coreclr/vm/eventtrace.cpp | 20 +++----------------- src/coreclr/vm/exceptionhandling.cpp | 4 ++-- src/coreclr/vm/jitinterface.cpp | 17 +++++++++++++++++ src/coreclr/vm/method.cpp | 22 +++++++++++++++++----- src/coreclr/vm/method.hpp | 6 +++--- src/coreclr/vm/multicorejitplayer.cpp | 2 +- src/coreclr/vm/prestub.cpp | 6 +++--- src/coreclr/vm/proftoeeinterfaceimpl.cpp | 4 ++-- src/coreclr/vm/tieredcompilation.cpp | 2 +- 18 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 1282ed4e1ea4a0..3f72c192ac2a0a 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -5090,7 +5090,7 @@ ClrDataAccess::FollowStubStep( methodDesc = PTR_MethodDesc(CORDB_ADDRESS_TO_TADDR(inBuffer->u.addr)); if (methodDesc->HasNativeCode()) { - *outAddr = methodDesc->GetNativeCode(); + *outAddr = methodDesc->GetNativeCode_CurrentDefault(); *outFlags = CLRDATA_FOLLOW_STUB_EXIT; return S_OK; } @@ -5923,7 +5923,7 @@ ClrDataAccess::GetMethodExtents(MethodDesc* methodDesc, // for all types of managed code. // - PCODE methodStart = methodDesc->GetNativeCode(); + PCODE methodStart = methodDesc->GetNativeCode_CurrentDefault(); if (!methodStart) { return E_NOINTERFACE; @@ -5981,7 +5981,8 @@ ClrDataAccess::GetMethodVarInfo(MethodDesc* methodDesc, } else { - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); + // This should get the native code here, then get the NativeCodeVersion, then from that call GetExecutableCode ... which should return either the jitted code or the interpreted code. + nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode_CurrentDefault()); } DebugInfoRequest request; @@ -6040,7 +6041,7 @@ ClrDataAccess::GetMethodNativeMap(MethodDesc* methodDesc, } else { - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); + nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode_CurrentDefault()); } DebugInfoRequest request; diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index 0fa75ad43cf054..a72e2c88a7a293 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -1127,7 +1127,7 @@ void DacDbiInterfaceImpl::GetMethodRegionInfo(MethodDesc * pMethodDe CONTRACTL_END; IJitManager::MethodRegionInfo methodRegionInfo = {(TADDR)NULL, 0, (TADDR)NULL, 0}; - PCODE functionAddress = pMethodDesc->GetNativeCode(); + PCODE functionAddress = pMethodDesc->GetNativeCode_CurrentDefault(); // get the start address of the hot region and initialize the jit manager pCodeInfo->m_rgCodeRegions[kHot].pAddress = CORDB_ADDRESS(PCODEToPINSTR(functionAddress)); @@ -1141,7 +1141,8 @@ void DacDbiInterfaceImpl::GetMethodRegionInfo(MethodDesc * pMethodDe codeInfo.GetMethodRegionInfo(&methodRegionInfo); // now get the rest of the region information - pCodeInfo->m_rgCodeRegions[kHot].cbSize = (ULONG)methodRegionInfo.hotSize; + pCodeInfo->m_rgCodeRegions[kHot].Init(PCODEToPINSTR(methodRegionInfo.hotStartAddress), + (ULONG)methodRegionInfo.hotSize); pCodeInfo->m_rgCodeRegions[kCold].Init(PCODEToPINSTR(methodRegionInfo.coldStartAddress), (ULONG)methodRegionInfo.coldSize); _ASSERTE(pCodeInfo->IsValid()); diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index 828ae77d6aae16..dba13a3305484c 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -594,7 +594,7 @@ HRESULT ClrDataAccess::DumpManagedExcepObject(CLRDataEnumMemoryFlags flags, OBJE // Pulls in data to translate from token to MethodDesc FindLoadedMethodRefOrDef(pMD->GetMethodTable()->GetModule(), pMD->GetMemberDef()); - PCODE addr = pMD->GetNativeCode(); + PCODE addr = pMD->GetNativeCode_CurrentDefault(); if (addr != (PCODE)NULL) { EECodeInfo codeInfo(addr); diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 9f567d48809b39..20a1204a161e89 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -229,7 +229,7 @@ BOOL DacValidateMD(PTR_MethodDesc pMD) if (retval && pMD->HasNativeCode() && !pMD->IsFCall()) { - PCODE jitCodeAddr = pMD->GetNativeCode(); + PCODE jitCodeAddr = pMD->GetNativeCode_CurrentDefault(); MethodDesc *pMDCheck = ExecutionManager::GetCodeMethodDesc(jitCodeAddr); if (pMDCheck) diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index edbb360a988c36..506e83db842ed6 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -4341,9 +4341,10 @@ ClrDataMethodInstance::GetRepresentativeEntryAddress( EX_TRY { - if (m_methodDesc->HasNativeCode()) + PCODE codeAddr = m_methodDesc->GetNativeCode_CurrentDefault(); + if (codeAddr != NULL) { - *addr = TO_CDADDR(m_methodDesc->GetNativeCode()); + *addr = TO_CDADDR(codeAddr); status = S_OK; } else diff --git a/src/coreclr/vm/codeversion.cpp b/src/coreclr/vm/codeversion.cpp index 9a2af2a97f79d0..7082bc16935c45 100644 --- a/src/coreclr/vm/codeversion.cpp +++ b/src/coreclr/vm/codeversion.cpp @@ -219,7 +219,7 @@ PCODE NativeCodeVersion::GetNativeCode() const } else { - return GetMethodDesc()->GetNativeCode(); + return GetMethodDesc()->GetNativeCode_CurrentDefault(); } } @@ -299,7 +299,7 @@ void NativeCodeVersion::SetActiveChildFlag(BOOL isActive) { if (isActive && !CodeVersionManager::InitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion() && - GetMethodDesc()->GetNativeCode() == (PCODE)NULL) + GetMethodDesc()->GetNativeCode_CurrentDefault() == (PCODE)NULL) { CodeVersionManager::SetInitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion(); } @@ -1695,7 +1695,7 @@ PCODE CodeVersionManager::PublishVersionableCodeIfNecessary( // native code version when the method's default native code version does not have native code, the global flag on // CodeVersionManager is set (not a typical case, may be possible with profilers). So, if the flag is not set and the // default native code version does not have native code, then it must be the active code version. - pCode = pMethodDesc->GetNativeCode(); + pCode = pMethodDesc->GetNativeCode_CurrentDefault(); if (pCode == (PCODE)NULL && !CodeVersionManager::InitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion()) { activeVersion = NativeCodeVersion(pMethodDesc); diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index e6171f60ebebe2..26c6e3907c39b1 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -5625,7 +5625,7 @@ PCODE JitILStub(MethodDesc* pStubMD) { STANDARD_VM_CONTRACT; - PCODE pCode = pStubMD->GetNativeCode(); + PCODE pCode = pStubMD->GetNativeCode_CurrentDefault(); if (pCode == (PCODE)NULL) { @@ -5644,7 +5644,7 @@ PCODE JitILStub(MethodDesc* pStubMD) pCode = pStubMD->PrepareInitialCode(); - _ASSERTE(pCode == pStubMD->GetNativeCode()); + _ASSERTE(pCode == pStubMD->GetNativeCode_CurrentDefault()); } else { diff --git a/src/coreclr/vm/eedbginterfaceimpl.cpp b/src/coreclr/vm/eedbginterfaceimpl.cpp index f810dbdab7960e..ef202f25118d85 100644 --- a/src/coreclr/vm/eedbginterfaceimpl.cpp +++ b/src/coreclr/vm/eedbginterfaceimpl.cpp @@ -605,7 +605,7 @@ size_t EEDbgInterfaceImpl::GetFunctionSize(MethodDesc *pFD) } CONTRACTL_END; - PCODE methodStart = pFD->GetNativeCode(); + PCODE methodStart = pFD->GetNativeCode_CurrentDefault(); if (methodStart == (PCODE)NULL) return 0; @@ -626,7 +626,7 @@ PCODE EEDbgInterfaceImpl::GetFunctionAddress(MethodDesc *pFD) SUPPORTS_DAC; } CONTRACTL_END; - return pFD->GetNativeCode(); + return pFD->GetNativeCode_CurrentDefault(); } #ifndef DACCESS_COMPILE diff --git a/src/coreclr/vm/encee.cpp b/src/coreclr/vm/encee.cpp index 4959fde39cd43e..ed89d04e58941f 100644 --- a/src/coreclr/vm/encee.cpp +++ b/src/coreclr/vm/encee.cpp @@ -616,7 +616,7 @@ PCODE EditAndContinueModule::JitUpdatedFunction( MethodDesc *pMD, pMD->DoPrestub(NULL); LOG((LF_ENC, LL_INFO100, "EACM::ResumeInUpdatedFunction JIT of %p successful\n", pMD)); } - jittedCode = pMD->GetNativeCode(); + jittedCode = pMD->GetNativeCode_CurrentDefault(); } EX_CATCH { #ifdef _DEBUG { diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 2ab23dfad1bbbf..134828d6f53a0f 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -4409,26 +4409,12 @@ TADDR MethodAndStartAddressToEECodeInfoPointer(MethodDesc *pMethodDesc, PCODE pN } CONTRACTL_END; // MethodDesc ==> Code Address ==>JitManager - TADDR start = PCODEToPINSTR(pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode()); + TADDR start = PCODEToPINSTR(pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode_CurrentDefault()); if(start == 0) { // this method hasn't been jitted return 0; } -#ifdef FEATURE_INTERPRETER - RangeSection * pRS = ExecutionManager::FindCodeRange(PINSTRToPCODE(start), ExecutionManager::GetScanFlags()); - if (pRS != NULL && pRS->_flags & RangeSection::RANGE_SECTION_RANGELIST) - { - if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE) - { - if (((StubPrecode*)start)->GetType() == PRECODE_INTERPRETER) - { - start = ((InterpreterPrecode*)start)->GetData()->ByteCodeAddr; - } - } - } -#endif // FEATURE_INTERPRETER - return start; } @@ -5020,7 +5006,7 @@ VOID ETW::MethodLog::SendEventsForJitMethodsHelper(LoaderAllocator *pLoaderAlloc if (nativeCodeVersion.IsNull()) { // The code version manager hasn't been updated with the jitted code - if (codeStart != pMD->GetNativeCode()) + if (codeStart != pMD->GetNativeCode_CurrentDefault()) { continue; } @@ -5033,7 +5019,7 @@ VOID ETW::MethodLog::SendEventsForJitMethodsHelper(LoaderAllocator *pLoaderAlloc } else #endif // FEATURE_CODE_VERSIONING - if (codeStart != pMD->GetNativeCode()) + if (codeStart != pMD->GetNativeCode_CurrentDefault()) { continue; } diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 818f5dbef72639..58d8fec24fa2bd 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -3210,7 +3210,7 @@ extern "C" void * QCALLTYPE CallCatchFunclet(QCall::ObjectHandleOnStack exceptio pThread->GetExceptionState()->GetDebuggerState()->GetDebuggerInterceptInfo(&pInterceptMD, NULL, (PBYTE*)&(sfInterceptStackFrame.SP), &ulRelOffset, NULL); if (sfInterceptStackFrame.SP == GetSP(pvRegDisplay->pCurrentContext)) { - PCODE pStartAddress = pInterceptMD->GetNativeCode(); + PCODE pStartAddress = pInterceptMD->GetNativeCode_CurrentDefault(); EECodeInfo codeInfo(pStartAddress); _ASSERTE(codeInfo.IsValid()); @@ -3347,7 +3347,7 @@ extern "C" void QCALLTYPE ResumeAtInterceptionLocation(REGDISPLAY* pvRegDisplay) ExInfo::PopExInfos(pThread, (void*)targetSp); - PCODE pStartAddress = pInterceptMD->GetNativeCode(); + PCODE pStartAddress = pInterceptMD->GetNativeCode_CurrentDefault(); EECodeInfo codeInfo(pStartAddress); _ASSERTE(codeInfo.IsValid()); diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 03a3fa0662fc7c..299d1273742fa8 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -15019,6 +15019,23 @@ void EECodeInfo::Init(PCODE codeAddress, ExecutionManager::ScanFlag scanFlag) if (pRS == NULL) goto Invalid; +#ifdef FEATURE_INTERPRETER + if (pRS != NULL && pRS->_flags & RangeSection::RANGE_SECTION_RANGELIST) + { + if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE) + { + PTR_StubPrecode pStubPrecode = dac_cast(PCODEToPINSTR(codeAddress)); + if (pStubPrecode->GetType() == PRECODE_INTERPRETER) + { + codeAddress = dac_cast(pStubPrecode)->GetData()->ByteCodeAddr; + pRS = ExecutionManager::FindCodeRange(codeAddress, scanFlag); + if (pRS == NULL) + goto Invalid; + } + } + } +#endif // FEATURE_INTERPRETER + if (!pRS->_pjit->JitCodeToMethodInfo(pRS, codeAddress, &m_pMD, this)) goto Invalid; diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 349a05ec3c5396..1d3558ff68f25f 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -1021,7 +1021,7 @@ WORD MethodDescChunk::InterlockedUpdateFlags(WORD wMask, BOOL fSet) // implemented by stubs. On WIN64, these stubs are IL stubs, which DO have native code. // // This function returns null if the method has no native code. -PCODE MethodDesc::GetNativeCode() +PCODE MethodDesc::GetNativeCode_CurrentDefault() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; @@ -1052,7 +1052,7 @@ PCODE MethodDesc::GetNativeCodeAnyVersion() WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - PCODE pDefaultCode = GetNativeCode(); + PCODE pDefaultCode = GetNativeCode_CurrentDefault(); if (pDefaultCode != (PCODE)NULL) { return pDefaultCode; @@ -2130,7 +2130,7 @@ PCODE MethodDesc::TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags else { if (IsPointingToStableNativeCode()) - return GetNativeCode(); + return GetNativeCode_CurrentDefault(); } if (HasStableEntryPoint()) @@ -2207,7 +2207,8 @@ MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint) } CONTRACTL_END - RangeSection* pRS = ExecutionManager::FindCodeRange(entryPoint, ExecutionManager::GetScanFlags()); + ExecutionManager::ScanFlag scanFlag = ExecutionManager::GetScanFlags(); + RangeSection* pRS = ExecutionManager::FindCodeRange(entryPoint, scanFlag); if (pRS == NULL) { return NULL; @@ -2222,7 +2223,18 @@ MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint) } if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE) { - return (MethodDesc*)((StubPrecode*)PCODEToPINSTR(entryPoint))->GetMethodDesc(); + StubPrecode stubPrecode = (StubPrecode*)PCODEToPINSTR(entryPoint); +#ifdef FEATURE_INTERPRETER + if (stubPrecode->GetType() == PRECODE_INTERPRETER)) + { + entryPoint = dac_cast(pStubPrecode)->GetData()->ByteCodeAddr; + pRS = ExecutionManager::FindCodeRange(entryPoint, scanFlag); + } + else +#endif // FEATURE_INTERPRETER + { + return (MethodDesc*)(stubPrecode)->GetMethodDesc(); + } } } diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index 1438276e35b42c..50b6eaee6b6492 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -1468,7 +1468,7 @@ class MethodDesc if (!HasPrecode()) return TRUE; - return GetPrecode()->IsPointingToNativeCode(GetNativeCode()); + return GetPrecode()->IsPointingToNativeCode(GetNativeCode_CurrentDefault()); } // Be careful about races with profiler when using this method. The profiler can @@ -1479,7 +1479,7 @@ class MethodDesc { LIMITED_METHOD_DAC_CONTRACT; - return GetNativeCode() != (PCODE)0; + return GetNativeCode_CurrentDefault() != (PCODE)0; } // Perf warning: takes the CodeVersionManagerLock on every call @@ -1579,7 +1579,7 @@ class MethodDesc //******************************************************************************* // Returns the address of the native code. - PCODE GetNativeCode(); + PCODE GetNativeCode_CurrentDefault(); // Returns GetNativeCode() if it exists, but also checks to see if there // is a non-default code version that is populated with a code body and returns that. diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index 78d7a53bda3aa5..d315fee1f348ad 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -967,7 +967,7 @@ void MulticoreJitProfilePlayer::CompileMethodInfoRecord(Module *pModule, MethodD } } - if (pMethod->GetNativeCode() == (PCODE)NULL && !GetAppDomain()->GetMulticoreJitManager().GetMulticoreJitCodeStorage().LookupMethodCode(pMethod)) + if (!pMethod->HasNativeCode() && !GetAppDomain()->GetMulticoreJitManager().GetMulticoreJitCodeStorage().LookupMethodCode(pMethod)) { if (CompileMethodDesc(pModule, pMethod)) { diff --git a/src/coreclr/vm/prestub.cpp b/src/coreclr/vm/prestub.cpp index 3ea82cfe8ae4d2..2e7420deb3ca21 100644 --- a/src/coreclr/vm/prestub.cpp +++ b/src/coreclr/vm/prestub.cpp @@ -1090,7 +1090,7 @@ PrepareCodeConfig::PrepareCodeConfig(NativeCodeVersion codeVersion, BOOL needsMu PCODE PrepareCodeConfig::IsJitCancellationRequested() { LIMITED_METHOD_CONTRACT; - return m_pMethodDesc->GetNativeCode(); + return m_pMethodDesc->GetNativeCode_CurrentDefault(); } BOOL PrepareCodeConfig::NeedsMulticoreJitNotification() @@ -2302,7 +2302,7 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo } /************************** POSTJIT *************************/ - _ASSERTE(pCode == (PCODE)NULL || GetNativeCode() == (PCODE)NULL || pCode == GetNativeCode()); + _ASSERTE(pCode == (PCODE)NULL || GetNativeCode_CurrentDefault() == (PCODE)NULL || pCode == GetNativeCode_CurrentDefault()); // At this point we must have either a pointer to managed code or to a stub. All of the above code // should have thrown an exception if it couldn't make a stub. @@ -2432,7 +2432,7 @@ static PCODE PatchNonVirtualExternalMethod(MethodDesc * pMD, PCODE pCode, PTR_RE if (pMD->HasPrecode() && pMD->GetPrecode()->GetType() == PRECODE_FIXUP && pMD->IsNativeCodeStableAfterInit()) { - PCODE pDirectTarget = pMD->IsFCall() ? ECall::GetFCallImpl(pMD, false /* throwForInvalidFCall */) : pMD->GetNativeCode(); + PCODE pDirectTarget = pMD->IsFCall() ? ECall::GetFCallImpl(pMD, false /* throwForInvalidFCall */) : pMD->GetNativeCode_CurrentDefault(); if (pDirectTarget != (PCODE)NULL) pCode = pDirectTarget; } diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index effd3b73b37441..998e2684dcf391 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -2396,7 +2396,7 @@ HRESULT ProfToEEInterfaceImpl::GetCodeInfo(FunctionID functionId, LPCBYTE * pSta ULONG32 cCodeInfos; HRESULT hr = GetCodeInfoFromCodeStart( - pMethodDesc->GetNativeCode(), + pMethodDesc->GetNativeCode_CurrentDefault(), ARRAY_SIZE(codeInfos), &cCodeInfos, codeInfos); @@ -2472,7 +2472,7 @@ HRESULT ProfToEEInterfaceImpl::GetCodeInfo2(FunctionID functionId, if (SUCCEEDED(hr)) { hr = GetCodeInfoFromCodeStart( - pMethodDesc->GetNativeCode(), + pMethodDesc->GetNativeCode_CurrentDefault(), cCodeInfos, pcCodeInfos, codeInfos); diff --git a/src/coreclr/vm/tieredcompilation.cpp b/src/coreclr/vm/tieredcompilation.cpp index 8f1b36eeac43ec..87ac460c42b373 100644 --- a/src/coreclr/vm/tieredcompilation.cpp +++ b/src/coreclr/vm/tieredcompilation.cpp @@ -116,7 +116,7 @@ NativeCodeVersion::OptimizationTier TieredCompilationManager::GetInitialOptimiza // 1 - OptimizationTier0 as we don't want to instrument the initial version (will only instrument hot Tier0) // 2 - OptimizationTier0Instrumented - instrument all ILOnly code if (g_pConfig->TieredPGO_InstrumentOnlyHotCode() || - ExecutionManager::IsReadyToRunCode(pMethodDesc->GetNativeCode())) + ExecutionManager::IsReadyToRunCode(pMethodDesc->GetNativeCode_CurrentDefault())) { return NativeCodeVersion::OptimizationTier0; } From 9e0075f05d0b85298b0f963d0814af025f903e67 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 13 Aug 2025 13:15:37 -0700 Subject: [PATCH 2/4] Rename GetNativeCode_CurrentDefault back to GetNativeCode --- src/coreclr/debug/daccess/daccess.cpp | 8 ++++---- src/coreclr/debug/daccess/dacdbiimpl.cpp | 2 +- src/coreclr/debug/daccess/enummem.cpp | 2 +- src/coreclr/debug/daccess/request.cpp | 2 +- src/coreclr/debug/daccess/task.cpp | 2 +- src/coreclr/vm/codeversion.cpp | 6 +++--- src/coreclr/vm/dllimport.cpp | 4 ++-- src/coreclr/vm/eedbginterfaceimpl.cpp | 4 ++-- src/coreclr/vm/encee.cpp | 2 +- src/coreclr/vm/eventtrace.cpp | 6 +++--- src/coreclr/vm/exceptionhandling.cpp | 4 ++-- src/coreclr/vm/method.cpp | 6 +++--- src/coreclr/vm/method.hpp | 6 +++--- src/coreclr/vm/prestub.cpp | 6 +++--- src/coreclr/vm/proftoeeinterfaceimpl.cpp | 4 ++-- src/coreclr/vm/tieredcompilation.cpp | 2 +- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 3f72c192ac2a0a..fd5948fcec43a6 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -5090,7 +5090,7 @@ ClrDataAccess::FollowStubStep( methodDesc = PTR_MethodDesc(CORDB_ADDRESS_TO_TADDR(inBuffer->u.addr)); if (methodDesc->HasNativeCode()) { - *outAddr = methodDesc->GetNativeCode_CurrentDefault(); + *outAddr = methodDesc->GetNativeCode(); *outFlags = CLRDATA_FOLLOW_STUB_EXIT; return S_OK; } @@ -5923,7 +5923,7 @@ ClrDataAccess::GetMethodExtents(MethodDesc* methodDesc, // for all types of managed code. // - PCODE methodStart = methodDesc->GetNativeCode_CurrentDefault(); + PCODE methodStart = methodDesc->GetNativeCode(); if (!methodStart) { return E_NOINTERFACE; @@ -5982,7 +5982,7 @@ ClrDataAccess::GetMethodVarInfo(MethodDesc* methodDesc, else { // This should get the native code here, then get the NativeCodeVersion, then from that call GetExecutableCode ... which should return either the jitted code or the interpreted code. - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode_CurrentDefault()); + nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); } DebugInfoRequest request; @@ -6041,7 +6041,7 @@ ClrDataAccess::GetMethodNativeMap(MethodDesc* methodDesc, } else { - nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode_CurrentDefault()); + nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); } DebugInfoRequest request; diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index a72e2c88a7a293..ba645532c83a5d 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -1127,7 +1127,7 @@ void DacDbiInterfaceImpl::GetMethodRegionInfo(MethodDesc * pMethodDe CONTRACTL_END; IJitManager::MethodRegionInfo methodRegionInfo = {(TADDR)NULL, 0, (TADDR)NULL, 0}; - PCODE functionAddress = pMethodDesc->GetNativeCode_CurrentDefault(); + PCODE functionAddress = pMethodDesc->GetNativeCode(); // get the start address of the hot region and initialize the jit manager pCodeInfo->m_rgCodeRegions[kHot].pAddress = CORDB_ADDRESS(PCODEToPINSTR(functionAddress)); diff --git a/src/coreclr/debug/daccess/enummem.cpp b/src/coreclr/debug/daccess/enummem.cpp index dba13a3305484c..828ae77d6aae16 100644 --- a/src/coreclr/debug/daccess/enummem.cpp +++ b/src/coreclr/debug/daccess/enummem.cpp @@ -594,7 +594,7 @@ HRESULT ClrDataAccess::DumpManagedExcepObject(CLRDataEnumMemoryFlags flags, OBJE // Pulls in data to translate from token to MethodDesc FindLoadedMethodRefOrDef(pMD->GetMethodTable()->GetModule(), pMD->GetMemberDef()); - PCODE addr = pMD->GetNativeCode_CurrentDefault(); + PCODE addr = pMD->GetNativeCode(); if (addr != (PCODE)NULL) { EECodeInfo codeInfo(addr); diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 20a1204a161e89..9f567d48809b39 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -229,7 +229,7 @@ BOOL DacValidateMD(PTR_MethodDesc pMD) if (retval && pMD->HasNativeCode() && !pMD->IsFCall()) { - PCODE jitCodeAddr = pMD->GetNativeCode_CurrentDefault(); + PCODE jitCodeAddr = pMD->GetNativeCode(); MethodDesc *pMDCheck = ExecutionManager::GetCodeMethodDesc(jitCodeAddr); if (pMDCheck) diff --git a/src/coreclr/debug/daccess/task.cpp b/src/coreclr/debug/daccess/task.cpp index 506e83db842ed6..2dae6a9b2cf16c 100644 --- a/src/coreclr/debug/daccess/task.cpp +++ b/src/coreclr/debug/daccess/task.cpp @@ -4341,7 +4341,7 @@ ClrDataMethodInstance::GetRepresentativeEntryAddress( EX_TRY { - PCODE codeAddr = m_methodDesc->GetNativeCode_CurrentDefault(); + PCODE codeAddr = m_methodDesc->GetNativeCode(); if (codeAddr != NULL) { *addr = TO_CDADDR(codeAddr); diff --git a/src/coreclr/vm/codeversion.cpp b/src/coreclr/vm/codeversion.cpp index 7082bc16935c45..9a2af2a97f79d0 100644 --- a/src/coreclr/vm/codeversion.cpp +++ b/src/coreclr/vm/codeversion.cpp @@ -219,7 +219,7 @@ PCODE NativeCodeVersion::GetNativeCode() const } else { - return GetMethodDesc()->GetNativeCode_CurrentDefault(); + return GetMethodDesc()->GetNativeCode(); } } @@ -299,7 +299,7 @@ void NativeCodeVersion::SetActiveChildFlag(BOOL isActive) { if (isActive && !CodeVersionManager::InitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion() && - GetMethodDesc()->GetNativeCode_CurrentDefault() == (PCODE)NULL) + GetMethodDesc()->GetNativeCode() == (PCODE)NULL) { CodeVersionManager::SetInitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion(); } @@ -1695,7 +1695,7 @@ PCODE CodeVersionManager::PublishVersionableCodeIfNecessary( // native code version when the method's default native code version does not have native code, the global flag on // CodeVersionManager is set (not a typical case, may be possible with profilers). So, if the flag is not set and the // default native code version does not have native code, then it must be the active code version. - pCode = pMethodDesc->GetNativeCode_CurrentDefault(); + pCode = pMethodDesc->GetNativeCode(); if (pCode == (PCODE)NULL && !CodeVersionManager::InitialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion()) { activeVersion = NativeCodeVersion(pMethodDesc); diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index 26c6e3907c39b1..e6171f60ebebe2 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -5625,7 +5625,7 @@ PCODE JitILStub(MethodDesc* pStubMD) { STANDARD_VM_CONTRACT; - PCODE pCode = pStubMD->GetNativeCode_CurrentDefault(); + PCODE pCode = pStubMD->GetNativeCode(); if (pCode == (PCODE)NULL) { @@ -5644,7 +5644,7 @@ PCODE JitILStub(MethodDesc* pStubMD) pCode = pStubMD->PrepareInitialCode(); - _ASSERTE(pCode == pStubMD->GetNativeCode_CurrentDefault()); + _ASSERTE(pCode == pStubMD->GetNativeCode()); } else { diff --git a/src/coreclr/vm/eedbginterfaceimpl.cpp b/src/coreclr/vm/eedbginterfaceimpl.cpp index ef202f25118d85..f810dbdab7960e 100644 --- a/src/coreclr/vm/eedbginterfaceimpl.cpp +++ b/src/coreclr/vm/eedbginterfaceimpl.cpp @@ -605,7 +605,7 @@ size_t EEDbgInterfaceImpl::GetFunctionSize(MethodDesc *pFD) } CONTRACTL_END; - PCODE methodStart = pFD->GetNativeCode_CurrentDefault(); + PCODE methodStart = pFD->GetNativeCode(); if (methodStart == (PCODE)NULL) return 0; @@ -626,7 +626,7 @@ PCODE EEDbgInterfaceImpl::GetFunctionAddress(MethodDesc *pFD) SUPPORTS_DAC; } CONTRACTL_END; - return pFD->GetNativeCode_CurrentDefault(); + return pFD->GetNativeCode(); } #ifndef DACCESS_COMPILE diff --git a/src/coreclr/vm/encee.cpp b/src/coreclr/vm/encee.cpp index ed89d04e58941f..4959fde39cd43e 100644 --- a/src/coreclr/vm/encee.cpp +++ b/src/coreclr/vm/encee.cpp @@ -616,7 +616,7 @@ PCODE EditAndContinueModule::JitUpdatedFunction( MethodDesc *pMD, pMD->DoPrestub(NULL); LOG((LF_ENC, LL_INFO100, "EACM::ResumeInUpdatedFunction JIT of %p successful\n", pMD)); } - jittedCode = pMD->GetNativeCode_CurrentDefault(); + jittedCode = pMD->GetNativeCode(); } EX_CATCH { #ifdef _DEBUG { diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 134828d6f53a0f..ae0e9556e45610 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -4409,7 +4409,7 @@ TADDR MethodAndStartAddressToEECodeInfoPointer(MethodDesc *pMethodDesc, PCODE pN } CONTRACTL_END; // MethodDesc ==> Code Address ==>JitManager - TADDR start = PCODEToPINSTR(pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode_CurrentDefault()); + TADDR start = PCODEToPINSTR(pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode()); if(start == 0) { // this method hasn't been jitted return 0; @@ -5006,7 +5006,7 @@ VOID ETW::MethodLog::SendEventsForJitMethodsHelper(LoaderAllocator *pLoaderAlloc if (nativeCodeVersion.IsNull()) { // The code version manager hasn't been updated with the jitted code - if (codeStart != pMD->GetNativeCode_CurrentDefault()) + if (codeStart != pMD->GetNativeCode()) { continue; } @@ -5019,7 +5019,7 @@ VOID ETW::MethodLog::SendEventsForJitMethodsHelper(LoaderAllocator *pLoaderAlloc } else #endif // FEATURE_CODE_VERSIONING - if (codeStart != pMD->GetNativeCode_CurrentDefault()) + if (codeStart != pMD->GetNativeCode()) { continue; } diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 58d8fec24fa2bd..818f5dbef72639 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -3210,7 +3210,7 @@ extern "C" void * QCALLTYPE CallCatchFunclet(QCall::ObjectHandleOnStack exceptio pThread->GetExceptionState()->GetDebuggerState()->GetDebuggerInterceptInfo(&pInterceptMD, NULL, (PBYTE*)&(sfInterceptStackFrame.SP), &ulRelOffset, NULL); if (sfInterceptStackFrame.SP == GetSP(pvRegDisplay->pCurrentContext)) { - PCODE pStartAddress = pInterceptMD->GetNativeCode_CurrentDefault(); + PCODE pStartAddress = pInterceptMD->GetNativeCode(); EECodeInfo codeInfo(pStartAddress); _ASSERTE(codeInfo.IsValid()); @@ -3347,7 +3347,7 @@ extern "C" void QCALLTYPE ResumeAtInterceptionLocation(REGDISPLAY* pvRegDisplay) ExInfo::PopExInfos(pThread, (void*)targetSp); - PCODE pStartAddress = pInterceptMD->GetNativeCode_CurrentDefault(); + PCODE pStartAddress = pInterceptMD->GetNativeCode(); EECodeInfo codeInfo(pStartAddress); _ASSERTE(codeInfo.IsValid()); diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 1d3558ff68f25f..0f66214a997a36 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -1021,7 +1021,7 @@ WORD MethodDescChunk::InterlockedUpdateFlags(WORD wMask, BOOL fSet) // implemented by stubs. On WIN64, these stubs are IL stubs, which DO have native code. // // This function returns null if the method has no native code. -PCODE MethodDesc::GetNativeCode_CurrentDefault() +PCODE MethodDesc::GetNativeCode() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; @@ -1052,7 +1052,7 @@ PCODE MethodDesc::GetNativeCodeAnyVersion() WRAPPER_NO_CONTRACT; SUPPORTS_DAC; - PCODE pDefaultCode = GetNativeCode_CurrentDefault(); + PCODE pDefaultCode = GetNativeCode(); if (pDefaultCode != (PCODE)NULL) { return pDefaultCode; @@ -2130,7 +2130,7 @@ PCODE MethodDesc::TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags else { if (IsPointingToStableNativeCode()) - return GetNativeCode_CurrentDefault(); + return GetNativeCode(); } if (HasStableEntryPoint()) diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index 50b6eaee6b6492..1438276e35b42c 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -1468,7 +1468,7 @@ class MethodDesc if (!HasPrecode()) return TRUE; - return GetPrecode()->IsPointingToNativeCode(GetNativeCode_CurrentDefault()); + return GetPrecode()->IsPointingToNativeCode(GetNativeCode()); } // Be careful about races with profiler when using this method. The profiler can @@ -1479,7 +1479,7 @@ class MethodDesc { LIMITED_METHOD_DAC_CONTRACT; - return GetNativeCode_CurrentDefault() != (PCODE)0; + return GetNativeCode() != (PCODE)0; } // Perf warning: takes the CodeVersionManagerLock on every call @@ -1579,7 +1579,7 @@ class MethodDesc //******************************************************************************* // Returns the address of the native code. - PCODE GetNativeCode_CurrentDefault(); + PCODE GetNativeCode(); // Returns GetNativeCode() if it exists, but also checks to see if there // is a non-default code version that is populated with a code body and returns that. diff --git a/src/coreclr/vm/prestub.cpp b/src/coreclr/vm/prestub.cpp index 2e7420deb3ca21..3ea82cfe8ae4d2 100644 --- a/src/coreclr/vm/prestub.cpp +++ b/src/coreclr/vm/prestub.cpp @@ -1090,7 +1090,7 @@ PrepareCodeConfig::PrepareCodeConfig(NativeCodeVersion codeVersion, BOOL needsMu PCODE PrepareCodeConfig::IsJitCancellationRequested() { LIMITED_METHOD_CONTRACT; - return m_pMethodDesc->GetNativeCode_CurrentDefault(); + return m_pMethodDesc->GetNativeCode(); } BOOL PrepareCodeConfig::NeedsMulticoreJitNotification() @@ -2302,7 +2302,7 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo } /************************** POSTJIT *************************/ - _ASSERTE(pCode == (PCODE)NULL || GetNativeCode_CurrentDefault() == (PCODE)NULL || pCode == GetNativeCode_CurrentDefault()); + _ASSERTE(pCode == (PCODE)NULL || GetNativeCode() == (PCODE)NULL || pCode == GetNativeCode()); // At this point we must have either a pointer to managed code or to a stub. All of the above code // should have thrown an exception if it couldn't make a stub. @@ -2432,7 +2432,7 @@ static PCODE PatchNonVirtualExternalMethod(MethodDesc * pMD, PCODE pCode, PTR_RE if (pMD->HasPrecode() && pMD->GetPrecode()->GetType() == PRECODE_FIXUP && pMD->IsNativeCodeStableAfterInit()) { - PCODE pDirectTarget = pMD->IsFCall() ? ECall::GetFCallImpl(pMD, false /* throwForInvalidFCall */) : pMD->GetNativeCode_CurrentDefault(); + PCODE pDirectTarget = pMD->IsFCall() ? ECall::GetFCallImpl(pMD, false /* throwForInvalidFCall */) : pMD->GetNativeCode(); if (pDirectTarget != (PCODE)NULL) pCode = pDirectTarget; } diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index 998e2684dcf391..effd3b73b37441 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -2396,7 +2396,7 @@ HRESULT ProfToEEInterfaceImpl::GetCodeInfo(FunctionID functionId, LPCBYTE * pSta ULONG32 cCodeInfos; HRESULT hr = GetCodeInfoFromCodeStart( - pMethodDesc->GetNativeCode_CurrentDefault(), + pMethodDesc->GetNativeCode(), ARRAY_SIZE(codeInfos), &cCodeInfos, codeInfos); @@ -2472,7 +2472,7 @@ HRESULT ProfToEEInterfaceImpl::GetCodeInfo2(FunctionID functionId, if (SUCCEEDED(hr)) { hr = GetCodeInfoFromCodeStart( - pMethodDesc->GetNativeCode_CurrentDefault(), + pMethodDesc->GetNativeCode(), cCodeInfos, pcCodeInfos, codeInfos); diff --git a/src/coreclr/vm/tieredcompilation.cpp b/src/coreclr/vm/tieredcompilation.cpp index 87ac460c42b373..8f1b36eeac43ec 100644 --- a/src/coreclr/vm/tieredcompilation.cpp +++ b/src/coreclr/vm/tieredcompilation.cpp @@ -116,7 +116,7 @@ NativeCodeVersion::OptimizationTier TieredCompilationManager::GetInitialOptimiza // 1 - OptimizationTier0 as we don't want to instrument the initial version (will only instrument hot Tier0) // 2 - OptimizationTier0Instrumented - instrument all ILOnly code if (g_pConfig->TieredPGO_InstrumentOnlyHotCode() || - ExecutionManager::IsReadyToRunCode(pMethodDesc->GetNativeCode_CurrentDefault())) + ExecutionManager::IsReadyToRunCode(pMethodDesc->GetNativeCode())) { return NativeCodeVersion::OptimizationTier0; } From 5be5f2b5cf5193091d9e2b23fcf6d3b27aefd004 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 13 Aug 2025 13:16:56 -0700 Subject: [PATCH 3/4] Remove spurious comment --- src/coreclr/debug/daccess/daccess.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index fd5948fcec43a6..1282ed4e1ea4a0 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -5981,7 +5981,6 @@ ClrDataAccess::GetMethodVarInfo(MethodDesc* methodDesc, } else { - // This should get the native code here, then get the NativeCodeVersion, then from that call GetExecutableCode ... which should return either the jitted code or the interpreted code. nativeCodeStartAddr = PCODEToPINSTR(methodDesc->GetNativeCode()); } From 771066a39926e33a3a8a55507ee38cb6ff7776f5 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 13 Aug 2025 15:38:21 -0700 Subject: [PATCH 4/4] Fix build issue --- src/coreclr/vm/method.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 0f66214a997a36..4e4305c6b7eeb1 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -2223,11 +2223,11 @@ MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint) } if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE) { - StubPrecode stubPrecode = (StubPrecode*)PCODEToPINSTR(entryPoint); + StubPrecode *stubPrecode = (StubPrecode*)PCODEToPINSTR(entryPoint); #ifdef FEATURE_INTERPRETER - if (stubPrecode->GetType() == PRECODE_INTERPRETER)) + if (stubPrecode->GetType() == PRECODE_INTERPRETER) { - entryPoint = dac_cast(pStubPrecode)->GetData()->ByteCodeAddr; + entryPoint = dac_cast(stubPrecode)->GetData()->ByteCodeAddr; pRS = ExecutionManager::FindCodeRange(entryPoint, scanFlag); } else