From db13a49c7728afce4410c70b85966700b05e6c87 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Tue, 11 Jan 2022 20:13:16 -0500 Subject: [PATCH 01/12] try wrapping pool alloc --- src/gc.c | 9 +++++++++ src/llvm-pass-helpers.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 56b2c31cbe7f1..ff91f89a6ca92 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1196,6 +1196,15 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT return fl; } +// called into by LLVM-generated code +JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_outer(jl_ptls_t ptls, int pool_offset, + int osize) +{ + jl_value_t *val = jl_gc_pool_alloc(ptls, pool_offset, osize); + maybe_record_alloc_to_profile(val, osize); + return val; +} + // Size includes the tag and the tag is not cleared!! JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, int osize) diff --git a/src/llvm-pass-helpers.cpp b/src/llvm-pass-helpers.cpp index 2821f9838a0a7..1ea02f94eb776 100644 --- a/src/llvm-pass-helpers.cpp +++ b/src/llvm-pass-helpers.cpp @@ -214,7 +214,7 @@ namespace jl_intrinsics { namespace jl_well_known { static const char *GC_BIG_ALLOC_NAME = XSTR(jl_gc_big_alloc); - static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc); + static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc_outer); static const char *GC_QUEUE_ROOT_NAME = XSTR(jl_gc_queue_root); using jl_intrinsics::addGCAllocAttributes; From 00a791e6e889b78a1ac2fccdf80591f14bfda114 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Tue, 11 Jan 2022 23:02:45 -0500 Subject: [PATCH 02/12] update exported functions --- src/jl_exported_funcs.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index 9665bb67da5d0..54fc33241b0af 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -182,6 +182,7 @@ XX(jl_gc_new_weakref_th) \ XX(jl_gc_num) \ XX(jl_gc_pool_alloc) \ + XX(jl_gc_pool_alloc_outer) \ XX(jl_gc_queue_multiroot) \ XX(jl_gc_queue_root) \ XX(jl_gc_schedule_foreign_sweepfunc) \ From d0f5ce0b758f6a5f5956a5e93a3076cd6f05eacf Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 17 Jan 2022 20:50:35 -0500 Subject: [PATCH 03/12] avoid segfault by zeroing out type tag --- src/gc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gc.c b/src/gc.c index ff91f89a6ca92..224400c23ba7a 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1201,6 +1201,9 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_outer(jl_ptls_t ptls, int pool_offset, int osize) { jl_value_t *val = jl_gc_pool_alloc(ptls, pool_offset, osize); + // zero out the type tag so it's not garbage + jl_set_typeof(val, 0); + maybe_record_alloc_to_profile(val, osize); return val; } From c4207ea1b8dc36622f26731d0dae04b66e317572 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 17 Jan 2022 23:45:09 -0500 Subject: [PATCH 04/12] capture managed_malloc --- src/gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 224400c23ba7a..fa5bd1bb8aa88 100644 --- a/src/gc.c +++ b/src/gc.c @@ -3552,6 +3552,7 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz) SetLastError(last_error); #endif errno = last_errno; + maybe_record_alloc_to_profile(b, sz); return b; } @@ -3593,7 +3594,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); return b; } From 667cc2968234b3a55ee88ad2b11917e791f82464 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 18 Jan 2022 16:36:02 -0500 Subject: [PATCH 05/12] Report the alloc as a jl_buff_tag. --- src/gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index fa5bd1bb8aa88..41fd4d2c86ef5 100644 --- a/src/gc.c +++ b/src/gc.c @@ -3552,7 +3552,8 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz) SetLastError(last_error); #endif errno = last_errno; - maybe_record_alloc_to_profile(b, sz); + // jl_gc_managed_malloc is currently always used for allocating array buffers. + maybe_record_alloc_to_profile(b, sz, jl_buff_tag); return b; } From 1a2d073a1d38904e6f9b833661dd037dc87af5e7 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 18 Jan 2022 16:49:16 -0500 Subject: [PATCH 06/12] Fixup gc_managed_realloc_ --- src/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 41fd4d2c86ef5..5949b13dd866a 100644 --- a/src/gc.c +++ b/src/gc.c @@ -3595,7 +3595,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); + maybe_record_alloc_to_profile(b, sz, jl_gc_unknown_type_tag); return b; } From da200691ba97b6fcb47d2f44c8f34fb179bef092 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 18 Jan 2022 16:18:31 -0500 Subject: [PATCH 07/12] Move type to param of _maybe_record_alloc_to_profile Make an UnknownType for the GC Profiler to handle these unknown types. --- src/array.c | 2 +- src/gc-alloc-profiler.cpp | 3 +-- src/gc-alloc-profiler.h | 8 +++++--- src/gc.c | 4 +--- src/julia_internal.h | 2 +- stdlib/Profile/src/Allocs.jl | 4 ++++ 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/array.c b/src/array.c index d620278e34b14..bd37ebc6caa89 100644 --- a/src/array.c +++ b/src/array.c @@ -508,7 +508,7 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len) s = jl_gc_big_alloc(ptls, allocsz); } jl_set_typeof(s, jl_string_type); - maybe_record_alloc_to_profile(s, len); + maybe_record_alloc_to_profile(s, len, jl_string_type); *(size_t*)s = len; jl_string_data(s)[len] = 0; return s; diff --git a/src/gc-alloc-profiler.cpp b/src/gc-alloc-profiler.cpp index d00b2117e2c04..4a78a587c864a 100644 --- a/src/gc-alloc-profiler.cpp +++ b/src/gc-alloc-profiler.cpp @@ -118,7 +118,7 @@ JL_DLLEXPORT void jl_free_alloc_profile() { // == callback called into by the outside == -void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOINT { +void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t *type) JL_NOTSAFEPOINT { auto& global_profile = g_alloc_profile; auto& profile = global_profile.per_thread_profiles[jl_threadid()]; @@ -128,7 +128,6 @@ void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOIN return; } - auto type = (jl_datatype_t*)jl_typeof(val); profile.allocs.emplace_back(jl_raw_alloc_t{ type, get_raw_backtrace(), diff --git a/src/gc-alloc-profiler.h b/src/gc-alloc-profiler.h index 3509b77daa1fc..3cfe7237dd183 100644 --- a/src/gc-alloc-profiler.h +++ b/src/gc-alloc-profiler.h @@ -31,13 +31,15 @@ JL_DLLEXPORT void jl_free_alloc_profile(void); // Functions to call from GC when alloc profiling is enabled // --------------------------------------------------------------------- -void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOINT; +void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t *typ) JL_NOTSAFEPOINT; extern int g_alloc_profile_enabled; -static inline void maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOINT { +#define jl_gc_unknown_type_tag ((uintptr_t)0xdeadaa03) + +static inline void maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t *typ) JL_NOTSAFEPOINT { if (__unlikely(g_alloc_profile_enabled)) { - _maybe_record_alloc_to_profile(val, size); + _maybe_record_alloc_to_profile(val, size, typ); } } diff --git a/src/gc.c b/src/gc.c index 5949b13dd866a..0ad93c7763904 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1201,10 +1201,8 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_outer(jl_ptls_t ptls, int pool_offset, int osize) { jl_value_t *val = jl_gc_pool_alloc(ptls, pool_offset, osize); - // zero out the type tag so it's not garbage - jl_set_typeof(val, 0); - maybe_record_alloc_to_profile(val, osize); + maybe_record_alloc_to_profile(val, osize, jl_gc_unknown_type_tag); return val; } diff --git a/src/julia_internal.h b/src/julia_internal.h index 1fbfb082e4a8f..5d9b9e6f5e870 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -365,7 +365,7 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty) v = jl_gc_big_alloc(ptls, allocsz); } jl_set_typeof(v, ty); - maybe_record_alloc_to_profile(v, sz); + maybe_record_alloc_to_profile(v, sz, (jl_datatype_t*)ty); return v; } diff --git a/stdlib/Profile/src/Allocs.jl b/stdlib/Profile/src/Allocs.jl index 922b31932cb0f..70a9978b456ca 100644 --- a/stdlib/Profile/src/Allocs.jl +++ b/stdlib/Profile/src/Allocs.jl @@ -161,15 +161,19 @@ const BacktraceCache = Dict{BTElement,Vector{StackFrame}} # copied from julia_internal.h const JL_BUFF_TAG = UInt(0x4eadc000) +const JL_GC_UNKNOWN_TYPE_TAG = UInt(0xdeadaa03) struct CorruptType end struct BufferType end +struct UnknownType end function load_type(ptr::Ptr{Type}) if UInt(ptr) < UInt(4096) return CorruptType elseif UInt(ptr) == JL_BUFF_TAG return BufferType + elseif UInt(ptr) == JL_GC_UNKNOWN_TYPE_TAG + return UnknownType end return unsafe_pointer_to_objref(ptr) end From 38f7e9b6683a6ee4bb56aa030244f640ac7bbbc8 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Tue, 25 Jan 2022 15:58:45 -0500 Subject: [PATCH 08/12] rename pool_alloc => pool_alloc_inner; pool_alloc_outer => pool_alloc --- src/array.c | 2 +- src/gc.c | 10 +++++----- src/jl_exported_funcs.inc | 1 - src/julia_internal.h | 6 +++--- src/llvm-pass-helpers.cpp | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/array.c b/src/array.c index bd37ebc6caa89..061ffdac86ec9 100644 --- a/src/array.c +++ b/src/array.c @@ -500,7 +500,7 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len) int pool_id = jl_gc_szclass_align8(allocsz); jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id]; int osize = jl_gc_sizeclasses[pool_id]; - s = jl_gc_pool_alloc(ptls, (char*)p - (char*)ptls, osize); + s = jl_gc_pool_alloc_inner(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" diff --git a/src/gc.c b/src/gc.c index 0ad93c7763904..bfdb5204e2aef 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1196,19 +1196,19 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT return fl; } -// called into by LLVM-generated code -JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_outer(jl_ptls_t ptls, int pool_offset, +// instrumented version of jl_gc_pool_alloc_inner called into by LLVM-generated code +JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, int osize) { - jl_value_t *val = jl_gc_pool_alloc(ptls, pool_offset, osize); + jl_value_t *val = jl_gc_pool_alloc_inner(ptls, pool_offset, osize); maybe_record_alloc_to_profile(val, osize, jl_gc_unknown_type_tag); return val; } // Size includes the tag and the tag is not cleared!! -JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, - int osize) +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 // to workaround a llvm bug. diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index 54fc33241b0af..9665bb67da5d0 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -182,7 +182,6 @@ XX(jl_gc_new_weakref_th) \ XX(jl_gc_num) \ XX(jl_gc_pool_alloc) \ - XX(jl_gc_pool_alloc_outer) \ XX(jl_gc_queue_multiroot) \ XX(jl_gc_queue_root) \ XX(jl_gc_schedule_foreign_sweepfunc) \ diff --git a/src/julia_internal.h b/src/julia_internal.h index 5d9b9e6f5e870..d246b98645113 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -228,8 +228,8 @@ extern jl_array_t *jl_all_methods JL_GLOBALLY_ROOTED; JL_DLLEXPORT extern int jl_lineno; JL_DLLEXPORT extern const char *jl_filename; -JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, - int osize); +jl_value_t *jl_gc_pool_alloc_inner(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); JL_DLLEXPORT int jl_gc_classify_pools(size_t sz, int *osize); extern uv_mutex_t gc_perm_lock; @@ -357,7 +357,7 @@ 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(ptls, (char*)p - (char*)ptls, osize); + v = jl_gc_pool_alloc_inner(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" diff --git a/src/llvm-pass-helpers.cpp b/src/llvm-pass-helpers.cpp index 1ea02f94eb776..2821f9838a0a7 100644 --- a/src/llvm-pass-helpers.cpp +++ b/src/llvm-pass-helpers.cpp @@ -214,7 +214,7 @@ namespace jl_intrinsics { namespace jl_well_known { static const char *GC_BIG_ALLOC_NAME = XSTR(jl_gc_big_alloc); - static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc_outer); + static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc); static const char *GC_QUEUE_ROOT_NAME = XSTR(jl_gc_queue_root); using jl_intrinsics::addGCAllocAttributes; From 51d0308df193155cb65fd587a9da102dfedbd941 Mon Sep 17 00:00:00 2001 From: Pete Vilter <7341+vilterp@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:47:15 -0500 Subject: [PATCH 09/12] alloc profile: inline gc_pool_alloc (with another wrapper) (#21) * add a wrapper and inline into it * review suggestions Co-authored-by: Nathan Daly --- src/array.c | 4 +++- src/gc.c | 31 +++++++++++++++++++------------ src/julia_internal.h | 6 ++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/array.c b/src/array.c index 061ffdac86ec9..e805615fe659d 100644 --- a/src/array.c +++ b/src/array.c @@ -500,7 +500,9 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len) int pool_id = jl_gc_szclass_align8(allocsz); jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id]; int osize = jl_gc_sizeclasses[pool_id]; - s = jl_gc_pool_alloc_inner(ptls, (char*)p - (char*)ptls, osize); + // We call `jl_gc_pool_alloc_wrapper` 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.) + s = jl_gc_pool_alloc_wrapper(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" diff --git a/src/gc.c b/src/gc.c index bfdb5204e2aef..3a75e77541b37 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1196,19 +1196,9 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT return fl; } -// instrumented version of jl_gc_pool_alloc_inner called into by LLVM-generated code -JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, - int osize) -{ - jl_value_t *val = jl_gc_pool_alloc_inner(ptls, pool_offset, osize); - - maybe_record_alloc_to_profile(val, osize, jl_gc_unknown_type_tag); - return val; -} - // Size includes the tag and the tag is not cleared!! -jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset, - int osize) +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 // to workaround a llvm bug. @@ -1263,6 +1253,23 @@ jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset, return jl_valueof(v); } +// instrumented version of jl_gc_pool_alloc_inner called into by LLVM-generated code +JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, + int osize) +{ + jl_value_t *val = jl_gc_pool_alloc_inner(ptls, pool_offset, osize); + + maybe_record_alloc_to_profile(val, osize, jl_gc_unknown_type_tag); + return val; +} + +// 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) { + return jl_gc_pool_alloc_inner(ptls, pool_offset, osize); +} + int jl_gc_classify_pools(size_t sz, int *osize) { if (sz > GC_MAX_SZCLASS) diff --git a/src/julia_internal.h b/src/julia_internal.h index d246b98645113..0546b94c23c2c 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -228,7 +228,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_inner(jl_ptls_t ptls, int pool_offset, +jl_value_t *jl_gc_pool_alloc_wrapper(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); JL_DLLEXPORT int jl_gc_classify_pools(size_t sz, int *osize); @@ -357,7 +357,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_inner(ptls, (char*)p - (char*)ptls, osize); + // We call `jl_gc_pool_alloc_wrapper` 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_wrapper(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" From 0ebf97b05ddf723dacaf436f7beeb531d78c382d Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Wed, 2 Feb 2022 09:42:41 -0500 Subject: [PATCH 10/12] Comment --- src/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 3a75e77541b37..05b79458c5a95 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1253,7 +1253,7 @@ static inline jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset return jl_valueof(v); } -// instrumented version of jl_gc_pool_alloc_inner called into by LLVM-generated code +// Instrumented version of jl_gc_pool_alloc_inner, called into by LLVM-generated code. JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, int osize) { From c0cd472223c4269828b79fcb3087eae0f6eb0220 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 4 Feb 2022 10:28:16 -0500 Subject: [PATCH 11/12] Rename `s/jl_gc_pool_alloc_wrapper/jl_gc_pool_alloc_noinline/g` --- src/array.c | 4 ++-- src/gc.c | 2 +- src/julia_internal.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/array.c b/src/array.c index e805615fe659d..fcfe22ed454d4 100644 --- a/src/array.c +++ b/src/array.c @@ -500,9 +500,9 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len) int pool_id = jl_gc_szclass_align8(allocsz); jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id]; int osize = jl_gc_sizeclasses[pool_id]; - // We call `jl_gc_pool_alloc_wrapper` instead of `jl_gc_pool_alloc` to avoid double-counting in + // 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.) - s = jl_gc_pool_alloc_wrapper(ptls, (char*)p - (char*)ptls, osize); + s = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" diff --git a/src/gc.c b/src/gc.c index 05b79458c5a95..8fd83a3b42589 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1266,7 +1266,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); } diff --git a/src/julia_internal.h b/src/julia_internal.h index 330ee7bb6f64d..420b828ad81ca 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -228,7 +228,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); JL_DLLEXPORT int jl_gc_classify_pools(size_t sz, int *osize); @@ -357,9 +357,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]; - // We call `jl_gc_pool_alloc_wrapper` instead of `jl_gc_pool_alloc` to avoid double-counting in + // 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_wrapper(ptls, (char*)p - (char*)ptls, osize); + v = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative" From c0c854e68f3977a7fcd18bdbe798063ec60f13ee Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 4 Feb 2022 10:39:21 -0500 Subject: [PATCH 12/12] Fix pointer casting warnings by adding the appropriate casts --- src/gc-alloc-profiler.h | 2 +- src/gc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gc-alloc-profiler.h b/src/gc-alloc-profiler.h index 3cfe7237dd183..8be6fed21a899 100644 --- a/src/gc-alloc-profiler.h +++ b/src/gc-alloc-profiler.h @@ -35,7 +35,7 @@ void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t extern int g_alloc_profile_enabled; -#define jl_gc_unknown_type_tag ((uintptr_t)0xdeadaa03) +#define jl_gc_unknown_type_tag ((jl_datatype_t*)0xdeadaa03) static inline void maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t *typ) JL_NOTSAFEPOINT { if (__unlikely(g_alloc_profile_enabled)) { diff --git a/src/gc.c b/src/gc.c index 8fd83a3b42589..745f5365510f9 100644 --- a/src/gc.c +++ b/src/gc.c @@ -3558,7 +3558,7 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz) #endif errno = last_errno; // jl_gc_managed_malloc is currently always used for allocating array buffers. - maybe_record_alloc_to_profile(b, sz, jl_buff_tag); + maybe_record_alloc_to_profile(b, sz, (jl_datatype_t*)jl_buff_tag); return b; }