Skip to content

Fix an edge case in the Tarjan GC bridge that leads to losing xref information #112825

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

Merged
merged 3 commits into from
Mar 24, 2025
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
15 changes: 13 additions & 2 deletions src/mono/mono/metadata/sgen-tarjan-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,27 @@ create_scc (ScanData *data)
gboolean found = FALSE;
gboolean found_bridge = FALSE;
ColorData *color_data = NULL;
gboolean can_reduce_color = TRUE;

for (i = dyn_array_ptr_size (&loop_stack) - 1; i >= 0; --i) {
ScanData *other = (ScanData *)dyn_array_ptr_get (&loop_stack, i);
found_bridge |= other->is_bridge;
if (dyn_array_ptr_size (&other->xrefs) > 0) {
// This scc will have more xrefs than the ones from the color_merge_array,
// we will need to create a new color to store this information.
can_reduce_color = FALSE;
}
if (found_bridge || other == data)
break;
}

if (found_bridge) {
color_data = new_color (TRUE);
++num_colors_with_bridges;
} else {
} else if (can_reduce_color) {
color_data = reduce_color ();
} else {
color_data = new_color (FALSE);
}
#if DUMP_GRAPH
printf ("|SCC %p rooted in %s (%p) has bridge %d\n", color_data, safe_name_bridge (data->obj), data->obj, found_bridge);
Expand Down Expand Up @@ -785,8 +793,11 @@ create_scc (ScanData *data)

// Maybe we should make sure we are not adding duplicates here. It is not really a problem
// since we will get rid of duplicates before submitting the SCCs to the client in gather_xrefs
if (color_data)
if (color_data) {
add_other_colors (color_data, &other->xrefs);
} else {
g_assert (dyn_array_ptr_size (&other->xrefs) == 0);
}
dyn_array_ptr_uninit (&other->xrefs);

if (other == data) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/GC/Features/Bridge/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public static int Main(string[] args)

RunGraphTest(SetupDeadList);
RunGraphTest(SetupSelfLinks);
// RunGraphTest(NestedCycles); // Fixed by Filip
RunGraphTest(NestedCycles);
// RunGraphTest(Spider); // Crashes
return 100;
}
Expand Down
Loading