Skip to content
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
4 changes: 4 additions & 0 deletions src/coreclr/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ void EEStartupHelper()

ExecutionManager::Init();

#ifdef FEATURE_PERFMAP
PerfMap::SignalDependenciesReady();
#endif

JitHost::Init();

#ifndef TARGET_UNIX
Expand Down
21 changes: 21 additions & 0 deletions src/coreclr/vm/perfmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

Volatile<bool> PerfMap::s_enabled = false;
Volatile<bool> PerfMap::s_dependenciesReady = false;
PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
Expand Down Expand Up @@ -121,6 +122,17 @@ void PerfMap::Enable(PerfMapType type, bool sendExisting)

if (sendExisting)
{
// When Enable is called very early in startup (e.g., via DiagnosticServer IPC before
// SystemDomain::Attach and ExecutionManager::Init), the AppDomain and EEJitManager
// may not exist yet. We use s_dependenciesReady (a Volatile<bool>) to guard against
// this, rather than null-checking individual pointers which would have race conditions
// due to non-Volatile statics like m_pEEJitManager.
// Safe to skip: no assemblies are loaded and no code is JIT'd at that point.
if (!s_dependenciesReady)
{
return;
}

AppDomain::AssemblyIterator assemblyIterator = GetAppDomain()->IterateAssembliesEx(
(AssemblyIterationFlags)(kIncludeLoaded | kIncludeExecution));
CollectibleAssemblyHolder<Assembly *> pAssembly;
Expand Down Expand Up @@ -208,6 +220,15 @@ void PerfMap::Disable()
}
}

// Signal that all dependencies (AppDomain, ExecutionManager) are ready.
// This method must be called before any code is JITed or restored from R2R image.
void PerfMap::SignalDependenciesReady()
{
LIMITED_METHOD_CONTRACT;

s_dependenciesReady = true;
}

// Construct a new map for the process.
PerfMap::PerfMap()
{
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class PerfMap
private:
static Volatile<bool> s_enabled;

// Set to true after all dependencies (AppDomain, ExecutionManager) are initialized.
static Volatile<bool> s_dependenciesReady;

// The one and only PerfMap for the process.
static PerfMap * s_Current;

Expand Down Expand Up @@ -104,6 +107,9 @@ class PerfMap
// Close the map and flush any remaining data.
static void Disable();

// Signal that all dependencies (AppDomain, ExecutionManager) are ready.
static void SignalDependenciesReady();

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // PERFPID_H
Loading