Skip to content

Commit 0ada892

Browse files
authored
Don't mutate the hashtable with forward edges during final iteration. (JuliaLang#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.
1 parent 425f6ff commit 0ada892

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/dump.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,10 @@ static void jl_collect_backedges_to(jl_method_instance_t *caller, htable_t *all_
12731273
{
12741274
if (module_in_worklist(caller->def.method->module) || method_instance_in_queue(caller))
12751275
return;
1276-
jl_array_t **pcallees = (jl_array_t**)ptrhash_bp(&edges_map, (void*)caller),
1277-
*callees = *pcallees;
1278-
if (callees != HT_NOTFOUND) {
1276+
if (ptrhash_has(&edges_map, caller)) {
1277+
jl_array_t **pcallees = (jl_array_t**)ptrhash_bp(&edges_map, (void*)caller),
1278+
*callees = *pcallees;
1279+
assert(callees != HT_NOTFOUND);
12791280
*pcallees = (jl_array_t*) HT_NOTFOUND;
12801281
size_t i, l = jl_array_len(callees);
12811282
for (i = 0; i < l; i++) {
@@ -1298,7 +1299,10 @@ static void jl_collect_backedges( /* edges */ jl_array_t *s, /* ext_targets */ j
12981299
htable_new(&all_callees, 0);
12991300
size_t i;
13001301
void **table = edges_map.table; // edges is caller => callees
1301-
for (i = 0; i < edges_map.size; i += 2) {
1302+
size_t table_size = edges_map.size;
1303+
for (i = 0; i < table_size; i += 2) {
1304+
assert(table == edges_map.table && table_size == edges_map.size &&
1305+
"edges_map changed during iteration");
13021306
jl_method_instance_t *caller = (jl_method_instance_t*)table[i];
13031307
jl_array_t *callees = (jl_array_t*)table[i + 1];
13041308
if (callees == HT_NOTFOUND)

0 commit comments

Comments
 (0)