Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/coreclr/inc/corhdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ typedef enum CorCallingConvention
IMAGE_CEE_CS_CALLCONV_UNMANAGED = 0x9, // Unmanaged calling convention encoded as modopts
IMAGE_CEE_CS_CALLCONV_GENERICINST = 0xa, // generic method instantiation
IMAGE_CEE_CS_CALLCONV_NATIVEVARARG = 0xb, // used ONLY for 64bit vararg PInvoke calls
IMAGE_CEE_CS_CALLCONV_MAX = 0xc, // first invalid calling convention
IMAGE_CEE_CS_CALLCONV_ASYNC = 0xc, // used for calli in IL stubs
IMAGE_CEE_CS_CALLCONV_MAX = 0xd, // first invalid calling convention


// The high bits of the calling convention convey additional info
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ var_types Compiler::impImportCall(OPCODE opcode,
JITDUMP(" Continuation continues on thread pool\n");
}
}
else if (opcode == CEE_CALLI)
{
// Used for unboxing/instantiating stubs
JITDUMP("Call is an async calli\n");
}
else
{
JITDUMP("Call is an async non-task await\n");
Expand Down Expand Up @@ -941,7 +946,9 @@ var_types Compiler::impImportCall(OPCODE opcode,
.WellKnown(WellKnownArg::VarArgsCookie));
}

if (call->AsCall()->IsAsync())
// Add async continuation arg. For calli these are used for IL
// stubs and the VM inserts the arg itself.
if (call->AsCall()->IsAsync() && (opcode != CEE_CALLI))
{
call->AsCall()->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewNull(), TYP_REF)
.WellKnown(WellKnownArg::AsyncContinuation));
Expand All @@ -955,7 +962,9 @@ var_types Compiler::impImportCall(OPCODE opcode,
}
else
{
if (call->AsCall()->IsAsync())
// Add async continuation arg. For calli these are used for IL
// stubs and the VM inserts the arg itself.
if (call->AsCall()->IsAsync() && (opcode != CEE_CALLI))
{
call->AsCall()->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewNull(), TYP_REF)
.WellKnown(WellKnownArg::AsyncContinuation));
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/callingconvention.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ class ArgIteratorTemplate : public ARGITERATOR_BASE
// explicit arguments have been scanned is platform dependent.
void GetThisLoc(ArgLocDesc * pLoc) { WRAPPER_NO_CONTRACT; GetSimpleLoc(GetThisOffset(), pLoc); }
void GetParamTypeLoc(ArgLocDesc * pLoc) { WRAPPER_NO_CONTRACT; GetSimpleLoc(GetParamTypeArgOffset(), pLoc); }
void GetAsyncContinuationLoc(ArgLocDesc * pLoc) { WRAPPER_NO_CONTRACT; GetSimpleLoc(GetAsyncContinuationArgOffset(), pLoc); }
void GetVASigCookieLoc(ArgLocDesc * pLoc) { WRAPPER_NO_CONTRACT; GetSimpleLoc(GetVASigCookieOffset(), pLoc); }

#ifndef CALLDESCR_RETBUFFARGREG
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@ BOOL GenerateShuffleArrayPortable(MethodDesc* pMethodSrc, MethodDesc *pMethodDst
#endif // !defined(TARGET_ARM64) || !defined(CALLDESCR_RETBUFFARGREG)
}

// Handle async continuation argument.
_ASSERTE(!!sArgPlacerDst.HasAsyncContinuation() == !!sArgPlacerSrc.HasAsyncContinuation());
if (sArgPlacerDst.HasAsyncContinuation())
{
// The async continuation is implicit in both signatures.
sArgPlacerSrc.GetAsyncContinuationLoc(&sArgSrc);
sArgPlacerDst.GetAsyncContinuationLoc(&sArgDst);

if (!AddNextShuffleEntryToArray(sArgSrc, sArgDst, pShuffleEntryArray, shuffleType))
return FALSE;
}

// Iterate all the regular arguments. mapping source registers and stack locations to the corresponding
// destination locations.
while ((ofsSrc = sArgPlacerSrc.GetNextOffset()) != TransitionBlock::InvalidOffset)
Expand Down
17 changes: 13 additions & 4 deletions src/coreclr/vm/ilstubcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void CreateModuleIndependentSignature(LoaderHeap* pCreationHeap,
// static
MethodDesc* ILStubCache::CreateAndLinkNewILStubMethodDesc(LoaderAllocator* pAllocator, MethodTable* pMT, DWORD dwStubFlags,
Module* pSigModule, PCCOR_SIGNATURE pSig, DWORD cbSig, SigTypeContext *pTypeContext,
ILStubLinker* pStubLinker)
ILStubLinker* pStubLinker, BOOL isAsync /* = FALSE */)
{
CONTRACT (MethodDesc*)
{
Expand All @@ -86,6 +86,7 @@ MethodDesc* ILStubCache::CreateAndLinkNewILStubMethodDesc(LoaderAllocator* pAllo
dwStubFlags,
pSigModule,
pSig, cbSig,
isAsync,
pTypeContext,
&amTracker);

Expand Down Expand Up @@ -143,7 +144,7 @@ namespace

// static
MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTable* pMT, DWORD dwStubFlags,
Module* pSigModule, PCCOR_SIGNATURE pSig, DWORD cbSig, SigTypeContext *pTypeContext,
Module* pSigModule, PCCOR_SIGNATURE pSig, DWORD cbSig, BOOL isAsync, SigTypeContext *pTypeContext,
AllocMemTracker* pamTracker)
{
CONTRACT (MethodDesc*)
Expand All @@ -160,7 +161,7 @@ MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTa
mcDynamic,
TRUE /* fNonVtableSlot */,
TRUE /* fNativeCodeSlot */,
FALSE /* HasAsyncMethodData */,
isAsync /* HasAsyncMethodData */,
pMT,
pamTracker);

Expand All @@ -175,6 +176,13 @@ MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTa
pMD->InitializeFlags(DynamicMethodDesc::FlagPublic | DynamicMethodDesc::FlagIsILStub);
pMD->SetTemporaryEntryPoint(pamTracker);

if (isAsync)
{
pMD->SetHasAsyncMethodData();
// Async stubs are standalone methods that do not form async/task-returning variant pairs.
pMD->GetAddrOfAsyncMethodData()->kind = AsyncMethodKind::AsyncExplicitImpl;
}

//
// convert signature to a compatible signature if needed
//
Expand Down Expand Up @@ -531,7 +539,8 @@ MethodDesc* ILStubCache::GetStubMethodDesc(
}

MethodTable *pStubMT = GetOrCreateStubMethodTable(pSigLoaderModule);
pMD = ILStubCache::CreateNewMethodDesc(m_pAllocator->GetHighFrequencyHeap(), pStubMT, dwStubFlags, pSigModule, pSig, cbSig, pTypeContext, pamTracker);
BOOL isAsync = pTargetMD == NULL ? FALSE: pTargetMD->IsAsyncMethod();
pMD = ILStubCache::CreateNewMethodDesc(m_pAllocator->GetHighFrequencyHeap(), pStubMT, dwStubFlags, pSigModule, pSig, cbSig, isAsync, pTypeContext, pamTracker);

if (SF_IsSharedStub(dwStubFlags))
{
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/vm/ilstubcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class ILStubCache final
PCCOR_SIGNATURE pSig,
DWORD cbSig,
SigTypeContext *pTypeContext,
ILStubLinker* pStubLinker);
ILStubLinker* pStubLinker,
BOOL isAsync = FALSE);

MethodTable * GetStubMethodTable()
{
Expand All @@ -97,6 +98,7 @@ class ILStubCache final
Module* pSigModule,
PCCOR_SIGNATURE pSig,
DWORD cbSig,
BOOL isAsync,
SigTypeContext *pTypeContext,
AllocMemTracker* pamTracker);

Expand Down
16 changes: 11 additions & 5 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,26 @@ static void ConvToJitSig(

uint32_t data;
IfFailThrow(sig.GetCallingConvInfo(&data));
sigRet->callConv = (CorInfoCallConv) data;

#if defined(TARGET_UNIX) || defined(TARGET_ARM)
if ((isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_VARARG)) ||
(isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_NATIVEVARARG)))
if ((isCallConv(data, IMAGE_CEE_CS_CALLCONV_VARARG)) ||
(isCallConv(data, IMAGE_CEE_CS_CALLCONV_NATIVEVARARG)))
{
// This signature corresponds to a method that uses varargs, which are not supported.
COMPlusThrow(kInvalidProgramException, IDS_EE_VARARG_NOT_SUPPORTED);
}
#endif // defined(TARGET_UNIX) || defined(TARGET_ARM)

// We have an internal calling convention for async used for signatures
// in IL stubs. Translate that to the flag representation in
// CorInfoCallConv.
if (isCallConv(data, IMAGE_CEE_CS_CALLCONV_ASYNC))
sigRet->callConv = (CorInfoCallConv)(CORINFO_CALLCONV_DEFAULT | CORINFO_CALLCONV_ASYNCCALL | (data & ~IMAGE_CEE_CS_CALLCONV_MASK));
else
sigRet->callConv = (CorInfoCallConv) data;

// Skip number of type arguments
if (sigRet->callConv & IMAGE_CEE_CS_CALLCONV_GENERIC)
if (data & IMAGE_CEE_CS_CALLCONV_GENERIC)
IfFailThrow(sig.GetData(NULL));

uint32_t numArgs;
Expand Down Expand Up @@ -1796,7 +1803,6 @@ CEEInfo::findSig(
if (IsDynamicScope(scopeHnd))
{
sig = GetDynamicResolver(scopeHnd)->ResolveSignature(sigTok);
sigTok = mdTokenNil;
}
else
{
Expand Down
56 changes: 38 additions & 18 deletions src/coreclr/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,16 +1394,18 @@ PrepareCodeConfigBuffer::PrepareCodeConfigBuffer(NativeCodeVersion codeVersion)

// CreateDerivedTargetSigWithExtraParams:
// This method is used to create the signature of the target of the ILStub for
// instantiating, unboxing, and async variant stubs, when/where we need to
// introduce a generic context/async continuation.
// And since the generic context/async continuations are hidden parameters,
// instantiating and unboxing stubs, when/where we need to
// introduce a generic context.
// And since the generic contexts are hidden parameters,
// we're creating a signature that looks like non-generic but with additional
// parameters right after the thisptr
void MethodDesc::CreateDerivedTargetSigWithExtraParams(MetaSig& msig, SigBuilder *stubSigBuilder)
{
STANDARD_VM_CONTRACT;

BYTE callingConvention = IMAGE_CEE_CS_CALLCONV_DEFAULT;
if (msig.HasAsyncContinuation())
callingConvention = IMAGE_CEE_CS_CALLCONV_ASYNC;
if (msig.HasThis())
callingConvention |= IMAGE_CEE_CS_CALLCONV_HASTHIS;
// CallingConvention
Expand Down Expand Up @@ -1475,9 +1477,6 @@ Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetM

_ASSERTE(msig.HasThis());

// TODO: (async) instantiating/unboxing stubs https://github.com/dotnet/runtime/issues/117266
_ASSERTE(!msig.HasAsyncContinuation());

ILStubLinker sl(pTargetMD->GetModule(),
pTargetMD->GetSignature(),
&typeContext,
Expand All @@ -1499,12 +1498,17 @@ Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetM
pCode->EmitLoadThis();
pCode->EmitLDFLDA(tokRawData);

#if defined(TARGET_X86)
#ifdef TARGET_X86
// Push the rest of the arguments for x86
for (unsigned i = 0; i < msig.NumFixedArgs();i++)
{
pCode->EmitLDARG(i);
}

if (msig.HasAsyncContinuation())
{
pCode->EmitLDNULL();
}
#endif

// Push the hidden context param
Expand All @@ -1515,7 +1519,12 @@ Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetM
pCode->EmitSUB();
pCode->EmitLDIND_I();

#if !defined(TARGET_X86)
#ifndef TARGET_X86
if (msig.HasAsyncContinuation())
{
pCode->EmitLDNULL();
}

// Push the rest of the arguments for not x86
for (unsigned i = 0; i < msig.NumFixedArgs();i++)
{
Expand All @@ -1540,7 +1549,8 @@ Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetM
pTargetMD->GetModule(),
pSig, cbSig,
&typeContext,
&sl);
&sl,
pTargetMD->IsAsyncMethod());

ILStubResolver *pResolver = pStubMD->AsDynamicMethodDesc()->GetILStubResolver();

Expand Down Expand Up @@ -1593,9 +1603,6 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)

ILCodeStream *pCode = sl.NewCodeStream(ILStubLinker::kDispatch);

// TODO: (async) instantiating/unboxing stubs https://github.com/dotnet/runtime/issues/117266
_ASSERTE(!msig.HasAsyncContinuation());

// Build the new signature
SigBuilder stubSigBuilder;
MethodDesc::CreateDerivedTargetSigWithExtraParams(msig, &stubSigBuilder);
Expand All @@ -1607,25 +1614,37 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
pCode->EmitLoadThis();
}

#if defined(TARGET_X86)
#ifdef TARGET_X86
// Push the rest of the arguments for x86
for (unsigned i = 0; i < msig.NumFixedArgs();i++)
{
pCode->EmitLDARG(i);
}
#endif // TARGET_X86

if (msig.HasAsyncContinuation())
{
pCode->EmitLDNULL();
}

// Push the hidden context param
// InstantiatingStub
pCode->EmitLDC((TADDR)pHiddenArg);
#else
// Push the hidden context param
// InstantiatingStub
pCode->EmitLDC((TADDR)pHiddenArg);

#if !defined(TARGET_X86)
// Push the rest of the arguments for not x86
if (msig.HasAsyncContinuation())
{
pCode->EmitLDNULL();
}

// Push the rest of the arguments for x86
for (unsigned i = 0; i < msig.NumFixedArgs();i++)
{
pCode->EmitLDARG(i);
}
#endif // !TARGET_X86
#endif

// Push the target address
pCode->EmitLDC((TADDR)pTargetMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY));
Expand All @@ -1644,7 +1663,8 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
pTargetMD->GetModule(),
pSig, cbSig,
&typeContext,
&sl);
&sl,
pTargetMD->IsAsyncMethod());

ILStubResolver *pResolver = pStubMD->AsDynamicMethodDesc()->GetILStubResolver();

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/siginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void SigPointer::ConvertToInternalExactlyOne(Module* pSigModule, const SigTypeCo
{
mdToken tk;
IfFailThrowBF(GetToken(&tk), BFA_BAD_COMPLUS_SIG, pSigModule);
TypeHandle th = ClassLoader::LoadTypeDefOrRefThrowing(pSigModule, tk);
TypeHandle th = ClassLoader::LoadTypeDefOrRefThrowing(pSigModule, tk, ClassLoader::ThrowIfNotFound, ClassLoader::PermitUninstDefOrRef);
pSigBuilder->AppendElementType(ELEMENT_TYPE_CMOD_INTERNAL);
pSigBuilder->AppendByte(typ == ELEMENT_TYPE_CMOD_REQD); // "is required" byte
pSigBuilder->AppendPointer(th.AsPtr());
Expand Down
Loading
Loading