Skip to content

Commit

Permalink
Don't mutate the hashtable with forward edges during final iteration. (
Browse files Browse the repository at this point in the history
…#46375)

By looking up keys, we possibly grow the hash table, invalidating the iteration
we were doing in jl_collect_backedges. First perform a non-mutating check instead,
and assert that the hashtable doesn't change during iteration.

(cherry picked from commit 0ada892)
  • Loading branch information
maleadt authored and KristofferC committed Aug 26, 2022
1 parent 72b7511 commit 0be7f57
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,9 +1202,10 @@ static void jl_collect_backedges_to(jl_method_instance_t *caller, htable_t *all_
{
if (module_in_worklist(caller->def.method->module) || method_instance_in_queue(caller))
return;
jl_array_t **pcallees = (jl_array_t**)ptrhash_bp(&edges_map, (void*)caller),
*callees = *pcallees;
if (callees != HT_NOTFOUND) {
if (ptrhash_has(&edges_map, caller)) {
jl_array_t **pcallees = (jl_array_t**)ptrhash_bp(&edges_map, (void*)caller),
*callees = *pcallees;
assert(callees != HT_NOTFOUND);
*pcallees = (jl_array_t*) HT_NOTFOUND;
size_t i, l = jl_array_len(callees);
for (i = 0; i < l; i++) {
Expand All @@ -1227,7 +1228,10 @@ static void jl_collect_backedges( /* edges */ jl_array_t *s, /* ext_targets */ j
htable_new(&all_callees, 0);
size_t i;
void **table = edges_map.table; // edges is caller => callees
for (i = 0; i < edges_map.size; i += 2) {
size_t table_size = edges_map.size;
for (i = 0; i < table_size; i += 2) {
assert(table == edges_map.table && table_size == edges_map.size &&
"edges_map changed during iteration");
jl_method_instance_t *caller = (jl_method_instance_t*)table[i];
jl_array_t *callees = (jl_array_t*)table[i + 1];
if (callees == HT_NOTFOUND)
Expand Down

0 comments on commit 0be7f57

Please sign in to comment.