Repository navigation
[mono] Fix gc descriptor for large static valuetypes - #136625
Merged
Merged
Conversation
`compute_class_bitmap` has the role of initializing the incoming bitmap, by setting bits for slots containing refs for the class in question. If the passed bitmap is not large enough to hold bits for all slots, it allocates a new bitmap which will be returned. `compute_class_bitmap` also receives a position argument to offset the bit setting in the received bitmap. All non-static field offsets include also the expected object header size (of 2 slots). If you need to set ref bits for a valuetype field inside a class having its bitmap computed, then you pass the bitmap owned by this parent class and the position where the bitmap needs to be initialized, position which need to subtract MONO_OBJECT_HEADER_BITS to revert the standard field offset. Consider the bitmap initialization for the class `StaticData` class from the testcase. It will allocate a bitmap able to hold all static data for the class, in our case only one field, therefore `sizeof(LargeValue) / sizeof(void*)` bits. The current offset to store the bits is 0. It will then recursively delegate the initialization of the bitmap section for the `LargeValue` to the instance field specific part, passing the -MONO_OBJECT_HEADER_BITS offset. The `max_size` that we compute for this class includes the object header, so it can therefore exceed the initial bitmap size. This would hit the realloc path which the caller doesn't expect, ending up with improperly initialized ref bitmaps.
BrzVlad
requested review from
steveisok,
thaystg and
vitek-karas
as code owners
October 29, 2026 12:17
|
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. |
Contributor
|
Tagging subscribers to this area: @BrzVlad |
lateralusX
approved these changes
Oct 30, 2026
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
2 of 4 tasks
2 of 4 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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_bitmaphas the role of initializing the incoming bitmap, by setting bits for slots containing refs for the class in question. If the passed bitmap is not large enough to hold bits for all slots, it allocates a new bitmap which will be returned.compute_class_bitmapalso receives a position argument to offset the bit setting in the received bitmap. All non-static field offsets include also the expected object header size (of 2 slots). If you need to set ref bits for a valuetype field inside a class having its bitmap computed, then you pass the bitmap owned by this parent class and the position where the bitmap needs to be initialized, position which needs to subtract MONO_OBJECT_HEADER_BITS to revert the standard field offset.Consider the bitmap initialization for the
StaticDataclass from the testcase. It will allocate a bitmap able to hold all static data for the class, in our case only one field, thereforesizeof(LargeValue) / sizeof(void*)bits. The current offset to store the bits is 0. It will then recursively delegate the initialization of the bitmap section for theLargeValueto the instance field specific part, passing the -MONO_OBJECT_HEADER_BITS offset. Themax_sizethat we compute for this class includes the object header, so it can therefore exceed the initial bitmap size. This would hit the realloc path which the caller doesn't expect, ending up with improperly initialized ref bitmaps.Fixes #136602