From 370b76198911846c5c616f7ce805a38a16f0a7e2 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 7 Jan 2020 21:59:16 +0300 Subject: [PATCH 01/20] Add GetStringLength() to jit interface --- .../superpmi-shared/icorjitinfoimpl.h | 4 ++ .../superpmi/superpmi-shared/lwmlist.h | 1 + .../superpmi-shared/methodcontext.cpp | 33 ++++++++++++++++ .../superpmi/superpmi-shared/methodcontext.h | 7 +++- .../superpmi-shim-collector/icorjitinfo.cpp | 10 +++++ .../superpmi-shim-counter/icorjitinfo.cpp | 8 ++++ .../superpmi-shim-simple/icorjitinfo.cpp | 7 ++++ .../ToolBox/superpmi/superpmi/icorjitinfo.cpp | 8 ++++ src/coreclr/src/inc/corinfo.h | 15 +++++--- src/coreclr/src/jit/ICorJitInfo_API_names.h | 1 + .../src/jit/ICorJitInfo_API_wrapper.hpp | 10 +++++ .../tools/Common/JitInterface/CorInfoImpl.cs | 2 + .../ThunkGenerator/ThunkInput.txt | 1 + .../crossgen2/jitinterface/jitwrapper.cpp | 10 ++--- src/coreclr/src/vm/dynamicmethod.cpp | 10 +++++ src/coreclr/src/vm/dynamicmethod.h | 2 + src/coreclr/src/vm/ilstubresolver.cpp | 7 ++++ src/coreclr/src/vm/ilstubresolver.h | 1 + src/coreclr/src/vm/jitinterface.cpp | 38 +++++++++++++++++++ src/coreclr/src/vm/jitinterface.h | 4 ++ src/coreclr/src/zap/zapinfo.cpp | 6 +++ src/coreclr/src/zap/zapinfo.h | 2 + 22 files changed, 176 insertions(+), 11 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h index ef526e94b9615..e597b198f84ac 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h @@ -255,6 +255,10 @@ BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ unsigned metaTOK /* IN */ ); +int getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ); + BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope); /**********************************************************************************/ diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h index 45449d1161d46..e024655086e98 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -147,6 +147,7 @@ LWM(IsInstantiationOfVerifiedGeneric, DWORDLONG, DWORD) LWM(IsSDArray, DWORDLONG, DWORD) LWM(IsStructRequiringStackAllocRetBuf, DWORDLONG, DWORD) LWM(IsValidStringRef, DLD, DWORD) +LWM(GetStringLength, DLD, DWORD) LWM(IsValidToken, DLD, DWORD) LWM(IsValueClass, DWORDLONG, DWORD) LWM(IsWriteBarrierHelperRequired, DWORDLONG, DWORD) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 12686514eb593..f7bc993f2c870 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -4606,6 +4606,39 @@ BOOL MethodContext::repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned m return value; } +void MethodContext::recGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int result) +{ + if (GetStringLength == nullptr) + GetStringLength = new LightWeightMap(); + + DLD key; + ZeroMemory(&key, sizeof(DLD)); // We use the input structs as a key and use memcmp to compare.. so we need to zero + // out padding too + + key.A = (DWORDLONG)module; + key.B = (DWORD)metaTOK; + + GetStringLength->Add(key, (DWORD)result); +} + +void MethodContext::dmpGetStringLength(DLD key, DWORD value) +{ + printf("GetStringLength key mod-%016llX tok-%08X, value res-%u", key.A, key.B, value); +} + +int MethodContext::repGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) +{ + DLD key; + ZeroMemory(&key, sizeof(DLD)); // We use the input structs as a key and use memcmp to compare.. so we need to zero + // out padding too + + key.A = (DWORDLONG)module; + key.B = (DWORD)metaTOK; + + int value = (int)GetStringLength->Get(key); + return value; +} + void MethodContext::recGetHelperName(CorInfoHelpFunc funcNum, const char* result) { if (GetHelperName == nullptr) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h index fb596c263ef0f..0e7a3e3b727a2 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -1086,6 +1086,10 @@ class MethodContext void dmpIsValidStringRef(DLD key, DWORD value); BOOL repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK); + void recGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int result); + void dmpGetStringLength(DLD key, DWORD value); + int repGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK); + void recGetHelperName(CorInfoHelpFunc funcNum, const char* result); void dmpGetHelperName(DWORD key, DWORD value); const char* repGetHelperName(CorInfoHelpFunc funcNum); @@ -1352,7 +1356,7 @@ class MethodContext }; // ********************* Please keep this up-to-date to ease adding more *************** -// Highest packet number: 174 +// Highest packet number: 175 // ************************************************************************************* enum mcPackets { @@ -1493,6 +1497,7 @@ enum mcPackets Packet_IsSDArray = 101, Packet_IsStructRequiringStackAllocRetBuf = 102, Packet_IsValidStringRef = 103, + Packet_GetStringLength = 175, // Added 1/7/2020 Retired6 = 104, Packet_IsValidToken = 144, // Added 7/19/2013 - adjusted members to proper types Packet_IsValueClass = 105, diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp index b2ead489e7655..33d2e28c9f2b9 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -517,6 +517,16 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return temp; } +int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) +{ + mc->cr->AddCall("getStringLength"); + int temp = original_ICorJitInfo->getStringLength(module, metaTOK); + mc->recGetStringLength(module, metaTOK, temp); + return temp; +} + BOOL interceptor_ICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) { mc->cr->AddCall("shouldEnforceCallvirtRestriction"); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp index 7ffa1ebbdff4d..5cb5d7d068e35 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp @@ -378,6 +378,14 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return original_ICorJitInfo->isValidStringRef(module, metaTOK); } +int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) +{ + mcs->AddCall("getStringLength"); + return original_ICorJitInfo->getStringLength(module, metaTOK); +} + BOOL interceptor_ICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) { mcs->AddCall("shouldEnforceCallvirtRestriction"); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp index f390fcb058b21..0153e53f5406f 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp @@ -340,6 +340,13 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return original_ICorJitInfo->isValidStringRef(module, metaTOK); } +int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) +{ + return original_ICorJitInfo->getStringLength(module, metaTOK); +} + BOOL interceptor_ICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) { return original_ICorJitInfo->shouldEnforceCallvirtRestriction(scope); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp index bf143b877bb4e..1c3675ea44473 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -408,6 +408,14 @@ BOOL MyICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return jitInstance->mc->repIsValidStringRef(module, metaTOK); } +int MyICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) +{ + jitInstance->mc->cr->AddCall("getStringLength"); + return jitInstance->mc->repGetStringLength(module, metaTOK); +} + BOOL MyICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) { jitInstance->mc->cr->AddCall("shouldEnforceCallvirtRestriction"); diff --git a/src/coreclr/src/inc/corinfo.h b/src/coreclr/src/inc/corinfo.h index 4b5ee24d51585..4485a29c8f664 100644 --- a/src/coreclr/src/inc/corinfo.h +++ b/src/coreclr/src/inc/corinfo.h @@ -217,11 +217,11 @@ TODO: Talk about initializing strutures before use #endif #endif -SELECTANY const GUID JITEEVersionIdentifier = { /* abcf830c-56d1-4b33-a8ec-5063bb5495f1 */ - 0xabcf830c, - 0x56d1, - 0x4b33, - {0xa8, 0xec, 0x50, 0x63, 0xbb, 0x54, 0x95, 0xf1} +SELECTANY const GUID JITEEVersionIdentifier = { /* 13028353-152c-4886-b05b-fa76ee8169cf */ + 0x13028353, + 0x152c, + 0x4886, + {0xb0, 0x5b, 0xfa, 0x76, 0xee, 0x81, 0x69, 0xcf} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2307,6 +2307,11 @@ class ICorStaticInfo unsigned metaTOK /* IN */ ) = 0; + virtual int getStringLength ( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */ + ) = 0; + virtual BOOL shouldEnforceCallvirtRestriction( CORINFO_MODULE_HANDLE scope ) = 0; diff --git a/src/coreclr/src/jit/ICorJitInfo_API_names.h b/src/coreclr/src/jit/ICorJitInfo_API_names.h index 2e578342cc1e1..a6136a5b94941 100644 --- a/src/coreclr/src/jit/ICorJitInfo_API_names.h +++ b/src/coreclr/src/jit/ICorJitInfo_API_names.h @@ -38,6 +38,7 @@ DEF_CLR_API(getTokenTypeAsHandle) DEF_CLR_API(canSkipVerification) DEF_CLR_API(isValidToken) DEF_CLR_API(isValidStringRef) +DEF_CLR_API(getStringLength) DEF_CLR_API(shouldEnforceCallvirtRestriction) DEF_CLR_API(asCorInfoType) DEF_CLR_API(getClassName) diff --git a/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp b/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp index 83ca2a2c7488f..fca4b0a80b892 100644 --- a/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp +++ b/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp @@ -367,6 +367,16 @@ BOOL WrapICorJitInfo::isValidStringRef( return temp; } +int WrapICorJitInfo::getStringLength( + CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK /* IN */) +{ + API_ENTER(getStringLength); + int temp = wrapHnd->getStringLength(module, metaTOK); + API_LEAVE(getStringLength); + return temp; +} + BOOL WrapICorJitInfo::shouldEnforceCallvirtRestriction( CORINFO_MODULE_HANDLE scope) { diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index 87d0f80e405b0..12327dad55a9b 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1162,6 +1162,8 @@ private bool isValidToken(CORINFO_MODULE_STRUCT_* module, uint metaTOK) { throw new NotImplementedException("isValidToken"); } private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) { throw new NotImplementedException("isValidStringRef"); } + private int getStringLength(CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { throw new NotImplementedException("getStringLength"); } private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index fffc0de16cd8e..3798a1150306e 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -199,6 +199,7 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) + int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitwrapper.cpp b/src/coreclr/src/tools/crossgen2/jitinterface/jitwrapper.cpp index 0da621980ae89..ce6aae9ba83d9 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitwrapper.cpp +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitwrapper.cpp @@ -27,11 +27,11 @@ class CORJIT_FLAGS uint64_t corJitFlags; }; -static const GUID JITEEVersionIdentifier = { /* abcf830c-56d1-4b33-a8ec-5063bb5495f1 */ - 0xabcf830c, - 0x56d1, - 0x4b33, - {0xa8, 0xec, 0x50, 0x63, 0xbb, 0x54, 0x95, 0xf1} +static const GUID JITEEVersionIdentifier = { /* 13028353-152c-4886-b05b-fa76ee8169cf */ + 0x13028353, + 0x152c, + 0x4886, + {0xb0, 0x5b, 0xfa, 0x76, 0xee, 0x81, 0x69, 0xcf} }; class Jit diff --git a/src/coreclr/src/vm/dynamicmethod.cpp b/src/coreclr/src/vm/dynamicmethod.cpp index b25dfb73e2774..52a8b448369e8 100644 --- a/src/coreclr/src/vm/dynamicmethod.cpp +++ b/src/coreclr/src/vm/dynamicmethod.cpp @@ -1197,6 +1197,16 @@ LCGMethodResolver::IsValidStringRef(mdToken metaTok) return GetStringLiteral(metaTok) != NULL; } +int +LCGMethodResolver::GetStringLength(mdToken metaTok) +{ + STANDARD_VM_CONTRACT; + + GCX_COOP(); + + return GetStringLiteral(metaTok)->GetStringLength(); +} + //--------------------------------------------------------------------------------------- // STRINGREF diff --git a/src/coreclr/src/vm/dynamicmethod.h b/src/coreclr/src/vm/dynamicmethod.h index c119877d55a8b..4500435f4f34f 100644 --- a/src/coreclr/src/vm/dynamicmethod.h +++ b/src/coreclr/src/vm/dynamicmethod.h @@ -73,6 +73,7 @@ class DynamicResolver // jit interface api virtual OBJECTHANDLE ConstructStringLiteral(mdToken metaTok) = 0; virtual BOOL IsValidStringRef(mdToken metaTok) = 0; + virtual int GetStringLength(mdToken metaTok) = 0; virtual void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) = 0; virtual SigPointer ResolveSignature(mdToken token) = 0; virtual SigPointer ResolveSignatureForVarArg(mdToken token) = 0; @@ -122,6 +123,7 @@ class LCGMethodResolver : public DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); + int GetStringLength(mdToken metaTok); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/ilstubresolver.cpp b/src/coreclr/src/vm/ilstubresolver.cpp index 665d39dd20de1..bb1c908a2de6d 100644 --- a/src/coreclr/src/vm/ilstubresolver.cpp +++ b/src/coreclr/src/vm/ilstubresolver.cpp @@ -140,6 +140,13 @@ BOOL ILStubResolver::IsValidStringRef(mdToken metaTok) return FALSE; } +int ILStubResolver::GetStringLength(mdToken metaTok) +{ + STANDARD_VM_CONTRACT; + _ASSERTE(FALSE); + return -1; +} + void ILStubResolver::ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) { STANDARD_VM_CONTRACT; diff --git a/src/coreclr/src/vm/ilstubresolver.h b/src/coreclr/src/vm/ilstubresolver.h index c3be136aaa9dc..1678ea7ad69e9 100644 --- a/src/coreclr/src/vm/ilstubresolver.h +++ b/src/coreclr/src/vm/ilstubresolver.h @@ -33,6 +33,7 @@ class ILStubResolver : DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); + int GetStringLength(mdToken metaTok); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index 7f886652b8eb7..1d7549f2fb333 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -799,6 +799,44 @@ BOOL CEEInfo::isValidStringRef ( return result; } +int CEEInfo::getStringLength ( + CORINFO_MODULE_HANDLE moduleHnd, + mdToken metaTOK) +{ + CONTRACTL{ + THROWS; + GC_TRIGGERS; + MODE_PREEMPTIVE; + } CONTRACTL_END; + + int length = 0; + Module* module = GetModule(moduleHnd); + + JIT_TO_EE_TRANSITION(); + + if (IsDynamicScope(moduleHnd)) + { + length = GetDynamicResolver(moduleHnd)->GetStringLength(metaTOK); + } + else + { + DWORD dwCharCount; + LPCWSTR pString; + if (!FAILED((module)->GetMDImport()->GetUserString(metaTOK, &dwCharCount, NULL, &pString)) && (pString != nullptr)) + { + length = dwCharCount; + } + else + { + length = -1; + } + } + + EE_TO_JIT_TRANSITION(); + + return length; +} + /* static */ size_t CEEInfo::findNameOfToken (Module* module, mdToken metaTOK, diff --git a/src/coreclr/src/vm/jitinterface.h b/src/coreclr/src/vm/jitinterface.h index 6eab4785a67b3..cb4dfdc6e0d45 100644 --- a/src/coreclr/src/vm/jitinterface.h +++ b/src/coreclr/src/vm/jitinterface.h @@ -700,6 +700,10 @@ class CEEInfo : public ICorJitInfo CORINFO_MODULE_HANDLE module, mdToken metaTOK); + int getStringLength ( + CORINFO_MODULE_HANDLE module, + mdToken metaTOK); + static size_t findNameOfToken (Module* module, mdToken metaTOK, __out_ecount (FQNameCapacity) char * szFQName, size_t FQNameCapacity); diff --git a/src/coreclr/src/zap/zapinfo.cpp b/src/coreclr/src/zap/zapinfo.cpp index 69476d0798171..a3cc7ee1e9a28 100644 --- a/src/coreclr/src/zap/zapinfo.cpp +++ b/src/coreclr/src/zap/zapinfo.cpp @@ -3809,6 +3809,12 @@ BOOL ZapInfo::isValidStringRef ( return m_pEEJitInfo->isValidStringRef(tokenScope, token); } +int ZapInfo::getStringLength ( + CORINFO_MODULE_HANDLE tokenScope, + unsigned token) +{ + return m_pEEJitInfo->getStringLength(tokenScope, token); +} // // ICorMethodInfo diff --git a/src/coreclr/src/zap/zapinfo.h b/src/coreclr/src/zap/zapinfo.h index 338ad74911db2..e9c1ff26c9bbc 100644 --- a/src/coreclr/src/zap/zapinfo.h +++ b/src/coreclr/src/zap/zapinfo.h @@ -629,6 +629,8 @@ class ZapInfo unsigned metaTOK); BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK); + int getStringLength(CORINFO_MODULE_HANDLE module, + unsigned metaTOK); // ICorMethodInfo From e3e889e0b3d69f1d24e8482fd9bc053fd0559329 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 7 Jan 2020 22:29:44 +0300 Subject: [PATCH 02/20] Use `gen.bat` to update crossgen2 --- .../tools/Common/JitInterface/CorInfoBase.cs | 23 +++++++++++++++++-- .../ThunkGenerator/ThunkInput.txt | 2 +- .../JitInterface/ThunkGenerator/gen.bat | 2 +- .../Common/JitInterface/ThunkGenerator/gen.sh | 2 +- .../crossgen2/jitinterface/jitinterface.h | 10 ++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index 1aa42f323d6af..bbf468bb5b2ba 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -369,6 +369,8 @@ unsafe partial class CorInfoImpl delegate uint __getExpectedTargetArchitecture(IntPtr _this, IntPtr* ppException); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate uint __getJitFlags(IntPtr _this, IntPtr* ppException, ref CORJIT_FLAGS flags, uint sizeInBytes); + [UnmanagedFunctionPointerAttribute(default(CallingConvention))] + delegate int __getStringLength(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); static uint _getMethodAttribs(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn) { @@ -2830,11 +2832,25 @@ static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, ref CORJIT_FLAG } } + static int _getStringLength(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { + var _this = GetThis(thisHandle); + try + { + return _this.getStringLength(module, metaTOK); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + return default(int); + } + } + static IntPtr GetUnmanagedCallbacks(out Object keepAlive) { - IntPtr * callbacks = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 179); - Object[] delegates = new Object[179]; + IntPtr * callbacks = (IntPtr *)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 180); + Object[] delegates = new Object[180]; var d0 = new __getMethodAttribs(_getMethodAttribs); callbacks[0] = Marshal.GetFunctionPointerForDelegate(d0); @@ -3373,6 +3389,9 @@ static IntPtr GetUnmanagedCallbacks(out Object keepAlive) var d178 = new __getJitFlags(_getJitFlags); callbacks[178] = Marshal.GetFunctionPointerForDelegate(d178); delegates[178] = d178; + var d179 = new __getStringLength(_getStringLength); + callbacks[179] = Marshal.GetFunctionPointerForDelegate(d179); + delegates[179] = d179; keepAlive = delegates; return (IntPtr)callbacks; diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 3798a1150306e..eba1e00de37f7 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -199,7 +199,6 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) - int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) @@ -343,3 +342,4 @@ FUNCTIONS void getModuleNativeEntryPointRange(void** pStart, void** pEnd) DWORD getExpectedTargetArchitecture() DWORD getJitFlags(CORJIT_FLAGS* flags, DWORD sizeInBytes) + int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.bat b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.bat index 2fec511758182..46328b52d08ba 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.bat +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.bat @@ -1,2 +1,2 @@ cd /d %~dp0 -dotnet run -- ThunkInput.txt ..\CorInfoBase.cs ..\..\..\jitinterface\jitinterface.h \ No newline at end of file +dotnet run -- ThunkInput.txt ..\CorInfoBase.cs ..\..\..\crossgen2\jitinterface\jitinterface.h \ No newline at end of file diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.sh b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.sh index 3eb458d6200b3..59672c72d4156 100755 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.sh +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/gen.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash cd "$(dirname ${BASH_SOURCE[0]})" -dotnet run -- ThunkInput.txt ../CorInfoBase.cs ../../../jitinterface/jitinterface.h +dotnet run -- ThunkInput.txt ../CorInfoBase.cs ../../../crossgen2/jitinterface/jitinterface.h diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h index 96ea0747092ee..4b378ee1fc905 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h @@ -189,6 +189,7 @@ struct JitInterfaceCallbacks void (* getModuleNativeEntryPointRange)(void * thisHandle, CorInfoException** ppException, void** pStart, void** pEnd); unsigned int (* getExpectedTargetArchitecture)(void * thisHandle, CorInfoException** ppException); unsigned int (* getJitFlags)(void * thisHandle, CorInfoException** ppException, void* flags, unsigned int sizeInBytes); + int (* getStringLength)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); }; @@ -1729,4 +1730,13 @@ class JitInterfaceWrapper return _ret; } + virtual int getStringLength(void* module, unsigned metaTOK) + { + CorInfoException* pException = nullptr; + int _ret = _callbacks->getStringLength(_thisHandle, &pException, module, metaTOK); + if (pException != nullptr) + throw pException; + return _ret; + } + }; From 9adda2ad358443b5a58da4513e571392f6ba6bce Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 7 Jan 2020 23:02:16 +0300 Subject: [PATCH 03/20] Implement the actual optimization --- src/coreclr/src/jit/importer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 01b67678038ac..41e3294686568 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3632,6 +3632,18 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, op1 = impPopStack().val; if (opts.OptimizationEnabled()) { + if (op1->OperIs(GT_CNS_STR)) + { + // Optimize `ldstr + String::get_Length()` to CNS_INT + // e.g. "Hello".Length => 5 + int len = info.compCompHnd->getStringLength( + op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX); + if (len >= 0) + { + retNode = gtNewIconNode(len); + break; + } + } GenTreeArrLen* arrLen = gtNewArrLen(TYP_INT, op1, OFFSETOF__CORINFO_String__stringLen); op1 = arrLen; } From 2776a5a2ce40293acef865fcc5b2011695924003 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 8 Jan 2020 00:58:38 +0300 Subject: [PATCH 04/20] Code formatting --- src/coreclr/src/jit/importer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 41e3294686568..caa65eecf14a1 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3636,8 +3636,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { // Optimize `ldstr + String::get_Length()` to CNS_INT // e.g. "Hello".Length => 5 - int len = info.compCompHnd->getStringLength( - op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX); + int len = info.compCompHnd->getStringLength(op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX); if (len >= 0) { retNode = gtNewIconNode(len); From faac68ecd2a1046e80e790fd7c9bd52047470911 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 8 Jan 2020 03:36:14 +0300 Subject: [PATCH 05/20] return -1 for crossgen2 (TODO: implement) --- src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index 12327dad55a9b..3bd09da1daccd 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1162,11 +1162,15 @@ private bool isValidToken(CORINFO_MODULE_STRUCT_* module, uint metaTOK) { throw new NotImplementedException("isValidToken"); } private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) { throw new NotImplementedException("isValidStringRef"); } - private int getStringLength(CORINFO_MODULE_STRUCT_* module, uint metaTOK) - { throw new NotImplementedException("getStringLength"); } private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } + private int getStringLength(CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { + // TODO: get length for string literal + return -1; + } + private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) { var type = HandleToObject(cls); From 5caee6198a97b9d2bef3a7586bf7c54ae4ba4c9f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 8 Jan 2020 15:49:38 +0300 Subject: [PATCH 06/20] Disable for R2R --- src/coreclr/src/jit/importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index caa65eecf14a1..0cbe249992312 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3632,7 +3632,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, op1 = impPopStack().val; if (opts.OptimizationEnabled()) { - if (op1->OperIs(GT_CNS_STR)) + if (!opts.IsReadyToRun() && op1->OperIs(GT_CNS_STR)) { // Optimize `ldstr + String::get_Length()` to CNS_INT // e.g. "Hello".Length => 5 From 0be9bbd9b07d711a5316d6b0b5f96cbad563d385 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 10 Jan 2020 03:33:24 +0300 Subject: [PATCH 07/20] remove `pString != nullptr` check (it's ok for empty strings) --- src/coreclr/src/jit/importer.cpp | 2 +- src/coreclr/src/vm/jitinterface.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 0cbe249992312..caa65eecf14a1 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3632,7 +3632,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, op1 = impPopStack().val; if (opts.OptimizationEnabled()) { - if (!opts.IsReadyToRun() && op1->OperIs(GT_CNS_STR)) + if (op1->OperIs(GT_CNS_STR)) { // Optimize `ldstr + String::get_Length()` to CNS_INT // e.g. "Hello".Length => 5 diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index 1d7549f2fb333..7fcaefcfa1698 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -822,8 +822,9 @@ int CEEInfo::getStringLength ( { DWORD dwCharCount; LPCWSTR pString; - if (!FAILED((module)->GetMDImport()->GetUserString(metaTOK, &dwCharCount, NULL, &pString)) && (pString != nullptr)) + if (!FAILED((module)->GetMDImport()->GetUserString(metaTOK, &dwCharCount, NULL, &pString))) { + // For string.Empty pString will be null length = dwCharCount; } else From e906aad5ace8626929d865e784a6823e20115a04 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 10 Jan 2020 04:40:54 +0300 Subject: [PATCH 08/20] does order matter? (in ThunkInput.txt) --- .../tools/Common/JitInterface/CorInfoBase.cs | 320 +++++++++--------- .../ThunkGenerator/ThunkInput.txt | 2 +- .../crossgen2/jitinterface/jitinterface.h | 20 +- src/coreclr/src/vm/dynamicmethod.cpp | 3 +- 4 files changed, 173 insertions(+), 172 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index bbf468bb5b2ba..48adec5764ea8 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -84,6 +84,8 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValidStringRef(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] + delegate int __getStringLength(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); + [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __shouldEnforceCallvirtRestriction(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate CorInfoType __asCorInfoType(IntPtr _this, IntPtr* ppException, CORINFO_CLASS_STRUCT_* cls); @@ -369,8 +371,6 @@ unsafe partial class CorInfoImpl delegate uint __getExpectedTargetArchitecture(IntPtr _this, IntPtr* ppException); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate uint __getJitFlags(IntPtr _this, IntPtr* ppException, ref CORJIT_FLAGS flags, uint sizeInBytes); - [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate int __getStringLength(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); static uint _getMethodAttribs(IntPtr thisHandle, IntPtr* ppException, CORINFO_METHOD_STRUCT_* ftn) { @@ -862,6 +862,20 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, } } + static int _getStringLength(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK) + { + var _this = GetThis(thisHandle); + try + { + return _this.getStringLength(module, metaTOK); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + return default(int); + } + } + [return: MarshalAs(UnmanagedType.Bool)]static bool _shouldEnforceCallvirtRestriction(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope) { var _this = GetThis(thisHandle); @@ -2832,20 +2846,6 @@ static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, ref CORJIT_FLAG } } - static int _getStringLength(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK) - { - var _this = GetThis(thisHandle); - try - { - return _this.getStringLength(module, metaTOK); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - return default(int); - } - } - static IntPtr GetUnmanagedCallbacks(out Object keepAlive) { @@ -2960,436 +2960,436 @@ static IntPtr GetUnmanagedCallbacks(out Object keepAlive) var d35 = new __isValidStringRef(_isValidStringRef); callbacks[35] = Marshal.GetFunctionPointerForDelegate(d35); delegates[35] = d35; - var d36 = new __shouldEnforceCallvirtRestriction(_shouldEnforceCallvirtRestriction); + var d36 = new __getStringLength(_getStringLength); callbacks[36] = Marshal.GetFunctionPointerForDelegate(d36); delegates[36] = d36; - var d37 = new __asCorInfoType(_asCorInfoType); + var d37 = new __shouldEnforceCallvirtRestriction(_shouldEnforceCallvirtRestriction); callbacks[37] = Marshal.GetFunctionPointerForDelegate(d37); delegates[37] = d37; - var d38 = new __getClassName(_getClassName); + var d38 = new __asCorInfoType(_asCorInfoType); callbacks[38] = Marshal.GetFunctionPointerForDelegate(d38); delegates[38] = d38; - var d39 = new __getClassNameFromMetadata(_getClassNameFromMetadata); + var d39 = new __getClassName(_getClassName); callbacks[39] = Marshal.GetFunctionPointerForDelegate(d39); delegates[39] = d39; - var d40 = new __getTypeInstantiationArgument(_getTypeInstantiationArgument); + var d40 = new __getClassNameFromMetadata(_getClassNameFromMetadata); callbacks[40] = Marshal.GetFunctionPointerForDelegate(d40); delegates[40] = d40; - var d41 = new __appendClassName(_appendClassName); + var d41 = new __getTypeInstantiationArgument(_getTypeInstantiationArgument); callbacks[41] = Marshal.GetFunctionPointerForDelegate(d41); delegates[41] = d41; - var d42 = new __isValueClass(_isValueClass); + var d42 = new __appendClassName(_appendClassName); callbacks[42] = Marshal.GetFunctionPointerForDelegate(d42); delegates[42] = d42; - var d43 = new __canInlineTypeCheck(_canInlineTypeCheck); + var d43 = new __isValueClass(_isValueClass); callbacks[43] = Marshal.GetFunctionPointerForDelegate(d43); delegates[43] = d43; - var d44 = new __canInlineTypeCheckWithObjectVTable(_canInlineTypeCheckWithObjectVTable); + var d44 = new __canInlineTypeCheck(_canInlineTypeCheck); callbacks[44] = Marshal.GetFunctionPointerForDelegate(d44); delegates[44] = d44; - var d45 = new __getClassAttribs(_getClassAttribs); + var d45 = new __canInlineTypeCheckWithObjectVTable(_canInlineTypeCheckWithObjectVTable); callbacks[45] = Marshal.GetFunctionPointerForDelegate(d45); delegates[45] = d45; - var d46 = new __isStructRequiringStackAllocRetBuf(_isStructRequiringStackAllocRetBuf); + var d46 = new __getClassAttribs(_getClassAttribs); callbacks[46] = Marshal.GetFunctionPointerForDelegate(d46); delegates[46] = d46; - var d47 = new __getClassModule(_getClassModule); + var d47 = new __isStructRequiringStackAllocRetBuf(_isStructRequiringStackAllocRetBuf); callbacks[47] = Marshal.GetFunctionPointerForDelegate(d47); delegates[47] = d47; - var d48 = new __getModuleAssembly(_getModuleAssembly); + var d48 = new __getClassModule(_getClassModule); callbacks[48] = Marshal.GetFunctionPointerForDelegate(d48); delegates[48] = d48; - var d49 = new __getAssemblyName(_getAssemblyName); + var d49 = new __getModuleAssembly(_getModuleAssembly); callbacks[49] = Marshal.GetFunctionPointerForDelegate(d49); delegates[49] = d49; - var d50 = new __LongLifetimeMalloc(_LongLifetimeMalloc); + var d50 = new __getAssemblyName(_getAssemblyName); callbacks[50] = Marshal.GetFunctionPointerForDelegate(d50); delegates[50] = d50; - var d51 = new __LongLifetimeFree(_LongLifetimeFree); + var d51 = new __LongLifetimeMalloc(_LongLifetimeMalloc); callbacks[51] = Marshal.GetFunctionPointerForDelegate(d51); delegates[51] = d51; - var d52 = new __getClassModuleIdForStatics(_getClassModuleIdForStatics); + var d52 = new __LongLifetimeFree(_LongLifetimeFree); callbacks[52] = Marshal.GetFunctionPointerForDelegate(d52); delegates[52] = d52; - var d53 = new __getClassSize(_getClassSize); + var d53 = new __getClassModuleIdForStatics(_getClassModuleIdForStatics); callbacks[53] = Marshal.GetFunctionPointerForDelegate(d53); delegates[53] = d53; - var d54 = new __getHeapClassSize(_getHeapClassSize); + var d54 = new __getClassSize(_getClassSize); callbacks[54] = Marshal.GetFunctionPointerForDelegate(d54); delegates[54] = d54; - var d55 = new __canAllocateOnStack(_canAllocateOnStack); + var d55 = new __getHeapClassSize(_getHeapClassSize); callbacks[55] = Marshal.GetFunctionPointerForDelegate(d55); delegates[55] = d55; - var d56 = new __getClassAlignmentRequirement(_getClassAlignmentRequirement); + var d56 = new __canAllocateOnStack(_canAllocateOnStack); callbacks[56] = Marshal.GetFunctionPointerForDelegate(d56); delegates[56] = d56; - var d57 = new __getClassGClayout(_getClassGClayout); + var d57 = new __getClassAlignmentRequirement(_getClassAlignmentRequirement); callbacks[57] = Marshal.GetFunctionPointerForDelegate(d57); delegates[57] = d57; - var d58 = new __getClassNumInstanceFields(_getClassNumInstanceFields); + var d58 = new __getClassGClayout(_getClassGClayout); callbacks[58] = Marshal.GetFunctionPointerForDelegate(d58); delegates[58] = d58; - var d59 = new __getFieldInClass(_getFieldInClass); + var d59 = new __getClassNumInstanceFields(_getClassNumInstanceFields); callbacks[59] = Marshal.GetFunctionPointerForDelegate(d59); delegates[59] = d59; - var d60 = new __checkMethodModifier(_checkMethodModifier); + var d60 = new __getFieldInClass(_getFieldInClass); callbacks[60] = Marshal.GetFunctionPointerForDelegate(d60); delegates[60] = d60; - var d61 = new __getNewHelper(_getNewHelper); + var d61 = new __checkMethodModifier(_checkMethodModifier); callbacks[61] = Marshal.GetFunctionPointerForDelegate(d61); delegates[61] = d61; - var d62 = new __getNewArrHelper(_getNewArrHelper); + var d62 = new __getNewHelper(_getNewHelper); callbacks[62] = Marshal.GetFunctionPointerForDelegate(d62); delegates[62] = d62; - var d63 = new __getCastingHelper(_getCastingHelper); + var d63 = new __getNewArrHelper(_getNewArrHelper); callbacks[63] = Marshal.GetFunctionPointerForDelegate(d63); delegates[63] = d63; - var d64 = new __getSharedCCtorHelper(_getSharedCCtorHelper); + var d64 = new __getCastingHelper(_getCastingHelper); callbacks[64] = Marshal.GetFunctionPointerForDelegate(d64); delegates[64] = d64; - var d65 = new __getSecurityPrologHelper(_getSecurityPrologHelper); + var d65 = new __getSharedCCtorHelper(_getSharedCCtorHelper); callbacks[65] = Marshal.GetFunctionPointerForDelegate(d65); delegates[65] = d65; - var d66 = new __getTypeForBox(_getTypeForBox); + var d66 = new __getSecurityPrologHelper(_getSecurityPrologHelper); callbacks[66] = Marshal.GetFunctionPointerForDelegate(d66); delegates[66] = d66; - var d67 = new __getBoxHelper(_getBoxHelper); + var d67 = new __getTypeForBox(_getTypeForBox); callbacks[67] = Marshal.GetFunctionPointerForDelegate(d67); delegates[67] = d67; - var d68 = new __getUnBoxHelper(_getUnBoxHelper); + var d68 = new __getBoxHelper(_getBoxHelper); callbacks[68] = Marshal.GetFunctionPointerForDelegate(d68); delegates[68] = d68; - var d69 = new __getReadyToRunHelper(_getReadyToRunHelper); + var d69 = new __getUnBoxHelper(_getUnBoxHelper); callbacks[69] = Marshal.GetFunctionPointerForDelegate(d69); delegates[69] = d69; - var d70 = new __getReadyToRunDelegateCtorHelper(_getReadyToRunDelegateCtorHelper); + var d70 = new __getReadyToRunHelper(_getReadyToRunHelper); callbacks[70] = Marshal.GetFunctionPointerForDelegate(d70); delegates[70] = d70; - var d71 = new __getHelperName(_getHelperName); + var d71 = new __getReadyToRunDelegateCtorHelper(_getReadyToRunDelegateCtorHelper); callbacks[71] = Marshal.GetFunctionPointerForDelegate(d71); delegates[71] = d71; - var d72 = new __initClass(_initClass); + var d72 = new __getHelperName(_getHelperName); callbacks[72] = Marshal.GetFunctionPointerForDelegate(d72); delegates[72] = d72; - var d73 = new __classMustBeLoadedBeforeCodeIsRun(_classMustBeLoadedBeforeCodeIsRun); + var d73 = new __initClass(_initClass); callbacks[73] = Marshal.GetFunctionPointerForDelegate(d73); delegates[73] = d73; - var d74 = new __getBuiltinClass(_getBuiltinClass); + var d74 = new __classMustBeLoadedBeforeCodeIsRun(_classMustBeLoadedBeforeCodeIsRun); callbacks[74] = Marshal.GetFunctionPointerForDelegate(d74); delegates[74] = d74; - var d75 = new __getTypeForPrimitiveValueClass(_getTypeForPrimitiveValueClass); + var d75 = new __getBuiltinClass(_getBuiltinClass); callbacks[75] = Marshal.GetFunctionPointerForDelegate(d75); delegates[75] = d75; - var d76 = new __getTypeForPrimitiveNumericClass(_getTypeForPrimitiveNumericClass); + var d76 = new __getTypeForPrimitiveValueClass(_getTypeForPrimitiveValueClass); callbacks[76] = Marshal.GetFunctionPointerForDelegate(d76); delegates[76] = d76; - var d77 = new __canCast(_canCast); + var d77 = new __getTypeForPrimitiveNumericClass(_getTypeForPrimitiveNumericClass); callbacks[77] = Marshal.GetFunctionPointerForDelegate(d77); delegates[77] = d77; - var d78 = new __areTypesEquivalent(_areTypesEquivalent); + var d78 = new __canCast(_canCast); callbacks[78] = Marshal.GetFunctionPointerForDelegate(d78); delegates[78] = d78; - var d79 = new __compareTypesForCast(_compareTypesForCast); + var d79 = new __areTypesEquivalent(_areTypesEquivalent); callbacks[79] = Marshal.GetFunctionPointerForDelegate(d79); delegates[79] = d79; - var d80 = new __compareTypesForEquality(_compareTypesForEquality); + var d80 = new __compareTypesForCast(_compareTypesForCast); callbacks[80] = Marshal.GetFunctionPointerForDelegate(d80); delegates[80] = d80; - var d81 = new __mergeClasses(_mergeClasses); + var d81 = new __compareTypesForEquality(_compareTypesForEquality); callbacks[81] = Marshal.GetFunctionPointerForDelegate(d81); delegates[81] = d81; - var d82 = new __isMoreSpecificType(_isMoreSpecificType); + var d82 = new __mergeClasses(_mergeClasses); callbacks[82] = Marshal.GetFunctionPointerForDelegate(d82); delegates[82] = d82; - var d83 = new __getParentType(_getParentType); + var d83 = new __isMoreSpecificType(_isMoreSpecificType); callbacks[83] = Marshal.GetFunctionPointerForDelegate(d83); delegates[83] = d83; - var d84 = new __getChildType(_getChildType); + var d84 = new __getParentType(_getParentType); callbacks[84] = Marshal.GetFunctionPointerForDelegate(d84); delegates[84] = d84; - var d85 = new __satisfiesClassConstraints(_satisfiesClassConstraints); + var d85 = new __getChildType(_getChildType); callbacks[85] = Marshal.GetFunctionPointerForDelegate(d85); delegates[85] = d85; - var d86 = new __isSDArray(_isSDArray); + var d86 = new __satisfiesClassConstraints(_satisfiesClassConstraints); callbacks[86] = Marshal.GetFunctionPointerForDelegate(d86); delegates[86] = d86; - var d87 = new __getArrayRank(_getArrayRank); + var d87 = new __isSDArray(_isSDArray); callbacks[87] = Marshal.GetFunctionPointerForDelegate(d87); delegates[87] = d87; - var d88 = new __getArrayInitializationData(_getArrayInitializationData); + var d88 = new __getArrayRank(_getArrayRank); callbacks[88] = Marshal.GetFunctionPointerForDelegate(d88); delegates[88] = d88; - var d89 = new __canAccessClass(_canAccessClass); + var d89 = new __getArrayInitializationData(_getArrayInitializationData); callbacks[89] = Marshal.GetFunctionPointerForDelegate(d89); delegates[89] = d89; - var d90 = new __getFieldName(_getFieldName); + var d90 = new __canAccessClass(_canAccessClass); callbacks[90] = Marshal.GetFunctionPointerForDelegate(d90); delegates[90] = d90; - var d91 = new __getFieldClass(_getFieldClass); + var d91 = new __getFieldName(_getFieldName); callbacks[91] = Marshal.GetFunctionPointerForDelegate(d91); delegates[91] = d91; - var d92 = new __getFieldType(_getFieldType); + var d92 = new __getFieldClass(_getFieldClass); callbacks[92] = Marshal.GetFunctionPointerForDelegate(d92); delegates[92] = d92; - var d93 = new __getFieldOffset(_getFieldOffset); + var d93 = new __getFieldType(_getFieldType); callbacks[93] = Marshal.GetFunctionPointerForDelegate(d93); delegates[93] = d93; - var d94 = new __isWriteBarrierHelperRequired(_isWriteBarrierHelperRequired); + var d94 = new __getFieldOffset(_getFieldOffset); callbacks[94] = Marshal.GetFunctionPointerForDelegate(d94); delegates[94] = d94; - var d95 = new __getFieldInfo(_getFieldInfo); + var d95 = new __isWriteBarrierHelperRequired(_isWriteBarrierHelperRequired); callbacks[95] = Marshal.GetFunctionPointerForDelegate(d95); delegates[95] = d95; - var d96 = new __isFieldStatic(_isFieldStatic); + var d96 = new __getFieldInfo(_getFieldInfo); callbacks[96] = Marshal.GetFunctionPointerForDelegate(d96); delegates[96] = d96; - var d97 = new __getBoundaries(_getBoundaries); + var d97 = new __isFieldStatic(_isFieldStatic); callbacks[97] = Marshal.GetFunctionPointerForDelegate(d97); delegates[97] = d97; - var d98 = new __setBoundaries(_setBoundaries); + var d98 = new __getBoundaries(_getBoundaries); callbacks[98] = Marshal.GetFunctionPointerForDelegate(d98); delegates[98] = d98; - var d99 = new __getVars(_getVars); + var d99 = new __setBoundaries(_setBoundaries); callbacks[99] = Marshal.GetFunctionPointerForDelegate(d99); delegates[99] = d99; - var d100 = new __setVars(_setVars); + var d100 = new __getVars(_getVars); callbacks[100] = Marshal.GetFunctionPointerForDelegate(d100); delegates[100] = d100; - var d101 = new __allocateArray(_allocateArray); + var d101 = new __setVars(_setVars); callbacks[101] = Marshal.GetFunctionPointerForDelegate(d101); delegates[101] = d101; - var d102 = new __freeArray(_freeArray); + var d102 = new __allocateArray(_allocateArray); callbacks[102] = Marshal.GetFunctionPointerForDelegate(d102); delegates[102] = d102; - var d103 = new __getArgNext(_getArgNext); + var d103 = new __freeArray(_freeArray); callbacks[103] = Marshal.GetFunctionPointerForDelegate(d103); delegates[103] = d103; - var d104 = new __getArgType(_getArgType); + var d104 = new __getArgNext(_getArgNext); callbacks[104] = Marshal.GetFunctionPointerForDelegate(d104); delegates[104] = d104; - var d105 = new __getArgClass(_getArgClass); + var d105 = new __getArgType(_getArgType); callbacks[105] = Marshal.GetFunctionPointerForDelegate(d105); delegates[105] = d105; - var d106 = new __getHFAType(_getHFAType); + var d106 = new __getArgClass(_getArgClass); callbacks[106] = Marshal.GetFunctionPointerForDelegate(d106); delegates[106] = d106; - var d107 = new __GetErrorHRESULT(_GetErrorHRESULT); + var d107 = new __getHFAType(_getHFAType); callbacks[107] = Marshal.GetFunctionPointerForDelegate(d107); delegates[107] = d107; - var d108 = new __GetErrorMessage(_GetErrorMessage); + var d108 = new __GetErrorHRESULT(_GetErrorHRESULT); callbacks[108] = Marshal.GetFunctionPointerForDelegate(d108); delegates[108] = d108; - var d109 = new __FilterException(_FilterException); + var d109 = new __GetErrorMessage(_GetErrorMessage); callbacks[109] = Marshal.GetFunctionPointerForDelegate(d109); delegates[109] = d109; - var d110 = new __HandleException(_HandleException); + var d110 = new __FilterException(_FilterException); callbacks[110] = Marshal.GetFunctionPointerForDelegate(d110); delegates[110] = d110; - var d111 = new __ThrowExceptionForJitResult(_ThrowExceptionForJitResult); + var d111 = new __HandleException(_HandleException); callbacks[111] = Marshal.GetFunctionPointerForDelegate(d111); delegates[111] = d111; - var d112 = new __ThrowExceptionForHelper(_ThrowExceptionForHelper); + var d112 = new __ThrowExceptionForJitResult(_ThrowExceptionForJitResult); callbacks[112] = Marshal.GetFunctionPointerForDelegate(d112); delegates[112] = d112; - var d113 = new __runWithErrorTrap(_runWithErrorTrap); + var d113 = new __ThrowExceptionForHelper(_ThrowExceptionForHelper); callbacks[113] = Marshal.GetFunctionPointerForDelegate(d113); delegates[113] = d113; - var d114 = new __getEEInfo(_getEEInfo); + var d114 = new __runWithErrorTrap(_runWithErrorTrap); callbacks[114] = Marshal.GetFunctionPointerForDelegate(d114); delegates[114] = d114; - var d115 = new __getJitTimeLogFilename(_getJitTimeLogFilename); + var d115 = new __getEEInfo(_getEEInfo); callbacks[115] = Marshal.GetFunctionPointerForDelegate(d115); delegates[115] = d115; - var d116 = new __getMethodDefFromMethod(_getMethodDefFromMethod); + var d116 = new __getJitTimeLogFilename(_getJitTimeLogFilename); callbacks[116] = Marshal.GetFunctionPointerForDelegate(d116); delegates[116] = d116; - var d117 = new __getMethodName(_getMethodName); + var d117 = new __getMethodDefFromMethod(_getMethodDefFromMethod); callbacks[117] = Marshal.GetFunctionPointerForDelegate(d117); delegates[117] = d117; - var d118 = new __getMethodNameFromMetadata(_getMethodNameFromMetadata); + var d118 = new __getMethodName(_getMethodName); callbacks[118] = Marshal.GetFunctionPointerForDelegate(d118); delegates[118] = d118; - var d119 = new __getMethodHash(_getMethodHash); + var d119 = new __getMethodNameFromMetadata(_getMethodNameFromMetadata); callbacks[119] = Marshal.GetFunctionPointerForDelegate(d119); delegates[119] = d119; - var d120 = new __findNameOfToken(_findNameOfToken); + var d120 = new __getMethodHash(_getMethodHash); callbacks[120] = Marshal.GetFunctionPointerForDelegate(d120); delegates[120] = d120; - var d121 = new __getSystemVAmd64PassStructInRegisterDescriptor(_getSystemVAmd64PassStructInRegisterDescriptor); + var d121 = new __findNameOfToken(_findNameOfToken); callbacks[121] = Marshal.GetFunctionPointerForDelegate(d121); delegates[121] = d121; - var d122 = new __getThreadTLSIndex(_getThreadTLSIndex); + var d122 = new __getSystemVAmd64PassStructInRegisterDescriptor(_getSystemVAmd64PassStructInRegisterDescriptor); callbacks[122] = Marshal.GetFunctionPointerForDelegate(d122); delegates[122] = d122; - var d123 = new __getInlinedCallFrameVptr(_getInlinedCallFrameVptr); + var d123 = new __getThreadTLSIndex(_getThreadTLSIndex); callbacks[123] = Marshal.GetFunctionPointerForDelegate(d123); delegates[123] = d123; - var d124 = new __getAddrOfCaptureThreadGlobal(_getAddrOfCaptureThreadGlobal); + var d124 = new __getInlinedCallFrameVptr(_getInlinedCallFrameVptr); callbacks[124] = Marshal.GetFunctionPointerForDelegate(d124); delegates[124] = d124; - var d125 = new __getHelperFtn(_getHelperFtn); + var d125 = new __getAddrOfCaptureThreadGlobal(_getAddrOfCaptureThreadGlobal); callbacks[125] = Marshal.GetFunctionPointerForDelegate(d125); delegates[125] = d125; - var d126 = new __getFunctionEntryPoint(_getFunctionEntryPoint); + var d126 = new __getHelperFtn(_getHelperFtn); callbacks[126] = Marshal.GetFunctionPointerForDelegate(d126); delegates[126] = d126; - var d127 = new __getFunctionFixedEntryPoint(_getFunctionFixedEntryPoint); + var d127 = new __getFunctionEntryPoint(_getFunctionEntryPoint); callbacks[127] = Marshal.GetFunctionPointerForDelegate(d127); delegates[127] = d127; - var d128 = new __getMethodSync(_getMethodSync); + var d128 = new __getFunctionFixedEntryPoint(_getFunctionFixedEntryPoint); callbacks[128] = Marshal.GetFunctionPointerForDelegate(d128); delegates[128] = d128; - var d129 = new __getLazyStringLiteralHelper(_getLazyStringLiteralHelper); + var d129 = new __getMethodSync(_getMethodSync); callbacks[129] = Marshal.GetFunctionPointerForDelegate(d129); delegates[129] = d129; - var d130 = new __embedModuleHandle(_embedModuleHandle); + var d130 = new __getLazyStringLiteralHelper(_getLazyStringLiteralHelper); callbacks[130] = Marshal.GetFunctionPointerForDelegate(d130); delegates[130] = d130; - var d131 = new __embedClassHandle(_embedClassHandle); + var d131 = new __embedModuleHandle(_embedModuleHandle); callbacks[131] = Marshal.GetFunctionPointerForDelegate(d131); delegates[131] = d131; - var d132 = new __embedMethodHandle(_embedMethodHandle); + var d132 = new __embedClassHandle(_embedClassHandle); callbacks[132] = Marshal.GetFunctionPointerForDelegate(d132); delegates[132] = d132; - var d133 = new __embedFieldHandle(_embedFieldHandle); + var d133 = new __embedMethodHandle(_embedMethodHandle); callbacks[133] = Marshal.GetFunctionPointerForDelegate(d133); delegates[133] = d133; - var d134 = new __embedGenericHandle(_embedGenericHandle); + var d134 = new __embedFieldHandle(_embedFieldHandle); callbacks[134] = Marshal.GetFunctionPointerForDelegate(d134); delegates[134] = d134; - var d135 = new __getLocationOfThisType(_getLocationOfThisType); + var d135 = new __embedGenericHandle(_embedGenericHandle); callbacks[135] = Marshal.GetFunctionPointerForDelegate(d135); delegates[135] = d135; - var d136 = new __getPInvokeUnmanagedTarget(_getPInvokeUnmanagedTarget); + var d136 = new __getLocationOfThisType(_getLocationOfThisType); callbacks[136] = Marshal.GetFunctionPointerForDelegate(d136); delegates[136] = d136; - var d137 = new __getAddressOfPInvokeFixup(_getAddressOfPInvokeFixup); + var d137 = new __getPInvokeUnmanagedTarget(_getPInvokeUnmanagedTarget); callbacks[137] = Marshal.GetFunctionPointerForDelegate(d137); delegates[137] = d137; - var d138 = new __getAddressOfPInvokeTarget(_getAddressOfPInvokeTarget); + var d138 = new __getAddressOfPInvokeFixup(_getAddressOfPInvokeFixup); callbacks[138] = Marshal.GetFunctionPointerForDelegate(d138); delegates[138] = d138; - var d139 = new __GetCookieForPInvokeCalliSig(_GetCookieForPInvokeCalliSig); + var d139 = new __getAddressOfPInvokeTarget(_getAddressOfPInvokeTarget); callbacks[139] = Marshal.GetFunctionPointerForDelegate(d139); delegates[139] = d139; - var d140 = new __canGetCookieForPInvokeCalliSig(_canGetCookieForPInvokeCalliSig); + var d140 = new __GetCookieForPInvokeCalliSig(_GetCookieForPInvokeCalliSig); callbacks[140] = Marshal.GetFunctionPointerForDelegate(d140); delegates[140] = d140; - var d141 = new __getJustMyCodeHandle(_getJustMyCodeHandle); + var d141 = new __canGetCookieForPInvokeCalliSig(_canGetCookieForPInvokeCalliSig); callbacks[141] = Marshal.GetFunctionPointerForDelegate(d141); delegates[141] = d141; - var d142 = new __GetProfilingHandle(_GetProfilingHandle); + var d142 = new __getJustMyCodeHandle(_getJustMyCodeHandle); callbacks[142] = Marshal.GetFunctionPointerForDelegate(d142); delegates[142] = d142; - var d143 = new __getCallInfo(_getCallInfo); + var d143 = new __GetProfilingHandle(_GetProfilingHandle); callbacks[143] = Marshal.GetFunctionPointerForDelegate(d143); delegates[143] = d143; - var d144 = new __canAccessFamily(_canAccessFamily); + var d144 = new __getCallInfo(_getCallInfo); callbacks[144] = Marshal.GetFunctionPointerForDelegate(d144); delegates[144] = d144; - var d145 = new __isRIDClassDomainID(_isRIDClassDomainID); + var d145 = new __canAccessFamily(_canAccessFamily); callbacks[145] = Marshal.GetFunctionPointerForDelegate(d145); delegates[145] = d145; - var d146 = new __getClassDomainID(_getClassDomainID); + var d146 = new __isRIDClassDomainID(_isRIDClassDomainID); callbacks[146] = Marshal.GetFunctionPointerForDelegate(d146); delegates[146] = d146; - var d147 = new __getFieldAddress(_getFieldAddress); + var d147 = new __getClassDomainID(_getClassDomainID); callbacks[147] = Marshal.GetFunctionPointerForDelegate(d147); delegates[147] = d147; - var d148 = new __getStaticFieldCurrentClass(_getStaticFieldCurrentClass); + var d148 = new __getFieldAddress(_getFieldAddress); callbacks[148] = Marshal.GetFunctionPointerForDelegate(d148); delegates[148] = d148; - var d149 = new __getVarArgsHandle(_getVarArgsHandle); + var d149 = new __getStaticFieldCurrentClass(_getStaticFieldCurrentClass); callbacks[149] = Marshal.GetFunctionPointerForDelegate(d149); delegates[149] = d149; - var d150 = new __canGetVarArgsHandle(_canGetVarArgsHandle); + var d150 = new __getVarArgsHandle(_getVarArgsHandle); callbacks[150] = Marshal.GetFunctionPointerForDelegate(d150); delegates[150] = d150; - var d151 = new __constructStringLiteral(_constructStringLiteral); + var d151 = new __canGetVarArgsHandle(_canGetVarArgsHandle); callbacks[151] = Marshal.GetFunctionPointerForDelegate(d151); delegates[151] = d151; - var d152 = new __emptyStringLiteral(_emptyStringLiteral); + var d152 = new __constructStringLiteral(_constructStringLiteral); callbacks[152] = Marshal.GetFunctionPointerForDelegate(d152); delegates[152] = d152; - var d153 = new __getFieldThreadLocalStoreID(_getFieldThreadLocalStoreID); + var d153 = new __emptyStringLiteral(_emptyStringLiteral); callbacks[153] = Marshal.GetFunctionPointerForDelegate(d153); delegates[153] = d153; - var d154 = new __setOverride(_setOverride); + var d154 = new __getFieldThreadLocalStoreID(_getFieldThreadLocalStoreID); callbacks[154] = Marshal.GetFunctionPointerForDelegate(d154); delegates[154] = d154; - var d155 = new __addActiveDependency(_addActiveDependency); + var d155 = new __setOverride(_setOverride); callbacks[155] = Marshal.GetFunctionPointerForDelegate(d155); delegates[155] = d155; - var d156 = new __GetDelegateCtor(_GetDelegateCtor); + var d156 = new __addActiveDependency(_addActiveDependency); callbacks[156] = Marshal.GetFunctionPointerForDelegate(d156); delegates[156] = d156; - var d157 = new __MethodCompileComplete(_MethodCompileComplete); + var d157 = new __GetDelegateCtor(_GetDelegateCtor); callbacks[157] = Marshal.GetFunctionPointerForDelegate(d157); delegates[157] = d157; - var d158 = new __getTailCallCopyArgsThunk(_getTailCallCopyArgsThunk); + var d158 = new __MethodCompileComplete(_MethodCompileComplete); callbacks[158] = Marshal.GetFunctionPointerForDelegate(d158); delegates[158] = d158; - var d159 = new __convertPInvokeCalliToCall(_convertPInvokeCalliToCall); + var d159 = new __getTailCallCopyArgsThunk(_getTailCallCopyArgsThunk); callbacks[159] = Marshal.GetFunctionPointerForDelegate(d159); delegates[159] = d159; - var d160 = new __getMemoryManager(_getMemoryManager); + var d160 = new __convertPInvokeCalliToCall(_convertPInvokeCalliToCall); callbacks[160] = Marshal.GetFunctionPointerForDelegate(d160); delegates[160] = d160; - var d161 = new __allocMem(_allocMem); + var d161 = new __getMemoryManager(_getMemoryManager); callbacks[161] = Marshal.GetFunctionPointerForDelegate(d161); delegates[161] = d161; - var d162 = new __reserveUnwindInfo(_reserveUnwindInfo); + var d162 = new __allocMem(_allocMem); callbacks[162] = Marshal.GetFunctionPointerForDelegate(d162); delegates[162] = d162; - var d163 = new __allocUnwindInfo(_allocUnwindInfo); + var d163 = new __reserveUnwindInfo(_reserveUnwindInfo); callbacks[163] = Marshal.GetFunctionPointerForDelegate(d163); delegates[163] = d163; - var d164 = new __allocGCInfo(_allocGCInfo); + var d164 = new __allocUnwindInfo(_allocUnwindInfo); callbacks[164] = Marshal.GetFunctionPointerForDelegate(d164); delegates[164] = d164; - var d165 = new __yieldExecution(_yieldExecution); + var d165 = new __allocGCInfo(_allocGCInfo); callbacks[165] = Marshal.GetFunctionPointerForDelegate(d165); delegates[165] = d165; - var d166 = new __setEHcount(_setEHcount); + var d166 = new __yieldExecution(_yieldExecution); callbacks[166] = Marshal.GetFunctionPointerForDelegate(d166); delegates[166] = d166; - var d167 = new __setEHinfo(_setEHinfo); + var d167 = new __setEHcount(_setEHcount); callbacks[167] = Marshal.GetFunctionPointerForDelegate(d167); delegates[167] = d167; - var d168 = new __logMsg(_logMsg); + var d168 = new __setEHinfo(_setEHinfo); callbacks[168] = Marshal.GetFunctionPointerForDelegate(d168); delegates[168] = d168; - var d169 = new __doAssert(_doAssert); + var d169 = new __logMsg(_logMsg); callbacks[169] = Marshal.GetFunctionPointerForDelegate(d169); delegates[169] = d169; - var d170 = new __reportFatalError(_reportFatalError); + var d170 = new __doAssert(_doAssert); callbacks[170] = Marshal.GetFunctionPointerForDelegate(d170); delegates[170] = d170; - var d171 = new __allocMethodBlockCounts(_allocMethodBlockCounts); + var d171 = new __reportFatalError(_reportFatalError); callbacks[171] = Marshal.GetFunctionPointerForDelegate(d171); delegates[171] = d171; - var d172 = new __getMethodBlockCounts(_getMethodBlockCounts); + var d172 = new __allocMethodBlockCounts(_allocMethodBlockCounts); callbacks[172] = Marshal.GetFunctionPointerForDelegate(d172); delegates[172] = d172; - var d173 = new __recordCallSite(_recordCallSite); + var d173 = new __getMethodBlockCounts(_getMethodBlockCounts); callbacks[173] = Marshal.GetFunctionPointerForDelegate(d173); delegates[173] = d173; - var d174 = new __recordRelocation(_recordRelocation); + var d174 = new __recordCallSite(_recordCallSite); callbacks[174] = Marshal.GetFunctionPointerForDelegate(d174); delegates[174] = d174; - var d175 = new __getRelocTypeHint(_getRelocTypeHint); + var d175 = new __recordRelocation(_recordRelocation); callbacks[175] = Marshal.GetFunctionPointerForDelegate(d175); delegates[175] = d175; - var d176 = new __getModuleNativeEntryPointRange(_getModuleNativeEntryPointRange); + var d176 = new __getRelocTypeHint(_getRelocTypeHint); callbacks[176] = Marshal.GetFunctionPointerForDelegate(d176); delegates[176] = d176; - var d177 = new __getExpectedTargetArchitecture(_getExpectedTargetArchitecture); + var d177 = new __getModuleNativeEntryPointRange(_getModuleNativeEntryPointRange); callbacks[177] = Marshal.GetFunctionPointerForDelegate(d177); delegates[177] = d177; - var d178 = new __getJitFlags(_getJitFlags); + var d178 = new __getExpectedTargetArchitecture(_getExpectedTargetArchitecture); callbacks[178] = Marshal.GetFunctionPointerForDelegate(d178); delegates[178] = d178; - var d179 = new __getStringLength(_getStringLength); + var d179 = new __getJitFlags(_getJitFlags); callbacks[179] = Marshal.GetFunctionPointerForDelegate(d179); delegates[179] = d179; diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index eba1e00de37f7..3798a1150306e 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -199,6 +199,7 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) + int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) @@ -342,4 +343,3 @@ FUNCTIONS void getModuleNativeEntryPointRange(void** pStart, void** pEnd) DWORD getExpectedTargetArchitecture() DWORD getJitFlags(CORJIT_FLAGS* flags, DWORD sizeInBytes) - int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h index 4b378ee1fc905..960d3cdc716b7 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h @@ -46,6 +46,7 @@ struct JitInterfaceCallbacks int (* canSkipVerification)(void * thisHandle, CorInfoException** ppException, void* module); int (* isValidToken)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); int (* isValidStringRef)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); + int (* getStringLength)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); int (* shouldEnforceCallvirtRestriction)(void * thisHandle, CorInfoException** ppException, void* scope); int (* asCorInfoType)(void * thisHandle, CorInfoException** ppException, void* cls); const char* (* getClassName)(void * thisHandle, CorInfoException** ppException, void* cls); @@ -189,7 +190,6 @@ struct JitInterfaceCallbacks void (* getModuleNativeEntryPointRange)(void * thisHandle, CorInfoException** ppException, void** pStart, void** pEnd); unsigned int (* getExpectedTargetArchitecture)(void * thisHandle, CorInfoException** ppException); unsigned int (* getJitFlags)(void * thisHandle, CorInfoException** ppException, void* flags, unsigned int sizeInBytes); - int (* getStringLength)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); }; @@ -514,6 +514,15 @@ class JitInterfaceWrapper return _ret; } + virtual int getStringLength(void* module, unsigned metaTOK) + { + CorInfoException* pException = nullptr; + int _ret = _callbacks->getStringLength(_thisHandle, &pException, module, metaTOK); + if (pException != nullptr) + throw pException; + return _ret; + } + virtual int shouldEnforceCallvirtRestriction(void* scope) { CorInfoException* pException = nullptr; @@ -1730,13 +1739,4 @@ class JitInterfaceWrapper return _ret; } - virtual int getStringLength(void* module, unsigned metaTOK) - { - CorInfoException* pException = nullptr; - int _ret = _callbacks->getStringLength(_thisHandle, &pException, module, metaTOK); - if (pException != nullptr) - throw pException; - return _ret; - } - }; diff --git a/src/coreclr/src/vm/dynamicmethod.cpp b/src/coreclr/src/vm/dynamicmethod.cpp index 52a8b448369e8..7818556ef6e5a 100644 --- a/src/coreclr/src/vm/dynamicmethod.cpp +++ b/src/coreclr/src/vm/dynamicmethod.cpp @@ -1204,7 +1204,8 @@ LCGMethodResolver::GetStringLength(mdToken metaTok) GCX_COOP(); - return GetStringLiteral(metaTok)->GetStringLength(); + STRINGREF str = GetStringLiteral(metaTok); + return str == NULL ? - 1 : str->GetStringLength(); } //--------------------------------------------------------------------------------------- From 286d7a976bb8d529f363b8df866df393fcdce7c2 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jan 2020 03:35:57 +0300 Subject: [PATCH 09/20] Rename to GetStringLiteral --- .../superpmi-shared/icorjitinfoimpl.h | 7 +-- .../superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi-shared/methodcontext.cpp | 44 +++++++++++++++---- .../superpmi/superpmi-shared/methodcontext.h | 8 ++-- .../superpmi-shim-collector/icorjitinfo.cpp | 13 +++--- .../superpmi-shim-counter/icorjitinfo.cpp | 11 ++--- .../superpmi-shim-simple/icorjitinfo.cpp | 9 ++-- .../ToolBox/superpmi/superpmi/icorjitinfo.cpp | 11 ++--- src/coreclr/src/inc/corinfo.h | 5 ++- src/coreclr/src/jit/ICorJitInfo_API_names.h | 2 +- .../src/jit/ICorJitInfo_API_wrapper.hpp | 11 ++--- src/coreclr/src/jit/importer.cpp | 8 ++-- .../tools/Common/JitInterface/CorInfoBase.cs | 10 ++--- .../tools/Common/JitInterface/CorInfoImpl.cs | 6 +-- .../ThunkGenerator/ThunkInput.txt | 2 +- .../crossgen2/jitinterface/jitinterface.h | 6 +-- src/coreclr/src/vm/dynamicmethod.cpp | 17 +++++-- src/coreclr/src/vm/dynamicmethod.h | 4 +- src/coreclr/src/vm/ilstubresolver.cpp | 5 ++- src/coreclr/src/vm/ilstubresolver.h | 2 +- src/coreclr/src/vm/jitinterface.cpp | 17 ++++--- src/coreclr/src/vm/jitinterface.h | 5 ++- src/coreclr/src/zap/zapinfo.cpp | 7 +-- src/coreclr/src/zap/zapinfo.h | 5 ++- 24 files changed, 135 insertions(+), 82 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h index e597b198f84ac..2607236107705 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/icorjitinfoimpl.h @@ -255,9 +255,10 @@ BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ unsigned metaTOK /* IN */ ); -int getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ - ); +LPCWSTR getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ + ); BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope); diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h index e024655086e98..59ebf7f35e7ba 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/lwmlist.h @@ -147,7 +147,7 @@ LWM(IsInstantiationOfVerifiedGeneric, DWORDLONG, DWORD) LWM(IsSDArray, DWORDLONG, DWORD) LWM(IsStructRequiringStackAllocRetBuf, DWORDLONG, DWORD) LWM(IsValidStringRef, DLD, DWORD) -LWM(GetStringLength, DLD, DWORD) +LWM(GetStringLiteral, DLD, DD) LWM(IsValidToken, DLD, DWORD) LWM(IsValueClass, DWORDLONG, DWORD) LWM(IsWriteBarrierHelperRequired, DWORDLONG, DWORD) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index f7bc993f2c870..2c4a8cc540b0a 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -4606,10 +4606,11 @@ BOOL MethodContext::repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned m return value; } -void MethodContext::recGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int result) + +void MethodContext::recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, LPCWSTR result) { - if (GetStringLength == nullptr) - GetStringLength = new LightWeightMap(); + if (GetStringLiteral == nullptr) + GetStringLiteral = new LightWeightMap(); DLD key; ZeroMemory(&key, sizeof(DLD)); // We use the input structs as a key and use memcmp to compare.. so we need to zero @@ -4618,16 +4619,31 @@ void MethodContext::recGetStringLength(CORINFO_MODULE_HANDLE module, unsigned me key.A = (DWORDLONG)module; key.B = (DWORD)metaTOK; - GetStringLength->Add(key, (DWORD)result); + DWORD strBuf = (DWORD)-1; + if (result != nullptr) + strBuf = (DWORD)GetStringLiteral->AddBuffer((unsigned char*)result, (unsigned int)((wcslen(result) * 2) + 2)); + + DD value; + value.A = (DWORD)length; + value.B = (DWORD)strBuf; + + GetStringLiteral->Add(key, value); } -void MethodContext::dmpGetStringLength(DLD key, DWORD value) +void MethodContext::dmpGetStringLiteral(DLD key, DD value) { - printf("GetStringLength key mod-%016llX tok-%08X, value res-%u", key.A, key.B, value); + printf("GetStringLiteral key mod-%016llX tok-%08X, result-%ls, len-%u", key.A, key.B, + (LPCWSTR)GetStringLiteral->GetBuffer(value.B), value.A); } -int MethodContext::repGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) +LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) { + if (GetStringLiteral == nullptr) + { + *length = -1; + return L"hackishStringLiteral"; + } + DLD key; ZeroMemory(&key, sizeof(DLD)); // We use the input structs as a key and use memcmp to compare.. so we need to zero // out padding too @@ -4635,8 +4651,18 @@ int MethodContext::repGetStringLength(CORINFO_MODULE_HANDLE module, unsigned met key.A = (DWORDLONG)module; key.B = (DWORD)metaTOK; - int value = (int)GetStringLength->Get(key); - return value; + int itemIndex = GetStringLiteral->GetIndex(key); + if (itemIndex < 0) + { + *length = -1; + return L"hackishStringLiteral"; + } + else + { + DD result = GetStringLiteral->Get(key); + *length = (int)result.A; + return (LPCWSTR)GetStringLiteral->GetBuffer(itemIndex); + } } void MethodContext::recGetHelperName(CorInfoHelpFunc funcNum, const char* result) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h index 0e7a3e3b727a2..3c1c4792d96a4 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.h @@ -1086,9 +1086,9 @@ class MethodContext void dmpIsValidStringRef(DLD key, DWORD value); BOOL repIsValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK); - void recGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int result); - void dmpGetStringLength(DLD key, DWORD value); - int repGetStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK); + void recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int length, LPCWSTR result); + void dmpGetStringLiteral(DLD key, DD value); + LPCWSTR repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length); void recGetHelperName(CorInfoHelpFunc funcNum, const char* result); void dmpGetHelperName(DWORD key, DWORD value); @@ -1497,7 +1497,7 @@ enum mcPackets Packet_IsSDArray = 101, Packet_IsStructRequiringStackAllocRetBuf = 102, Packet_IsValidStringRef = 103, - Packet_GetStringLength = 175, // Added 1/7/2020 + Packet_GetStringLiteral = 175, // Added 1/7/2020 Retired6 = 104, Packet_IsValidToken = 144, // Added 7/19/2013 - adjusted members to proper types Packet_IsValueClass = 105, diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 33d2e28c9f2b9..24fd670db10d7 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -517,13 +517,14 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return temp; } -int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ - ) +LPCWSTR interceptor_ICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ + ) { - mc->cr->AddCall("getStringLength"); - int temp = original_ICorJitInfo->getStringLength(module, metaTOK); - mc->recGetStringLength(module, metaTOK, temp); + mc->cr->AddCall("getStringLiteral"); + LPCWSTR temp = original_ICorJitInfo->getStringLiteral(module, metaTOK, length); + mc->recGetStringLiteral(module, metaTOK, *length, temp); return temp; } diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp index 5cb5d7d068e35..a753033abf7eb 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp @@ -378,12 +378,13 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return original_ICorJitInfo->isValidStringRef(module, metaTOK); } -int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ - ) +LPCWSTR interceptor_ICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ + ) { - mcs->AddCall("getStringLength"); - return original_ICorJitInfo->getStringLength(module, metaTOK); + mcs->AddCall("getStringLiteral"); + return original_ICorJitInfo->getStringLiteral(module, metaTOK, length); } BOOL interceptor_ICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp index 0153e53f5406f..e0db803d30b05 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp @@ -340,11 +340,12 @@ BOOL interceptor_ICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return original_ICorJitInfo->isValidStringRef(module, metaTOK); } -int interceptor_ICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ - ) +LPCWSTR interceptor_ICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ + ) { - return original_ICorJitInfo->getStringLength(module, metaTOK); + return original_ICorJitInfo->getStringLiteral(module, metaTOK, length); } BOOL interceptor_ICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp index 1c3675ea44473..b95d88fcecd7d 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi/icorjitinfo.cpp @@ -408,12 +408,13 @@ BOOL MyICJI::isValidStringRef(CORINFO_MODULE_HANDLE module, /* IN */ return jitInstance->mc->repIsValidStringRef(module, metaTOK); } -int MyICJI::getStringLength(CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ - ) +LPCWSTR MyICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ + ) { - jitInstance->mc->cr->AddCall("getStringLength"); - return jitInstance->mc->repGetStringLength(module, metaTOK); + jitInstance->mc->cr->AddCall("getStringLiteral"); + return jitInstance->mc->repGetStringLiteral(module, metaTOK, length); } BOOL MyICJI::shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) diff --git a/src/coreclr/src/inc/corinfo.h b/src/coreclr/src/inc/corinfo.h index 2481141e1495b..ff4b5b13f9f35 100644 --- a/src/coreclr/src/inc/corinfo.h +++ b/src/coreclr/src/inc/corinfo.h @@ -2307,9 +2307,10 @@ class ICorStaticInfo unsigned metaTOK /* IN */ ) = 0; - virtual int getStringLength ( + virtual LPCWSTR getStringLiteral ( CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */ + unsigned metaTOK, /* IN */ + int* length /* OUT */ ) = 0; virtual BOOL shouldEnforceCallvirtRestriction( diff --git a/src/coreclr/src/jit/ICorJitInfo_API_names.h b/src/coreclr/src/jit/ICorJitInfo_API_names.h index a6136a5b94941..a17127ed6d29a 100644 --- a/src/coreclr/src/jit/ICorJitInfo_API_names.h +++ b/src/coreclr/src/jit/ICorJitInfo_API_names.h @@ -38,7 +38,7 @@ DEF_CLR_API(getTokenTypeAsHandle) DEF_CLR_API(canSkipVerification) DEF_CLR_API(isValidToken) DEF_CLR_API(isValidStringRef) -DEF_CLR_API(getStringLength) +DEF_CLR_API(getStringLiteral) DEF_CLR_API(shouldEnforceCallvirtRestriction) DEF_CLR_API(asCorInfoType) DEF_CLR_API(getClassName) diff --git a/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp b/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp index fca4b0a80b892..824f86b8dd995 100644 --- a/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp +++ b/src/coreclr/src/jit/ICorJitInfo_API_wrapper.hpp @@ -367,13 +367,14 @@ BOOL WrapICorJitInfo::isValidStringRef( return temp; } -int WrapICorJitInfo::getStringLength( +LPCWSTR WrapICorJitInfo::getStringLiteral( CORINFO_MODULE_HANDLE module, /* IN */ - unsigned metaTOK /* IN */) + unsigned metaTOK, /* IN */ + int* length /* OUT */) { - API_ENTER(getStringLength); - int temp = wrapHnd->getStringLength(module, metaTOK); - API_LEAVE(getStringLength); + API_ENTER(getStringLiteral); + LPCWSTR temp = wrapHnd->getStringLiteral(module, metaTOK, length); + API_LEAVE(getStringLiteral); return temp; } diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index caa65eecf14a1..1671e7a6ee792 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3636,10 +3636,12 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { // Optimize `ldstr + String::get_Length()` to CNS_INT // e.g. "Hello".Length => 5 - int len = info.compCompHnd->getStringLength(op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX); - if (len >= 0) + int length = -1; + LPCWSTR str = info.compCompHnd->getStringLiteral(op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX, &length); + if (length >= 0) { - retNode = gtNewIconNode(len); + JITDUMP("Optimizing '\"%ls\".Length' to just '%d'\n", str, length); + retNode = gtNewIconNode(length); break; } } diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index 48adec5764ea8..fb135633c7100 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -84,7 +84,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValidStringRef(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate int __getStringLength(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); + [return: MarshalAs(UnmanagedType.LPWStr)]delegate string __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __shouldEnforceCallvirtRestriction(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -862,17 +862,17 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, } } - static int _getStringLength(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK) + [return: MarshalAs(UnmanagedType.LPWStr)]static string _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { var _this = GetThis(thisHandle); try { - return _this.getStringLength(module, metaTOK); + return _this.getStringLiteral(module, metaTOK, ref length); } catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(int); + return default(string); } } @@ -2960,7 +2960,7 @@ static IntPtr GetUnmanagedCallbacks(out Object keepAlive) var d35 = new __isValidStringRef(_isValidStringRef); callbacks[35] = Marshal.GetFunctionPointerForDelegate(d35); delegates[35] = d35; - var d36 = new __getStringLength(_getStringLength); + var d36 = new __getStringLiteral(_getStringLiteral); callbacks[36] = Marshal.GetFunctionPointerForDelegate(d36); delegates[36] = d36; var d37 = new __shouldEnforceCallvirtRestriction(_shouldEnforceCallvirtRestriction); diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index 3bd09da1daccd..daf67c926d2e9 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1165,10 +1165,10 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } - private int getStringLength(CORINFO_MODULE_STRUCT_* module, uint metaTOK) + private string getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { - // TODO: get length for string literal - return -1; + length = -1; + return null; } private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 3798a1150306e..07bfb1d2cdf37 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -199,7 +199,7 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) - int getStringLength(CORINFO_MODULE_HANDLE module, unsigned metaTOK) + LPCWSTR getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h index 960d3cdc716b7..64ce8fcf69a22 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h @@ -46,7 +46,7 @@ struct JitInterfaceCallbacks int (* canSkipVerification)(void * thisHandle, CorInfoException** ppException, void* module); int (* isValidToken)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); int (* isValidStringRef)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); - int (* getStringLength)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); + const wchar_t* (* getStringLiteral)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK, int* length); int (* shouldEnforceCallvirtRestriction)(void * thisHandle, CorInfoException** ppException, void* scope); int (* asCorInfoType)(void * thisHandle, CorInfoException** ppException, void* cls); const char* (* getClassName)(void * thisHandle, CorInfoException** ppException, void* cls); @@ -514,10 +514,10 @@ class JitInterfaceWrapper return _ret; } - virtual int getStringLength(void* module, unsigned metaTOK) + virtual const wchar_t* getStringLiteral(void* module, unsigned metaTOK, int* length) { CorInfoException* pException = nullptr; - int _ret = _callbacks->getStringLength(_thisHandle, &pException, module, metaTOK); + const wchar_t* _ret = _callbacks->getStringLiteral(_thisHandle, &pException, module, metaTOK, length); if (pException != nullptr) throw pException; return _ret; diff --git a/src/coreclr/src/vm/dynamicmethod.cpp b/src/coreclr/src/vm/dynamicmethod.cpp index 7818556ef6e5a..16ded7411fe1b 100644 --- a/src/coreclr/src/vm/dynamicmethod.cpp +++ b/src/coreclr/src/vm/dynamicmethod.cpp @@ -1197,15 +1197,26 @@ LCGMethodResolver::IsValidStringRef(mdToken metaTok) return GetStringLiteral(metaTok) != NULL; } -int -LCGMethodResolver::GetStringLength(mdToken metaTok) +LPCWSTR +LCGMethodResolver::GetStringLiteral(mdToken metaTok, int* length) { STANDARD_VM_CONTRACT; GCX_COOP(); STRINGREF str = GetStringLiteral(metaTok); - return str == NULL ? - 1 : str->GetStringLength(); + if (str == NULL) + { + *length = -1; + return NULL; + } + else + { + *length = str->GetStringLength(); + SString sstr; + str->GetSString(sstr); + return sstr.GetUnicode(); + } } //--------------------------------------------------------------------------------------- diff --git a/src/coreclr/src/vm/dynamicmethod.h b/src/coreclr/src/vm/dynamicmethod.h index 4500435f4f34f..f74dac89cadd8 100644 --- a/src/coreclr/src/vm/dynamicmethod.h +++ b/src/coreclr/src/vm/dynamicmethod.h @@ -73,7 +73,7 @@ class DynamicResolver // jit interface api virtual OBJECTHANDLE ConstructStringLiteral(mdToken metaTok) = 0; virtual BOOL IsValidStringRef(mdToken metaTok) = 0; - virtual int GetStringLength(mdToken metaTok) = 0; + virtual LPCWSTR GetStringLiteral(mdToken metaTok, int* length) = 0; virtual void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) = 0; virtual SigPointer ResolveSignature(mdToken token) = 0; virtual SigPointer ResolveSignatureForVarArg(mdToken token) = 0; @@ -123,7 +123,7 @@ class LCGMethodResolver : public DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); - int GetStringLength(mdToken metaTok); + LPCWSTR GetStringLiteral(mdToken metaTok, int* length); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/ilstubresolver.cpp b/src/coreclr/src/vm/ilstubresolver.cpp index bb1c908a2de6d..37a01a8220f2b 100644 --- a/src/coreclr/src/vm/ilstubresolver.cpp +++ b/src/coreclr/src/vm/ilstubresolver.cpp @@ -140,11 +140,12 @@ BOOL ILStubResolver::IsValidStringRef(mdToken metaTok) return FALSE; } -int ILStubResolver::GetStringLength(mdToken metaTok) +LPCWSTR ILStubResolver::GetStringLiteral(mdToken metaTok, int* length) { STANDARD_VM_CONTRACT; _ASSERTE(FALSE); - return -1; + *length = -1; + return NULL; } void ILStubResolver::ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) diff --git a/src/coreclr/src/vm/ilstubresolver.h b/src/coreclr/src/vm/ilstubresolver.h index 1678ea7ad69e9..db75ae5462938 100644 --- a/src/coreclr/src/vm/ilstubresolver.h +++ b/src/coreclr/src/vm/ilstubresolver.h @@ -33,7 +33,7 @@ class ILStubResolver : DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); - int GetStringLength(mdToken metaTok); + LPCWSTR GetStringLiteral(mdToken metaTok, int* length); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index 92e85188b44f3..1fe0e82fe09f1 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -799,9 +799,10 @@ BOOL CEEInfo::isValidStringRef ( return result; } -int CEEInfo::getStringLength ( +LPCWSTR CEEInfo::getStringLiteral ( CORINFO_MODULE_HANDLE moduleHnd, - mdToken metaTOK) + mdToken metaTOK, + int* length) { CONTRACTL{ THROWS; @@ -809,14 +810,15 @@ int CEEInfo::getStringLength ( MODE_PREEMPTIVE; } CONTRACTL_END; - int length = 0; Module* module = GetModule(moduleHnd); + LPCWSTR result = nullptr; + JIT_TO_EE_TRANSITION(); if (IsDynamicScope(moduleHnd)) { - length = GetDynamicResolver(moduleHnd)->GetStringLength(metaTOK); + result = GetDynamicResolver(moduleHnd)->GetStringLiteral(metaTOK, length); } else { @@ -825,17 +827,18 @@ int CEEInfo::getStringLength ( if (!FAILED((module)->GetMDImport()->GetUserString(metaTOK, &dwCharCount, NULL, &pString))) { // For string.Empty pString will be null - length = dwCharCount; + *length = dwCharCount; + result = pString; } else { - length = -1; + *length = -1; } } EE_TO_JIT_TRANSITION(); - return length; + return result; } /* static */ diff --git a/src/coreclr/src/vm/jitinterface.h b/src/coreclr/src/vm/jitinterface.h index cb4dfdc6e0d45..5859f4abb4016 100644 --- a/src/coreclr/src/vm/jitinterface.h +++ b/src/coreclr/src/vm/jitinterface.h @@ -700,9 +700,10 @@ class CEEInfo : public ICorJitInfo CORINFO_MODULE_HANDLE module, mdToken metaTOK); - int getStringLength ( + LPCWSTR getStringLiteral ( CORINFO_MODULE_HANDLE module, - mdToken metaTOK); + mdToken metaTOK, + int* length); static size_t findNameOfToken (Module* module, mdToken metaTOK, __out_ecount (FQNameCapacity) char * szFQName, size_t FQNameCapacity); diff --git a/src/coreclr/src/zap/zapinfo.cpp b/src/coreclr/src/zap/zapinfo.cpp index a3cc7ee1e9a28..980c2ad4116df 100644 --- a/src/coreclr/src/zap/zapinfo.cpp +++ b/src/coreclr/src/zap/zapinfo.cpp @@ -3809,11 +3809,12 @@ BOOL ZapInfo::isValidStringRef ( return m_pEEJitInfo->isValidStringRef(tokenScope, token); } -int ZapInfo::getStringLength ( +LPCWSTR ZapInfo::getStringLiteral ( CORINFO_MODULE_HANDLE tokenScope, - unsigned token) + unsigned token, + int* length) { - return m_pEEJitInfo->getStringLength(tokenScope, token); + return m_pEEJitInfo->getStringLiteral(tokenScope, token, length); } // diff --git a/src/coreclr/src/zap/zapinfo.h b/src/coreclr/src/zap/zapinfo.h index e9c1ff26c9bbc..8253de792f5db 100644 --- a/src/coreclr/src/zap/zapinfo.h +++ b/src/coreclr/src/zap/zapinfo.h @@ -629,8 +629,9 @@ class ZapInfo unsigned metaTOK); BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK); - int getStringLength(CORINFO_MODULE_HANDLE module, - unsigned metaTOK); + LPCWSTR getStringLiteral(CORINFO_MODULE_HANDLE module, + unsigned metaTOK, + int* length); // ICorMethodInfo From 1596fd9621e6f0a48f4d9b7df6d1ece25876248c Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jan 2020 03:53:17 +0300 Subject: [PATCH 10/20] Fix build errors --- .../ToolBox/superpmi/superpmi-shared/methodcontext.cpp | 8 ++++---- src/coreclr/src/jit/importer.cpp | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 2c4a8cc540b0a..976ce6898af3a 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -4632,8 +4632,8 @@ void MethodContext::recGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned m void MethodContext::dmpGetStringLiteral(DLD key, DD value) { - printf("GetStringLiteral key mod-%016llX tok-%08X, result-%ls, len-%u", key.A, key.B, - (LPCWSTR)GetStringLiteral->GetBuffer(value.B), value.A); + printf("GetStringLiteral key mod-%016llX tok-%08X, result-%s, len-%u", key.A, key.B, + GetStringLiteral->GetBuffer(value.B), value.A); } LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) @@ -4641,7 +4641,7 @@ LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigne if (GetStringLiteral == nullptr) { *length = -1; - return L"hackishStringLiteral"; + return W("hackishStringLiteral"); } DLD key; @@ -4655,7 +4655,7 @@ LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigne if (itemIndex < 0) { *length = -1; - return L"hackishStringLiteral"; + return W("hackishStringLiteral"); } else { diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 1671e7a6ee792..72ae367bc2187 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3637,10 +3637,11 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // Optimize `ldstr + String::get_Length()` to CNS_INT // e.g. "Hello".Length => 5 int length = -1; - LPCWSTR str = info.compCompHnd->getStringLiteral(op1->AsStrCon()->gtScpHnd, op1->AsStrCon()->gtSconCPX, &length); + LPCWSTR str = info.compCompHnd->getStringLiteral(op1->AsStrCon()->gtScpHnd, + op1->AsStrCon()->gtSconCPX, &length); if (length >= 0) { - JITDUMP("Optimizing '\"%ls\".Length' to just '%d'\n", str, length); + JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", str, length); retNode = gtNewIconNode(length); break; } From 9703fe3aea06dafe95b19d17df22013a8ce94222 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 27 Jan 2020 10:04:16 +0100 Subject: [PATCH 11/20] Address feedback --- src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs | 6 +++--- src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs | 2 +- .../tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt | 2 +- src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h | 6 +++--- src/coreclr/src/vm/dynamicmethod.cpp | 5 +---- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index fb135633c7100..ddda53634b04b 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -84,7 +84,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValidStringRef(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - [return: MarshalAs(UnmanagedType.LPWStr)]delegate string __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); + delegate byte* __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __shouldEnforceCallvirtRestriction(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -862,7 +862,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, } } - [return: MarshalAs(UnmanagedType.LPWStr)]static string _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + static byte* _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { var _this = GetThis(thisHandle); try @@ -872,7 +872,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(string); + return default(byte*); } } diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index d2ae66c62c7ca..b9a87ddf91ed5 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1152,7 +1152,7 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } - private string getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + private byte* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { length = -1; return null; diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 07bfb1d2cdf37..24855b9c026e8 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -199,7 +199,7 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) - LPCWSTR getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) + const char* getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h index 64ce8fcf69a22..62d3165732793 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h @@ -46,7 +46,7 @@ struct JitInterfaceCallbacks int (* canSkipVerification)(void * thisHandle, CorInfoException** ppException, void* module); int (* isValidToken)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); int (* isValidStringRef)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); - const wchar_t* (* getStringLiteral)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK, int* length); + const char* (* getStringLiteral)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK, int* length); int (* shouldEnforceCallvirtRestriction)(void * thisHandle, CorInfoException** ppException, void* scope); int (* asCorInfoType)(void * thisHandle, CorInfoException** ppException, void* cls); const char* (* getClassName)(void * thisHandle, CorInfoException** ppException, void* cls); @@ -514,10 +514,10 @@ class JitInterfaceWrapper return _ret; } - virtual const wchar_t* getStringLiteral(void* module, unsigned metaTOK, int* length) + virtual const char* getStringLiteral(void* module, unsigned metaTOK, int* length) { CorInfoException* pException = nullptr; - const wchar_t* _ret = _callbacks->getStringLiteral(_thisHandle, &pException, module, metaTOK, length); + const char* _ret = _callbacks->getStringLiteral(_thisHandle, &pException, module, metaTOK, length); if (pException != nullptr) throw pException; return _ret; diff --git a/src/coreclr/src/vm/dynamicmethod.cpp b/src/coreclr/src/vm/dynamicmethod.cpp index 16ded7411fe1b..546b02a64cd1f 100644 --- a/src/coreclr/src/vm/dynamicmethod.cpp +++ b/src/coreclr/src/vm/dynamicmethod.cpp @@ -1208,15 +1208,12 @@ LCGMethodResolver::GetStringLiteral(mdToken metaTok, int* length) if (str == NULL) { *length = -1; - return NULL; } else { *length = str->GetStringLength(); - SString sstr; - str->GetSString(sstr); - return sstr.GetUnicode(); } + return NULL; } //--------------------------------------------------------------------------------------- From 067e21d71036763d4e85252d3b342da459cc6fab Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 27 Jan 2020 10:11:53 +0100 Subject: [PATCH 12/20] handle null return value --- src/coreclr/src/jit/importer.cpp | 2 +- src/coreclr/src/vm/jitinterface.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 2d25c7f9a77d9..a649bab616753 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3641,8 +3641,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, op1->AsStrCon()->gtSconCPX, &length); if (length >= 0) { - JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", str, length); retNode = gtNewIconNode(length); + JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", (str == nullptr ? "n/a" : str), length); break; } } diff --git a/src/coreclr/src/vm/jitinterface.h b/src/coreclr/src/vm/jitinterface.h index 2ce97b0e0998b..9c8ff71f91d56 100644 --- a/src/coreclr/src/vm/jitinterface.h +++ b/src/coreclr/src/vm/jitinterface.h @@ -662,6 +662,7 @@ class CEEInfo : public ICorJitInfo CORINFO_MODULE_HANDLE module, mdToken metaTOK); + // Get string length and content (can be null) for given metaTOK LPCWSTR getStringLiteral ( CORINFO_MODULE_HANDLE module, mdToken metaTOK, From db6e94eea7902d1ae22f2496e67cfa1715ab1e3f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 27 Jan 2020 10:31:03 +0100 Subject: [PATCH 13/20] fix build --- src/coreclr/src/jit/importer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index a649bab616753..f2d477f3dff3b 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3642,7 +3642,14 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, if (length >= 0) { retNode = gtNewIconNode(length); - JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", (str == nullptr ? "n/a" : str), length); + if (str == nullptr) // can be NULL for dynamic context + { + JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", str, length); + } + else + { + JITDUMP("Optimizing 'CNS_STR.Length' to just '%d'\n", length); + } break; } } From 7fd4d878bc6c57471afb08789c6edfd347226a39 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 27 Jan 2020 20:24:00 +0100 Subject: [PATCH 14/20] Address feedback --- .../src/tools/Common/JitInterface/CorInfoImpl.cs | 6 ++++-- src/coreclr/src/vm/dynamicmethod.cpp | 14 +++++--------- src/coreclr/src/vm/dynamicmethod.h | 4 ++-- src/coreclr/src/vm/ilstubresolver.cpp | 5 ++--- src/coreclr/src/vm/ilstubresolver.h | 2 +- src/coreclr/src/vm/jitinterface.cpp | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index b9a87ddf91ed5..e567e83f1a255 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1154,8 +1154,10 @@ private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) private byte* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { - length = -1; - return null; + MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); + string s = (string)methodIL.GetObject((int)metaTOK); + length = (int)s.Length; + return (byte*)GetPin(s); } private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) diff --git a/src/coreclr/src/vm/dynamicmethod.cpp b/src/coreclr/src/vm/dynamicmethod.cpp index 546b02a64cd1f..bb595a5cf9076 100644 --- a/src/coreclr/src/vm/dynamicmethod.cpp +++ b/src/coreclr/src/vm/dynamicmethod.cpp @@ -1197,23 +1197,19 @@ LCGMethodResolver::IsValidStringRef(mdToken metaTok) return GetStringLiteral(metaTok) != NULL; } -LPCWSTR -LCGMethodResolver::GetStringLiteral(mdToken metaTok, int* length) +int +LCGMethodResolver::GetStringLiteralLength(mdToken metaTok) { STANDARD_VM_CONTRACT; GCX_COOP(); STRINGREF str = GetStringLiteral(metaTok); - if (str == NULL) + if (str != NULL) { - *length = -1; + return str->GetStringLength(); } - else - { - *length = str->GetStringLength(); - } - return NULL; + return -1; } //--------------------------------------------------------------------------------------- diff --git a/src/coreclr/src/vm/dynamicmethod.h b/src/coreclr/src/vm/dynamicmethod.h index f74dac89cadd8..9e4322de213cf 100644 --- a/src/coreclr/src/vm/dynamicmethod.h +++ b/src/coreclr/src/vm/dynamicmethod.h @@ -73,7 +73,7 @@ class DynamicResolver // jit interface api virtual OBJECTHANDLE ConstructStringLiteral(mdToken metaTok) = 0; virtual BOOL IsValidStringRef(mdToken metaTok) = 0; - virtual LPCWSTR GetStringLiteral(mdToken metaTok, int* length) = 0; + virtual int GetStringLiteralLength(mdToken metaTok) = 0; virtual void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) = 0; virtual SigPointer ResolveSignature(mdToken token) = 0; virtual SigPointer ResolveSignatureForVarArg(mdToken token) = 0; @@ -123,7 +123,7 @@ class LCGMethodResolver : public DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); - LPCWSTR GetStringLiteral(mdToken metaTok, int* length); + int GetStringLiteralLength(mdToken metaTok); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/ilstubresolver.cpp b/src/coreclr/src/vm/ilstubresolver.cpp index 37a01a8220f2b..94be0cf9ca2be 100644 --- a/src/coreclr/src/vm/ilstubresolver.cpp +++ b/src/coreclr/src/vm/ilstubresolver.cpp @@ -140,12 +140,11 @@ BOOL ILStubResolver::IsValidStringRef(mdToken metaTok) return FALSE; } -LPCWSTR ILStubResolver::GetStringLiteral(mdToken metaTok, int* length) +int ILStubResolver::GetStringLiteralLength(mdToken metaTok) { STANDARD_VM_CONTRACT; _ASSERTE(FALSE); - *length = -1; - return NULL; + return -1; } void ILStubResolver::ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD) diff --git a/src/coreclr/src/vm/ilstubresolver.h b/src/coreclr/src/vm/ilstubresolver.h index db75ae5462938..8b42a0cd3b313 100644 --- a/src/coreclr/src/vm/ilstubresolver.h +++ b/src/coreclr/src/vm/ilstubresolver.h @@ -33,7 +33,7 @@ class ILStubResolver : DynamicResolver OBJECTHANDLE ConstructStringLiteral(mdToken metaTok); BOOL IsValidStringRef(mdToken metaTok); - LPCWSTR GetStringLiteral(mdToken metaTok, int* length); + int GetStringLiteralLength(mdToken metaTok); void ResolveToken(mdToken token, TypeHandle * pTH, MethodDesc ** ppMD, FieldDesc ** ppFD); SigPointer ResolveSignature(mdToken token); SigPointer ResolveSignatureForVarArg(mdToken token); diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index 1fe0e82fe09f1..1da99b3be7d4b 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -818,7 +818,7 @@ LPCWSTR CEEInfo::getStringLiteral ( if (IsDynamicScope(moduleHnd)) { - result = GetDynamicResolver(moduleHnd)->GetStringLiteral(metaTOK, length); + *length = GetDynamicResolver(moduleHnd)->GetStringLiteralLength(metaTOK); } else { From 76d984e943f2279fa1874b45d083c34fbad463e1 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 27 Jan 2020 21:49:07 +0100 Subject: [PATCH 15/20] add comments in corinfo.h --- src/coreclr/src/inc/corinfo.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/src/inc/corinfo.h b/src/coreclr/src/inc/corinfo.h index 66f2576c6c351..d7331491b5d13 100644 --- a/src/coreclr/src/inc/corinfo.h +++ b/src/coreclr/src/inc/corinfo.h @@ -2307,6 +2307,8 @@ class ICorStaticInfo unsigned metaTOK /* IN */ ) = 0; + // Returns string length and content (can be null for dynamic context) + // for given metaTOK and module, length `-1` means input is incorrect virtual LPCWSTR getStringLiteral ( CORINFO_MODULE_HANDLE module, /* IN */ unsigned metaTOK, /* IN */ From becc851d74eaaa37de1cde519f09f7b64281caa6 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 28 Jan 2020 09:05:25 +0100 Subject: [PATCH 16/20] Address feedback --- .../src/tools/Common/JitInterface/CorInfoBase.cs | 12 ++++++------ .../src/tools/Common/JitInterface/CorInfoImpl.cs | 6 +++--- .../ThunkGenerator/ThunkGenerator.csproj | 2 +- .../JitInterface/ThunkGenerator/ThunkInput.txt | 3 +-- .../src/tools/crossgen2/jitinterface/jitinterface.h | 6 +++--- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index ddda53634b04b..90d9938a333cb 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -84,7 +84,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValidStringRef(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate byte* __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); + delegate short* __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __shouldEnforceCallvirtRestriction(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -244,7 +244,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate void __getEEInfo(IntPtr _this, IntPtr* ppException, ref CORINFO_EE_INFO pEEInfoOut); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - [return: MarshalAs(UnmanagedType.LPWStr)]delegate string __getJitTimeLogFilename(IntPtr _this, IntPtr* ppException); + delegate short* __getJitTimeLogFilename(IntPtr _this, IntPtr* ppException); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate mdToken __getMethodDefFromMethod(IntPtr _this, IntPtr* ppException, CORINFO_METHOD_STRUCT_* hMethod); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -862,7 +862,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, } } - static byte* _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + static short* _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { var _this = GetThis(thisHandle); try @@ -872,7 +872,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(byte*); + return default(short*); } } @@ -1969,7 +1969,7 @@ static void _getEEInfo(IntPtr thisHandle, IntPtr* ppException, ref CORINFO_EE_IN } } - [return: MarshalAs(UnmanagedType.LPWStr)]static string _getJitTimeLogFilename(IntPtr thisHandle, IntPtr* ppException) + static short* _getJitTimeLogFilename(IntPtr thisHandle, IntPtr* ppException) { var _this = GetThis(thisHandle); try @@ -1979,7 +1979,7 @@ static void _getEEInfo(IntPtr thisHandle, IntPtr* ppException, ref CORINFO_EE_IN catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(string); + return default(short*); } } diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index e567e83f1a255..00781f4823f8a 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1152,12 +1152,12 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } - private byte* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + private short* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); string s = (string)methodIL.GetObject((int)metaTOK); length = (int)s.Length; - return (byte*)GetPin(s); + return (short*)GetPin(s); } private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) @@ -2424,7 +2424,7 @@ private void getEEInfo(ref CORINFO_EE_INFO pEEInfoOut) pEEInfoOut.osType = _compilation.NodeFactory.Target.IsWindows ? CORINFO_OS.CORINFO_WINNT : CORINFO_OS.CORINFO_UNIX; } - private string getJitTimeLogFilename() + private short* getJitTimeLogFilename() { return null; } diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj index 06ad79da63cc5..958d2f1daae33 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj @@ -2,7 +2,7 @@ Exe - $(NetCoreAppCurrent) + netcoreapp3.0 diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 24855b9c026e8..a196571421b6f 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -158,7 +158,6 @@ struct _EXCEPTION_POINTERS*,_EXCEPTION_POINTERS*,void* RETURNTYPES BOOL,[return: MarshalAs(UnmanagedType.Bool)]bool,int bool,[return: MarshalAs(UnmanagedType.I1)]bool -LPCWSTR,[return: MarshalAs(UnmanagedType.LPWStr)]string,const wchar_t* ; NOTE in managed SIZE_T is an enum that is 64bits in size, and returning one of those causing mcg to do the wrong thing. size_t,byte*,size_t @@ -199,7 +198,7 @@ FUNCTIONS CorInfoCanSkipVerificationResult canSkipVerification(CORINFO_MODULE_HANDLE module) BOOL isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK) BOOL isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK) - const char* getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) + LPCWSTR getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, int* length) BOOL shouldEnforceCallvirtRestriction(CORINFO_MODULE_HANDLE scope) CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls) const char* getClassName(CORINFO_CLASS_HANDLE cls) diff --git a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h index 62d3165732793..64ce8fcf69a22 100644 --- a/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h +++ b/src/coreclr/src/tools/crossgen2/jitinterface/jitinterface.h @@ -46,7 +46,7 @@ struct JitInterfaceCallbacks int (* canSkipVerification)(void * thisHandle, CorInfoException** ppException, void* module); int (* isValidToken)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); int (* isValidStringRef)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK); - const char* (* getStringLiteral)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK, int* length); + const wchar_t* (* getStringLiteral)(void * thisHandle, CorInfoException** ppException, void* module, unsigned metaTOK, int* length); int (* shouldEnforceCallvirtRestriction)(void * thisHandle, CorInfoException** ppException, void* scope); int (* asCorInfoType)(void * thisHandle, CorInfoException** ppException, void* cls); const char* (* getClassName)(void * thisHandle, CorInfoException** ppException, void* cls); @@ -514,10 +514,10 @@ class JitInterfaceWrapper return _ret; } - virtual const char* getStringLiteral(void* module, unsigned metaTOK, int* length) + virtual const wchar_t* getStringLiteral(void* module, unsigned metaTOK, int* length) { CorInfoException* pException = nullptr; - const char* _ret = _callbacks->getStringLiteral(_thisHandle, &pException, module, metaTOK, length); + const wchar_t* _ret = _callbacks->getStringLiteral(_thisHandle, &pException, module, metaTOK, length); if (pException != nullptr) throw pException; return _ret; From 91a4a26d89a5a5a947dc2cee994d3c158e308ab8 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Tue, 28 Jan 2020 09:06:45 +0100 Subject: [PATCH 17/20] Update ThunkGenerator.csproj --- .../Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj index 958d2f1daae33..06ad79da63cc5 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkGenerator.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + $(NetCoreAppCurrent) From eb99781b91c9423c7f37ba7a44eb075c0d46d289 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 30 Jan 2020 12:21:24 +0300 Subject: [PATCH 18/20] remove HackishString thing --- .../src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp index 976ce6898af3a..b52fbcf400d4e 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp @@ -4641,7 +4641,7 @@ LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigne if (GetStringLiteral == nullptr) { *length = -1; - return W("hackishStringLiteral"); + return nullptr; } DLD key; @@ -4655,7 +4655,7 @@ LPCWSTR MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigne if (itemIndex < 0) { *length = -1; - return W("hackishStringLiteral"); + return nullptr; } else { From d6533b43a735c3383dae7f24a52e1c9b28c52be5 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 31 Jan 2020 23:12:39 +0300 Subject: [PATCH 19/20] Update importer.cpp --- src/coreclr/src/jit/importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index e322b9a75e39a..292651c3a3027 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3642,7 +3642,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, if (length >= 0) { retNode = gtNewIconNode(length); - if (str == nullptr) // can be NULL for dynamic context + if (str != nullptr) // can be NULL for dynamic context { JITDUMP("Optimizing '\"%ws\".Length' to just '%d'\n", str, length); } From 0940e93ecd4af0fcd7731c9feefaa91cc9ef7c7b Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 1 Feb 2020 00:54:05 +0300 Subject: [PATCH 20/20] Map wchar_t to C# char in ThunkInput.txt --- .../tools/Common/JitInterface/CorInfoBase.cs | 20 +++++++++---------- .../tools/Common/JitInterface/CorInfoImpl.cs | 18 ++++++++--------- .../ThunkGenerator/ThunkInput.txt | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs index 90d9938a333cb..5e64833b92487 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoBase.cs @@ -84,7 +84,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValidStringRef(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate short* __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); + delegate char* __getStringLiteral(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __shouldEnforceCallvirtRestriction(IntPtr _this, IntPtr* ppException, CORINFO_MODULE_STRUCT_* scope); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -96,7 +96,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate CORINFO_CLASS_STRUCT_* __getTypeInstantiationArgument(IntPtr _this, IntPtr* ppException, CORINFO_CLASS_STRUCT_* cls, uint index); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate int __appendClassName(IntPtr _this, IntPtr* ppException, short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly); + delegate int __appendClassName(IntPtr _this, IntPtr* ppException, char** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] [return: MarshalAs(UnmanagedType.Bool)]delegate bool __isValueClass(IntPtr _this, IntPtr* ppException, CORINFO_CLASS_STRUCT_* cls); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -230,7 +230,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate HRESULT __GetErrorHRESULT(IntPtr _this, IntPtr* ppException, _EXCEPTION_POINTERS* pExceptionPointers); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate uint __GetErrorMessage(IntPtr _this, IntPtr* ppException, short* buffer, uint bufferLength); + delegate uint __GetErrorMessage(IntPtr _this, IntPtr* ppException, char* buffer, uint bufferLength); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate int __FilterException(IntPtr _this, IntPtr* ppException, _EXCEPTION_POINTERS* pExceptionPointers); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -244,7 +244,7 @@ unsafe partial class CorInfoImpl [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate void __getEEInfo(IntPtr _this, IntPtr* ppException, ref CORINFO_EE_INFO pEEInfoOut); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] - delegate short* __getJitTimeLogFilename(IntPtr _this, IntPtr* ppException); + delegate char* __getJitTimeLogFilename(IntPtr _this, IntPtr* ppException); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] delegate mdToken __getMethodDefFromMethod(IntPtr _this, IntPtr* ppException, CORINFO_METHOD_STRUCT_* hMethod); [UnmanagedFunctionPointerAttribute(default(CallingConvention))] @@ -862,7 +862,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, } } - static short* _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + static char* _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { var _this = GetThis(thisHandle); try @@ -872,7 +872,7 @@ static CorInfoCanSkipVerificationResult _canSkipVerification(IntPtr thisHandle, catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(short*); + return default(char*); } } @@ -946,7 +946,7 @@ static CorInfoType _asCorInfoType(IntPtr thisHandle, IntPtr* ppException, CORINF } } - static int _appendClassName(IntPtr thisHandle, IntPtr* ppException, short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly) + static int _appendClassName(IntPtr thisHandle, IntPtr* ppException, char** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, [MarshalAs(UnmanagedType.Bool)]bool fNamespace, [MarshalAs(UnmanagedType.Bool)]bool fFullInst, [MarshalAs(UnmanagedType.Bool)]bool fAssembly) { var _this = GetThis(thisHandle); try @@ -1875,7 +1875,7 @@ static HRESULT _GetErrorHRESULT(IntPtr thisHandle, IntPtr* ppException, _EXCEPTI } } - static uint _GetErrorMessage(IntPtr thisHandle, IntPtr* ppException, short* buffer, uint bufferLength) + static uint _GetErrorMessage(IntPtr thisHandle, IntPtr* ppException, char* buffer, uint bufferLength) { var _this = GetThis(thisHandle); try @@ -1969,7 +1969,7 @@ static void _getEEInfo(IntPtr thisHandle, IntPtr* ppException, ref CORINFO_EE_IN } } - static short* _getJitTimeLogFilename(IntPtr thisHandle, IntPtr* ppException) + static char* _getJitTimeLogFilename(IntPtr thisHandle, IntPtr* ppException) { var _this = GetThis(thisHandle); try @@ -1979,7 +1979,7 @@ static void _getEEInfo(IntPtr thisHandle, IntPtr* ppException, ref CORINFO_EE_IN catch (Exception ex) { *ppException = _this.AllocException(ex); - return default(short*); + return default(char*); } } diff --git a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs index 00781f4823f8a..9d1ec443e3fc7 100644 --- a/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs @@ -1152,12 +1152,12 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) private bool shouldEnforceCallvirtRestriction(CORINFO_MODULE_STRUCT_* scope) { throw new NotImplementedException("shouldEnforceCallvirtRestriction"); } - private short* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) + private char* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) { MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); string s = (string)methodIL.GetObject((int)metaTOK); length = (int)s.Length; - return (short*)GetPin(s); + return (char*)GetPin(s); } private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) @@ -1196,7 +1196,7 @@ private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) } - private int appendClassName(short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, bool fNamespace, bool fFullInst, bool fAssembly) + private int appendClassName(char** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUCT_* cls, bool fNamespace, bool fFullInst, bool fAssembly) { // We support enough of this to make SIMD work, but not much else. @@ -1208,13 +1208,13 @@ private int appendClassName(short** ppBuf, ref int pnBufLen, CORINFO_CLASS_STRUC int length = name.Length; if (pnBufLen > 0) { - short* buffer = *ppBuf; + char* buffer = *ppBuf; for (int i = 0; i < Math.Min(name.Length, pnBufLen); i++) - buffer[i] = (short)name[i]; + buffer[i] = name[i]; if (name.Length < pnBufLen) - buffer[name.Length] = 0; + buffer[name.Length] = (char)0; else - buffer[pnBufLen - 1] = 0; + buffer[pnBufLen - 1] = (char)0; pnBufLen -= length; *ppBuf = buffer + length; } @@ -2361,7 +2361,7 @@ private CorInfoType getHFAType(CORINFO_CLASS_STRUCT_* hClass) private HRESULT GetErrorHRESULT(_EXCEPTION_POINTERS* pExceptionPointers) { throw new NotImplementedException("GetErrorHRESULT"); } - private uint GetErrorMessage(short* buffer, uint bufferLength) + private uint GetErrorMessage(char* buffer, uint bufferLength) { throw new NotImplementedException("GetErrorMessage"); } private int FilterException(_EXCEPTION_POINTERS* pExceptionPointers) @@ -2424,7 +2424,7 @@ private void getEEInfo(ref CORINFO_EE_INFO pEEInfoOut) pEEInfoOut.osType = _compilation.NodeFactory.Target.IsWindows ? CORINFO_OS.CORINFO_WINNT : CORINFO_OS.CORINFO_UNIX; } - private short* getJitTimeLogFilename() + private char* getJitTimeLogFilename() { return null; } diff --git a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index a196571421b6f..a124f01f0e85b 100644 --- a/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/src/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -72,11 +72,11 @@ ULONG32*,ref uint,unsigned int* LONG*,int*,long* char*,byte* const char**,byte** -WCHAR**,short**,wchar_t** +WCHAR**,char**,wchar_t** LPCSTR,byte*,const char* -LPWSTR,short*,wchar_t* -LPCWSTR,short*,const wchar_t* -wchar_t*,short* +LPWSTR,char*,wchar_t* +LPCWSTR,char*,const wchar_t* +wchar_t*,char* const wchar_t*,String DWORD**,ref uint*,unsigned int**