Adding support for aligning AllocateTypeAssociatedMemory#122094
Merged
tannergooding merged 5 commits intodotnet:mainfrom Dec 5, 2025
Merged
Adding support for aligning AllocateTypeAssociatedMemory#122094tannergooding merged 5 commits intodotnet:mainfrom
tannergooding merged 5 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for aligned memory allocation in the AllocateTypeAssociatedMemory API by introducing a new overload that accepts an alignment parameter. The implementation covers all three runtime variants (CoreCLR, Mono, and NativeAOT) and includes test coverage for the new functionality.
Key Changes
- Added new
AllocateTypeAssociatedMemory(Type, int, int)overload with alignment parameter across all runtime implementations - Updated XML documentation for existing overload to match new style guidelines
- Implemented validation to ensure alignment is a power of 2
- Added comprehensive test cases for both valid and invalid argument scenarios
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime/ref/System.Runtime.cs | Added public API signature for the new aligned allocation overload |
| src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs | CoreCLR managed implementation with QCall to native code |
| src/coreclr/vm/runtimehandles.h | Added native function declaration for aligned allocation |
| src/coreclr/vm/runtimehandles.cpp | CoreCLR native implementation using LoaderHeap::AllocAlignedMem |
| src/coreclr/vm/qcallentrypoints.cpp | Registered new QCall entry point for aligned allocation |
| src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs | Mono implementation using NativeMemory.AlignedAlloc |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs | NativeAOT implementation using NativeMemory.AlignedAlloc |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs | Added test coverage for both invalid and valid arguments |
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs
Outdated
Show resolved
Hide resolved
...veaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs
Outdated
Show resolved
Hide resolved
tannergooding
commented
Dec 2, 2025
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Show resolved
Hide resolved
tannergooding
commented
Dec 2, 2025
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
tannergooding
commented
Dec 2, 2025
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
tannergooding
commented
Dec 2, 2025
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Show resolved
Hide resolved
tannergooding
commented
Dec 2, 2025
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
tannergooding
commented
Dec 2, 2025
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
c82f51d to
2bc401a
Compare
Co-authored-by: Copilot <[email protected]>
2bc401a to
583446b
Compare
This was referenced Dec 3, 2025
Open
...veaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs
Outdated
Show resolved
Hide resolved
3 tasks
AaronRobinsonMSFT
approved these changes
Dec 4, 2025
jkotas
reviewed
Dec 4, 2025
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
Member
Author
|
Removed the note and added tests for a few key sizes from 1-256kb: [InlineData(1)]
[InlineData(2)]
[InlineData(4)]
[InlineData(8)] // .NET largest natural alignment
[InlineData(16)] // V128, typical max_align_t
[InlineData(32)] // V256
[InlineData(64)] // V512, typical cache line size
[InlineData(128)] // less typical cache line size
[InlineData(512)] // historical disk sector size
[InlineData(4096)] // typical disk sector and page size
[InlineData(16384)] // less typical disk sector and page size
[InlineData(65536)] // typical texture and buffer alignment for GPU
[InlineData(262144)] // typical non-temporal chunk alignment |
AaronRobinsonMSFT
approved these changes
Dec 4, 2025
ef55e7a to
9b69689
Compare
This was referenced Dec 5, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This resolves #118897