Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a new JitEE method.
with a naive implementation so far.
  • Loading branch information
Sergey committed Aug 24, 2021
commit f239a37fcdc40d451df16a7c0003f98299861dd1
1 change: 1 addition & 0 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ LWM(TryResolveToken, Agnostic_CORINFO_RESOLVED_TOKENin, TryResolveTokenValue)
LWM(SatisfiesClassConstraints, DWORDLONG, DWORD)
LWM(SatisfiesMethodConstraints, DLDL, DWORD)
LWM(GetUnmanagedCallConv, MethodOrSigInfoValue, DD)
LWM(DoesFieldBelongToClass, DLDL, DWORD)
DENSELWM(SigInstHandleMap, DWORDLONG)

#undef LWM
Expand Down
34 changes: 34 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6265,6 +6265,40 @@ DWORD MethodContext::repGetExpectedTargetArchitecture()
return value;
}

void MethodContext::recDoesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls, bool result)
{
if (DoesFieldBelongToClass == nullptr)
DoesFieldBelongToClass = new LightWeightMap<DLDL, DWORD>();

DLDL key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key.A = CastHandle(fld);
key.B = CastHandle(cls);

DWORD value = (DWORD)result;
DoesFieldBelongToClass->Add(key, value);
DEBUG_REC(dmpDoesFieldBelongToClass(key, result));
}

void MethodContext::dmpDoesFieldBelongToClass(DLDL key, bool value)
{
printf("DoesFieldBelongToClass key fld=%016llX, cls=%016llx, result=%d", key.A, key.B, value);
}

bool MethodContext::repDoesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls)
{
DLDL key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key.A = CastHandle(fld);
key.B = CastHandle(cls);

AssertMapAndKeyExist(DoesFieldBelongToClass, key, ": key %016llX %016llX", key.A, key.B);

bool value = (bool)DoesFieldBelongToClass->Get(key);
DEBUG_REP(dmpDoesFieldBelongToClass(key, value));
return value;
}

void MethodContext::recIsValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK, bool result)
{
if (IsValidToken == nullptr)
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ class MethodContext
void dmpGetExpectedTargetArchitecture(DWORD key, DWORD result);
DWORD repGetExpectedTargetArchitecture();

void recDoesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls, bool result);
void dmpDoesFieldBelongToClass(DLDL key, bool value);
bool repDoesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls);

void recIsValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK, bool result);
void dmpIsValidToken(DLD key, DWORD value);
bool repIsValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK);
Expand Down Expand Up @@ -1063,7 +1067,7 @@ enum mcPackets
Packet_TryResolveToken = 158, // Added 4/26/2016
Packet_SatisfiesClassConstraints = 110,
Packet_SatisfiesMethodConstraints = 111,
Packet_ShouldEnforceCallvirtRestriction = 112, // Retired 2/18/2020
Packet_DoesFieldBelongToClass = 112, // Added 8/12/2021
Packet_SigInstHandleMap = 184,
Packet_AllocPgoInstrumentationBySchema = 186, // Added 1/4/2021
Packet_GetPgoInstrumentationResults = 187, // Added 1/4/2021
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2010,3 +2010,13 @@ bool interceptor_ICJI::notifyInstructionSetUsage(CORINFO_InstructionSet instruct
{
return original_ICorJitInfo->notifyInstructionSetUsage(instructionSet, supported);
}

bool interceptor_ICJI::doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls)
{
mc->cr->AddCall("doesFieldBelongToClass");
bool result = original_ICorJitInfo->doesFieldBelongToClass(fldHnd, cls);
mc->recDoesFieldBelongToClass(fldHnd, cls, result);
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1389,3 +1389,11 @@ uint32_t interceptor_ICJI::getJitFlags(
return original_ICorJitInfo->getJitFlags(flags, sizeInBytes);
}

bool interceptor_ICJI::doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls)
{
mcs->AddCall("doesFieldBelongToClass");
return original_ICorJitInfo->doesFieldBelongToClass(fldHnd, cls);
}

Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,10 @@ uint32_t interceptor_ICJI::getJitFlags(
return original_ICorJitInfo->getJitFlags(flags, sizeInBytes);
}

bool interceptor_ICJI::doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls)
{
return original_ICorJitInfo->doesFieldBelongToClass(fldHnd, cls);
}

7 changes: 7 additions & 0 deletions src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,13 @@ uint32_t MyICJI::getJitFlags(CORJIT_FLAGS* jitFlags, uint32_t sizeInBytes)
return ret;
}

bool MyICJI::doesFieldBelongToClass(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls)
{
jitInstance->mc->cr->AddCall("doesFieldBelongToClass");
bool result = jitInstance->mc->repDoesFieldBelongToClass(fldHnd, cls);
return result;
}

// Runs the given function with the given parameter under an error trap
// and returns true if the function completes successfully. We fake this
// up a bit for SuperPMI and simply catch all exceptions.
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/inc/corjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ class ICorJitInfo : public ICorDynamicInfo
uint32_t sizeInBytes /* IN: The size of the buffer. Note that this is effectively a
version number for the CORJIT_FLAGS value. */
) = 0;

// Checks if a field belongs to a given class.
virtual bool doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd, /* IN: the field that we are checking */
CORINFO_CLASS_HANDLE cls /* IN: the class that we are checking */
) = 0;
};

/**********************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ uint32_t getJitFlags(
CORJIT_FLAGS* flags,
uint32_t sizeInBytes) override;

bool doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls) override;

/**********************************************************************************/
// clang-format on
/**********************************************************************************/
12 changes: 6 additions & 6 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* c2e4a466-795d-4e64-a776-0ae7b2eed65b */
0xc2e4a466,
0x795d,
0x4e64,
{0xa7, 0x76, 0x0a, 0xe7, 0xb2, 0xee, 0xd6, 0x5b}
};
constexpr GUID JITEEVersionIdentifier = { /* 5ed35c58-857b-48dd-a818-7c0136dc9f73 */
0x5ed35c58,
0x857b,
0x48dd,
{0xa8, 0x18, 0x7c, 0x01, 0x36, 0xdc, 0x9f, 0x73}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@ DEF_CLR_API(recordRelocation)
DEF_CLR_API(getRelocTypeHint)
DEF_CLR_API(getExpectedTargetArchitecture)
DEF_CLR_API(getJitFlags)
DEF_CLR_API(doesFieldBelongToClass)

#undef DEF_CLR_API
10 changes: 10 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,16 @@ uint32_t WrapICorJitInfo::getJitFlags(
return temp;
}

bool WrapICorJitInfo::doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls)
{
API_ENTER(doesFieldBelongToClass);
bool temp = wrapHnd->doesFieldBelongToClass(fldHnd, cls);
API_LEAVE(doesFieldBelongToClass);
return temp;
}

/**********************************************************************************/
// clang-format on
/**********************************************************************************/
18 changes: 17 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2549,10 +2549,25 @@ static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_FLAGS* f
}
}

[UnmanagedCallersOnly]
static byte _doesFieldBelongToClass(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* fldHnd, CORINFO_CLASS_STRUCT_* cls)
{
var _this = GetThis(thisHandle);
try
{
return _this.doesFieldBelongToClass(fldHnd, cls) ? (byte)1 : (byte)0;
}
catch (Exception ex)
{
*ppException = _this.AllocException(ex);
return default;
}
}


static IntPtr GetUnmanagedCallbacks()
{
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 172);
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 173);

callbacks[0] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, byte>)&_isJitIntrinsic;
callbacks[1] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, uint>)&_getMethodAttribs;
Expand Down Expand Up @@ -2726,6 +2741,7 @@ static IntPtr GetUnmanagedCallbacks()
callbacks[169] = (delegate* unmanaged<IntPtr, IntPtr*, void*, ushort>)&_getRelocTypeHint;
callbacks[170] = (delegate* unmanaged<IntPtr, IntPtr*, uint>)&_getExpectedTargetArchitecture;
callbacks[171] = (delegate* unmanaged<IntPtr, IntPtr*, CORJIT_FLAGS*, uint, uint>)&_getJitFlags;
callbacks[172] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_FIELD_STRUCT_*, CORINFO_CLASS_STRUCT_*, byte>)&_doesFieldBelongToClass;

return (IntPtr)callbacks;
}
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,12 @@ private uint getExpectedTargetArchitecture()
}
}

private bool doesFieldBelongToClass(CORINFO_FIELD_STRUCT_* fld, CORINFO_CLASS_STRUCT_* cls)
{
// we need it to return true for both canon and not-canon classes.
return (HandleToObject(fld).OwningType == HandleToObject(cls));
}

private bool isMethodDefinedInCoreLib()
{
TypeDesc owningType = MethodBeingCompiled.OwningType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,4 @@ FUNCTIONS
uint16_t getRelocTypeHint(void* target)
uint32_t getExpectedTargetArchitecture()
uint32_t getJitFlags(CORJIT_FLAGS* flags, uint32_t sizeInBytes)

bool doesFieldBelongToClass(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls)
11 changes: 11 additions & 0 deletions src/coreclr/tools/aot/jitinterface/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct JitInterfaceCallbacks
uint16_t (* getRelocTypeHint)(void * thisHandle, CorInfoExceptionClass** ppException, void* target);
uint32_t (* getExpectedTargetArchitecture)(void * thisHandle, CorInfoExceptionClass** ppException);
uint32_t (* getJitFlags)(void * thisHandle, CorInfoExceptionClass** ppException, CORJIT_FLAGS* flags, uint32_t sizeInBytes);
bool (* doesFieldBelongToClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls);

};

Expand Down Expand Up @@ -1857,4 +1858,14 @@ class JitInterfaceWrapper : public ICorJitInfo
if (pException != nullptr) throw pException;
return temp;
}

virtual bool doesFieldBelongToClass(
CORINFO_FIELD_HANDLE fldHnd,
CORINFO_CLASS_HANDLE cls)
{
CorInfoExceptionClass* pException = nullptr;
bool temp = _callbacks->doesFieldBelongToClass(_thisHandle, &pException, fldHnd, cls);
if (pException != nullptr) throw pException;
return temp;
}
};
29 changes: 29 additions & 0 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11476,6 +11476,29 @@ uint32_t CEEJitInfo::getExpectedTargetArchitecture()
return IMAGE_FILE_MACHINE_NATIVE;
}

bool CEEJitInfo::doesFieldBelongToClass(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls)
{
CONTRACTL {
THROWS;
GC_TRIGGERS;
MODE_PREEMPTIVE;
} CONTRACTL_END;

bool result;

JIT_TO_EE_TRANSITION();

FieldDesc* field = (FieldDesc*) fldHnd;
TypeHandle th(cls);

MethodTable* pMT = field->GetExactDeclaringType(th.GetMethodTable());
result = (pMT != nullptr);

EE_TO_JIT_TRANSITION();

return result;
}

void CEEInfo::JitProcessShutdownWork()
{
LIMITED_METHOD_CONTRACT;
Expand Down Expand Up @@ -14165,6 +14188,12 @@ uint32_t CEEInfo::getExpectedTargetArchitecture()
return IMAGE_FILE_MACHINE_NATIVE;
}

bool CEEInfo::doesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls)
{
LIMITED_METHOD_CONTRACT;
UNREACHABLE_RET(); // only called on derived class.
}

void CEEInfo::setBoundaries(CORINFO_METHOD_HANDLE ftn, ULONG32 cMap,
ICorDebugInfo::OffsetMapping *pMap)
{
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ class CEEJitInfo : public CEEInfo

uint32_t getExpectedTargetArchitecture() override final;

bool doesFieldBelongToClass(CORINFO_FIELD_HANDLE fld, CORINFO_CLASS_HANDLE cls) override final;

void ResetForJitRetry()
{
CONTRACTL {
Expand Down