Skip to content

Use inline arrays in GCMemoryInfoData. - #131827

Merged
jkotas merged 2 commits into
dotnet:mainfrom
teo-tsirpanis:gc-memory-info-data-inline-array
Aug 5, 2026
Merged

Use inline arrays in GCMemoryInfoData.#131827
jkotas merged 2 commits into
dotnet:mainfrom
teo-tsirpanis:gc-memory-info-data-inline-array

Conversation

@teo-tsirpanis

Copy link
Copy Markdown
Contributor

Removes two uses of MemoryMarshal.CreateReadOnlySpan.

Copilot AI review requested due to automatic review settings August 4, 2026 19:17
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 4, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Copilot AI 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 GCMemoryInfoData to use inline arrays (InlineArray5<GCGenerationInfo> and InlineArray2<TimeSpan>) in order to avoid MemoryMarshal.CreateReadOnlySpan when exposing generation info and pause durations via ReadOnlySpan<T>.

Changes:

  • Replaces the per-element backing fields for generation info and pause durations with InlineArray5<T> / InlineArray2<T> fields.
  • Updates GCMemoryInfo.PauseDurations and GCMemoryInfo.GenerationInfo to return spans directly from the inline-array fields.
  • Adds using System.Runtime.CompilerServices; for inline-array types.

Comment thread src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs
@teo-tsirpanis

Copy link
Copy Markdown
Contributor Author

@jkotas is there a way that we could make the DEFINE_FIELD_U declarations work with InlineArray?

DEFINE_FIELD_U(_pauseDuration0, GCMemoryInfoData, pauseDuration0)
DEFINE_FIELD_U(_pauseDuration1, GCMemoryInfoData, pauseDuration1)
DEFINE_FIELD_U(_generationInfo0, GCMemoryInfoData, generationInfo0)
DEFINE_FIELD_U(_generationInfo1, GCMemoryInfoData, generationInfo1)
DEFINE_FIELD_U(_generationInfo2, GCMemoryInfoData, generationInfo2)
DEFINE_FIELD_U(_generationInfo3, GCMemoryInfoData, generationInfo3)
DEFINE_FIELD_U(_generationInfo4, GCMemoryInfoData, generationInfo4)

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI review requested due to automatic review settings August 4, 2026 23:26
@jkotas

jkotas commented Aug 4, 2026

Copy link
Copy Markdown
Member

is there a way that we could make the DEFINE_FIELD_U declarations work with InlineArray?

Try changing the C++ definition of GCMemoryInfoData to use GCGenerationInfo generationInfo[5]; and the corelib.h to DEFINE_FIELD_U(_generationInfo, GCMemoryInfoData, generationInfo)

@teo-tsirpanis

Copy link
Copy Markdown
Contributor Author

Done, thanks. I first thought I had to encode the managed field's type in the declaration, but turns out that's not the case.

Copilot AI 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.

Suppressed comments (3)

src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs:191

  • If GCMemoryInfoData keeps span accessors (to avoid exposing writable inline-array fields), this property should return the accessor rather than the backing field.
        public ReadOnlySpan<GCGenerationInfo> GenerationInfo => _data._generationInfo;

src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs:75

  • These inline-array fields were previously private (via the individual element fields). Making them internal widens the writable surface area for what appears to be runtime-filled layout data, and a repo-wide search shows no other managed code needs direct field access. Consider keeping the fields private and exposing internal ReadOnlySpan<T> accessors (still avoiding MemoryMarshal.CreateReadOnlySpan).
        internal InlineArray5<GCGenerationInfo> _generationInfo;
        internal InlineArray2<TimeSpan> _pauseDurations;

src/libraries/System.Private.CoreLib/src/System/GCMemoryInfo.cs:181

  • If GCMemoryInfoData keeps span accessors (to avoid exposing writable inline-array fields), this property should return the accessor rather than the backing field.

This issue also appears on line 191 of the same file.

        public ReadOnlySpan<TimeSpan> PauseDurations => _data._pauseDurations;

@teo-tsirpanis

Copy link
Copy Markdown
Contributor Author

CI is about to get green.

@jkotas

jkotas commented Aug 5, 2026

Copy link
Copy Markdown
Member

/ba-g Build Monitor Helix Jobs stuck

@jkotas jkotas 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.

Thanks

@jkotas
jkotas merged commit 8668a62 into dotnet:main Aug 5, 2026
147 of 149 checks passed
@teo-tsirpanis
teo-tsirpanis deleted the gc-memory-info-data-inline-array branch August 5, 2026 09:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Runtime community-contribution Indicates that the PR has been added by a community member reduce-unsafe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants