Skip to content

Commit ef6ca45

Browse files
Finish profiler feature cleanup
Co-authored-by: Copilot <[email protected]> Copilot-Session: da72e163-376d-48aa-988d-c52f3150a614
1 parent 45074e8 commit ef6ca45

3 files changed

Lines changed: 43 additions & 29 deletions

File tree

‎src/coreclr/clr.featuredefines.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<FeaturePortableTimer>true</FeaturePortableTimer>
1414
</PropertyGroup>
1515

16-
<PropertyGroup Condition="'$(TargetsWasm)' == 'true' OR '$(TargetsAndroid)' == 'true' OR '$(TargetsMacCatalyst)' == 'true' OR '$(TargetsiOS)' == 'true' OR '$(TargetstvOS)' == 'true'">
16+
<PropertyGroup Condition="'$(TargetsMobile)' == 'true' OR '$(TargetsWasm)' == 'true' OR '$(TargetsLinuxBionic)' == 'true'">
1717
<FeatureCorProfiler>false</FeatureCorProfiler>
1818
</PropertyGroup>
1919

‎src/coreclr/vm/ceeload.cpp‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,8 @@ void Module::UpdateNewlyAddedTypes()
217217
}
218218
CONTRACTL_END
219219

220-
DWORD countTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtTypeDef);
221-
DWORD countExportedTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtExportedType);
222-
DWORD countCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
223-
224-
if (m_dwTypeCount == countTypesAfterProfilerUpdate
225-
&& m_dwExportedTypeCount == countExportedTypesAfterProfilerUpdate
226-
&& m_dwCustomAttributeCount == countCustomAttributeCount)
220+
TypeCounts currTypeCounts = GetCurrentTypeCounts();
221+
if (m_typeCounts == currTypeCounts)
227222
{
228223
// The profiler added no new types, do not create the in memory hashes
229224
return;
@@ -242,27 +237,39 @@ void Module::UpdateNewlyAddedTypes()
242237
// If the hash tables already exist (either R2R and we've previously populated the ) we need to manually add the types.
243238

244239
// typeDefs rids 0 and 1 aren't included in the count, thus X typeDefs before means rid X+1 was valid and our incremental addition should start at X+2
245-
for (DWORD typeDefRid = m_dwTypeCount + 2; typeDefRid < countTypesAfterProfilerUpdate + 2; typeDefRid++)
240+
for (DWORD typeDefRid = m_typeCounts.TypeCount + 2; typeDefRid < currTypeCounts.TypeCount + 2; typeDefRid++)
246241
{
247242
GetAssembly()->AddType(this, TokenFromRid(typeDefRid, mdtTypeDef));
248243
}
249244

250245
// exportedType rid 0 isn't included in the count, thus X exportedTypes before means rid X was valid and our incremental addition should start at X+1
251-
for (DWORD exportedTypeDef = m_dwExportedTypeCount + 1; exportedTypeDef < countExportedTypesAfterProfilerUpdate + 1; exportedTypeDef++)
246+
for (DWORD exportedTypeDef = m_typeCounts.ExportedTypeCount + 1; exportedTypeDef < currTypeCounts.ExportedTypeCount + 1; exportedTypeDef++)
252247
{
253248
GetAssembly()->AddExportedType(TokenFromRid(exportedTypeDef, mdtExportedType));
254249
}
255250

256-
if ((countCustomAttributeCount != m_dwCustomAttributeCount) && IsReadyToRun())
251+
if ((currTypeCounts.CustomAttributeCount != m_typeCounts.CustomAttributeCount) && IsReadyToRun())
257252
{
258253
// Set of custom attributes has changed. Disable the cuckoo filter from ready to run, and do normal custom attribute parsing
259254
GetReadyToRunInfo()->DisableCustomAttributeFilter();
260255
}
261256
}
262257

263-
m_dwTypeCount = countTypesAfterProfilerUpdate;
264-
m_dwExportedTypeCount = countExportedTypesAfterProfilerUpdate;
265-
m_dwCustomAttributeCount = countCustomAttributeCount;
258+
m_typeCounts = currTypeCounts;
259+
}
260+
261+
Module::TypeCounts Module::GetCurrentTypeCounts()
262+
{
263+
WRAPPER_NO_CONTRACT;
264+
265+
IMDInternalImport* pMDImport = GetMDImport();
266+
_ASSERTE(pMDImport != NULL);
267+
268+
TypeCounts typeCounts;
269+
typeCounts.TypeCount = pMDImport->GetCountWithTokenKind(mdtTypeDef);
270+
typeCounts.ExportedTypeCount = pMDImport->GetCountWithTokenKind(mdtExportedType);
271+
typeCounts.CustomAttributeCount = pMDImport->GetCountWithTokenKind(mdtCustomAttribute);
272+
return typeCounts;
266273
}
267274
#endif // PROFILING_SUPPORTED || FEATURE_METADATA_UPDATER
268275

@@ -282,10 +289,8 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
282289
// the profiler once.
283290
if (SetTransientFlagInterlocked(IS_PROFILER_NOTIFIED))
284291
{
285-
// Record how many types are already present
286-
m_dwTypeCount = GetMDImport()->GetCountWithTokenKind(mdtTypeDef);
287-
m_dwExportedTypeCount = GetMDImport()->GetCountWithTokenKind(mdtExportedType);
288-
m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
292+
// Initialize how many types are already present
293+
m_typeCounts = GetCurrentTypeCounts();
289294

290295
BOOL profilerCallbackHappened = FALSE;
291296
// Notify the profiler, this may cause metadata to be updated
@@ -498,15 +503,11 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName)
498503
}
499504

500505
#if defined(PROFILING_SUPPORTED_DATA) || defined(FEATURE_METADATA_UPDATER)
501-
#ifdef PROFILING_SUPPORTED
502-
// These will be initialized in NotifyProfilerLoadFinished.
503-
m_dwTypeCount = 0;
504-
m_dwExportedTypeCount = 0;
505-
m_dwCustomAttributeCount = 0;
506+
#if defined(PROFILING_SUPPORTED)
507+
// These will be updated in NotifyProfilerLoadFinished for profiling scenarios.
508+
m_typeCounts = {};
506509
#else
507-
m_dwTypeCount = GetMDImport()->GetCountWithTokenKind(mdtTypeDef);
508-
m_dwExportedTypeCount = GetMDImport()->GetCountWithTokenKind(mdtExportedType);
509-
m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
510+
m_typeCounts = GetCurrentTypeCounts();
510511
#endif // PROFILING_SUPPORTED
511512
#endif // PROFILING_SUPPORTED_DATA || FEATURE_METADATA_UPDATER
512513

‎src/coreclr/vm/ceeload.h‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,22 @@ class Module : public ModuleBase
862862

863863
#if defined(PROFILING_SUPPORTED_DATA) || defined(FEATURE_METADATA_UPDATER)
864864
private:
865-
DWORD m_dwTypeCount;
866-
DWORD m_dwExportedTypeCount;
867-
DWORD m_dwCustomAttributeCount;
865+
struct TypeCounts final
866+
{
867+
DWORD TypeCount;
868+
DWORD ExportedTypeCount;
869+
DWORD CustomAttributeCount;
870+
871+
bool operator==(const TypeCounts& other) const
872+
{
873+
return TypeCount == other.TypeCount
874+
&& ExportedTypeCount == other.ExportedTypeCount
875+
&& CustomAttributeCount == other.CustomAttributeCount;
876+
}
877+
};
878+
TypeCounts GetCurrentTypeCounts();
879+
880+
TypeCounts m_typeCounts;
868881
#endif // PROFILING_SUPPORTED_DATA || FEATURE_METADATA_UPDATER
869882

870883
protected:

0 commit comments

Comments
 (0)