diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index f8893f7351fe6..9dab914dbc931 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -901,6 +901,12 @@ HCIMPL1(void*, JIT_GetNonGCThreadStaticBaseOptimized, UINT32 staticBlockIndex) FCALL_CONTRACT; + staticBlock = GetThreadLocalStaticBaseIfExistsAndInitialized(staticBlockIndex); + if (staticBlock != NULL) + { + return staticBlock; + } + HELPER_METHOD_FRAME_BEGIN_RET_0(); // Set up a frame TLSIndex tlsIndex(staticBlockIndex); // Check if the class constructor needs to be run @@ -975,6 +981,12 @@ HCIMPL1(void*, JIT_GetGCThreadStaticBaseOptimized, UINT32 staticBlockIndex) FCALL_CONTRACT; + staticBlock = GetThreadLocalStaticBaseIfExistsAndInitialized(staticBlockIndex); + if (staticBlock != NULL) + { + return staticBlock; + } + HELPER_METHOD_FRAME_BEGIN_RET_0(); // Set up a frame TLSIndex tlsIndex(staticBlockIndex); diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index c8072a2731256..27dfd82a691ed 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -3840,8 +3840,8 @@ void MethodTable::CheckRunClassInitThrowing() // To find GC hole easier... TRIGGERSGC(); - // Don't initialize shared generic instantiations (e.g. MyClass<__Canon>) - if (IsSharedByGenericInstantiations()) + // Don't initialize shared generic instantiations (e.g. MyClass<__Canon>), or an already initialized MethodTable + if (IsClassInited() || IsSharedByGenericInstantiations()) return; _ASSERTE(!ContainsGenericVariables()); @@ -3946,7 +3946,11 @@ void MethodTable::EnsureTlsIndexAllocated() CONTRACTL_END; PTR_MethodTableAuxiliaryData pAuxiliaryData = GetAuxiliaryDataForWrite(); - if (!pAuxiliaryData->IsTlsIndexAllocated() && GetNumThreadStaticFields() > 0) + + if (pAuxiliaryData->IsTlsIndexAllocated()) + return; + + if (GetNumThreadStaticFields() > 0) { ThreadStaticsInfo *pThreadStaticsInfo = MethodTableAuxiliaryData::GetThreadStaticsInfo(GetAuxiliaryDataForWrite()); // Allocate space for normal statics if we might have them