Skip to content

Commit

Permalink
Fix PGO trace data collection in the presence of collectible assembli…
Browse files Browse the repository at this point in the history
…es (dotnet#68001)

* Fix PGO data emission in the presence of collectible assemblies
  • Loading branch information
davidwrighton authored Apr 15, 2022
1 parent 3088b05 commit 248b8c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/coreclr/vm/pgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class SchemaWriterFunctor

auto lambda = [&](int64_t thWritten)
{
if (ICorJitInfo::IsUnknownTypeHandle(thWritten)) return;

if (thWritten != 0)
{
TypeHandle th = *(TypeHandle*)&thWritten;
Expand All @@ -129,6 +131,7 @@ class SchemaWriterFunctor
typeHandlesEncountered.Append(th);
}
}
return;
};

if (!writer.AppendDataFromLastSchema(lambda))
Expand All @@ -140,6 +143,7 @@ class SchemaWriterFunctor
}
};

#ifndef DACCESS_COMPILE
void PgoManager::WritePgoData()
{
if (ETW_EVENT_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context, JitInstrumentationDataVerbose))
Expand Down Expand Up @@ -233,11 +237,16 @@ void PgoManager::WritePgoData()
break;
case ICorJitInfo::PgoInstrumentationKind::TypeHandle:
{
TypeHandle th = *(TypeHandle*)(data + entryOffset);
intptr_t typehandleData = *(intptr_t*)(data + entryOffset);
TypeHandle th = TypeHandle::FromPtr((void*)typehandleData);
if (th.IsNull())
{
fprintf(pgoDataFile, s_TypeHandle, "NULL");
}
else if (ICorJitInfo::IsUnknownTypeHandle(typehandleData))
{
fprintf(pgoDataFile, s_TypeHandle, "UNKNOWN");
}
else
{
StackSString ss;
Expand Down Expand Up @@ -272,6 +281,7 @@ void PgoManager::WritePgoData()
fprintf(pgoDataFile, s_FileTrailerString);
fclose(pgoDataFile);
}
#endif // DACCESS_COMPILE

void ReadLineAndDiscard(FILE* file)
{
Expand Down Expand Up @@ -459,7 +469,7 @@ void PgoManager::ReadPgoData()

TypeHandle th;
INT_PTR ptrVal = 0;
if (strcmp(typeString, "NULL") != 0)
if ((strcmp(typeString, "NULL") != 0) || (strcmp(typeString, "UNKNOWN") != 0))
{
// As early type loading is likely problematic, simply drop the string into the data, and fix it up later
void* tempString = malloc(endOfString);
Expand Down

0 comments on commit 248b8c0

Please sign in to comment.