@@ -3096,7 +3096,8 @@ static void record_dispatch_statement(jl_method_instance_t *mi)
30963096 s_dispatch = (JL_STREAM * ) & f_dispatch ;
30973097 }
30983098 }
3099- if (!jl_has_free_typevars (mi -> specTypes )) {
3099+ // NOTE: For builtin functions, the specType is just `Tuple`, which is not useful to print.
3100+ if (!jl_has_free_typevars (mi -> specTypes ) && (jl_datatype_t * )mi -> specTypes != jl_tuple_type ) {
31003101 jl_printf (s_dispatch , "precompile(" );
31013102 jl_static_show (s_dispatch , mi -> specTypes );
31023103 jl_printf (s_dispatch , ")\n" );
@@ -3106,6 +3107,19 @@ static void record_dispatch_statement(jl_method_instance_t *mi)
31063107 JL_UNLOCK (& dispatch_statement_out_lock );
31073108}
31083109
3110+ static void record_dispatch_statement_on_first_dispatch (jl_method_instance_t * mfunc ) {
3111+ uint8_t force_trace_dispatch = jl_atomic_load_relaxed (& jl_force_trace_dispatch_enabled );
3112+ if (force_trace_dispatch || jl_options .trace_dispatch != NULL ) {
3113+ uint8_t miflags = jl_atomic_load_relaxed (& mfunc -> flags );
3114+ uint8_t was_dispatched = miflags & JL_MI_FLAGS_MASK_DISPATCHED ;
3115+ if (!was_dispatched ) {
3116+ miflags |= JL_MI_FLAGS_MASK_DISPATCHED ;
3117+ jl_atomic_store_relaxed (& mfunc -> flags , miflags );
3118+ record_dispatch_statement (mfunc );
3119+ }
3120+ }
3121+ }
3122+
31093123// If waitcompile is 0, this will return NULL if compiling is on-going in the JIT. This is
31103124// useful for the JIT itself, since it just doesn't cause redundant work or missed updates,
31113125// but merely causes it to look into the current JIT worklist.
@@ -3941,6 +3955,11 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
39413955 jl_atomic_store_relaxed (& pick_which [cache_idx [0 ]], which );
39423956 jl_atomic_store_release (& call_cache [cache_idx [which & 3 ]], entry );
39433957 }
3958+ if (entry ) {
3959+ // mfunc was found in slow path, so log --trace-dispatch
3960+ jl_method_instance_t * mfunc = entry -> func .linfo ;
3961+ record_dispatch_statement_on_first_dispatch (mfunc );
3962+ }
39443963 }
39453964
39463965 jl_method_instance_t * mfunc ;
@@ -3963,23 +3982,15 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t
39633982 jl_method_error (F , args , nargs , world );
39643983 // unreachable
39653984 }
3966- // mfunc is about to be dispatched
3967- uint8_t force_trace_dispatch = jl_atomic_load_relaxed (& jl_force_trace_dispatch_enabled );
3968- if (force_trace_dispatch || jl_options .trace_dispatch != NULL ) {
3969- uint8_t miflags = jl_atomic_load_relaxed (& mfunc -> flags );
3970- uint8_t was_dispatched = miflags & JL_MI_FLAGS_MASK_DISPATCHED ;
3971- if (!was_dispatched ) {
3972- miflags |= JL_MI_FLAGS_MASK_DISPATCHED ;
3973- jl_atomic_store_relaxed (& mfunc -> flags , miflags );
3974- record_dispatch_statement (mfunc );
3975- }
3976- }
3985+ // mfunc was found in slow path, so log --trace-dispatch
3986+ record_dispatch_statement_on_first_dispatch (mfunc );
39773987 }
39783988
39793989#ifdef JL_TRACE
39803990 if (traceen )
39813991 jl_printf (JL_STDOUT , " at %s:%d\n" , jl_symbol_name (mfunc -> def .method -> file ), mfunc -> def .method -> line );
39823992#endif
3993+
39833994 return mfunc ;
39843995}
39853996
0 commit comments