Skip to content

Commit

Permalink
allocation profiler: get stacks for pool allocs via wrapper function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vilterp authored and NHDaly committed Feb 10, 2022
1 parent a96ad14 commit 28eb1f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
}

// Size includes the tag and the tag is not cleared!!
JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset,
static inline jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset,
int osize)
{
// Use the pool offset instead of the pool address as the argument
Expand Down Expand Up @@ -1256,7 +1256,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset,
// This wrapper exists only to prevent `jl_gc_pool_alloc_inner` from being inlined into
// its callers. We provide an external-facing interface for callers, and inline `jl_gc_pool_alloc_inner`
// into this. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
jl_value_t *jl_gc_pool_alloc_wrapper(jl_ptls_t ptls, int pool_offset, int osize) {
jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset, int osize) {
return jl_gc_pool_alloc_inner(ptls, pool_offset, osize);
}

Expand Down Expand Up @@ -3493,6 +3493,8 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
SetLastError(last_error);
#endif
errno = last_errno;
// jl_gc_managed_malloc is currently always used for allocating array buffers.
maybe_record_alloc_to_profile(b, sz, (jl_datatype_t*)jl_buff_tag);
return b;
}

Expand Down Expand Up @@ -3531,7 +3533,7 @@ static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t olds
SetLastError(last_error);
#endif
errno = last_errno;

maybe_record_alloc_to_profile(b, sz, jl_gc_unknown_type_tag);
return b;
}

Expand Down
6 changes: 4 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ extern jl_array_t *jl_all_methods JL_GLOBALLY_ROOTED;
JL_DLLEXPORT extern int jl_lineno;
JL_DLLEXPORT extern const char *jl_filename;

jl_value_t *jl_gc_pool_alloc_wrapper(jl_ptls_t ptls, int pool_offset,
jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset,
int osize);
JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t allocsz);
int jl_gc_classify_pools(size_t sz, int *osize);
Expand Down Expand Up @@ -313,7 +313,9 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
int pool_id = jl_gc_szclass(allocsz);
jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id];
int osize = jl_gc_sizeclasses[pool_id];
v = jl_gc_pool_alloc_wrapper(ptls, (char*)p - (char*)ptls, osize);
// We call `jl_gc_pool_alloc_noinline` instead of `jl_gc_pool_alloc` to avoid double-counting in
// the Allocations Profiler. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
v = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize);
}
else {
if (allocsz < sz) // overflow in adding offs, size was "negative"
Expand Down

0 comments on commit 28eb1f6

Please sign in to comment.