|
Packit Service |
724aca |
#ifndef JEMALLOC_INTERNAL_TYPES_H
|
|
Packit Service |
724aca |
#define JEMALLOC_INTERNAL_TYPES_H
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
#include "jemalloc/internal/quantum.h"
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Page size index type. */
|
|
Packit Service |
724aca |
typedef unsigned pszind_t;
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Size class index type. */
|
|
Packit Service |
724aca |
typedef unsigned szind_t;
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Processor / core id type. */
|
|
Packit Service |
724aca |
typedef int malloc_cpuid_t;
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/*
|
|
Packit Service |
724aca |
* Flags bits:
|
|
Packit Service |
724aca |
*
|
|
Packit Service |
724aca |
* a: arena
|
|
Packit Service |
724aca |
* t: tcache
|
|
Packit Service |
724aca |
* 0: unused
|
|
Packit Service |
724aca |
* z: zero
|
|
Packit Service |
724aca |
* n: alignment
|
|
Packit Service |
724aca |
*
|
|
Packit Service |
724aca |
* aaaaaaaa aaaatttt tttttttt 0znnnnnn
|
|
Packit Service |
724aca |
*/
|
|
Packit Service |
724aca |
#define MALLOCX_ARENA_BITS 12
|
|
Packit Service |
724aca |
#define MALLOCX_TCACHE_BITS 12
|
|
Packit Service |
724aca |
#define MALLOCX_LG_ALIGN_BITS 6
|
|
Packit Service |
724aca |
#define MALLOCX_ARENA_SHIFT 20
|
|
Packit Service |
724aca |
#define MALLOCX_TCACHE_SHIFT 8
|
|
Packit Service |
724aca |
#define MALLOCX_ARENA_MASK \
|
|
Packit Service |
724aca |
(((1 << MALLOCX_ARENA_BITS) - 1) << MALLOCX_ARENA_SHIFT)
|
|
Packit Service |
724aca |
/* NB: Arena index bias decreases the maximum number of arenas by 1. */
|
|
Packit Service |
724aca |
#define MALLOCX_ARENA_LIMIT ((1 << MALLOCX_ARENA_BITS) - 1)
|
|
Packit Service |
724aca |
#define MALLOCX_TCACHE_MASK \
|
|
Packit Service |
724aca |
(((1 << MALLOCX_TCACHE_BITS) - 1) << MALLOCX_TCACHE_SHIFT)
|
|
Packit Service |
724aca |
#define MALLOCX_TCACHE_MAX ((1 << MALLOCX_TCACHE_BITS) - 3)
|
|
Packit Service |
724aca |
#define MALLOCX_LG_ALIGN_MASK ((1 << MALLOCX_LG_ALIGN_BITS) - 1)
|
|
Packit Service |
724aca |
/* Use MALLOCX_ALIGN_GET() if alignment may not be specified in flags. */
|
|
Packit Service |
724aca |
#define MALLOCX_ALIGN_GET_SPECIFIED(flags) \
|
|
Packit Service |
724aca |
(ZU(1) << (flags & MALLOCX_LG_ALIGN_MASK))
|
|
Packit Service |
724aca |
#define MALLOCX_ALIGN_GET(flags) \
|
|
Packit Service |
724aca |
(MALLOCX_ALIGN_GET_SPECIFIED(flags) & (SIZE_T_MAX-1))
|
|
Packit Service |
724aca |
#define MALLOCX_ZERO_GET(flags) \
|
|
Packit Service |
724aca |
((bool)(flags & MALLOCX_ZERO))
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
#define MALLOCX_TCACHE_GET(flags) \
|
|
Packit Service |
724aca |
(((unsigned)((flags & MALLOCX_TCACHE_MASK) >> MALLOCX_TCACHE_SHIFT)) - 2)
|
|
Packit Service |
724aca |
#define MALLOCX_ARENA_GET(flags) \
|
|
Packit Service |
724aca |
(((unsigned)(((unsigned)flags) >> MALLOCX_ARENA_SHIFT)) - 1)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Smallest size class to support. */
|
|
Packit Service |
724aca |
#define TINY_MIN (1U << LG_TINY_MIN)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
#define LONG ((size_t)(1U << LG_SIZEOF_LONG))
|
|
Packit Service |
724aca |
#define LONG_MASK (LONG - 1)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the smallest long multiple that is >= a. */
|
|
Packit Service |
724aca |
#define LONG_CEILING(a) \
|
|
Packit Service |
724aca |
(((a) + LONG_MASK) & ~LONG_MASK)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
#define SIZEOF_PTR (1U << LG_SIZEOF_PTR)
|
|
Packit Service |
724aca |
#define PTR_MASK (SIZEOF_PTR - 1)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the smallest (void *) multiple that is >= a. */
|
|
Packit Service |
724aca |
#define PTR_CEILING(a) \
|
|
Packit Service |
724aca |
(((a) + PTR_MASK) & ~PTR_MASK)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/*
|
|
Packit Service |
724aca |
* Maximum size of L1 cache line. This is used to avoid cache line aliasing.
|
|
Packit Service |
724aca |
* In addition, this controls the spacing of cacheline-spaced size classes.
|
|
Packit Service |
724aca |
*
|
|
Packit Service |
724aca |
* CACHELINE cannot be based on LG_CACHELINE because __declspec(align()) can
|
|
Packit Service |
724aca |
* only handle raw constants.
|
|
Packit Service |
724aca |
*/
|
|
Packit Service |
724aca |
#define LG_CACHELINE 6
|
|
Packit Service |
724aca |
#define CACHELINE 64
|
|
Packit Service |
724aca |
#define CACHELINE_MASK (CACHELINE - 1)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the smallest cacheline multiple that is >= s. */
|
|
Packit Service |
724aca |
#define CACHELINE_CEILING(s) \
|
|
Packit Service |
724aca |
(((s) + CACHELINE_MASK) & ~CACHELINE_MASK)
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the nearest aligned address at or below a. */
|
|
Packit Service |
724aca |
#define ALIGNMENT_ADDR2BASE(a, alignment) \
|
|
Packit Service |
724aca |
((void *)((uintptr_t)(a) & ((~(alignment)) + 1)))
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the offset between a and the nearest aligned address at or below a. */
|
|
Packit Service |
724aca |
#define ALIGNMENT_ADDR2OFFSET(a, alignment) \
|
|
Packit Service |
724aca |
((size_t)((uintptr_t)(a) & (alignment - 1)))
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Return the smallest alignment multiple that is >= s. */
|
|
Packit Service |
724aca |
#define ALIGNMENT_CEILING(s, alignment) \
|
|
Packit Service |
724aca |
(((s) + (alignment - 1)) & ((~(alignment)) + 1))
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
/* Declare a variable-length array. */
|
|
Packit Service |
724aca |
#if __STDC_VERSION__ < 199901L
|
|
Packit Service |
724aca |
# ifdef _MSC_VER
|
|
Packit Service |
724aca |
# include <malloc.h>
|
|
Packit Service |
724aca |
# define alloca _alloca
|
|
Packit Service |
724aca |
# else
|
|
Packit Service |
724aca |
# ifdef JEMALLOC_HAS_ALLOCA_H
|
|
Packit Service |
724aca |
# include <alloca.h>
|
|
Packit Service |
724aca |
# else
|
|
Packit Service |
724aca |
# include <stdlib.h>
|
|
Packit Service |
724aca |
# endif
|
|
Packit Service |
724aca |
# endif
|
|
Packit Service |
724aca |
# define VARIABLE_ARRAY(type, name, count) \
|
|
Packit Service |
724aca |
type *name = alloca(sizeof(type) * (count))
|
|
Packit Service |
724aca |
#else
|
|
Packit Service |
724aca |
# define VARIABLE_ARRAY(type, name, count) type name[(count)]
|
|
Packit Service |
724aca |
#endif
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
#endif /* JEMALLOC_INTERNAL_TYPES_H */
|