[SGen/Tarjan] Handle edge case with node heaviness changing due to deduplication #113044
+91
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This code path can introduce duplicates into the
color->other_colors
array:runtime/src/mono/mono/metadata/sgen-tarjan-bridge.c
Lines 795 to 798 in b658cd2
Then we get to the code that counts
xref_count
:runtime/src/mono/mono/metadata/sgen-tarjan-bridge.c
Lines 1101 to 1114 in b658cd2
It uses the
color_visible_to_client
helper method which in turn callsbridgeless_color_is_heavy
:runtime/src/mono/mono/metadata/sgen-tarjan-bridge.c
Lines 131 to 139 in b658cd2
The
fanout
metric is computed from the count ofother_colors
which contain duplicates. Once the references are gathered withgather_xrefs
they get deduplicated. This can change the number of fanout nodes just enough that it no longer satisfies the "heavy" property. We still increase thexref_count
but in the second loop that iterates over the same data it will get skipped and result in a mismatch:runtime/src/mono/mono/metadata/sgen-tarjan-bridge.c
Lines 1126 to 1130 in b658cd2
Repro: https://github.com/user-attachments/files/19044193/Archive.zip
Fixes #106410