Skip to content

Commit

Permalink
correctly track freed bytes in array_to_string (#54309)
Browse files Browse the repository at this point in the history
Should fix #54275.
  • Loading branch information
d-netto authored May 1, 2024
1 parent 0b4590a commit 54614fd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
return o;
}
}
jl_gc_count_freed(jl_array_nbytes(a));
a->nrows = 0;
a->length = 0;
a->maxsize = 0;
Expand Down
7 changes: 7 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,13 @@ void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + sz);
}

void jl_gc_count_freed(size_t sz) JL_NOTSAFEPOINT
{
jl_ptls_t ptls = jl_current_task->ptls;
jl_atomic_store_relaxed(&ptls->gc_num.freed,
jl_atomic_load_relaxed(&ptls->gc_num.freed) + sz);
}

static void combine_thread_gc_counts(jl_gc_num_t *dest) JL_NOTSAFEPOINT
{
int gc_n_threads;
Expand Down
2 changes: 0 additions & 2 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,6 @@ void gc_stats_big_obj(void);
// For debugging
void gc_count_pool(void);

size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;

JL_DLLEXPORT void jl_enable_gc_logging(int enable);
JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void);
void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect) JL_NOTSAFEPOINT;
Expand Down
2 changes: 2 additions & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ JL_DLLEXPORT void JL_NORETURN jl_throw_out_of_memory_error(void);
JL_DLLEXPORT int64_t jl_gc_diff_total_bytes(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT;
void jl_gc_track_malloced_array(jl_ptls_t ptls, jl_array_t *a) JL_NOTSAFEPOINT;
size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;
void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT;
void jl_gc_count_freed(size_t sz) JL_NOTSAFEPOINT;
void jl_gc_run_all_finalizers(jl_task_t *ct);
void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task);
void jl_gc_add_finalizer_(jl_ptls_t ptls, void *v, void *f) JL_NOTSAFEPOINT;
Expand Down

0 comments on commit 54614fd

Please sign in to comment.