44 size_t instances,
size_t element_size,
45 const char *pool_name)
46 :
mem_usage (allocated, times, peak, instances),
65 char *location_string = loc->
to_string ();
67 fprintf (stderr,
"%-32s%-48s " PRsa(5)
PRsa(9)
":%5.1f%%"
78 free (location_string);
85 fprintf (stderr,
"%-32s%-48s %6s%11s%16s%17s%12s\n",
"Pool name", name,
86 "Pools",
"Leak",
"Peak",
"Times",
"Elt size");
93 fprintf (stderr,
"%s" PRsa(82)
PRsa(10)
"\n",
"Total",
118template <
size_t BlockSize>
119class custom_block_allocator
122 static const size_t block_size = BlockSize;
125 allocate () ATTRIBUTE_MALLOC
127 return XNEWVEC (
char, BlockSize);
131 release (
void *block)
140template <
typename TBlockAllocator>
184 get_instance (
void *data_ptr)
203 return (((x+7) >> 3) << 3);
239template <
typename TBlockAllocator>
243 m_name (name), m_id (0), m_elts_per_block (0), m_returned_free_list (
NULL),
244 m_virgin_free_list (
NULL), m_virgin_elts_remaining (0), m_elts_allocated (0),
245 m_elts_free (0), m_blocks_allocated (0), m_block_list (
NULL), m_elt_size (0),
246 m_size (size), m_initialized (
false),
251template <
typename TBlockAllocator>
256 m_initialized =
true;
258 size_t size = m_size;
268 size = align_eight (size);
275 if (GATHER_STATISTICS)
287 m_elts_per_block = (TBlockAllocator::block_size - header_size) / size;
300template <
typename TBlockAllocator>
310 for (block = m_block_list; block !=
NULL; block = next_block)
312 next_block = block->
next;
313 TBlockAllocator::release (block);
319 (
this, (m_elts_allocated - m_elts_free) * m_elt_size);
322 m_returned_free_list =
NULL;
323 m_virgin_free_list =
NULL;
324 m_virgin_elts_remaining = 0;
325 m_elts_allocated = 0;
327 m_blocks_allocated = 0;
331template <
typename TBlockAllocator>
335 if (m_elts_free == m_elts_allocated)
339template <
typename TBlockAllocator>
340inline base_pool_allocator <TBlockAllocator>::~base_pool_allocator ()
346template <
typename TBlockAllocator>
354#ifdef ENABLE_VALGRIND_ANNOTATIONS
358 if (GATHER_STATISTICS)
363#ifdef ENABLE_VALGRIND_ANNOTATIONS
368 if (!m_returned_free_list)
371 if (!m_virgin_elts_remaining)
376 block =
reinterpret_cast<char *
> (TBlockAllocator::allocate ());
381 block_header->
next = m_block_list;
382 m_block_list = block_header;
385 m_virgin_free_list = block;
386 m_virgin_elts_remaining = m_elts_per_block;
390 m_elts_allocated += m_elts_per_block;
391 m_elts_free += m_elts_per_block;
392 m_blocks_allocated += 1;
397 block = m_virgin_free_list;
406 m_returned_free_list = header;
407 m_virgin_free_list += m_elt_size;
408 m_virgin_elts_remaining--;
413 header = m_returned_free_list;
415 m_returned_free_list = header->
next;
420 allocation_object::get_instance (header)->id = m_id;
424 return (
void *)(header);
428template <
typename TBlockAllocator>
439 && m_elts_free < m_elts_allocated);
442 gcc_assert (m_id == allocation_object::get_instance (
object)->
id);
445 memset (
object, 0xaf, size);
450 allocation_object::get_instance (
object)->id = 0;
454 header->
next = m_returned_free_list;
455 m_returned_free_list = header;
459 if (GATHER_STATISTICS)
467template <
typename TBlockAllocator>
471 return m_elts_allocated - m_elts_free;
569 return a.allocate_raw ();
mem_alloc_description< pool_usage > pool_allocator_usage
Definition alloc-pool.cc:27
ALLOC_POOL_ID_TYPE last_id
Definition alloc-pool.cc:26
base_pool_allocator< memory_block_pool > pool_allocator
Definition alloc-pool.h:477
hash_map< const char *, alloc_pool_descriptor > * alloc_pool_hash
void dump_alloc_pool_statistics(void)
Definition alloc-pool.cc:32
bool after_memory_report
Definition alloc-pool.cc:28
unsigned long ALLOC_POOL_ID_TYPE
Definition alloc-pool.h:31
Definition alloc-pool.h:142
size_t m_elts_free
Definition alloc-pool.h:224
const char * m_name
Definition alloc-pool.h:206
~base_pool_allocator()
Definition alloc-pool.h:340
char * m_virgin_free_list
Definition alloc-pool.h:216
void release_if_empty()
Definition alloc-pool.h:333
size_t m_virgin_elts_remaining
Definition alloc-pool.h:220
ALLOC_POOL_ID_TYPE m_id
Definition alloc-pool.h:207
allocation_pool_list * m_block_list
Definition alloc-pool.h:228
allocation_pool_list * m_returned_free_list
Definition alloc-pool.h:212
void initialize()
Definition alloc-pool.h:253
size_t m_size
Definition alloc-pool.h:232
base_pool_allocator(const char *name, size_t size CXX_MEM_STAT_INFO)
Definition alloc-pool.h:241
size_t m_elts_per_block
Definition alloc-pool.h:208
size_t num_elts_current()
Definition alloc-pool.h:469
size_t m_blocks_allocated
Definition alloc-pool.h:226
void remove(void *object)
Definition alloc-pool.h:430
static size_t align_eight(size_t x)
Definition alloc-pool.h:201
size_t m_elt_size
Definition alloc-pool.h:230
size_t m_elts_allocated
Definition alloc-pool.h:222
void release()
Definition alloc-pool.h:302
mem_location m_location
Definition alloc-pool.h:236
void * allocate() ATTRIBUTE_MALLOC
Definition alloc-pool.h:348
bool m_initialized
Definition alloc-pool.h:234
Definition genoutput.cc:150
Definition mem-stats.h:278
Definition mem-stats.h:35
char * to_string()
Definition mem-stats.h:93
Definition mem-stats.h:128
size_t m_allocated
Definition mem-stats.h:253
size_t m_peak
Definition mem-stats.h:257
size_t m_instances
Definition mem-stats.h:259
size_t m_times
Definition mem-stats.h:255
static float get_percent(size_t nominator, size_t denominator)
Definition mem-stats.h:230
Definition alloc-pool.h:482
pool_allocator m_allocator
Definition alloc-pool.h:540
void * allocate_raw() ATTRIBUTE_MALLOC
Definition alloc-pool.h:513
void remove_raw(void *object)
Definition alloc-pool.h:528
void remove(T *object)
Definition alloc-pool.h:519
object_allocator(const char *name CXX_MEM_STAT_INFO)
Definition alloc-pool.h:485
void release()
Definition alloc-pool.h:489
void release_if_empty()
Definition alloc-pool.h:494
size_t num_elts_current()
Definition alloc-pool.h:534
T * allocate() ATTRIBUTE_MALLOC
Definition alloc-pool.h:503
Definition alloc-pool.h:38
const char * m_pool_name
Definition alloc-pool.h:100
pool_usage()
Definition alloc-pool.h:41
pool_usage operator+(const pool_usage &second)
Definition alloc-pool.h:52
void dump(mem_location *loc, const mem_usage &total) const
Definition alloc-pool.h:63
pool_usage(size_t allocated, size_t times, size_t peak, size_t instances, size_t element_size, const char *pool_name)
Definition alloc-pool.h:43
size_t m_element_size
Definition alloc-pool.h:98
static void dump_header(const char *name)
Definition alloc-pool.h:83
void dump_footer()
Definition alloc-pool.h:91
static struct token T
Definition gengtype-parse.cc:45
#define PRIu64
Definition hwint.h:93
@ ALLOC_POOL_ORIGIN
Definition mem-stats-traits.h:33
Ca & a
Definition poly-int.h:770
#define PASS_MEM_STAT
Definition statistics.h:54
#define MEM_STAT_DECL
Definition statistics.h:52
#define CXX_MEM_STAT_INFO
Definition statistics.h:58
Definition alloc-pool.h:550
unsigned long current
Definition alloc-pool.h:556
unsigned long allocated
Definition alloc-pool.h:554
int elt_size
Definition alloc-pool.h:560
unsigned long created
Definition alloc-pool.h:552
unsigned long peak
Definition alloc-pool.h:558
Definition alloc-pool.h:163
static void * get_data(void *instance_ptr)
Definition alloc-pool.h:193
union base_pool_allocator::allocation_object::@1 u
int64_t align_i
Definition alloc-pool.h:179
char data[1]
Definition alloc-pool.h:172
char * align_p
Definition alloc-pool.h:178
Definition alloc-pool.h:155
allocation_pool_list * next
Definition alloc-pool.h:156
Definition collect2.cc:168
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:814
#define offsetof(TYPE, MEMBER)
Definition system.h:745
#define false
Definition system.h:888
#define VALGRIND_DISCARD(x)
Definition system.h:1215
#define SIZE_AMOUNT(size)
Definition system.h:1283
#define PRsa(n)
Definition system.h:1287
#define gcc_checking_assert(EXPR)
Definition system.h:821