From 0846b49f435711339fb5f958b5629c45ef696f36 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Sat, 6 Dec 2025 19:48:27 -0500 Subject: [PATCH 1/4] Avoid writing jitdump code for block data --- src/coreclr/pal/inc/pal.h | 2 +- src/coreclr/pal/src/misc/perfjitdump.cpp | 17 ++++++++--------- src/coreclr/vm/perfmap.cpp | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 88e67e10c71700..600936bfff8495 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -385,7 +385,7 @@ PALIMPORT int PALAPI // Log a method to the jitdump file. -PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo); +PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock = true); PALIMPORT int diff --git a/src/coreclr/pal/src/misc/perfjitdump.cpp b/src/coreclr/pal/src/misc/perfjitdump.cpp index 84680cc2b4ffed..3b45b8c8856d62 100644 --- a/src/coreclr/pal/src/misc/perfjitdump.cpp +++ b/src/coreclr/pal/src/misc/perfjitdump.cpp @@ -247,7 +247,7 @@ struct PerfJitDumpState return 0; } - int LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo) + int LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock) { int result = 0; @@ -257,7 +257,9 @@ struct PerfJitDumpState JitCodeLoadRecord record; - size_t bytesRemaining = sizeof(JitCodeLoadRecord) + symbolLen + 1 + codeSize; + size_t reportedCodeSize = reportCodeBlock ? codeSize : 0; + + size_t bytesRemaining = sizeof(JitCodeLoadRecord) + symbolLen + 1 + reportedCodeSize; record.header.timestamp = GetTimeStampNS(); record.vma = (uint64_t) pCode; @@ -269,15 +271,12 @@ struct PerfJitDumpState // ToDo insert debugInfo and unwindInfo record items immediately before the JitCodeLoadRecord. { &record, sizeof(JitCodeLoadRecord) }, { (void *)symbol, symbolLen + 1 }, - { pCode, codeSize }, + { pCode, reportedCodeSize }, }; size_t itemsCount = sizeof(items) / sizeof(items[0]); size_t itemsWritten = 0; - if (result != 0) - return FatalError(); - if (!enabled) goto exit; @@ -390,9 +389,9 @@ PAL_PerfJitDump_IsStarted() int PALAPI -PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo) +PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock) { - return GetState().LogMethod(pCode, codeSize, symbol, debugInfo, unwindInfo); + return GetState().LogMethod(pCode, codeSize, symbol, debugInfo, unwindInfo, reportCodeBlock); } int @@ -420,7 +419,7 @@ PAL_PerfJitDump_IsStarted() int PALAPI -PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo) +PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock) { return 0; } diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 74be61ed435527..937524e6ae88cc 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -431,7 +431,7 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, s_Current->WriteLine(line); } - PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr); + PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, stubAllocationType != PerfMapStubType::Block); } } EX_CATCH{} EX_END_CATCH From 571b734c0e9f1e99f5ab5ec7bff3ad3df2e91181 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Wed, 4 Feb 2026 22:20:26 -0500 Subject: [PATCH 2/4] Address PR feedback --- src/coreclr/vm/perfmap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 937524e6ae88cc..2339b8d39d777d 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -431,6 +431,9 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, s_Current->WriteLine(line); } + // For block-level stub allocations, the memory may be reserved but not yet committed. + // Emitting code bytes in that case can cause jitdump logging to fail, and the bytes + // are optional in the jitdump specification. PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, stubAllocationType != PerfMapStubType::Block); } } From bc2db43b417242dc02b536cd1631b75c21880fce Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Wed, 11 Feb 2026 16:52:09 -0500 Subject: [PATCH 3/4] Address PR feedback --- src/coreclr/pal/inc/pal.h | 2 +- src/coreclr/vm/perfmap.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index f42a0fca5f192b..e70a5433ff7090 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -360,7 +360,7 @@ PALIMPORT int PALAPI // Log a method to the jitdump file. -PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock = true); +PAL_PerfJitDump_LogMethod(void* pCode, size_t codeSize, const char* symbol, void* debugInfo, void* unwindInfo, bool reportCodeBlock); PALIMPORT int diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index a8dba83cb1d953..c093313944811a 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -339,7 +339,7 @@ void PerfMap::LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t cod s_Current->WriteLine(line); } - PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr); + PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true); } } EX_CATCH{} EX_END_CATCH @@ -380,7 +380,7 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode) if (methodRegionInfo.hotSize > 0) { CrstHolder ch(&(s_csPerfMap)); - PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.hotStartAddress, methodRegionInfo.hotSize, name.GetUTF8(), nullptr, nullptr); + PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.hotStartAddress, methodRegionInfo.hotSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true); } if (methodRegionInfo.coldSize > 0) @@ -393,7 +393,7 @@ void PerfMap::LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode) name.Append(W("[PreJit-cold]")); } - PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr); + PAL_PerfJitDump_LogMethod((void*)methodRegionInfo.coldStartAddress, methodRegionInfo.coldSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/true); } } EX_CATCH{} EX_END_CATCH @@ -453,7 +453,7 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, // For block-level stub allocations, the memory may be reserved but not yet committed. // Emitting code bytes in that case can cause jitdump logging to fail, and the bytes // are optional in the jitdump specification. - PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, stubAllocationType != PerfMapStubType::Block); + PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/ stubAllocationType != PerfMapStubType::Block); } } EX_CATCH{} EX_END_CATCH From 18613bb3407199acb76e5c450eb5825f43f03928 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Tue, 10 Mar 2026 12:48:56 -0400 Subject: [PATCH 4/4] Add comment stating why we don't report block allocations --- src/coreclr/vm/perfmap.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index c093313944811a..d51c75dbe35f01 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -453,6 +453,10 @@ void PerfMap::LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, // For block-level stub allocations, the memory may be reserved but not yet committed. // Emitting code bytes in that case can cause jitdump logging to fail, and the bytes // are optional in the jitdump specification. + // + // Even when the memory is committed, block-level stubs are reported at commit time + // before the actual stub code has been written, so the code bytes would be zeros or + // uninitialized. We therefore skip code bytes for block allocations entirely. PAL_PerfJitDump_LogMethod((void*)pCode, codeSize, name.GetUTF8(), nullptr, nullptr, /*reportCodeBlock*/ stubAllocationType != PerfMapStubType::Block); } }