mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-21 10:22:30 +03:00
Extract profiling code from [re]allocation functions.
Extract profiling code from malloc(), imemalign(), calloc(), realloc(), mallocx(), rallocx(), and xallocx(). This slightly reduces the amount of code compiled into the fast paths, but the primary benefit is the combinatorial complexity reduction. Simplify iralloc[t]() by creating a separate ixalloc() that handles the no-move cases. Further simplify [mrxn]allocx() (and by implication [mrn]allocm()) to make request size overflows due to size class and/or alignment constraints trigger undefined behavior (detected by debug-only assertions). Report ENOMEM rather than EINVAL if an OOM occurs during heap profiling backtrace creation in imemalign(). This bug impacted posix_memalign() and aligned_alloc().
This commit is contained in:
parent
6b694c4d47
commit
b2c31660be
10 changed files with 553 additions and 497 deletions
|
|
@ -44,23 +44,6 @@ TEST_BEGIN(test_alignment_errors)
|
|||
void *p;
|
||||
size_t nsz, rsz, sz, alignment;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
sz = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
sz = 0x80000000LU;
|
||||
#endif
|
||||
nsz = 0;
|
||||
assert_d_ne(nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)), ALLOCM_SUCCESS,
|
||||
"Expected error for nallocm(&nsz, %zu, %#x)",
|
||||
sz, ALLOCM_ALIGN(alignment));
|
||||
rsz = 0;
|
||||
assert_d_ne(allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)),
|
||||
ALLOCM_SUCCESS, "Expected error for allocm(&p, %zu, %#x)",
|
||||
sz, ALLOCM_ALIGN(alignment));
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
sz = UINT64_C(0x8400000000000001);
|
||||
|
|
@ -75,22 +58,6 @@ TEST_BEGIN(test_alignment_errors)
|
|||
assert_d_ne(allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)),
|
||||
ALLOCM_SUCCESS, "Expected error for allocm(&p, %zu, %#x)",
|
||||
sz, ALLOCM_ALIGN(alignment));
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
sz = UINT64_C(0xfffffffffffffff0);
|
||||
#else
|
||||
sz = 0xfffffff0LU;
|
||||
#endif
|
||||
nsz = 0;
|
||||
assert_d_ne(nallocm(&nsz, sz, ALLOCM_ALIGN(alignment)), ALLOCM_SUCCESS,
|
||||
"Expected error for nallocm(&nsz, %zu, %#x)",
|
||||
sz, ALLOCM_ALIGN(alignment));
|
||||
rsz = 0;
|
||||
assert_d_ne(allocm(&p, &rsz, sz, ALLOCM_ALIGN(alignment)),
|
||||
ALLOCM_SUCCESS, "Expected error for allocm(&p, %zu, %#x)",
|
||||
sz, ALLOCM_ALIGN(alignment));
|
||||
assert_zu_eq(nsz, rsz, "nallocm()/allocm() rsize mismatch");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
|
|||
|
|
@ -39,20 +39,6 @@ TEST_BEGIN(test_alignment_errors)
|
|||
void *p;
|
||||
size_t nsz, sz, alignment;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
sz = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
sz = 0x80000000LU;
|
||||
#endif
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_zu_eq(nsz, 0, "Expected error for nallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
p = mallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_ptr_null(p, "Expected error for mallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
sz = UINT64_C(0x8400000000000001);
|
||||
|
|
@ -65,22 +51,6 @@ TEST_BEGIN(test_alignment_errors)
|
|||
p = mallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_ptr_null(p, "Expected error for mallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
sz = UINT64_C(0xfffffffffffffff0);
|
||||
#else
|
||||
sz = 0xfffffff0LU;
|
||||
#endif
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_zu_eq(nsz, 0, "Expected error for nallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_zu_eq(nsz, 0, "Expected error for nallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
p = mallocx(sz, MALLOCX_ALIGN(alignment));
|
||||
assert_ptr_null(p, "Expected error for mallocx(%zu, %#x)", sz,
|
||||
MALLOCX_ALIGN(alignment));
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue