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

Function imalloc_body

deps/memkind/src/jemalloc/src/jemalloc.c:1727–1922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1725}
1726
1727JEMALLOC_ALWAYS_INLINE int
1728imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) {
1729 /* Where the actual allocated memory will live. */
1730 void *allocation = NULL;
1731 /* Filled in by compute_size_with_overflow below. */
1732 size_t size = 0;
1733 /*
1734 * For unaligned allocations, we need only ind. For aligned
1735 * allocations, or in case of stats or profiling we need usize.
1736 *
1737 * These are actually dead stores, in that their values are reset before
1738 * any branch on their value is taken. Sometimes though, it's
1739 * convenient to pass them as arguments before this point. To avoid
1740 * undefined behavior then, we initialize them with dummy stores.
1741 */
1742 szind_t ind = 0;
1743 size_t usize = 0;
1744
1745 /* Reentrancy is only checked on slow path. */
1746 int8_t reentrancy_level;
1747
1748 /* Compute the amount of memory the user wants. */
1749 if (unlikely(compute_size_with_overflow(sopts->may_overflow, dopts,
1750 &size))) {
1751 goto label_oom;
1752 }
1753
1754 /* Validate the user input. */
1755 if (sopts->bump_empty_alloc) {
1756 if (unlikely(size == 0)) {
1757 size = 1;
1758 }
1759 }
1760
1761 if (sopts->assert_nonempty_alloc) {
1762 assert (size != 0);
1763 }
1764
1765 if (unlikely(dopts->alignment < sopts->min_alignment
1766 || (dopts->alignment & (dopts->alignment - 1)) != 0)) {
1767 goto label_invalid_alignment;
1768 }
1769
1770 /* This is the beginning of the "core" algorithm. */
1771
1772 if (dopts->alignment == 0) {
1773 ind = sz_size2index(size);
1774 if (unlikely(ind >= NSIZES)) {
1775 goto label_oom;
1776 }
1777 if (config_stats || (config_prof && opt_prof)) {
1778 usize = sz_index2size(ind);
1779 assert(usize > 0 && usize <= LARGE_MAXCLASS);
1780 }
1781 } else {
1782 usize = sz_sa2u(size, dopts->alignment);
1783 if (unlikely(usize == 0 || usize > LARGE_MAXCLASS)) {
1784 goto label_oom;

Callers 1

imallocFunction · 0.70

Calls 13

check_entry_exit_lockingFunction · 0.70
imalloc_no_sampleFunction · 0.70
imalloc_sampleFunction · 0.70
malloc_writeFunction · 0.70
sz_size2indexFunction · 0.50
sz_index2sizeFunction · 0.50
sz_sa2uFunction · 0.50
tsd_tsdnFunction · 0.50
prof_active_get_unlockedFunction · 0.50
prof_mallocFunction · 0.50
isallocFunction · 0.50

Tested by

no test coverage detected