Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup unused JIT stubs in vm #111237

Merged
merged 16 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ void Lowering::RehomeArgForFastTailCall(unsigned int lclNum,
//------------------------------------------------------------------------
// LowerTailCallViaJitHelper: lower a call via the tailcall JIT helper. Morph
// has already inserted tailcall helper special arguments. This function inserts
// actual data for some placeholders. This function is only used on x86.
// actual data for some placeholders. This function is only used on Windows x86.
//
// Lower
// tail.call(<function args>, int numberOfOldStackArgs, int dummyNumberOfNewStackArgs, int flags, void* dummyArg)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6319,7 +6319,7 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call)
// For the helper-assisted tail calls, we need to push all the arguments
// into a single list, and then add a few extra at the beginning or end.
//
// For x86, the tailcall helper is defined as:
// For Windows x86, the tailcall helper is defined as:
//
// JIT_TailCall(<function args>, int numberOfOldStackArgsWords, int numberOfNewStackArgsWords, int flags, void*
// callTarget)
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,6 @@ elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
)
endif()

if(CLR_CMAKE_HOST_UNIX)
list(APPEND VM_SOURCES_WKS_ARCH
${ARCH_SOURCES_DIR}/unixstubs.cpp
)
endif(CLR_CMAKE_HOST_UNIX)

set(VM_SOURCES_DAC_ARCH
exceptionhandling.cpp
)
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/vm/amd64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
#
# ***********************************************************

# EXTERN_C void JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle);
# <NOTE>
#
# </NOTE>
LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNIX_AMD64 was the only platform not implementing this in ASM.
What's the requirement for this method? Can it be implemented in C for all platforms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has custom calling convention - it has to preserve more register than the default calling convention is guaranteed to preserve. It cannot be implemented in C in general.

I think we just got lucky on UNIX_AMD64 or this profiling scenario is not tested on Unix Amd64.

ret
LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT

# EXTERN_C void ProfileEnterNaked(FunctionIDOrClientID functionIDOrClientID, size_t profiledRsp);
# <NOTE>
#
Expand Down
9 changes: 4 additions & 5 deletions src/coreclr/vm/amd64/excepamd64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ inline PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrameWorker(UINT_PTR establi
return *ppContext;
}

#ifdef TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(DISPATCHER_CONTEXT * pDispatcherContext)
{
LIMITED_METHOD_DAC_CONTRACT;

return GetCONTEXTFromRedirectedStubStackFrameWorker(pDispatcherContext->EstablisherFrame);
}
#endif // TARGET_WINDOWS

PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
{
Expand All @@ -63,17 +65,14 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
}

#if !defined(DACCESS_COMPILE)

#ifdef TARGET_WINDOWS
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
{
LIMITED_METHOD_CONTRACT;

return (FaultingExceptionFrame*)(pDispatcherContext->EstablisherFrame + THROWSTUB_ESTABLISHER_OFFSET_FaultingExceptionFrame);
}

#endif // !DACCESS_COMPILE

#if !defined(DACCESS_COMPILE)
#endif // TARGET_WINDOWS

#define AMD64_SIZE64_PREFIX 0x48
#define AMD64_ADD_IMM8_OP 0x83
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/amd64/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ EXTERN_C void RedirectForThrowControl();
// Retrieves the redirected CONTEXT* from the stack frame of one of the
// RedirectedHandledJITCaseForXXX_Stub's.
//
#ifdef TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(DISPATCHER_CONTEXT * pDispatcherContext);
#endif // TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext);

#ifdef TARGET_WINDOWS
//
// Retrieves the FaultingExceptionFrame* from the stack frame of
// RedirectForThrowControl.
//
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext);
#endif // TARGET_WINDOWS

//
// Functions that wrap RtlVirtualUnwind to make sure that in the AMD64 case all the
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/vm/amd64/unixstubs.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/coreclr/vm/arm/exceparm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
#include "asmconstants.h"
#include "virtualcallstub.h"

PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext)
{
LIMITED_METHOD_DAC_CONTRACT;

UINT_PTR stackSlot = pDispatcherContext->EstablisherFrame + REDIRECTSTUB_SP_OFFSET_CONTEXT;
PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
return *ppContext;
}

PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
{
LIMITED_METHOD_DAC_CONTRACT;
Expand All @@ -27,32 +18,6 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)

#if !defined(DACCESS_COMPILE)

// The next two functions help retrieve data kept relative to FaultingExceptionFrame that is setup
// for handling async exceptions (e.g. AV, NullRef, ThreadAbort, etc).
//
// FEF (and related data) is available relative to R4 - the thing to be kept in mind is that the
// DispatcherContext->ContextRecord:
//
// 1) represents the caller context in the first pass.
// 2) represents the current context in the second pass.
//
// Since R4 is a non-volatile register, this works for us since we setup the value of R4
// in the redirection helpers (e.g. RedirectForThreadAbort) but do not
// change it in their respective callee functions (e.g. RedirectForThreadAbort2)
// that have the personality routines associated with them (which perform the collided unwind and also
// invoke the two functions below).
//
// Thus, when our personality routine gets called in either passes, DC->ContextRecord->R4 will
// have the same value.

// Returns the pointer to the FEF
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext)
{
LIMITED_METHOD_CONTRACT;

return (FaultingExceptionFrame*)((TADDR)pDispatcherContext->ContextRecord->R4);
}

// Returns TRUE if caller should resume execution.
BOOL
AdjustContextForVirtualStub(
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/vm/arm/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ class FaultingExceptionFrame;
// Retrieves the redirected CONTEXT* from the stack frame of one of the
// RedirectedHandledJITCaseForXXX_Stub's.
//
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext);

//
// Retrieves the FaultingExceptionFrame* from the stack frame of
// RedirectForThrowControl.
//
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext);

inline
PCODE GetAdjustedCallAddress(PCODE returnAddress)
{
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/vm/arm/unixstubs.cpp

This file was deleted.

6 changes: 5 additions & 1 deletion src/coreclr/vm/arm64/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class FaultingExceptionFrame;
// Retrieves the redirected CONTEXT* from the stack frame of one of the
// RedirectedHandledJITCaseForXXX_Stub's.
//
#ifdef TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
#endif // TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext);

#ifdef TARGET_WINDOWS
//
// Retrieves the FaultingExceptionFrame* from the stack frame of
// RedirectForThrowControl.
// RedirectForThreadAbort.
//
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext);
#endif // TARGET_WINDOWS

inline
PCODE GetAdjustedCallAddress(PCODE returnAddress)
Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/vm/arm64/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,6 @@ void emitCOMStubCall (ComCallMethodDesc *pCOMMethodRX, ComCallMethodDesc *pCOMMe
}
#endif // FEATURE_COMINTEROP

void JIT_TailCall()
{
_ASSERTE(!"ARM64:NYI");
}

#if !defined(DACCESS_COMPILE)
EXTERN_C void JIT_UpdateWriteBarrierState(bool skipEphemeralCheck, size_t writeableOffset);

Expand Down Expand Up @@ -917,6 +912,7 @@ void InitJITHelpers1()
void UpdateWriteBarrierState(bool) {}
#endif // !defined(DACCESS_COMPILE)

#ifdef TARGET_WINDOWS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext)
{
LIMITED_METHOD_DAC_CONTRACT;
Expand All @@ -925,6 +921,7 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispa
PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
return *ppContext;
}
#endif // TARGET_WINDOWS

PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
{
Expand All @@ -936,13 +933,14 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
}

#if !defined(DACCESS_COMPILE)
#ifdef TARGET_WINDOWS
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
{
LIMITED_METHOD_CONTRACT;

return (FaultingExceptionFrame*)((TADDR)pDispatcherContext->ContextRecord->X19);
}

#endif // TARGET_WINDOWS

BOOL
AdjustContextForVirtualStub(
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/vm/arm64/unixstubs.cpp

This file was deleted.

15 changes: 2 additions & 13 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5891,7 +5891,7 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo

pDispatcherContext->ControlPc = (UINT_PTR) GetIP(pDispatcherContext->ContextRecord);

#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
#if defined(TARGET_ARM64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It would be nice to change the ifdef around this method to #ifdef TARGET_WINDOWS to match the rest

// Since this routine is used to fixup contexts for async exceptions,
// clear the CONTEXT_UNWOUND_TO_CALL flag since, semantically, frames
// where such exceptions have happened do not have callsites. On a similar
Expand All @@ -5911,21 +5911,10 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo
// be fixing it at their end, in their implementation of collided unwind.
pDispatcherContext->ContextRecord->ContextFlags &= ~CONTEXT_DEBUG_REGISTERS;

#ifdef TARGET_ARM
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_ARM;
#elif defined(TARGET_LOONGARCH64)
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_LOONGARCH64;
#elif defined(TARGET_RISCV64)
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_RISCV64;
#else // TARGET_ARM64
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_ARM64;
#endif // TARGET_ARM

#endif // TARGET_ARM || TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64
#endif // TARGET_ARM64

INDEBUG(pDispatcherContext->FunctionEntry = (PT_RUNTIME_FUNCTION)INVALID_POINTER_CD);
INDEBUG(pDispatcherContext->ImageBase = INVALID_POINTER_CD);
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/i386/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ EXTERN_C LPVOID STDCALL COMPlusEndCatch(LPVOID ebp, DWORD ebx, DWORD edi, DWORD
// RedirectedHandledJITCaseForXXX_Stub's.
//
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext);
#ifdef FEATURE_EH_FUNCLETS
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
#endif // FEATURE_EH_FUNCLETS

// Determine the address of the instruction that made the current call.
inline
Expand Down
30 changes: 0 additions & 30 deletions src/coreclr/vm/i386/unixstubs.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions src/coreclr/vm/i386/virtualcallstubcpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,10 @@ StubCallSite::StubCallSite(TADDR siteAddrForRegisterIndirect, PCODE returnAddr)
}
}

#ifndef UNIX_X86_ABI
// the special return address for VSD tailcalls
extern "C" void STDCALL JIT_TailCallReturnFromVSD();
#endif // UNIX_X86_ABI

PCODE StubCallSite::GetCallerAddress()
{
Expand Down
15 changes: 5 additions & 10 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,19 @@ extern "C"
{
#ifndef FEATURE_EH_FUNCLETS
void STDCALL JIT_EndCatch(); // JIThelp.asm/JIThelp.s
#endif // TARGET_X86
#endif // FEATURE_EH_FUNCLETS

void STDCALL JIT_ByRefWriteBarrier(); // JIThelp.asm/JIThelp.s

#if defined(TARGET_AMD64) || defined(TARGET_ARM)

FCDECL2VA(void, JIT_TailCall, PCODE copyArgs, PCODE target);

#else // TARGET_AMD64 || TARGET_ARM

#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
void STDCALL JIT_TailCall(); // JIThelp.asm

#endif // TARGET_AMD64 || TARGET_ARM
#endif // defined(TARGET_X86) && !defined(UNIX_X86_ABI)

void STDMETHODCALLTYPE JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle);
#if !defined(TARGET_ARM64) && !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)
// TODO: implement stack probing for other architectures https://github.com/dotnet/runtime/issues/13519
void STDCALL JIT_StackProbe();
#endif // TARGET_ARM64
#endif // !defined(TARGET_ARM64) && !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)
jkotas marked this conversation as resolved.
Show resolved Hide resolved
};

/*********************************************************************/
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/vm/loongarch64/excepcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@ class FaultingExceptionFrame;
// Retrieves the redirected CONTEXT* from the stack frame of one of the
// RedirectedHandledJITCaseForXXX_Stub's.
//
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext);

//
// Retrieves the FaultingExceptionFrame* from the stack frame of
// RedirectForThrowControl.
//
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext);

inline
PCODE GetAdjustedCallAddress(PCODE returnAddress)
{
Expand Down
Loading
Loading