Skip to content

Commit 15a47c2

Browse files
committed
Import string.Empty as ""
1 parent ee390ff commit 15a47c2

22 files changed

Lines changed: 168 additions & 13 deletions

File tree

src/coreclr/inc/corjit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ class ICorJitInfo : public ICorDynamicInfo
485485
//
486486
virtual uint32_t getExpectedTargetArchitecture() = 0;
487487

488+
// Obtains MdToken corresponding to "". It's used to import String.Empty as GT_CNS_STR
489+
virtual uint32_t getEmptyStringMdToken() = 0;
490+
488491
// Fetches extended flags for a particular compilation instance. Returns
489492
// the number of bytes written to the provided buffer.
490493
virtual uint32_t getJitFlags(

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ uint16_t getRelocTypeHint(
702702

703703
uint32_t getExpectedTargetArchitecture() override;
704704

705+
uint32_t getEmptyStringMdToken() override;
706+
705707
uint32_t getJitFlags(
706708
CORJIT_FLAGS* flags,
707709
uint32_t sizeInBytes) override;

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* 323185e9-208a-4b35-a413-23f9aac2d5f7 */
47-
0x323185e9,
48-
0x208a,
49-
0x4b35,
50-
{0xa4, 0x13, 0x23, 0xf9, 0xaa, 0xc2, 0xd5, 0xf7}
46+
constexpr GUID JITEEVersionIdentifier = { /* 7910ee9e-2034-425d-bd9a-f1d44783c86e */
47+
0x7910ee9e,
48+
0x2034,
49+
0x425d,
50+
{0xbd, 0x9a, 0xf1, 0xd4, 0x47, 0x83, 0xc8, 0x6e}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/ICorJitInfo_API_names.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ DEF_CLR_API(recordCallSite)
174174
DEF_CLR_API(recordRelocation)
175175
DEF_CLR_API(getRelocTypeHint)
176176
DEF_CLR_API(getExpectedTargetArchitecture)
177+
DEF_CLR_API(getEmptyStringMdToken)
177178
DEF_CLR_API(getJitFlags)
178179
DEF_CLR_API(doesFieldBelongToClass)
179180

src/coreclr/jit/ICorJitInfo_API_wrapper.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,14 @@ uint32_t WrapICorJitInfo::getExpectedTargetArchitecture()
16701670
return temp;
16711671
}
16721672

1673+
uint32_t WrapICorJitInfo::getEmptyStringMdToken()
1674+
{
1675+
API_ENTER(getEmptyStringMdToken);
1676+
uint32_t temp = wrapHnd->getEmptyStringMdToken();
1677+
API_LEAVE(getEmptyStringMdToken);
1678+
return temp;
1679+
}
1680+
16731681
uint32_t WrapICorJitInfo::getJitFlags(
16741682
CORJIT_FLAGS* flags,
16751683
uint32_t sizeInBytes)

src/coreclr/jit/importer.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15115,9 +15115,20 @@ void Compiler::impImportBlockCode(BasicBlock* block)
1511515115
{
1511615116
assert(aflags & CORINFO_ACCESS_GET);
1511715117

15118-
LPVOID pValue;
15119-
InfoAccessType iat = info.compCompHnd->emptyStringLiteral(&pValue);
15120-
op1 = gtNewStringLiteralNode(iat, pValue);
15118+
// Try to import String.Empty as "" (GT_CNS_STR) if VM has a mdToken for ""
15119+
uint32_t emptyStrTok = info.compCompHnd->getEmptyStringMdToken();
15120+
if (emptyStrTok > 0)
15121+
{
15122+
// emptyStrTok is always from corelib
15123+
op1 = gtNewSconNode(emptyStrTok, info.compCompHnd->getClassModule(impGetObjectClass()));
15124+
}
15125+
else
15126+
{
15127+
// Import normally
15128+
LPVOID pValue;
15129+
InfoAccessType iat = info.compCompHnd->emptyStringLiteral(&pValue);
15130+
op1 = gtNewStringLiteralNode(iat, pValue);
15131+
}
1512115132
goto FIELD_DONE;
1512215133
}
1512315134
break;

src/coreclr/tools/Common/JitInterface/CorInfoBase.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,21 @@ static uint _getExpectedTargetArchitecture(IntPtr thisHandle, IntPtr* ppExceptio
25192519
}
25202520
}
25212521

2522+
[UnmanagedCallersOnly]
2523+
static uint _getEmptyStringMdToken(IntPtr thisHandle, IntPtr* ppException)
2524+
{
2525+
var _this = GetThis(thisHandle);
2526+
try
2527+
{
2528+
return _this.getEmptyStringMdToken();
2529+
}
2530+
catch (Exception ex)
2531+
{
2532+
*ppException = _this.AllocException(ex);
2533+
return default;
2534+
}
2535+
}
2536+
25222537
[UnmanagedCallersOnly]
25232538
static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_FLAGS* flags, uint sizeInBytes)
25242539
{
@@ -2552,7 +2567,7 @@ static byte _doesFieldBelongToClass(IntPtr thisHandle, IntPtr* ppException, CORI
25522567

25532568
static IntPtr GetUnmanagedCallbacks()
25542569
{
2555-
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 172);
2570+
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 173);
25562571

25572572
callbacks[0] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, byte>)&_isIntrinsic;
25582573
callbacks[1] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, uint>)&_getMethodAttribs;
@@ -2724,8 +2739,9 @@ static IntPtr GetUnmanagedCallbacks()
27242739
callbacks[167] = (delegate* unmanaged<IntPtr, IntPtr*, void*, void*, void*, ushort, ushort, int, void>)&_recordRelocation;
27252740
callbacks[168] = (delegate* unmanaged<IntPtr, IntPtr*, void*, ushort>)&_getRelocTypeHint;
27262741
callbacks[169] = (delegate* unmanaged<IntPtr, IntPtr*, uint>)&_getExpectedTargetArchitecture;
2727-
callbacks[170] = (delegate* unmanaged<IntPtr, IntPtr*, CORJIT_FLAGS*, uint, uint>)&_getJitFlags;
2728-
callbacks[171] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_FIELD_STRUCT_*, CORINFO_CLASS_STRUCT_*, byte>)&_doesFieldBelongToClass;
2742+
callbacks[170] = (delegate* unmanaged<IntPtr, IntPtr*, uint>)&_getEmptyStringMdToken;
2743+
callbacks[171] = (delegate* unmanaged<IntPtr, IntPtr*, CORJIT_FLAGS*, uint, uint>)&_getJitFlags;
2744+
callbacks[172] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_FIELD_STRUCT_*, CORINFO_CLASS_STRUCT_*, byte>)&_doesFieldBelongToClass;
27292745

27302746
return (IntPtr)callbacks;
27312747
}

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,11 @@ private uint getExpectedTargetArchitecture()
36423642
}
36433643
}
36443644

3645+
private uint getEmptyStringMdToken()
3646+
{
3647+
return 0;
3648+
}
3649+
36453650
private bool doesFieldBelongToClass(CORINFO_FIELD_STRUCT_* fld, CORINFO_CLASS_STRUCT_* cls)
36463651
{
36473652
var field = HandleToObject(fld);

src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,6 @@ FUNCTIONS
323323
void recordRelocation(void* location, void* locationRW, void* target, uint16_t fRelocType, uint16_t slotNum, int32_t addlDelta)
324324
uint16_t getRelocTypeHint(void* target)
325325
uint32_t getExpectedTargetArchitecture()
326+
uint32_t getEmptyStringMdToken()
326327
uint32_t getJitFlags(CORJIT_FLAGS* flags, uint32_t sizeInBytes)
327328
bool doesFieldBelongToClass(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls)

src/coreclr/tools/aot/jitinterface/jitinterface.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ struct JitInterfaceCallbacks
181181
void (* recordRelocation)(void * thisHandle, CorInfoExceptionClass** ppException, void* location, void* locationRW, void* target, uint16_t fRelocType, uint16_t slotNum, int32_t addlDelta);
182182
uint16_t (* getRelocTypeHint)(void * thisHandle, CorInfoExceptionClass** ppException, void* target);
183183
uint32_t (* getExpectedTargetArchitecture)(void * thisHandle, CorInfoExceptionClass** ppException);
184+
uint32_t (* getEmptyStringMdToken)(void * thisHandle, CorInfoExceptionClass** ppException);
184185
uint32_t (* getJitFlags)(void * thisHandle, CorInfoExceptionClass** ppException, CORJIT_FLAGS* flags, uint32_t sizeInBytes);
185186
bool (* doesFieldBelongToClass)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE cls);
186187

@@ -1838,6 +1839,14 @@ class JitInterfaceWrapper : public ICorJitInfo
18381839
return temp;
18391840
}
18401841

1842+
virtual uint32_t getEmptyStringMdToken()
1843+
{
1844+
CorInfoExceptionClass* pException = nullptr;
1845+
uint32_t temp = _callbacks->getEmptyStringMdToken(_thisHandle, &pException);
1846+
if (pException != nullptr) throw pException;
1847+
return temp;
1848+
}
1849+
18411850
virtual uint32_t getJitFlags(
18421851
CORJIT_FLAGS* flags,
18431852
uint32_t sizeInBytes)

0 commit comments

Comments
 (0)