Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct JLOptions
task_metrics::Int8
timeout_for_safepoint_straggler_s::Int16
serialize_machine_code_only::Int8
drop_edges::Int8
end

# This runs early in the sysimage != is not defined yet
Expand Down
1 change: 1 addition & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ STATIC_INLINE jl_value_t *jl_gc_big_alloc_inner(jl_ptls_t ptls, size_t sz)
memset(v, 0xee, allocsz);
#endif
v->sz = allocsz;
v->header = 0;
gc_big_object_link(ptls->gc_tls.heap.young_generation_of_bigvals, v);
return jl_valueof(&v->header);
}
Expand Down
6 changes: 6 additions & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ JL_DLLEXPORT void jl_init_options(void)
0, // task_metrics
25, // timeout_for_safepoint_straggler_s
0, // serialize_machine_code_only
0, // drop_edges
};
jl_options_initialized = 1;
}
Expand Down Expand Up @@ -247,6 +248,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
opt_inline,
opt_polly,
opt_serialize_machine_code_only,
opt_drop_edges,
opt_timeout_for_safepoint_straggler,
opt_trace_compile,
opt_trace_compile_timing,
Expand Down Expand Up @@ -328,6 +330,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
{ "inline", required_argument, 0, opt_inline },
{ "polly", required_argument, 0, opt_polly },
{ "serialize-machine-code-only", no_argument, 0, opt_serialize_machine_code_only },
{ "drop-edges", no_argument, 0, opt_drop_edges },
{ "timeout-for-safepoint-straggler", required_argument, 0, opt_timeout_for_safepoint_straggler },
{ "trace-compile", required_argument, 0, opt_trace_compile },
{ "trace-compile-timing", no_argument, 0, opt_trace_compile_timing },
Expand Down Expand Up @@ -899,6 +902,9 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
case opt_serialize_machine_code_only:
jl_options.serialize_machine_code_only = 1;
break;
case opt_drop_edges:
jl_options.drop_edges = 1;
break;
case opt_task_metrics:
if (!strcmp(optarg, "no"))
jl_options.task_metrics = JL_OPTIONS_TASK_METRICS_OFF;
Expand Down
1 change: 1 addition & 0 deletions src/jloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct {
int8_t task_metrics;
int16_t timeout_for_safepoint_straggler_s;
int8_t serialize_machine_code_only;
int8_t drop_edges;
} jl_options_t;

#endif
19 changes: 16 additions & 3 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,9 +2244,11 @@ static void strip_specializations_(jl_method_instance_t *mi)
}
codeinst = jl_atomic_load_relaxed(&codeinst->next);
}
if (jl_options.strip_ir || jl_options.drop_edges) {
record_field_change((jl_value_t**)&mi->backedges, NULL);
}
if (jl_options.strip_ir) {
record_field_change((jl_value_t**)&mi->uninferred, NULL);
record_field_change((jl_value_t**)&mi->backedges, NULL);
record_field_change((jl_value_t**)&mi->callbacks, NULL);
}
}
Expand Down Expand Up @@ -2300,7 +2302,7 @@ static int strip_all_codeinfos__(jl_typemap_entry_t *def, void *_env)

static int strip_all_codeinfos_(jl_methtable_t *mt, void *_env)
{
if (jl_options.strip_ir && mt->backedges)
if ((jl_options.strip_ir || jl_options.drop_edges) && mt->backedges)
record_field_change((jl_value_t**)&mt->backedges, NULL);
return jl_typemap_visitor(mt->defs, strip_all_codeinfos__, NULL);
}
Expand Down Expand Up @@ -2411,7 +2413,7 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
{
htable_new(&field_replace, 0);
// strip metadata and IR when requested
if (jl_options.strip_metadata || jl_options.strip_ir)
if (jl_options.strip_metadata || jl_options.strip_ir || jl_options.drop_edges)
jl_strip_all_codeinfos();

int en = jl_gc_enable(0);
Expand Down Expand Up @@ -2525,6 +2527,17 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
// Queue the new roots
jl_queue_for_serialization(&s, method_roots_list);
// Queue the edges
if (jl_options.drop_edges) {
// Empty ext_targets
ext_targets = jl_alloc_vec_any(0);
// The caller field in `edges` is used in loading so we only empty the
// callees array when we drop edges.
size_t i, l = jl_array_len(edges) / 2;
for (i = 0; i < l; i++) {
jl_array_t *cids = jl_alloc_array_1d(jl_array_int32_type, 0);
jl_array_ptr_set(edges, 2 * i + 1, cids);
}
}
jl_queue_for_serialization(&s, ext_targets);
jl_queue_for_serialization(&s, edges);
}
Expand Down
5 changes: 5 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,8 @@ end
exename = `$(Base.julia_cmd())`
@test parse(Int,read(`$exename --serialize-machine-code-only -E "Base.JLOptions().serialize_machine_code_only"`, String)) == 1
end

@testset "--drop-edges" begin
exename = `$(Base.julia_cmd())`
@test parse(Int,read(`$exename --drop-edges -E "Base.JLOptions().drop_edges`, String)) == 1
end