Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion src/coreclr/clrdefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if(CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)
add_compile_definitions(OUT_OF_PROCESS_SETTHREADCONTEXT)
endif(CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)

if(NOT CLR_CMAKE_TARGET_ARCH_I386)
if(NOT CLR_CMAKE_TARGET_ARCH_I386 AND NOT FEATURE_PORTABLE_ENTRYPOINTS)
add_definitions(-DFEATURE_PORTABLE_SHUFFLE_THUNKS)
endif()

Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ BOOL GenerateShuffleArrayPortable(MethodDesc* pMethodSrc, MethodDesc *pMethodDst
}
#endif // FEATURE_PORTABLE_SHUFFLE_THUNKS

#ifndef FEATURE_PORTABLE_ENTRYPOINTS
BOOL GenerateShuffleArray(MethodDesc* pInvoke, MethodDesc *pTargetMeth, SArray<ShuffleEntry> * pShuffleEntryArray)
{
STANDARD_VM_CONTRACT;
Expand Down Expand Up @@ -773,8 +774,8 @@ BOOL GenerateShuffleArray(MethodDesc* pInvoke, MethodDesc *pTargetMeth, SArray<S
}
return TRUE;
}

static ShuffleThunkCache* s_pShuffleThunkCache = NULL;
#endif // !FEATURE_PORTABLE_ENTRYPOINTS

// One time init.
void COMDelegate::Init()
Expand All @@ -786,8 +787,9 @@ void COMDelegate::Init()
MODE_ANY;
}
CONTRACTL_END;

#ifndef FEATURE_PORTABLE_ENTRYPOINTS
s_pShuffleThunkCache = new ShuffleThunkCache(SystemDomain::GetGlobalLoaderAllocator()->GetStubHeap());
#endif
}

#ifdef FEATURE_COMINTEROP
Expand Down Expand Up @@ -913,6 +915,7 @@ static PCODE SetupShuffleThunk(MethodTable * pDelMT, MethodDesc *pTargetMeth)

MethodDesc *pMD = pClass->GetInvokeMethod();

#ifndef FEATURE_PORTABLE_ENTRYPOINTS
// We haven't already setup a shuffle thunk, go do it now (which will cache the result automatically).
StackSArray<ShuffleEntry> rShuffleEntryArray;
if (GenerateShuffleArray(pMD, pTargetMeth, &rShuffleEntryArray))
Expand All @@ -928,6 +931,7 @@ static PCODE SetupShuffleThunk(MethodTable * pDelMT, MethodDesc *pTargetMeth)
pShuffleThunk = pShuffleThunkCache->Canonicalize((const BYTE *)&rShuffleEntryArray[0], "DelegateShuffleThunk");
}
else
#endif // !FEATURE_PORTABLE_ENTRYPOINTS
{
#if defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
pShuffleThunk = CreateILDelegateShuffleThunk(pMD, isInstRetBuff);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/comdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ class ShuffleThunkCache : public StubCacheBase
{
STANDARD_VM_CONTRACT;

#ifndef FEATURE_PORTABLE_ENTRYPOINTS
((CPUSTUBLINKER*)pstublinker)->EmitShuffleThunk((ShuffleEntry*)pRawStub);
#else
PORTABILITY_ASSERT("Shuffle thunks are not supported with portable entrypoints");
#endif // !FEATURE_PORTABLE_ENTRYPOINTS
return NEWSTUB_FL_SHUFFLE_THUNK;
}

Expand Down
36 changes: 26 additions & 10 deletions src/coreclr/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ void MethodDesc::CreateDerivedTargetSigWithExtraParams(MetaSig& msig, SigBuilder

#ifdef FEATURE_INSTANTIATINGSTUB_AS_IL

Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetMD)
Stub * CreateUnboxingILStubForValueTypeMethods(MethodDesc* pTargetMD)
{

CONTRACT(Stub*)
Expand Down Expand Up @@ -1510,13 +1510,16 @@ Stub * CreateUnboxingILStubForSharedGenericValueTypeMethods(MethodDesc* pTargetM
}
#endif

// Push the hidden context param
// The context is going to be captured from the thisptr
pCode->EmitLoadThis();
pCode->EmitLDFLDA(tokRawData);
pCode->EmitLDC(Object::GetOffsetOfFirstField());
pCode->EmitSUB();
pCode->EmitLDIND_I();
if (pTargetMD->RequiresInstMethodTableArg())
{
// Push the hidden context param
// The context is going to be captured from the thisptr
pCode->EmitLoadThis();
pCode->EmitLDFLDA(tokRawData);
pCode->EmitLDC(Object::GetOffsetOfFirstField());
pCode->EmitSUB();
pCode->EmitLDIND_I();
}

#ifndef TARGET_X86
if (msig.HasAsyncContinuation())
Expand Down Expand Up @@ -1727,13 +1730,16 @@ Stub * MakeUnboxingStubWorker(MethodDesc *pMD)
else
#endif
{
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
pstub = CreateUnboxingILStubForValueTypeMethods(pUnboxedMD);
#else // !FEATURE_PORTABLE_ENTRYPOINTS
#ifdef FEATURE_INSTANTIATINGSTUB_AS_IL
#ifndef FEATURE_PORTABLE_SHUFFLE_THUNKS
if (pUnboxedMD->RequiresInstMethodTableArg())
#endif // !FEATURE_PORTABLE_SHUFFLE_THUNKS
{
_ASSERTE(pUnboxedMD->RequiresInstMethodTableArg());
pstub = CreateUnboxingILStubForSharedGenericValueTypeMethods(pUnboxedMD);
pstub = CreateUnboxingILStubForValueTypeMethods(pUnboxedMD);
}
#ifndef FEATURE_PORTABLE_SHUFFLE_THUNKS
else
Expand All @@ -1746,6 +1752,7 @@ Stub * MakeUnboxingStubWorker(MethodDesc *pMD)
pstub = sl.Link(pMD->GetLoaderAllocator()->GetStubHeap(), NEWSTUB_FL_NONE, "UnboxingStub");
}
#endif // !FEATURE_PORTABLE_SHUFFLE_THUNKS
#endif // FEATURE_PORTABLE_ENTRYPOINTS
}
RETURN pstub;
}
Expand Down Expand Up @@ -2377,6 +2384,15 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo
}
else
{
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
pCode = pStub->GetEntryPoint();
pStub->DecRef();

void* ilStubInterpData = PortableEntryPoint::GetInterpreterData(pCode);
_ASSERTE(ilStubInterpData != NULL);
SetInterpreterCode((InterpByteCodeStart*)ilStubInterpData);
SetCodeEntryPoint(pCode);
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#else
#else // FEATURE_PORTABLE_ENTRYPOINTS

if (!GetOrCreatePrecode()->SetTargetInterlocked(pStub->GetEntryPoint()))
{
if (pStub->HasExternalEntryPoint())
Expand All @@ -2396,12 +2412,12 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT, CallerGCMode callerGCMo
// need to free the Stub allocation now.
pStub->DecRef();
}
#endif // !FEATURE_PORTABLE_ENTRYPOINTS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif // !FEATURE_PORTABLE_ENTRYPOINTS
#endif // FEATURE_PORTABLE_ENTRYPOINTS

}

_ASSERTE(!IsPointingToPrestub());
_ASSERTE(HasStableEntryPoint());


pCode = DoBackpatch(pMT, pDispatchingMT, FALSE);

Return:
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/vm/wasm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ class StubLinkerCPU : public StubLinker
{
public:
static void Init() { /* no-op on wasm */ }
inline void EmitShuffleThunk(struct ShuffleEntry *pShuffleEntryArray) {
_ASSERTE("The EmitShuffleThunk is not implemented on wasm");
}
inline VOID EmitComputedInstantiatingMethodStub(MethodDesc* pSharedMD, struct ShuffleEntry *pShuffleEntryArray, void* extraArg) {
_ASSERTE("The EmitComputedInstantiatingMethodStub is not implemented on wasm");
}
};

//**********************************************************************
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/vm/wasm/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ namespace
*(int32_t*)pRet = (*fptr)(ARG_IND(0), ARG(1));
}

void CallFunc_I32_I32IND_I32_I32IND_I32_RetI32(PCODE pcode, int8_t *pArgs, int8_t *pRet)
{
int32_t (*fptr)(int32_t, int32_t, int32_t, int32_t, int32_t) = (int32_t (*)(int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
*(int32_t*)pRet = (*fptr)(ARG(0), ARG_IND(1), ARG(2), ARG_IND(3), ARG(4));
}

void CallFunc_I32IND_I32_I32_I32_I32_I32_RetI32(PCODE pcode, int8_t *pArgs, int8_t *pRet)
{
int32_t (*fptr)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t) = (int32_t (*)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
Expand Down Expand Up @@ -690,6 +696,16 @@ namespace
return (void*)&CallFunc_I32IND_I32_RetI32;
}
break;
case 5:
if (args[0] == ConvertType::ToI32 &&
args[1] == ConvertType::ToI32Indirect &&
args[2] == ConvertType::ToI32 &&
args[3] == ConvertType::ToI32Indirect &&
args[4] == ConvertType::ToI32)
{
return (void*)&CallFunc_I32_I32IND_I32_I32IND_I32_RetI32;
}
break;
case 6:
if (args[0] == ConvertType::ToI32Indirect &&
args[1] == ConvertType::ToI32 &&
Expand Down
Loading