Skip to content

[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

Open
wants to merge 1 commit into
base: release/9.0-staging
Choose a base branch
from

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Jun 24, 2025

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.

Customer Impact

  • Customer reported
  • Found internally

Types having InlineArray attribute 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

  • Yes
  • No

InlineArray attribute 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 InlineArray attribute. Verified fix on sample app provided by customer.

Risk

Low. The fix is localized to types that have InlineArray attribute, where the previous implementation was completely broken.

`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.
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 06:44
Copy link
Contributor

@Copilot Copilot AI left a 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_size to hold the size of each element via mono_type_size
  • Wrapped the inline‐array logic in braces to scope assignments
  • Changed field_instance_offset to increment by field_size instead of field_offset
Comments suppressed due to low confidence (1)

src/mono/mono/metadata/object.c:914

  • [nitpick] The name field_size is ambiguous in this context—consider renaming it to element_size to clarify that it represents the size of each array element.
				field_size = mono_type_size (field->type, &align);

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

@BrzVlad BrzVlad added the Servicing-consider Issue for next servicing release review label Jun 24, 2025
@BrzVlad BrzVlad added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jun 25, 2025
@BrzVlad BrzVlad added this to the 9.0.8 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-GC-mono Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants