Skip to content

Commit d0677a0

Browse files
committed
Approach two: Create a separate per-thread allocations backtrace buffer.
1 parent 4b5d076 commit d0677a0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/gc-alloc-profiler.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ jl_combined_results g_combined_results; // Will live forever.
5050

5151
jl_raw_backtrace_t get_raw_backtrace() JL_NOTSAFEPOINT {
5252
// We first record the backtrace onto a MAX-sized buffer, so that we don't have to
53-
// allocate the buffer until we know the size. To ensure thread-safety, we *re-use the
54-
// per-thread backtrace buffer*, which is shared with Julia's exception throwing
55-
// mechanism. This sharing is safe, because this function cannot be interleaved with
56-
// exception throwing.
53+
// allocate the buffer until we know the size. To ensure thread-safety, we use a
54+
// per-thread backtrace buffer.
5755
jl_ptls_t ptls = jl_current_task->ptls;
58-
jl_bt_element_t *shared_bt_data_buffer = ptls->bt_data;
56+
jl_bt_element_t *shared_bt_data_buffer = ptls->profiling_bt_buffer;
5957

6058
size_t bt_size = rec_backtrace(shared_bt_data_buffer, JL_MAX_BT_SIZE, 2);
6159

src/julia_threads.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ typedef struct _jl_tls_states_t {
246246
// Temporary backtrace buffer. Scanned for gc roots when bt_size > 0.
247247
struct _jl_bt_element_t *bt_data; // JL_MAX_BT_SIZE + 1 elements long
248248
size_t bt_size; // Size for backtrace in transit in bt_data
249+
// Temporary backtrace buffer used only for allocations profiler.
250+
struct _jl_bt_element_t *profiling_bt_buffer;
249251
// Atomically set by the sender, reset by the handler.
250252
volatile _Atomic(sig_atomic_t) signal_request; // TODO: no actual reason for this to be _Atomic
251253
// Allow the sigint to be raised asynchronously

0 commit comments

Comments
 (0)