-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Adding support for aligning AllocateTypeAssociatedMemory #122094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 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
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
...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
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
c82f51d to
2bc401a
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2bc401a to
583446b
Compare
...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
...coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
|
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 |
ef55e7a to
9b69689
Compare
This resolves #118897