From ee755e322dabc2fc280e2561b0fbaf6e90aedf54 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 26 Feb 2019 08:56:45 -0800 Subject: Update added types and methoddefs on ApplyMetadata (#22617) --- src/vm/ceeload.cpp | 66 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-) (limited to 'src/vm/ceeload.cpp') diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp index 6d1643b46e..07109ae0c2 100644 --- a/src/vm/ceeload.cpp +++ b/src/vm/ceeload.cpp @@ -191,6 +191,35 @@ BOOL Module::SetTransientFlagInterlocked(DWORD dwFlag) } #if PROFILING_SUPPORTED +void Module::UpdateNewlyAddedTypes() +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + INJECT_FAULT(COMPlusThrowOM();); + } + CONTRACTL_END + + DWORD countTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); + DWORD countExportedTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtExportedType); + + // 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 + for (DWORD typeDefRid = m_dwTypeCount + 2; typeDefRid < countTypesAfterProfilerUpdate + 2; typeDefRid++) + { + GetAssembly()->AddType(this, TokenFromRid(typeDefRid, mdtTypeDef)); + } + + // 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 + for (DWORD exportedTypeDef = m_dwExportedTypeCount + 1; exportedTypeDef < countExportedTypesAfterProfilerUpdate + 1; exportedTypeDef++) + { + GetAssembly()->AddExportedType(TokenFromRid(exportedTypeDef, mdtExportedType)); + } + + m_dwTypeCount = countTypesAfterProfilerUpdate; + m_dwExportedTypeCount = countExportedTypesAfterProfilerUpdate; +} + void Module::NotifyProfilerLoadFinished(HRESULT hr) { CONTRACTL @@ -208,12 +237,10 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr) if (SetTransientFlagInterlocked(IS_PROFILER_NOTIFIED)) { // Record how many types are already present - DWORD countTypesOrig = 0; - DWORD countExportedTypesOrig = 0; if (!IsResource()) { - countTypesOrig = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); - countExportedTypesOrig = GetMDImport()->GetCountWithTokenKind(mdtExportedType); + m_dwTypeCount = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); + m_dwExportedTypeCount = GetMDImport()->GetCountWithTokenKind(mdtExportedType); } // Notify the profiler, this may cause metadata to be updated @@ -236,18 +263,7 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr) // assembly if (!IsResource()) { - DWORD countTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtTypeDef); - DWORD countExportedTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtExportedType); - // 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 - for (DWORD typeDefRid = countTypesOrig + 2; typeDefRid < countTypesAfterProfilerUpdate + 2; typeDefRid++) - { - GetAssembly()->AddType(this, TokenFromRid(typeDefRid, mdtTypeDef)); - } - // 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 - for (DWORD exportedTypeDef = countExportedTypesOrig + 1; exportedTypeDef < countExportedTypesAfterProfilerUpdate + 1; exportedTypeDef++) - { - GetAssembly()->AddExportedType(TokenFromRid(exportedTypeDef, mdtExportedType)); - } + UpdateNewlyAddedTypes(); } { @@ -585,6 +601,11 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) m_ModuleID = NULL; m_ModuleIndex.m_dwIndex = (SIZE_T)-1; + // These will be initialized in NotifyProfilerLoadFinished, set them to + // a safe initial value now. + m_dwTypeCount = 0; + m_dwExportedTypeCount = 0; + // Prepare statics that are known at module load time AllocateStatics(pamTracker); @@ -1187,7 +1208,7 @@ void Module::ApplyMetaData() CONTRACTL { THROWS; - GC_NOTRIGGER; + GC_TRIGGERS; MODE_ANY; } CONTRACTL_END; @@ -1197,6 +1218,13 @@ void Module::ApplyMetaData() HRESULT hr = S_OK; ULONG ulCount; +#if PROFILING_SUPPORTED + if (!IsResource()) + { + UpdateNewlyAddedTypes(); + } +#endif // PROFILING_SUPPORTED + // Ensure for TypeRef ulCount = GetMDImport()->GetCountWithTokenKind(mdtTypeRef) + 1; EnsureTypeRefCanBeStored(TokenFromRid(ulCount, mdtTypeRef)); @@ -1204,6 +1232,10 @@ void Module::ApplyMetaData() // Ensure for AssemblyRef ulCount = GetMDImport()->GetCountWithTokenKind(mdtAssemblyRef) + 1; EnsureAssemblyRefCanBeStored(TokenFromRid(ulCount, mdtAssemblyRef)); + + // Ensure for MethodDef + ulCount = GetMDImport()->GetCountWithTokenKind(mdtMethodDef) + 1; + EnsureMethodDefCanBeStored(TokenFromRid(ulCount, mdtMethodDef)); } // -- cgit v1.2.3