From 9da122e5766bde430996f15eaa1ccd97454174ed Mon Sep 17 00:00:00 2001 From: d-netto Date: Tue, 4 Feb 2025 15:28:28 -0300 Subject: [PATCH] introduce safepoint_waiter --- src/gc.c | 10 ++++++++++ src/jl_uv.c | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 1c8821a92befb..edcdcefdcaf7a 100644 --- a/src/gc.c +++ b/src/gc.c @@ -226,6 +226,14 @@ NOINLINE uintptr_t gc_get_stack_ptr(void) #define should_timeout() 0 +uv_thread_t safepoint_waiter; + +int jl_inside_waiting_for_the_world(void) +{ + uv_thread_t self = uv_thread_self(); + return uv_thread_equal(&safepoint_waiter, &self); +} + void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads) { JL_TIMING(GC, GC_Stop); @@ -234,6 +242,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads) TracyCZoneColor(ctx, 0x696969); #endif assert(gc_n_threads); + safepoint_waiter = uv_thread_self(); if (gc_n_threads > 1) jl_wake_libuv(); for (int i = 0; i < gc_n_threads; i++) { @@ -263,6 +272,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads) } } } + memset(&safepoint_waiter, 0, sizeof(safepoint_waiter)); } // malloc wrappers, aligned allocation diff --git a/src/jl_uv.c b/src/jl_uv.c index fd8718ebbea26..385edaed04bb0 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -754,6 +754,7 @@ STATIC_INLINE void write_to_safe_crash_log(char *buf) JL_NOTSAFEPOINT } extern int jl_inside_heartbeat_thread(void); +extern int jl_inside_waiting_for_the_world(void); JL_DLLEXPORT void jl_safe_printf(const char *fmt, ...) { @@ -774,7 +775,7 @@ JL_DLLEXPORT void jl_safe_printf(const char *fmt, ...) // order is important here: we want to ensure that the threading infra // has been initialized before we start trying to print to the // safe crash log file - if (jl_sig_fd != 0 && (jl_inside_signal_handler() || jl_inside_heartbeat_thread())) { + if (jl_sig_fd != 0 && (jl_inside_signal_handler() || jl_inside_heartbeat_thread() || jl_inside_waiting_for_the_world())) { write_to_safe_crash_log(buf); } if (write(STDERR_FILENO, buf, strlen(buf)) < 0) {