GCC Middle and Back End API Reference
ggc-common.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "timevar.h"
#include "diagnostic-core.h"
#include "ggc-internal.h"
#include "hosthooks.h"
#include "plugin.h"
#include "options.h"
Include dependency graph for ggc-common.cc:

Data Structures

struct  ptr_data
 
struct  saving_hasher
 
struct  traversal_state
 
struct  mmap_info
 
class  ggc_usage
 

Macros

#define INCLUDE_MALLOC_H
 
#define POINTER_HASH(x)   (hashval_t)((intptr_t)x >> 3)
 

Typedefs

typedef const struct ggc_root_tabconst_ggc_root_tab_t
 

Functions

static int compare_ptr_data (const void *, const void *)
 
static void relocate_ptrs (void *, void *, void *)
 
static void write_pch_globals (const struct ggc_root_tab *const *tab, struct traversal_state *state)
 
void ggc_register_root_tab (const struct ggc_root_tab *rt)
 
static void ggc_mark_root_tab (const_ggc_root_tab_t rt)
 
static void ggc_zero_rtab_roots (const_ggc_root_tab_t rt)
 
void ggc_mark_roots (void)
 
voidggc_internal_cleared_alloc (size_t size, void(*f)(void *), size_t s, size_t n MEM_STAT_DECL)
 
voidggc_realloc (void *x, size_t size MEM_STAT_DECL)
 
voidggc_cleared_alloc_htab_ignore_args (size_t c, size_t n)
 
voidggc_cleared_alloc_ptr_array_two_args (size_t c, size_t n)
 
voidggc_splay_alloc (int sz, void *nl)
 
void ggc_splay_dont_free (void *x, void *nl)
 
void ggc_print_common_statistics (FILE *stream, ggc_statistics *stats)
 
int gt_pch_note_object (void *obj, void *note_ptr_cookie, gt_note_pointers note_ptr_fn, size_t length_override)
 
void gt_pch_note_callback (void *obj, void *base)
 
void gt_pch_note_reorder (void *obj, void *note_ptr_cookie, gt_handle_reorder reorder_fn)
 
int ggc_call_count (ptr_data **slot, traversal_state *state)
 
int ggc_call_alloc (ptr_data **slot, traversal_state *state)
 
static int compare_ptr (const void *p1_p, const void *p2_p)
 
static unsigned charread_uleb128 (unsigned char *p, size_t *val)
 
static size_t write_uleb128 (unsigned char *p, size_t val)
 
void gt_pch_save (FILE *f)
 
void gt_pch_restore (FILE *f)
 
voiddefault_gt_pch_get_address (size_t size, int fd)
 
int default_gt_pch_use_address (void *&base, size_t size, int fd, size_t offset)
 
size_t default_gt_pch_alloc_granularity (void)
 
static double ggc_rlimit_bound (double limit)
 
static int ggc_min_expand_heuristic (void)
 
static int ggc_min_heapsize_heuristic (void)
 
void init_ggc_heuristics (void)
 
void dump_ggc_loc_statistics ()
 
void ggc_record_overhead (size_t allocated, size_t overhead, void *ptr MEM_STAT_DECL)
 
void ggc_free_overhead (void *ptr)
 
void ggc_prune_overhead_list (void)
 
void report_heap_memory_use ()
 
void ggc_common_finalize ()
 

Variables

bool ggc_protect_identifiers = true
 
static ggc_statisticsggc_stats
 
static vec< const_ggc_root_tab_textra_root_vec
 
static hash_table< saving_hasher > * saving_htab
 
static vec< void * > callback_vec
 
static vec< void * > reloc_addrs_vec
 
static mem_alloc_description< ggc_usageggc_mem_desc
 

Macro Definition Documentation

◆ INCLUDE_MALLOC_H

#define INCLUDE_MALLOC_H
Simple garbage collection for the GNU compiler.
   Copyright (C) 1999-2024 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/>.   
Generic garbage collection (GC) functions and data, not specific to
any particular GC implementation.   

◆ POINTER_HASH

Typedef Documentation

◆ const_ggc_root_tab_t

Maintain global roots that are preserved during GC.   
This extra vector of dynamically registered root_tab-s is used by
ggc_mark_roots and gives the ability to dynamically add new GGC root
tables, for instance from some plugins; this vector is on the heap
since it is used by GGC internally.   

Function Documentation

◆ compare_ptr()

static int compare_ptr ( const void * p1_p,
const void * p2_p )
static

◆ compare_ptr_data()

static int compare_ptr_data ( const void * p1_p,
const void * p2_p )
static
Callback for qsort.   

References ggc_alloc().

Referenced by gt_pch_save().

◆ default_gt_pch_alloc_granularity()

size_t default_gt_pch_alloc_granularity ( void )
Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS.   Return the
alignment required for allocating virtual memory. Usually this is the
same as pagesize.   

References ggc_alloc().

◆ default_gt_pch_get_address()

void * default_gt_pch_get_address ( size_t size,
int fd )
Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is not present.
Select no address whatsoever, and let gt_pch_save choose what it will with
malloc, presumably.   

References NULL.

◆ default_gt_pch_use_address()

int default_gt_pch_use_address ( void *& base,
size_t size,
int fd,
size_t offset )
Default version of HOST_HOOKS_GT_PCH_USE_ADDRESS when mmap is not present.
Allocate SIZE bytes with malloc.  Return 0 if the address we got is the
same as base, indicating that the memory has been allocated but needs to
be read in from the file.  Return -1 if the address differs, to relocation
of the PCH file would be required.   

References ggc_alloc().

◆ dump_ggc_loc_statistics()

void dump_ggc_loc_statistics ( )
Dump per-site memory statistics.   

References ggc_alloc(), GGC_COLLECT_FORCE, ggc_mem_desc, and GGC_ORIGIN.

Referenced by dump_memory_report().

◆ ggc_call_alloc()

int ggc_call_alloc ( ptr_data ** slot,
traversal_state * state )

◆ ggc_call_count()

int ggc_call_count ( ptr_data ** slot,
traversal_state * state )
Callbacks for htab_traverse.   

References ggc_pch_count_object(), ptr_data::obj, and ptr_data::size.

Referenced by gt_pch_save().

◆ ggc_cleared_alloc_htab_ignore_args()

void * ggc_cleared_alloc_htab_ignore_args ( size_t c,
size_t n )

References gcc_assert, and ggc_alloc().

◆ ggc_cleared_alloc_ptr_array_two_args()

void * ggc_cleared_alloc_ptr_array_two_args ( size_t c,
size_t n )
TODO: once we actually use type information in GGC, create a new tag
gt_gcc_ptr_array and use it for pointer arrays.   

References gcc_assert, and ggc_alloc().

◆ ggc_common_finalize()

void ggc_common_finalize ( )
Forcibly clear all GTY roots.   

References ggc_alloc(), ggc_zero_rtab_roots(), gt_ggc_deletable_rtab, gt_ggc_rtab, gt_pch_scalar_rtab, and NULL.

Referenced by toplev::finalize().

◆ ggc_free_overhead()

void ggc_free_overhead ( void * ptr)
Notice that the pointer has been freed.   

References ggc_mem_desc.

Referenced by ggc_free().

◆ ggc_internal_cleared_alloc()

void * ggc_internal_cleared_alloc ( size_t size,
void(*)(void *) f,
size_t s,
size_t n MEM_STAT_DECL )
Allocate a block of memory, then clear it.   

References ggc_alloc(), ggc_internal_alloc(), and PASS_MEM_STAT.

◆ ggc_mark_root_tab()

static void ggc_mark_root_tab ( const_ggc_root_tab_t rt)
static
Mark all the roots in the table RT.   

References ggc_alloc(), i, and NULL.

Referenced by ggc_mark_roots().

◆ ggc_mark_roots()

◆ ggc_min_expand_heuristic()

static int ggc_min_expand_heuristic ( void )
static
Heuristic to set a default for GGC_MIN_EXPAND.   

References ggc_alloc(), ggc_rlimit_bound(), MIN, and ONE_G.

Referenced by ggc_min_heapsize_heuristic(), and init_ggc_heuristics().

◆ ggc_min_heapsize_heuristic()

static int ggc_min_heapsize_heuristic ( void )
static
Heuristic to set a default for GGC_MIN_HEAPSIZE.   

References ggc_alloc(), ggc_min_expand_heuristic(), ggc_rlimit_bound(), MAX, MIN, and ONE_K.

Referenced by init_ggc_heuristics().

◆ ggc_print_common_statistics()

void ggc_print_common_statistics ( FILE * stream,
ggc_statistics * stats )
Used by the various collectors to gather and print statistics that
do not depend on the collector in use.   

References ggc_stats, NULL, and stats.

Referenced by ggc_print_statistics().

◆ ggc_prune_overhead_list()

void ggc_prune_overhead_list ( void )
After live values has been marked, walk all recorded pointers and see if
they are still live.   

References ggc_alloc(), ggc_marked_p(), and ggc_mem_desc.

Referenced by ggc_collect().

◆ ggc_realloc()

void * ggc_realloc ( void * x,
size_t size MEM_STAT_DECL )
Resize a block of memory, possibly re-allocating it.   

References ggc_alloc(), ggc_free(), ggc_get_size(), ggc_internal_alloc(), NULL, PASS_MEM_STAT, r, and VALGRIND_DISCARD.

Referenced by grow_tree_vec(), and realloc_for_line_map().

◆ ggc_record_overhead()

void ggc_record_overhead ( size_t allocated,
size_t overhead,
void *ptr MEM_STAT_DECL )
Record ALLOCATED and OVERHEAD bytes to descriptor NAME:LINE (FUNCTION).   

References FINAL_PASS_MEM_STAT, ggc_alloc(), ggc_mem_desc, GGC_ORIGIN, ggc_usage::register_overhead(), and usage().

Referenced by ggc_internal_alloc().

◆ ggc_register_root_tab()

void ggc_register_root_tab ( const struct ggc_root_tab * rt)
Dynamically register a new GGC root table RT. This is useful for
plugins.  

References extra_root_vec, and ggc_alloc().

Referenced by register_callback().

◆ ggc_rlimit_bound()

static double ggc_rlimit_bound ( double limit)
static
Modify the bound based on rlimits.   

References ggc_alloc(), and ONE_M.

Referenced by ggc_min_expand_heuristic(), and ggc_min_heapsize_heuristic().

◆ ggc_splay_alloc()

void * ggc_splay_alloc ( int sz,
void * nl )
These are for splay_tree_new_ggc.   

References gcc_assert, and ggc_internal_alloc().

◆ ggc_splay_dont_free()

void ggc_splay_dont_free ( void * x,
void * nl )

References gcc_assert.

◆ ggc_zero_rtab_roots()

static void ggc_zero_rtab_roots ( const_ggc_root_tab_t rt)
static
Zero out all the roots in the table RT.   

References ggc_alloc(), i, and NULL.

Referenced by ggc_common_finalize().

◆ gt_pch_note_callback()

void gt_pch_note_callback ( void * obj,
void * base )
Register address of a callback pointer.   

References callback_vec, gcc_assert, ggc_alloc(), NULL, ptr_data::obj, POINTER_HASH, and saving_htab.

◆ gt_pch_note_object()

int gt_pch_note_object ( void * obj,
void * note_ptr_cookie,
gt_note_pointers note_ptr_fn,
size_t length_override )

◆ gt_pch_note_reorder()

void gt_pch_note_reorder ( void * obj,
void * note_ptr_cookie,
gt_handle_reorder reorder_fn )

◆ gt_pch_restore()

◆ gt_pch_save()

◆ init_ggc_heuristics()

void init_ggc_heuristics ( void )

◆ read_uleb128()

static unsigned char * read_uleb128 ( unsigned char * p,
size_t * val )
static
Decode one uleb128 from P, return first byte after it, store
decoded value into *VAL.   

References ggc_alloc(), and shift.

Referenced by gt_pch_restore().

◆ relocate_ptrs()

static void relocate_ptrs ( void * ptr_p,
void * real_ptr_p,
void * state_p )
static
Callbacks for note_ptr_fn.   

References gcc_assert, ggc_alloc(), ptr_data::new_addr, NULL, POINTER_HASH, reloc_addrs_vec, and saving_htab.

Referenced by gt_pch_save().

◆ report_heap_memory_use()

void report_heap_memory_use ( void )
Print memory used by heap if this info is available.   

References ggc_alloc(), PRsa, and SIZE_AMOUNT.

Referenced by execute_one_pass(), ipa_read_optimization_summaries_1(), and ipa_read_summaries_1().

◆ write_pch_globals()

static void write_pch_globals ( const struct ggc_root_tab *const * tab,
struct traversal_state * state )
static
Write out, after relocation, the pointers in TAB.   

References fatal_error(), ggc_alloc(), i, input_location, NULL, POINTER_HASH, and saving_htab.

Referenced by gt_pch_save().

◆ write_uleb128()

static size_t write_uleb128 ( unsigned char * p,
size_t val )
static
Store VAL as uleb128 at P, return length in bytes.   

Referenced by gt_pch_save().

Variable Documentation

◆ callback_vec

vec<void *> callback_vec
static

◆ extra_root_vec

vec<const_ggc_root_tab_t> extra_root_vec
static

◆ ggc_mem_desc

◆ ggc_protect_identifiers

bool ggc_protect_identifiers = true
When true, protect the contents of the identifier hash table.   

Referenced by compile_file(), do_compile(), and ggc_mark_roots().

◆ ggc_stats

ggc_statistics* ggc_stats
static
Statistics about the allocation.   

Referenced by ggc_print_common_statistics().

◆ reloc_addrs_vec

vec<void *> reloc_addrs_vec
static

Referenced by gt_pch_save(), and relocate_ptrs().

◆ saving_htab