Skip to content

Fix NativeAOT string GC config handling - #128455

Merged
janvorli merged 8 commits into
dotnet:mainfrom
janvorli:fix-nativeaot-string-config
May 29, 2026
Merged

Fix NativeAOT string GC config handling#128455
janvorli merged 8 commits into
dotnet:mainfrom
janvorli:fix-nativeaot-string-config

Conversation

@janvorli

Copy link
Copy Markdown
Member

The NativeAOT doesn't have real implementation of
GCToEEInterface::GetStringConfigValue, the method
just return false. That prevents extraction of
settings that are strings, like GCHeapAffinitizeRanges.

This change fixes it by adding proper implementation.

Close#128396

The NativeAOT doesn't have real implementation of
GCToEEInterface::GetStringConfigValue, the method
just return false. That prevents extraction of
settings that are strings, like GCHeapAffinitizeRanges.
This change fixes it by adding proper implementation.
Closedotnet#128396
@janvorlijanvorli added this to the 11.0.0 milestone May 21, 2026
@janvorlijanvorli self-assigned this May 21, 2026
CopilotAI review requested due to automatic review settings May 21, 2026 15:28
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp Outdated

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 updates the NativeAOT runtime’s GC configuration plumbing so that string-valued GC configs can be retrieved (instead of always being treated as absent), bringing NativeAOT behavior closer to CoreCLR for settings like heap affinitization ranges.

Changes:

  • Add NativeAOT RhConfig helpers to read string config values from DOTNET_* environment variables and from embedded config blobs.
  • Implement GCToEEInterface::GetStringConfigValue for NativeAOT by delegating to the new RhConfig string readers.
  • Route GCToEEInterface::FreeStringConfigValue through RhConfig for consistent ownership handling.

Reviewed changes

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

FileDescription
src/coreclr/nativeaot/Runtime/RhConfig.hAdds declarations for reading and freeing string config values (settings + knobs).
src/coreclr/nativeaot/Runtime/RhConfig.cppImplements string config retrieval (env + embedded) and centralized freeing.
src/coreclr/nativeaot/Runtime/gcenv.ee.cppWires GC string config lookup/freeing to RhConfig for NativeAOT.

Comment threadsrc/coreclr/nativeaot/Runtime/RhConfig.cpp
Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp Outdated
Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
CopilotAI review requested due to automatic review settings May 21, 2026 15:49

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

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

Comment threadsrc/coreclr/nativeaot/Runtime/RhConfig.cpp
Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp Outdated
Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp
Comment threadsrc/coreclr/nativeaot/Runtime/gcenv.ee.cpp Outdated
CopilotAI review requested due to automatic review settings May 21, 2026 18:01

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

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

@MichalStrehovsky

Copy link
Copy Markdown
Member

I am not sure how to test it in a regression test. The affinitization applies to GC threads, not regular threads, so it is not visible to the user code.

Could we update the GetConfigurationVariables.cs test to test this? The test is not really testing anything right now: mark the test as RequiresProcessIsolation, add CLRTestEnvironmentVariable setting this, and verify we can see it in GetConfigurationVariables.

@MichalStrehovskyMichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the test needs TestLibrary.PlatformDetection.IsMonoRuntime conditioning, but LGTM otherwise, thanks!

CopilotAI review requested due to automatic review settings May 26, 2026 11:35

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

CopilotAI review requested due to automatic review settings May 27, 2026 12:39

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

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

@VSadovVSadov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@janvorli
janvorli merged commit 6684fb2 into dotnet:mainMay 29, 2026
107 of 117 checks passed
@janvorli

Copy link
Copy Markdown
MemberAuthor

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

svick pushed a commit that referenced this pull request Jun 9, 2026
Backport of #128455 to release/10.0
/cc @janvorli
## Customer Impact
- [x] Customer reported - issue #128396
- [ ] Found internally
When publishing with NativeAOT (PublishAot=true), the
GCHeapAffinitizeRanges configuration is ignored regardless of how it is
supplied — RuntimeHostConfigurationOption in the .csproj, IlcArg
--runtimeopt:, or the DOTNET_GCHeapAffinitizeRanges environment
variable. The Server GC heap threads fall back to the default per-heap
affinity (heap 0 → CPU 0, heap 1 → CPU 1, etc.) instead of the
user-specified ranges. The same configuration works correctly in non-AOT
builds.
## Regression
- [ ] Yes
- [x] No
## Testing
Local testing using targeted repro app provided by the customer, local
NativeAOT tests execution, CI.
## Risk
Low, the change is specific to string config values handling in
NativeAOT that was ignoring those before.
---------
Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 3, 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.

GCHeapAffinitizeRanges is completely ignored under NativeAOT

6 participants

@janvorli@MichalStrehovsky@AustinWise@jkotas@VSadov