MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ixallocx_prof

Function ixallocx_prof

deps/jemalloc/src/jemalloc.c:3338–3387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3336}
3337
3338JEMALLOC_ALWAYS_INLINE size_t
3339ixallocx_prof(tsd_t *tsd, void *ptr, size_t old_usize, size_t size,
3340 size_t extra, size_t alignment, bool zero, alloc_ctx_t *alloc_ctx) {
3341 size_t usize_max, usize;
3342 bool prof_active;
3343 prof_tctx_t *old_tctx, *tctx;
3344
3345 prof_active = prof_active_get_unlocked();
3346 old_tctx = prof_tctx_get(tsd_tsdn(tsd), ptr, alloc_ctx);
3347 /*
3348 * usize isn't knowable before ixalloc() returns when extra is non-zero.
3349 * Therefore, compute its maximum possible value and use that in
3350 * prof_alloc_prep() to decide whether to capture a backtrace.
3351 * prof_realloc() will use the actual usize to decide whether to sample.
3352 */
3353 if (alignment == 0) {
3354 usize_max = sz_s2u(size+extra);
3355 assert(usize_max > 0
3356 && usize_max <= SC_LARGE_MAXCLASS);
3357 } else {
3358 usize_max = sz_sa2u(size+extra, alignment);
3359 if (unlikely(usize_max == 0
3360 || usize_max > SC_LARGE_MAXCLASS)) {
3361 /*
3362 * usize_max is out of range, and chances are that
3363 * allocation will fail, but use the maximum possible
3364 * value and carry on with prof_alloc_prep(), just in
3365 * case allocation succeeds.
3366 */
3367 usize_max = SC_LARGE_MAXCLASS;
3368 }
3369 }
3370 tctx = prof_alloc_prep(tsd, usize_max, prof_active, false);
3371
3372 if (unlikely((uintptr_t)tctx != (uintptr_t)1U)) {
3373 usize = ixallocx_prof_sample(tsd_tsdn(tsd), ptr, old_usize,
3374 size, extra, alignment, zero, tctx);
3375 } else {
3376 usize = ixallocx_helper(tsd_tsdn(tsd), ptr, old_usize, size,
3377 extra, alignment, zero);
3378 }
3379 if (usize == old_usize) {
3380 prof_alloc_rollback(tsd, tctx, false);
3381 return usize;
3382 }
3383 prof_realloc(tsd, ptr, usize, tctx, prof_active, false, ptr, old_usize,
3384 old_tctx);
3385
3386 return usize;
3387}
3388
3389JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW
3390je_xallocx(void *ptr, size_t size, size_t extra, int flags) {

Callers 1

je_xallocxFunction · 0.70

Calls 7

ixallocx_prof_sampleFunction · 0.70
ixallocx_helperFunction · 0.70
prof_active_get_unlockedFunction · 0.50
tsd_tsdnFunction · 0.50
sz_s2uFunction · 0.50
sz_sa2uFunction · 0.50
prof_reallocFunction · 0.50

Tested by

no test coverage detected