Skip to content

Commit

Permalink
Do not create R2R in memory hashes if profiler is not present or hasn…
Browse files Browse the repository at this point in the history
…'t added types (dotnet#49177)

* only create lazy map if profiler added types

* also don't create for ApplyMetadata if they haven't added new types

* add check to skip call if no profiler was called

* Update src/coreclr/vm/ceeload.cpp

Co-authored-by: Brian Robbins <[email protected]>

Co-authored-by: Brian Robbins <[email protected]>
  • Loading branch information
davmason and brianrob authored Mar 5, 2021
1 parent e0b4fc6 commit 05f9cc1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ void Module::UpdateNewlyAddedTypes()
DWORD countExportedTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtExportedType);
DWORD countCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);

if (m_dwTypeCount == countTypesAfterProfilerUpdate
&& m_dwExportedTypeCount == countExportedTypesAfterProfilerUpdate
&& m_dwCustomAttributeCount == countCustomAttributeCount)
{
// The profiler added no new types, do not create the in memory hashes
return;
}

// R2R pre-computes an export table and tries to avoid populating a class hash at runtime. However the profiler can
// still add new types on the fly by calling here. If that occurs we fallback to the slower path of creating the
// in memory hashtable as usual.
Expand Down Expand Up @@ -280,6 +288,7 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
}

BOOL profilerCallbackHappened = FALSE;
// Notify the profiler, this may cause metadata to be updated
{
BEGIN_PIN_PROFILER(CORProfilerTrackModuleLoads());
Expand All @@ -292,13 +301,15 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
g_profControlBlock.pProfInterface->ModuleAttachedToAssembly((ModuleID) this,
(AssemblyID)m_pAssembly);
}

profilerCallbackHappened = TRUE;
}
END_PIN_PROFILER();
}

// If there are more types than before, add these new types to the
// assembly
if (!IsResource())
if (profilerCallbackHappened && !IsResource())
{
UpdateNewlyAddedTypes();
}
Expand Down Expand Up @@ -13832,4 +13843,3 @@ void EEConfig::DebugCheckAndForceIBCFailure(BitForMask bitForMask)
}
}
#endif // defined(_DEBUG) && !defined(DACCESS_COMPILE)

0 comments on commit 05f9cc1

Please sign in to comment.