GCC Middle and Back End API Reference
ggc-common.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "hash-table.h"
#include "ggc.h"
#include "ggc-internal.h"
#include "diagnostic-core.h"
#include "params.h"
#include "hosthooks.h"
#include "hosthooks-def.h"
#include "plugin.h"
#include "vec.h"
#include "timevar.h"
Include dependency graph for ggc-common.c:

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

Macros

#define SCALE(x)
#define LABEL(x)   ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M'))
#define POINTER_HASH(x)   (hashval_t)((intptr_t)x >> 3)

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 ()
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

Macro Definition Documentation

#define LABEL (   x)    ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M'))
#define POINTER_HASH (   x)    (hashval_t)((intptr_t)x >> 3)

Referenced by gt_pch_note_object().

#define SCALE (   x)
Value:
((unsigned long) ((x) < 1024*10 \
? (x) \
: ((x) < 1024*1024*10 \
? (x) / 1024 \
: (x) / (1024*1024))))

Print statistics that are independent of the collector in use.


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 limit.

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.

References NULL.

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, NULL, 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 PASS_MEM_STAT.

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).

 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, CONST_CAST, ggc_htab_delete(), ggc_set_mark(), and NULL.

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.

References MIN.

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.   
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().

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

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