Skip to content

Commit cc17a46

Browse files
huoyaoyuanjkotas
andauthored
Cleanup some code under FEATURE_STUBS_AS_IL (#104731)
* Use direct SinglecastDelegateInvokeStub on windows x86 * Cleanup ifdefs * EmitDebugBreak is unused * Use IL stub for Delegate.Invoke * Remove SinglecastDelegateInvokeStub in asm * Fix method name and argument count * Code quality * Delete JIT_InternalThrow and CorInfoException * Apply the same codegen to ilc * Add KeepAlive * Emit recursive call instead * Add tests for indirect delegate invocation * Use public reflection instead. * Use ldvirtftn to bypass this check * Use winner from CompareExchange * Return Stub from GetInvokeMethodStub * Delete NEWSTUB_FL_MULTICAST and dependents * Handle new stub in ILStubManager --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent 51bd2b9 commit cc17a46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+198
-511
lines changed

src/coreclr/inc/corinfo.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -826,22 +826,6 @@ enum CORINFO_EH_CLAUSE_FLAGS
826826
CORINFO_EH_CLAUSE_SAMETRY = 0x0010, // This clause covers same try block as the previous one
827827
};
828828

829-
// This enumeration is passed to InternalThrow
830-
enum CorInfoException
831-
{
832-
CORINFO_NullReferenceException,
833-
CORINFO_DivideByZeroException,
834-
CORINFO_InvalidCastException,
835-
CORINFO_IndexOutOfRangeException,
836-
CORINFO_OverflowException,
837-
CORINFO_SynchronizationLockException,
838-
CORINFO_ArrayTypeMismatchException,
839-
CORINFO_RankException,
840-
CORINFO_ArgumentNullException,
841-
CORINFO_ArgumentException,
842-
CORINFO_Exception_Count,
843-
};
844-
845829
// These are used to detect array methods as NamedIntrinsic in JIT importer,
846830
// which otherwise don't have a name.
847831
enum class CorInfoArrayIntrinsic

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ public static MethodIL EmitIL(MethodDesc method)
5050
FieldDesc functionPointerField = delegateType.GetKnownField("_functionPointer");
5151
ILCodeStream codeStream = emit.NewCodeStream();
5252

53+
// Store the function pointer into local variable to avoid unnecessary register usage by JIT
54+
ILLocalVariable functionPointer = emit.NewLocal(context.GetWellKnownType(WellKnownType.IntPtr));
55+
56+
codeStream.EmitLdArg(0);
57+
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(functionPointerField.InstantiateAsOpen()));
58+
codeStream.EmitStLoc(functionPointer);
59+
5360
codeStream.EmitLdArg(0);
5461
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(firstParameterField.InstantiateAsOpen()));
5562
for (int i = 0; i < method.Signature.Length; i++)
5663
{
5764
codeStream.EmitLdArg(i + 1);
5865
}
59-
codeStream.EmitLdArg(0);
60-
codeStream.Emit(ILOpcode.ldfld, emit.NewToken(functionPointerField.InstantiateAsOpen()));
66+
codeStream.EmitLdLoc(functionPointer);
6167

6268
MethodSignature signature = method.Signature;
6369
if (method.OwningType.HasInstantiation)

src/coreclr/vm/amd64/AsmHelpers.asm

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
include AsmMacros.inc
55
include asmconstants.inc
66

7-
extern JIT_InternalThrow:proc
87
extern NDirectImportWorker:proc
98
extern ThePreStub:proc
109
extern ProfileEnter:proc
@@ -565,26 +564,6 @@ NESTED_ENTRY ProfileTailcallNaked, _TEXT
565564
ret
566565
NESTED_END ProfileTailcallNaked, _TEXT
567566

568-
569-
extern JIT_InternalThrowFromHelper:proc
570-
571-
LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT
572-
573-
test rcx, rcx
574-
jz NullObject
575-
576-
577-
mov rax, [rcx + OFFSETOF__DelegateObject___methodPtr]
578-
mov rcx, [rcx + OFFSETOF__DelegateObject___target] ; replace "this" pointer
579-
580-
jmp rax
581-
582-
NullObject:
583-
mov rcx, CORINFO_NullReferenceException_ASM
584-
jmp JIT_InternalThrow
585-
586-
LEAF_END SinglecastDelegateInvokeStub, _TEXT
587-
588567
ifdef FEATURE_TIERED_COMPILATION
589568

590569
extern OnCallCountThresholdReached:proc

src/coreclr/vm/amd64/JitHelpers_Fast.asm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ ifdef _DEBUG
4747
extern JIT_WriteBarrier_Debug:proc
4848
endif
4949

50-
extern JIT_InternalThrow:proc
51-
5250

5351
; JIT_ByRefWriteBarrier has weird semantics, see usage in StubLinkerX86.cpp
5452
;

src/coreclr/vm/amd64/JitHelpers_Slow.asm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ extern g_pStringClass:QWORD
5555
extern FramedAllocateString:proc
5656
extern JIT_NewArr1:proc
5757

58-
extern JIT_InternalThrow:proc
59-
6058
ifdef _DEBUG
6159
; Version for when we're sure to be in the GC, checks whether or not the card
6260
; needs to be updated

src/coreclr/vm/amd64/asmconstants.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__ThreadExceptionState__m_pCurrentTracker
124124

125125

126126

127-
#define OFFSETOF__DelegateObject___methodPtr 0x18
128-
ASMCONSTANT_OFFSETOF_ASSERT(DelegateObject, _methodPtr);
129-
130-
#define OFFSETOF__DelegateObject___target 0x08
131-
ASMCONSTANT_OFFSETOF_ASSERT(DelegateObject, _target);
132-
133127
#define OFFSETOF__MethodTable__m_dwFlags 0x00
134128
ASMCONSTANTS_C_ASSERT(OFFSETOF__MethodTable__m_dwFlags
135129
== offsetof(MethodTable, m_dwFlags));
@@ -198,18 +192,6 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics
198192
ASMCONSTANTS_C_ASSERT(OFFSETOF__DynamicStaticsInfo__m_pGCStatics
199193
== offsetof(DynamicStaticsInfo, m_pGCStatics));
200194

201-
#define CORINFO_NullReferenceException_ASM 0
202-
ASMCONSTANTS_C_ASSERT( CORINFO_NullReferenceException_ASM
203-
== CORINFO_NullReferenceException);
204-
205-
#define CORINFO_IndexOutOfRangeException_ASM 3
206-
ASMCONSTANTS_C_ASSERT( CORINFO_IndexOutOfRangeException_ASM
207-
== CORINFO_IndexOutOfRangeException);
208-
209-
#define CORINFO_ArgumentException_ASM 9
210-
ASMCONSTANTS_C_ASSERT( CORINFO_ArgumentException_ASM
211-
== CORINFO_ArgumentException);
212-
213195

214196
// MachState offsets (AMD64\gmscpu.h)
215197

src/coreclr/vm/amd64/cgencpu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class Module;
3131
struct VASigCookie;
3232
class ComCallMethodDesc;
3333

34-
//
35-
// functions implemented in AMD64 assembly
36-
//
37-
EXTERN_C void SinglecastDelegateInvokeStub();
3834

3935
#define COMMETHOD_PREPAD 16 // # extra bytes to allocate in addition to sizeof(ComCallMethodDesc)
4036
#define COMMETHOD_CALL_PRESTUB_SIZE 6 // 32-bit indirect relative call

src/coreclr/vm/amd64/unixasmhelpers.S

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,6 @@ NESTED_END OnHijackTripThread, _TEXT
182182

183183
#endif // FEATURE_HIJACK
184184

185-
LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT
186-
187-
test rdi, rdi
188-
jz NullObject
189-
190-
191-
mov rax, [rdi + OFFSETOF__DelegateObject___methodPtr]
192-
mov rdi, [rdi + OFFSETOF__DelegateObject___target] // replace "this" pointer
193-
194-
jmp rax
195-
196-
NullObject:
197-
mov rdi, CORINFO_NullReferenceException_ASM
198-
jmp C_FUNC(JIT_InternalThrow)
199-
200-
LEAF_END SinglecastDelegateInvokeStub, _TEXT
201-
202185
#ifdef FEATURE_TIERED_COMPILATION
203186

204187
NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler

src/coreclr/vm/arm/asmconstants.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@
3535

3636
#define REDIRECTSTUB_SP_OFFSET_CONTEXT 0
3737

38-
#define CORINFO_NullReferenceException_ASM 0
39-
ASMCONSTANTS_C_ASSERT( CORINFO_NullReferenceException_ASM
40-
== CORINFO_NullReferenceException);
41-
42-
#define CORINFO_IndexOutOfRangeException_ASM 3
43-
ASMCONSTANTS_C_ASSERT( CORINFO_IndexOutOfRangeException_ASM
44-
== CORINFO_IndexOutOfRangeException);
45-
4638

4739
// Offset of the array containing the address of captured registers in MachState
4840
#define MachState__captureR4_R11 0x0
@@ -64,12 +56,6 @@ ASMCONSTANTS_C_ASSERT(LazyMachState_captureSp == offsetof(LazyMachState, capture
6456
#define LazyMachState_captureIp (LazyMachState_captureSp+4)
6557
ASMCONSTANTS_C_ASSERT(LazyMachState_captureIp == offsetof(LazyMachState, captureIp))
6658

67-
#define DelegateObject___methodPtr 0x0c
68-
ASMCONSTANTS_C_ASSERT(DelegateObject___methodPtr == offsetof(DelegateObject, _methodPtr));
69-
70-
#define DelegateObject___target 0x04
71-
ASMCONSTANTS_C_ASSERT(DelegateObject___target == offsetof(DelegateObject, _target));
72-
7359
#define MethodTable__m_BaseSize 0x04
7460
ASMCONSTANTS_C_ASSERT(MethodTable__m_BaseSize == offsetof(MethodTable, m_BaseSize));
7561

src/coreclr/vm/arm/asmhelpers.S

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,6 @@ CallDescrWorkerInternalReturnAddressOffset:
152152

153153
LEAF_END LazyMachStateCaptureState, _TEXT
154154

155-
// void SinglecastDelegateInvokeStub(Delegate *pThis)
156-
LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT
157-
cmp r0, #0
158-
beq LOCAL_LABEL(LNullThis)
159-
160-
ldr r12, [r0, #DelegateObject___methodPtr]
161-
ldr r0, [r0, #DelegateObject___target]
162-
163-
bx r12
164-
165-
LOCAL_LABEL(LNullThis):
166-
mov r0, #CORINFO_NullReferenceException_ASM
167-
b C_FUNC(JIT_InternalThrow)
168-
169-
LEAF_END SinglecastDelegateInvokeStub, _TEXT
170-
171155
//
172156
// r12 = UMEntryThunk*
173157
//

0 commit comments

Comments
 (0)