Skip to content

[cDAC]: Flush contract caches - #125627

Merged
rcj1 merged 4 commits into
dotnet:mainfrom
rcj1:Flush
Mar 17, 2026
Merged

[cDAC]: Flush contract caches#125627
rcj1 merged 4 commits into
dotnet:mainfrom
rcj1:Flush

Conversation

@rcj1

@rcj1rcj1 commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Complete Flush() impl by flushing contract caches along with all processed data.

@rcj1rcj1 changed the title Flush contract caches[cDAC]: Flush contract cachesMar 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a Flush() mechanism across the cDAC contract system so cached contract data can be cleared when the target process state changes (e.g., after resume), and wires it into existing DAC flush entry points.

Changes:

  • Add Flush() to IContract and ContractRegistry, and implement registry-wide flushing in CachingContractRegistry.
  • Invoke contract flushing from DAC-facing Flush()/LockedFlush() implementations alongside _target.ProcessedData.Clear().
  • Implement (mostly no-op) Flush() methods across many contract implementations; clear internal dictionaries where applicable.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/CachingContractRegistry.csImplements registry-wide flushing by calling Flush() on cached contract instances.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.csEnsures IXCLRDataProcess.Flush clears both processed data and contract caches.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.csUpdates ISOSDacInterface13.LockedFlush to clear processed data and contract caches.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/SyncBlock_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/StackWalk_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureDecoder_1.csClears cached signature provider dictionaries on Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/SHash_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.csClears RTS caches (method tables/descs/type handle caches) on Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeInfo_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ReJIT_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PrecodeStubs_Common.csAdds contract Flush() (currently no-op) on common PrecodeStubs base.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/PlatformMetadata_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Object_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Notifications_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Loader_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GCInfo/GCInfo_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/GC/GC_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.csClears ExecutionManager code-info cache on Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_1.csForwards Flush() to shared ExecutionManagerCore.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_2.csForwards Flush() to shared ExecutionManagerCore.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Exception_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/EcmaMetadata_1.csClears cached metadata providers on Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebugInfo/DebugInfo_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DebugInfo/DebugInfo_2.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/DacStreams_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ComWrappers_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/BuiltInCOM_1.csAdds contract Flush() (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IContract.csAdds Flush() to the base contract interface.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.csAdds Flush() to the contract registry abstraction.

CopilotAI review requested due to automatic review settings March 16, 2026 20:37

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a unified “flush” pathway in cDAC to clear cached target/contract state when the debuggee’s state may have changed (e.g., resume), and wires that through existing legacy DAC COM flush entry points.

Changes:

  • Add Flush() to Target, ContractRegistry, and IContract, and implement registry-wide flushing in CachingContractRegistry.
  • Implement per-contract cache clearing for several contracts (ExecutionManager, RuntimeTypeSystem, EcmaMetadata, SignatureDecoder).
  • Route legacy DAC COM Flush/LockedFlush calls to _target.Flush().

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
src/native/managed/cdac/tests/TestPlaceholderTarget.csAdds a ContractRegistry.Flush() override for the test registry (currently no-op).
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/CachingContractRegistry.csImplements registry-wide flushing by calling Flush() on created contracts.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.csRoutes IXCLRDataProcess.Flush() to _target.Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.csRoutes ISOSDacInterface13.LockedFlush() to _target.Flush().
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Signature/SignatureDecoder_1.csClears signature provider caches on flush.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.csClears RuntimeTypeSystem dictionaries on flush.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManagerCore.csClears code info cache on flush.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_1.csForwards flush to core implementation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager/ExecutionManager_2.csForwards flush to core implementation.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/EcmaMetadata_1.csClears metadata cache on flush.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Target.csAdds Target.Flush() to clear ProcessedData and flush contracts.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IContract.csAdds IContract.Flush() default interface method.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.csAdds abstract ContractRegistry.Flush().
Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.IXCLRDataProcess.cs:29

  • IXCLRDataProcess.Flush is a COM boundary and currently calls _target.Flush() without exception handling. With the new Target.Flush() implementation calling into Contracts.Flush() (and ultimately per-contract cache clear logic), exceptions (e.g., from contract code) would escape across the COM boundary. Please wrap the body in a try/catch and return ex.HResult (or otherwise guarantee Target.Flush() is non-throwing).
 int IXCLRDataProcess.Flush()
{
_target.Flush();
// As long as any part of cDAC falls back to the legacy DAC, we need to propagate the Flush call
if (_legacyProcess is not null)
return _legacyProcess.Flush();
return HResults.S_OK;

Comment threadsrc/native/managed/cdac/tests/TestPlaceholderTarget.cs
@rcj1
rcj1 merged commit ab699a4 into dotnet:mainMar 17, 2026
52 checks passed
@rcj1
rcj1 deleted the Flush branch March 17, 2026 02:21
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 16, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@rcj1@max-charlamb