Skip to content

Commit d2ce174

Browse files
authored
Deduplicate entrypoint to MD mapping helpers (#119135)
NonVirtualEntry2MethodDesc and MethodTable::GetMethodDescForSlotAddress provided equivalent functionality. NonVirtualEntry2MethodDesc is used more frequently and has more sensible name. - Delete MethodTable::GetMethodDescForSlotAddress and replaced all calls to it with NonVirtualEntry2MethodDesc - DACized NonVirtualEntry2MethodDesc.
1 parent 614ada9 commit d2ce174

File tree

13 files changed

+49
-93
lines changed

13 files changed

+49
-93
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,7 @@ HRESULT DacDbiInterfaceImpl::GetMethodDescPtrFromIpEx(TADDR funcIp, VMPTR_Method
31913191
}
31923192

31933193
// Otherwise try to see if a method desc is available for the method that isn't jitted by walking the code stubs.
3194-
MethodDesc* pMD = MethodTable::GetMethodDescForSlotAddress(PINSTRToPCODE(funcIp));
3194+
MethodDesc* pMD = NonVirtualEntry2MethodDesc(PINSTRToPCODE(funcIp));
31953195

31963196
if (pMD == NULL)
31973197
return E_INVALIDARG;

src/coreclr/debug/daccess/request.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ BOOL DacValidateMD(PTR_MethodDesc pMD)
218218
PCODE tempEntryPoint = pMD->GetTemporaryEntryPointIfExists();
219219
if (tempEntryPoint != (PCODE)NULL)
220220
{
221-
MethodDesc *pMDCheck = MethodDesc::GetMethodDescFromStubAddr(tempEntryPoint, TRUE);
221+
MethodDesc *pMDCheck = MethodDesc::GetMethodDescFromPrecode(tempEntryPoint, TRUE);
222222

223223
if (PTR_HOST_TO_TADDR(pMD) != PTR_HOST_TO_TADDR(pMDCheck))
224224
{
@@ -1343,7 +1343,7 @@ ClrDataAccess::GetCodeHeaderData(CLRDATA_ADDRESS ip, struct DacpCodeHeaderData *
13431343
if (!codeInfo.IsValid())
13441344
{
13451345
// We may be able to walk stubs to find a method desc if it's not a jitted method.
1346-
MethodDesc *methodDescI = MethodTable::GetMethodDescForSlotAddress(TO_TADDR(ip));
1346+
MethodDesc *methodDescI = NonVirtualEntry2MethodDesc(TO_TADDR(ip));
13471347
if (methodDescI == NULL)
13481348
{
13491349
hr = E_INVALIDARG;

src/coreclr/vm/classcompat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class MethodTableBuilder
361361
if (pVtable[slot] != NULL && pVtableMD[slot] == NULL)
362362
pVtableMD[slot] = pParentMethodTable->GetMethodDescForSlot(slot);
363363
_ASSERTE((pVtable[slot] == NULL) ||
364-
(MethodTable::GetMethodDescForSlotAddress(pVtable[slot]) == pVtableMD[slot]));
364+
(NonVirtualEntry2MethodDesc(pVtable[slot]) == pVtableMD[slot]));
365365
return pVtableMD[slot];
366366
}
367367
#endif // DACCESS_COMPILE

src/coreclr/vm/comdelegate.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ extern "C" void QCALLTYPE Delegate_InitializeVirtualCallStub(QCall::ObjectHandle
15811581

15821582
GCX_COOP();
15831583

1584-
MethodDesc *pMeth = MethodTable::GetMethodDescForSlotAddress((PCODE)method);
1584+
MethodDesc *pMeth = NonVirtualEntry2MethodDesc((PCODE)method);
15851585
_ASSERTE(pMeth);
15861586
_ASSERTE(!pMeth->IsStatic() && pMeth->IsVirtual());
15871587
PCODE target = GetVirtualCallStub(pMeth, TypeHandle(pMeth->GetMethodTable()));
@@ -1874,20 +1874,13 @@ MethodDesc *COMDelegate::GetMethodDesc(OBJECTREF orDelegate)
18741874
// Next, check for an open delegate
18751875
PCODE code = thisDel->GetMethodPtrAux();
18761876

1877-
if (code != (PCODE)NULL)
1877+
if (code == (PCODE)NULL)
18781878
{
1879-
// Note that MethodTable::GetMethodDescForSlotAddress is significantly faster than Entry2MethodDesc
1880-
pMethodHandle = MethodTable::GetMethodDescForSlotAddress(code);
1881-
}
1882-
else
1883-
{
1884-
MethodTable * pMT = NULL;
1885-
18861879
// Must be a normal delegate
18871880
code = thisDel->GetMethodPtr();
1888-
1889-
pMethodHandle = NonVirtualEntry2MethodDesc(code);
18901881
}
1882+
1883+
pMethodHandle = NonVirtualEntry2MethodDesc(code);
18911884
}
18921885

18931886
_ASSERTE(pMethodHandle);

src/coreclr/vm/comutilnative.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ static BOOL HasOverriddenMethod(MethodTable* mt, MethodTable* classMT, WORD meth
15871587

15881588
// If CoreLib is JITed, the slots can be patched and thus we need to compare the actual MethodDescs
15891589
// to detect match reliably
1590-
if (MethodTable::GetMethodDescForSlotAddress(actual) == MethodTable::GetMethodDescForSlotAddress(base))
1590+
if (NonVirtualEntry2MethodDesc(actual) == NonVirtualEntry2MethodDesc(base))
15911591
{
15921592
return FALSE;
15931593
}
@@ -1913,7 +1913,7 @@ static bool HasOverriddenStreamMethod(MethodTable* streamMT, MethodTable* pMT, W
19131913

19141914
// If CoreLib is JITed, the slots can be patched and thus we need to compare
19151915
// the actual MethodDescs to detect match reliably.
1916-
return MethodTable::GetMethodDescForSlotAddress(actual) != MethodTable::GetMethodDescForSlotAddress(base);
1916+
return NonVirtualEntry2MethodDesc(actual) != NonVirtualEntry2MethodDesc(base);
19171917
}
19181918

19191919
extern "C" BOOL QCALLTYPE Stream_HasOverriddenSlow(MethodTable* pMT, BOOL isRead)

src/coreclr/vm/contractimpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MethodDesc * DispatchSlot::GetMethodDesc()
3636
if (IsNull())
3737
return NULL;
3838
else
39-
return MethodTable::GetMethodDescForSlotAddress(GetTarget());
39+
return NonVirtualEntry2MethodDesc(GetTarget());
4040
}
4141

4242
//------------------------------------------------------------------------

src/coreclr/vm/method.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,8 @@ PCODE MethodDesc::GetCallTarget(OBJECTREF* pThisObj, TypeHandle ownerType)
21982198
return pTarget;
21992199
}
22002200

2201+
#endif // !DACCESS_COMPILE
2202+
22012203
MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint)
22022204
{
22032205
CONTRACTL {
@@ -2213,38 +2215,37 @@ MethodDesc* NonVirtualEntry2MethodDesc(PCODE entryPoint)
22132215
return NULL;
22142216
}
22152217

2216-
// Inlined fast path for fixup precode and stub precode from RangeList implementation
2217-
if (pRS->_flags == RangeSection::RANGE_SECTION_RANGELIST)
2218+
if (pRS->_flags & RangeSection::RANGE_SECTION_RANGELIST)
22182219
{
2220+
Precode* pPrecode = Precode::GetPrecodeFromEntryPoint(entryPoint);
2221+
#ifdef DACCESS_COMPILE
2222+
// GetPrecodeFromEntryPoint can return NULL under DAC
2223+
if (pPrecode == NULL)
2224+
return NULL;
2225+
#endif
22192226
if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_FIXUPPRECODE)
22202227
{
2221-
return (MethodDesc*)((FixupPrecode*)PCODEToPINSTR(entryPoint))->GetMethodDesc();
2228+
return dac_cast<PTR_MethodDesc>(pPrecode->AsFixupPrecode()->GetMethodDesc());
22222229
}
22232230
if (pRS->_pRangeList->GetCodeBlockKind() == STUB_CODE_BLOCK_STUBPRECODE)
22242231
{
2225-
return (MethodDesc*)((StubPrecode*)PCODEToPINSTR(entryPoint))->GetMethodDesc();
2232+
return dac_cast<PTR_MethodDesc>(pPrecode->AsStubPrecode()->GetMethodDesc());
22262233
}
22272234
}
2228-
2229-
MethodDesc* pMD;
2230-
if (pRS->_pjit->JitCodeToMethodInfo(pRS, entryPoint, &pMD, NULL))
2231-
return pMD;
2232-
2233-
auto stubCodeBlockKind = pRS->_pjit->GetStubCodeBlockKind(pRS, entryPoint);
2234-
2235-
switch(stubCodeBlockKind)
2235+
else
22362236
{
2237-
case STUB_CODE_BLOCK_FIXUPPRECODE:
2238-
return (MethodDesc*)((FixupPrecode*)PCODEToPINSTR(entryPoint))->GetMethodDesc();
2239-
case STUB_CODE_BLOCK_STUBPRECODE:
2240-
return (MethodDesc*)((StubPrecode*)PCODEToPINSTR(entryPoint))->GetMethodDesc();
2241-
default:
2242-
// We should never get here
2243-
_ASSERTE(!"NonVirtualEntry2MethodDesc failed for RangeSection");
2244-
return NULL;
2237+
MethodDesc* pMD;
2238+
if (pRS->_pjit->JitCodeToMethodInfo(pRS, entryPoint, &pMD, NULL))
2239+
return pMD;
22452240
}
2241+
2242+
// We should never get here
2243+
_ASSERTE(!"NonVirtualEntry2MethodDesc failed");
2244+
return NULL;
22462245
}
22472246

2247+
#ifndef DACCESS_COMPILE
2248+
22482249
static void GetNameOfTypeDefOrRef(Module* pModule, mdToken tk, LPCSTR* pName, LPCSTR* pNamespace)
22492250
{
22502251
*pName = "";
@@ -2624,7 +2625,7 @@ void MethodDesc::CheckRestore(ClassLoadLevel level)
26242625
}
26252626

26262627
// static
2627-
MethodDesc* MethodDesc::GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative /*=FALSE*/)
2628+
MethodDesc* MethodDesc::GetMethodDescFromPrecode(PCODE addr, BOOL fSpeculative /*=FALSE*/)
26282629
{
26292630
CONTRACT(MethodDesc *)
26302631
{
@@ -2635,8 +2636,6 @@ MethodDesc* MethodDesc::GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative
26352636

26362637
MethodDesc* pMD = NULL;
26372638

2638-
// Otherwise this must be some kind of precode
2639-
//
26402639
PTR_Precode pPrecode = Precode::GetPrecodeFromEntryPoint(addr, fSpeculative);
26412640
_ASSERTE(fSpeculative || (pPrecode != NULL));
26422641
if (pPrecode != NULL)
@@ -2670,7 +2669,7 @@ PCODE MethodDesc::GetTemporaryEntryPoint()
26702669
_ASSERTE(pEntryPoint != (PCODE)NULL);
26712670

26722671
#ifdef _DEBUG
2673-
MethodDesc * pMD = MethodDesc::GetMethodDescFromStubAddr(pEntryPoint);
2672+
MethodDesc * pMD = MethodDesc::GetMethodDescFromPrecode(pEntryPoint);
26742673
_ASSERTE(PTR_HOST_TO_TADDR(this) == PTR_HOST_TO_TADDR(pMD));
26752674
#endif
26762675

src/coreclr/vm/method.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,7 @@ class MethodDesc
415415
Precode* GetOrCreatePrecode();
416416
void MarkPrecodeAsStableEntrypoint();
417417

418-
419-
// Given a code address return back the MethodDesc whenever possible
420-
//
421-
static MethodDesc * GetMethodDescFromStubAddr(PCODE addr, BOOL fSpeculative = FALSE);
418+
static MethodDesc * GetMethodDescFromPrecode(PCODE addr, BOOL fSpeculative = FALSE);
422419

423420

424421
DWORD GetAttrs() const;

src/coreclr/vm/methodtable.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ MethodDesc *MethodTable::GetMethodDescForComInterfaceMethod(MethodDesc *pItfMD,
572572

573573
if (tgt != NULL)
574574
{
575-
RETURN(MethodTable::GetMethodDescForSlotAddress(tgt));
575+
RETURN(NonVirtualEntry2MethodDesc(tgt));
576576
}
577577

578578
// The interface is not in the static class definition so we need to look at the
@@ -1833,7 +1833,7 @@ MethodDesc *MethodTable::GetMethodDescForInterfaceMethod(TypeHandle ownerType, M
18331833
_ASSERTE(!throwOnConflict);
18341834
return NULL;
18351835
}
1836-
pMD = MethodTable::GetMethodDescForSlotAddress(pTgt);
1836+
pMD = NonVirtualEntry2MethodDesc(pTgt);
18371837

18381838
#ifdef _DEBUG
18391839
MethodDesc *pDispSlotMD = FindDispatchSlotForInterfaceMD(ownerType, pInterfaceMD, throwOnConflict).GetMethodDesc();
@@ -6199,33 +6199,6 @@ void MethodTable::GetGuid(GUID *pGuid, BOOL bGenerateIfNotFound, BOOL bClassic /
61996199
#endif // !DACCESS_COMPILE
62006200
}
62016201

6202-
6203-
//==========================================================================================
6204-
MethodDesc* MethodTable::GetMethodDescForSlotAddress(PCODE addr, BOOL fSpeculative /*=FALSE*/)
6205-
{
6206-
CONTRACT(MethodDesc *)
6207-
{
6208-
GC_NOTRIGGER;
6209-
NOTHROW;
6210-
POSTCONDITION(CheckPointer(RETVAL, NULL_NOT_OK));
6211-
POSTCONDITION(RETVAL->m_pDebugMethodTable == NULL || // We must be in BuildMethdTableThrowing()
6212-
RETVAL->SanityCheck());
6213-
}
6214-
CONTRACT_END;
6215-
6216-
MethodDesc* pMethodDesc = ExecutionManager::GetCodeMethodDesc(addr);
6217-
if (NULL != pMethodDesc)
6218-
{
6219-
goto lExit;
6220-
}
6221-
6222-
pMethodDesc = MethodDesc::GetMethodDescFromStubAddr(addr, fSpeculative);
6223-
6224-
lExit:
6225-
6226-
RETURN(pMethodDesc);
6227-
}
6228-
62296202
//==========================================================================================
62306203
/* static*/
62316204
BOOL MethodTable::ComputeContainsGenericVariables(Instantiation inst)
@@ -7880,7 +7853,7 @@ void MethodTable::SetSlot(UINT32 slotNumber, PCODE slotCode)
78807853

78817854
if (fSharedVtableChunk)
78827855
{
7883-
MethodDesc* pMD = GetMethodDescForSlotAddress(slotCode);
7856+
MethodDesc* pMD = NonVirtualEntry2MethodDesc(slotCode);
78847857
_ASSERTE(pMD->IsVersionableWithVtableSlotBackpatch() || pMD->GetStableEntryPoint() == slotCode);
78857858
}
78867859
}

src/coreclr/vm/methodtable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,6 @@ class MethodTable
17451745
// algorithm that does not allocate a temporary entrypoint for the slot if it doesn't exist.
17461746
MethodDesc* GetMethodDescForSlot_NoThrow(DWORD slot);
17471747

1748-
static MethodDesc* GetMethodDescForSlotAddress(PCODE addr, BOOL fSpeculative = FALSE);
1749-
17501748
PCODE GetRestoredSlot(DWORD slot);
17511749

17521750
// Returns MethodTable that GetRestoredSlot get its values from

0 commit comments

Comments
 (0)