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 some code under FEATURE_STUBS_AS_IL #104731

Merged
merged 33 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c06cc3f
Use direct SinglecastDelegateInvokeStub on windows x86
huoyaoyuan Jul 11, 2024
4845202
Cleanup ifdefs
huoyaoyuan Jul 11, 2024
faf25e7
EmitDebugBreak is unused
huoyaoyuan Jul 11, 2024
09fcf2b
endif format
huoyaoyuan Jul 11, 2024
19057f9
Restore comment
huoyaoyuan Jul 11, 2024
157325b
Fix JIT_InternalThrowFromHelper reference
huoyaoyuan Jul 11, 2024
c98be47
Use IL stub for Delegate.Invoke
huoyaoyuan Jul 15, 2024
72fd2d6
Remove SinglecastDelegateInvokeStub in asm
huoyaoyuan Jul 15, 2024
e60b3f1
Fix method name and argument count
huoyaoyuan Jul 17, 2024
7f117aa
Code quality
huoyaoyuan Jul 17, 2024
cd648fa
Delete JIT_InternalThrow and CorInfoException
huoyaoyuan Jul 17, 2024
b078f3a
Apply the same codegen to ilc
huoyaoyuan Jul 17, 2024
1ae9027
Add KeepAlive
huoyaoyuan Jul 18, 2024
a862368
Emit recursive call instead
huoyaoyuan Jul 21, 2024
39dc3f6
Merge branch 'main' into stubs-as-il
huoyaoyuan Jul 21, 2024
2c0510b
Merge branch 'main' into stubs-as-il
huoyaoyuan Jul 22, 2024
98b8b4e
Fix type
huoyaoyuan Jul 23, 2024
9130aa8
Merge branch 'main' into stubs-as-il
huoyaoyuan Jul 29, 2024
ee90e03
Add tests for indirect delegate invocation
huoyaoyuan Aug 1, 2024
b5304ad
Use public reflection instead.
huoyaoyuan Aug 1, 2024
22e344e
Use ldvirtftn to bypass this check
huoyaoyuan Aug 6, 2024
27ae5ba
Merge branch 'main'
huoyaoyuan Aug 6, 2024
0785f0b
Use winner from CompareExchange
huoyaoyuan Aug 7, 2024
8992882
Apply suggestions from code review
huoyaoyuan Sep 18, 2024
e06998c
Merge branch 'main' into stubs-as-il
huoyaoyuan Sep 18, 2024
c221eed
Return Stub from GetInvokeMethodStub
huoyaoyuan Sep 18, 2024
1c640f8
Delete NEWSTUB_FL_MULTICAST and dependents
huoyaoyuan Sep 18, 2024
e39afa1
Rename
huoyaoyuan Sep 19, 2024
eebbc01
Renumber
huoyaoyuan Sep 19, 2024
c2cf515
Merge branch 'main'
huoyaoyuan Sep 19, 2024
bc1a766
Format
huoyaoyuan Sep 19, 2024
ee674a3
Update src/coreclr/vm/method.hpp
jkotas Sep 19, 2024
fdd83eb
Handle new stub in ILStubManager
jkotas Sep 19, 2024
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
3 changes: 0 additions & 3 deletions src/coreclr/vm/amd64/AsmHelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,6 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT
ret
NESTED_END ProfileTailcallNaked, _TEXT


extern JIT_InternalThrowFromHelper:proc

LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT

test rcx, rcx
Expand Down
21 changes: 0 additions & 21 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,28 +1894,7 @@ PCODE COMDelegate::TheDelegateInvokeStub()
}
CONTRACT_END;

#if defined(TARGET_X86) && !defined(FEATURE_STUBS_AS_IL)
static PCODE s_pInvokeStub;

if (s_pInvokeStub == NULL)
{
CPUSTUBLINKER sl;
sl.EmitDelegateInvoke();
// Process-wide singleton stub that never unloads
Stub *pCandidate = sl.Link(SystemDomain::GetGlobalLoaderAllocator()->GetStubHeap(), NEWSTUB_FL_MULTICAST);
huoyaoyuan marked this conversation as resolved.
Show resolved Hide resolved

if (InterlockedCompareExchangeT<PCODE>(&s_pInvokeStub, pCandidate->GetEntryPoint(), NULL) != NULL)
{
// if we are here someone managed to set the stub before us so we release the current
ExecutableWriterHolder<Stub> candidateWriterHolder(pCandidate, sizeof(Stub));
candidateWriterHolder.GetRW()->DecRef();
}
}

RETURN s_pInvokeStub;
#else
RETURN GetEEFuncEntryPoint(SinglecastDelegateInvokeStub);
#endif // TARGET_X86 && !FEATURE_STUBS_AS_IL
}

// Get the cpu stub for a delegate invoke.
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/dllimportcallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ class UMEntryThunkCache
AppDomain *m_pDomain;
};

#if defined(TARGET_X86) && !defined(FEATURE_STUBS_AS_IL)
#ifndef FEATURE_EH_FUNCLETS
EXCEPTION_HANDLER_DECL(FastNExportExceptHandler);
#endif // TARGET_X86 && !FEATURE_STUBS_AS_IL
#endif // FEATURE_EH_FUNCLETS

extern "C" void TheUMEntryPrestub(void);
extern "C" PCODE TheUMEntryPrestubWorker(UMEntryThunk * pUMEntryThunk);
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/i386/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ ASMCONSTANTS_C_ASSERT(InlinedCallFrame__m_pCallerReturnAddress == offsetof(Inlin
#define InlinedCallFrame__m_pCalleeSavedFP 0x14
ASMCONSTANTS_C_ASSERT(InlinedCallFrame__m_pCalleeSavedFP == offsetof(InlinedCallFrame, m_pCalleeSavedFP));

#ifdef FEATURE_STUBS_AS_IL
// DelegateObject from src/vm/object.h
#define DelegateObject___target 0x04 // offset 0 is m_pMethTab of base class Object
#define DelegateObject___methodBase 0x08
Expand All @@ -299,8 +298,6 @@ ASMCONSTANTS_C_ASSERT(DelegateObject___methodPtrAux == offsetof(DelegateObje
ASMCONSTANTS_C_ASSERT(DelegateObject___invocationList == offsetof(DelegateObject, _invocationList));
ASMCONSTANTS_C_ASSERT(DelegateObject___invocationCount == offsetof(DelegateObject, _invocationCount));

#endif

// ResolveCacheElem from src/vm/virtualcallstub.h
#define ResolveCacheElem__pMT 0x00
#define ResolveCacheElem__token 0x04
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/i386/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ NESTED_ENTRY ResolveWorkerAsmStub, _TEXT, NoHandler
jmp eax // continue on into the method
NESTED_END ResolveWorkerAsmStub, _TEXT

#ifdef FEATURE_STUBS_AS_IL
// ==========================================================================
// void SinglecastDelegateInvokeStub();
//
Expand All @@ -756,7 +755,6 @@ LOCAL_LABEL(NullObject):
jmp C_FUNC(JIT_InternalThrow)

LEAF_END SinglecastDelegateInvokeStub, _TEXT
#endif // FEATURE_STUBS_AS_IL

// =======================================================================================
// void ResolveWorkerChainLookupAsmStub();
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/vm/i386/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,23 @@ _ProfileTailcallNaked@4 proc public
retn 4
_ProfileTailcallNaked@4 endp

_SinglecastDelegateInvokeStub@0 proc public

test ecx, ecx
jz NullObject


mov eax, [ecx + DelegateObject___methodPtr]
mov ecx, [ecx + DelegateObject___target] ; replace "this" pointer

jmp eax

NullObject:
mov ecx, CORINFO_NullReferenceException_ASM
jmp @JIT_InternalThrow@4
huoyaoyuan marked this conversation as resolved.
Show resolved Hide resolved

_SinglecastDelegateInvokeStub@0 endp

;==========================================================================
; Invoked for vararg forward P/Invoke calls as a stub.
; Except for secret return buffer, arguments come on the stack so EDX is available as scratch.
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/i386/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class BaseDomain;
// CPU-dependent functions
Stub * GenerateInitPInvokeFrameHelper();

#ifdef FEATURE_STUBS_AS_IL
EXTERN_C void SinglecastDelegateInvokeStub();
#endif // FEATURE_STUBS_AS_IL

#define GetEEFuncEntryPoint(pfn) GFN_TADDR(pfn)

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/i386/jithelp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ JIT_LLsh TEXTEQU <_JIT_LLsh@0>
JIT_LRsh TEXTEQU <_JIT_LRsh@0>
JIT_LRsz TEXTEQU <_JIT_LRsz@0>
JIT_LMul TEXTEQU <@JIT_LMul@16>
JIT_InternalThrowFromHelper TEXTEQU <@JIT_InternalThrowFromHelper@4>
JIT_WriteBarrierReg_PreGrow TEXTEQU <_JIT_WriteBarrierReg_PreGrow@0>
JIT_WriteBarrierReg_PostGrow TEXTEQU <_JIT_WriteBarrierReg_PostGrow@0>
JIT_TailCall TEXTEQU <_JIT_TailCall@0>
Expand All @@ -53,7 +52,6 @@ EXTERN g_card_table:DWORD
ifdef _DEBUG
EXTERN WriteBarrierAssert:PROC
endif ; _DEBUG
EXTERN JIT_InternalThrowFromHelper:PROC
ifdef FEATURE_HIJACK
EXTERN JIT_TailCallHelper:PROC
endif
Expand Down
50 changes: 0 additions & 50 deletions src/coreclr/vm/i386/stublinkerx86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3586,56 +3586,6 @@ VOID StubLinkerCPU::EmitShuffleThunk(ShuffleEntry *pShuffleEntryArray)

#if !defined(FEATURE_STUBS_AS_IL)

#ifdef TARGET_X86
//===========================================================================
// Emits code for MulticastDelegate.Invoke()
VOID StubLinkerCPU::EmitDelegateInvoke()
{
STANDARD_VM_CONTRACT;

CodeLabel *pNullLabel = NewCodeLabel();

// test THISREG, THISREG
X86EmitR2ROp(0x85, THIS_kREG, THIS_kREG);

// jz null
X86EmitCondJump(pNullLabel, X86CondCode::kJZ);

// mov SCRATCHREG, [THISREG + Delegate.FP] ; Save target stub in register
X86EmitIndexRegLoad(SCRATCH_REGISTER_X86REG, THIS_kREG, DelegateObject::GetOffsetOfMethodPtr());

// mov THISREG, [THISREG + Delegate.OR] ; replace "this" pointer
X86EmitIndexRegLoad(THIS_kREG, THIS_kREG, DelegateObject::GetOffsetOfTarget());

// jmp SCRATCHREG
Emit16(0xe0ff | (SCRATCH_REGISTER_X86REG<<8));

// Do a null throw
EmitLabel(pNullLabel);

// mov ECX, CORINFO_NullReferenceException
Emit8(0xb8+kECX);
Emit32(CORINFO_NullReferenceException);

X86EmitCall(NewExternalCodeLabel(GetEEFuncEntryPoint(JIT_InternalThrowFromHelper)), 0);

X86EmitReturn(0);
}
#endif // TARGET_X86

#endif // !FEATURE_STUBS_AS_IL

#if !defined(FEATURE_STUBS_AS_IL)
//===========================================================================
// Emits code to break into debugger
VOID StubLinkerCPU::EmitDebugBreak()
{
STANDARD_VM_CONTRACT;

// int3
Emit8(0xCC);
}

#if defined(FEATURE_COMINTEROP) && defined(TARGET_X86)

#ifdef _MSC_VER
Expand Down
16 changes: 0 additions & 16 deletions src/coreclr/vm/i386/stublinkerx86.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,27 +374,11 @@ class StubLinkerCPU : public StubLinker
BOOL bShouldProfile);
#endif // FEATURE_COMINTEROP && TARGET_X86

#ifndef FEATURE_STUBS_AS_IL

#ifdef TARGET_X86
//===========================================================================
// Emits code for Delegate.Invoke() any delegate type
VOID EmitDelegateInvoke();
#endif // TARGET_X86

#endif // !FEATURE_STUBS_AS_IL

//===========================================================================
// Emits code to adjust for a static delegate target.
VOID EmitShuffleThunk(struct ShuffleEntry *pShuffleEntryArray);


#ifndef FEATURE_STUBS_AS_IL
//===========================================================================
// Emits code to break into debugger
VOID EmitDebugBreak();
#endif // !FEATURE_STUBS_AS_IL

#if defined(_DEBUG) && !defined(TARGET_UNIX)
//===========================================================================
// Emits code to log JITHelper access
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3923,19 +3923,6 @@ HCIMPL1(void, JIT_InternalThrow, unsigned exceptNum)
}
HCIMPLEND

/*********************************************************************/
HCIMPL1(void*, JIT_InternalThrowFromHelper, unsigned exceptNum)
{
FCALL_CONTRACT;

FC_GC_POLL_NOT_NEEDED(); // throws always open up for GC
HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_NOPOLL(Frame::FRAME_ATTR_CAPTURE_DEPTH_2|Frame::FRAME_ATTR_EXACT_DEPTH);
COMPlusThrow(MapCorInfoExceptionToRuntimeExceptionKind(exceptNum));
HELPER_METHOD_FRAME_END();
return NULL;
}
HCIMPLEND

#ifndef STATUS_STACK_BUFFER_OVERRUN // Not defined yet in CESDK includes
# define STATUS_STACK_BUFFER_OVERRUN ((NTSTATUS)0xC0000409L)
#endif
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ extern "C" FCDECL2(VOID, JIT_WriteBarrier_Callable, Object **dst, Object *ref);
#define WriteBarrier_Helper JIT_WriteBarrier_Callable

extern "C" FCDECL1(void, JIT_InternalThrow, unsigned exceptNum);
huoyaoyuan marked this conversation as resolved.
Show resolved Hide resolved
extern "C" FCDECL1(void*, JIT_InternalThrowFromHelper, unsigned exceptNum);

#ifdef TARGET_AMD64

Expand Down
Loading