Skip to content

[mono][gc] Fix gc descriptor computation for InlineArray structs #116879

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

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Jun 20, 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.

Fixes Humanizr/Humanizer#1572

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 20:43
@BrzVlad BrzVlad requested a review from kotlarmilos June 20, 2025 20:43
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 20, 2025
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 fixes the GC descriptor computation for InlineArray structs in Mono by correcting the offset calculation logic.

  • Introduces a new variable (field_size) to capture the size of an element for InlineArray types.
  • Updates the iteration loop to increment the offset using field_size instead of the previously used field_offset.
Comments suppressed due to low confidence (1)

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

  • If the struct is not an InlineArray, field_size remains 0 causing no offset update. Consider adding an else clause to set field_size to field_offset for non-InlineArray cases, ensuring correct offset computation.
				field_instance_offset += field_size;

@BrzVlad BrzVlad added area-GC-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 20, 2025
Copy link
Contributor

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

@BrzVlad BrzVlad merged commit 6da0fa9 into dotnet:main Jun 23, 2025
68 of 73 checks passed
@BrzVlad
Copy link
Member Author

BrzVlad commented Jun 23, 2025

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/15832129926

Copy link
Contributor

@BrzVlad backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: [mono][gc] Fix gc descriptor computation for InlineArray structs
Using index info to reconstruct a base tree...
M	src/mono/mono/metadata/object.c
Falling back to patching base and 3-way merge...
Auto-merging src/mono/mono/metadata/object.c
CONFLICT (content): Merge conflict in src/mono/mono/metadata/object.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 [mono][gc] Fix gc descriptor computation for InlineArray structs
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GC crashes in .NET 9 for iOS after using Humanizer
2 participants