Skip to content

Commit

Permalink
[mono][interp] Add missing GC wbarriers for static field stores with …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
BrzVlad authored and Ruihan-Yin committed May 30, 2024
1 parent 20a6043 commit 887deaa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -4644,6 +4644,18 @@ interp_emit_sfld_access (TransformData *td, MonoClassField *field, MonoClass *fi
}
interp_ins_set_dreg (td->last_ins, td->sp [-1].var);
} else {
// Fields from hotreload update and fields from collectible assemblies are not
// stored inside fixed gc roots but rather in other objects. This means that
// storing into these fields requires write barriers.
if ((mt == MINT_TYPE_VT || mt == MINT_TYPE_O) &&
(m_field_is_from_update (field) ||
mono_image_get_alc (m_class_get_image (m_field_get_parent (field)))->collectible)) {
interp_emit_ldsflda (td, field, error);
return_if_nok (error);
interp_emit_stobj (td, field_class, TRUE);
return;
}

if (G_LIKELY (!wide_data))
interp_add_ins (td, (mt == MINT_TYPE_VT) ? MINT_STSFLD_VT : (MINT_STSFLD_I1 + mt - MINT_TYPE_I1));
else
Expand Down

0 comments on commit 887deaa

Please sign in to comment.