diff --git a/src/mono/mono/sgen/sgen-cardtable.c b/src/mono/mono/sgen/sgen-cardtable.c index 6a662fb605019..e344ec15fe228 100644 --- a/src/mono/mono/sgen/sgen-cardtable.c +++ b/src/mono/mono/sgen/sgen-cardtable.c @@ -165,6 +165,31 @@ sgen_card_table_wbarrier_range_copy (gpointer _dest, gconstpointer _src, int siz } } +// Marks more cards so that it works with remset consistency debug checks +static void +sgen_card_table_wbarrier_range_copy_debug (gpointer _dest, gconstpointer _src, int size) +{ + GCObject **dest = (GCObject **)_dest; + GCObject **src = (GCObject **)_src; + + size_t nursery_bits = sgen_nursery_bits; + char *start = sgen_nursery_start; + G_GNUC_UNUSED char *end = sgen_nursery_end; + + while (size) { + GCObject *value = *src; + *dest = value; + if (SGEN_PTR_IN_NURSERY (value, nursery_bits, start, end) || sgen_concurrent_collection_in_progress) { + volatile guint8 *card_address = (volatile guint8 *)sgen_card_table_get_card_address ((mword)dest); + *card_address = 1; + sgen_dummy_use (value); + } + ++src; + ++dest; + size -= SIZEOF_VOID_P; + } +} + MONO_RESTORE_WARNING #ifdef SGEN_HAVE_OVERLAPPING_CARDS @@ -606,7 +631,7 @@ sgen_cardtable_scan_object (GCObject *obj, mword block_obj_size, guint8 *cards, } void -sgen_card_table_init (SgenRememberedSet *remset) +sgen_card_table_init (SgenRememberedSet *remset, gboolean consistency_checks) { sgen_cardtable = (guint8 *)sgen_alloc_os_memory (CARD_COUNT_IN_BYTES, (SgenAllocFlags)(SGEN_ALLOC_INTERNAL | SGEN_ALLOC_ACTIVATE), "card table", MONO_MEM_ACCOUNT_SGEN_CARD_TABLE); @@ -637,7 +662,10 @@ sgen_card_table_init (SgenRememberedSet *remset) remset->find_address = sgen_card_table_find_address; remset->find_address_with_cards = sgen_card_table_find_address_with_cards; - remset->wbarrier_range_copy = sgen_card_table_wbarrier_range_copy; + if (consistency_checks) + remset->wbarrier_range_copy = sgen_card_table_wbarrier_range_copy_debug; + else + remset->wbarrier_range_copy = sgen_card_table_wbarrier_range_copy; need_mod_union = sgen_get_major_collector ()->is_concurrent; } diff --git a/src/mono/mono/sgen/sgen-cardtable.h b/src/mono/mono/sgen/sgen-cardtable.h index 1ea3055fce085..e07bc2cf5c034 100644 --- a/src/mono/mono/sgen/sgen-cardtable.h +++ b/src/mono/mono/sgen/sgen-cardtable.h @@ -30,7 +30,7 @@ void sgen_card_table_preclean_mod_union (guint8 *cards, guint8 *cards_preclean, guint8* sgen_get_card_table_configuration (int *shift_bits, gpointer *mask); guint8* sgen_get_target_card_table_configuration (int *shift_bits, target_mgreg_t *mask); -void sgen_card_table_init (SgenRememberedSet *remset); +void sgen_card_table_init (SgenRememberedSet *remset, gboolean consistency_checks); /*How many bytes a single card covers*/ #define CARD_BITS 9 diff --git a/src/mono/mono/sgen/sgen-gc.c b/src/mono/mono/sgen/sgen-gc.c index 705b8168ed36f..8ca983771ed79 100644 --- a/src/mono/mono/sgen/sgen-gc.c +++ b/src/mono/mono/sgen/sgen-gc.c @@ -3909,7 +3909,7 @@ sgen_gc_init (void) memset (&remset, 0, sizeof (remset)); - sgen_card_table_init (&remset); + sgen_card_table_init (&remset, remset_consistency_checks); sgen_register_root (NULL, 0, sgen_make_user_root_descriptor (sgen_mark_normal_gc_handles), ROOT_TYPE_NORMAL, MONO_ROOT_SOURCE_GC_HANDLE, GINT_TO_POINTER (ROOT_TYPE_NORMAL), "GC Handles (SGen, Normal)");