Skip to content

Cleanup holder types#126368

Open
AaronRobinsonMSFT wants to merge 11 commits intodotnet:mainfrom
AaronRobinsonMSFT:cleanup-holder-types
Open

Cleanup holder types#126368
AaronRobinsonMSFT wants to merge 11 commits intodotnet:mainfrom
AaronRobinsonMSFT:cleanup-holder-types

Conversation

@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Mar 31, 2026

This pull request refactors memory management in the createdump and related debugging code by removing the legacy ArrayHolder (and some other holders) and replacing them with new, more robust holder types defined in holder.h. The changes modernize resource management, improve safety, and simplify code by consolidating smart pointer logic. Additionally, some minor improvements and cleanups are made to COM interface holders and other utility types.

The most important changes are:

Memory Management Refactoring:

  • Removed the entire ArrayHolder implementation (arrayholder.h) and replaced all usages with new holder types like AStringHolder, WStringHolder, and NewArrayHolder, as defined in holder.h.
  • Introduced new, safer resource management types in holder.h, including LifetimeHolder, MapViewHolder, and LocalAllocHolder, and updated their usage throughout the codebase.

Holder Type Consolidation and Cleanup:

  • Replaced NonVMComHolder with ReleaseHolder for COM interface management, and removed redundant holder aliases.
  • Cleaned up unused or legacy macros, includes, and warning suppressions related to holders.

Minor Fixes and Improvements:

  • Fixed a typo in a comment (RelesaeRelease).
  • Updated code to use .Extract() instead of .Detach() for stack frame management.
  • Improved contract annotations and resource release logic for new holder types.

These changes collectively improve code safety, maintainability, and clarity by consolidating resource management logic and removing legacy code.This pull request refactors resource management throughout the CoreCLR debugging components by replacing the custom ArrayHolder and NonVMComHolder smart pointer classes with new, more general-purpose holders defined in holder.h. It also removes the now-unused arrayholder.h and releaseholder.h files and introduces more robust, trait-based holder implementations, improving code clarity and maintainability. The changes touch many files, especially those dealing with memory and handle management, and update usage sites accordingly.

AaronRobinsonMSFT and others added 4 commits March 30, 2026 13:51
… classes

- Remove NonVMComHolder<T> (identical alias to ReleaseHolder<T>), update call sites
- Remove unused types: DoNothingHolder, FileHandleHolder, RegKeyHolder,
  BoolFlagStateHolder, FieldNuller, VoidCloseFileHandle, VoidUnmapViewOfFile,
  TypeUnmapViewOfFile, DoLocalFree
- Replace MapViewHolder Wrapper typedef with explicit RAII class
- Replace LocalAllocHolder SpecializedWrapper alias with explicit RAII class
- Refactor HKEYHolder: add SuppressRelease(), proper Release() in operator=,
  assertion in operator&(), remove implicit operator HKEY*()
- Remove unnecessary #ifndef SOS_INCLUDE guard around ReleaseHolder
- Add STATIC_CONTRACT_WRAPPER to DoTheRelease

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gement in holder.h; update LocalAllocHolder usage in sstring.cpp and util.cpp
…lder types and remove unused ArrayHolder class
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Mar 31, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors native resource management in CoreCLR debugging / createdump components by removing legacy holder types (ArrayHolder, NonVMComHolder, standalone releaseholder.h) and standardizing usage on the more general holders in holder.h (e.g., NewArrayHolder, AStringHolder, WStringHolder, ReleaseHolder, and new trait-based lifetime holders).

Changes:

  • Removed arrayholder.h / releaseholder.h and updated call sites to use holders from holder.h.
  • Added new trait-based holders in holder.h (e.g., LifetimeHolder, MapViewHolder, LocalAllocHolder, HKEYHolder, BSTRHolder) and updated usage patterns accordingly.
  • Simplified COM registry lookup helper logic and updated createdump/debugger code paths to use the unified holders.

Reviewed changes

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

Show a summary per file
File Description
src/coreclr/utilcode/util.cpp Refactors registry string reading helper and COM CLSID lookup to use HKEYHolder and updated ReadStringValue signature.
src/coreclr/utilcode/sstring.cpp Updates FormatMessage dynamic allocation to use the updated LocalAllocHolder pattern.
src/coreclr/inc/releaseholder.h Removes the legacy COM ReleaseHolder implementation (now consolidated into holder.h).
src/coreclr/inc/holder.h Introduces trait-based LifetimeHolder and related holders; removes legacy aliases/holders and consolidates release logic.
src/coreclr/inc/arrayholder.h Removes the legacy ArrayHolder implementation (replaced by NewArrayHolder / AStringHolder / WStringHolder).
src/coreclr/debug/di/module.cpp Updates file mapping code to use the new MapViewHolder initialization style.
src/coreclr/debug/dbgutil/machoreader.cpp Replaces ArrayHolder usage with NewArrayHolder for dyld image info allocation.
src/coreclr/debug/daccess/daccess.cpp Replaces NonVMComHolder with ReleaseHolder for COM interface ownership.
src/coreclr/debug/daccess/cdac.h Updates stored COM target field to use ReleaseHolder.
src/coreclr/debug/createdump/threadinfo.cpp Replaces ArrayHolder<WCHAR> with WStringHolder for exception type name buffers.
src/coreclr/debug/createdump/dumpname.cpp Replaces ArrayHolder<char> with AStringHolder for hostname buffer.
src/coreclr/debug/createdump/createdumpwindows.cpp Replaces ArrayHolder<char> with AStringHolder for temporary path/name buffer.
src/coreclr/debug/createdump/createdumpmain.cpp Replaces ArrayHolder<char> with AStringHolder for temp path buffer.
src/coreclr/debug/createdump/createdump.h Replaces removed holder headers with holder.h and defines _ASSERTE for compatibility.
src/coreclr/debug/createdump/crashreportwriter.cpp Replaces array holders with AStringHolder/WStringHolder for sysctl/method name buffers.
src/coreclr/debug/createdump/crashinfo.cpp Replaces array holders with AStringHolder/WStringHolder for module name and formatting buffers.

…r.h and updating related includes; adjust method calls for consistency
Copilot AI review requested due to automatic review settings March 31, 2026 21:46
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member Author

@hoyosjs for createdump changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@jkoritzinsky
Copy link
Copy Markdown
Member

Can we move more of the holder types over from SpecializedWrapper? It would be nice to start unraveling the Wrapper/Holder hierarchy if we can.

Copilot AI review requested due to automatic review settings March 31, 2026 23:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants