LCOV - code coverage report
Current view: top level - gcc - memory-block.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 26 26
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 5 5
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Shared pool of memory blocks for pool allocators.
       2                 :             :    Copyright (C) 2015-2024 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "memory-block.h"
      24                 :             : #include "obstack.h"
      25                 :             : 
      26                 :             : /* Global singleton-like instance.  */
      27                 :             : memory_block_pool memory_block_pool::instance;
      28                 :             : 
      29                 :      685056 : memory_block_pool::memory_block_pool () : m_blocks (NULL) {}
      30                 :             : 
      31                 :             : /* Reduce free list to NUM blocks and return remaining to malloc.  */
      32                 :             : void
      33                 :   490562755 : memory_block_pool::reduce_free_list (int num)
      34                 :             : {
      35                 :   490562755 :   block_list **blocks = &m_blocks;
      36                 :             : 
      37                 :             :   /* First skip NUM blocks.  */
      38                 :             : 
      39                 :  3710002659 :   for (;num > 0 && *blocks; num--)
      40                 :  3219439904 :     blocks = &(*blocks)->m_next;
      41                 :             : 
      42                 :   490562755 :   if (!*blocks)
      43                 :             :     return;
      44                 :             : 
      45                 :             :   /* And free the remainder of them.  */
      46                 :             : 
      47                 :     2229263 :   block_list *to_free = *blocks;
      48                 :     2229263 :   *blocks = NULL;
      49                 :             : 
      50                 :     9366878 :   while (to_free)
      51                 :             :     {
      52                 :     7137615 :       block_list *next = to_free->m_next;
      53                 :     7137615 :       XDELETEVEC (to_free);
      54                 :     7137615 :       to_free = next;
      55                 :             :     }
      56                 :             : }
      57                 :             : 
      58                 :             : /* Allocate a chunk for obstack.  Use the pool if requested chunk size matches
      59                 :             :    the size of blocks in the pool.  */
      60                 :             : void *
      61                 :   593299269 : mempool_obstack_chunk_alloc (size_t size)
      62                 :             : {
      63                 :   593299269 :   if (size == memory_block_pool::block_size)
      64                 :   338902833 :     return memory_block_pool::allocate ();
      65                 :             :   else
      66                 :   254396436 :     return XNEWVEC (char, size);
      67                 :             : }
      68                 :             : 
      69                 :             : /* Free previously allocated obstack chunk.  */
      70                 :             : void
      71                 :   590132248 : mempool_obstack_chunk_free (void *chunk)
      72                 :             : {
      73                 :   590132248 :   size_t size = (reinterpret_cast<_obstack_chunk *> (chunk)->limit
      74                 :   590132248 :                  - reinterpret_cast<char *> (chunk));
      75                 :   590132248 :   if (size == memory_block_pool::block_size)
      76                 :   337820796 :     memory_block_pool::release (chunk);
      77                 :             :   else
      78                 :   252311452 :     XDELETEVEC (chunk);
      79                 :   590132248 : }
      80                 :             : 
      81                 :             : /* Return allocated memory back to malloc (and to system).  */
      82                 :             : void
      83                 :   490562755 : memory_block_pool::trim (int num)
      84                 :             : {
      85                 :   490562755 :   instance.reduce_free_list (num);
      86                 :   490562755 : }
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.