Skip to content

Commit 39bae29

Browse files
authored
Revert "[release/9.0] Fix edge cases in Tarjan GC bridge (Android) (#114391)" (#114641)
This reverts commit 703efd5. Reverting due to assertions found in Android SDK testing.
1 parent 8f4c768 commit 39bae29

File tree

6 files changed

+37
-550
lines changed

6 files changed

+37
-550
lines changed

src/mono/mono/metadata/sgen-bridge.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,24 +316,24 @@ dump_processor_state (SgenBridgeProcessor *p)
316316
{
317317
int i;
318318
319-
g_message ("------\n");
320-
g_message ("SCCS %d\n", p->num_sccs);
319+
printf ("------\n");
320+
printf ("SCCS %d\n", p->num_sccs);
321321
for (i = 0; i < p->num_sccs; ++i) {
322322
int j;
323323
MonoGCBridgeSCC *scc = p->api_sccs [i];
324-
g_message ("\tSCC %d:", i);
324+
printf ("\tSCC %d:", i);
325325
for (j = 0; j < scc->num_objs; ++j) {
326326
MonoObject *obj = scc->objs [j];
327-
g_message (" %p(%s)", obj, m_class_get_name (SGEN_LOAD_VTABLE (obj)->klass));
327+
printf (" %p(%s)", obj, SGEN_LOAD_VTABLE (obj)->klass->name);
328328
}
329-
g_message ("\n");
329+
printf ("\n");
330330
}
331331
332-
g_message ("XREFS %d\n", p->num_xrefs);
332+
printf ("XREFS %d\n", p->num_xrefs);
333333
for (i = 0; i < p->num_xrefs; ++i)
334-
g_message ("\t%d -> %d\n", p->api_xrefs [i].src_scc_index, p->api_xrefs [i].dst_scc_index);
334+
printf ("\t%d -> %d\n", p->api_xrefs [i].src_scc_index, p->api_xrefs [i].dst_scc_index);
335335
336-
g_message ("-------\n");
336+
printf ("-------\n");
337337
}
338338
*/
339339

@@ -352,7 +352,7 @@ sgen_compare_bridge_processor_results (SgenBridgeProcessor *a, SgenBridgeProcess
352352
if (a->num_sccs != b->num_sccs)
353353
g_error ("SCCS count expected %d but got %d", a->num_sccs, b->num_sccs);
354354
if (a->num_xrefs != b->num_xrefs)
355-
g_error ("XREFS count expected %d but got %d", a->num_xrefs, b->num_xrefs);
355+
g_error ("SCCS count expected %d but got %d", a->num_xrefs, b->num_xrefs);
356356

357357
/*
358358
* First we build a hash of each object in `a` to its respective SCC index within

src/mono/mono/metadata/sgen-tarjan-bridge.c

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,16 @@ static const char*
400400
safe_name_bridge (GCObject *obj)
401401
{
402402
GCVTable vt = SGEN_LOAD_VTABLE (obj);
403-
return m_class_get_name (vt->klass);
403+
return vt->klass->name;
404+
}
405+
406+
static ScanData*
407+
find_or_create_data (GCObject *obj)
408+
{
409+
ScanData *entry = find_data (obj);
410+
if (!entry)
411+
entry = create_data (obj);
412+
return entry;
404413
}
405414
#endif
406415

@@ -557,15 +566,10 @@ find_in_cache (int *insert_index)
557566

558567
// Populate other_colors for a give color (other_colors represent the xrefs for this color)
559568
static void
560-
add_other_colors (ColorData *color, DynPtrArray *other_colors, gboolean check_visited)
569+
add_other_colors (ColorData *color, DynPtrArray *other_colors)
561570
{
562571
for (int i = 0; i < dyn_array_ptr_size (other_colors); ++i) {
563572
ColorData *points_to = (ColorData *)dyn_array_ptr_get (other_colors, i);
564-
if (check_visited) {
565-
if (points_to->visited)
566-
continue;
567-
points_to->visited = TRUE;
568-
}
569573
dyn_array_ptr_add (&color->other_colors, points_to);
570574
// Inform targets
571575
points_to->incoming_colors = MIN (points_to->incoming_colors + 1, INCOMING_COLORS_MAX);
@@ -589,7 +593,7 @@ new_color (gboolean has_bridges)
589593
cd = alloc_color_data ();
590594
cd->api_index = -1;
591595

592-
add_other_colors (cd, &color_merge_array, FALSE);
596+
add_other_colors (cd, &color_merge_array);
593597

594598
/* if cacheSlot >= 0, it means we prepared a given slot to receive the new color */
595599
if (cacheSlot >= 0)
@@ -696,11 +700,11 @@ compute_low_index (ScanData *data, GCObject *obj)
696700
obj = bridge_object_forward (obj);
697701
other = find_data (obj);
698702

699-
if (!other)
700-
return;
701703
#if DUMP_GRAPH
702-
printf ("\tcompute low %p ->%p (%s) %p (%d / %d, color %p)\n", data->obj, obj, safe_name_bridge (obj), other, other ? other->index : -2, other->low_index, other->color);
704+
printf ("\tcompute low %p ->%p (%s) %p (%d / %d, color %p)\n", data->obj, obj, safe_name_bridge (obj), other, other ? other->index : -2, other ? other->low_index : -2, other->color);
703705
#endif
706+
if (!other)
707+
return;
704708

705709
g_assert (other->state != INITIAL);
706710

@@ -773,32 +777,24 @@ create_scc (ScanData *data)
773777
gboolean found = FALSE;
774778
gboolean found_bridge = FALSE;
775779
ColorData *color_data = NULL;
776-
gboolean can_reduce_color = TRUE;
777780

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

790788
if (found_bridge) {
791789
color_data = new_color (TRUE);
792790
++num_colors_with_bridges;
793-
} else if (can_reduce_color) {
794-
color_data = reduce_color ();
795791
} else {
796-
color_data = new_color (FALSE);
792+
color_data = reduce_color ();
797793
}
798794
#if DUMP_GRAPH
799795
printf ("|SCC %p rooted in %s (%p) has bridge %d\n", color_data, safe_name_bridge (data->obj), data->obj, found_bridge);
800796
printf ("\tloop stack: ");
801-
for (i = 0; i < dyn_array_ptr_size (&loop_stack); ++i) {
797+
for (int i = 0; i < dyn_array_ptr_size (&loop_stack); ++i) {
802798
ScanData *other = dyn_array_ptr_get (&loop_stack, i);
803799
printf ("(%d/%d)", other->index, other->low_index);
804800
}
@@ -828,19 +824,10 @@ create_scc (ScanData *data)
828824
dyn_array_ptr_add (&color_data->bridges, other->obj);
829825
}
830826

831-
if (dyn_array_ptr_size (&other->xrefs) > 0) {
832-
g_assert (color_data != NULL);
833-
g_assert (can_reduce_color == FALSE);
834-
// We need to eliminate duplicates early otherwise the heaviness property
835-
// can change in gather_xrefs and it breaks down the loop that reports the
836-
// xrefs to the client.
837-
//
838-
// We reuse the visited flag to mark the objects that are already part of
839-
// the color_data array. The array was created above with the new_color call
840-
// and xrefs were populated from color_merge_array, which is already
841-
// deduplicated and every entry is marked as visited.
842-
add_other_colors (color_data, &other->xrefs, TRUE);
843-
}
827+
// Maybe we should make sure we are not adding duplicates here. It is not really a problem
828+
// since we will get rid of duplicates before submitting the SCCs to the client in gather_xrefs
829+
if (color_data)
830+
add_other_colors (color_data, &other->xrefs);
844831
dyn_array_ptr_uninit (&other->xrefs);
845832

846833
if (other == data) {
@@ -850,22 +837,11 @@ create_scc (ScanData *data)
850837
}
851838
g_assert (found);
852839

853-
// Clear the visited flag on nodes that were added with add_other_colors in the loop above
854-
if (!can_reduce_color) {
855-
for (i = dyn_array_ptr_size (&color_merge_array); i < dyn_array_ptr_size (&color_data->other_colors); i++) {
856-
ColorData *cd = (ColorData *)dyn_array_ptr_get (&color_data->other_colors, i);
857-
g_assert (cd->visited);
858-
cd->visited = FALSE;
859-
}
860-
}
861-
862840
#if DUMP_GRAPH
863-
if (color_data) {
864-
printf ("\tpoints-to-colors: ");
865-
for (i = 0; i < dyn_array_ptr_size (&color_data->other_colors); i++)
866-
printf ("%p ", dyn_array_ptr_get (&color_data->other_colors, i));
867-
printf ("\n");
868-
}
841+
printf ("\tpoints-to-colors: ");
842+
for (int i = 0; i < dyn_array_ptr_size (&color_data->other_colors); i++)
843+
printf ("%p ", dyn_array_ptr_get (&color_data->other_colors, i));
844+
printf ("\n");
869845
#endif
870846
}
871847

@@ -990,11 +966,8 @@ dump_color_table (const char *why, gboolean do_index)
990966
printf (" bridges: ");
991967
for (j = 0; j < dyn_array_ptr_size (&cd->bridges); ++j) {
992968
GCObject *obj = dyn_array_ptr_get (&cd->bridges, j);
993-
ScanData *data = find_data (obj);
994-
if (!data)
995-
printf ("%p ", obj);
996-
else
997-
printf ("%p(%d) ", obj, data->index);
969+
ScanData *data = find_or_create_data (obj);
970+
printf ("%d ", data->index);
998971
}
999972
}
1000973
printf ("\n");
@@ -1054,7 +1027,7 @@ processing_stw_step (void)
10541027
#if defined (DUMP_GRAPH)
10551028
printf ("----summary----\n");
10561029
printf ("bridges:\n");
1057-
for (i = 0; i < bridge_count; ++i) {
1030+
for (int i = 0; i < bridge_count; ++i) {
10581031
ScanData *sd = find_data (dyn_array_ptr_get (&registered_bridges, i));
10591032
printf ("\t%s (%p) index %d color %p\n", safe_name_bridge (sd->obj), sd->obj, sd->index, sd->color);
10601033
}
@@ -1168,7 +1141,6 @@ processing_build_callback_data (int generation)
11681141
gather_xrefs (cd);
11691142
reset_xrefs (cd);
11701143
dyn_array_ptr_set_all (&cd->other_colors, &color_merge_array);
1171-
g_assert (color_visible_to_client (cd));
11721144
xref_count += dyn_array_ptr_size (&cd->other_colors);
11731145
}
11741146
}

0 commit comments

Comments
 (0)