@@ -1923,6 +1923,7 @@ imallocx_flags_decode_hard(tsd_t *tsd, size_t size, int flags, size_t *usize,
1923
1923
* alignment = MALLOCX_ALIGN_GET_SPECIFIED (flags );
1924
1924
* usize = sa2u (size , * alignment );
1925
1925
}
1926
+ assert (* usize != 0 );
1926
1927
* zero = MALLOCX_ZERO_GET (flags );
1927
1928
if ((flags & MALLOCX_TCACHE_MASK ) != 0 ) {
1928
1929
if ((flags & MALLOCX_TCACHE_MASK ) == MALLOCX_TCACHE_NONE )
@@ -1965,41 +1966,29 @@ imallocx_flags(tsd_t *tsd, size_t usize, size_t alignment, bool zero,
1965
1966
tcache_t * tcache , arena_t * arena )
1966
1967
{
1967
1968
1968
- if (alignment != 0 )
1969
+ if (unlikely ( alignment != 0 ) )
1969
1970
return (ipalloct (tsd , usize , alignment , zero , tcache , arena ));
1970
- if (zero )
1971
+ if (unlikely ( zero ) )
1971
1972
return (icalloct (tsd , usize , tcache , arena ));
1972
1973
return (imalloct (tsd , usize , tcache , arena ));
1973
1974
}
1974
1975
1975
- JEMALLOC_ALWAYS_INLINE_C void *
1976
- imallocx_maybe_flags (tsd_t * tsd , size_t size , int flags , size_t usize ,
1977
- size_t alignment , bool zero , tcache_t * tcache , arena_t * arena )
1978
- {
1979
-
1980
- if (likely (flags == 0 ))
1981
- return (imalloc (tsd , size ));
1982
- return (imallocx_flags (tsd , usize , alignment , zero , tcache , arena ));
1983
- }
1984
-
1985
1976
static void *
1986
- imallocx_prof_sample (tsd_t * tsd , size_t size , int flags , size_t usize ,
1987
- size_t alignment , bool zero , tcache_t * tcache , arena_t * arena )
1977
+ imallocx_prof_sample (tsd_t * tsd , size_t usize , size_t alignment , bool zero ,
1978
+ tcache_t * tcache , arena_t * arena )
1988
1979
{
1989
1980
void * p ;
1990
1981
1991
1982
if (usize <= SMALL_MAXCLASS ) {
1992
1983
assert (((alignment == 0 ) ? s2u (LARGE_MINCLASS ) :
1993
1984
sa2u (LARGE_MINCLASS , alignment )) == LARGE_MINCLASS );
1994
- p = imallocx_maybe_flags (tsd , LARGE_MINCLASS , flags ,
1995
- LARGE_MINCLASS , alignment , zero , tcache , arena );
1985
+ p = imallocx_flags (tsd , LARGE_MINCLASS , alignment , zero , tcache ,
1986
+ arena );
1996
1987
if (p == NULL )
1997
1988
return (NULL );
1998
1989
arena_prof_promoted (p , usize );
1999
- } else {
2000
- p = imallocx_maybe_flags (tsd , size , flags , usize , alignment ,
2001
- zero , tcache , arena );
2002
- }
1990
+ } else
1991
+ p = imallocx_flags (tsd , usize , alignment , zero , tcache , arena );
2003
1992
2004
1993
return (p );
2005
1994
}
@@ -2018,12 +2007,11 @@ imallocx_prof(tsd_t *tsd, size_t size, int flags, size_t *usize)
2018
2007
& zero , & tcache , & arena )))
2019
2008
return (NULL );
2020
2009
tctx = prof_alloc_prep (tsd , * usize , prof_active_get_unlocked (), true);
2021
- if (likely ((uintptr_t )tctx == (uintptr_t )1U )) {
2022
- p = imallocx_maybe_flags (tsd , size , flags , * usize , alignment ,
2023
- zero , tcache , arena );
2024
- } else if ((uintptr_t )tctx > (uintptr_t )1U ) {
2025
- p = imallocx_prof_sample (tsd , size , flags , * usize , alignment ,
2026
- zero , tcache , arena );
2010
+ if (likely ((uintptr_t )tctx == (uintptr_t )1U ))
2011
+ p = imallocx_flags (tsd , * usize , alignment , zero , tcache , arena );
2012
+ else if ((uintptr_t )tctx > (uintptr_t )1U ) {
2013
+ p = imallocx_prof_sample (tsd , * usize , alignment , zero , tcache ,
2014
+ arena );
2027
2015
} else
2028
2016
p = NULL ;
2029
2017
if (unlikely (p == NULL )) {
@@ -2098,8 +2086,8 @@ je_mallocx(size_t size, int flags)
2098
2086
}
2099
2087
2100
2088
static void *
2101
- irallocx_prof_sample (tsd_t * tsd , void * old_ptr , size_t old_usize , size_t size ,
2102
- size_t alignment , size_t usize , bool zero , tcache_t * tcache , arena_t * arena ,
2089
+ irallocx_prof_sample (tsd_t * tsd , void * old_ptr , size_t old_usize ,
2090
+ size_t usize , size_t alignment , bool zero , tcache_t * tcache , arena_t * arena ,
2103
2091
prof_tctx_t * tctx )
2104
2092
{
2105
2093
void * p ;
@@ -2113,7 +2101,7 @@ irallocx_prof_sample(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t size,
2113
2101
return (NULL );
2114
2102
arena_prof_promoted (p , usize );
2115
2103
} else {
2116
- p = iralloct (tsd , old_ptr , old_usize , size , alignment , zero ,
2104
+ p = iralloct (tsd , old_ptr , old_usize , usize , alignment , zero ,
2117
2105
tcache , arena );
2118
2106
}
2119
2107
@@ -2133,8 +2121,8 @@ irallocx_prof(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t size,
2133
2121
old_tctx = prof_tctx_get (old_ptr );
2134
2122
tctx = prof_alloc_prep (tsd , * usize , prof_active , true);
2135
2123
if (unlikely ((uintptr_t )tctx != (uintptr_t )1U )) {
2136
- p = irallocx_prof_sample (tsd , old_ptr , old_usize , size ,
2137
- alignment , * usize , zero , tcache , arena , tctx );
2124
+ p = irallocx_prof_sample (tsd , old_ptr , old_usize , * usize ,
2125
+ alignment , zero , tcache , arena , tctx );
2138
2126
} else {
2139
2127
p = iralloct (tsd , old_ptr , old_usize , size , alignment , zero ,
2140
2128
tcache , arena );
@@ -2251,26 +2239,13 @@ ixallocx_helper(void *ptr, size_t old_usize, size_t size, size_t extra,
2251
2239
2252
2240
static size_t
2253
2241
ixallocx_prof_sample (void * ptr , size_t old_usize , size_t size , size_t extra ,
2254
- size_t alignment , size_t usize_max , bool zero , prof_tctx_t * tctx )
2242
+ size_t alignment , bool zero , prof_tctx_t * tctx )
2255
2243
{
2256
2244
size_t usize ;
2257
2245
2258
2246
if (tctx == NULL )
2259
2247
return (old_usize );
2260
- /* Use minimum usize to determine whether promotion may happen. */
2261
- if (((alignment == 0 ) ? s2u (size ) : sa2u (size , alignment )) <=
2262
- SMALL_MAXCLASS ) {
2263
- if (ixalloc (ptr , old_usize , SMALL_MAXCLASS + 1 ,
2264
- (SMALL_MAXCLASS + 1 >= size + extra ) ? 0 : size + extra -
2265
- (SMALL_MAXCLASS + 1 ), alignment , zero ))
2266
- return (old_usize );
2267
- usize = isalloc (ptr , config_prof );
2268
- if (usize_max < LARGE_MINCLASS )
2269
- arena_prof_promoted (ptr , usize );
2270
- } else {
2271
- usize = ixallocx_helper (ptr , old_usize , size , extra , alignment ,
2272
- zero );
2273
- }
2248
+ usize = ixallocx_helper (ptr , old_usize , size , extra , alignment , zero );
2274
2249
2275
2250
return (usize );
2276
2251
}
@@ -2293,15 +2268,16 @@ ixallocx_prof(tsd_t *tsd, void *ptr, size_t old_usize, size_t size,
2293
2268
*/
2294
2269
usize_max = (alignment == 0 ) ? s2u (size + extra ) : sa2u (size + extra ,
2295
2270
alignment );
2271
+ assert (usize_max != 0 );
2296
2272
tctx = prof_alloc_prep (tsd , usize_max , prof_active , false);
2297
2273
if (unlikely ((uintptr_t )tctx != (uintptr_t )1U )) {
2298
2274
usize = ixallocx_prof_sample (ptr , old_usize , size , extra ,
2299
- alignment , usize_max , zero , tctx );
2275
+ alignment , zero , tctx );
2300
2276
} else {
2301
2277
usize = ixallocx_helper (ptr , old_usize , size , extra , alignment ,
2302
2278
zero );
2303
2279
}
2304
- if (unlikely ( usize == old_usize ) ) {
2280
+ if (usize == old_usize ) {
2305
2281
prof_alloc_rollback (tsd , tctx , false);
2306
2282
return (usize );
2307
2283
}
0 commit comments