-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add --trace-dispatch
#55848
Add --trace-dispatch
#55848
Changes from 6 commits
a50b362
6b9059f
b754f6f
3559580
28a32ea
00bc708
9ca2a2c
57caa57
d67f200
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2561,6 +2561,40 @@ static void record_precompile_statement(jl_method_instance_t *mi, double compila | |
JL_UNLOCK(&precomp_statement_out_lock); | ||
} | ||
|
||
jl_mutex_t dispatch_statement_out_lock; | ||
|
||
static void record_dispatch_statement(jl_method_instance_t *mi) | ||
{ | ||
static ios_t f_dispatch; | ||
static JL_STREAM* s_dispatch = NULL; | ||
jl_method_t *def = mi->def.method; | ||
if (jl_options.trace_dispatch == NULL) | ||
return; | ||
if (!jl_is_method(def)) | ||
return; | ||
|
||
JL_LOCK(&dispatch_statement_out_lock); | ||
if (s_dispatch == NULL) { | ||
const char *t = jl_options.trace_dispatch; | ||
if (!strncmp(t, "stderr", 6)) { | ||
s_dispatch = JL_STDERR; | ||
} | ||
else { | ||
if (ios_file(&f_dispatch, t, 1, 1, 1, 1) == NULL) | ||
jl_errorf("cannot open dispatch statement file \"%s\" for writing", t); | ||
s_dispatch = (JL_STREAM*) &f_dispatch; | ||
} | ||
} | ||
if (!jl_has_free_typevars(mi->specTypes)) { | ||
jl_printf(s_dispatch, "precompile("); | ||
jl_static_show(s_dispatch, mi->specTypes); | ||
jl_printf(s_dispatch, ")\n"); | ||
if (s_dispatch != JL_STDERR) | ||
ios_flush(&f_dispatch); | ||
} | ||
JL_UNLOCK(&dispatch_statement_out_lock); | ||
} | ||
|
||
// If waitcompile is 0, this will return NULL if compiling is on-going in the JIT. This is | ||
// useful for the JIT itself, since it just doesn't cause redundant work or missed updates, | ||
// but merely causes it to look into the current JIT worklist. | ||
|
@@ -3068,7 +3102,8 @@ static void jl_compile_now(jl_method_instance_t *mi) | |
JL_DLLEXPORT void jl_compile_method_instance(jl_method_instance_t *mi, jl_tupletype_t *types, size_t world) | ||
{ | ||
size_t tworld = jl_typeinf_world; | ||
jl_atomic_store_relaxed(&mi->precompiled, 1); | ||
uint8_t miflags = jl_atomic_load_relaxed(&mi->flags) | JL_MI_FLAGS_MASK_PRECOMPILED; | ||
jl_atomic_store_relaxed(&mi->flags, miflags); | ||
if (jl_generating_output()) { | ||
jl_compile_now(mi); | ||
// In addition to full compilation of the compilation-signature, if `types` is more specific (e.g. due to nospecialize), | ||
|
@@ -3083,7 +3118,8 @@ JL_DLLEXPORT void jl_compile_method_instance(jl_method_instance_t *mi, jl_tuplet | |
types2 = jl_type_intersection_env((jl_value_t*)types, (jl_value_t*)mi->def.method->sig, &tpenv2); | ||
jl_method_instance_t *mi2 = jl_specializations_get_linfo(mi->def.method, (jl_value_t*)types2, tpenv2); | ||
JL_GC_POP(); | ||
jl_atomic_store_relaxed(&mi2->precompiled, 1); | ||
miflags = jl_atomic_load_relaxed(&mi2->flags) | JL_MI_FLAGS_MASK_PRECOMPILED; | ||
jl_atomic_store_relaxed(&mi2->flags, miflags); | ||
if (jl_rettype_inferred_native(mi2, world, world) == jl_nothing) | ||
(void)jl_type_infer(mi2, world, SOURCE_MODE_NOT_REQUIRED); | ||
if (jl_typeinf_func && jl_atomic_load_relaxed(&mi->def.method->primary_world) <= tworld) { | ||
|
@@ -3360,6 +3396,13 @@ JL_DLLEXPORT jl_value_t *jl_apply_generic(jl_value_t *F, jl_value_t **args, uint | |
jl_int32hash_fast(jl_return_address()), | ||
world); | ||
JL_GC_PROMISE_ROOTED(mfunc); | ||
uint8_t miflags = jl_atomic_load_relaxed(&mfunc->flags); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this has no overhead? Could it go in a slow path? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, not sure. I think the cost should be negligible. Thoughts @vtjnash? Could add an outer check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved this atomic load off the fast path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably better but I think it should go in a slower lookup path in jl_lookup_generic; at least only when the fast cache misses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Going by the comments in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved it here; please take a look? |
||
uint8_t was_dispatched = miflags & JL_MI_FLAGS_MASK_DISPATCHED; | ||
if (!was_dispatched) { | ||
miflags |= JL_MI_FLAGS_MASK_DISPATCHED; | ||
jl_atomic_store_relaxed(&mfunc->flags, miflags); | ||
record_dispatch_statement(mfunc); | ||
} | ||
return _jl_invoke(F, args, nargs, mfunc, world); | ||
} | ||
|
||
|
@@ -3466,6 +3509,13 @@ jl_value_t *jl_gf_invoke_by_method(jl_method_t *method, jl_value_t *gf, jl_value | |
jl_gc_sync_total_bytes(last_alloc); // discard allocation count from compilation | ||
} | ||
JL_GC_PROMISE_ROOTED(mfunc); | ||
uint8_t miflags = jl_atomic_load_relaxed(&mfunc->flags); | ||
uint8_t was_dispatched = miflags & JL_MI_FLAGS_MASK_DISPATCHED; | ||
if (!was_dispatched) { | ||
miflags |= JL_MI_FLAGS_MASK_DISPATCHED; | ||
jl_atomic_store_relaxed(&mfunc->flags, miflags); | ||
record_dispatch_statement(mfunc); | ||
} | ||
size_t world = jl_current_task->world_age; | ||
return _jl_invoke(gf, args, nargs - 1, mfunc, world); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very awkward (and slightly unsound) to throw errors from here. We should try to move this into the jloptions file so we can detect any issues earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I essentially duplicated
record_precompile_statement
from right above this, which does the same thing.