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

Function imalloc_body

deps/jemalloc/src/jemalloc.c:2027–2225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2025}
2026
2027JEMALLOC_ALWAYS_INLINE int
2028imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) {
2029 /* Where the actual allocated memory will live. */
2030 void *allocation = NULL;
2031 /* Filled in by compute_size_with_overflow below. */
2032 size_t size = 0;
2033 /*
2034 * For unaligned allocations, we need only ind. For aligned
2035 * allocations, or in case of stats or profiling we need usize.
2036 *
2037 * These are actually dead stores, in that their values are reset before
2038 * any branch on their value is taken. Sometimes though, it's
2039 * convenient to pass them as arguments before this point. To avoid
2040 * undefined behavior then, we initialize them with dummy stores.
2041 */
2042 szind_t ind = 0;
2043 size_t usize = 0;
2044
2045 /* Reentrancy is only checked on slow path. */
2046 int8_t reentrancy_level;
2047
2048 /* Compute the amount of memory the user wants. */
2049 if (unlikely(compute_size_with_overflow(sopts->may_overflow, dopts,
2050 &size))) {
2051 goto label_oom;
2052 }
2053
2054 if (unlikely(dopts->alignment < sopts->min_alignment
2055 || (dopts->alignment & (dopts->alignment - 1)) != 0)) {
2056 goto label_invalid_alignment;
2057 }
2058
2059 /* This is the beginning of the "core" algorithm. */
2060
2061 if (dopts->alignment == 0) {
2062 ind = sz_size2index(size);
2063 if (unlikely(ind >= SC_NSIZES)) {
2064 goto label_oom;
2065 }
2066 if (config_stats || (config_prof && opt_prof) || sopts->usize) {
2067 usize = sz_index2size(ind);
2068 dopts->usize = usize;
2069 assert(usize > 0 && usize
2070 <= SC_LARGE_MAXCLASS);
2071 }
2072 } else {
2073 if (sopts->bump_empty_aligned_alloc) {
2074 if (unlikely(size == 0)) {
2075 size = 1;
2076 }
2077 }
2078 usize = sz_sa2u(size, dopts->alignment);
2079 dopts->usize = usize;
2080 if (unlikely(usize == 0
2081 || usize > SC_LARGE_MAXCLASS)) {
2082 goto label_oom;
2083 }
2084 }

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