Skip to content

Commit 3dd878b

Browse files
authored
[mono][gc] Fix gc descriptor computation for InlineArray structs (#116951)
`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.
1 parent ccf556d commit 3dd878b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mono/mono/metadata/object.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,13 @@ compute_class_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int
906906

907907
guint32 field_iter = 1;
908908
guint32 field_instance_offset = field_offset;
909+
int field_size = 0;
909910
// If struct has InlineArray attribute, iterate `length` times to set a bitmap
910-
if (m_class_is_inlinearray (p))
911+
if (m_class_is_inlinearray (p)) {
912+
int align;
911913
field_iter = m_class_inlinearray_value (p);
914+
field_size = mono_type_size (field->type, &align);
915+
}
912916

913917
if (field_iter > 500)
914918
g_warning ("Large number of iterations detected when creating a GC bitmap, might affect performance.");
@@ -973,7 +977,7 @@ compute_class_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int
973977
break;
974978
}
975979

976-
field_instance_offset += field_offset;
980+
field_instance_offset += field_size;
977981
field_iter--;
978982
}
979983
}

0 commit comments

Comments
 (0)