Jason Evans | 1ff0953 | 2017-01-16 11:09:24 -0800 | [diff] [blame] | 1 | #include "test/jemalloc_test.h" |
| 2 | |
| 3 | #ifdef JEMALLOC_PROF |
| 4 | const char *malloc_conf = "prof:true,lg_prof_sample:0"; |
| 5 | #endif |
| 6 | |
| 7 | TEST_BEGIN(test_prof_realloc) |
| 8 | { |
| 9 | tsdn_t *tsdn; |
| 10 | int flags; |
| 11 | void *p, *q; |
| 12 | extent_t *extent_p, *extent_q; |
| 13 | prof_tctx_t *tctx_p, *tctx_q; |
| 14 | uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3; |
| 15 | |
| 16 | test_skip_if(!config_prof); |
| 17 | |
| 18 | tsdn = tsdn_fetch(); |
| 19 | flags = MALLOCX_TCACHE_NONE; |
| 20 | |
| 21 | prof_cnt_all(&curobjs_0, NULL, NULL, NULL); |
| 22 | p = mallocx(1024, flags); |
| 23 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); |
| 24 | extent_p = iealloc(tsdn, p); |
| 25 | assert_ptr_not_null(extent_p, "Unexpected iealloc() failure"); |
| 26 | tctx_p = prof_tctx_get(tsdn, extent_p, p); |
| 27 | assert_ptr_ne(tctx_p, (prof_tctx_t *)(uintptr_t)1U, |
| 28 | "Expected valid tctx"); |
| 29 | prof_cnt_all(&curobjs_1, NULL, NULL, NULL); |
| 30 | assert_u64_eq(curobjs_0 + 1, curobjs_1, |
| 31 | "Allocation should have increased sample size"); |
| 32 | |
| 33 | q = rallocx(p, 2048, flags); |
| 34 | assert_ptr_ne(p, q, "Expected move"); |
| 35 | assert_ptr_not_null(p, "Unexpected rmallocx() failure"); |
| 36 | extent_q = iealloc(tsdn, q); |
| 37 | assert_ptr_not_null(extent_q, "Unexpected iealloc() failure"); |
| 38 | tctx_q = prof_tctx_get(tsdn, extent_q, q); |
| 39 | assert_ptr_ne(tctx_q, (prof_tctx_t *)(uintptr_t)1U, |
| 40 | "Expected valid tctx"); |
| 41 | prof_cnt_all(&curobjs_2, NULL, NULL, NULL); |
| 42 | assert_u64_eq(curobjs_1, curobjs_2, |
| 43 | "Reallocation should not have changed sample size"); |
| 44 | |
| 45 | dallocx(q, flags); |
| 46 | prof_cnt_all(&curobjs_3, NULL, NULL, NULL); |
| 47 | assert_u64_eq(curobjs_0, curobjs_3, |
| 48 | "Sample size should have returned to base level"); |
| 49 | } |
| 50 | TEST_END |
| 51 | |
| 52 | int |
| 53 | main(void) |
| 54 | { |
| 55 | return test( |
| 56 | test_prof_realloc); |
| 57 | } |