Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPMI: Capture EE API exceptions in getNewHelper, and simplify the API shape a bit #89852

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2494,9 +2494,9 @@ class ICorStaticInfo

// returns the "NEW" helper optimized for "newCls."
virtual CorInfoHelpFunc getNewHelper(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
bool * pHasSideEffects
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects
) = 0;

// returns the newArr (1-Dim array) helper optimized for "arrayCls."
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool checkMethodModifier(
bool fOptional) override;

CorInfoHelpFunc getNewHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects) override;

Expand Down
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 = { /* cef79bc8-29bf-4f7b-9d05-9fc06832098c */
0xcef79bc8,
0x29bf,
0x4f7b,
{0x9d, 0x05, 0x9f, 0xc0, 0x68, 0x32, 0x09, 0x8c}
constexpr GUID JITEEVersionIdentifier = { /* f2ab43df-bfd4-4da8-95e3-33faeb9c49ed */
0xf2ab43df,
0xbfd4,
0x4da8,
{0x95, 0xe3, 0x33, 0xfa, 0xeb, 0x9c, 0x49, 0xed}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@ bool WrapICorJitInfo::checkMethodModifier(
}

CorInfoHelpFunc WrapICorJitInfo::getNewHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
{
API_ENTER(getNewHelper);
CorInfoHelpFunc temp = wrapHnd->getNewHelper(pResolvedToken, callerHandle, pHasSideEffects);
CorInfoHelpFunc temp = wrapHnd->getNewHelper(classHandle, callerHandle, pHasSideEffects);
API_LEAVE(getNewHelper);
return temp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8668,7 +8668,7 @@ GenTreeAllocObj* Compiler::gtNewAllocObjNode(CORINFO_RESOLVED_TOKEN* pResolvedTo

bool helperHasSideEffects;
CorInfoHelpFunc helperTemp =
info.compCompHnd->getNewHelper(pResolvedToken, info.compMethodHnd, &helperHasSideEffects);
info.compCompHnd->getNewHelper(pResolvedToken->hClass, info.compMethodHnd, &helperHasSideEffects);

if (!usingReadyToRunHelper)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8582,7 +8582,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
//
bool hasSideEffects = false;
CorInfoHelpFunc newHelper =
info.compCompHnd->getNewHelper(&resolvedToken, info.compMethodHnd, &hasSideEffects);
info.compCompHnd->getNewHelper(resolvedToken.hClass, info.compMethodHnd, &hasSideEffects);

if (hasSideEffects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,12 @@ private static byte _checkMethodModifier(IntPtr thisHandle, IntPtr* ppException,
}

[UnmanagedCallersOnly]
private static CorInfoHelpFunc _getNewHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, bool* pHasSideEffects)
private static CorInfoHelpFunc _getNewHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_CLASS_STRUCT_* classHandle, CORINFO_METHOD_STRUCT_* callerHandle, bool* pHasSideEffects)
{
var _this = GetThis(thisHandle);
try
{
return _this.getNewHelper(ref *pResolvedToken, callerHandle, ref *pHasSideEffects);
return _this.getNewHelper(classHandle, callerHandle, ref *pHasSideEffects);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2566,7 +2566,7 @@ private static IntPtr GetUnmanagedCallbacks()
callbacks[54] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, int, CORINFO_FIELD_STRUCT_*>)&_getFieldInClass;
callbacks[55] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, CORINFO_TYPE_LAYOUT_NODE*, UIntPtr*, GetTypeLayoutResult>)&_getTypeLayout;
callbacks[56] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, byte*, byte, byte>)&_checkMethodModifier;
callbacks[57] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_RESOLVED_TOKEN*, CORINFO_METHOD_STRUCT_*, bool*, CorInfoHelpFunc>)&_getNewHelper;
callbacks[57] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, CORINFO_METHOD_STRUCT_*, bool*, CorInfoHelpFunc>)&_getNewHelper;
callbacks[58] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, CorInfoHelpFunc>)&_getNewArrHelper;
callbacks[59] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_RESOLVED_TOKEN*, byte, CorInfoHelpFunc>)&_getCastingHelper;
callbacks[60] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, CorInfoHelpFunc>)&_getSharedCCtorHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ FUNCTIONS
CORINFO_FIELD_HANDLE getFieldInClass(CORINFO_CLASS_HANDLE clsHnd, int32_t num)
GetTypeLayoutResult getTypeLayout(CORINFO_CLASS_HANDLE typeHnd, CORINFO_TYPE_LAYOUT_NODE* treeNodes, size_t* numTreeNodes)
bool checkMethodModifier(CORINFO_METHOD_HANDLE hMethod, const char * modifier, bool fOptional)
CorInfoHelpFunc getNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects)
CorInfoHelpFunc getNewHelper(CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects)
CorInfoHelpFunc getNewArrHelper(CORINFO_CLASS_HANDLE arrayCls)
CorInfoHelpFunc getCastingHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, bool fThrowing)
CorInfoHelpFunc getSharedCCtorHelper(CORINFO_CLASS_HANDLE clsHnd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,9 +1505,9 @@ private CorInfoHelpFunc getCastingHelper(ref CORINFO_RESOLVED_TOKEN pResolvedTok
return fThrowing ? CorInfoHelpFunc.CORINFO_HELP_CHKCASTANY : CorInfoHelpFunc.CORINFO_HELP_ISINSTANCEOFANY;
}

private CorInfoHelpFunc getNewHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, ref bool pHasSideEffects)
private CorInfoHelpFunc getNewHelper(CORINFO_CLASS_STRUCT_* classHandle, CORINFO_METHOD_STRUCT_* callerHandle, ref bool pHasSideEffects)
{
TypeDesc type = HandleToObject(pResolvedToken.hClass);
TypeDesc type = HandleToObject(classHandle);
MetadataType metadataType = type as MetadataType;
if (metadataType != null && metadataType.IsAbstract)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,9 @@ private CorInfoHelpFunc getCastingHelper(ref CORINFO_RESOLVED_TOKEN pResolvedTok
return helper;
}

private CorInfoHelpFunc getNewHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, ref bool pHasSideEffects)
private CorInfoHelpFunc getNewHelper(CORINFO_CLASS_STRUCT_* classHandle, CORINFO_METHOD_STRUCT_* callerHandle, ref bool pHasSideEffects)
{
TypeDesc type = HandleToObject(pResolvedToken.hClass);
TypeDesc type = HandleToObject(classHandle);

Debug.Assert(!type.IsString && !type.IsArray && !type.IsCanonicalDefinitionType(CanonicalFormKind.Any));

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/aot/jitinterface/jitinterface_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct JitInterfaceCallbacks
CORINFO_FIELD_HANDLE (* getFieldInClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE clsHnd, int32_t num);
GetTypeLayoutResult (* getTypeLayout)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE typeHnd, CORINFO_TYPE_LAYOUT_NODE* treeNodes, size_t* numTreeNodes);
bool (* checkMethodModifier)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE hMethod, const char* modifier, bool fOptional);
CorInfoHelpFunc (* getNewHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects);
CorInfoHelpFunc (* getNewHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects);
CorInfoHelpFunc (* getNewArrHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE arrayCls);
CorInfoHelpFunc (* getCastingHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, bool fThrowing);
CorInfoHelpFunc (* getSharedCCtorHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE clsHnd);
Expand Down Expand Up @@ -755,12 +755,12 @@ class JitInterfaceWrapper : public ICorJitInfo
}

virtual CorInfoHelpFunc getNewHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
{
CorInfoExceptionClass* pException = nullptr;
CorInfoHelpFunc temp = _callbacks->getNewHelper(_thisHandle, &pException, pResolvedToken, callerHandle, pHasSideEffects);
CorInfoHelpFunc temp = _callbacks->getNewHelper(_thisHandle, &pException, classHandle, callerHandle, pHasSideEffects);
if (pException != nullptr) throw pException;
return temp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi-shared/agnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ struct Agnostic_FindCallSiteSig

struct Agnostic_GetNewHelper
{
DWORDLONG hClass;
DWORDLONG classHandle;
DWORDLONG callerHandle;
};

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ LWM(GetMethodSig, DLDL, Agnostic_CORINFO_SIG_INFO)
LWM(GetMethodSync, DWORDLONG, DLDL)
LWM(GetMethodVTableOffset, DWORDLONG, DDD)
LWM(GetNewArrHelper, DWORDLONG, DWORD)
LWM(GetNewHelper, Agnostic_GetNewHelper, DD)
LWM(GetNewHelper, Agnostic_GetNewHelper, DDD)
LWM(GetOSRInfo, DWORD, Agnostic_GetOSRInfo)
LWM(GetParentType, DWORDLONG, DWORDLONG)
LWM(GetProfilingHandle, DWORD, Agnostic_GetProfilingHandle)
Expand Down
41 changes: 22 additions & 19 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3026,48 +3026,51 @@ bool MethodContext::repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_I
return result;
}

void MethodContext::recGetNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects,
CorInfoHelpFunc result)
void MethodContext::recGetNewHelper(CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool hasSideEffects,
CorInfoHelpFunc result,
DWORD exceptionCode)
{
if (GetNewHelper == nullptr)
GetNewHelper = new LightWeightMap<Agnostic_GetNewHelper, DD>();
GetNewHelper = new LightWeightMap<Agnostic_GetNewHelper, DDD>();

Agnostic_GetNewHelper key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key.hClass = CastHandle(pResolvedToken->hClass);
ZeroMemory(&key, sizeof(key));
key.classHandle = CastHandle(classHandle);
key.callerHandle = CastHandle(callerHandle);

DD value;
value.A = (pHasSideEffects != nullptr) ? (DWORD)(*pHasSideEffects ? 1 : 0) : (DWORD)0;
DDD value;
value.A = hasSideEffects ? 1 : 0;
value.B = (DWORD)result;
value.C = exceptionCode;

GetNewHelper->Add(key, value);
DEBUG_REC(dmpGetNewHelper(key, value));
}
void MethodContext::dmpGetNewHelper(const Agnostic_GetNewHelper& key, DD value)
void MethodContext::dmpGetNewHelper(const Agnostic_GetNewHelper& key, const DDD& value)
{
printf("GetNewHelper key cls-%016" PRIX64 " chan-%016" PRIX64 ", hasSideEffects-%u, value res-%u", key.hClass, key.callerHandle, value.A, value.B);
printf("GetNewHelper key cls-%016" PRIX64 " chan-%016" PRIX64 ", hasSideEffects-%u, value res-%u, exceptionCode-%08X", key.classHandle, key.callerHandle, value.A, value.B, value.C);
}
CorInfoHelpFunc MethodContext::repGetNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
CorInfoHelpFunc MethodContext::repGetNewHelper(CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects,
DWORD* exceptionCode)
{
Agnostic_GetNewHelper key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
key.hClass = CastHandle(pResolvedToken->hClass);
ZeroMemory(&key, sizeof(key));
key.classHandle = CastHandle(classHandle);
key.callerHandle = CastHandle(callerHandle);

DD value = LookupByKeyOrMiss(GetNewHelper, key, ": key %016" PRIX64 " %016" PRIX64 "", key.hClass, key.callerHandle);

DDD value = LookupByKeyOrMiss(GetNewHelper, key, ": key %016" PRIX64 " %016" PRIX64 "", key.classHandle, key.callerHandle);
DEBUG_REP(dmpGetNewHelper(key, value));

if (pHasSideEffects != nullptr)
{
*pHasSideEffects = (value.A == 0) ? false : true;
*pHasSideEffects = value.A != 0;
}
CorInfoHelpFunc result = (CorInfoHelpFunc)value.B;
*exceptionCode = value.C;
return result;
}

Expand Down
13 changes: 7 additions & 6 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,13 @@ class MethodContext
void dmpGetMethodInfo(DLDL key, const Agnostic_GetMethodInfo& value);
bool repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_INFO* info, CORINFO_CONTEXT_HANDLE context, DWORD* exceptionCode);

void recGetNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects,
CorInfoHelpFunc result);
void dmpGetNewHelper(const Agnostic_GetNewHelper& key, DD value);
CorInfoHelpFunc repGetNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool * pHasSideEffects);
void recGetNewHelper(CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool hasSideEffects,
CorInfoHelpFunc result,
DWORD exceptionCode);
void dmpGetNewHelper(const Agnostic_GetNewHelper& key, const DDD& value);
CorInfoHelpFunc repGetNewHelper(CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects, DWORD* exceptionCode);

void recEmbedGenericHandle(CORINFO_RESOLVED_TOKEN* pResolvedToken,
bool fEmbedParent,
Expand Down
28 changes: 22 additions & 6 deletions src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,30 @@ bool interceptor_ICJI::checkMethodModifier(CORINFO_METHOD_HANDLE hMethod, LPCSTR
}

// returns the "NEW" helper optimized for "newCls."
CorInfoHelpFunc interceptor_ICJI::getNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
CorInfoHelpFunc interceptor_ICJI::getNewHelper(CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
{
mc->cr->AddCall("getNewHelper");
CorInfoHelpFunc temp = original_ICorJitInfo->getNewHelper(pResolvedToken, callerHandle, pHasSideEffects);
mc->recGetNewHelper(pResolvedToken, callerHandle, pHasSideEffects, temp);
return temp;
CorInfoHelpFunc result = CORINFO_HELP_UNDEF;
bool hasSideEffects = false;

RunWithErrorExceptionCodeCaptureAndContinue(
[&]()
{
mc->cr->AddCall("getNewHelper");
result = original_ICorJitInfo->getNewHelper(classHandle, callerHandle, &hasSideEffects);
},
[&](DWORD exceptionCode)
{
mc->recGetNewHelper(classHandle, callerHandle, hasSideEffects, result, exceptionCode);
});

if (pHasSideEffects != nullptr)
{
*pHasSideEffects = hasSideEffects;
}

return result;
}

// returns the newArr (1-Dim array) helper optimized for "arrayCls."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ bool interceptor_ICJI::checkMethodModifier(
}

CorInfoHelpFunc interceptor_ICJI::getNewHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
{
mcs->AddCall("getNewHelper");
return original_ICorJitInfo->getNewHelper(pResolvedToken, callerHandle, pHasSideEffects);
return original_ICorJitInfo->getNewHelper(classHandle, callerHandle, pHasSideEffects);
}

CorInfoHelpFunc interceptor_ICJI::getNewArrHelper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ bool interceptor_ICJI::checkMethodModifier(
}

CorInfoHelpFunc interceptor_ICJI::getNewHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_CLASS_HANDLE classHandle,
CORINFO_METHOD_HANDLE callerHandle,
bool* pHasSideEffects)
{
return original_ICorJitInfo->getNewHelper(pResolvedToken, callerHandle, pHasSideEffects);
return original_ICorJitInfo->getNewHelper(classHandle, callerHandle, pHasSideEffects);
}

CorInfoHelpFunc interceptor_ICJI::getNewArrHelper(
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,14 @@ bool MyICJI::checkMethodModifier(CORINFO_METHOD_HANDLE hMethod, LPCSTR modifier,
}

// returns the "NEW" helper optimized for "newCls."
CorInfoHelpFunc MyICJI::getNewHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool * pHasSideEffects)
CorInfoHelpFunc MyICJI::getNewHelper(CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects)
{
jitInstance->mc->cr->AddCall("getNewHelper");
return jitInstance->mc->repGetNewHelper(pResolvedToken, callerHandle, pHasSideEffects);
DWORD exceptionCode = 0;
CorInfoHelpFunc result = jitInstance->mc->repGetNewHelper(classHandle, callerHandle, pHasSideEffects, &exceptionCode);
if (exceptionCode != 0)
ThrowException(exceptionCode);
return result;
}

// returns the newArr (1-Dim array) helper optimized for "arrayCls."
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6084,7 +6084,7 @@ void Interpreter::NewObj()
{
GCX_PREEMP();
bool sideEffect;
newHelper = m_interpCeeInfo.getNewHelper(&methTok, m_methInfo->m_method, &sideEffect);
newHelper = m_interpCeeInfo.getNewHelper(methTok.hClass, m_methInfo->m_method, &sideEffect);
}

MethodTable * pNewObjMT = GetMethodTableFromClsHnd(methTok.hClass);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5772,7 +5772,7 @@ bool __stdcall TrackAllocationsEnabled()
}

/***********************************************************************/
CorInfoHelpFunc CEEInfo::getNewHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, bool * pHasSideEffects)
CorInfoHelpFunc CEEInfo::getNewHelper(CORINFO_CLASS_HANDLE classHandle, CORINFO_METHOD_HANDLE callerHandle, bool* pHasSideEffects)
Copy link
Member

Choose a reason for hiding this comment

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

Can callerHandle be deleted? It looks unused.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used for diagnostics by crossgen2 – I initially actually was deleting it, until I ran into that use.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can replace the use by methodBeingCompiled -- it will have slightly different behavior when inlining, but maybe that's ok?

Copy link
Member Author

@jakobbotsch jakobbotsch Aug 2, 2023

Choose a reason for hiding this comment

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

Actually it shouldn't have any visible behavior difference since if crossgen2 throws the exception during inlining it will just result in the inlining attempt being aborted, and the exception won't be surfaced to the user. So let me make this change.

Copy link
Member

Choose a reason for hiding this comment

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

We can replace the use by methodBeingCompiled -- it will have slightly different behavior when inlining, but maybe that's ok?

I do not think it will have different observable behavior. We catch and ignore exceptions during inlining, so the only place where this error can show up is when we fail during compilation of the top level method. When we fail during compilation of the top-level method, we are going to print its name in front of the error message. It is not necessary to duplicate the name of the method that failed to compile in the error message.

{
CONTRACTL {
THROWS;
Expand All @@ -5784,7 +5784,7 @@ CorInfoHelpFunc CEEInfo::getNewHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, C

JIT_TO_EE_TRANSITION();

TypeHandle VMClsHnd(pResolvedToken->hClass);
TypeHandle VMClsHnd(classHandle);

if(VMClsHnd.IsTypeDesc())
{
Expand Down