Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 13 additions & 6 deletions src/coreclr/vm/interpexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ static CallStubHeader *UpdateCallStubForMethod(MethodDesc *pMD, PCODE target)
header->SetTarget(target);
}

if (pMD->SetCallStub(header))
if (pMD->SetCalliCookie(header))
{
amTracker.SuppressRelease();
}
else
{
// We have lost the race for generating the header, use the one that was generated by another thread
// and let the amTracker release the memory of the one we generated.
header = pMD->GetCallStub();
header = pMD->GetCalliCookie();
}

return header;
Expand Down Expand Up @@ -408,7 +408,7 @@ void InvokeManagedMethod(ManagedMethodParam* pParam)
PCODE target = pParam->target;
Object** pContinuationRet = pParam->pContinuationRet;

CallStubHeader *pHeader = pParam->pMD->GetCallStub();
CallStubHeader *pHeader = pParam->pMD->GetCalliCookie();
if (pHeader == NULL)
{
pHeader = UpdateCallStubForMethod(pMD, target == (PCODE)NULL ? pMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY) : target);
Comment thread
radekdoulik marked this conversation as resolved.
Expand Down Expand Up @@ -467,7 +467,7 @@ void InvokeDelegateInvokeMethod(DelegateInvokeMethodParam* pParam)
PCODE target = pParam->target;
Object** pContinuationRet = pParam->pContinuationRet;

CallStubHeader *stubHeaderTemplate = pMDDelegateInvoke->GetCallStub();
CallStubHeader *stubHeaderTemplate = pMDDelegateInvoke->GetCalliCookie();
if (stubHeaderTemplate == NULL)
{
stubHeaderTemplate = UpdateCallStubForMethod(pMDDelegateInvoke, (PCODE)pMDDelegateInvoke->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY));
Expand Down Expand Up @@ -3073,8 +3073,15 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
if (!PortableEntryPoint::HasNativeEntryPoint(calliFunctionPointer))
goto CALL_INTERP_METHOD;

MetaSig sig(targetMethod);
cookie = GetCookieForCalliSig(sig, NULL);
cookie = (void*)targetMethod->GetCalliCookie();
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
if (cookie == NULL)
{
MetaSig sig(targetMethod);
cookie = GetCookieForCalliSig(sig, NULL);
_ASSERTE(cookie != NULL);
targetMethod->SetCalliCookie((InterpreterCalliCookie)cookie);
Comment thread
jkotas marked this conversation as resolved.
Outdated
cookie = (void*)targetMethod->GetCalliCookie();
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
}
#endif // FEATURE_PORTABLE_ENTRYPOINTS
frameNeedsTailcallUpdate = false;
CalliStubParam param = { calliFunctionPointer, cookie, callArgsAddress, returnValueAddress, pInterpreterFrame->GetContinuationPtr() };
Expand Down
37 changes: 24 additions & 13 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11451,18 +11451,6 @@ LPVOID CInterpreterJitInfo::GetCookieForInterpreterCalliSig(CORINFO_SIG_INFO* sz
void* result = NULL;
JIT_TO_EE_TRANSITION();

Instantiation classInst = Instantiation((TypeHandle*) szMetaSig->sigInst.classInst, szMetaSig->sigInst.classInstCount);
Instantiation methodInst = Instantiation((TypeHandle*) szMetaSig->sigInst.methInst, szMetaSig->sigInst.methInstCount);
SigTypeContext typeContext = SigTypeContext(classInst, methodInst);
Module* mod = GetModule(szMetaSig->scope);

MetaSig sig(szMetaSig->pSig, szMetaSig->cbSig, mod, &typeContext);

if (szMetaSig->isAsyncCall())
sig.SetIsAsyncCall();

_ASSERTE(szMetaSig->isAsyncCall() == sig.IsAsyncCall());

// When compiling a calli inside an IL stub for a P/Invoke, pass the target
// P/Invoke MethodDesc so ComputeCallStub can detect the Swift calling convention.
MethodDesc* pContextMD = nullptr;
Expand All @@ -11472,9 +11460,32 @@ LPVOID CInterpreterJitInfo::GetCookieForInterpreterCalliSig(CORINFO_SIG_INFO* sz
if (pTargetMD != nullptr)
{
pContextMD = pTargetMD;
result = (void*)pTargetMD->GetCalliCookie();
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
}
}

if (result == NULL)
{
Instantiation classInst = Instantiation((TypeHandle*) szMetaSig->sigInst.classInst, szMetaSig->sigInst.classInstCount);
Instantiation methodInst = Instantiation((TypeHandle*) szMetaSig->sigInst.methInst, szMetaSig->sigInst.methInstCount);
SigTypeContext typeContext = SigTypeContext(classInst, methodInst);
Module* mod = GetModule(szMetaSig->scope);

MetaSig sig(szMetaSig->pSig, szMetaSig->cbSig, mod, &typeContext);

if (szMetaSig->isAsyncCall())
sig.SetIsAsyncCall();

_ASSERTE(szMetaSig->isAsyncCall() == sig.IsAsyncCall());

result = GetCookieForCalliSig(sig, pContextMD);

if (pContextMD != nullptr)
{
pContextMD->SetCalliCookie((InterpreterCalliCookie)result);
Comment thread
jkotas marked this conversation as resolved.
Outdated
result = (void*)pContextMD->GetCalliCookie();
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
}
}
result = GetCookieForCalliSig(sig, pContextMD);

EE_TO_JIT_TRANSITION();
return result;
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,26 @@ void MethodDesc::SetMethodDescOptimizationTier(NativeCodeVersion::OptimizationTi
#endif // FEATURE_CODE_VERSIONING

#ifdef FEATURE_INTERPRETER
// Set the call stub for the interpreter to JIT/AOT calls
// Returns true if the current call set the stub, false if it was already set
bool MethodDesc::SetCallStub(CallStubHeader *pHeader)
// Cache the calli cookie on the MethodDesc
// Returns true if the current call set the cookie, false if it was already set
bool MethodDesc::SetCalliCookie(InterpreterCalliCookie cookie)
{
STANDARD_VM_CONTRACT;

IfFailThrow(EnsureCodeDataExists(NULL));

_ASSERTE(m_codeData != NULL);
return InterlockedCompareExchangeT(&m_codeData->CallStub, pHeader, NULL) == NULL;
return InterlockedCompareExchangeT(&m_codeData->CalliCookie, (void*)cookie, (void*)NULL) == NULL;
}
Comment thread
radekdoulik marked this conversation as resolved.
Comment thread
radekdoulik marked this conversation as resolved.

CallStubHeader *MethodDesc::GetCallStub()
InterpreterCalliCookie MethodDesc::GetCalliCookie()
{
LIMITED_METHOD_CONTRACT;

PTR_MethodDescCodeData codeData = VolatileLoadWithoutBarrier(&m_codeData);
if (codeData == NULL)
return NULL;
return VolatileLoadWithoutBarrier(&codeData->CallStub);
return (InterpreterCalliCookie)NULL;
Comment thread
jkotas marked this conversation as resolved.
Outdated
return (InterpreterCalliCookie)VolatileLoadWithoutBarrier(&codeData->CalliCookie);
}
#endif // FEATURE_INTERPRETER

Expand Down
14 changes: 11 additions & 3 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ enum MethodDescFlags
};

// Used for storing additional items related to native code
#ifdef FEATURE_INTERPRETER
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
typedef void(*InterpreterCalliCookie)(PCODE, int8_t*, int8_t*);
#else
typedef CallStubHeader* InterpreterCalliCookie;
#endif // FEATURE_PORTABLE_ENTRYPOINTS
Comment thread
radekdoulik marked this conversation as resolved.
Comment thread
radekdoulik marked this conversation as resolved.
#endif // FEATURE_INTERPRETER

struct MethodDescCodeData final
{
#ifdef FEATURE_CODE_VERSIONING
Expand All @@ -260,7 +268,7 @@ struct MethodDescCodeData final
#endif // FEATURE_CODE_VERSIONING
PCODE TemporaryEntryPoint;
#ifdef FEATURE_INTERPRETER
CallStubHeader *CallStub;
void* CalliCookie;
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
#endif // FEATURE_INTERPRETER
};
using PTR_MethodDescCodeData = DPTR(MethodDescCodeData);
Expand Down Expand Up @@ -1981,8 +1989,8 @@ class MethodDesc
#endif //!DACCESS_COMPILE

#if defined(FEATURE_INTERPRETER) && !defined(DACCESS_COMPILE)
bool SetCallStub(CallStubHeader *pHeader);
CallStubHeader *GetCallStub();
bool SetCalliCookie(InterpreterCalliCookie cookie);
InterpreterCalliCookie GetCalliCookie();
#endif // FEATURE_INTERPRETER && !DACCESS_COMPILE

#ifdef FEATURE_CODE_VERSIONING
Expand Down
15 changes: 10 additions & 5 deletions src/coreclr/vm/wasm/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,17 @@ void* GetUnmanagedCallersOnlyThunk(MethodDesc* pMD)

void InvokeManagedMethod(ManagedMethodParam *pParam)
{
MetaSig sig(pParam->pMD);
void* cookie = GetCookieForCalliSig(sig, pParam->pMD);

_ASSERTE(cookie != NULL);
InterpreterCalliCookie cookie = pParam->pMD->GetCalliCookie();
if (cookie == NULL)
{
MetaSig sig(pParam->pMD);
Comment thread
radekdoulik marked this conversation as resolved.
cookie = (InterpreterCalliCookie)GetCookieForCalliSig(sig, pParam->pMD);
_ASSERTE(cookie != NULL);
pParam->pMD->SetCalliCookie(cookie);
Comment thread
radekdoulik marked this conversation as resolved.
cookie = pParam->pMD->GetCalliCookie();
Comment thread
radekdoulik marked this conversation as resolved.
}

CalliStubParam param = { pParam->target == NULL ? pParam->pMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY) : pParam->target, cookie, pParam->pArgs, pParam->pRet, pParam->pContinuationRet };
CalliStubParam param = { pParam->target == NULL ? pParam->pMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY) : pParam->target, (void*)cookie, pParam->pArgs, pParam->pRet, pParam->pContinuationRet };
Comment thread
radekdoulik marked this conversation as resolved.
Outdated
InvokeCalliStub(&param);
}

Expand Down
Loading