From 160fedd0d7871d15136a37c809054e605d1489d6 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 21 Apr 2023 14:08:02 +0200 Subject: [PATCH 01/10] Introduce readObject --- src/coreclr/inc/corinfo.h | 7 + src/coreclr/inc/icorjitinfoimpl_generated.h | 6 + src/coreclr/inc/jiteeversionguid.h | 10 +- src/coreclr/jit/ICorJitInfo_names_generated.h | 1 + .../jit/ICorJitInfo_wrapper_generated.hpp | 12 + src/coreclr/jit/valuenum.cpp | 335 +++++++++++------- src/coreclr/jit/valuenum.h | 10 + .../JitInterface/CorInfoImpl_generated.cs | 74 ++-- .../ThunkGenerator/ThunkInput.txt | 1 + .../JitInterface/CorInfoImpl.ReadyToRun.cs | 5 + .../JitInterface/CorInfoImpl.RyuJit.cs | 29 ++ .../aot/jitinterface/jitinterface_generated.h | 13 + .../tools/superpmi/superpmi-shared/lwmlist.h | 1 + .../superpmi-shared/methodcontext.cpp | 47 +++ .../superpmi/superpmi-shared/methodcontext.h | 5 + .../superpmi-shim-collector/icorjitinfo.cpp | 8 + .../icorjitinfo_generated.cpp | 10 + .../icorjitinfo_generated.cpp | 9 + .../tools/superpmi/superpmi/icorjitinfo.cpp | 6 + src/coreclr/vm/jitinterface.cpp | 33 ++ 20 files changed, 461 insertions(+), 161 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 0b50a047b3f66..aade9effacc77 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -3244,6 +3244,13 @@ class ICorDynamicInfo : public ICorStaticInfo bool ignoreMovableObjects = true ) = 0; + virtual bool readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset + ) = 0; + // If pIsSpeculative is NULL, return the class handle for the value of ref-class typed // static readonly fields, if there is a unique location for the static and the class // is already initialized. diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index e053b3d2f816f..846c57138512a 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -643,6 +643,12 @@ bool getReadonlyStaticFieldValue( int valueOffset, bool ignoreMovableObjects) override; +bool readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset) override; + CORINFO_CLASS_HANDLE getStaticFieldCurrentClass( CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) override; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 765668241e3c3..a9b7bb877930b 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 236d7997-3d71-45f9-b7d7-5241ad89a56f */ - 0x236d7997, - 0x3d71, - 0x45f9, - { 0xb7, 0xd7, 0x52, 0x41, 0xad, 0x89, 0xa5, 0x6f } +constexpr GUID JITEEVersionIdentifier = { /* 7658c1e7-a363-4ccf-a1a4-1486bac7b5c8 */ + 0x7658c1e7, + 0xa363, + 0x4ccf, + { 0xa1, 0xa4, 0x14, 0x86, 0xba, 0xc7, 0xb5, 0xc8 } }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index 6a9f0408fb82a..fa532a145192c 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -160,6 +160,7 @@ DEF_CLR_API(canAccessFamily) DEF_CLR_API(isRIDClassDomainID) DEF_CLR_API(getClassDomainID) DEF_CLR_API(getReadonlyStaticFieldValue) +DEF_CLR_API(readObject) DEF_CLR_API(getStaticFieldCurrentClass) DEF_CLR_API(getVarArgsHandle) DEF_CLR_API(canGetVarArgsHandle) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 1b3aa470acf33..5b795f237a43a 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -1535,6 +1535,18 @@ bool WrapICorJitInfo::getReadonlyStaticFieldValue( return temp; } +bool WrapICorJitInfo::readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset) +{ + API_ENTER(readObject); + bool temp = wrapHnd->readObject(obj, buffer, bufferSize, valueOffset); + API_LEAVE(readObject); + return temp; +} + CORINFO_CLASS_HANDLE WrapICorJitInfo::getStaticFieldCurrentClass( CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 18c4d946c2736..97409882e5796 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -1876,6 +1876,113 @@ ValueNum ValueNumStore::VNForSimd64Con(simd64_t cnsVal) #endif // TARGET_XARCH #endif // FEATURE_SIMD +ValueNum ValueNumStore::VNForGenericCon(var_types typ, uint8_t* cnsVal) +{ + // For now we only support these primitives, we can extend this list to FP, SIMD and structs in future. + switch (typ) + { +#define READ_VALUE(typ) \ + typ val = {}; \ + memcpy(&val, cnsVal, sizeof(typ)); + + case TYP_BOOL: + case TYP_UBYTE: + { + READ_VALUE(uint8_t); + return VNForIntCon(val); + } + case TYP_BYTE: + { + READ_VALUE(int8_t); + return VNForIntCon(val); + } + case TYP_SHORT: + { + READ_VALUE(int16_t); + return VNForIntCon(val); + } + case TYP_USHORT: + { + READ_VALUE(uint16_t); + return VNForIntCon(val); + } + case TYP_INT: + { + READ_VALUE(int32_t); + return VNForIntCon(val); + } + case TYP_UINT: + { + READ_VALUE(uint32_t); + return VNForIntCon(val); + } + case TYP_LONG: + { + READ_VALUE(int64_t); + return VNForLongCon(val); + } + case TYP_ULONG: + { + READ_VALUE(uint64_t); + return VNForLongCon(val); + } + case TYP_FLOAT: + { + READ_VALUE(float); + return VNForFloatCon(val); + } + case TYP_DOUBLE: + { + READ_VALUE(double); + return VNForDoubleCon(val); + } + case TYP_REF: + { + READ_VALUE(ssize_t); + if (val == 0) + { + return VNForNull(); + } + else + { + return VNForHandle(val, GTF_ICON_OBJ_HDL); + } + } +#if defined(FEATURE_SIMD) + case TYP_SIMD8: + { + READ_VALUE(simd8_t); + return VNForSimd8Con(val); + } + case TYP_SIMD12: + { + READ_VALUE(simd12_t); + return VNForSimd12Con(val); + } + case TYP_SIMD16: + { + READ_VALUE(simd16_t); + return VNForSimd16Con(val); + } +#if defined(TARGET_XARCH) + case TYP_SIMD32: + { + READ_VALUE(simd32_t); + return VNForSimd32Con(val); + } + case TYP_SIMD64: + { + READ_VALUE(simd64_t); + return VNForSimd64Con(val); + } +#endif // TARGET_XARCH +#endif // FEATURE_SIMD + default: + unreached(); + break; + } +} + ValueNum ValueNumStore::VNForCastOper(var_types castToType, bool srcIsUnsigned) { assert(castToType != TYP_STRUCT); @@ -2284,7 +2391,7 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN) { // Case 1: ARR_LENGTH(FROZEN_OBJ) ValueNum addressVN = VNNormalValue(arg0VN); - if (IsVNHandle(addressVN) && (GetHandleFlags(addressVN) == GTF_ICON_OBJ_HDL)) + if (IsVNObjHandle(addressVN)) { size_t handle = CoercedConstantValue(addressVN); int len = m_pComp->info.compCompHnd->getArrayOrStringLength((CORINFO_OBJECT_HANDLE)handle); @@ -5810,6 +5917,11 @@ bool ValueNumStore::IsVNHandle(ValueNum vn) return c->m_attribs == CEA_Handle; } +bool ValueNumStore::IsVNObjHandle(ValueNum vn) +{ + return IsVNHandle(vn) && GetHandleFlags(vn) == GTF_ICON_OBJ_HDL; +} + //------------------------------------------------------------------------ // SwapRelop: return VNFunc for swapped relop // @@ -10178,6 +10290,23 @@ static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, s } } + // Another special case for NativeAOT: ADD(IND(ICON_STATIC_ADDR_PTR), CNS_INT) where CNS_INT has field sequence + if (tree->OperIs(GT_ADD) && tree->gtGetOp1()->isIndir() && tree->gtGetOp2()->IsCnsIntOrI()) + { + GenTreeIndir* indir = tree->gtGetOp1()->AsIndir(); + if (indir->TypeIs(TYP_I_IMPL) && indir->Addr()->TypeIs(TYP_I_IMPL) && + indir->Addr()->IsIconHandle(GTF_ICON_STATIC_ADDR_PTR)) + { + GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); + if (cns2->gtFieldSeq != nullptr) + { + *byteOffset = cns2->IconValue() - cns2->gtFieldSeq->GetOffset(); + *pFseq = cns2->gtFieldSeq; + return true; + } + } + } + // Accumulate final offset while (tree->OperIs(GT_ADD)) { @@ -10221,6 +10350,50 @@ static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, s return false; } +//---------------------------------------------------------------------------------- +// GetObjectHandleAndOffset: Try to obtain a constant object handle with an offset from +// the given tree. +// +// Arguments: +// vnStore - ValueNumStore object +// tree - tree node to inspect +// byteOffset - [Out] resulting byte offset +// pObj - [Out] constant object handle +// +// Return Value: +// true if the given tree is a ObjHandle + CNS +// +static bool GetObjectHandleAndOffset(ValueNumStore* vnStore, + GenTree* tree, + ssize_t* byteOffset, + CORINFO_OBJECT_HANDLE* pObj) +{ + + if (!tree->gtVNPair.BothEqual()) + { + return false; + } + + ValueNum treeVN = tree->gtVNPair.GetLiberal(); + VNFuncApp funcApp; + if (vnStore->GetVNFunc(treeVN, &funcApp) && (funcApp.m_func == (VNFunc)GT_ADD)) + { + if (vnStore->IsVNObjHandle(funcApp.m_args[0]) && vnStore->IsVNConstant(funcApp.m_args[1])) + { + *pObj = vnStore->ConstantObjHandle(funcApp.m_args[0]); + *byteOffset = vnStore->ConstantValue(funcApp.m_args[1]); + return true; + } + } + else if (vnStore->IsVNObjHandle(treeVN)) + { + *pObj = vnStore->ConstantObjHandle(treeVN); + *byteOffset = 0; + return true; + } + return false; +} + //---------------------------------------------------------------------------------- // fgValueNumberConstLoad: Try to detect const_immutable_array[cns_index] tree // and apply a constant VN representing given element at cns_index in that array. @@ -10244,138 +10417,47 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) // // sbyte GetVal() => RVA[1]; // fold to '100' // - ssize_t byteOffset = 0; - FieldSeq* fieldSeq = nullptr; + ssize_t byteOffset = 0; + FieldSeq* fieldSeq = nullptr; + CORINFO_OBJECT_HANDLE obj = nullptr; + int size = (int)genTypeSize(tree->TypeGet()); + const int maxElementSize = sizeof(simd_t); + if ((varTypeIsSIMD(tree) || varTypeIsIntegral(tree) || varTypeIsFloating(tree) || tree->TypeIs(TYP_REF)) && GetStaticFieldSeqAndAddress(vnStore, tree->gtGetOp1(), &byteOffset, &fieldSeq)) { - CORINFO_FIELD_HANDLE fieldHandle = fieldSeq->GetFieldHandle(); - int size = (int)genTypeSize(tree->TypeGet()); - const int maxElementSize = sizeof(simd_t); + CORINFO_FIELD_HANDLE fieldHandle = fieldSeq->GetFieldHandle(); if ((fieldHandle != nullptr) && (size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { uint8_t buffer[maxElementSize] = {0}; if (info.compCompHnd->getReadonlyStaticFieldValue(fieldHandle, (uint8_t*)&buffer, size, (int)byteOffset)) { - // For now we only support these primitives, we can extend this list to FP, SIMD and structs in future. - switch (tree->TypeGet()) + ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); + if (vnStore->IsVNObjHandle(vn)) { -#define READ_VALUE(typ) \ - typ val = {}; \ - memcpy(&val, buffer, sizeof(typ)); - - case TYP_BOOL: - case TYP_UBYTE: - { - READ_VALUE(uint8_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_BYTE: - { - READ_VALUE(int8_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_SHORT: - { - READ_VALUE(int16_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_USHORT: - { - READ_VALUE(uint16_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_INT: - { - READ_VALUE(int32_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_UINT: - { - READ_VALUE(uint32_t); - tree->gtVNPair.SetBoth(vnStore->VNForIntCon(val)); - return true; - } - case TYP_LONG: - { - READ_VALUE(int64_t); - tree->gtVNPair.SetBoth(vnStore->VNForLongCon(val)); - return true; - } - case TYP_ULONG: - { - READ_VALUE(uint64_t); - tree->gtVNPair.SetBoth(vnStore->VNForLongCon(val)); - return true; - } - case TYP_FLOAT: - { - READ_VALUE(float); - tree->gtVNPair.SetBoth(vnStore->VNForFloatCon(val)); - return true; - } - case TYP_DOUBLE: - { - READ_VALUE(double); - tree->gtVNPair.SetBoth(vnStore->VNForDoubleCon(val)); - return true; - } - case TYP_REF: - { - READ_VALUE(ssize_t); - if (val == 0) - { - tree->gtVNPair.SetBoth(vnStore->VNForNull()); - } - else - { - tree->gtVNPair.SetBoth(vnStore->VNForHandle(val, GTF_ICON_OBJ_HDL)); - setMethodHasFrozenObjects(); - } - return true; - } -#if defined(FEATURE_SIMD) - case TYP_SIMD8: - { - READ_VALUE(simd8_t); - tree->gtVNPair.SetBoth(vnStore->VNForSimd8Con(val)); - return true; - } - case TYP_SIMD12: - { - READ_VALUE(simd12_t); - tree->gtVNPair.SetBoth(vnStore->VNForSimd12Con(val)); - return true; - } - case TYP_SIMD16: - { - READ_VALUE(simd16_t); - tree->gtVNPair.SetBoth(vnStore->VNForSimd16Con(val)); - return true; - } -#if defined(TARGET_XARCH) - case TYP_SIMD32: - { - READ_VALUE(simd32_t); - tree->gtVNPair.SetBoth(vnStore->VNForSimd32Con(val)); - return true; - } - case TYP_SIMD64: - { - READ_VALUE(simd64_t); - tree->gtVNPair.SetBoth(vnStore->VNForSimd64Con(val)); - return true; - } -#endif // TARGET_XARCH -#endif // FEATURE_SIMD - default: - assert(!varTypeIsSIMD(tree)); - break; + setMethodHasFrozenObjects(); + } + tree->gtVNPair.SetBoth(vn); + return true; + } + } + } + else if ((varTypeIsSIMD(tree) || varTypeIsIntegral(tree) || varTypeIsFloating(tree)) && + GetObjectHandleAndOffset(vnStore, tree->gtGetOp1(), &byteOffset, &obj)) + { + // See if we can fold IND(ADD(FrozenObj, CNS)) to a constant + assert(obj != nullptr); + if (info.compCompHnd->isObjectImmutable(obj)) + { + if ((size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) + { + uint8_t buffer[maxElementSize] = {0}; + if (info.compCompHnd->readObject(obj, (uint8_t*)&buffer, size, (int)byteOffset)) + { + ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); + assert(!vnStore->IsVNObjHandle(vn)); + tree->gtVNPair.SetBoth(vn); + return true; } } } @@ -10396,10 +10478,9 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) // Is given VN representing a frozen object handle auto isCnsObjHandle = [](ValueNumStore* vnStore, ValueNum vn, CORINFO_OBJECT_HANDLE* handle) -> bool { - if (vnStore->IsVNHandle(vn) && (vnStore->GetHandleFlags(vn) == GTF_ICON_OBJ_HDL)) + if (vnStore->IsVNObjHandle(vn)) { - const size_t obj = vnStore->CoercedConstantValue(vn); - *handle = reinterpret_cast(obj); + *handle = vnStore->ConstantObjHandle(vn); return true; } return false; diff --git a/src/coreclr/jit/valuenum.h b/src/coreclr/jit/valuenum.h index 31ebe77ed9a18..c4f9a2918c0a3 100644 --- a/src/coreclr/jit/valuenum.h +++ b/src/coreclr/jit/valuenum.h @@ -442,6 +442,7 @@ class ValueNumStore ValueNum VNForSimd64Con(simd64_t cnsVal); #endif // TARGET_XARCH #endif // FEATURE_SIMD + ValueNum VNForGenericCon(var_types typ, uint8_t* cnsVal); #ifdef TARGET_64BIT ValueNum VNForPtrSizeIntCon(INT64 cnsVal) @@ -990,6 +991,9 @@ class ValueNumStore // Returns true iff the VN represents a handle constant. bool IsVNHandle(ValueNum vn); + // Returns true iff the VN represents an object handle constant. + bool IsVNObjHandle(ValueNum vn); + // Returns true iff the VN represents a relop bool IsVNRelop(ValueNum vn); @@ -1120,6 +1124,12 @@ class ValueNumStore return ConstantValueInternal(vn DEBUGARG(true)); } + CORINFO_OBJECT_HANDLE ConstantObjHandle(ValueNum vn) + { + assert(IsVNObjHandle(vn)); + return reinterpret_cast(CoercedConstantValue(vn)); + } + // Requires "mthFunc" to be an intrinsic math function (one of the allowable values for the "gtMath" field // of a GenTreeMath node). For unary ops, return the value number for the application of this function to // "arg0VN". For binary ops, return the value number for the application of this function to "arg0VN" and diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 26b637ef6357d..8c52a2452b77c 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2317,6 +2317,21 @@ private static byte _getReadonlyStaticFieldValue(IntPtr thisHandle, IntPtr* ppEx } } + [UnmanagedCallersOnly] + private static byte _readObject(IntPtr thisHandle, IntPtr* ppException, CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + { + var _this = GetThis(thisHandle); + try + { + return _this.readObject(obj, buffer, bufferSize, valueOffset) ? (byte)1 : (byte)0; + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + return default; + } + } + [UnmanagedCallersOnly] private static CORINFO_CLASS_STRUCT_* _getStaticFieldCurrentClass(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* field, byte* pIsSpeculative) { @@ -2730,7 +2745,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 184); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 185); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2888,34 +2903,35 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[153] = (delegate* unmanaged)&_isRIDClassDomainID; callbacks[154] = (delegate* unmanaged)&_getClassDomainID; callbacks[155] = (delegate* unmanaged)&_getReadonlyStaticFieldValue; - callbacks[156] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[157] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[158] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[159] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[160] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[161] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[162] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[163] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[164] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[165] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[166] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[167] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[168] = (delegate* unmanaged)&_allocMem; - callbacks[169] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[170] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[171] = (delegate* unmanaged)&_allocGCInfo; - callbacks[172] = (delegate* unmanaged)&_setEHcount; - callbacks[173] = (delegate* unmanaged)&_setEHinfo; - callbacks[174] = (delegate* unmanaged)&_logMsg; - callbacks[175] = (delegate* unmanaged)&_doAssert; - callbacks[176] = (delegate* unmanaged)&_reportFatalError; - callbacks[177] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[178] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[179] = (delegate* unmanaged)&_recordCallSite; - callbacks[180] = (delegate* unmanaged)&_recordRelocation; - callbacks[181] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[182] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[183] = (delegate* unmanaged)&_getJitFlags; + callbacks[156] = (delegate* unmanaged)&_readObject; + callbacks[157] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[158] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[159] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[160] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[161] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[162] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[163] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[164] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[165] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[166] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[167] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[168] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[169] = (delegate* unmanaged)&_allocMem; + callbacks[170] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[171] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[172] = (delegate* unmanaged)&_allocGCInfo; + callbacks[173] = (delegate* unmanaged)&_setEHcount; + callbacks[174] = (delegate* unmanaged)&_setEHinfo; + callbacks[175] = (delegate* unmanaged)&_logMsg; + callbacks[176] = (delegate* unmanaged)&_doAssert; + callbacks[177] = (delegate* unmanaged)&_reportFatalError; + callbacks[178] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[179] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[180] = (delegate* unmanaged)&_recordCallSite; + callbacks[181] = (delegate* unmanaged)&_recordRelocation; + callbacks[182] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[183] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[184] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 5c4d8ad0b94b1..e67ef909a42d7 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -315,6 +315,7 @@ FUNCTIONS bool isRIDClassDomainID(CORINFO_CLASS_HANDLE cls); unsigned getClassDomainID (CORINFO_CLASS_HANDLE cls, void **ppIndirection); bool getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + bool readObject(CORINFO_OBJECT_HANDLE obj, uint8_t *buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, BoolStar pIsSpeculative); CORINFO_VARARGS_HANDLE getVarArgsHandle(CORINFO_SIG_INFO *pSig, void **ppIndirection); bool canGetVarArgsHandle(CORINFO_SIG_INFO *pSig); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index c40ee03d8fb05..2004fd9e9b2ed 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3028,6 +3028,11 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } + private bool readObject(CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + { + throw new NotSupportedException(); + } + private CORINFO_CLASS_STRUCT_* getObjectType(CORINFO_OBJECT_STRUCT_* objPtr) { throw new NotSupportedException(); diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index b336eb9665e61..dbc6155edccd6 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2303,6 +2303,35 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } +#pragma warning disable CA1822 // Mark members as static + private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) +#pragma warning restore CA1822 // Mark members as static + { + Debug.Assert(objPtr != null); + Debug.Assert(buffer != null); + Debug.Assert(bufferSize >= 0); + Debug.Assert(valueOffset >= 0); + + object obj = HandleToObject(objPtr); + if (obj is FrozenStringNode frozenStr) + { + // Only support reading the string data + int strDataOffset = IntPtr.Size + sizeof(int); // 12 on 64bit + if (valueOffset >= strDataOffset && (long)frozenStr.Data.Length * 2 >= bufferSize) + { + int offset = valueOffset - strDataOffset; + fixed (char* pStr = frozenStr.Data) + { + new Span((byte*)pStr + offset, bufferSize).CopyTo( + new Span(buffer, bufferSize)); + return true; + } + } + } + // TODO: handle FrozenObjectNode + return false; + } + private CORINFO_CLASS_STRUCT_* getObjectType(CORINFO_OBJECT_STRUCT_* objPtr) { object obj = HandleToObject(objPtr); diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index bc1f1383c2966..7f914cd4af9c2 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -167,6 +167,7 @@ struct JitInterfaceCallbacks bool (* isRIDClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); unsigned (* getClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, void** ppIndirection); bool (* getReadonlyStaticFieldValue)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + bool (* readObject)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE (* getStaticFieldCurrentClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool* pIsSpeculative); CORINFO_VARARGS_HANDLE (* getVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig, void** ppIndirection); bool (* canGetVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig); @@ -1715,6 +1716,18 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } + virtual bool readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset) +{ + CorInfoExceptionClass* pException = nullptr; + bool temp = _callbacks->readObject(_thisHandle, &pException, obj, buffer, bufferSize, valueOffset); + if (pException != nullptr) throw pException; + return temp; +} + virtual CORINFO_CLASS_HANDLE getStaticFieldCurrentClass( CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index f079877342882..0f6ea943ffdff 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -82,6 +82,7 @@ LWM(GetDelegateCtor, Agnostic_GetDelegateCtorIn, Agnostic_GetDelegateCtorOut) LWM(GetEEInfo, DWORD, Agnostic_CORINFO_EE_INFO) LWM(GetEHinfo, DLD, Agnostic_CORINFO_EH_CLAUSE) LWM(GetReadonlyStaticFieldValue, DLDDD, DD) +LWM(ReadObject, DLDD, DD) LWM(GetStaticFieldCurrentClass, DLD, Agnostic_GetStaticFieldCurrentClass) LWM(GetFieldClass, DWORDLONG, DWORDLONG) LWM(GetFieldInClass, DLD, DWORDLONG) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 7680c8685fe8f..c3c25ec81f36a 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3776,6 +3776,53 @@ bool MethodContext::repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u return (bool)value.A; } +void MethodContext::recReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result) +{ + if (ReadObject == nullptr) + ReadObject = new LightWeightMap(); + + DLDD key; + ZeroMemory(&key, sizeof(key)); + key.A = CastHandle(obj); + key.B = (DWORD)bufferSize; + key.C = (DWORD)valueOffset; + + DWORD tmpBuf = (DWORD)-1; + if (buffer != nullptr && result) + tmpBuf = (DWORD)ReadObject->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); + + DD value; + value.A = (DWORD)result; + value.B = (DWORD)tmpBuf; + + ReadObject->Add(key, value); + DEBUG_REC(dmpReadObject(key, value)); +} +void MethodContext::dmpReadObject(DLDD key, DD value) +{ + printf("ReadObject key fld-%016" PRIX64 " bufSize-%u, valOffset-%u result-%u", key.A, key.B, key.C, value.A); + ReadObject->Unlock(); +} +bool MethodContext::repReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +{ + DLDD key; + ZeroMemory(&key, sizeof(key)); + key.A = CastHandle(obj); + key.B = (DWORD)bufferSize; + key.C = (DWORD)valueOffset; + + DD value = LookupByKeyOrMiss(ReadObject, key, ": key %016" PRIX64 "", key.A); + + DEBUG_REP(dmpReadObject(key, value)); + if (buffer != nullptr && (bool)value.A) + { + uint8_t* srcBuffer = (uint8_t*)ReadObject->GetBuffer(value.B); + Assert(srcBuffer != nullptr); + memcpy(buffer, srcBuffer, bufferSize); + } + return (bool)value.A; +} + void MethodContext::recGetStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative, CORINFO_CLASS_HANDLE result) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 949d780b09089..54c8b81cfaaf4 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -501,6 +501,10 @@ class MethodContext void dmpGetReadonlyStaticFieldValue(DLDDD key, DD value); bool repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + void recReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result); + void dmpReadObject(DLDD key, DD value); + bool repReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); + void recGetStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative, CORINFO_CLASS_HANDLE result); void dmpGetStaticFieldCurrentClass(DLD key, const Agnostic_GetStaticFieldCurrentClass& value); CORINFO_CLASS_HANDLE repGetStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative); @@ -1187,6 +1191,7 @@ enum mcPackets Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, Packet_GetRISCV64PassStructInRegisterFlags = 209, + Packet_ReadObject = 210, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index c318a1a6481a4..c71bcc9e564a1 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1751,6 +1751,14 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u return result; } +bool interceptor_ICJI::readObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +{ + mc->cr->AddCall("readObject"); + bool result = original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); + mc->recReadObject(obj, buffer, bufferSize, valueOffset, result); + return result; +} + // return the class handle for the current value of a static field CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index ab0c006b8c3ce..bc6d89c8ce6af 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -1258,6 +1258,16 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue( return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } +bool interceptor_ICJI::readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset) +{ + mcs->AddCall("readObject"); + return original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); +} + CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index d8e33021f6286..f2ee360d28f4c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -1102,6 +1102,15 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue( return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } +bool interceptor_ICJI::readObject( + CORINFO_OBJECT_HANDLE obj, + uint8_t* buffer, + int bufferSize, + int valueOffset) +{ + return original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); +} + CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 693ea2fe00673..54cfe532e64e1 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1521,6 +1521,12 @@ bool MyICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* bu return jitInstance->mc->repGetReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } +bool MyICJI::readObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +{ + jitInstance->mc->cr->AddCall("readObject"); + return jitInstance->mc->repReadObject(obj, buffer, bufferSize, valueOffset); +} + // return the class handle for the current value of a static field CORINFO_CLASS_HANDLE MyICJI::getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative) { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 32d338a0da6b4..1c47439e343ce 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11981,6 +11981,39 @@ bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t return result; } +bool CEEInfo::readObject(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int bufferSize, int valueOffset) +{ + CONTRACTL { + THROWS; + GC_TRIGGERS; + MODE_PREEMPTIVE; + } CONTRACTL_END; + + _ASSERT(handle != NULL); + _ASSERT(buffer != NULL); + _ASSERT(bufferSize > 0); + _ASSERT(valueOffset >= 0); + + bool result = false; + + JIT_TO_EE_TRANSITION(); + + GCX_COOP(); + OBJECTREF objRef = getObjectFromJitHandle(handle); + _ASSERTE(objRef != NULL); + if (bufferSize + valueOffset <= (int)objRef->GetSize()) + { + Object* obj = OBJECTREFToObject(objRef); + assert(GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(obj)); + memcpy(buffer, (uint8_t*)obj + valueOffset, bufferSize); + result = true; + } + + EE_TO_JIT_TRANSITION(); + + return result; +} + /*********************************************************************/ CORINFO_CLASS_HANDLE CEEJitInfo::getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE fieldHnd, bool* pIsSpeculative) From b266af42c66c1579614334cbffafb9546e094ad3 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 21 Apr 2023 19:08:02 +0200 Subject: [PATCH 02/10] Address feedback --- .../ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index dbc6155edccd6..c85f829843617 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2303,9 +2303,7 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } -#pragma warning disable CA1822 // Mark members as static private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) -#pragma warning restore CA1822 // Mark members as static { Debug.Assert(objPtr != null); Debug.Assert(buffer != null); @@ -2316,13 +2314,13 @@ private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int buffer if (obj is FrozenStringNode frozenStr) { // Only support reading the string data - int strDataOffset = IntPtr.Size + sizeof(int); // 12 on 64bit + int strDataOffset = _compilation.TypeSystemContext.Target.PointerSize + sizeof(int); // 12 on 64bit if (valueOffset >= strDataOffset && (long)frozenStr.Data.Length * 2 >= bufferSize) { int offset = valueOffset - strDataOffset; fixed (char* pStr = frozenStr.Data) { - new Span((byte*)pStr + offset, bufferSize).CopyTo( + new Span((byte*)pStr /*+ offset*/ + 1 /*intentional bug*/, bufferSize).CopyTo( new Span(buffer, bufferSize)); return true; } From a61f0ac017adaa901692d88a4708f604368a49a3 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 22 Apr 2023 00:27:00 +0200 Subject: [PATCH 03/10] Add a test for NAOT --- .../JitInterface/CorInfoImpl.RyuJit.cs | 2 +- .../tests/MemoryMarshal/GetReference.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index c85f829843617..a87ebefee9f40 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2320,7 +2320,7 @@ private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int buffer int offset = valueOffset - strDataOffset; fixed (char* pStr = frozenStr.Data) { - new Span((byte*)pStr /*+ offset*/ + 1 /*intentional bug*/, bufferSize).CopyTo( + new Span((byte*)pStr + offset, bufferSize).CopyTo( new Span(buffer, bufferSize)); return true; } diff --git a/src/libraries/System.Memory/tests/MemoryMarshal/GetReference.cs b/src/libraries/System.Memory/tests/MemoryMarshal/GetReference.cs index f65ae5ba47550..d0e83a069d0b4 100644 --- a/src/libraries/System.Memory/tests/MemoryMarshal/GetReference.cs +++ b/src/libraries/System.Memory/tests/MemoryMarshal/GetReference.cs @@ -100,5 +100,17 @@ public static void ReadOnlySpanGetReferenceEmpty() Assert.True(Unsafe.AreSame(ref Unsafe.AsRef(null), ref pinnableReference)); } } + + [Fact] + public static void ReadOnlySpanGetReferenceAndReadInteger() + { + Assert.Equal(6619240, + Unsafe.As(ref Unsafe.Add(ref Unsafe.As( + ref MemoryMarshal.GetReference("hello world 1".AsSpan())), 0))); + + Assert.Equal(7998511687277765888, + Unsafe.As(ref Unsafe.Add(ref Unsafe.As( + ref MemoryMarshal.GetReference("hello world 2".AsSpan())), 1))); + } } } From 74d0d17591484c73d5f539c8d47486ff477cd641 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Sun, 23 Apr 2023 13:20:35 +0200 Subject: [PATCH 04/10] Update src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs Co-authored-by: Jakob Botsch Nielsen --- .../aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index a87ebefee9f40..bc82f9a6a1985 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2315,7 +2315,7 @@ private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int buffer { // Only support reading the string data int strDataOffset = _compilation.TypeSystemContext.Target.PointerSize + sizeof(int); // 12 on 64bit - if (valueOffset >= strDataOffset && (long)frozenStr.Data.Length * 2 >= bufferSize) + if (valueOffset >= strDataOffset && (long)frozenStr.Data.Length * 2 >= (valueOffset - strDataOffset) + bufferSize) { int offset = valueOffset - strDataOffset; fixed (char* pStr = frozenStr.Data) From 02c30b81e76cce56ff0a3dbf2d18f3473307c1ba Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 23 Apr 2023 17:34:45 +0200 Subject: [PATCH 05/10] Address feedback --- src/coreclr/jit/valuenum.cpp | 57 ++++++++++++++++----------------- src/coreclr/vm/jitinterface.cpp | 1 - src/coreclr/vm/jitinterface.h | 1 + 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 04aeed0f366b0..1f1faf54c3223 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10277,26 +10277,17 @@ static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, s } ssize_t val = 0; - // Special case for NativeAOT: ADD(ICON_STATIC, CNS_INT) where CNS_INT has field sequence corresponding to field's - // offset - if (tree->OperIs(GT_ADD) && tree->gtGetOp1()->IsIconHandle(GTF_ICON_STATIC_HDL) && tree->gtGetOp2()->IsCnsIntOrI()) + // Special cases for NativeAOT: + // ADD(ICON_STATIC, CNS_INT) // nonGC-static base + // ADD(IND(ICON_STATIC_ADDR_PTR), CNS_INT) // GC-static base + // where CNS_INT has field sequence corresponding to field's offset + if (tree->OperIs(GT_ADD) && tree->gtGetOp2()->IsCnsIntOrI() && !tree->gtGetOp2()->IsIconHandle()) { - GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); - if (cns2->gtFieldSeq != nullptr) - { - *byteOffset = cns2->IconValue() - cns2->gtFieldSeq->GetOffset(); - *pFseq = cns2->gtFieldSeq; - return true; - } - } - - // Another special case for NativeAOT: ADD(IND(ICON_STATIC_ADDR_PTR), CNS_INT) where CNS_INT has field sequence - if (tree->OperIs(GT_ADD) && tree->gtGetOp1()->isIndir() && tree->gtGetOp2()->IsCnsIntOrI()) - { - GenTreeIndir* indir = tree->gtGetOp1()->AsIndir(); - if (indir->TypeIs(TYP_I_IMPL) && indir->Addr()->TypeIs(TYP_I_IMPL) && - indir->Addr()->IsIconHandle(GTF_ICON_STATIC_ADDR_PTR)) + GenTree* addr = tree->gtGetOp1(); + if (addr->IsIconHandle(GTF_ICON_STATIC_HDL) || + (addr->isIndir() && addr->gtGetOp1()->IsIconHandle(GTF_ICON_STATIC_ADDR_PTR))) { + assert(addr->TypeIs(TYP_I_IMPL)); GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); if (cns2->gtFieldSeq != nullptr) { @@ -10378,12 +10369,23 @@ static bool GetObjectHandleAndOffset(ValueNumStore* vnStore, VNFuncApp funcApp; if (vnStore->GetVNFunc(treeVN, &funcApp) && (funcApp.m_func == (VNFunc)GT_ADD)) { + // [objHandle + offset] if (vnStore->IsVNObjHandle(funcApp.m_args[0]) && vnStore->IsVNConstant(funcApp.m_args[1])) { *pObj = vnStore->ConstantObjHandle(funcApp.m_args[0]); *byteOffset = vnStore->ConstantValue(funcApp.m_args[1]); return true; } + + // [offset + objHandle] + // TODO: Introduce a general helper to accumulate offsets for + // shapes such as (((X + CNS1) + CNS2) + CNS3) etc. + if (vnStore->IsVNObjHandle(funcApp.m_args[1]) && vnStore->IsVNConstant(funcApp.m_args[0])) + { + *pObj = vnStore->ConstantObjHandle(funcApp.m_args[1]); + *byteOffset = vnStore->ConstantValue(funcApp.m_args[0]); + return true; + } } else if (vnStore->IsVNObjHandle(treeVN)) { @@ -10430,7 +10432,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) if ((fieldHandle != nullptr) && (size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { uint8_t buffer[maxElementSize] = {0}; - if (info.compCompHnd->getReadonlyStaticFieldValue(fieldHandle, (uint8_t*)&buffer, size, (int)byteOffset)) + if (info.compCompHnd->getReadonlyStaticFieldValue(fieldHandle, buffer, size, (int)byteOffset)) { ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); if (vnStore->IsVNObjHandle(vn)) @@ -10447,18 +10449,15 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) { // See if we can fold IND(ADD(FrozenObj, CNS)) to a constant assert(obj != nullptr); - if (info.compCompHnd->isObjectImmutable(obj)) + if ((size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { - if ((size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) + uint8_t buffer[maxElementSize] = {0}; + if (info.compCompHnd->readObject(obj, buffer, size, (int)byteOffset)) { - uint8_t buffer[maxElementSize] = {0}; - if (info.compCompHnd->readObject(obj, (uint8_t*)&buffer, size, (int)byteOffset)) - { - ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); - assert(!vnStore->IsVNObjHandle(vn)); - tree->gtVNPair.SetBoth(vn); - return true; - } + ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); + assert(!vnStore->IsVNObjHandle(vn)); + tree->gtVNPair.SetBoth(vn); + return true; } } } diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 1c47439e343ce..ab0f6ff594282 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -12004,7 +12004,6 @@ bool CEEInfo::readObject(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int buff if (bufferSize + valueOffset <= (int)objRef->GetSize()) { Object* obj = OBJECTREFToObject(objRef); - assert(GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(obj)); memcpy(buffer, (uint8_t*)obj + valueOffset, bufferSize); result = true; } diff --git a/src/coreclr/vm/jitinterface.h b/src/coreclr/vm/jitinterface.h index 5f2fd20abda2a..73778a1ca6bab 100644 --- a/src/coreclr/vm/jitinterface.h +++ b/src/coreclr/vm/jitinterface.h @@ -422,6 +422,7 @@ class CEEInfo : public ICorJitInfo public: #include "icorjitinfoimpl_generated.h" uint32_t getClassAttribsInternal (CORINFO_CLASS_HANDLE cls); + bool isObjectImmutableInteral(OBJECTREF obj); static unsigned getClassAlignmentRequirementStatic(TypeHandle clsHnd); From 0da23981148953250b46d7f68bdb2b7c40a9f5e0 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 23 Apr 2023 17:45:16 +0200 Subject: [PATCH 06/10] remove assert --- src/coreclr/jit/valuenum.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 1f1faf54c3223..d2fa68f046237 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10287,7 +10287,6 @@ static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, s if (addr->IsIconHandle(GTF_ICON_STATIC_HDL) || (addr->isIndir() && addr->gtGetOp1()->IsIconHandle(GTF_ICON_STATIC_ADDR_PTR))) { - assert(addr->TypeIs(TYP_I_IMPL)); GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); if (cns2->gtFieldSeq != nullptr) { From d96947501efd0b0ce1e5e7ee0f663f8a6c47a5b9 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 23 Apr 2023 23:44:55 +0200 Subject: [PATCH 07/10] Address feedback --- src/coreclr/inc/corinfo.h | 2 +- src/coreclr/inc/icorjitinfoimpl_generated.h | 2 +- src/coreclr/jit/ICorJitInfo_names_generated.h | 2 +- .../jit/ICorJitInfo_wrapper_generated.hpp | 8 +++--- src/coreclr/jit/valuenum.cpp | 17 +++++------- .../JitInterface/CorInfoImpl_generated.cs | 2 +- .../ThunkGenerator/ThunkInput.txt | 2 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 2 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 2 +- .../aot/jitinterface/jitinterface_generated.h | 6 ++--- .../tools/superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi-shared/methodcontext.cpp | 26 +++++++++---------- .../superpmi/superpmi-shared/methodcontext.h | 6 ++--- .../superpmi-shim-collector/icorjitinfo.cpp | 6 ++--- .../icorjitinfo_generated.cpp | 6 ++--- .../icorjitinfo_generated.cpp | 4 +-- .../tools/superpmi/superpmi/icorjitinfo.cpp | 4 +-- src/coreclr/vm/jitinterface.cpp | 2 +- 18 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index aade9effacc77..2e3c7a960090d 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -3244,7 +3244,7 @@ class ICorDynamicInfo : public ICorStaticInfo bool ignoreMovableObjects = true ) = 0; - virtual bool readObject( + virtual bool getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 846c57138512a..430c1e5d1ad8f 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -643,7 +643,7 @@ bool getReadonlyStaticFieldValue( int valueOffset, bool ignoreMovableObjects) override; -bool readObject( +bool getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index fa532a145192c..d3cac5ffa2949 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -160,7 +160,7 @@ DEF_CLR_API(canAccessFamily) DEF_CLR_API(isRIDClassDomainID) DEF_CLR_API(getClassDomainID) DEF_CLR_API(getReadonlyStaticFieldValue) -DEF_CLR_API(readObject) +DEF_CLR_API(getObjectData) DEF_CLR_API(getStaticFieldCurrentClass) DEF_CLR_API(getVarArgsHandle) DEF_CLR_API(canGetVarArgsHandle) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 5b795f237a43a..7b2720af5a8d3 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -1535,15 +1535,15 @@ bool WrapICorJitInfo::getReadonlyStaticFieldValue( return temp; } -bool WrapICorJitInfo::readObject( +bool WrapICorJitInfo::getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - API_ENTER(readObject); - bool temp = wrapHnd->readObject(obj, buffer, bufferSize, valueOffset); - API_LEAVE(readObject); + API_ENTER(getObjectData); + bool temp = wrapHnd->getObjectData(obj, buffer, bufferSize, valueOffset); + API_LEAVE(getObjectData); return temp; } diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index d2fa68f046237..195f250a7708d 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10283,17 +10283,12 @@ static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, s // where CNS_INT has field sequence corresponding to field's offset if (tree->OperIs(GT_ADD) && tree->gtGetOp2()->IsCnsIntOrI() && !tree->gtGetOp2()->IsIconHandle()) { - GenTree* addr = tree->gtGetOp1(); - if (addr->IsIconHandle(GTF_ICON_STATIC_HDL) || - (addr->isIndir() && addr->gtGetOp1()->IsIconHandle(GTF_ICON_STATIC_ADDR_PTR))) + GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); + if ((cns2->gtFieldSeq != nullptr) && (cns2->gtFieldSeq->GetKind() == FieldSeq::FieldKind::SimpleStatic)) { - GenTreeIntCon* cns2 = tree->gtGetOp2()->AsIntCon(); - if (cns2->gtFieldSeq != nullptr) - { - *byteOffset = cns2->IconValue() - cns2->gtFieldSeq->GetOffset(); - *pFseq = cns2->gtFieldSeq; - return true; - } + *byteOffset = cns2->IconValue() - cns2->gtFieldSeq->GetOffset(); + *pFseq = cns2->gtFieldSeq; + return true; } } @@ -10451,7 +10446,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) if ((size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { uint8_t buffer[maxElementSize] = {0}; - if (info.compCompHnd->readObject(obj, buffer, size, (int)byteOffset)) + if (info.compCompHnd->getObjectData(obj, buffer, size, (int)byteOffset)) { ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); assert(!vnStore->IsVNObjHandle(vn)); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 8c52a2452b77c..ba9c231a661f8 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2323,7 +2323,7 @@ private static byte _readObject(IntPtr thisHandle, IntPtr* ppException, CORINFO_ var _this = GetThis(thisHandle); try { - return _this.readObject(obj, buffer, bufferSize, valueOffset) ? (byte)1 : (byte)0; + return _this.getObjectData(obj, buffer, bufferSize, valueOffset) ? (byte)1 : (byte)0; } catch (Exception ex) { diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index e67ef909a42d7..939c62943bc40 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -315,7 +315,7 @@ FUNCTIONS bool isRIDClassDomainID(CORINFO_CLASS_HANDLE cls); unsigned getClassDomainID (CORINFO_CLASS_HANDLE cls, void **ppIndirection); bool getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - bool readObject(CORINFO_OBJECT_HANDLE obj, uint8_t *buffer, int bufferSize, int valueOffset); + bool getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t *buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, BoolStar pIsSpeculative); CORINFO_VARARGS_HANDLE getVarArgsHandle(CORINFO_SIG_INFO *pSig, void **ppIndirection); bool canGetVarArgsHandle(CORINFO_SIG_INFO *pSig); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 2004fd9e9b2ed..13c60bac1ce2a 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3028,7 +3028,7 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } - private bool readObject(CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + private bool getObjectData(CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) { throw new NotSupportedException(); } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index bc82f9a6a1985..ca4e659a4b55e 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2303,7 +2303,7 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } - private bool readObject(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) + private bool getObjectData(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) { Debug.Assert(objPtr != null); Debug.Assert(buffer != null); diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 7f914cd4af9c2..277c7c67a1a27 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -167,7 +167,7 @@ struct JitInterfaceCallbacks bool (* isRIDClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); unsigned (* getClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, void** ppIndirection); bool (* getReadonlyStaticFieldValue)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - bool (* readObject)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); + bool (* getObjectData)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE (* getStaticFieldCurrentClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool* pIsSpeculative); CORINFO_VARARGS_HANDLE (* getVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig, void** ppIndirection); bool (* canGetVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig); @@ -1716,14 +1716,14 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } - virtual bool readObject( + virtual bool getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { CorInfoExceptionClass* pException = nullptr; - bool temp = _callbacks->readObject(_thisHandle, &pException, obj, buffer, bufferSize, valueOffset); + bool temp = _callbacks->getObjectData(_thisHandle, &pException, obj, buffer, bufferSize, valueOffset); if (pException != nullptr) throw pException; return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index 0f6ea943ffdff..76adcb87e47ae 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -82,7 +82,7 @@ LWM(GetDelegateCtor, Agnostic_GetDelegateCtorIn, Agnostic_GetDelegateCtorOut) LWM(GetEEInfo, DWORD, Agnostic_CORINFO_EE_INFO) LWM(GetEHinfo, DLD, Agnostic_CORINFO_EH_CLAUSE) LWM(GetReadonlyStaticFieldValue, DLDDD, DD) -LWM(ReadObject, DLDD, DD) +LWM(GetObjectData, DLDD, DD) LWM(GetStaticFieldCurrentClass, DLD, Agnostic_GetStaticFieldCurrentClass) LWM(GetFieldClass, DWORDLONG, DWORDLONG) LWM(GetFieldInClass, DLD, DWORDLONG) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index c3c25ec81f36a..77ebe78082ca9 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3776,10 +3776,10 @@ bool MethodContext::repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u return (bool)value.A; } -void MethodContext::recReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result) +void MethodContext::recGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result) { - if (ReadObject == nullptr) - ReadObject = new LightWeightMap(); + if (GetObjectData == nullptr) + GetObjectData = new LightWeightMap(); DLDD key; ZeroMemory(&key, sizeof(key)); @@ -3789,21 +3789,21 @@ void MethodContext::recReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, in DWORD tmpBuf = (DWORD)-1; if (buffer != nullptr && result) - tmpBuf = (DWORD)ReadObject->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); + tmpBuf = (DWORD)GetObjectData->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); DD value; value.A = (DWORD)result; value.B = (DWORD)tmpBuf; - ReadObject->Add(key, value); - DEBUG_REC(dmpReadObject(key, value)); + GetObjectData->Add(key, value); + DEBUG_REC(dmpGetObjectData(key, value)); } -void MethodContext::dmpReadObject(DLDD key, DD value) +void MethodContext::dmpGetObjectData(DLDD key, DD value) { - printf("ReadObject key fld-%016" PRIX64 " bufSize-%u, valOffset-%u result-%u", key.A, key.B, key.C, value.A); - ReadObject->Unlock(); + printf("GetObjectData key fld-%016" PRIX64 " bufSize-%u, valOffset-%u result-%u", key.A, key.B, key.C, value.A); + GetObjectData->Unlock(); } -bool MethodContext::repReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool MethodContext::repGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { DLDD key; ZeroMemory(&key, sizeof(key)); @@ -3811,12 +3811,12 @@ bool MethodContext::repReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, in key.B = (DWORD)bufferSize; key.C = (DWORD)valueOffset; - DD value = LookupByKeyOrMiss(ReadObject, key, ": key %016" PRIX64 "", key.A); + DD value = LookupByKeyOrMiss(GetObjectData, key, ": key %016" PRIX64 "", key.A); - DEBUG_REP(dmpReadObject(key, value)); + DEBUG_REP(dmpGetObjectData(key, value)); if (buffer != nullptr && (bool)value.A) { - uint8_t* srcBuffer = (uint8_t*)ReadObject->GetBuffer(value.B); + uint8_t* srcBuffer = (uint8_t*)GetObjectData->GetBuffer(value.B); Assert(srcBuffer != nullptr); memcpy(buffer, srcBuffer, bufferSize); } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 54c8b81cfaaf4..c82321bfa3ccc 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -501,9 +501,9 @@ class MethodContext void dmpGetReadonlyStaticFieldValue(DLDDD key, DD value); bool repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - void recReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result); - void dmpReadObject(DLDD key, DD value); - bool repReadObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); + void recGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result); + void dmpGetObjectData(DLDD key, DD value); + bool repGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); void recGetStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative, CORINFO_CLASS_HANDLE result); void dmpGetStaticFieldCurrentClass(DLD key, const Agnostic_GetStaticFieldCurrentClass& value); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index c71bcc9e564a1..7a8407ee9dd4c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1751,10 +1751,10 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u return result; } -bool interceptor_ICJI::readObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool interceptor_ICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - mc->cr->AddCall("readObject"); - bool result = original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); + mc->cr->AddCall("getObjectData"); + bool result = original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); mc->recReadObject(obj, buffer, bufferSize, valueOffset, result); return result; } diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index bc6d89c8ce6af..5c1219de15c06 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -1258,14 +1258,14 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue( return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool interceptor_ICJI::readObject( +bool interceptor_ICJI::getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - mcs->AddCall("readObject"); - return original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); + mcs->AddCall("getObjectData"); + return original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); } CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index f2ee360d28f4c..8e7557b6d3f45 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -1102,13 +1102,13 @@ bool interceptor_ICJI::getReadonlyStaticFieldValue( return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool interceptor_ICJI::readObject( +bool interceptor_ICJI::getObjectData( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - return original_ICorJitInfo->readObject(obj, buffer, bufferSize, valueOffset); + return original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); } CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 54cfe532e64e1..13c51dfca21b8 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1521,9 +1521,9 @@ bool MyICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* bu return jitInstance->mc->repGetReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool MyICJI::readObject(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool MyICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - jitInstance->mc->cr->AddCall("readObject"); + jitInstance->mc->cr->AddCall("getObjectData"); return jitInstance->mc->repReadObject(obj, buffer, bufferSize, valueOffset); } diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index ab0f6ff594282..a141162d07b6a 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11981,7 +11981,7 @@ bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t return result; } -bool CEEInfo::readObject(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int bufferSize, int valueOffset) +bool CEEInfo::getObjectData(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int bufferSize, int valueOffset) { CONTRACTL { THROWS; From a3b2b06503e8478779dae2ae79bb573f15a48377 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 23 Apr 2023 23:45:40 +0200 Subject: [PATCH 08/10] missing rename --- .../tools/Common/JitInterface/CorInfoImpl_generated.cs | 4 ++-- src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h | 2 +- .../tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp | 2 +- src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index ba9c231a661f8..e7ad7ddaae8aa 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2318,7 +2318,7 @@ private static byte _getReadonlyStaticFieldValue(IntPtr thisHandle, IntPtr* ppEx } [UnmanagedCallersOnly] - private static byte _readObject(IntPtr thisHandle, IntPtr* ppException, CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + private static byte _getObjectData(IntPtr thisHandle, IntPtr* ppException, CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) { var _this = GetThis(thisHandle); try @@ -2903,7 +2903,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[153] = (delegate* unmanaged)&_isRIDClassDomainID; callbacks[154] = (delegate* unmanaged)&_getClassDomainID; callbacks[155] = (delegate* unmanaged)&_getReadonlyStaticFieldValue; - callbacks[156] = (delegate* unmanaged)&_readObject; + callbacks[156] = (delegate* unmanaged)&_getObjectData; callbacks[157] = (delegate* unmanaged)&_getStaticFieldCurrentClass; callbacks[158] = (delegate* unmanaged)&_getVarArgsHandle; callbacks[159] = (delegate* unmanaged)&_canGetVarArgsHandle; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index c82321bfa3ccc..07029b1e80a23 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -1191,7 +1191,7 @@ enum mcPackets Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, Packet_GetRISCV64PassStructInRegisterFlags = 209, - Packet_ReadObject = 210, + Packet_GetObjectData = 210, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 7a8407ee9dd4c..a56b4ee426b69 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1755,7 +1755,7 @@ bool interceptor_ICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, { mc->cr->AddCall("getObjectData"); bool result = original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); - mc->recReadObject(obj, buffer, bufferSize, valueOffset, result); + mc->recGetObjectData(obj, buffer, bufferSize, valueOffset, result); return result; } diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 13c51dfca21b8..44d997ed6abe7 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1524,7 +1524,7 @@ bool MyICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* bu bool MyICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { jitInstance->mc->cr->AddCall("getObjectData"); - return jitInstance->mc->repReadObject(obj, buffer, bufferSize, valueOffset); + return jitInstance->mc->repGetObjectData(obj, buffer, bufferSize, valueOffset); } // return the class handle for the current value of a static field From 11d801e21761f5cb482b1da5c00e6ccbcaf3ee16 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 24 Apr 2023 00:26:53 +0200 Subject: [PATCH 09/10] Rename getObjectType -> getObjectContent; getReadonlyStaticFieldValue -> getStaticFieldContent --- src/coreclr/inc/corinfo.h | 6 +-- src/coreclr/inc/icorjitinfoimpl_generated.h | 4 +- src/coreclr/jit/ICorJitInfo_names_generated.h | 4 +- .../jit/ICorJitInfo_wrapper_generated.hpp | 16 +++--- src/coreclr/jit/importer.cpp | 8 +-- src/coreclr/jit/valuenum.cpp | 6 +-- .../JitInterface/CorInfoImpl_generated.cs | 12 ++--- .../ThunkGenerator/ThunkInput.txt | 4 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 4 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 4 +- .../aot/jitinterface/jitinterface_generated.h | 12 ++--- .../tools/superpmi/superpmi-shared/lwmlist.h | 4 +- .../superpmi-shared/methodcontext.cpp | 52 +++++++++---------- .../superpmi/superpmi-shared/methodcontext.h | 16 +++--- .../superpmi-shim-collector/icorjitinfo.cpp | 16 +++--- .../icorjitinfo_generated.cpp | 12 ++--- .../icorjitinfo_generated.cpp | 8 +-- .../tools/superpmi/superpmi/icorjitinfo.cpp | 12 ++--- src/coreclr/vm/jitinterface.cpp | 8 +-- 19 files changed, 105 insertions(+), 103 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 2e3c7a960090d..6d8286db02614 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -3224,7 +3224,7 @@ class ICorDynamicInfo : public ICorStaticInfo ) = 0; //------------------------------------------------------------------------------ - // getReadonlyStaticFieldValue: returns true and the actual field's value if the given + // getStaticFieldContent: returns true and the actual field's value if the given // field represents a statically initialized readonly field of any type. // // Arguments: @@ -3236,7 +3236,7 @@ class ICorDynamicInfo : public ICorStaticInfo // Return Value: // Returns true if field's constant value was available and successfully copied to buffer // - virtual bool getReadonlyStaticFieldValue( + virtual bool getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, @@ -3244,7 +3244,7 @@ class ICorDynamicInfo : public ICorStaticInfo bool ignoreMovableObjects = true ) = 0; - virtual bool getObjectData( + virtual bool getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 430c1e5d1ad8f..18ea19b28df17 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -636,14 +636,14 @@ unsigned getClassDomainID( CORINFO_CLASS_HANDLE cls, void** ppIndirection) override; -bool getReadonlyStaticFieldValue( +bool getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) override; -bool getObjectData( +bool getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index d3cac5ffa2949..e554312dedb64 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -159,8 +159,8 @@ DEF_CLR_API(getCallInfo) DEF_CLR_API(canAccessFamily) DEF_CLR_API(isRIDClassDomainID) DEF_CLR_API(getClassDomainID) -DEF_CLR_API(getReadonlyStaticFieldValue) -DEF_CLR_API(getObjectData) +DEF_CLR_API(getStaticFieldContent) +DEF_CLR_API(getObjectContent) DEF_CLR_API(getStaticFieldCurrentClass) DEF_CLR_API(getVarArgsHandle) DEF_CLR_API(canGetVarArgsHandle) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 7b2720af5a8d3..26aa42f752260 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -1522,28 +1522,28 @@ unsigned WrapICorJitInfo::getClassDomainID( return temp; } -bool WrapICorJitInfo::getReadonlyStaticFieldValue( +bool WrapICorJitInfo::getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { - API_ENTER(getReadonlyStaticFieldValue); - bool temp = wrapHnd->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); - API_LEAVE(getReadonlyStaticFieldValue); + API_ENTER(getStaticFieldContent); + bool temp = wrapHnd->getStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + API_LEAVE(getStaticFieldContent); return temp; } -bool WrapICorJitInfo::getObjectData( +bool WrapICorJitInfo::getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - API_ENTER(getObjectData); - bool temp = wrapHnd->getObjectData(obj, buffer, bufferSize, valueOffset); - API_LEAVE(getObjectData); + API_ENTER(getObjectContent); + bool temp = wrapHnd->getObjectContent(obj, buffer, bufferSize, valueOffset); + API_LEAVE(getObjectContent); return temp; } diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index c8f4d40e35016..7f50f255da412 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3867,7 +3867,7 @@ GenTree* Compiler::impImportStaticReadOnlyField(CORINFO_FIELD_HANDLE field, CORI if (varTypeIsIntegral(fieldType) || varTypeIsFloating(fieldType) || (fieldType == TYP_REF)) { assert(bufferSize >= genTypeSize(fieldType)); - if (info.compCompHnd->getReadonlyStaticFieldValue(field, buffer, genTypeSize(fieldType))) + if (info.compCompHnd->getStaticFieldContent(field, buffer, genTypeSize(fieldType))) { GenTree* cnsValue = impImportCnsTreeFromBuffer(buffer, fieldType); if (cnsValue != nullptr) @@ -3897,7 +3897,7 @@ GenTree* Compiler::impImportStaticReadOnlyField(CORINFO_FIELD_HANDLE field, CORI } uint8_t buffer[MaxStructSize] = {0}; - if (info.compCompHnd->getReadonlyStaticFieldValue(field, buffer, totalSize)) + if (info.compCompHnd->getStaticFieldContent(field, buffer, totalSize)) { #ifdef FEATURE_SIMD // First, let's check whether field is a SIMD vector and import it as GT_CNS_VEC @@ -3947,7 +3947,7 @@ GenTree* Compiler::impImportStaticReadOnlyField(CORINFO_FIELD_HANDLE field, CORI return gtNewLclvNode(structTempNum, realType); } - JITDUMP("getReadonlyStaticFieldValue returned false - bail out."); + JITDUMP("getStaticFieldContent returned false - bail out."); return nullptr; } @@ -3978,7 +3978,7 @@ GenTree* Compiler::impImportStaticReadOnlyField(CORINFO_FIELD_HANDLE field, CORI const int bufferSize = TARGET_POINTER_SIZE; uint8_t buffer[bufferSize] = {0}; - if ((totalSize > bufferSize) || !info.compCompHnd->getReadonlyStaticFieldValue(field, buffer, totalSize)) + if ((totalSize > bufferSize) || !info.compCompHnd->getStaticFieldContent(field, buffer, totalSize)) { return nullptr; } diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 195f250a7708d..5eb6fcb7dd0d6 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -2415,7 +2415,7 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN) if (field != NULL) { uint8_t buffer[TARGET_POINTER_SIZE] = {0}; - if (m_pComp->info.compCompHnd->getReadonlyStaticFieldValue(field, buffer, + if (m_pComp->info.compCompHnd->getStaticFieldContent(field, buffer, TARGET_POINTER_SIZE, 0, false)) { // In case of 64bit jit emitting 32bit codegen this handle will be 64bit @@ -10426,7 +10426,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) if ((fieldHandle != nullptr) && (size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { uint8_t buffer[maxElementSize] = {0}; - if (info.compCompHnd->getReadonlyStaticFieldValue(fieldHandle, buffer, size, (int)byteOffset)) + if (info.compCompHnd->getStaticFieldContent(fieldHandle, buffer, size, (int)byteOffset)) { ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); if (vnStore->IsVNObjHandle(vn)) @@ -10446,7 +10446,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree) if ((size > 0) && (size <= maxElementSize) && ((size_t)byteOffset < INT_MAX)) { uint8_t buffer[maxElementSize] = {0}; - if (info.compCompHnd->getObjectData(obj, buffer, size, (int)byteOffset)) + if (info.compCompHnd->getObjectContent(obj, buffer, size, (int)byteOffset)) { ValueNum vn = vnStore->VNForGenericCon(tree->TypeGet(), buffer); assert(!vnStore->IsVNObjHandle(vn)); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index e7ad7ddaae8aa..55c7d70b6618a 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2303,12 +2303,12 @@ private static uint _getClassDomainID(IntPtr thisHandle, IntPtr* ppException, CO } [UnmanagedCallersOnly] - private static byte _getReadonlyStaticFieldValue(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* field, byte* buffer, int bufferSize, int valueOffset, byte ignoreMovableObjects) + private static byte _getStaticFieldContent(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* field, byte* buffer, int bufferSize, int valueOffset, byte ignoreMovableObjects) { var _this = GetThis(thisHandle); try { - return _this.getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects != 0) ? (byte)1 : (byte)0; + return _this.getStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects != 0) ? (byte)1 : (byte)0; } catch (Exception ex) { @@ -2318,12 +2318,12 @@ private static byte _getReadonlyStaticFieldValue(IntPtr thisHandle, IntPtr* ppEx } [UnmanagedCallersOnly] - private static byte _getObjectData(IntPtr thisHandle, IntPtr* ppException, CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + private static byte _getObjectContent(IntPtr thisHandle, IntPtr* ppException, CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) { var _this = GetThis(thisHandle); try { - return _this.getObjectData(obj, buffer, bufferSize, valueOffset) ? (byte)1 : (byte)0; + return _this.getObjectContent(obj, buffer, bufferSize, valueOffset) ? (byte)1 : (byte)0; } catch (Exception ex) { @@ -2902,8 +2902,8 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[152] = (delegate* unmanaged)&_canAccessFamily; callbacks[153] = (delegate* unmanaged)&_isRIDClassDomainID; callbacks[154] = (delegate* unmanaged)&_getClassDomainID; - callbacks[155] = (delegate* unmanaged)&_getReadonlyStaticFieldValue; - callbacks[156] = (delegate* unmanaged)&_getObjectData; + callbacks[155] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[156] = (delegate* unmanaged)&_getObjectContent; callbacks[157] = (delegate* unmanaged)&_getStaticFieldCurrentClass; callbacks[158] = (delegate* unmanaged)&_getVarArgsHandle; callbacks[159] = (delegate* unmanaged)&_canGetVarArgsHandle; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 939c62943bc40..870d86df9136d 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -314,8 +314,8 @@ FUNCTIONS bool canAccessFamily(CORINFO_METHOD_HANDLE hCaller, CORINFO_CLASS_HANDLE hInstanceType); bool isRIDClassDomainID(CORINFO_CLASS_HANDLE cls); unsigned getClassDomainID (CORINFO_CLASS_HANDLE cls, void **ppIndirection); - bool getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - bool getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t *buffer, int bufferSize, int valueOffset); + bool getStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t *buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + bool getObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t *buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE getStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, BoolStar pIsSpeculative); CORINFO_VARARGS_HANDLE getVarArgsHandle(CORINFO_SIG_INFO *pSig, void **ppIndirection); bool canGetVarArgsHandle(CORINFO_SIG_INFO *pSig); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 13c60bac1ce2a..e0617683dce46 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3015,7 +3015,7 @@ private int getExactClasses(CORINFO_CLASS_STRUCT_* baseType, int maxExactClasses return 0; } - private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) + private bool getStaticFieldContent(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { Debug.Assert(fieldHandle != null); FieldDesc field = HandleToObject(fieldHandle); @@ -3028,7 +3028,7 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } - private bool getObjectData(CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) + private bool getObjectContent(CORINFO_OBJECT_STRUCT_* obj, byte* buffer, int bufferSize, int valueOffset) { throw new NotSupportedException(); } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index ca4e659a4b55e..8d0b4de86d843 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2240,7 +2240,7 @@ private int getExactClasses(CORINFO_CLASS_STRUCT_* baseType, int maxExactClasses return index; } - private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) + private bool getStaticFieldContent(CORINFO_FIELD_STRUCT_* fieldHandle, byte* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { Debug.Assert(fieldHandle != null); Debug.Assert(buffer != null); @@ -2303,7 +2303,7 @@ private bool getReadonlyStaticFieldValue(CORINFO_FIELD_STRUCT_* fieldHandle, byt return false; } - private bool getObjectData(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) + private bool getObjectContent(CORINFO_OBJECT_STRUCT_* objPtr, byte* buffer, int bufferSize, int valueOffset) { Debug.Assert(objPtr != null); Debug.Assert(buffer != null); diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 277c7c67a1a27..038abebbeceac 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -166,8 +166,8 @@ struct JitInterfaceCallbacks bool (* canAccessFamily)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE hCaller, CORINFO_CLASS_HANDLE hInstanceType); bool (* isRIDClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls); unsigned (* getClassDomainID)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, void** ppIndirection); - bool (* getReadonlyStaticFieldValue)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - bool (* getObjectData)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); + bool (* getStaticFieldContent)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + bool (* getObjectContent)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); CORINFO_CLASS_HANDLE (* getStaticFieldCurrentClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool* pIsSpeculative); CORINFO_VARARGS_HANDLE (* getVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig, void** ppIndirection); bool (* canGetVarArgsHandle)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_SIG_INFO* pSig); @@ -1703,7 +1703,7 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } - virtual bool getReadonlyStaticFieldValue( + virtual bool getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, @@ -1711,19 +1711,19 @@ class JitInterfaceWrapper : public ICorJitInfo bool ignoreMovableObjects) { CorInfoExceptionClass* pException = nullptr; - bool temp = _callbacks->getReadonlyStaticFieldValue(_thisHandle, &pException, field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + bool temp = _callbacks->getStaticFieldContent(_thisHandle, &pException, field, buffer, bufferSize, valueOffset, ignoreMovableObjects); if (pException != nullptr) throw pException; return temp; } - virtual bool getObjectData( + virtual bool getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { CorInfoExceptionClass* pException = nullptr; - bool temp = _callbacks->getObjectData(_thisHandle, &pException, obj, buffer, bufferSize, valueOffset); + bool temp = _callbacks->getObjectContent(_thisHandle, &pException, obj, buffer, bufferSize, valueOffset); if (pException != nullptr) throw pException; return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index 76adcb87e47ae..0a26a5d05774f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -81,8 +81,8 @@ LWM(GetDefaultEqualityComparerClass, DWORDLONG, DWORDLONG) LWM(GetDelegateCtor, Agnostic_GetDelegateCtorIn, Agnostic_GetDelegateCtorOut) LWM(GetEEInfo, DWORD, Agnostic_CORINFO_EE_INFO) LWM(GetEHinfo, DLD, Agnostic_CORINFO_EH_CLAUSE) -LWM(GetReadonlyStaticFieldValue, DLDDD, DD) -LWM(GetObjectData, DLDD, DD) +LWM(GetStaticFieldContent, DLDDD, DD) +LWM(GetObjectContent, DLDD, DD) LWM(GetStaticFieldCurrentClass, DLD, Agnostic_GetStaticFieldCurrentClass) LWM(GetFieldClass, DWORDLONG, DWORDLONG) LWM(GetFieldInClass, DLD, DWORDLONG) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 77ebe78082ca9..43032b7616103 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3727,10 +3727,10 @@ CORINFO_METHOD_HANDLE MethodContext::repEmbedMethodHandle(CORINFO_METHOD_HANDLE return (CORINFO_METHOD_HANDLE)value.B; } -void MethodContext::recGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects, bool result) +void MethodContext::recGetStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects, bool result) { - if (GetReadonlyStaticFieldValue == nullptr) - GetReadonlyStaticFieldValue = new LightWeightMap(); + if (GetStaticFieldContent == nullptr) + GetStaticFieldContent = new LightWeightMap(); DLDDD key; ZeroMemory(&key, sizeof(key)); @@ -3741,21 +3741,21 @@ void MethodContext::recGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u DWORD tmpBuf = (DWORD)-1; if (buffer != nullptr && result) - tmpBuf = (DWORD)GetReadonlyStaticFieldValue->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); + tmpBuf = (DWORD)GetStaticFieldContent->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); DD value; value.A = (DWORD)result; value.B = (DWORD)tmpBuf; - GetReadonlyStaticFieldValue->Add(key, value); - DEBUG_REC(dmpGetReadonlyStaticFieldValue(key, value)); + GetStaticFieldContent->Add(key, value); + DEBUG_REC(dmpGetStaticFieldContent(key, value)); } -void MethodContext::dmpGetReadonlyStaticFieldValue(DLDDD key, DD value) +void MethodContext::dmpGetStaticFieldContent(DLDDD key, DD value) { - printf("GetReadonlyStaticFieldValue key fld-%016" PRIX64 " bufSize-%u, ignoremovable-%u, valOffset-%u result-%u", key.A, key.B, key.C, key.D, value.A); - GetReadonlyStaticFieldValue->Unlock(); + printf("GetStaticFieldContent key fld-%016" PRIX64 " bufSize-%u, ignoremovable-%u, valOffset-%u result-%u", key.A, key.B, key.C, key.D, value.A); + GetStaticFieldContent->Unlock(); } -bool MethodContext::repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) +bool MethodContext::repGetStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { DLDDD key; ZeroMemory(&key, sizeof(key)); @@ -3764,22 +3764,22 @@ bool MethodContext::repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, u key.C = (DWORD)ignoreMovableObjects; key.D = (DWORD)valueOffset; - DD value = LookupByKeyOrMiss(GetReadonlyStaticFieldValue, key, ": key %016" PRIX64 "", key.A); + DD value = LookupByKeyOrMiss(GetStaticFieldContent, key, ": key %016" PRIX64 "", key.A); - DEBUG_REP(dmpGetReadonlyStaticFieldValue(key, value)); + DEBUG_REP(dmpGetStaticFieldContent(key, value)); if (buffer != nullptr && (bool)value.A) { - uint8_t* srcBuffer = (uint8_t*)GetReadonlyStaticFieldValue->GetBuffer(value.B); + uint8_t* srcBuffer = (uint8_t*)GetStaticFieldContent->GetBuffer(value.B); Assert(srcBuffer != nullptr); memcpy(buffer, srcBuffer, bufferSize); } return (bool)value.A; } -void MethodContext::recGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result) +void MethodContext::recGetObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result) { - if (GetObjectData == nullptr) - GetObjectData = new LightWeightMap(); + if (GetObjectContent == nullptr) + GetObjectContent = new LightWeightMap(); DLDD key; ZeroMemory(&key, sizeof(key)); @@ -3789,21 +3789,21 @@ void MethodContext::recGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, DWORD tmpBuf = (DWORD)-1; if (buffer != nullptr && result) - tmpBuf = (DWORD)GetObjectData->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); + tmpBuf = (DWORD)GetObjectContent->AddBuffer((uint8_t*)buffer, (uint32_t)bufferSize); DD value; value.A = (DWORD)result; value.B = (DWORD)tmpBuf; - GetObjectData->Add(key, value); - DEBUG_REC(dmpGetObjectData(key, value)); + GetObjectContent->Add(key, value); + DEBUG_REC(dmpGetObjectContent(key, value)); } -void MethodContext::dmpGetObjectData(DLDD key, DD value) +void MethodContext::dmpGetObjectContent(DLDD key, DD value) { - printf("GetObjectData key fld-%016" PRIX64 " bufSize-%u, valOffset-%u result-%u", key.A, key.B, key.C, value.A); - GetObjectData->Unlock(); + printf("GetObjectContent key fld-%016" PRIX64 " bufSize-%u, valOffset-%u result-%u", key.A, key.B, key.C, value.A); + GetObjectContent->Unlock(); } -bool MethodContext::repGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool MethodContext::repGetObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { DLDD key; ZeroMemory(&key, sizeof(key)); @@ -3811,12 +3811,12 @@ bool MethodContext::repGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, key.B = (DWORD)bufferSize; key.C = (DWORD)valueOffset; - DD value = LookupByKeyOrMiss(GetObjectData, key, ": key %016" PRIX64 "", key.A); + DD value = LookupByKeyOrMiss(GetObjectContent, key, ": key %016" PRIX64 "", key.A); - DEBUG_REP(dmpGetObjectData(key, value)); + DEBUG_REP(dmpGetObjectContent(key, value)); if (buffer != nullptr && (bool)value.A) { - uint8_t* srcBuffer = (uint8_t*)GetObjectData->GetBuffer(value.B); + uint8_t* srcBuffer = (uint8_t*)GetObjectContent->GetBuffer(value.B); Assert(srcBuffer != nullptr); memcpy(buffer, srcBuffer, bufferSize); } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 07029b1e80a23..d8935bb4f806b 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -497,13 +497,13 @@ class MethodContext void dmpEmbedMethodHandle(DWORDLONG key, DLDL value); CORINFO_METHOD_HANDLE repEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection); - void recGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects, bool result); - void dmpGetReadonlyStaticFieldValue(DLDDD key, DD value); - bool repGetReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); + void recGetStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects, bool result); + void dmpGetStaticFieldContent(DLDDD key, DD value); + bool repGetStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects); - void recGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result); - void dmpGetObjectData(DLDD key, DD value); - bool repGetObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); + void recGetObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset, bool result); + void dmpGetObjectContent(DLDD key, DD value); + bool repGetObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset); void recGetStaticFieldCurrentClass(CORINFO_FIELD_HANDLE field, bool* pIsSpeculative, CORINFO_CLASS_HANDLE result); void dmpGetStaticFieldCurrentClass(DLD key, const Agnostic_GetStaticFieldCurrentClass& value); @@ -1179,7 +1179,7 @@ enum mcPackets Packet_GetExactClasses = 195, Packet_GetRuntimeTypePointer = 196, Packet_PrintObjectDescription = 197, - Packet_GetReadonlyStaticFieldValue = 198, + Packet_GetStaticFieldContent = 198, Packet_GetObjectType = 199, Packet_IsObjectImmutable = 200, Packet_ExpandRawHandleIntrinsic = 201, @@ -1191,7 +1191,7 @@ enum mcPackets Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, Packet_GetRISCV64PassStructInRegisterFlags = 209, - Packet_GetObjectData = 210, + Packet_GetObjectContent = 210, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index a56b4ee426b69..6adbb6ac6f624 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1743,19 +1743,19 @@ unsigned interceptor_ICJI::getClassDomainID(CORINFO_CLASS_HANDLE cls, void** ppI return temp; } -bool interceptor_ICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) +bool interceptor_ICJI::getStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { - mc->cr->AddCall("getReadonlyStaticFieldValue"); - bool result = original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); - mc->recGetReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects, result); + mc->cr->AddCall("getStaticFieldContent"); + bool result = original_ICorJitInfo->getStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + mc->recGetStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects, result); return result; } -bool interceptor_ICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool interceptor_ICJI::getObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - mc->cr->AddCall("getObjectData"); - bool result = original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); - mc->recGetObjectData(obj, buffer, bufferSize, valueOffset, result); + mc->cr->AddCall("getObjectContent"); + bool result = original_ICorJitInfo->getObjectContent(obj, buffer, bufferSize, valueOffset); + mc->recGetObjectContent(obj, buffer, bufferSize, valueOffset, result); return result; } diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 5c1219de15c06..e4aa9e7e69af8 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -1247,25 +1247,25 @@ unsigned interceptor_ICJI::getClassDomainID( return original_ICorJitInfo->getClassDomainID(cls, ppIndirection); } -bool interceptor_ICJI::getReadonlyStaticFieldValue( +bool interceptor_ICJI::getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { - mcs->AddCall("getReadonlyStaticFieldValue"); - return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + mcs->AddCall("getStaticFieldContent"); + return original_ICorJitInfo->getStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool interceptor_ICJI::getObjectData( +bool interceptor_ICJI::getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - mcs->AddCall("getObjectData"); - return original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); + mcs->AddCall("getObjectContent"); + return original_ICorJitInfo->getObjectContent(obj, buffer, bufferSize, valueOffset); } CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 8e7557b6d3f45..d832d82b4f3b5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -1092,23 +1092,23 @@ unsigned interceptor_ICJI::getClassDomainID( return original_ICorJitInfo->getClassDomainID(cls, ppIndirection); } -bool interceptor_ICJI::getReadonlyStaticFieldValue( +bool interceptor_ICJI::getStaticFieldContent( CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { - return original_ICorJitInfo->getReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + return original_ICorJitInfo->getStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool interceptor_ICJI::getObjectData( +bool interceptor_ICJI::getObjectContent( CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - return original_ICorJitInfo->getObjectData(obj, buffer, bufferSize, valueOffset); + return original_ICorJitInfo->getObjectContent(obj, buffer, bufferSize, valueOffset); } CORINFO_CLASS_HANDLE interceptor_ICJI::getStaticFieldCurrentClass( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 44d997ed6abe7..3b25e9ad9f076 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1515,16 +1515,16 @@ unsigned MyICJI::getClassDomainID(CORINFO_CLASS_HANDLE cls, void** ppIndirection return jitInstance->mc->repGetClassDomainID(cls, ppIndirection); } -bool MyICJI::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) +bool MyICJI::getStaticFieldContent(CORINFO_FIELD_HANDLE field, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { - jitInstance->mc->cr->AddCall("getReadonlyStaticFieldValue"); - return jitInstance->mc->repGetReadonlyStaticFieldValue(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); + jitInstance->mc->cr->AddCall("getStaticFieldContent"); + return jitInstance->mc->repGetStaticFieldContent(field, buffer, bufferSize, valueOffset, ignoreMovableObjects); } -bool MyICJI::getObjectData(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) +bool MyICJI::getObjectContent(CORINFO_OBJECT_HANDLE obj, uint8_t* buffer, int bufferSize, int valueOffset) { - jitInstance->mc->cr->AddCall("getObjectData"); - return jitInstance->mc->repGetObjectData(obj, buffer, bufferSize, valueOffset); + jitInstance->mc->cr->AddCall("getObjectContent"); + return jitInstance->mc->repGetObjectContent(obj, buffer, bufferSize, valueOffset); } // return the class handle for the current value of a static field diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index a141162d07b6a..8c7c2b4475cfb 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11843,7 +11843,7 @@ InfoAccessType CEEJitInfo::emptyStringLiteral(void ** ppValue) return result; } -bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) +bool CEEInfo::getStaticFieldContent(CORINFO_FIELD_HANDLE fieldHnd, uint8_t* buffer, int bufferSize, int valueOffset, bool ignoreMovableObjects) { CONTRACTL { THROWS; @@ -11981,7 +11981,7 @@ bool CEEInfo::getReadonlyStaticFieldValue(CORINFO_FIELD_HANDLE fieldHnd, uint8_t return result; } -bool CEEInfo::getObjectData(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int bufferSize, int valueOffset) +bool CEEInfo::getObjectContent(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int bufferSize, int valueOffset) { CONTRACTL { THROWS; @@ -12001,7 +12001,9 @@ bool CEEInfo::getObjectData(CORINFO_OBJECT_HANDLE handle, uint8_t* buffer, int b GCX_COOP(); OBJECTREF objRef = getObjectFromJitHandle(handle); _ASSERTE(objRef != NULL); - if (bufferSize + valueOffset <= (int)objRef->GetSize()) + + // TODO: support types containing GC pointers + if (!objRef->GetMethodTable()->ContainsPointers() && bufferSize + valueOffset <= (int)objRef->GetSize()) { Object* obj = OBJECTREFToObject(objRef); memcpy(buffer, (uint8_t*)obj + valueOffset, bufferSize); From 1b6a8d9bd5e4df335e721c40c219304d03d3e692 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 24 Apr 2023 00:36:56 +0200 Subject: [PATCH 10/10] make formatter happy --- src/coreclr/jit/valuenum.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 5eb6fcb7dd0d6..3d258bdb8263e 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -2415,8 +2415,8 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN) if (field != NULL) { uint8_t buffer[TARGET_POINTER_SIZE] = {0}; - if (m_pComp->info.compCompHnd->getStaticFieldContent(field, buffer, - TARGET_POINTER_SIZE, 0, false)) + if (m_pComp->info.compCompHnd->getStaticFieldContent(field, buffer, TARGET_POINTER_SIZE, 0, + false)) { // In case of 64bit jit emitting 32bit codegen this handle will be 64bit // value holding 32bit handle with upper half zeroed (hence, "= NULL").