Skip to content

Commit df8e7e8

Browse files
authored
[hot_reload] Check for added fields earlier in compute_class_bitmap (#89121)
Added fields don't contribute to the class bitmap, and they also might not have their type resolved yet - move the "is from update" check before we need to access the field's type Fixes #86172 * Add regression test * [hot_reload] Check for added fields earlier in compute_class_bitmap and in mono_class_create_runtime_vtable
1 parent 74d69fd commit df8e7e8

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/libraries/System.Runtime.Loader/tests/ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddStaticField/AddStaticField.cs

+7
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ public void TestMethod () {
1919
}
2020

2121
}
22+
public class AddStaticField2
23+
{
24+
public static int Test()
25+
{
26+
return -1;
27+
}
28+
}
2229
}

src/libraries/System.Runtime.Loader/tests/ApplyUpdate/System.Reflection.Metadata.ApplyUpdate.Test.AddStaticField/AddStaticField_v1.cs

+9
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ public void TestMethod () {
2222
}
2323

2424
}
25+
public class AddStaticField2
26+
{
27+
private static int A {get; set;}
28+
public static int Test()
29+
{
30+
A = 11;
31+
return A + A;
32+
}
33+
}
2534
}

src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs

+3
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ public static void TestAddStaticField()
302302

303303
string result = x.GetField;
304304
Assert.Equal("4567", result);
305+
306+
int aa = System.Reflection.Metadata.ApplyUpdate.Test.AddStaticField2.Test();
307+
Assert.Equal(22, aa);
305308
});
306309
}
307310

src/mono/mono/metadata/object.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@ compute_class_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int
834834
while ((field = mono_class_get_fields_internal (p, &iter))) {
835835
MonoType *type;
836836

837+
/* metadata-update: added fields aren't stored in the object, don't
838+
* contribute to the GC descriptor. */
839+
if (m_field_is_from_update (field))
840+
continue;
841+
837842
if (static_fields) {
838843
if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
839844
continue;
@@ -847,11 +852,6 @@ compute_class_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int
847852
if (m_type_is_byref (field->type))
848853
break;
849854

850-
/* metadadta-update: added fields aren't stored in the object, don't
851-
* contribute to the GC descriptor. */
852-
if (m_field_is_from_update (field))
853-
continue;
854-
855855
int field_offset = m_field_get_offset (field);
856856

857857
if (static_fields && (field->offset == -1 || field->offset == -2))
@@ -2211,13 +2211,13 @@ mono_class_create_runtime_vtable (MonoClass *klass, MonoError *error)
22112211

22122212
iter = NULL;
22132213
while ((field = mono_class_get_fields_internal (klass, &iter))) {
2214+
/* metadata-update: added fields are stored external to the object, and don't contribute to the bitmap */
2215+
if (m_field_is_from_update (field))
2216+
continue;
22142217
if (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC))
22152218
continue;
22162219
if (mono_field_is_deleted (field))
22172220
continue;
2218-
/* metadata-update: added fields are stored external to the object, and don't contribute to the bitmap */
2219-
if (m_field_is_from_update (field))
2220-
continue;
22212221
if (!(field->type->attrs & FIELD_ATTRIBUTE_LITERAL)) {
22222222
gint32 special_static = m_class_has_no_special_static_fields (klass) ? SPECIAL_STATIC_NONE : field_is_special_static (klass, field);
22232223
if (special_static != SPECIAL_STATIC_NONE) {

0 commit comments

Comments
 (0)