Skip to content

Commit 887deaa

Browse files
BrzVladRuihan-Yin
authored andcommitted
[mono][interp] Add missing GC wbarriers for static field stores with hotreload enabled (dotnet#100775)
* [mono][interp] Add missing GC wbarriers for static field stores in hotreload By default, static fields are stored in malloced memory that is registered and always scanned as roots. With hotreload, new static data is allocated inside newly created objects, so storing into it will require write barriers. In order to avoid slowing the normal execution, for fields from metadata updates, we will store into them via ldflda + stobj instead. * [mono][interp] Add missing GC wbarriers for static field stores in collectible assemblies
1 parent 20a6043 commit 887deaa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4644,6 +4644,18 @@ interp_emit_sfld_access (TransformData *td, MonoClassField *field, MonoClass *fi
46444644
}
46454645
interp_ins_set_dreg (td->last_ins, td->sp [-1].var);
46464646
} else {
4647+
// Fields from hotreload update and fields from collectible assemblies are not
4648+
// stored inside fixed gc roots but rather in other objects. This means that
4649+
// storing into these fields requires write barriers.
4650+
if ((mt == MINT_TYPE_VT || mt == MINT_TYPE_O) &&
4651+
(m_field_is_from_update (field) ||
4652+
mono_image_get_alc (m_class_get_image (m_field_get_parent (field)))->collectible)) {
4653+
interp_emit_ldsflda (td, field, error);
4654+
return_if_nok (error);
4655+
interp_emit_stobj (td, field_class, TRUE);
4656+
return;
4657+
}
4658+
46474659
if (G_LIKELY (!wide_data))
46484660
interp_add_ins (td, (mt == MINT_TYPE_VT) ? MINT_STSFLD_VT : (MINT_STSFLD_I1 + mt - MINT_TYPE_I1));
46494661
else

0 commit comments

Comments
 (0)