]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/alloc-pool.c
Remove old pool allocator.
[thirdparty/gcc.git] / gcc / alloc-pool.c
1 /* Functions to support a pool of allocatable objects.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dan@cgsoftware.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "alloc-pool.h"
25 #include "hash-table.h"
26 #include "hash-map.h"
27
28 ALLOC_POOL_ID_TYPE last_id;
29
30 /* Hashtable mapping alloc_pool names to descriptors. */
31 hash_map<const char *, alloc_pool_descriptor> *alloc_pool_hash;
32
33 struct alloc_pool_descriptor *
34 allocate_pool_descriptor (const char *name)
35 {
36 if (!alloc_pool_hash)
37 alloc_pool_hash = new hash_map<const char *, alloc_pool_descriptor> (10,
38 false,
39 false);
40
41 return &alloc_pool_hash->get_or_insert (name);
42 }
43
44 /* Output per-alloc_pool statistics. */
45
46 /* Used to accumulate statistics about alloc_pool sizes. */
47 struct pool_output_info
48 {
49 unsigned long total_created;
50 unsigned long total_allocated;
51 };
52
53 /* Called via hash_map.traverse. Output alloc_pool descriptor pointed out by
54 SLOT and update statistics. */
55 bool
56 print_alloc_pool_statistics (const char *const &name,
57 const alloc_pool_descriptor &d,
58 struct pool_output_info *i)
59 {
60 if (d.allocated)
61 {
62 fprintf (stderr,
63 "%-22s %6d %10lu %10lu(%10lu) %10lu(%10lu) %10lu(%10lu)\n",
64 name, d.elt_size, d.created, d.allocated,
65 d.allocated / d.elt_size, d.peak, d.peak / d.elt_size,
66 d.current, d.current / d.elt_size);
67 i->total_allocated += d.allocated;
68 i->total_created += d.created;
69 }
70 return 1;
71 }
72
73 /* Output per-alloc_pool memory usage statistics. */
74 void
75 dump_alloc_pool_statistics (void)
76 {
77 struct pool_output_info info;
78
79 if (! GATHER_STATISTICS)
80 return;
81
82 if (!alloc_pool_hash)
83 return;
84
85 fprintf (stderr, "\nAlloc-pool Kind Elt size Pools Allocated (elts) Peak (elts) Leak (elts)\n");
86 fprintf (stderr, "--------------------------------------------------------------------------------------------------------------\n");
87 info.total_created = 0;
88 info.total_allocated = 0;
89 alloc_pool_hash->traverse <struct pool_output_info *,
90 print_alloc_pool_statistics> (&info);
91 fprintf (stderr, "--------------------------------------------------------------------------------------------------------------\n");
92 fprintf (stderr, "%-22s %7lu %10lu\n",
93 "Total", info.total_created, info.total_allocated);
94 fprintf (stderr, "--------------------------------------------------------------------------------------------------------------\n");
95 }