@@ -400,7 +400,16 @@ static const char*
400
400
safe_name_bridge (GCObject * obj )
401
401
{
402
402
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 ;
404
413
}
405
414
#endif
406
415
@@ -557,15 +566,10 @@ find_in_cache (int *insert_index)
557
566
558
567
// Populate other_colors for a give color (other_colors represent the xrefs for this color)
559
568
static void
560
- add_other_colors (ColorData * color , DynPtrArray * other_colors , gboolean check_visited )
569
+ add_other_colors (ColorData * color , DynPtrArray * other_colors )
561
570
{
562
571
for (int i = 0 ; i < dyn_array_ptr_size (other_colors ); ++ i ) {
563
572
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
- }
569
573
dyn_array_ptr_add (& color -> other_colors , points_to );
570
574
// Inform targets
571
575
points_to -> incoming_colors = MIN (points_to -> incoming_colors + 1 , INCOMING_COLORS_MAX );
@@ -589,7 +593,7 @@ new_color (gboolean has_bridges)
589
593
cd = alloc_color_data ();
590
594
cd -> api_index = -1 ;
591
595
592
- add_other_colors (cd , & color_merge_array , FALSE );
596
+ add_other_colors (cd , & color_merge_array );
593
597
594
598
/* if cacheSlot >= 0, it means we prepared a given slot to receive the new color */
595
599
if (cacheSlot >= 0 )
@@ -696,11 +700,11 @@ compute_low_index (ScanData *data, GCObject *obj)
696
700
obj = bridge_object_forward (obj );
697
701
other = find_data (obj );
698
702
699
- if (!other )
700
- return ;
701
703
#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 );
703
705
#endif
706
+ if (!other )
707
+ return ;
704
708
705
709
g_assert (other -> state != INITIAL );
706
710
@@ -773,32 +777,24 @@ create_scc (ScanData *data)
773
777
gboolean found = FALSE;
774
778
gboolean found_bridge = FALSE;
775
779
ColorData * color_data = NULL ;
776
- gboolean can_reduce_color = TRUE;
777
780
778
781
for (i = dyn_array_ptr_size (& loop_stack ) - 1 ; i >= 0 ; -- i ) {
779
782
ScanData * other = (ScanData * )dyn_array_ptr_get (& loop_stack , i );
780
783
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
- }
786
784
if (found_bridge || other == data )
787
785
break ;
788
786
}
789
787
790
788
if (found_bridge ) {
791
789
color_data = new_color (TRUE);
792
790
++ num_colors_with_bridges ;
793
- } else if (can_reduce_color ) {
794
- color_data = reduce_color ();
795
791
} else {
796
- color_data = new_color (FALSE );
792
+ color_data = reduce_color ( );
797
793
}
798
794
#if DUMP_GRAPH
799
795
printf ("|SCC %p rooted in %s (%p) has bridge %d\n" , color_data , safe_name_bridge (data -> obj ), data -> obj , found_bridge );
800
796
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 ) {
802
798
ScanData * other = dyn_array_ptr_get (& loop_stack , i );
803
799
printf ("(%d/%d)" , other -> index , other -> low_index );
804
800
}
@@ -828,19 +824,10 @@ create_scc (ScanData *data)
828
824
dyn_array_ptr_add (& color_data -> bridges , other -> obj );
829
825
}
830
826
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 );
844
831
dyn_array_ptr_uninit (& other -> xrefs );
845
832
846
833
if (other == data ) {
@@ -850,22 +837,11 @@ create_scc (ScanData *data)
850
837
}
851
838
g_assert (found );
852
839
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
-
862
840
#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" );
869
845
#endif
870
846
}
871
847
@@ -990,11 +966,8 @@ dump_color_table (const char *why, gboolean do_index)
990
966
printf (" bridges: " );
991
967
for (j = 0 ; j < dyn_array_ptr_size (& cd -> bridges ); ++ j ) {
992
968
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 );
998
971
}
999
972
}
1000
973
printf ("\n" );
@@ -1054,7 +1027,7 @@ processing_stw_step (void)
1054
1027
#if defined (DUMP_GRAPH )
1055
1028
printf ("----summary----\n" );
1056
1029
printf ("bridges:\n" );
1057
- for (i = 0 ; i < bridge_count ; ++ i ) {
1030
+ for (int i = 0 ; i < bridge_count ; ++ i ) {
1058
1031
ScanData * sd = find_data (dyn_array_ptr_get (& registered_bridges , i ));
1059
1032
printf ("\t%s (%p) index %d color %p\n" , safe_name_bridge (sd -> obj ), sd -> obj , sd -> index , sd -> color );
1060
1033
}
@@ -1168,7 +1141,6 @@ processing_build_callback_data (int generation)
1168
1141
gather_xrefs (cd );
1169
1142
reset_xrefs (cd );
1170
1143
dyn_array_ptr_set_all (& cd -> other_colors , & color_merge_array );
1171
- g_assert (color_visible_to_client (cd ));
1172
1144
xref_count += dyn_array_ptr_size (& cd -> other_colors );
1173
1145
}
1174
1146
}
0 commit comments