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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Change the PerfMap crst into an UNSAFE_ANYMODE crst by davidwrighton · Pull Request #129021 · dotnet/runtime · GitHub
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
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -433,7 +433,7 @@ RETAIL_CONFIG_STRING_INFO(UNSUPPORTED_ETW_ObjectAllocationEventsPerTypePerSec, W
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux and macOS to enable writing /tmp/perf-$pid.map. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored as a marker in the perf logs. It is disabled by default")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapShowOptimizationTiers, W("PerfMapShowOptimizationTiers"), 1, "Shows optimization tiers in the perf map for methods, as part of the symbol name. Useful for seeing separate stack frames for different optimization tiers of each method.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate).")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_PerfMapStubGranularity, W("PerfMapStubGranularity"), 0, "Report stubs with varying amounts of granularity (low bit being zero indicates attempt to group all stubs of a type together) (second lowest bit being non-zero records stubs at individual allocation sites, which is more expensive, but also more accurate) (third lowest bit disables stub logging).")
#endif

RETAIL_CONFIG_STRING_INFO(EXTERNAL_StartupDelayMS, W("StartupDelayMS"), "")
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -233,7 +233,11 @@ static
uint32_t
ds_rt_enable_perfmap (uint32_t type)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

#ifdef FEATURE_PERFMAP
PerfMap::PerfMapType perfMapType = (PerfMap::PerfMapType)type;
Expand Down
40 changes: 31 additions & 9 deletions src/coreclr/vm/perfmap.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ PerfMap * PerfMap::s_Current = nullptr;
bool PerfMap::s_ShowOptimizationTiers = false;
bool PerfMap::s_GroupStubsOfSameType = false;
bool PerfMap::s_IndividualAllocationStubReporting = false;
bool PerfMap::s_LogStubs = false;

unsigned PerfMap::s_StubsMapped = 0;
CrstStatic PerfMap::s_csPerfMap;
Expand All@@ -47,7 +48,15 @@ void PerfMap::Initialize()
{
LIMITED_METHOD_CONTRACT;

s_csPerfMap.Init(CrstPerfMap);
// Use CRST_UNSAFE_ANYMODE to avoid a GC-mode toggle deadlock: callers such as
// CodeFragmentHeap::RealAllocAlignedMem hold CRST_UNSAFE_ANYMODE locks in cooperative
// mode. A default Crst here would toggle cooperative->preemptive->acquire->cooperative,
// and the post-acquire DisablePreemptiveGC can block on a pending GC suspension,
// forming a deadlock cycle with threads waiting on the outer UNSAFE_ANYMODE lock.
// All data accessed under this lock is native (FILE*, fd, SString) so holding it
// in cooperative mode does not introduce new GC-safety issues. Doing I/O
// in cooperative mode is still less than ideal.
s_csPerfMap.Init(CrstPerfMap, CrstFlags(CRST_UNSAFE_ANYMODE));

PerfMapType perfMapType = (PerfMapType)CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapEnabled);
PerfMap::Enable(perfMapType, false);
Expand DownExpand Up@@ -77,11 +86,16 @@ void PerfMap::InitializeConfiguration()
DWORD granularity = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapStubGranularity);
s_GroupStubsOfSameType = (granularity & 1) != 1;
s_IndividualAllocationStubReporting = (granularity & 2) != 0;
s_LogStubs = (granularity & 4) == 0;
}
Comment thread
davidwrighton marked this conversation as resolved.

void PerfMap::Enable(PerfMapType type, bool sendExisting)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
MODE_PREEMPTIVE;
}
CONTRACTL_END;

if (type == PerfMapType::DISABLED)
{
Expand DownExpand Up@@ -294,8 +308,6 @@ void PerfMap::WriteLine(SString& line)

void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
LIMITED_METHOD_CONTRACT;

CONTRACTL{
THROWS;
GC_NOTRIGGER;
Expand DownExpand Up@@ -349,7 +361,12 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod
// Log a pre-compiled method to the perfmap.
void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
Comment thread
davidwrighton marked this conversation as resolved.
}
CONTRACTL_END;

if (!s_enabled)
{
Expand DownExpand Up@@ -385,14 +402,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)

if (methodRegionInfo.coldSize > 0)
{
CrstHolder ch(&(s_csPerfMap));

if (s_ShowOptimizationTiers)
{
pMethod->GetFullMethodInfo(name);
name.Append(W("[PreJit-cold]"));
}

CrstHolder ch(&(s_csPerfMap));
Comment thread
davidwrighton marked this conversation as resolved.

PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true);
}
}
Expand All@@ -402,9 +419,14 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
// Log a set of stub to the map.
void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
LIMITED_METHOD_CONTRACT;
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!s_enabled)
if (!s_enabled || !s_LogStubs)
{
return;
}
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/perfmap.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,52 @@ enum class PerfMapStubType
Individual
};

#ifndef FEATURE_PERFMAP

class PerfMap
{
public:
static bool IsEnabled()
{
#ifdef DEBUG
return true;
Comment thread
davidwrighton marked this conversation as resolved.
#else
return false;
#endif
Comment thread
davidwrighton marked this conversation as resolved.
}
Comment thread
davidwrighton marked this conversation as resolved.
static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize, PrepareCodeConfig *pConfig)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
}

static void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode)
{
CONTRACTL
{
THROWS;
MODE_PREEMPTIVE;
}
CONTRACTL_END;
Comment thread
davidwrighton marked this conversation as resolved.
}

static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize, PerfMapStubType stubAllocationType)
{
CONTRACTL
{
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
}
Comment thread
davidwrighton marked this conversation as resolved.
};

#else // FEATURE_PERFMAP

class PerfMap
{
private:
Expand All@@ -36,6 +82,7 @@ class PerfMap
// Indicate current stub granularity rules
static bool s_GroupStubsOfSameType;
static bool s_IndividualAllocationStubReporting;
static bool s_LogStubs; // If false, do not log stubs at all

// Set to true if an error is encountered when writing to the file.
static unsigned s_StubsMapped;
Expand DownExpand Up@@ -112,4 +159,5 @@ class PerfMap

static bool LowGranularityStubs() { return !s_IndividualAllocationStubReporting; }
};
#endif // FEATURE_PERFMAP
#endif // PERFPID_H
85 changes: 58 additions & 27 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,7 @@
#include "comdelegate.h"
#include <dn-stdio.h>

#ifdef FEATURE_PERFMAP
#include "perfmap.h"
#endif

#ifndef DACCESS_COMPILE

Expand DownExpand Up@@ -1051,7 +1049,19 @@ PCODE VirtualCallStubManager::GetCallStub(DispatchToken token)
{
if ((stub = (PCODE)(lookups->Find(&probeL))) == CALL_STUB_EMPTY_ENTRY)
{
LookupHolder *pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
LookupHolder *pLookupHolder;
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
Comment thread
davidwrighton marked this conversation as resolved.
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pLookupHolder = GenerateLookupStub(addrOfResolver, token.To_SIZE_T());
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = lookups->SetUpProber(token.To_SIZE_T(), 0, &probeL);
Comment thread
davidwrighton marked this conversation as resolved.
_ASSERTE(success);
}
stub = (PCODE) (lookups->Add((size_t)(pLookupHolder->stub()->entryPoint()), &probeL));
}
}
Expand DownExpand Up@@ -1082,7 +1092,20 @@ PCODE VirtualCallStubManager::GetVTableCallStub(DWORD slot)
{
if ((stub = (PCODE)(vtableCallers->Find(&probe))) == CALL_STUB_EMPTY_ENTRY)
{
VTableCallHolder *pHolder = GenerateVTableCallStub(slot);
VTableCallHolder *pHolder;

bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pHolder = GenerateVTableCallStub(slot);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = vtableCallers->SetUpProber(DispatchToken::CreateDispatchToken(slot).To_SIZE_T(), 0, &probe);
_ASSERTE(success);
}
stub = (PCODE)(vtableCallers->Add((size_t)(pHolder->stub()->entryPoint()), &probe));
}
}
Expand DownExpand Up@@ -1115,9 +1138,7 @@ VTableCallHolder* VirtualCallStubManager::GenerateVTableCallStub(DWORD slot)
LOG((LF_STUBS, LL_INFO10000, "GenerateVTableCallStub for slot " FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(slot), DBG_ADDR(pHolder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateVTableCallStub", (PCODE)pHolder->stub(), pHolder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN(pHolder);
}
Expand DownExpand Up@@ -2054,14 +2075,24 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
}
#endif // TARGET_X86 && !UNIX_X86_ABI

pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pResolveHolder = GenerateResolveStub(pResolverFcn,
pBackPatchFcn,
token.To_SIZE_T()
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
, stackArgumentsSize
, stackArgumentsSize
#endif
);
}

if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
BOOL success = resolvers->SetUpProber(token.To_SIZE_T(), 0, &probeR);
_ASSERTE(success);
}
// Add the resolve entrypoint into the cache.
//@TODO: Can we store a pointer to the holder rather than the entrypoint?
resolvers->Add((size_t)(pResolveHolder->stub()->resolveEntryPoint()), &probeR);
Expand DownExpand Up@@ -2095,9 +2126,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
if (addrOfDispatch == CALL_STUB_EMPTY_ENTRY)
{
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2208,9 +2242,12 @@ PCODE VirtualCallStubManager::ResolveWorker(StubCallSite* pCallSite,
// so we may have to create it now
ResolveHolder* pResolveHolder = ResolveHolder::FromResolveEntry(pCallSite->GetSiteTarget());
PCODE addrOfFail = pResolveHolder->stub()->failEntryPoint();
bool reenteredCooperativeGCMode = false;
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
bool reenteredCooperativeGCMode = PerfMap::IsEnabled();
{
GCX_MAYBE_PREEMP(reenteredCooperativeGCMode);
pDispatchHolder = GenerateDispatchStub(
target, addrOfFail, objectType, token.To_SIZE_T(), &reenteredCooperativeGCMode);
}
Comment thread
davidwrighton marked this conversation as resolved.
if (reenteredCooperativeGCMode)
{
// The prober may have been invalidated by reentering cooperative GC mode, reset it
Expand DownExpand Up@@ -2799,7 +2836,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2862,9 +2898,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStub(PCODE ad
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand All@@ -2888,7 +2922,6 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
PRECONDITION(addrOfFail != NULL);
PRECONDITION(CheckPointer(pMTExpected));
PRECONDITION(pMayHaveReenteredCooperativeGCMode != nullptr);
PRECONDITION(!*pMayHaveReenteredCooperativeGCMode);
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;

Expand DownExpand Up@@ -2923,9 +2956,7 @@ DispatchHolder *VirtualCallStubManager::GenerateDispatchStubLong(PCODE
LOG((LF_STUBS, LL_INFO10000, "GenerateDispatchStub for token" FMT_ADDR "and pMT" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(pMTExpected), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateDispatchStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3021,9 +3052,7 @@ ResolveHolder *VirtualCallStubManager::GenerateResolveStub(PCODE addr
LOG((LF_STUBS, LL_INFO10000, "GenerateResolveStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateResolveStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3054,9 +3083,7 @@ LookupHolder *VirtualCallStubManager::GenerateLookupStub(PCODE addrOfResolver, s
LOG((LF_STUBS, LL_INFO10000, "GenerateLookupStub for token" FMT_ADDR "at" FMT_ADDR "\n",
DBG_ADDR(dispatchToken), DBG_ADDR(holder->stub())));

#ifdef FEATURE_PERFMAP
PerfMap::LogStubs(__FUNCTION__, "GenerateLookupStub", (PCODE)holder->stub(), holder->stub()->size(), PerfMapStubType::IndividualWithinBlock);
#endif

RETURN (holder);
}
Expand DownExpand Up@@ -3084,8 +3111,12 @@ ResolveCacheElem *VirtualCallStubManager::GenerateResolveCacheElem(void *addrOfC
CONSISTENCY_CHECK(CheckPointer(pMTExpected));

//allocate from the requisite heap and set the appropriate fields
ResolveCacheElem *e = (ResolveCacheElem*) (void*)
ResolveCacheElem *e;
{
GCX_NOTRIGGER();
e = (ResolveCacheElem*) (void*)
cache_entry_heap->AllocAlignedMem(sizeof(ResolveCacheElem), CODE_SIZE_ALIGN);
}

e->pMT = pMTExpected;
e->token = token;
Expand Down
Loading