[cDAC] Implement DacDbi heap walking#128463
Open
Copilot wants to merge 12 commits into
Open
Conversation
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the cDAC-based DacDbi implementation to support GC heap walking, adds GC contract helpers needed to mirror the native DAC walking logic (object-size alignment and allocation-context skipping), and refactors the native DAC heap walker to advance to the next valid segment/object on corruption while still signaling partial-heap results via E_FAIL.
Changes:
- Implement
CreateHeapWalk,WalkHeap, andDeleteHeapWalkin the managed (cDAC)DacDbiImpl, including a linear read cache and per-segment enumeration. - Add
IGC.GetPotentialNextObjectAddressandIGC.AlignObjectSize(and implement them inGC_1) to support heap-walk stepping/alignment parity with native. - Refactor native
DacHeapWalkerto advance to the next valid object/segment after corruption and fix allocation-context bookkeeping.
Show a summary per file
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs | Adds managed heap-walk handle lifecycle + iterator-based walking with a small page cache and alloc-context handling. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.cs | Implements contract helpers for alloc-context skipping and SOH/LOH/POH alignment needed by the walker. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IGC.cs | Extends the IGC contract interface with two new helper methods used by heap walking. |
| src/coreclr/debug/daccess/dacimpl.h | Updates DacHeapWalker private method naming to match the new “advance to next valid object” behavior. |
| src/coreclr/debug/daccess/dacdbiimpl.cpp | Reworks heap-walk advancement logic to skip corrupt segments cleanly (while surfacing partial-heap) and fixes global alloc context counting. |
| docs/design/datacontracts/GC.md | Documents the new IGC APIs and the intended algorithms for stepping/alignment. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 8
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Comment on lines
+2146
to
+2149
| if (hrLocal == HResults.S_OK && walk is not null) | ||
| walk.LegacyHandle = new TargetPointer(legacyHandle); | ||
| else if (hrLocal == HResults.S_OK) | ||
| _legacy.DeleteHeapWalk(legacyHandle); |
Comment on lines
+2321
to
+2328
| size = _gc.AlignObjectSize(size, seg.Generation); | ||
|
|
||
| // Advance past this object (and any allocation-context tail) in a single call. | ||
| TargetPointer nextObj = _gc.GetPotentialNextObjectAddress(currentObj, size, seg, _allocContexts); | ||
| if (nextObj.Value > seg.End.Value || nextObj.Value <= currentObj.Value) | ||
| { | ||
| break; | ||
| } |
…ally Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot
AI
changed the title
[cDAC] Implement DacDbi heap walking
Document allocation context dependencies inline in GC.md
May 22, 2026
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot
AI
changed the title
Document allocation context dependencies inline in GC.md
[cDAC] Implement DacDbi heap walking
May 22, 2026
Comment on lines
+2319
to
+2326
| size = _gc.AlignObjectSize(size, seg.Generation); | ||
|
|
||
| // Advance past this object (and any allocation-context tail) in a single call. | ||
| TargetPointer nextObj = _gc.GetPotentialNextObjectAddress(currentObj, size, seg); | ||
| if (nextObj.Value > seg.End.Value || nextObj.Value <= currentObj.Value) | ||
| { | ||
| break; | ||
| } |
Comment on lines
+2213
to
+2221
| while (i < count && walk.Enumerator.MoveNext()) | ||
| { | ||
| COR_HEAPOBJECT current = walk.Enumerator.Current; | ||
| // Sentinel value indicates invalid object. | ||
| if (current.address == 0) | ||
| { | ||
| hr = HResults.E_FAIL; | ||
| break; | ||
| } |
Contributor
There was a problem hiding this comment.
No, the first output will never be E_FAIL because upon Walk we always navigate to the next valid object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
note to ccr: we aren't doing the api-review process