From 00e6775a5faa43702e96e315e7a1c22297983f2a Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 5 Nov 2018 14:35:56 +0100 Subject: Fix vector memory statistics. 2018-11-05 Martin Liska * mem-stats.h (mem_alloc_description::release_instance_overhead): Return T *. * vec.c (struct vec_usage): Register m_element_size. (vec_prefix::register_overhead): New arguments: elements and element_size. (vec_prefix::release_overhead): Subtract elements. * vec.h (struct vec_prefix): Change signature. (va_heap::reserve): Pass proper arguments. (va_heap::release): Likewise. From-SVN: r265799 --- gcc/vec.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'gcc/vec.h') diff --git a/gcc/vec.h b/gcc/vec.h index 0af5187782e..f8c039754d2 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -195,7 +195,7 @@ struct vec_prefix /* Memory allocation support routines in vec.c. */ void register_overhead (void *, size_t, size_t CXX_MEM_STAT_INFO); - void release_overhead (void *, size_t, bool CXX_MEM_STAT_INFO); + void release_overhead (void *, size_t, size_t, bool CXX_MEM_STAT_INFO); static unsigned calculate_allocation (vec_prefix *, unsigned, bool); static unsigned calculate_allocation_1 (unsigned, unsigned); @@ -276,12 +276,14 @@ inline void va_heap::reserve (vec *&v, unsigned reserve, bool exact MEM_STAT_DECL) { + size_t elt_size = sizeof (T); unsigned alloc = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact); gcc_checking_assert (alloc); if (GATHER_STATISTICS && v) - v->m_vecpfx.release_overhead (v, v->allocated (), false); + v->m_vecpfx.release_overhead (v, elt_size * v->allocated (), + v->allocated (), false); size_t size = vec::embedded_size (alloc); unsigned nelem = v ? v->length () : 0; @@ -289,7 +291,7 @@ va_heap::reserve (vec *&v, unsigned reserve, bool exact v->embedded_init (alloc, nelem); if (GATHER_STATISTICS) - v->m_vecpfx.register_overhead (v, alloc, nelem PASS_MEM_STAT); + v->m_vecpfx.register_overhead (v, alloc, elt_size PASS_MEM_STAT); } @@ -299,11 +301,13 @@ template void va_heap::release (vec *&v) { + size_t elt_size = sizeof (T); if (v == NULL) return; if (GATHER_STATISTICS) - v->m_vecpfx.release_overhead (v, v->allocated (), true); + v->m_vecpfx.release_overhead (v, elt_size * v->allocated (), + v->allocated (), true); ::free (v); v = NULL; } -- cgit v1.2.3