Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump: make serialization gc-safe #47086

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! dump: make serialization gc-safe
vtjnash committed Oct 10, 2022
commit b39745f94a6368b86bbcb5a6e20c6a0e557ee59d
13 changes: 10 additions & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ static jl_array_t *newly_inferred JL_GLOBALLY_ROOTED;
static htable_t queued_method_roots;

// inverse of backedges graph (caller=>callees hash)
jl_array_t *edges_map;
jl_array_t *edges_map JL_GLOBALLY_ROOTED; // rooted for the duration of our uses of this

// list of requested ccallable signatures
static arraylist_t ccallable_list;
@@ -1210,7 +1210,9 @@ static void jl_collect_missing_backedges(jl_methtable_t *mt)
jl_array_t *edges = (jl_array_t*)jl_eqtable_get(edges_map, (jl_value_t*)caller, NULL);
if (edges == NULL) {
edges = jl_alloc_vec_any(0);
JL_GC_PUSH1(&edges);
edges_map = jl_eqtable_put(edges_map, (jl_value_t*)caller, (jl_value_t*)edges, NULL);
JL_GC_POP();
}
jl_array_ptr_1d_push(edges, NULL);
jl_array_ptr_1d_push(edges, missing_callee);
@@ -1232,7 +1234,9 @@ static void collect_backedges(jl_method_instance_t *callee, int internal) JL_GC_
jl_array_t *edges = (jl_array_t*)jl_eqtable_get(edges_map, (jl_value_t*)caller, NULL);
if (edges == NULL) {
edges = jl_alloc_vec_any(0);
JL_GC_PUSH1(&edges);
edges_map = jl_eqtable_put(edges_map, (jl_value_t*)caller, (jl_value_t*)edges, NULL);
JL_GC_POP();
}
jl_array_ptr_1d_push(edges, invokeTypes);
jl_array_ptr_1d_push(edges, (jl_value_t*)callee);
@@ -1376,10 +1380,13 @@ static void jl_collect_edges(jl_array_t *edges, jl_array_t *ext_targets)
}
// process target list to turn it into a memoized validity table
// and compute the old methods list, ready for serialization
jl_value_t *matches = NULL;
jl_array_t *callee_ids = NULL;
JL_GC_PUSH2(&matches, &callee_ids);
for (size_t i = 0; i < l; i += 2) {
jl_array_t *callees = (jl_array_t*)jl_array_ptr_ref(edges, i + 1);
size_t l = jl_array_len(callees);
jl_array_t *callee_ids = jl_alloc_array_1d(jl_array_int32_type, l + 1);
callee_ids = jl_alloc_array_1d(jl_array_int32_type, l + 1);
int32_t *idxs = (int32_t*)jl_array_data(callee_ids);
idxs[0] = 0;
size_t nt = 0;
@@ -1400,7 +1407,6 @@ static void jl_collect_edges(jl_array_t *edges, jl_array_t *ext_targets)
// (invokeTypes, nullptr) => missing invoke (unused--inferred as Any)
void *target = ptrhash_get(&edges_map2, invokeTypes ? (void*)invokeTypes : (void*)callee);
if (target == HT_NOTFOUND) {
jl_value_t *matches;
size_t min_valid = 0;
size_t max_valid = ~(size_t)0;
if (invokeTypes) {
@@ -1462,6 +1468,7 @@ static void jl_collect_edges(jl_array_t *edges, jl_array_t *ext_targets)
}
jl_array_del_end(callee_ids, l - nt);
}
JL_GC_POP();
htable_free(&edges_map2);
}

6 changes: 3 additions & 3 deletions src/julia.h
Original file line number Diff line number Diff line change
@@ -1656,10 +1656,10 @@ STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name)
}

// eq hash tables
JL_DLLEXPORT jl_array_t *jl_eqtable_put(jl_array_t *h, jl_value_t *key, jl_value_t *val, int *inserted);
JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_array_t *jl_eqtable_put(jl_array_t *h JL_ROOTING_ARGUMENT, jl_value_t *key, jl_value_t *val JL_ROOTED_ARGUMENT, int *inserted);
JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_eqtable_pop(jl_array_t *h, jl_value_t *key, jl_value_t *deflt, int *found);
jl_value_t *jl_eqtable_getkey(jl_array_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT;
jl_value_t *jl_eqtable_getkey(jl_array_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT;

// system information
JL_DLLEXPORT int jl_errno(void) JL_NOTSAFEPOINT;
1 change: 0 additions & 1 deletion src/typemap.c
Original file line number Diff line number Diff line change
@@ -290,7 +290,6 @@ static jl_typemap_t *mtcache_hash_lookup(jl_array_t *cache JL_PROPAGATES_ROOT, j
if (cache == (jl_array_t*)jl_an_empty_vec_any)
return (jl_typemap_t*)jl_nothing;
jl_typemap_t *ml = (jl_typemap_t*)jl_eqtable_get(cache, ty, jl_nothing);
JL_GC_PROMISE_ROOTED(ml); // clang-sa doesn't trust our JL_PROPAGATES_ROOT claim
return ml;
}