|
GCC Middle and Back End API Reference
|
#include "config.h"#include "system.h"#include "coretypes.h"#include "backend.h"#include "alias.h"#include "tree.h"#include "rtl.h"#include "memmodel.h"#include "tm_p.h"#include "diagnostic-core.h"#include "flags.h"#include "ggc-internal.h"#include "timevar.h"#include "cgraph.h"#include "cfgloop.h"#include "plugin.h"
Data Structures | |
| struct | max_alignment |
| struct | page_entry |
| struct | page_group |
| class | finalizer |
| class | vec_finalizer |
| struct | free_list |
| struct | ggc_globals |
| struct | ggc_pch_ondisk |
| struct | ggc_pch_data |
| struct | [struct].inverse_table |
Macros | |
| #define | USING_MALLOC_PAGE_GROUPS |
| #define | GGC_DEBUG_LEVEL (0) |
| #define | PAGE_L1_BITS (8) |
| #define | PAGE_L2_BITS (32 - PAGE_L1_BITS - G.lg_pagesize) |
| #define | PAGE_L1_SIZE ((uintptr_t) 1 << PAGE_L1_BITS) |
| #define | PAGE_L2_SIZE ((uintptr_t) 1 << PAGE_L2_BITS) |
| #define | LOOKUP_L1(p) |
| #define | LOOKUP_L2(p) |
| #define | OBJECTS_PER_PAGE(ORDER) |
| #define | OBJECTS_IN_PAGE(P) |
| #define | OBJECT_SIZE(ORDER) |
| #define | DIV_MULT(ORDER) |
| #define | DIV_SHIFT(ORDER) |
| #define | OFFSET_TO_BIT(OFFSET, ORDER) |
| #define | MAX_ALIGNMENT (offsetof (struct max_alignment, u)) |
| #define | NUM_EXTRA_ORDERS ARRAY_SIZE (extra_order_size_table) |
| #define | RTL_SIZE(NSLOTS) |
| #define | TREE_EXP_SIZE(OPS) |
| #define | NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS) |
| #define | ROUND_UP_VALUE(x, f) |
| #define | PAGE_ALIGN(x) |
| #define | BITMAP_SIZE(Num_objects) |
| #define | GGC_QUIRE_SIZE 16 |
| #define | INITIAL_PTE_COUNT 128 |
| #define | prefetch(X) |
| #define | save_in_use_p_i(__i) |
| #define | save_in_use_p(__p) |
| #define | NUM_SIZE_LOOKUP 512 |
| #define | poison_pages() |
| #define | validate_free_objects() |
Typedefs | |
| typedef page_entry ** | page_table[PAGE_L1_SIZE] |
Functions | |
| static page_entry * | lookup_page_table_entry (const void *) |
| static void | set_page_table_entry (void *, page_entry *) |
| static size_t | page_group_index (char *, char *) |
| static void | set_page_group_in_use (page_group *, char *) |
| static void | clear_page_group_in_use (page_group *, char *) |
| static struct page_entry * | alloc_page (unsigned) |
| static void | free_page (struct page_entry *) |
| static void | clear_marks (void) |
| static void | sweep_pages (void) |
| static void | ggc_recalculate_in_use_p (page_entry *) |
| static void | compute_inverse (unsigned) |
| static void | adjust_depth (void) |
| static void | move_ptes_to_front (int, int) |
| void | debug_print_page_list (int) |
| static void | push_depth (unsigned int) |
| static void | push_by_depth (page_entry *, unsigned long *) |
| static page_entry * | safe_lookup_page_table_entry (const void *p) |
| static struct free_list * | find_free_list (size_t entry_size) |
| static struct free_list * | find_free_list_order (unsigned order, size_t bytes) |
| static void | do_release_pages (struct free_list *free_list, size_t &n1, size_t &n2) |
| static void | release_pages () |
| static void | ggc_round_alloc_size_1 (size_t requested_size, size_t *size_order, size_t *alloced_size) |
| size_t | ggc_round_alloc_size (size_t requested_size) |
| static void | add_finalizer (void *result, void(*f)(void *), size_t s, size_t n) |
| void * | ggc_internal_alloc (size_t size, void(*f)(void *), size_t s, size_t n MEM_STAT_DECL) |
| void * | ggc_internal_alloc_no_dtor (size_t size, void(*f)(void *), size_t s, size_t n MEM_STAT_DECL) |
| void | gt_ggc_m_S (const void *p) |
| void | gt_ggc_mx (const char *&x) |
| void | gt_ggc_mx (char *&x) |
| void | gt_ggc_mx (unsigned char *&x) |
| void | gt_ggc_mx (unsigned char &x) |
| bool | ggc_set_mark (const void *p) |
| bool | ggc_marked_p (const void *p) |
| size_t | ggc_get_size (const void *p) |
| void | ggc_free (void *p) |
| void | init_ggc (void) |
| static void | ggc_handle_finalizers () |
| void | ggc_collect (enum ggc_collect mode) |
| void | ggc_trim () |
| void | ggc_grow (void) |
| void | ggc_print_statistics (void) |
| struct ggc_pch_data * | init_ggc_pch (void) |
| void | ggc_pch_count_object (struct ggc_pch_data *d, void *x, size_t size) |
| size_t | ggc_pch_total_size (struct ggc_pch_data *d) |
| void | ggc_pch_this_base (struct ggc_pch_data *d, void *base) |
| char * | ggc_pch_alloc_object (struct ggc_pch_data *d, void *x, size_t size) |
| void | ggc_pch_prepare_write (struct ggc_pch_data *d, FILE *f) |
| void | ggc_pch_write_object (struct ggc_pch_data *d, FILE *f, void *x, void *newx, size_t size) |
| void | ggc_pch_finish (struct ggc_pch_data *d, FILE *f) |
| void | ggc_pch_read (FILE *f, void *addr) |
Variables | |
| static const size_t | extra_order_size_table [] |
| static unsigned | objects_per_page_table [NUM_ORDERS] |
| static size_t | object_size_table [NUM_ORDERS] |
| static struct | inverse_table [NUM_ORDERS] |
| constexpr int | num_free_list = 8 |
| static struct ggc_globals | G |
| static bool | in_gc = false |
| static struct free_list * | cache_free_list [NUM_ORDERS] |
| static unsigned char | size_lookup [NUM_SIZE_LOOKUP] |
| #define BITMAP_SIZE | ( | Num_objects | ) |
The size in bytes required to maintain a bitmap for the objects on a page-entry.
Referenced by alloc_page(), clear_marks(), ggc_pch_read(), ggc_print_statistics(), and ggc_recalculate_in_use_p().
| #define DIV_MULT | ( | ORDER | ) |
For speed, we avoid doing a general integer divide to locate the offset in the allocation bitmap, by precalculating numbers M, S such that (O * M) >> S == O / Z (modulo 2^32), for any offset O within the page which is evenly divisible by the object size Z.
Referenced by compute_inverse().
| #define DIV_SHIFT | ( | ORDER | ) |
Referenced by compute_inverse().
| #define GGC_DEBUG_LEVEL (0) |
Strategy: This garbage-collecting allocator allocates objects on one of a set of pages. Each page can allocate objects of a single size only; available sizes are powers of two starting at four bytes. The size of an allocation request is rounded up to the next power of two (`order'), and satisfied from the appropriate page. Each page is recorded in a page-entry, which also maintains an in-use bitmap of object positions on the page. This allows the allocation state of a particular object to be flipped without touching the page itself. Each page-entry also has a context depth, which is used to track pushing and popping of allocation contexts. Only objects allocated in the current (highest-numbered) context may be collected. Page entries are arranged in an array of singly-linked lists. The array is indexed by the allocation size, in bits, of the pages on it; i.e. all pages on a list allocate objects of the same size. Pages are ordered on the list such that all non-full pages precede all full pages, with non-full pages arranged in order of decreasing context depth. Empty pages (of all orders) are kept on a single page cache list, and are considered first when new pages are required; they are deallocated at the start of the next collection if they haven't been recycled by then.
Define GGC_DEBUG_LEVEL to print debugging information. 0: No debugging output. 1: GC statistics only. 2: Page-entry allocations/deallocations as well. 3: Object allocations as well. 4: Object marks as well.
Referenced by alloc_page(), free_page(), ggc_collect(), ggc_free(), ggc_internal_alloc(), ggc_set_mark(), and gt_ggc_m_S().
| #define GGC_QUIRE_SIZE 16 |
Allocate pages in chunks of this size, to throttle calls to memory allocation routines. The first page is used, the rest go onto the free list. This cannot be larger than HOST_BITS_PER_INT for the in_use bitmask for page_group. Hosts that need a different value can override this by defining GGC_QUIRE_SIZE explicitly.
Referenced by alloc_page(), and do_release_pages().
| #define INITIAL_PTE_COUNT 128 |
Initial guess as to how many page table entries we might need.
Referenced by init_ggc().
| #define LOOKUP_L1 | ( | p | ) |
Referenced by lookup_page_table_entry(), safe_lookup_page_table_entry(), and set_page_table_entry().
| #define LOOKUP_L2 | ( | p | ) |
Referenced by lookup_page_table_entry(), safe_lookup_page_table_entry(), and set_page_table_entry().
| #define MAX_ALIGNMENT (offsetof (struct max_alignment, u)) |
The biggest alignment required.
Referenced by init_ggc().
| #define NUM_EXTRA_ORDERS ARRAY_SIZE (extra_order_size_table) |
The number of extra orders, not corresponding to power-of-two sized objects.
| #define NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS) |
The total number of orders.
Referenced by clear_marks(), ggc_pch_read(), ggc_pch_this_base(), ggc_pch_total_size(), ggc_print_statistics(), init_ggc(), and sweep_pages().
| #define NUM_SIZE_LOOKUP 512 |
This table provides a fast way to determine ceil(log_2(size)) for allocation requests. The minimum allocation size is eight bytes.
Referenced by ggc_pch_alloc_object(), ggc_pch_count_object(), ggc_pch_write_object(), ggc_round_alloc_size_1(), and init_ggc().
| #define OBJECT_SIZE | ( | ORDER | ) |
The size of an object on a page of the indicated ORDER.
Referenced by alloc_page(), compute_inverse(), ggc_free(), ggc_get_size(), ggc_internal_alloc(), ggc_pch_alloc_object(), ggc_pch_count_object(), ggc_pch_read(), ggc_pch_this_base(), ggc_pch_total_size(), ggc_pch_write_object(), ggc_print_statistics(), ggc_round_alloc_size_1(), init_ggc(), and sweep_pages().
| #define OBJECTS_IN_PAGE | ( | P | ) |
The number of objects in P.
Referenced by clear_marks(), ggc_print_statistics(), ggc_recalculate_in_use_p(), and sweep_pages().
| #define OBJECTS_PER_PAGE | ( | ORDER | ) |
The number of objects per allocation page, for objects on a page of the indicated ORDER.
Referenced by alloc_page().
| #define OFFSET_TO_BIT | ( | OFFSET, | |
| ORDER ) |
Referenced by ggc_free(), ggc_marked_p(), ggc_set_mark(), and gt_ggc_m_S().
| #define PAGE_ALIGN | ( | x | ) |
Round X to next multiple of the page size
Referenced by alloc_page(), ggc_pch_read(), ggc_pch_this_base(), and ggc_pch_total_size().
| #define PAGE_L1_BITS (8) |
A two-level tree is used to look up the page-entry for a given
pointer. Two chunks of the pointer's bits are extracted to index
the first and second levels of the tree, as follows:
HOST_PAGE_SIZE_BITS
32 | |
msb +----------------+----+------+------+ lsb
| | |
PAGE_L1_BITS |
| |
PAGE_L2_BITS
The bottommost HOST_PAGE_SIZE_BITS are ignored, since page-entry
pages are aligned on system page boundaries. The next most
significant PAGE_L2_BITS and PAGE_L1_BITS are the second and first
index values in the lookup table, respectively.
For 32-bit architectures and the settings below, there are no
leftover bits. For architectures with wider pointers, the lookup
tree points to a list of pages, which must be scanned to find the
correct one.
| #define PAGE_L1_SIZE ((uintptr_t) 1 << PAGE_L1_BITS) |
| #define PAGE_L2_BITS (32 - PAGE_L1_BITS - G.lg_pagesize) |
| #define PAGE_L2_SIZE ((uintptr_t) 1 << PAGE_L2_BITS) |
Referenced by set_page_table_entry().
| #define poison_pages | ( | ) |
Referenced by ggc_collect(), and ggc_pch_read().
| #define prefetch | ( | X | ) |
Referenced by issue_prefetch_ref(), and schedule_prefetches().
| #define ROUND_UP_VALUE | ( | x, | |
| f ) |
Compute the smallest nonnegative number which when added to X gives a multiple of F.
Referenced by ggc_pch_write_object().
| #define RTL_SIZE | ( | NSLOTS | ) |
| #define save_in_use_p | ( | __p | ) |
Referenced by clear_marks(), and ggc_recalculate_in_use_p().
| #define save_in_use_p_i | ( | __i | ) |
| #define TREE_EXP_SIZE | ( | OPS | ) |
| #define USING_MALLOC_PAGE_GROUPS |
"Bag-of-pages" garbage collector for the GNU compiler. Copyright (C) 1999-2026 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>.
Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a file open. Prefer either to valloc.
| #define validate_free_objects | ( | ) |
Referenced by ggc_collect(), and ggc_pch_read().
| typedef page_entry** page_table[PAGE_L1_SIZE] |
On 32-bit hosts, we use a two level page table, as pictured above.
|
static |
Push a finalizer onto the appropriate vec.
References add_finalizer(), ggc_globals::context_depth, ggc_globals::finalizers, G, NULL, and ggc_globals::vec_finalizers.
Referenced by add_finalizer(), and ggc_internal_alloc().
|
inlinestatic |
Adjust the size of G.depth so that no index greater than the one used by the top of the G.by_depth is used.
References adjust_depth(), ggc_globals::by_depth, ggc_globals::by_depth_in_use, page_entry::context_depth, ggc_globals::depth_in_use, and G.
Referenced by adjust_depth(), and free_page().
|
inlinestatic |
Allocate a new page for allocating objects of size 2^ORDER, and return an entry for it. The entry is not added to the appropriate page_table list.
References a, alloc_page(), page_group::alloc_size, page_group::allocation, BITMAP_SIZE, page_entry::bytes, ggc_globals::bytes_mapped, ggc_globals::context_depth, page_entry::context_depth, ggc_globals::context_depth_allocations, ggc_globals::debug_file, page_entry::discarded, find_free_list_order(), fmt_size_t, free(), page_entry::free_list, free_list::free_pages, G, gcc_assert, GGC_DEBUG_LEVEL, GGC_QUIRE_SIZE, page_entry::group, HOST_BITS_PER_LONG, HOST_SIZE_T_PRINT_UNSIGNED, i, page_group::in_use, page_entry::in_use_p, ggc_globals::lg_pagesize, page_entry::next, page_group::next, page_entry::next_bit_hint, NULL, page_entry::num_free_objects, OBJECT_SIZE, OBJECTS_PER_PAGE, page_entry::order, page_entry::page, PAGE_ALIGN, ggc_globals::page_groups, ggc_globals::pagesize, set_page_group_in_use(), and set_page_table_entry().
Referenced by alloc_page(), and ggc_internal_alloc().
|
static |
Unmark all objects.
References BITMAP_SIZE, clear_marks(), ggc_globals::context_depth, page_entry::context_depth, G, gcc_assert, HOST_BITS_PER_LONG, page_entry::in_use_p, page_entry::next, NULL, page_entry::num_free_objects, NUM_ORDERS, OBJECTS_IN_PAGE, page_entry::order, page_entry::page, ggc_globals::pages, ggc_globals::pagesize, and save_in_use_p.
Referenced by clear_marks(), ggc_collect(), and ggc_pch_read().
|
inlinestatic |
References page_group::allocation, clear_page_group_in_use(), page_entry::group, page_group::in_use, page_entry::page, and page_group_index().
Referenced by clear_page_group_in_use(), and free_page().
|
static |
Subroutine of init_ggc which computes the pair of numbers used to perform division by OBJECT_SIZE (order) and fills in inverse_table[]. This algorithm is taken from Granlund and Montgomery's paper "Division by Invariant Integers using Multiplication" (Proc. SIGPLAN PLDI, 1994), section 9 (Exact division by constants).
References compute_inverse(), DIV_MULT, DIV_SHIFT, and OBJECT_SIZE.
Referenced by compute_inverse(), and init_ggc().
| DEBUG_FUNCTION void debug_print_page_list | ( | int | order | ) |
Prints the page-entry for object size ORDER, for debugging.
References page_entry::context_depth, debug_print_page_list(), G, NULL, page_entry::order, ggc_globals::page_tails, and ggc_globals::pages.
Referenced by debug_print_page_list().
|
static |
Release the free page cache for FREE_LIST to the system.
References page_entry::bytes, ggc_globals::bytes_mapped, page_entry::discarded, do_release_pages(), free(), free_list::free_pages, G, GGC_QUIRE_SIZE, page_entry::group, page_group::in_use, page_entry::next, NULL, page_entry::page, and ggc_globals::pagesize.
Referenced by do_release_pages(), and release_pages().
|
inlinestatic |
Find a free list for ENTRY_SIZE.
References free_list::bytes, find_free_list(), ggc_globals::free_lists, G, i, num_free_list, and ggc_globals::stats.
Referenced by find_free_list(), find_free_list_order(), ggc_pch_read(), and init_ggc().
|
inlinestatic |
Faster way to find a free list by ORDER for BYTES.
References free_list::bytes, cache_free_list, find_free_list(), find_free_list_order(), and NULL.
Referenced by alloc_page(), and find_free_list_order().
|
static |
For a page that is no longer needed, put it on the free page list.
References adjust_depth(), ggc_globals::by_depth, ggc_globals::by_depth_in_use, page_entry::bytes, clear_page_group_in_use(), page_entry::context_depth, ggc_globals::debug_file, page_entry::free_list, free_page(), free_list::free_pages, G, gcc_assert, GGC_DEBUG_LEVEL, page_entry::group, i, page_entry::index_by_depth, page_entry::next, NULL, page_entry::page, ggc_globals::save_in_use, set_page_table_entry(), and VALGRIND_DISCARD.
Referenced by free_page(), and sweep_pages().
| void ggc_collect | ( | enum ggc_collect | mode | ) |
Top level mark-and-sweep routine.
References ggc_globals::allocated, ggc_globals::allocated_last_gc, clear_marks(), ggc_globals::context_depth, ggc_globals::context_depth_collections, ggc_globals::debug_file, G, GGC_COLLECT_HEURISTIC, GGC_DEBUG_LEVEL, ggc_handle_finalizers(), ggc_mark_roots(), ggc_prune_overhead_list(), in_gc, invoke_plugin_callbacks(), MAX, NULL, ONE_K, poison_pages, PRsa, release_pages(), SIZE_AMOUNT, sweep_pages(), timevar_pop(), timevar_push(), memory_block_pool::trim(), and validate_free_objects.
| void ggc_free | ( | void * | p | ) |
Release the memory for object P.
Free a block. To be used when known for certain it's not reachable.
References ggc_globals::allocated, ggc_globals::debug_file, fmt_size_t, G, GGC_DEBUG_LEVEL, ggc_free(), ggc_free_overhead(), HOST_BITS_PER_LONG, HOST_SIZE_T_PRINT_UNSIGNED, in_gc, page_entry::in_use_p, lookup_page_table_entry(), page_entry::next, page_entry::next_bit_hint, NULL, page_entry::num_free_objects, OBJECT_SIZE, OFFSET_TO_BIT, page_entry::order, page_entry::page, ggc_globals::page_tails, ggc_globals::pages, page_entry::prev, and VALGRIND_DISCARD.
| size_t ggc_get_size | ( | const void * | p | ) |
Return the size of the gc-able object P.
Return the number of bytes allocated at the indicated address.
References ggc_get_size(), lookup_page_table_entry(), OBJECT_SIZE, and page_entry::order.
Referenced by ggc_get_size(), ggc_realloc(), ggc_record_overhead(), and gt_pch_note_object().
| void ggc_grow | ( | void | ) |
Assume that all GGC memory is reachable and grow the limits for next collection. With checking, trigger GGC so -Q compilation outputs how much of memory really is reachable.
Assume that all GGC memory is reachable and grow the limits for next collection.
References ggc_globals::allocated, ggc_globals::allocated_last_gc, G, ggc_grow(), MAX, PRsa, and SIZE_AMOUNT.
|
static |
Check if any blocks with a registered finalizer have become unmarked. If so run the finalizer and unregister it because the block is about to be freed. Note that no guarantee is made about what order finalizers will run in so touching other objects in gc memory is extremely unwise.
References finalizer::addr(), vec_finalizer::addr(), finalizer::call(), vec_finalizer::call(), ggc_globals::context_depth, ggc_globals::finalizers, G, gcc_assert, ggc_handle_finalizers(), ggc_marked_p(), i, and ggc_globals::vec_finalizers.
Referenced by ggc_collect(), and ggc_handle_finalizers().
| void * ggc_internal_alloc | ( | size_t | size, |
| void(* | f )(void *), | ||
| size_t | s, | ||
| size_t n | MEM_STAT_DECL ) |
Allocate a chunk of memory of SIZE bytes. Its contents are undefined.
References add_finalizer(), alloc_page(), ggc_globals::allocated, ggc_globals::by_depth_in_use, page_entry::context_depth, ggc_globals::debug_file, ggc_globals::depth_in_use, FINAL_PASS_MEM_STAT, fmt_size_t, G, GGC_DEBUG_LEVEL, ggc_internal_alloc(), ggc_record_overhead(), ggc_round_alloc_size_1(), HOST_BITS_PER_LONG, HOST_SIZE_T_PRINT_UNSIGNED, page_entry::in_use_p, page_entry::index_by_depth, MEM_STAT_DECL, page_entry::next, page_entry::next_bit_hint, NULL, page_entry::num_free_objects, OBJECT_SIZE, page_entry::order, page_entry::page, ggc_globals::page_tails, ggc_globals::pages, page_entry::prev, push_by_depth(), push_depth(), ggc_globals::stats, timevar_ggc_mem_total, and VALGRIND_DISCARD.
| void * ggc_internal_alloc_no_dtor | ( | size_t | size, |
| void(* | f )(void *), | ||
| size_t | s, | ||
| size_t n | MEM_STAT_DECL ) |
References ggc_internal_alloc(), ggc_internal_alloc_no_dtor(), MEM_STAT_DECL, and PASS_MEM_STAT.
| bool ggc_marked_p | ( | const void * | p | ) |
Return true if P has been marked, zero otherwise. P must have been allocated by the GC allocator; it mustn't point to static objects, stack variables, or memory allocated with malloc.
References gcc_assert, ggc_marked_p(), HOST_BITS_PER_LONG, page_entry::in_use_p, lookup_page_table_entry(), OFFSET_TO_BIT, page_entry::order, and page_entry::page.
Referenced by ggc_handle_finalizers(), ggc_marked_p(), ggc_prune_overhead_list(), ggc_purge_stringpool(), gt_value_expr_mark_1(), gt_value_expr_mark_2(), ggc_cache_remove< T >::keep_cache_entry(), hash_map< KeyId, Value, Traits >::hash_entry::keep_cache_entry(), tm_clone_hasher::keep_cache_entry(), tm_wrapper_hasher::keep_cache_entry(), tree_decl_map_cache_hasher::keep_cache_entry(), tree_type_map_cache_hasher::keep_cache_entry(), tree_vec_map_cache_hasher::keep_cache_entry(), type_cache_hasher::keep_cache_entry(), maybe_delete_ident(), and tree_map_base_marked_p().
| char * ggc_pch_alloc_object | ( | struct ggc_pch_data * | d, |
| void * | x, | ||
| size_t | size ) |
Assuming that the objects really do end up at the address passed to ggc_pch_this_base, return the address of this object.
References ggc_pch_data::d, ggc_pch_alloc_object(), NUM_SIZE_LOOKUP, OBJECT_SIZE, and size_lookup.
Referenced by ggc_call_alloc(), and ggc_pch_alloc_object().
| void ggc_pch_count_object | ( | struct ggc_pch_data * | d, |
| void * | x, | ||
| size_t | size ) |
The second parameter and third parameters give the address and size of an object. Update the ggc_pch_data structure with as much of that information as is necessary.
References ggc_pch_data::d, ggc_pch_count_object(), NUM_SIZE_LOOKUP, OBJECT_SIZE, size_lookup, and ggc_pch_ondisk::totals.
Referenced by ggc_call_count(), and ggc_pch_count_object().
| void ggc_pch_finish | ( | struct ggc_pch_data * | d, |
| FILE * | f ) |
All objects have been written, write out any final information required.
References ggc_pch_data::d, fatal_error(), free(), ggc_pch_finish(), and input_location.
Referenced by ggc_pch_finish(), and gt_pch_save().
| void ggc_pch_prepare_write | ( | struct ggc_pch_data * | d, |
| FILE * | f ) |
Write out any initial information required.
References ggc_pch_prepare_write().
Referenced by ggc_pch_prepare_write(), and gt_pch_save().
| void ggc_pch_read | ( | FILE * | f, |
| void * | addr ) |
A PCH file has just been read in at the address specified second parameter. Set up the GC implementation for the new objects.
References ggc_globals::allocated, ggc_globals::allocated_last_gc, BITMAP_SIZE, ggc_globals::by_depth_in_use, page_entry::bytes, clear_marks(), ggc_globals::context_depth, page_entry::context_depth, fatal_error(), ggc_globals::finalizers, find_free_list(), page_entry::free_list, G, gcc_assert, ggc_pch_read(), HOST_BITS_PER_LONG, i, page_entry::in_use_p, input_location, move_ptes_to_front(), page_entry::next, NULL, page_entry::num_free_objects, NUM_ORDERS, OBJECT_SIZE, page_entry::order, page_entry::page, PAGE_ALIGN, ggc_globals::page_tails, ggc_globals::pages, ggc_globals::pagesize, poison_pages, push_by_depth(), set_page_table_entry(), ggc_pch_ondisk::totals, validate_free_objects, ggc_globals::vec_finalizers, and vNULL.
Referenced by ggc_pch_read(), and gt_pch_restore().
| void ggc_pch_this_base | ( | struct ggc_pch_data * | d, |
| void * | base ) |
The objects, when read, will most likely be at the address in the second parameter.
References a, ggc_pch_data::base, ggc_pch_data::d, ggc_pch_this_base(), i, NUM_ORDERS, OBJECT_SIZE, PAGE_ALIGN, and ggc_pch_ondisk::totals.
Referenced by ggc_pch_this_base(), and gt_pch_save().
| size_t ggc_pch_total_size | ( | struct ggc_pch_data * | d | ) |
Return the total size of the data to be written to hold all the objects previously passed to ggc_pch_count_object.
References a, ggc_pch_data::d, ggc_pch_total_size(), i, NUM_ORDERS, OBJECT_SIZE, PAGE_ALIGN, and ggc_pch_ondisk::totals.
Referenced by ggc_pch_total_size(), and gt_pch_save().
| void ggc_pch_write_object | ( | struct ggc_pch_data * | d, |
| FILE * | f, | ||
| void * | x, | ||
| void * | newx, | ||
| size_t | size ) |
Write out this object, including any padding.
References ggc_pch_data::d, fatal_error(), G, ggc_pch_write_object(), input_location, NUM_SIZE_LOOKUP, OBJECT_SIZE, ggc_globals::pagesize, ROUND_UP_VALUE, SEEK_CUR, size_lookup, and ggc_pch_ondisk::totals.
Referenced by ggc_pch_write_object(), and gt_pch_save().
| void ggc_print_statistics | ( | void | ) |
Statistics.
Print allocation statistics.
References ggc_globals::allocated, ggc_globals::allocated_last_gc, BITMAP_SIZE, page_entry::bytes, ggc_globals::bytes_mapped, G, ggc_print_common_statistics(), ggc_print_statistics(), i, page_entry::next, page_entry::num_free_objects, NUM_ORDERS, OBJECT_SIZE, OBJECTS_IN_PAGE, ggc_globals::pages, PRIu64, PRsa, release_pages(), SIZE_AMOUNT, and ggc_globals::stats.
Referenced by dump_memory_report(), and ggc_print_statistics().
|
static |
Merge the SAVE_IN_USE_P and IN_USE_P arrays in P so that IN_USE_P reflects reality. Recalculate NUM_FREE_OBJECTS as well.
References BITMAP_SIZE, CEIL, gcc_assert, ggc_recalculate_in_use_p(), i, page_entry::in_use_p, page_entry::num_free_objects, OBJECTS_IN_PAGE, and save_in_use_p.
Referenced by ggc_recalculate_in_use_p(), and sweep_pages().
| size_t ggc_round_alloc_size | ( | size_t | requested_size | ) |
For a given size of memory requested for allocation, return the actual size that is going to be allocated.
Null garbage collection for the GNU compiler. Copyright (C) 1998-2026 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>.
This version is used by the gen* programs and certain language-specific targets (such as java), where we don't really need GC at all. This prevents problems with pulling in all the tree stuff.
For a given size of memory requested for allocation, return the actual size that is going to be allocated.
References ggc_round_alloc_size(), ggc_round_alloc_size_1(), and NULL.
|
static |
For a given size of memory requested for allocation, return the actual size that is going to be allocated, as well as the size order.
References ggc_round_alloc_size_1(), NUM_SIZE_LOOKUP, OBJECT_SIZE, and size_lookup.
Referenced by ggc_internal_alloc(), ggc_round_alloc_size(), and ggc_round_alloc_size_1().
| bool ggc_set_mark | ( | const void * | p | ) |
If P is not marked, marks it and return false. Otherwise return true. P must have been allocated by the GC allocator; it mustn't point to static objects, stack variables, or memory allocated with malloc.
Actually set the mark on a particular region of memory, but don't follow pointers. This function is called by ggc_mark_*. It returns false if the object was not previously marked; true if the object was already marked, or if, for any other reason, pointers in this data structure should not be traversed.
References ggc_globals::debug_file, G, gcc_assert, GGC_DEBUG_LEVEL, ggc_set_mark(), HOST_BITS_PER_LONG, page_entry::in_use_p, lookup_page_table_entry(), page_entry::num_free_objects, OFFSET_TO_BIT, page_entry::order, and page_entry::page.
Referenced by ggc_set_mark().
| void ggc_trim | ( | void | ) |
Return free pages to the system.
Return unused memory pages to the system.
References ggc_globals::allocated, ggc_globals::bytes_mapped, G, ggc_trim(), PRsa, release_pages(), SIZE_AMOUNT, sweep_pages(), timevar_pop(), and timevar_push().
| void gt_ggc_m_S | ( | const void * | p | ) |
Mark function for strings.
References ggc_globals::debug_file, G, gcc_assert, GGC_DEBUG_LEVEL, gt_ggc_m_S(), HOST_BITS_PER_LONG, page_entry::in_use_p, page_entry::num_free_objects, object_size_table, OFFSET_TO_BIT, offsetof, page_entry::order, page_entry::page, and safe_lookup_page_table_entry().
Referenced by gt_ggc_m_S(), gt_ggc_mx(), gt_ggc_mx(), and gt_ggc_mx().
| void gt_ggc_mx | ( | char *& | x | ) |
References gt_ggc_m_S(), and gt_ggc_mx().
| void gt_ggc_mx | ( | const char *& | x | ) |
User-callable entry points for marking string X.
References gt_ggc_m_S(), and gt_ggc_mx().
| void gt_ggc_mx | ( | unsigned char & | x | ) |
References gt_ggc_mx().
| void gt_ggc_mx | ( | unsigned char *& | x | ) |
References gt_ggc_m_S(), and gt_ggc_mx().
| void init_ggc | ( | void | ) |
Initialize the ggc-mmap allocator.
Initialize the garbage collector.
References ggc_globals::by_depth, ggc_globals::by_depth_in_use, ggc_globals::by_depth_max, compute_inverse(), ggc_globals::debug_file, ggc_globals::depth, ggc_globals::depth_in_use, ggc_globals::depth_max, exact_log2(), extra_order_size_table, ggc_globals::finalizers, find_free_list(), fopen, G, gcc_assert, HOST_BITS_PER_PTR, i, init_ggc(), INITIAL_PTE_COUNT, internal_error(), ggc_globals::lg_pagesize, MAX_ALIGNMENT, NULL, NUM_ORDERS, NUM_SIZE_LOOKUP, O_RDONLY, OBJECT_SIZE, object_size_table, objects_per_page_table, page_entry::order, ggc_globals::pagesize, ROUND_UP, ggc_globals::save_in_use, size_lookup, ggc_globals::vec_finalizers, and vNULL.
Referenced by general_init(), and init_ggc().
| struct ggc_pch_data * init_ggc_pch | ( | void | ) |
Return a new ggc_pch_data structure.
References init_ggc_pch().
Referenced by gt_pch_save(), and init_ggc_pch().
|
inlinestatic |
Traverse the page table and find the entry for a page. Die (probably) if the object wasn't allocated via GC.
References G, ggc_globals::lookup, LOOKUP_L1, LOOKUP_L2, and lookup_page_table_entry().
Referenced by ggc_free(), ggc_get_size(), ggc_marked_p(), ggc_set_mark(), and lookup_page_table_entry().
|
static |
Move the PCH PTE entries just added to the end of by_depth, to the front.
References ggc_globals::by_depth, ggc_globals::by_depth_in_use, ggc_globals::by_depth_max, free(), G, i, page_entry::index_by_depth, move_ptes_to_front(), push_depth(), and ggc_globals::save_in_use.
Referenced by ggc_pch_read(), and move_ptes_to_front().
|
inlinestatic |
Compute the index for this page into the page group.
References G, ggc_globals::lg_pagesize, page_entry::page, and page_group_index().
Referenced by clear_page_group_in_use(), page_group_index(), and set_page_group_in_use().
|
inlinestatic |
Push an entry onto G.by_depth and G.save_in_use.
References ggc_globals::by_depth, ggc_globals::by_depth_in_use, ggc_globals::by_depth_max, G, push_by_depth(), and ggc_globals::save_in_use.
Referenced by ggc_internal_alloc(), ggc_pch_read(), and push_by_depth().
|
inlinestatic |
Push an entry onto G.depth.
References ggc_globals::depth, ggc_globals::depth_in_use, ggc_globals::depth_max, G, i, and push_depth().
Referenced by ggc_internal_alloc(), move_ptes_to_front(), and push_depth().
|
static |
Release the free page cache to the system.
References ggc_globals::bytes_mapped, do_release_pages(), free(), ggc_globals::free_lists, G, g, i, NULL, num_free_list, ggc_globals::page_groups, PRsa, release_pages(), and SIZE_AMOUNT.
Referenced by ggc_collect(), ggc_print_statistics(), ggc_trim(), and release_pages().
|
inlinestatic |
Traverse the page table and find the entry for a page. If the object wasn't allocated in GC return NULL.
References G, ggc_globals::lookup, LOOKUP_L1, LOOKUP_L2, NULL, and safe_lookup_page_table_entry().
Referenced by gt_ggc_m_S(), and safe_lookup_page_table_entry().
|
inlinestatic |
Set and clear the in_use bit for this page in the page group.
References page_group::allocation, page_entry::group, page_group::in_use, page_entry::page, page_group_index(), and set_page_group_in_use().
Referenced by alloc_page(), and set_page_group_in_use().
|
static |
Set the page table entry for a page.
References G, ggc_globals::lookup, LOOKUP_L1, LOOKUP_L2, NULL, PAGE_L2_SIZE, and set_page_table_entry().
Referenced by alloc_page(), free_page(), ggc_pch_read(), and set_page_table_entry().
|
static |
Free all empty pages. Partially empty pages need no attention because the `mark' bit doubles as an `unused' bit.
References ggc_globals::allocated, ggc_globals::context_depth, page_entry::context_depth, free_page(), G, ggc_recalculate_in_use_p(), page_entry::next, NULL, page_entry::num_free_objects, NUM_ORDERS, OBJECT_SIZE, OBJECTS_IN_PAGE, page_entry::order, ggc_globals::page_tails, ggc_globals::pages, page_entry::prev, and sweep_pages().
Referenced by ggc_collect(), ggc_trim(), and sweep_pages().
|
static |
Fast lookup of free_list by order.
Referenced by find_free_list_order().
|
static |
The Ith entry is the maximum size of an object to be stored in the Ith extra order. Adding a new entry to this array is the *only* thing you need to do to add a new special allocation size.
Referenced by init_ggc().
|
static |
Referenced by add_finalizer(), adjust_depth(), alloc_page(), clear_marks(), debug_print_page_list(), do_release_pages(), find_free_list(), free_page(), get_tail_padding_adjustment(), ggc_collect(), ggc_free(), ggc_grow(), ggc_handle_finalizers(), ggc_internal_alloc(), ggc_pch_read(), ggc_pch_write_object(), ggc_print_statistics(), ggc_set_mark(), ggc_trim(), gt_ggc_m_S(), init_ggc(), lookup_page_table_entry(), move_ptes_to_front(), page_group_index(), push_by_depth(), push_depth(), release_pages(), safe_lookup_page_table_entry(), set_page_table_entry(), and sweep_pages().
True if a gc is currently taking place.
Referenced by ggc_collect(), and ggc_free().
| struct [struct].inverse_table inverse_table[NUM_ORDERS] |
|
constexpr |
Referenced by find_free_list(), and release_pages().
|
static |
The Ith entry is the size of an object on a page of order I.
Referenced by gt_ggc_m_S(), and init_ggc().
|
static |
The Ith entry is the number of objects on a page or order I.
Referenced by init_ggc().
|
static |
Referenced by ggc_pch_alloc_object(), ggc_pch_count_object(), ggc_pch_write_object(), ggc_round_alloc_size_1(), and init_ggc().