Skip to content

Commit

Permalink
Fix redundant MethodInfo lookup in UnixNativeCodeManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jun 16, 2023
1 parent 35a5afb commit f7300b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,23 @@ bool UnixNativeCodeManager::UnwindStackFrame(MethodInfo * pMethodInfo,

bool UnixNativeCodeManager::IsUnwindable(PTR_VOID pvAddress)
{
MethodInfo * pMethodInfo = NULL;

#if defined(TARGET_ARM64)
MethodInfo methodInfo;
FindMethodInfo(pvAddress, &methodInfo);
pMethodInfo = &methodInfo;
#endif

// VirtualUnwind can't unwind epilogues.
return TrailingEpilogueInstructionsCount(pvAddress) == 0;
return TrailingEpilogueInstructionsCount(pMethodInfo, pvAddress) == 0;
}

// when stopped in an epilogue, returns the count of remaining stack-consuming instructions
// otherwise returns
// 0 - not in epilogue,
// -1 - unknown.
int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(PTR_VOID pvAddress)
int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(MethodInfo * pMethodInfo, PTR_VOID pvAddress)
{
#ifdef TARGET_AMD64

Expand Down Expand Up @@ -598,9 +606,8 @@ int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(PTR_VOID pvAddress)
#define BEGS_BITS 0x14000000
#define BEGS_MASK 0x1C000000

MethodInfo pMethodInfo;
FindMethodInfo(pvAddress, &pMethodInfo);
UnixNativeMethodInfo* pNativeMethodInfo = (UnixNativeMethodInfo*)&pMethodInfo;
UnixNativeMethodInfo * pNativeMethodInfo = (UnixNativeMethodInfo *)pMethodInfo;
ASSERT(pNativeMethodInfo != NULL);

uint32_t* start = (uint32_t*)pNativeMethodInfo->pMethodStartAddress;

Expand Down Expand Up @@ -699,7 +706,7 @@ bool UnixNativeCodeManager::GetReturnAddressHijackInfo(MethodInfo * pMethodIn
GcInfoDecoder decoder(GCInfoToken(p), flags);
*pRetValueKind = GetGcRefKind(decoder.GetReturnKind());

int epilogueInstructions = TrailingEpilogueInstructionsCount((PTR_VOID)pRegisterSet->IP);
int epilogueInstructions = TrailingEpilogueInstructionsCount(pMethodInfo, (PTR_VOID)pRegisterSet->IP);
if (epilogueInstructions < 0)
{
// can't figure, possibly a breakpoint instruction
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class UnixNativeCodeManager : public ICodeManager
PInvokeTransitionFrame** ppPreviousTransitionFrame); // out

uintptr_t GetConservativeUpperBoundForOutgoingArgs(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet);
REGDISPLAY * pRegisterSet);

bool IsUnwindable(PTR_VOID pvAddress);

int TrailingEpilogueInstructionsCount(PTR_VOID pvAddress);
int TrailingEpilogueInstructionsCount(MethodInfo * pMethodInfo, PTR_VOID pvAddress);

bool GetReturnAddressHijackInfo(MethodInfo * pMethodInfo,
REGDISPLAY * pRegisterSet, // in
Expand Down

0 comments on commit f7300b5

Please sign in to comment.