-
-
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
Conversation
e138bc3
to
8728e7e
Compare
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 think you also need to cover the invoke codepath in this same file to get all dispatches, but looks like a good start overall to implementing this
} | ||
else { | ||
if (ios_file(&f_dispatch, t, 1, 1, 1, 1) == NULL) | ||
jl_errorf("cannot open dispatch statement file \"%s\" for writing", t); |
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.
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.
Clearly needed in conjunction with #55047, thanks for doing this.
I added this; does that look right? Is there anywhere else where this should be recorded? |
Similar to `--trace-compile`, emit the `precompile` statement for a method once, but only when it is dynamically dispatched. For this, we add a `dispatched` field into `jl_method_instance_t` that is initialized to 0, and when the method is dispatched, it is set to 1 and the precompile statement is emitted (once).
- Rename `precompiled` field in `jl_method_instance_t` to `flags` and use bit 0 as `precompiled` and bit 1 as `dispatched`. - Use relaxed atomic operations to access `flags`. - Add setting of `dispatched` to `jl_gf_invoke_by_method`.
Also add a test for `--trace-compile`.
e3fab0a
to
00bc708
Compare
Added a test. |
src/gf.c
Outdated
@@ -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 comment
The 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 comment
The 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 jloptions.trace_dispatch
? Remove the check from inside the record...
function?
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've moved this atomic load off the fast path.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Going by the comments in jl_lookup_generic_
, there is a lookup in an associative cache, and if that misses, a lookup in the full cache. Can a method instance be in either of those caches if it hasn't been dispatched? If not, then I could move the call here?
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've moved it here; please take a look?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Just sharing a thought that if the user wants both Maybe that's overthinking it but at least it's possible if desired. |
Merge? @JeffBezanson |
Similar to
--trace-compile
, emit theprecompile
statement for a method once, but only when it is dynamically dispatched.For this, we add a
dispatched
field intojl_method_instance_t
that is initialized to 0, and when the method is dispatched, it is set to 1 and the precompile statement is emitted (once).TODO: