-
-
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
Merged
Merged
Add --trace-dispatch
#55848
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a50b362
Add `--trace-dispatch`
kpamnany 6b9059f
Add NEWS entry
kpamnany b754f6f
Add documentation
kpamnany 3559580
Address review comments
kpamnany 28a32ea
Fix test
kpamnany 00bc708
Add test for `--trace-dispatch`
kpamnany 9ca2a2c
Move the atomic load off the fast path
kpamnany 57caa57
Move `record_dispatch_statement` call to method cache miss path
kpamnany d67f200
Merge branch 'master' into kp/add-trace-dispatch
IanButterworth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2561,6 +2561,38 @@ 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_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 +3100,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 +3116,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) { | ||
|
@@ -3344,6 +3378,16 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t | |
jl_method_error(F, args, nargs, world); | ||
// unreachable | ||
} | ||
// mfunc is about to be dispatched | ||
if (jl_options.trace_dispatch != NULL) { | ||
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); | ||
} | ||
} | ||
} | ||
|
||
#ifdef JL_TRACE | ||
|
@@ -3466,6 +3510,15 @@ 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); | ||
if (jl_options.trace_dispatch != NULL) { | ||
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); | ||
Comment on lines
+3517
to
+3518
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. Shouldn't these require an |
||
record_dispatch_statement(mfunc); | ||
} | ||
} | ||
size_t world = jl_current_task->world_age; | ||
return _jl_invoke(gf, args, nargs - 1, mfunc, world); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.