Skip to content

Commit 46b692e

Browse files
vilterpNHDaly
authored andcommitted
allocation profiler: get stacks for pool allocs via wrapper function (#43868)
1 parent 62e8dec commit 46b692e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/gc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
11951195
}
11961196

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

@@ -3522,6 +3522,8 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
35223522
SetLastError(last_error);
35233523
#endif
35243524
errno = last_errno;
3525+
// jl_gc_managed_malloc is currently always used for allocating array buffers.
3526+
maybe_record_alloc_to_profile(b, sz, (jl_datatype_t*)jl_buff_tag);
35253527
return b;
35263528
}
35273529

@@ -3563,7 +3565,7 @@ static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t olds
35633565
SetLastError(last_error);
35643566
#endif
35653567
errno = last_errno;
3566-
3568+
maybe_record_alloc_to_profile(b, sz, jl_gc_unknown_type_tag);
35673569
return b;
35683570
}
35693571

src/julia_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extern jl_array_t *jl_all_methods JL_GLOBALLY_ROOTED;
226226
JL_DLLEXPORT extern int jl_lineno;
227227
JL_DLLEXPORT extern const char *jl_filename;
228228

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

0 commit comments

Comments
 (0)