Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
new JitEE interface method: expandRawHandleIntrinsic (#12071)
Browse files Browse the repository at this point in the history
Create a new JitEE method expandRawHandleIntrinsic. Delete old isDelegateCreationAllowed and getAddrModuleDomainID.

Support CORINFO_INTRINSIC_GetRawHandle.
Change JITEEVersionIdentifier.
fix MEASURE_CLRAPI_CALLS: add resolveVirtualMethod and expandRawHandleIntrinsic there.
  • Loading branch information
Sergey Andreenko committed Jun 6, 2017
1 parent b688511 commit b23a11e
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 157 deletions.
9 changes: 4 additions & 5 deletions src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ CORINFO_METHOD_HANDLE resolveVirtualMethod(CORINFO_METHOD_HANDLE virtualMethod,
CORINFO_CLASS_HANDLE implementingClass,
CORINFO_CONTEXT_HANDLE ownerType);

void expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult);

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
// *pMustExpand tells whether or not JIT must expand the intrinsic.
Expand Down Expand Up @@ -150,9 +154,6 @@ BOOL isCompatibleDelegate(CORINFO_CLASS_HANDLE objCls, /* type of the
BOOL* pfIsOpenDelegate /* is the delegate open */
);

// Determines whether the delegate creation obeys security transparency rules
BOOL isDelegateCreationAllowed(CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd);

// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
CorInfoInstantiationVerification isInstantiationOfVerifiedGeneric(CORINFO_METHOD_HANDLE method /* IN */
Expand Down Expand Up @@ -720,8 +721,6 @@ const void* getInlinedCallFrameVptr(void** ppIndirection = NULL);

LONG* getAddrOfCaptureThreadGlobal(void** ppIndirection = NULL);

SIZE_T* getAddrModuleDomainID(CORINFO_MODULE_HANDLE module);

// return the native entry point to an EE helper (see CorInfoHelpFunc)
void* getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection = NULL);

Expand Down
23 changes: 8 additions & 15 deletions src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::resolveVirtualMethod(CORINFO_METHOD_HAND
return result;
}

void interceptor_ICJI::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
{
mc->cr->AddCall("expandRawHandleIntrinsic");
original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult);
}

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
CorInfoIntrinsics interceptor_ICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */
Expand Down Expand Up @@ -303,15 +311,6 @@ BOOL interceptor_ICJI::isCompatibleDelegate(
return temp;
}

// Determines whether the delegate creation obeys security transparency rules
BOOL interceptor_ICJI::isDelegateCreationAllowed(CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd)
{
mc->cr->AddCall("isDelegateCreationAllowed");
BOOL temp = original_ICorJitInfo->isDelegateCreationAllowed(delegateHnd, calleeHnd);
mc->recIsDelegateCreationAllowed(delegateHnd, calleeHnd, temp);
return temp;
}

// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
CorInfoInstantiationVerification interceptor_ICJI::isInstantiationOfVerifiedGeneric(CORINFO_METHOD_HANDLE method /* IN
Expand Down Expand Up @@ -1428,12 +1427,6 @@ LONG* interceptor_ICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection)
return temp;
}

SIZE_T* interceptor_ICJI::getAddrModuleDomainID(CORINFO_MODULE_HANDLE module)
{
mc->cr->AddCall("getAddrModuleDomainID");
return original_ICorJitInfo->getAddrModuleDomainID(module);
}

// return the native entry point to an EE helper (see CorInfoHelpFunc)
void* interceptor_ICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection)
{
Expand Down
21 changes: 8 additions & 13 deletions src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::resolveVirtualMethod(CORINFO_METHOD_HAND
return original_ICorJitInfo->resolveVirtualMethod(virtualMethod, implementingClass, ownerType);
}

void interceptor_ICJI::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
{
mcs->AddCall("expandRawHandleIntrinsic");
original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult);
}

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
CorInfoIntrinsics interceptor_ICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */
Expand Down Expand Up @@ -217,13 +225,6 @@ BOOL interceptor_ICJI::isCompatibleDelegate(
return original_ICorJitInfo->isCompatibleDelegate(objCls, methodParentCls, method, delegateCls, pfIsOpenDelegate);
}

// Determines whether the delegate creation obeys security transparency rules
BOOL interceptor_ICJI::isDelegateCreationAllowed(CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd)
{
mcs->AddCall("isDelegateCreationAllowed");
return original_ICorJitInfo->isDelegateCreationAllowed(delegateHnd, calleeHnd);
}

// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
CorInfoInstantiationVerification interceptor_ICJI::isInstantiationOfVerifiedGeneric(CORINFO_METHOD_HANDLE method /* IN
Expand Down Expand Up @@ -1126,12 +1127,6 @@ LONG* interceptor_ICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection)
return original_ICorJitInfo->getAddrOfCaptureThreadGlobal(ppIndirection);
}

SIZE_T* interceptor_ICJI::getAddrModuleDomainID(CORINFO_MODULE_HANDLE module)
{
mcs->AddCall("getAddrModuleDomainID");
return original_ICorJitInfo->getAddrModuleDomainID(module);
}

// return the native entry point to an EE helper (see CorInfoHelpFunc)
void* interceptor_ICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection)
{
Expand Down
18 changes: 7 additions & 11 deletions src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ CORINFO_METHOD_HANDLE interceptor_ICJI::resolveVirtualMethod(CORINFO_METHOD_HAND
return original_ICorJitInfo->resolveVirtualMethod(virtualMethod, implementingClass, ownerType);
}

void interceptor_ICJI::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
{
return original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult);
}

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
CorInfoIntrinsics interceptor_ICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */
Expand Down Expand Up @@ -198,12 +205,6 @@ BOOL interceptor_ICJI::isCompatibleDelegate(
return original_ICorJitInfo->isCompatibleDelegate(objCls, methodParentCls, method, delegateCls, pfIsOpenDelegate);
}

// Determines whether the delegate creation obeys security transparency rules
BOOL interceptor_ICJI::isDelegateCreationAllowed(CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd)
{
return original_ICorJitInfo->isDelegateCreationAllowed(delegateHnd, calleeHnd);
}

// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
CorInfoInstantiationVerification interceptor_ICJI::isInstantiationOfVerifiedGeneric(CORINFO_METHOD_HANDLE method /* IN
Expand Down Expand Up @@ -1014,11 +1015,6 @@ LONG* interceptor_ICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection)
return original_ICorJitInfo->getAddrOfCaptureThreadGlobal(ppIndirection);
}

SIZE_T* interceptor_ICJI::getAddrModuleDomainID(CORINFO_MODULE_HANDLE module)
{
return original_ICorJitInfo->getAddrModuleDomainID(module);
}

// return the native entry point to an EE helper (see CorInfoHelpFunc)
void* interceptor_ICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection)
{
Expand Down
24 changes: 9 additions & 15 deletions src/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ CORINFO_METHOD_HANDLE MyICJI::resolveVirtualMethod(CORINFO_METHOD_HANDLE virtua
return result;
}

void MyICJI::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
{
jitInstance->mc->cr->AddCall("expandRawHandleIntrinsic");
LogError("Hit unimplemented expandRawHandleIntrinsic");
DebugBreakorAV(129);
}

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
CorInfoIntrinsics MyICJI::getIntrinsicID(CORINFO_METHOD_HANDLE method, bool* pMustExpand /* OUT */
Expand Down Expand Up @@ -238,13 +247,6 @@ BOOL MyICJI::isCompatibleDelegate(CORINFO_CLASS_HANDLE objCls, /* type
return jitInstance->mc->repIsCompatibleDelegate(objCls, methodParentCls, method, delegateCls, pfIsOpenDelegate);
}

// Determines whether the delegate creation obeys security transparency rules
BOOL MyICJI::isDelegateCreationAllowed(CORINFO_CLASS_HANDLE delegateHnd, CORINFO_METHOD_HANDLE calleeHnd)
{
jitInstance->mc->cr->AddCall("isDelegateCreationAllowed");
return jitInstance->mc->repIsDelegateCreationAllowed(delegateHnd, calleeHnd);
}

// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
CorInfoInstantiationVerification MyICJI::isInstantiationOfVerifiedGeneric(CORINFO_METHOD_HANDLE method /* IN */
Expand Down Expand Up @@ -1228,14 +1230,6 @@ LONG* MyICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection)
return jitInstance->mc->repGetAddrOfCaptureThreadGlobal(ppIndirection);
}

SIZE_T* MyICJI::getAddrModuleDomainID(CORINFO_MODULE_HANDLE module)
{
jitInstance->mc->cr->AddCall("getAddrModuleDomainID");
LogError("Hit unimplemented getAddrModuleDomainID");
DebugBreakorAV(88);
return 0;
}

// return the native entry point to an EE helper (see CorInfoHelpFunc)
void* MyICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection)
{
Expand Down
29 changes: 15 additions & 14 deletions src/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ TODO: Talk about initializing strutures before use
#define SELECTANY extern __declspec(selectany)
#endif

SELECTANY const GUID JITEEVersionIdentifier = { /* f00b3f49-ddd2-49be-ba43-6e49ffa66959 */
0xf00b3f49,
0xddd2,
0x49be,
{ 0xba, 0x43, 0x6e, 0x49, 0xff, 0xa6, 0x69, 0x59 }
SELECTANY const GUID JITEEVersionIdentifier = { /* e5708e9e-dd18-4287-8745-5d10ff2697cf */
0xe5708e9e,
0xdd18,
0x4287,
{ 0x87, 0x45, 0x5d, 0x10, 0xff, 0x26, 0x97, 0xcf }
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -960,6 +960,7 @@ enum CorInfoIntrinsics
CORINFO_INTRINSIC_ByReference_Value,
CORINFO_INTRINSIC_Span_GetItem,
CORINFO_INTRINSIC_ReadOnlySpan_GetItem,
CORINFO_INTRINSIC_GetRawHandle,

CORINFO_INTRINSIC_Count,
CORINFO_INTRINSIC_Illegal = -1, // Not a true intrinsic,
Expand Down Expand Up @@ -2075,6 +2076,15 @@ class ICorStaticInfo
CORINFO_CONTEXT_HANDLE ownerType = NULL /* IN */
) = 0;

// Given resolved token that corresponds to an intrinsic classified as
// a CORINFO_INTRINSIC_GetRawHandle intrinsic, fetch the handle associated
// with the token. If this is not possible at compile-time (because the current method's
// code is shared and the token contains generic parameters) then indicate
// how the handle should be looked up at runtime.
virtual void expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult) = 0;

// If a method's attributes have (getMethodAttribs) CORINFO_FLG_INTRINSIC set,
// getIntrinsicID() returns the intrinsic ID.
// *pMustExpand tells whether or not JIT must expand the intrinsic.
Expand Down Expand Up @@ -2119,13 +2129,6 @@ class ICorStaticInfo
BOOL *pfIsOpenDelegate /* is the delegate open */
) = 0;

// Determines whether the delegate creation obeys security transparency rules
virtual BOOL isDelegateCreationAllowed (
CORINFO_CLASS_HANDLE delegateHnd,
CORINFO_METHOD_HANDLE calleeHnd
) = 0;


// Indicates if the method is an instance of the generic
// method that passes (or has passed) verification
virtual CorInfoInstantiationVerification isInstantiationOfVerifiedGeneric (
Expand Down Expand Up @@ -2846,8 +2849,6 @@ class ICorDynamicInfo : public ICorStaticInfo
void **ppIndirection = NULL
) = 0;

virtual SIZE_T* getAddrModuleDomainID(CORINFO_MODULE_HANDLE module) = 0;

// return the native entry point to an EE helper (see CorInfoHelpFunc)
virtual void* getHelperFtn (
CorInfoHelpFunc ftnNum,
Expand Down
4 changes: 2 additions & 2 deletions src/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DEF_CLR_API(getUnmanagedCallConv)
DEF_CLR_API(pInvokeMarshalingRequired)
DEF_CLR_API(satisfiesMethodConstraints)
DEF_CLR_API(isCompatibleDelegate)
DEF_CLR_API(isDelegateCreationAllowed)
DEF_CLR_API(isInstantiationOfVerifiedGeneric)
DEF_CLR_API(initConstraintsForVerification)
DEF_CLR_API(canSkipMethodVerification)
Expand Down Expand Up @@ -113,7 +112,6 @@ DEF_CLR_API(getSystemVAmd64PassStructInRegisterDescriptor)
DEF_CLR_API(getThreadTLSIndex)
DEF_CLR_API(getInlinedCallFrameVptr)
DEF_CLR_API(getAddrOfCaptureThreadGlobal)
DEF_CLR_API(getAddrModuleDomainID)
DEF_CLR_API(getHelperFtn)
DEF_CLR_API(getFunctionEntryPoint)
DEF_CLR_API(getFunctionFixedEntryPoint)
Expand Down Expand Up @@ -167,5 +165,7 @@ DEF_CLR_API(recordRelocation)
DEF_CLR_API(getRelocTypeHint)
DEF_CLR_API(getModuleNativeEntryPointRange)
DEF_CLR_API(getExpectedTargetArchitecture)
DEF_CLR_API(resolveVirtualMethod)
DEF_CLR_API(expandRawHandleIntrinsic)

#undef DEF_CLR_API
40 changes: 21 additions & 19 deletions src/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,6 @@ BOOL WrapICorJitInfo::isCompatibleDelegate(
return temp;
}

BOOL WrapICorJitInfo::isDelegateCreationAllowed(
CORINFO_CLASS_HANDLE delegateHnd,
CORINFO_METHOD_HANDLE calleeHnd)
{
API_ENTER(isDelegateCreationAllowed);
BOOL temp = wrapHnd->isDelegateCreationAllowed(delegateHnd, calleeHnd);
API_LEAVE(isDelegateCreationAllowed);
return temp;
}


CorInfoInstantiationVerification WrapICorJitInfo::isInstantiationOfVerifiedGeneric(
CORINFO_METHOD_HANDLE method /* IN */)
{
Expand Down Expand Up @@ -1097,14 +1086,6 @@ LONG * WrapICorJitInfo::getAddrOfCaptureThreadGlobal(
return temp;
}

SIZE_T* WrapICorJitInfo::getAddrModuleDomainID(CORINFO_MODULE_HANDLE module)
{
API_ENTER(getAddrModuleDomainID);
SIZE_T* result = wrapHnd->getAddrModuleDomainID(module);
API_LEAVE(getAddrModuleDomainID);
return result;
}

void* WrapICorJitInfo::getHelperFtn(
CorInfoHelpFunc ftnNum,
void **ppIndirection)
Expand Down Expand Up @@ -1615,6 +1596,27 @@ DWORD WrapICorJitInfo::getExpectedTargetArchitecture()
return result;
}

CORINFO_METHOD_HANDLE WrapICorJitInfo::resolveVirtualMethod(
CORINFO_METHOD_HANDLE virtualMethod, /* IN */
CORINFO_CLASS_HANDLE implementingClass, /* IN */
CORINFO_CONTEXT_HANDLE ownerType = NULL /* IN */
)
{
API_ENTER(resolveVirtualMethod);
CORINFO_METHOD_HANDLE result = wrapHnd->resolveVirtualMethod(virtualMethod, implementingClass, ownerType);
API_LEAVE(resolveVirtualMethod);
return result;
}

void WrapICorJitInfo::expandRawHandleIntrinsic(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_GENERICHANDLE_RESULT * pResult)
{
API_ENTER(expandRawHandleIntrinsic);
wrapHnd->expandRawHandleIntrinsic(pResolvedToken, pResult);
API_LEAVE(expandRawHandleIntrinsic);
}

/**********************************************************************************/
// clang-format on
/**********************************************************************************/
37 changes: 37 additions & 0 deletions src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,38 @@ GenTreePtr Compiler::impIntrinsic(GenTreePtr newobjThis,
break;
}

case CORINFO_INTRINSIC_GetRawHandle:
{
noway_assert(IsTargetAbi(CORINFO_CORERT_ABI)); // Only CoreRT supports it.
CORINFO_RESOLVED_TOKEN resolvedToken;
resolvedToken.tokenContext = MAKE_METHODCONTEXT(info.compMethodHnd);
resolvedToken.tokenScope = info.compScopeHnd;
resolvedToken.token = memberRef;
resolvedToken.tokenType = CORINFO_TOKENKIND_Method;

CORINFO_GENERICHANDLE_RESULT embedInfo;
info.compCompHnd->expandRawHandleIntrinsic(&resolvedToken, &embedInfo);

GenTreePtr rawHandle = impLookupToTree(&resolvedToken, &embedInfo.lookup, gtTokenToIconFlags(memberRef),
embedInfo.compileTimeHandle);
if (rawHandle == nullptr)
{
return nullptr;
}

noway_assert(genTypeSize(rawHandle->TypeGet()) == genTypeSize(TYP_I_IMPL));

unsigned rawHandleSlot = lvaGrabTemp(true DEBUGARG("rawHandle"));
impAssignTempGen(rawHandleSlot, rawHandle, clsHnd, (unsigned)CHECK_SPILL_NONE);

GenTreePtr lclVar = gtNewLclvNode(rawHandleSlot, TYP_I_IMPL);
GenTreePtr lclVarAddr = gtNewOperNode(GT_ADDR, TYP_I_IMPL, lclVar);
var_types resultType = JITtype2varType(sig->retType);
retNode = gtNewOperNode(GT_IND, resultType, lclVarAddr);

break;
}

default:
/* Unknown intrinsic */
break;
Expand Down Expand Up @@ -6689,6 +6721,11 @@ var_types Compiler::impImportCall(OPCODE opcode,
call = impIntrinsic(newobjThis, clsHnd, methHnd, sig, pResolvedToken->token, readonlyCall,
(canTailCall && (tailCall != 0)), &intrinsicID);

if (compIsForInlining() && compInlineResult->IsFailure())
{
return callRetTyp;
}

if (call != nullptr)
{
assert(!(mflags & CORINFO_FLG_VIRTUAL) || (mflags & CORINFO_FLG_FINAL) ||
Expand Down
Loading

0 comments on commit b23a11e

Please sign in to comment.