Skip to content

Commit

Permalink
SPMI: Implement missing NAOT support (and fix garbage values passed t…
Browse files Browse the repository at this point in the history
…o JIT in expandRawHandleIntrinsic) (#76996)

Implement expandRawHandleIntrinsic in SPMI

Also fix NAOT passing garbage back to JIT.

Fix #76925
  • Loading branch information
jakobbotsch committed Oct 25, 2022
1 parent 041aa3b commit afdd009
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* fd11cceb-ac62-4a6e-892c-dc54b677cacd */
0xfd11cceb,
0xac62,
0x4a6e,
{ 0x89, 0x2c, 0xdc, 0x54, 0xb6, 0x77, 0xca, 0xcd }
constexpr GUID JITEEVersionIdentifier = { /* 2ed4cd12-48ed-4a0e-892e-d24d004a5e4c */
0x2ed4cd12,
0x48ed,
0x4a0e,
{0x89, 0x2e, 0xd2, 0x4d, 0x00, 0x4a, 0x5e, 0x4c}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1818,17 +1818,25 @@ private void expandRawHandleIntrinsic(ref CORINFO_RESOLVED_TOKEN pResolvedToken,
// Resolved token as a potentially RuntimeDetermined object.
MethodDesc method = (MethodDesc)GetRuntimeDeterminedObjectForToken(ref pResolvedToken);

pResult.compileTimeHandle = null;

switch (method.Name)
{
case "EETypePtrOf":
case "Of":
ComputeLookup(ref pResolvedToken, method.Instantiation[0], ReadyToRunHelperId.TypeHandle, ref pResult.lookup);
pResult.handleType = CorInfoGenericHandleType.CORINFO_HANDLETYPE_CLASS;
break;
case "DefaultConstructorOf":
ComputeLookup(ref pResolvedToken, method.Instantiation[0], ReadyToRunHelperId.DefaultConstructor, ref pResult.lookup);
pResult.handleType = CorInfoGenericHandleType.CORINFO_HANDLETYPE_METHOD;
break;
case "AllocatorOf":
ComputeLookup(ref pResolvedToken, method.Instantiation[0], ReadyToRunHelperId.ObjectAllocator, ref pResult.lookup);
pResult.handleType = CorInfoGenericHandleType.CORINFO_HANDLETYPE_UNKNOWN;
break;
default:
Debug.Fail("Unexpected raw handle intrinsic");
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ LWM(InitClass, Agnostic_InitClass, DWORD)
LWM(IsCompatibleDelegate, Agnostic_IsCompatibleDelegate, DD)
LWM(IsDelegateCreationAllowed, DLDL, DWORD)
LWM(IsFieldStatic, DWORDLONG, DWORD)
LWM(ExpandRawHandleIntrinsic, Agnostic_CORINFO_RESOLVED_TOKENin, Agnostic_CORINFO_GENERICHANDLE_RESULT)
LWM(IsIntrinsicType, DWORDLONG, DWORD)
LWM(IsSDArray, DWORDLONG, DWORD)
LWM(IsValidStringRef, DLD, DWORD)
Expand Down
41 changes: 41 additions & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,47 @@ void MethodContext::repGetCallInfoFromMethodHandle(CORINFO_METHOD_HANDLE methodH
LogException(EXCEPTIONCODE_MC, "Didn't find key %016llX.", methodHandle);
}

void MethodContext::recExpandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult)
{
if (ExpandRawHandleIntrinsic == nullptr)
ExpandRawHandleIntrinsic = new LightWeightMap<Agnostic_CORINFO_RESOLVED_TOKENin, Agnostic_CORINFO_GENERICHANDLE_RESULT>;

Agnostic_CORINFO_RESOLVED_TOKENin key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key = SpmiRecordsHelper::CreateAgnostic_CORINFO_RESOLVED_TOKENin(pResolvedToken);

Agnostic_CORINFO_GENERICHANDLE_RESULT value;
value.lookup = SpmiRecordsHelper::StoreAgnostic_CORINFO_LOOKUP(&pResult->lookup);
value.compileTimeHandle = CastHandle(pResult->compileTimeHandle);
value.handleType = (DWORD)pResult->handleType;

ExpandRawHandleIntrinsic->Add(key, value);
DEBUG_REC(dmpExpandRawHandleIntrinsic(key, value));
}
void MethodContext::dmpExpandRawHandleIntrinsic(const Agnostic_CORINFO_RESOLVED_TOKENin& key, const Agnostic_CORINFO_GENERICHANDLE_RESULT& result)
{
printf("ExpandRawHandleIntrinsic key: %s, value %s cth-%016llx ht-%u",
SpmiDumpHelper::DumpAgnostic_CORINFO_RESOLVED_TOKENin(key).c_str(),
SpmiDumpHelper::DumpAgnostic_CORINFO_LOOKUP(result.lookup).c_str(),
result.compileTimeHandle,
result.handleType);
}
void MethodContext::repExpandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult)
{
Agnostic_CORINFO_RESOLVED_TOKENin key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key = SpmiRecordsHelper::CreateAgnostic_CORINFO_RESOLVED_TOKENin(pResolvedToken);

AssertMapAndKeyExist(ExpandRawHandleIntrinsic, key, ": key %x", pResolvedToken->token);

Agnostic_CORINFO_GENERICHANDLE_RESULT value = ExpandRawHandleIntrinsic->Get(key);
DEBUG_REP(dmpExpandRawHandleIntrinsic(key, value));

pResult->lookup = SpmiRecordsHelper::RestoreCORINFO_LOOKUP(value.lookup);
pResult->compileTimeHandle = (CORINFO_GENERIC_HANDLE)value.compileTimeHandle;
pResult->handleType = (CorInfoGenericHandleType)value.handleType;
}

void MethodContext::recIsIntrinsicType(CORINFO_CLASS_HANDLE cls, bool result)
{
if (IsIntrinsicType == nullptr)
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ class MethodContext
void dmpIsSDArray(DWORDLONG key, DWORD value);
bool repIsSDArray(CORINFO_CLASS_HANDLE cls);

void recExpandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult);
void dmpExpandRawHandleIntrinsic(const Agnostic_CORINFO_RESOLVED_TOKENin& key, const Agnostic_CORINFO_GENERICHANDLE_RESULT& result);
void repExpandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult);

void recIsIntrinsicType(CORINFO_CLASS_HANDLE cls, bool result);
void dmpIsIntrinsicType(DWORDLONG key, DWORD value);
bool repIsIntrinsicType(CORINFO_CLASS_HANDLE cls);
Expand Down Expand Up @@ -1144,6 +1148,7 @@ enum mcPackets
Packet_GetReadonlyStaticFieldValue = 198,
Packet_GetObjectType = 199,
Packet_IsObjectImmutable = 200,
Packet_ExpandRawHandleIntrinsic = 201,
};

void SetDebugDumpVariables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ void interceptor_ICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pR
{
mc->cr->AddCall("expandRawHandleIntrinsic");
original_ICorJitInfo->expandRawHandleIntrinsic(pResolvedToken, pResult);
mc->recExpandRawHandleIntrinsic(pResolvedToken, pResult);
}

// Is the given type in System.Private.Corelib and marked with IntrinsicAttribute?
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ CORINFO_CLASS_HANDLE MyICJI::getDefaultEqualityComparerClass(CORINFO_CLASS_HANDL
void MyICJI::expandRawHandleIntrinsic(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_GENERICHANDLE_RESULT* pResult)
{
jitInstance->mc->cr->AddCall("expandRawHandleIntrinsic");
LogError("Hit unimplemented expandRawHandleIntrinsic");
DebugBreakorAV(129);
jitInstance->mc->repExpandRawHandleIntrinsic(pResolvedToken, pResult);
}

// Is the given type in System.Private.Corelib and marked with IntrinsicAttribute?
Expand Down

0 comments on commit afdd009

Please sign in to comment.