Skip to content

Commit

Permalink
Replace HELPER_METHOD_FRAME with DynamicHelperFrame in patchpoints (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
3 people authored Feb 5, 2025
1 parent c9af66c commit 5148d9a
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 332 deletions.
19 changes: 19 additions & 0 deletions src/coreclr/vm/amd64/AsmHelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,25 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT
TAILJMP_RAX
NESTED_END OnCallCountThresholdReachedStub, _TEXT

extern JIT_PatchpointWorkerWorkerWithPolicy:proc

NESTED_ENTRY JIT_Patchpoint, _TEXT
PROLOG_WITH_TRANSITION_BLOCK

lea rcx, [rsp + __PWTB_TransitionBlock] ; TransitionBlock *
call JIT_PatchpointWorkerWorkerWithPolicy

EPILOG_WITH_TRANSITION_BLOCK_RETURN
TAILJMP_RAX
NESTED_END JIT_Patchpoint, _TEXT

; first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
mov rdx, rcx
xor rcx, rcx
jmp JIT_Patchpoint
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT

endif ; FEATURE_TIERED_COMPILATION

LEAF_ENTRY JIT_PollGC, _TEXT
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/vm/amd64/unixasmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,20 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
TAILJMP_RAX
NESTED_END OnCallCountThresholdReachedStub, _TEXT

NESTED_ENTRY JIT_Patchpoint, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK

lea rdi, [rsp + __PWTB_TransitionBlock] // TransitionBlock *
call C_FUNC(JIT_PatchpointWorkerWorkerWithPolicy)

EPILOG_WITH_TRANSITION_BLOCK_RETURN
NESTED_END JIT_Patchpoint, _TEXT

// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
mov rsi, rdi
xor rdi, rdi
jmp C_FUNC(JIT_Patchpoint)
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT

#endif // FEATURE_TIERED_COMPILATION
16 changes: 16 additions & 0 deletions src/coreclr/vm/arm64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,22 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
EPILOG_BRANCH_REG x9
NESTED_END OnCallCountThresholdReachedStub, _TEXT

NESTED_ENTRY JIT_Patchpoint, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK

add x0, sp, #__PWTB_TransitionBlock // TransitionBlock *
bl C_FUNC(JIT_PatchpointWorkerWorkerWithPolicy)

EPILOG_WITH_TRANSITION_BLOCK_RETURN
NESTED_END JIT_Patchpoint, _TEXT

// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
LEAF_ENTRY JIT_PartialCompilationPatchpoint, _TEXT
mov x1, x0
mov x0, #0
b C_FUNC(JIT_Patchpoint)
LEAF_END JIT_PartialCompilationPatchpoint, _TEXT

#endif // FEATURE_TIERED_COMPILATION

LEAF_ENTRY JIT_ValidateIndirectCall, _TEXT
Expand Down
18 changes: 18 additions & 0 deletions src/coreclr/vm/arm64/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,24 @@ __HelperNakedFuncName SETS "$helper":CC:"Naked"
EPILOG_BRANCH_REG x9
NESTED_END

IMPORT JIT_PatchpointWorkerWorkerWithPolicy

NESTED_ENTRY JIT_Patchpoint
PROLOG_WITH_TRANSITION_BLOCK

add x0, sp, #__PWTB_TransitionBlock ; TransitionBlock *
bl JIT_PatchpointWorkerWorkerWithPolicy

EPILOG_WITH_TRANSITION_BLOCK_RETURN
NESTED_END

// first arg register holds iloffset, which needs to be moved to the second register, and the first register filled with NULL
LEAF_ENTRY JIT_PartialCompilationPatchpoint
mov x1, x0
mov x0, #0
b JIT_Patchpoint
LEAF_END

#endif ; FEATURE_TIERED_COMPILATION

LEAF_ENTRY JIT_ValidateIndirectCall
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/vm/callingconvention.h
Original file line number Diff line number Diff line change
Expand Up @@ -2209,4 +2209,28 @@ inline BOOL IsRetBuffPassedAsFirstArg()
#endif
}

inline TADDR GetFirstArgumentRegisterValuePtr(TransitionBlock * pTransitionBlock)
{
TADDR pArgument = (TADDR)pTransitionBlock + TransitionBlock::GetOffsetOfArgumentRegisters();
#ifdef TARGET_X86
// x86 is special as always
pArgument += offsetof(ArgumentRegisters, ECX);
#endif

return pArgument;
}

inline TADDR GetSecondArgumentRegisterValuePtr(TransitionBlock * pTransitionBlock)
{
TADDR pArgument = (TADDR)pTransitionBlock + TransitionBlock::GetOffsetOfArgumentRegisters();
#ifdef TARGET_X86
// x86 is special as always
pArgument += offsetof(ArgumentRegisters, EDX);
#else
pArgument += sizeof(TADDR);
#endif

return pArgument;
}

#endif // __CALLING_CONVENTION_INCLUDED
8 changes: 4 additions & 4 deletions src/coreclr/vm/codeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ class EECodeInfo

TADDR GetSavedMethodCode();

TADDR GetStartAddress();
TADDR GetStartAddress() const;

BOOL IsValid()
{
Expand Down Expand Up @@ -2505,15 +2505,15 @@ class EECodeInfo
}

// This returns a pointer to the start of an instruction; conceptually, a PINSTR.
TADDR GetCodeAddress()
TADDR GetCodeAddress() const
{
LIMITED_METHOD_DAC_CONTRACT;
return PCODEToPINSTR(m_codeAddress);
}

NativeCodeVersion GetNativeCodeVersion();
NativeCodeVersion GetNativeCodeVersion() const;

MethodDesc * GetMethodDesc()
MethodDesc * GetMethodDesc() const
{
LIMITED_METHOD_DAC_CONTRACT;
return m_pMD;
Expand Down
Loading

0 comments on commit 5148d9a

Please sign in to comment.