Implement ISOSDacInterface::GetThreadAllocData in cDAC SOSDacImpl#124817
Implement ISOSDacInterface::GetThreadAllocData in cDAC SOSDacImpl#124817
Conversation
|
Tagging subscribers to this area: @agocke, @VSadov |
- Add AllocBytes and AllocBytesLoh fields to GCAllocContext data descriptor - Add ThreadAllocData record struct and GetThreadAllocData to IThread contract - Implement GetThreadAllocData in Thread_1.cs contract - Define DacpAllocData managed struct in ISOSDacInterface.cs - Implement GetThreadAllocData in SOSDacImpl.cs with DEBUG comparison - Add unit tests for GetThreadAllocData with non-zero and zero values - Add dump test for GetThreadAllocData - Update Thread.md and GC.md documentation Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
max-charlamb
left a comment
There was a problem hiding this comment.
@copilot , address feedback
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
...tive/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs
Outdated
Show resolved
Hide resolved
…eption for E_POINTER, rename to GetThreadAllocContext Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
max-charlamb
left a comment
There was a problem hiding this comment.
@copilot , address feedback
...native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements ISOSDacInterface::GetThreadAllocData in the cDAC-based SOSDacImpl by exposing per-thread GC allocation byte counters from gc_alloc_context through the managed contracts and data descriptors.
Changes:
- Added
AllocBytes/AllocBytesLohfields to theGCAllocContextdata descriptor and managed data model. - Extended the
IThreadcontract withGetThreadAllocContextreturning a newThreadAllocDatarecord, and wired it intoSOSDacImpl.GetThreadAllocData. - Added unit + dump tests and updated mock descriptors and design docs to cover/describe the new fields.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/managed/cdac/tests/ThreadTests.cs | Adds unit tests for GetThreadAllocContext. |
| src/native/managed/cdac/tests/MockDescriptors/MockDescriptors.Thread.cs | Extends mock type layouts and thread creation to include alloc-context hierarchy and alloc byte values. |
| src/native/managed/cdac/tests/DumpTests/ThreadDumpTests.cs | Adds dump test to validate alloc context can be read across all threads. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs | Implements GetThreadAllocData using the IThread contract and follows existing try/catch + DEBUG-compare patterns. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/ISOSDacInterface.cs | Introduces DacpAllocData and updates the interface signature to use it. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs | Reads new alloc-byte fields from the target in managed data representation. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs | Implements IThread.GetThreadAllocContext. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs | Adds ThreadAllocData record and the new contract method. |
| src/coreclr/vm/datadescriptor/datadescriptor.inc | Adds GCAllocContext field descriptors for alloc byte counts. |
| docs/design/datacontracts/Thread.md | Documents new GCAllocContext field dependencies for the Thread contract. |
| docs/design/datacontracts/GC.md | Documents new GCAllocContext field descriptors used by GC-related contracts. |
| [Theory] | ||
| [ClassData(typeof(MockTarget.StdArch))] | ||
| public void GetThreadAllocContext(MockTarget.Architecture arch) | ||
| { | ||
| long allocBytes = 1024; | ||
| long allocBytesLoh = 4096; | ||
|
|
||
| TargetPointer addr = thread.AddThread(1, new TargetNUInt(1234), allocBytes, allocBytesLoh); | ||
|
|
||
| Target target = CreateTarget(thread); | ||
| IThread contract = target.Contracts.Thread; |
There was a problem hiding this comment.
GetThreadAllocContext test references a thread variable that isn't declared in the method scope (unlike the other tests that create TargetTestHelpers/MockMemorySpace.Builder/MockDescriptors.Thread). This will not compile and also means the arch parameter isn't used to build the target. Create a local MockDescriptors.Thread using the provided arch before calling AddThread/CreateTarget.
...ative/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/GCAllocContext.cs
Show resolved
Hide resolved
|
@copilot, please fix build break |
…dAllocContext test and fix trailing whitespace Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
| TargetPointer LastThrownObjectHandle, | ||
| TargetPointer NextThread); | ||
|
|
||
| public record struct ThreadAllocData( |
There was a problem hiding this comment.
@copilot use out variables instead of this struct
There was a problem hiding this comment.
Done in fa4b867 — replaced ThreadAllocData record struct with out long allocBytes, out long allocBytesLoh parameters on GetThreadAllocContext, matching the pattern used by GetStackLimitData. Updated Thread_1 implementation, SOSDacImpl caller, and all tests.
…ontext Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Description
Implements
GetThreadAllocDatain the cDACSOSDacImpl, based onClrDataAccess::GetThreadAllocDatainrequest.cpp. This exposes per-thread GC allocation byte counts (alloc_bytesandalloc_bytes_uohfromgc_alloc_context) through the cDAC diagnostic interface.Data descriptor & contract changes:
AllocBytesandAllocBytesLohfields toGCAllocContextindatadescriptor.inc, mapped fromgc_alloc_context::alloc_bytesandgc_alloc_context::alloc_bytes_uohGCAllocContextdata class with correspondinglongpropertiesGetThreadAllocContextwithout long allocBytes, out long allocBytesLohparameters toIThreadcontract; implement inThread_1SOSDacImpl changes:
DacpAllocDatastruct (matches native layout: twoClrDataAddressfields)throw new ArgumentException()for invalid address,throw new NullReferenceException()for null data pointer to produce E_POINTER, contract call,#if DEBUGlegacy comparison)Tests:
GetThreadAllocContext(non-zero values) andGetThreadAllocContext_ZeroValuesacross all 4 mock architecturesGetThreadAllocContextreturns non-negative valuesMockDescriptors.Threadto set upRuntimeThreadLocals/EEAllocContext/GCAllocContexttype hierarchyDocumentation:
Thread.mdandGC.mdwith newGCAllocContextfield descriptors💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.