Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][sgen] Add separate card mark function to be used with debug #109698

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/mono/mono/sgen/sgen-cardtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so is this only enabled in debug builds ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of, only if certain debug flags are passed at runtime via env vars this is used to mark cards when copying objects. It is a conservative approach. It might be useful to backport since there are active crashes there that are not actionable and this PR should at least fix the use of some GC debugging features that might help investigate.

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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/sgen/sgen-cardtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)");

Expand Down