GCC Middle and Back End API Reference
ggc-common.c File Reference

Data Structures

struct  ptr_data
struct  saving_hasher
struct  traversal_state
struct  mmap_info
struct  loc_descriptor
struct  loc_desc_hasher
struct  ptr_hash_entry
struct  ptr_hash_hasher

Typedefs

typedef struct ggc_root_tabconst_ggc_root_tab_t
typedef struct ggc_cache_tabconst_ggc_cache_tab_t

Functions

static int ggc_htab_delete (void **, void *)
static int compare_ptr_data (const void *, const void *)
static void relocate_ptrs (void *, void *)
static void write_pch_globals (const struct ggc_root_tab *const *tab, struct traversal_state *state)
static int ggc_htab_delete ()
void ggc_register_root_tab ()
void ggc_register_cache_tab ()
static void ggc_scan_cache_tab ()
static void ggc_mark_root_tab ()
void ggc_mark_roots ()
void * ggc_internal_cleared_alloc_stat ()
void * ggc_realloc_stat ()
void * ggc_cleared_alloc_htab_ignore_args (size_t c, size_t n)
void * ggc_cleared_alloc_ptr_array_two_args ()
void * ggc_splay_alloc ()
void ggc_splay_dont_free ()
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)
void gt_pch_note_reorder (void *obj, void *note_ptr_cookie, gt_handle_reorder reorder_fn)
int ggc_call_count ()
int ggc_call_alloc ()
static int compare_ptr_data ()
static void relocate_ptrs ()
void gt_pch_save ()
void gt_pch_restore ()
void * default_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 * mmap_gt_pch_get_address ()
int mmap_gt_pch_use_address ()
static double ggc_rlimit_bound ()
static int ggc_min_expand_heuristic ()
static int ggc_min_heapsize_heuristic ()
void init_ggc_heuristics ()
static struct loc_descriptormake_loc_descriptor ()
void ggc_record_overhead (size_t allocated, size_t overhead, void *ptr, const char *name, int line, const char *function)
int ggc_prune_ptr ()
void ggc_prune_overhead_list ()
void ggc_free_overhead ()
static int final_cmp_statistic ()
static int cmp_statistic ()
int ggc_add_statistics ()
void dump_ggc_loc_statistics ()

Variables

bool ggc_force_collect
bool ggc_protect_identifiers = true
static ggc_statisticsggc_stats
static vec< const_ggc_root_tab_textra_root_vec
static vec< const_ggc_cache_tab_textra_cache_vec
static hash_table< saving_hashersaving_htab
static hash_table
< loc_desc_hasher
loc_hash
static hash_table
< ptr_hash_hasher
ptr_hash
static struct loc_descriptor ** loc_array

Typedef Documentation

   This extra vector of dynamically registered cache_tab-s is used by
   ggc_mark_roots and gives the ability to dynamically add new GGC cache
   tables, for instance from some plugins; this vector is on the heap
   since it is used by GGC internally.  
   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

static int cmp_statistic ( )
static
   Helper for qsort; sort descriptors by amount of memory consumed.  
static int compare_ptr_data ( const void *  ,
const void *   
)
static
static int compare_ptr_data ( )
static
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 getrlimit().

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.  
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.  
void dump_ggc_loc_statistics ( )
   Dump per-site memory statistics.  
static int final_cmp_statistic ( )
static
   Helper for qsort; sort descriptors by amount of memory consumed.  
int ggc_add_statistics ( )
int ggc_call_alloc ( )
int ggc_call_count ( )
   Callbacks for htab_traverse.  
void* ggc_cleared_alloc_htab_ignore_args ( size_t  c,
size_t  n 
)
void* ggc_cleared_alloc_ptr_array_two_args ( )
   TODO: once we actually use type information in GGC, create a new tag
   gt_gcc_ptr_array and use it for pointer arrays.  
void ggc_free_overhead ( )
   Notice that the pointer has been freed.  
     The pointer might be not found if a PCH read happened between allocation
     and ggc_free () call.  FIXME: account memory properly in the presence of
     PCH. 

Referenced by gt_ggc_m_S().

static int ggc_htab_delete ( void **  ,
void *   
)
static

Referenced by ggc_register_cache_tab().

static int ggc_htab_delete ( )
static
   Maintain global roots that are preserved during GC.  
   Process a slot of an htab by deleting it if it has not been marked.  
void* ggc_internal_cleared_alloc_stat ( )
   Allocate a block of memory, then clear it.  
static void ggc_mark_root_tab ( )
static
   Mark all the roots in the table RT.  

References ggc_root_tab::base, gt_ggc_deletable_rtab, gt_ggc_rtab, memset(), and ggc_root_tab::stride.

void ggc_mark_roots ( void  )
   Iterate through all registered roots and mark each element.  
     Now scan all hash tables that have objects which are to be deleted if
     they are not already marked.  
     Some plugins may call ggc_set_mark from here.  

References ggc_internal_alloc_stat(), and memset().

static int ggc_min_expand_heuristic ( )
static
   Heuristic to set a default for GGC_MIN_EXPAND.  
     Adjust for rlimits.  
     The heuristic is a percentage equal to 30% + 70%*(RAM/1GB), yielding
     a lower bound of 30% and an upper bound of 100% (when RAM >= 1GB).  
static int ggc_min_heapsize_heuristic ( )
static
   Heuristic to set a default for GGC_MIN_HEAPSIZE.  
     The heuristic is RAM/8, with a lower bound of 4M and an upper
     bound of 128M (when RAM >= 1GB).  
     Try not to overrun the RSS limit while doing garbage collection.
     The RSS limit is only advisory, so no margin is subtracted.  
     Don't blindly run over our data limit; do GC at least when the
     *next* GC would be within 20Mb of the limit or within a quarter of
     the limit, whichever is larger.  If GCC does hit the data limit,
     compilation will fail, so this tries to be conservative.  
void ggc_print_common_statistics ( FILE *  ,
ggc_statistics  
)
   Used by the various collectors to gather and print statistics that
   do not depend on the collector in use.  
     Set the pointer so that during collection we will actually gather
     the statistics.  
     Then do one collection to fill in the statistics.  
     At present, we don't really gather any interesting statistics.  
     Don't gather statistics any more.  
void ggc_prune_overhead_list ( void  )
   After live values has been marked, walk all recorded pointers and see if
   they are still live.  
int ggc_prune_ptr ( )
   Helper function for prune_overhead_list.  See if SLOT is still marked and
   remove it from hashtable if it is not.  

Referenced by ptr_hash_hasher::equal().

void* ggc_realloc_stat ( )
   Resize a block of memory, possibly re-allocating it.  
         Mark the unwanted memory as unaccessible.  We also need to make
         the "new" size accessible, since ggc_get_size returns the size of
         the pool, not the size of the individually allocated object, the
         size which was previously made accessible.  Unfortunately, we
         don't know that previously allocated size.  Without that
         knowledge we have to lose some initialization-tracking for the
         old parts of the object.  An alternative is to mark the whole
         old_size as reachable, but that would lose tracking of writes
         after the end of the object (by small offsets).  Discard the
         handle to avoid handle leak.  
     Since ggc_get_size returns the size of the pool, not the size of the
     individually allocated object, we'd access parts of the old object
     that were marked invalid with the memcpy below.  We lose a bit of the
     initialization-tracking since some of it may be uninitialized.  
     The old object is not supposed to be used anymore.  
void ggc_record_overhead ( size_t  allocated,
size_t  overhead,
void *  ptr,
const char *  name,
int  line,
const char *  function 
)
   Record ALLOCATED and OVERHEAD bytes to descriptor NAME:LINE (FUNCTION).  

References loc_descriptor::allocated, loc_descriptor::collected, loc_descriptor::freed, and loc_descriptor::overhead.

void ggc_register_cache_tab ( )
   Dynamically register a new GGC cache table CT. This is useful for
   plugins. 

References ggc_cache_tab::base, ggc_htab_delete(), and ggc_set_mark().

void ggc_register_root_tab ( )
   Dynamically register a new GGC root table RT. This is useful for
   plugins. 
static double ggc_rlimit_bound ( )
static
   Modify the bound based on rlimits.  
     RLIMIT_AS is what POSIX says is the limit on mmap.  Presumably
     any OS which has RLIMIT_AS also has a working mmap that GCC will use.  
     ... but some older OSs bound mmap based on RLIMIT_DATA, or we
     might be on an OS that has a broken mmap.  (Others don't bound
     mmap at all, apparently.)  
         Darwin has this horribly bogus default setting of
         RLIMIT_DATA, to 6144Kb.  No-one notices because RLIMIT_DATA
         appears to be ignored.  Ignore such silliness.  If a limit
         this small was actually effective for mmap, GCC wouldn't even
         start up.  

References getrlimit().

static void ggc_scan_cache_tab ( )
static
   Scan a hash table that has objects which are to be deleted if they are not
   already marked.  
void* ggc_splay_alloc ( )
   These are for splay_tree_new_ggc.  

References ggc_collect(), and stats.

void ggc_splay_dont_free ( )
int gt_pch_note_object ( void *  obj,
void *  note_ptr_cookie,
gt_note_pointers  note_ptr_fn 
)
void gt_pch_note_reorder ( void *  obj,
void *  note_ptr_cookie,
gt_handle_reorder  reorder_fn 
)
   Register an object in the hash table.  
void gt_pch_restore ( )
   Read the state of the compiler back in from F.  
     Delete any deletable objects.  This makes ggc_pch_read much
     faster, as it can be sure that no GCable objects remain other
     than the ones just read in.  
     Read in all the scalar variables.  
     Read in all the global pointers, in 6 easy loops.  
void gt_pch_save ( )
   Write out the state of the compiler to F.  
     Prepare the objects for writing, determine addresses and such.  
     Try to arrange things so that no relocation is necessary, but
     don't try very hard.  On most platforms, this will always work,
     and on the rest it's a lot of work to do better.
     (The extra work goes in HOST_HOOKS_GT_PCH_GET_ADDRESS and
     HOST_HOOKS_GT_PCH_USE_ADDRESS.)  
     Write out all the scalar variables.  
     Write out all the global pointers, after translation.  
     Pad the PCH file so that the mmapped area starts on an allocation
     granularity (usually page) boundary.  
     Actually write out the objects.  
         obj might contain uninitialized bytes, e.g. in the trailing
         padding of the object.  Avoid warnings by making the memory
         temporarily defined and then restoring previous state.  
                 We assume that first part of obj is addressable, and
                 the rest is unaddressable.  Find out where the boundary is
                 using binary search.  
void init_ggc_heuristics ( void  )
   Heuristics.  
static struct loc_descriptor* make_loc_descriptor ( )
staticread
   Return descriptor for given call site, create new one if needed.  

Referenced by loc_desc_hasher::hash().

void* mmap_gt_pch_get_address ( )
   Default version of HOST_HOOKS_GT_PCH_GET_ADDRESS when mmap is present.
   We temporarily allocate SIZE bytes, and let the kernel place the data
   wherever it will.  If it worked, that's our spot, if not we're likely
   to be in trouble.  
int mmap_gt_pch_use_address ( )
   Default version of HOST_HOOKS_GT_PCH_USE_ADDRESS when mmap is present.
   Map SIZE bytes of FD+OFFSET at BASE.  Return 1 if we succeeded at
   mapping the data at BASE, -1 if we couldn't.

   This version assumes that the kernel honors the START operand of mmap
   even without MAP_FIXED if START through START+SIZE are not currently
   mapped with something.  
     We're called with size == 0 if we're not planning to load a PCH
     file at all.  This allows the hook to free any static space that
     we might have allocated at link time.  
static void relocate_ptrs ( void *  ,
void *   
)
static
static void relocate_ptrs ( )
static
   Callbacks for note_ptr_fn.  
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.  

Variable Documentation

vec<const_ggc_cache_tab_t> extra_cache_vec
static
vec<const_ggc_root_tab_t> extra_root_vec
static
bool ggc_force_collect
@verbatim 

Simple garbage collection for the GNU compiler. Copyright (C) 1999-2013 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.  
   When set, ggc_collect will do collection.  
bool ggc_protect_identifiers = true
   When true, protect the contents of the identifier hash table.  
ggc_statistics* ggc_stats
static
   Statistics about the allocation.  
struct loc_descriptor** loc_array
static
   Collect array of the descriptors from hashtable.  
hash_table<loc_desc_hasher> loc_hash
static
   Hashtable used for statistics.  
hash_table<ptr_hash_hasher> ptr_hash
static
   Hashtable converting address of allocated field to loc descriptor.  
hash_table<saving_hasher> saving_htab
static