diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index e906373fdbb18..d337a9c54361d 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -416,7 +416,6 @@ enum CorInfoHelpFunc CORINFO_HELP_NEWARR_1_ALIGN8, // like VC, but aligns the array start CORINFO_HELP_STRCNS, // create a new string literal - CORINFO_HELP_STRCNS_CURRENT_MODULE, // create a new string literal from the current module (used by NGen code) /* Object model */ @@ -591,7 +590,10 @@ enum CorInfoHelpFunc CORINFO_HELP_READYTORUN_NEWARR_1, CORINFO_HELP_READYTORUN_ISINSTANCEOF, CORINFO_HELP_READYTORUN_CHKCAST, - CORINFO_HELP_READYTORUN_STATIC_BASE, + CORINFO_HELP_READYTORUN_GCSTATIC_BASE, // static gc field access + CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, // static non gc field access + CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, + CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 63e1ce6c8f7cf..00fc20a46e1f6 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* aaa9536e-1295-4741-a7d9-6c09a5b01512 */ - 0xaaa9536e, - 0x1295, - 0x4741, - {0xa7, 0xd9, 0x6c, 0x9, 0xa5, 0xb0, 0x15, 0x12} +constexpr GUID JITEEVersionIdentifier = { /* fd13d4e1-9815-4336-8232-b27878b9ebd4 */ + 0xfd13d4e1, + 0x9815, + 0x4336, + {0x82, 0x32, 0xb2, 0x78, 0x78, 0xb9, 0xeb, 0xd4} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index e897d592322e6..601588f98167e 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -82,7 +82,6 @@ DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_ALIGN8, JIT_NewArr1,CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_STRCNS, JIT_StrCns, CORINFO_HELP_SIG_REG_ONLY) - JITHELPER(CORINFO_HELP_STRCNS_CURRENT_MODULE, NULL, CORINFO_HELP_SIG_REG_ONLY) // Object model JITHELPER(CORINFO_HELP_INITCLASS, JIT_InitClass, CORINFO_HELP_SIG_REG_ONLY) @@ -259,7 +258,10 @@ JITHELPER(CORINFO_HELP_READYTORUN_NEWARR_1, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_ISINSTANCEOF, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_CHKCAST, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) - JITHELPER(CORINFO_HELP_READYTORUN_STATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) + JITHELPER(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) + JITHELPER(CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) + JITHELPER(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) + JITHELPER(CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, NULL,CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_GENERIC_HANDLE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 68483414fb7f7..22a01c6320208 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -1968,6 +1968,8 @@ void Compiler::compInit(ArenaAllocator* pAlloc, #endif // FEATURE_SIMD compUsesThrowHelper = false; + + m_preferredInitCctor = CORINFO_HELP_UNDEF; } /***************************************************************************** diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 1df7ae4841fd8..52102c99b0f44 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4661,6 +4661,12 @@ class Compiler PhaseStatus placeLoopAlignInstructions(); #endif + // This field keep the R2R helper call that would be inserted to trigger the constructor + // of the static class. It is set as nongc or gc static base if they are imported, so + // CSE can eliminate the repeated call, or the chepeast helper function that triggers it. + CorInfoHelpFunc m_preferredInitCctor; + void fgSetPreferredInitCctor(); + GenTree* fgInitThisClass(); GenTreeCall* fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfoHelpFunc helper); diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index ba73f5439a37a..94d2223fe8d94 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -3597,7 +3597,9 @@ inline bool Compiler::IsSharedStaticHelper(GenTree* tree) helper == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS || helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS || #ifdef FEATURE_READYTORUN - helper == CORINFO_HELP_READYTORUN_STATIC_BASE || helper == CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE || + helper == CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE || helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || + helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE || helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE || + helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE || #endif helper == CORINFO_HELP_CLASSINIT_SHARED_DYNAMICCLASS; #if 0 diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 7ed3f33073ac0..2ad1f508f78c8 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -885,6 +885,19 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo return result; } +//------------------------------------------------------------------------------ +// fgSetPreferredInitCctor: Set CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE as the +// preferred call constructure if it is undefined. +// +void Compiler::fgSetPreferredInitCctor() +{ + if (m_preferredInitCctor == CORINFO_HELP_UNDEF) + { + // This is the cheapest helper that triggers the constructor. + m_preferredInitCctor = CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE; + } +} + GenTreeCall* Compiler::fgGetSharedCCtor(CORINFO_CLASS_HANDLE cls) { #ifdef FEATURE_READYTORUN @@ -893,8 +906,8 @@ GenTreeCall* Compiler::fgGetSharedCCtor(CORINFO_CLASS_HANDLE cls) CORINFO_RESOLVED_TOKEN resolvedToken; memset(&resolvedToken, 0, sizeof(resolvedToken)); resolvedToken.hClass = cls; - - return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_STATIC_BASE, TYP_BYREF); + fgSetPreferredInitCctor(); + return impReadyToRunHelperToTree(&resolvedToken, m_preferredInitCctor, TYP_BYREF); } #endif diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 4a3b20eb855ad..074510b2d7725 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -4277,7 +4277,13 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT callFlags |= GTF_CALL_HOISTABLE; } - op1 = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_STATIC_BASE, TYP_BYREF); + op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && + (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || + pFieldInfo->helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE)) + { + m_preferredInitCctor = pFieldInfo->helper; + } op1->gtFlags |= callFlags; op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 13e81bda6ac74..6ee34ed06ed5a 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -8369,18 +8369,9 @@ GenTree* Compiler::fgMorphConst(GenTree* tree) { // For un-important blocks, we want to construct the string lazily - if (helper == CORINFO_HELP_STRCNS_CURRENT_MODULE) - { - tree = gtNewHelperCallNode(helper, TYP_REF, - gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT)); - } - else - { - tree = gtNewHelperCallNode(helper, TYP_REF, - gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), - gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); - } - + tree = + gtNewHelperCallNode(helper, TYP_REF, gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), + gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); return fgMorphTree(tree); } } @@ -14311,7 +14302,8 @@ GenTree* Compiler::fgInitThisClass() if (!(info.compClassAttr & CORINFO_FLG_SHAREDINST)) { resolvedToken.hClass = info.compClassHnd; - return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_STATIC_BASE, TYP_BYREF); + fgSetPreferredInitCctor(); + return impReadyToRunHelperToTree(&resolvedToken, m_preferredInitCctor, TYP_BYREF); } // We need a runtime lookup. diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 71dd6f03d2c95..45974776dadd6 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -1399,7 +1399,10 @@ void HelperCallProperties::init() case CORINFO_HELP_GETSTATICFIELDADDR_TLS: case CORINFO_HELP_GETGENERICS_GCSTATIC_BASE: case CORINFO_HELP_GETGENERICS_NONGCSTATIC_BASE: - case CORINFO_HELP_READYTORUN_STATIC_BASE: + case CORINFO_HELP_READYTORUN_GCSTATIC_BASE: + case CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE: + case CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: + case CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: case CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE: // These may invoke static class constructors diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 4a8c2ad0976bf..681cadd543894 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10194,7 +10194,10 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } break; - case VNF_ReadyToRunStaticBase: + case VNF_ReadyToRunStaticBaseGC: + case VNF_ReadyToRunStaticBaseNonGC: + case VNF_ReadyToRunStaticBaseThread: + case VNF_ReadyToRunStaticBaseThreadNonGC: case VNF_ReadyToRunGenericStaticBase: case VNF_ReadyToRunIsInstanceOf: case VNF_ReadyToRunCastClass: @@ -10555,8 +10558,17 @@ VNFunc Compiler::fgValueNumberJitHelperMethodVNFunc(CorInfoHelpFunc helpFunc) case CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR: vnf = VNF_GetsharedNongcstaticBaseNoctor; break; - case CORINFO_HELP_READYTORUN_STATIC_BASE: - vnf = VNF_ReadyToRunStaticBase; + case CORINFO_HELP_READYTORUN_GCSTATIC_BASE: + vnf = VNF_ReadyToRunStaticBaseGC; + break; + case CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE: + vnf = VNF_ReadyToRunStaticBaseNonGC; + break; + case CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: + vnf = VNF_ReadyToRunStaticBaseThread; + break; + case CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: + vnf = VNF_ReadyToRunStaticBaseThreadNonGC; break; case CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE: vnf = VNF_ReadyToRunGenericStaticBase; diff --git a/src/coreclr/jit/valuenumfuncs.h b/src/coreclr/jit/valuenumfuncs.h index b8fcc8b7af66a..32c0a6435b81e 100644 --- a/src/coreclr/jit/valuenumfuncs.h +++ b/src/coreclr/jit/valuenumfuncs.h @@ -115,7 +115,10 @@ ValueNumFuncDef(GetsharedGcstaticBase, 2, false, true, true) ValueNumFuncDef(GetsharedNongcstaticBase, 2, false, true, true) ValueNumFuncDef(GetsharedGcstaticBaseNoctor, 1, false, true, true) ValueNumFuncDef(GetsharedNongcstaticBaseNoctor, 1, false, true, true) -ValueNumFuncDef(ReadyToRunStaticBase, 1, false, true, true) +ValueNumFuncDef(ReadyToRunStaticBaseGC, 1, false, true, true) +ValueNumFuncDef(ReadyToRunStaticBaseNonGC, 1, false, true, true) +ValueNumFuncDef(ReadyToRunStaticBaseThread, 1, false, true, true) +ValueNumFuncDef(ReadyToRunStaticBaseThreadNonGC, 1, false, true, true) ValueNumFuncDef(ReadyToRunGenericStaticBase, 2, false, true, true) ValueNumFuncDef(GetsharedGcstaticBaseDynamicclass, 2, false, true, true) ValueNumFuncDef(GetsharedNongcstaticBaseDynamicclass, 2, false, true, true) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index c6774127307e0..df5e74249682c 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -59,7 +59,6 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_NEWARR_1_ALIGN8, // like VC, but aligns the array start CORINFO_HELP_STRCNS, // create a new string literal - CORINFO_HELP_STRCNS_CURRENT_MODULE, // create a new string literal from the current module (used by NGen code) /* Object model */ CORINFO_HELP_INITCLASS, // Initialize class if not already initialized @@ -233,7 +232,10 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_READYTORUN_NEWARR_1, CORINFO_HELP_READYTORUN_ISINSTANCEOF, CORINFO_HELP_READYTORUN_CHKCAST, - CORINFO_HELP_READYTORUN_STATIC_BASE, + CORINFO_HELP_READYTORUN_GCSTATIC_BASE, + CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, + CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, + CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 5f2aa030dca74..a0b956c3d8fc9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3237,6 +3237,29 @@ private uint getThreadTLSIndex(ref void* ppIndirection) } } + public static ReadyToRunHelperId GetReadyToRunHelperFromStaticBaseHelper(CorInfoHelpFunc helper) + { + ReadyToRunHelperId res; + switch (helper) + { + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GCSTATIC_BASE: + res = ReadyToRunHelperId.GetGCStaticBase; + break; + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE: + res = ReadyToRunHelperId.GetNonGCStaticBase; + break; + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: + res = ReadyToRunHelperId.GetThreadStaticBase; + break; + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: + res = ReadyToRunHelperId.GetThreadNonGcStaticBase; + break; + default: + throw new NotImplementedException("ReadyToRun: " + helper.ToString()); + } + return res; + } + private void getFunctionFixedEntryPoint(CORINFO_METHOD_STRUCT_* ftn, bool isUnsafeFunctionPointer, ref CORINFO_CONST_LOOKUP pResult) { throw new NotImplementedException("getFunctionFixedEntryPoint"); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 907a6245c5326..066687296f159 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -726,13 +726,16 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.CreateReadyToRunHelper(ReadyToRunHelperId.CastClass, type)); } break; - case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GCSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: { var type = HandleToObject(pResolvedToken.hClass); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) return false; - - pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.CreateReadyToRunHelper(ReadyToRunHelperId.CctorTrigger, type)); + var helperId = GetReadyToRunHelperFromStaticBaseHelper(id); + pLookup = CreateConstLookupToSymbol(_compilation.SymbolNodeFactory.CreateReadyToRunHelper(helperId, type)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GENERIC_HANDLE: @@ -1536,7 +1539,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET else { fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER; - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE; + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_UNDEF; ReadyToRunHelperId helperId = ReadyToRunHelperId.Invalid; CORINFO_FIELD_ACCESSOR intrinsicAccessor; @@ -1550,18 +1553,27 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { if (field.HasGCStaticBase) { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadStaticBase; } else { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadNonGcStaticBase; } } else { - helperId = field.HasGCStaticBase ? - ReadyToRunHelperId.GetGCStaticBase : - ReadyToRunHelperId.GetNonGCStaticBase; + if (field.HasGCStaticBase) + { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GCSTATIC_BASE; + helperId = ReadyToRunHelperId.GetGCStaticBase; + } + else + { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE; + helperId = ReadyToRunHelperId.GetNonGCStaticBase; + } } if (!_compilation.NodeFactory.CompilationModuleGroup.VersionsWithType(field.OwningType) && diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 9911a0f3c21e1..c51c976c5037f 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -312,13 +312,16 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_ISINSTANCEOF: case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_CHKCAST: return false; - case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GCSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: { var type = HandleToObject(pResolvedToken.hClass); if (type.IsCanonicalSubtype(CanonicalFormKind.Any)) return false; - - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(ReadyToRunHelperId.GetNonGCStaticBase, type)); + var helperId = GetReadyToRunHelperFromStaticBaseHelper(id); + pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ReadyToRunHelper(helperId, type)); } break; case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE: @@ -2123,7 +2126,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET else { fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER; - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE; + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_UNDEF; ReadyToRunHelperId helperId = ReadyToRunHelperId.Invalid; CORINFO_FIELD_ACCESSOR intrinsicAccessor; @@ -2135,13 +2138,21 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET } else if (field.IsThreadStatic) { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadStaticBase; } else { - helperId = field.HasGCStaticBase ? - ReadyToRunHelperId.GetGCStaticBase : - ReadyToRunHelperId.GetNonGCStaticBase; + if (field.HasGCStaticBase) + { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_GCSTATIC_BASE; + helperId = ReadyToRunHelperId.GetGCStaticBase; + } + else + { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE; + helperId = ReadyToRunHelperId.GetNonGCStaticBase; + } // // Currently, we only do this optimization for regular statics, but it