Skip to content

Commit

Permalink
staticdata: remove reinit_ccallable
Browse files Browse the repository at this point in the history
If #56499 is merged, the functionality of
`jl_reinit_ccallable` will become incomplete. However, it is
questionable whether `jl_reinit_ccallable` is truly necessary.
It seems to have been added in #44527, but all test cases
appear to pass without it. Therefore, it might be safe to remove it
altogether.
  • Loading branch information
aviatesk committed Jan 8, 2025
1 parent fe1ed74 commit cf6b5ac
Showing 1 changed file with 3 additions and 47 deletions.
50 changes: 3 additions & 47 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
- step 3 combines the different sections (fields of `jl_serializer_state`) into one
- step 4 writes the values of the hard-coded tagged items and `ccallable_list`
Much of the "real work" during deserialization is done by `get_item_for_reloc`. But a few items require specific
attention:
- uniquing: during deserialization, the target item (an "external" type or MethodInstance) must be checked against
Expand Down Expand Up @@ -538,7 +536,6 @@ typedef struct {
arraylist_t uniquing_objs; // a list of locations that reference non-types that must be de-duplicated
arraylist_t fixup_types; // a list of locations of types requiring (re)caching
arraylist_t fixup_objs; // a list of locations of objects requiring (re)caching
arraylist_t ccallable_list; // @ccallable entry points to install
// mapping from a buildid_idx to a depmods_idx
jl_array_t *buildid_depmods_idxs;
// record of build_ids for all external linkages, in order of serialization for the current sysimg/pkgimg
Expand Down Expand Up @@ -1772,8 +1769,6 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
else {
newm->nroots_sysimg = m->roots ? jl_array_len(m->roots) : 0;
}
if (m->ccallable)
arraylist_push(&s->ccallable_list, (void*)reloc_offset);
}
else if (jl_is_method_instance(v)) {
assert(f == s->s);
Expand Down Expand Up @@ -2451,29 +2446,6 @@ static void jl_root_new_gvars(jl_serializer_state *s, jl_image_t *image, uint32_
}
}


static void jl_compile_extern(jl_method_t *m, void *sysimg_handle) JL_GC_DISABLED
{
// install ccallable entry point in JIT
assert(m); // makes clang-sa happy
jl_svec_t *sv = m->ccallable;
int success = jl_compile_extern_c(NULL, NULL, sysimg_handle, jl_svecref(sv, 0), jl_svecref(sv, 1));
if (!success)
jl_safe_printf("WARNING: @ccallable was already defined for this method name\n"); // enjoy a very bad time
assert(success || !sysimg_handle);
}


static void jl_reinit_ccallable(arraylist_t *ccallable_list, char *base, void *sysimg_handle)
{
for (size_t i = 0; i < ccallable_list->len; i++) {
uintptr_t item = (uintptr_t)ccallable_list->items[i];
jl_method_t *m = (jl_method_t*)(base + item);
jl_compile_extern(m, sysimg_handle);
}
}


// Code below helps slim down the images by
// removing cached types not referenced in the stream
static jl_svec_t *jl_prune_type_cache_hash(jl_svec_t *cache) JL_GC_DISABLED
Expand Down Expand Up @@ -3002,7 +2974,6 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
arraylist_new(&s.uniquing_objs, 0);
arraylist_new(&s.fixup_types, 0);
arraylist_new(&s.fixup_objs, 0);
arraylist_new(&s.ccallable_list, 0);
s.buildid_depmods_idxs = image_to_depmodidx(mod_array);
s.link_ids_relocs = jl_alloc_array_1d(jl_array_int32_type, 0);
s.link_ids_gctags = jl_alloc_array_1d(jl_array_int32_type, 0);
Expand Down Expand Up @@ -3247,7 +3218,6 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
write_uint32(f, jl_array_len(s.link_ids_external_fnvars));
ios_write(f, (char*)jl_array_data(s.link_ids_external_fnvars, uint32_t), jl_array_len(s.link_ids_external_fnvars) * sizeof(uint32_t));
write_uint32(f, external_fns_begin);
jl_write_arraylist(s.s, &s.ccallable_list);
}

assert(object_worklist.len == 0);
Expand All @@ -3259,7 +3229,6 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
arraylist_free(&s.uniquing_objs);
arraylist_free(&s.fixup_types);
arraylist_free(&s.fixup_objs);
arraylist_free(&s.ccallable_list);
arraylist_free(&s.memowner_list);
arraylist_free(&s.memref_list);
arraylist_free(&s.relocs_list);
Expand Down Expand Up @@ -3473,7 +3442,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
jl_array_t **extext_methods, jl_array_t **internal_methods,
jl_array_t **new_ext_cis, jl_array_t **method_roots_list,
jl_array_t **edges,
char **base, arraylist_t *ccallable_list, pkgcachesizes *cachesizes) JL_GC_DISABLED
pkgcachesizes *cachesizes) JL_GC_DISABLED
{
jl_task_t *ct = jl_current_task;
int en = jl_gc_enable(0);
Expand Down Expand Up @@ -3600,7 +3569,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
ios_read(f, (char*)jl_array_data(s.link_ids_external_fnvars, uint32_t), nlinks_external_fnvars * sizeof(uint32_t));
}
uint32_t external_fns_begin = read_uint32(f);
jl_read_arraylist(s.s, ccallable_list ? ccallable_list : &s.ccallable_list);
if (s.incremental) {
assert(restored && init_order && extext_methods && internal_methods && new_ext_cis && method_roots_list && edges);
*restored = (jl_array_t*)jl_delayed_reloc(&s, offset_restored);
Expand All @@ -3620,8 +3588,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl

char *image_base = (char*)&sysimg.buf[0];
reloc_t *relocs_base = (reloc_t*)&relocs.buf[0];
if (base)
*base = image_base;

s.s = &sysimg;
jl_read_reloclist(&s, s.link_ids_gctags, GC_OLD | GC_IN_IMAGE); // gctags
Expand Down Expand Up @@ -3965,11 +3931,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl

s.s = &sysimg;
jl_update_all_fptrs(&s, image); // fptr relocs and registration
if (!ccallable_list) {
// TODO: jl_sysimg_handle or img_handle?
jl_reinit_ccallable(&s.ccallable_list, image_base, jl_sysimg_handle);
arraylist_free(&s.ccallable_list);
}
s.s = NULL;

ios_close(&fptr_record);
Expand Down Expand Up @@ -4047,8 +4008,6 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i

assert(datastartpos > 0 && datastartpos < dataendpos);
needs_permalloc = jl_options.permalloc_pkgimg || needs_permalloc;
char *base;
arraylist_t ccallable_list;

jl_value_t *restored = NULL;
jl_array_t *init_order = NULL, *extext_methods = NULL, *internal_methods = NULL, *new_ext_cis = NULL, *method_roots_list = NULL, *edges = NULL;
Expand Down Expand Up @@ -4078,7 +4037,7 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
ios_static_buffer(f, sysimg, len);
pkgcachesizes cachesizes;
jl_restore_system_image_from_stream_(f, image, depmods, checksum, (jl_array_t**)&restored, &init_order, &extext_methods, &internal_methods, &new_ext_cis, &method_roots_list,
&edges, &base, &ccallable_list, &cachesizes);
&edges, &cachesizes);
JL_SIGATOMIC_END();

// No special processing of `new_ext_cis` is required because recaching handled it
Expand Down Expand Up @@ -4110,9 +4069,6 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
JL_UNLOCK(&world_counter_lock);
// but one of those immediate users is going to be our cache insertions
jl_insert_backedges((jl_array_t*)edges, (jl_array_t*)new_ext_cis); // restore existing caches (needs to be last)
// reinit ccallables
jl_reinit_ccallable(&ccallable_list, base, pkgimage_handle);
arraylist_free(&ccallable_list);

if (completeinfo) {
cachesizes_sv = jl_alloc_svec(7);
Expand Down Expand Up @@ -4140,7 +4096,7 @@ static jl_value_t *jl_restore_package_image_from_stream(void* pkgimage_handle, i
static void jl_restore_system_image_from_stream(ios_t *f, jl_image_t *image, uint32_t checksum)
{
JL_TIMING(LOAD_IMAGE, LOAD_Sysimg);
jl_restore_system_image_from_stream_(f, image, NULL, checksum | ((uint64_t)0xfdfcfbfa << 32), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
jl_restore_system_image_from_stream_(f, image, NULL, checksum | ((uint64_t)0xfdfcfbfa << 32), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}

JL_DLLEXPORT jl_value_t *jl_restore_incremental_from_buf(void* pkgimage_handle, const char *buf, jl_image_t *image, size_t sz, jl_array_t *depmods, int completeinfo, const char *pkgname, int needs_permalloc)
Expand Down

0 comments on commit cf6b5ac

Please sign in to comment.