Skip to content

Commit 5148d9a

Browse files
davidwrightonjkotasAndyAyersMS
authored
Replace HELPER_METHOD_FRAME with DynamicHelperFrame in patchpoints (#112025)
- Consolidate the 2 functions so we only need 1 copy of the C++ code (JIT_Patchpoint and JIT_PartialCompilationPatchpoint are still separate entrypoints, but the real meat of the logic is now all in PatchpointWorkerWorkerWithPolicy) - Instead of using a managed function, I decided to use a transition frame to manage the case of calling into the runtime. In this case we are able to re-use the DynamicHelperFrame which appears to be sufficient. - Add asm helpers in the current architectures which support on stack replacement to setup the TransitionBlock and call into the common C++ code --------- Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: Andy Ayers <[email protected]>
1 parent c9af66c commit 5148d9a

File tree

12 files changed

+382
-332
lines changed

12 files changed

+382
-332
lines changed

src/coreclr/vm/amd64/AsmHelpers.asm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,25 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT
447447
TAILJMP_RAX
448448
NESTED_END OnCallCountThresholdReachedStub, _TEXT
449449

450+
extern JIT_PatchpointWorkerWorkerWithPolicy:proc
451+
452+
NESTED_ENTRY JIT_Patchpoint, _TEXT
453+
PROLOG_WITH_TRANSITION_BLOCK
454+
455+
lea rcx, [rsp + __PWTB_TransitionBlock] ; TransitionBlock *
456+
call JIT_PatchpointWorkerWorkerWithPolicy
457+
458+
EPILOG_WITH_TRANSITION_BLOCK_RETURN
459+
TAILJMP_RAX
460+
NESTED_END JIT_Patchpoint, _TEXT
461+
462+
; first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
463+
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
464+
mov rdx, rcx
465+
xor rcx, rcx
466+
jmp JIT_Patchpoint
467+
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT
468+
450469
endif ; FEATURE_TIERED_COMPILATION
451470

452471
LEAF_ENTRY JIT_PollGC, _TEXT

src/coreclr/vm/amd64/unixasmhelpers.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,20 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
195195
TAILJMP_RAX
196196
NESTED_END OnCallCountThresholdReachedStub, _TEXT
197197

198+
NESTED_ENTRY JIT_Patchpoint, _TEXT, NoHandler
199+
PROLOG_WITH_TRANSITION_BLOCK
200+
201+
lea rdi, [rsp + __PWTB_TransitionBlock] // TransitionBlock *
202+
call C_FUNC(JIT_PatchpointWorkerWorkerWithPolicy)
203+
204+
EPILOG_WITH_TRANSITION_BLOCK_RETURN
205+
NESTED_END JIT_Patchpoint, _TEXT
206+
207+
// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
208+
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
209+
mov rsi, rdi
210+
xor rdi, rdi
211+
jmp C_FUNC(JIT_Patchpoint)
212+
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT
213+
198214
#endif // FEATURE_TIERED_COMPILATION

src/coreclr/vm/arm64/asmhelpers.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,22 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
747747
EPILOG_BRANCH_REG x9
748748
NESTED_END OnCallCountThresholdReachedStub, _TEXT
749749

750+
NESTED_ENTRY JIT_Patchpoint, _TEXT, NoHandler
751+
PROLOG_WITH_TRANSITION_BLOCK
752+
753+
add x0, sp, #__PWTB_TransitionBlock // TransitionBlock *
754+
bl C_FUNC(JIT_PatchpointWorkerWorkerWithPolicy)
755+
756+
EPILOG_WITH_TRANSITION_BLOCK_RETURN
757+
NESTED_END JIT_Patchpoint, _TEXT
758+
759+
// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
760+
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
761+
mov x1, x0
762+
mov x0, #0
763+
b C_FUNC(JIT_Patchpoint)
764+
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT
765+
750766
#endif // FEATURE_TIERED_COMPILATION
751767

752768
LEAF_ENTRY JIT_ValidateIndirectCall, _TEXT

src/coreclr/vm/arm64/asmhelpers.asm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,24 @@ __HelperNakedFuncName SETS "$helper":CC:"Naked"
11391139
EPILOG_BRANCH_REG x9
11401140
NESTED_END
11411141

1142+
IMPORT JIT_PatchpointWorkerWorkerWithPolicy
1143+
1144+
NESTED_ENTRY JIT_Patchpoint
1145+
PROLOG_WITH_TRANSITION_BLOCK
1146+
1147+
add x0, sp, #__PWTB_TransitionBlock ; TransitionBlock *
1148+
bl JIT_PatchpointWorkerWorkerWithPolicy
1149+
1150+
EPILOG_WITH_TRANSITION_BLOCK_RETURN
1151+
NESTED_END
1152+
1153+
// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
1154+
LEAF_ENTRY JIT_PartialCompilationPatchpoint
1155+
mov x1, x0
1156+
mov x0, #0
1157+
b JIT_Patchpoint
1158+
LEAF_END
1159+
11421160
#endif ; FEATURE_TIERED_COMPILATION
11431161

11441162
LEAF_ENTRY JIT_ValidateIndirectCall

src/coreclr/vm/callingconvention.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,4 +2209,28 @@ inline BOOL IsRetBuffPassedAsFirstArg()
22092209
#endif
22102210
}
22112211

2212+
inline TADDR GetFirstArgumentRegisterValuePtr(TransitionBlock * pTransitionBlock)
2213+
{
2214+
TADDR pArgument = (TADDR)pTransitionBlock + TransitionBlock::GetOffsetOfArgumentRegisters();
2215+
#ifdef TARGET_X86
2216+
// x86 is special as always
2217+
pArgument += offsetof(ArgumentRegisters, ECX);
2218+
#endif
2219+
2220+
return pArgument;
2221+
}
2222+
2223+
inline TADDR GetSecondArgumentRegisterValuePtr(TransitionBlock * pTransitionBlock)
2224+
{
2225+
TADDR pArgument = (TADDR)pTransitionBlock + TransitionBlock::GetOffsetOfArgumentRegisters();
2226+
#ifdef TARGET_X86
2227+
// x86 is special as always
2228+
pArgument += offsetof(ArgumentRegisters, EDX);
2229+
#else
2230+
pArgument += sizeof(TADDR);
2231+
#endif
2232+
2233+
return pArgument;
2234+
}
2235+
22122236
#endif // __CALLING_CONVENTION_INCLUDED

src/coreclr/vm/codeman.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ class EECodeInfo
24772477

24782478
TADDR GetSavedMethodCode();
24792479

2480-
TADDR GetStartAddress();
2480+
TADDR GetStartAddress() const;
24812481

24822482
BOOL IsValid()
24832483
{
@@ -2505,15 +2505,15 @@ class EECodeInfo
25052505
}
25062506

25072507
// This returns a pointer to the start of an instruction; conceptually, a PINSTR.
2508-
TADDR GetCodeAddress()
2508+
TADDR GetCodeAddress() const
25092509
{
25102510
LIMITED_METHOD_DAC_CONTRACT;
25112511
return PCODEToPINSTR(m_codeAddress);
25122512
}
25132513

2514-
NativeCodeVersion GetNativeCodeVersion();
2514+
NativeCodeVersion GetNativeCodeVersion() const;
25152515

2516-
MethodDesc * GetMethodDesc()
2516+
MethodDesc * GetMethodDesc() const
25172517
{
25182518
LIMITED_METHOD_DAC_CONTRACT;
25192519
return m_pMD;

0 commit comments

Comments
 (0)