Skip to content

Commit

Permalink
Approach two: Create a separate per-thread allocations backtrace buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Feb 15, 2022
1 parent 4b5d076 commit d0677a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/gc-alloc-profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ jl_combined_results g_combined_results; // Will live forever.

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

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

Expand Down
2 changes: 2 additions & 0 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ typedef struct _jl_tls_states_t {
// Temporary backtrace buffer. Scanned for gc roots when bt_size > 0.
struct _jl_bt_element_t *bt_data; // JL_MAX_BT_SIZE + 1 elements long
size_t bt_size; // Size for backtrace in transit in bt_data
// Temporary backtrace buffer used only for allocations profiler.
struct _jl_bt_element_t *profiling_bt_buffer;
// Atomically set by the sender, reset by the handler.
volatile _Atomic(sig_atomic_t) signal_request; // TODO: no actual reason for this to be _Atomic
// Allow the sigint to be raised asynchronously
Expand Down

0 comments on commit d0677a0

Please sign in to comment.