- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
[release/9.0-staging][mono][gc] Fix gc descriptor computation for InlineArray structs #116951
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
[release/9.0-staging][mono][gc] Fix gc descriptor computation for InlineArray structs #116951
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.
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 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);
| 
           Tagging subscribers to this area: @BrzVlad  | 
    
| 
           Are we good to merge this? Just reminder Code-complete is 14-Jul 4pm PT cut-off  | 
    
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.