[release/9.0-staging][mono][gc] Fix gc descriptor computation for InlineArray structs#116951
Merged
BrzVlad merged 1 commit intodotnet:release/9.0-stagingfrom Jul 11, 2025
Merged
Conversation
`compute_class_bitmap` iterates over all ref field slots in the current class so we can produce a GC descriptor. `field_iter` represents how many times the type in question is repeated in the current struct. Instead of bumping the current offset by the size of the repeated field, for each iteration, we were adding `field_offset` which is wrong.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR corrects the GC bitmap generation for structs marked with the InlineArray attribute by using the actual element size when iterating through array slots rather than repeatedly adding the field’s original offset.
- Introduced
field_sizeto hold the size of each element viamono_type_size - Wrapped the inline‐array logic in braces to scope assignments
- Changed
field_instance_offsetto increment byfield_sizeinstead offield_offset
Comments suppressed due to low confidence (1)
src/mono/mono/metadata/object.c:914
- [nitpick] The name
field_sizeis ambiguous in this context—consider renaming it toelement_sizeto clarify that it represents the size of each array element.
field_size = mono_type_size (field->type, &align);
Contributor
|
Tagging subscribers to this area: @BrzVlad |
lambdageek
approved these changes
Jun 24, 2025
Member
|
Are we good to merge this? Just reminder Code-complete is 14-Jul 4pm PT cut-off |
This was referenced Aug 5, 2025
This was referenced Aug 7, 2025
Closed
Closed
Merged
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.
compute_class_bitmapiterates over all ref field slots in the current class so we can produce a GC descriptor.field_iterrepresents how many times the type in question is repeated in the current struct. Instead of bumping the current offset by the size of the repeated field, for each iteration, we were addingfield_offsetwhich is wrong.Customer Impact
Types having
InlineArrayattribute are not correctly scanned by the GC for refs. This can lead to GC crashes on Maui applications. User reported problem migrating from legacy xamarin to maui Humanizr/Humanizer#1572.Regression
InlineArrayattribute for types was added around .NET8, with some uses showing up in the libraries code in .NET9, which could lead to regressions for some users.Testing
Tested on local test that the GC descriptor is now computed correctly for types with
InlineArrayattribute. Verified fix on sample app provided by customer.Risk
Low. The fix is localized to types that have
InlineArrayattribute, where the previous implementation was completely broken.