Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perf problems found in investigation of issue #107728 #107806

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3797,8 +3797,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());
Expand Down Expand Up @@ -3903,7 +3903,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
Expand Down
Loading