Skip to content

Commit fa03f38

Browse files
NHDalyvilterp
andcommitted
Instrument jl_gc_big_alloc() when called from generated code for Allocations Profiler (#44043)
* Instrument jl_gc_big_alloc() when called from generated code for Allocations Profiler Add _maybe_record_alloc_to_profile() call into jl_gc_big_alloc() to allow us to instrument it in the Allocations Profiler. Followup to #43868 Finishes fixing #43688 (gets the stacks, though not the types, of big allocs). ----- - Rename jl_gc_big_alloc to jl_gc_big_alloc_inner, make it inlined - add jl_gc_pool_alloc_noinline that calls jl_gc_big_alloc_inner - replace all internal calls to jl_gc_big_alloc to call this instead - add a new jl_gc_pool_alloc that calls jl_gc_big_alloc_inner - This one is instrumented, and is meant to be called by generated code. Co-authored-by: Pete Vilter <[email protected]>
1 parent 28eb1f6 commit fa03f38

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/gc.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ static void sweep_weak_refs(void)
939939
// big value list
940940

941941
// Size includes the tag and the tag is not cleared!!
942-
JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t sz)
942+
static inline jl_value_t *jl_gc_big_alloc_inner(jl_ptls_t ptls, size_t sz)
943943
{
944944
maybe_collect(ptls);
945945
size_t offs = offsetof(bigval_t, header);
@@ -965,6 +965,22 @@ JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t sz)
965965
return jl_valueof(&v->header);
966966
}
967967

968+
// Instrumented version of jl_gc_big_alloc_inner, called into by LLVM-generated code.
969+
JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t sz)
970+
{
971+
jl_value_t *val = jl_gc_big_alloc_inner(ptls, sz);
972+
973+
maybe_record_alloc_to_profile(val, sz, jl_gc_unknown_type_tag);
974+
return val;
975+
}
976+
977+
// This wrapper exists only to prevent `jl_gc_big_alloc_inner` from being inlined into
978+
// its callers. We provide an external-facing interface for callers, and inline `jl_gc_big_alloc_inner`
979+
// into this. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
980+
jl_value_t *jl_gc_big_alloc_noinline(jl_ptls_t ptls, size_t sz) {
981+
return jl_gc_big_alloc_inner(ptls, sz);
982+
}
983+
968984
// Sweep list rooted at *pv, removing and freeing any unmarked objects.
969985
// Return pointer to last `next` field in the culled list.
970986
static bigval_t **sweep_big_list(int sweep_full, bigval_t **pv) JL_NOTSAFEPOINT

src/julia_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ JL_DLLEXPORT extern const char *jl_filename;
205205

206206
jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset,
207207
int osize);
208-
JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t allocsz);
208+
jl_value_t *jl_gc_big_alloc_noinline(jl_ptls_t ptls, size_t allocsz);
209209
int jl_gc_classify_pools(size_t sz, int *osize);
210210
extern jl_mutex_t gc_perm_lock;
211211
void *jl_gc_perm_alloc_nolock(size_t sz, int zero,
@@ -320,7 +320,7 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
320320
else {
321321
if (allocsz < sz) // overflow in adding offs, size was "negative"
322322
jl_throw(jl_memory_exception);
323-
v = jl_gc_big_alloc(ptls, allocsz);
323+
v = jl_gc_big_alloc_noinline(ptls, allocsz);
324324
}
325325
jl_set_typeof(v, ty);
326326
maybe_record_alloc_to_profile(v, sz, (jl_datatype_t*)ty);

0 commit comments

Comments
 (0)