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

Data Structures

struct  max_alignment
struct  page_entry
struct  page_group
struct  page_table_chain
struct  free_object
struct  globals
struct  ggc_pch_ondisk
struct  ggc_pch_data

Typedefs

typedef struct page_entry page_entry
typedef struct page_group page_group
typedef page_entry ** page_table [PAGE_L1_SIZE]

Functions

static int ggc_allocated_p (const void *)
static page_entrylookup_page_table_entry (const void *)
static void set_page_table_entry (void *, page_entry *)
static char * alloc_anon (char *, size_t, bool check)
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_entryalloc_page (unsigned)
static void free_page (struct page_entry *)
static void release_pages (void)
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 void push_depth ()
static void push_by_depth ()
static int ggc_allocated_p ()
static page_entrylookup_page_table_entry ()
static void set_page_table_entry ()
DEBUG_FUNCTION void debug_print_page_list ()
static char * alloc_anon ()
static size_t page_group_index ()
static void set_page_group_in_use ()
static void clear_page_group_in_use ()
static struct page_entryalloc_page ()
static void free_page ()
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 ()
void * ggc_internal_alloc_stat ()
void gt_ggc_m_S ()
void gt_ggc_mx ()
int ggc_set_mark ()
int ggc_marked_p ()
size_t ggc_get_size ()
void ggc_free ()
static void compute_inverse ()
void init_ggc ()
static void ggc_recalculate_in_use_p ()
static void poison_pages ()
static void validate_free_objects ()
void ggc_collect ()
void ggc_print_statistics ()
struct ggc_pch_datainit_ggc_pch ()
void ggc_pch_count_object (struct ggc_pch_data *d, void *x, size_t size, bool is_string)
size_t ggc_pch_total_size ()
void ggc_pch_this_base ()
char * ggc_pch_alloc_object (struct ggc_pch_data *d, void *x, size_t size, bool is_string)
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, bool is_string)
void ggc_pch_finish ()
static void move_ptes_to_front ()
void ggc_pch_read ()

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]
struct {
   size_t   mult
   unsigned int   shift
inverse_table [NUM_ORDERS]
static struct globals G
static unsigned char size_lookup [NUM_SIZE_LOOKUP]

Typedef Documentation

typedef struct page_entry page_entry
A page_entry records the status of an allocation page.  This
   structure is dynamically sized to fit the bitmap in_use_p.   
typedef struct page_group page_group
A page_group describes a large allocation from malloc, from which
   we parcel out aligned pages.   
typedef struct page_table_chain * page_table
On 32-bit hosts, we use a two level page table, as pictured above.   
On 64-bit hosts, we use the same two level page tables plus a linked
   list that disambiguates the top 32-bits.  There will almost always be
   exactly one entry in the list.   

Function Documentation

static void adjust_depth ( )
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 globals::by_depth, globals::by_depth_in_use, page_entry::context_depth, globals::depth_in_use, and G.

Referenced by free_page().

static char* alloc_anon ( char *  ,
size_t  ,
bool  check 
)
static

Referenced by alloc_page(), and init_ggc().

static char* alloc_anon ( )
inlinestatic
Allocate SIZE bytes of anonymous memory, preferably near PREF,
   (if non-null).  The ifdef structure here is intended to cause a
   compile error unless exactly one of the HAVE_* is defined.   

References globals::bytes_mapped, globals::dev_zero_fd, G, page_entry::page, and pref.

static struct page_entry* alloc_page ( unsigned  )
staticread

Referenced by ggc_internal_alloc_stat().

static void clear_page_group_in_use ( page_group ,
char *   
)
static

Referenced by free_page().

static void clear_page_group_in_use ( )
inlinestatic
static void compute_inverse ( unsigned  )
static

Referenced by init_ggc().

static void compute_inverse ( )
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 inv().

void debug_print_page_list ( int  )
DEBUG_FUNCTION void debug_print_page_list ( )
Prints the page-entry for object size ORDER, for debugging.   

References page_entry::context_depth, G, page_entry::next, page_entry::num_free_objects, order, globals::page_tails, and globals::pages.

static void free_page ( struct page_entry )
static

Referenced by sweep_pages().

static int ggc_allocated_p ( const void *  )
static

Referenced by gt_ggc_m_S().

static int ggc_allocated_p ( )
inlinestatic
Returns nonzero if P was allocated in GC'able memory.   

References G, globals::lookup, and table.

size_t ggc_get_size ( )
Return the size of the gc-able object P.   

References lookup_page_table_entry(), and page_entry::order.

int ggc_marked_p ( )
Return 1 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 HOST_BITS_PER_LONG, page_entry::in_use_p, lookup_page_table_entry(), page_entry::order, and page_entry::page.

Referenced by ggc_prune_ptr(), maybe_delete_ident(), tree_map_base_marked_p(), and type_hash_marked_p().

char* ggc_pch_alloc_object ( struct ggc_pch_data ,
void *  ,
size_t  ,
bool   
)
Assuming that the objects really do end up at the address
   passed to ggc_pch_this_base, return the address of this object.
   The bool argument should be true if the object is a string.   

References ggc_pch_data::base, and order.

Referenced by ggc_call_alloc().

void ggc_pch_count_object ( struct ggc_pch_data ,
void *  ,
size_t  ,
bool   
)
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. The bool argument should be true
   if the object is a string.   

References ggc_pch_data::d, order, and ggc_pch_ondisk::totals.

Referenced by ggc_call_count().

void ggc_pch_finish ( )
void ggc_pch_prepare_write ( struct ggc_pch_data ,
FILE *   
)
Write out any initial information required.   

Referenced by gt_pch_save().

void ggc_pch_this_base ( )
size_t ggc_pch_total_size ( )
void ggc_pch_write_object ( struct ggc_pch_data ,
FILE *  ,
void *  ,
void *  ,
size_t  ,
bool   
)
Write out this object, including any padding.  The last argument should be
   true if the object is a string.   

References ggc_pch_data::d, fatal_error(), G, order, globals::pagesize, ggc_pch_ondisk::totals, and ggc_pch_data::written.

Referenced by gt_pch_save().

static void ggc_recalculate_in_use_p ( page_entry )
static

Referenced by sweep_pages().

static void ggc_recalculate_in_use_p ( )
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 page_entry::in_use_p, and page_entry::num_free_objects.

size_t ggc_round_alloc_size ( )
For a given size of memory requested for allocation, return the
   actual size that is going to be allocated.   

References ggc_round_alloc_size_1().

static void ggc_round_alloc_size_1 ( size_t  requested_size,
size_t *  size_order,
size_t *  alloced_size 
)
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 order.

Referenced by ggc_internal_alloc_stat(), and ggc_round_alloc_size().

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

References globals::debug_file, G, HOST_BITS_PER_LONG, page_entry::in_use_p, lookup_page_table_entry(), page_entry::num_free_objects, page_entry::order, and page_entry::page.

Referenced by ggc_scan_cache_tab().

void gt_ggc_mx ( )
User-callable entry points for marking string X.   

References gt_ggc_m_S().

struct ggc_pch_data* init_ggc_pch ( void  )
read
Return a new ggc_pch_data structure.   

Referenced by gt_pch_save().

static page_entry* lookup_page_table_entry ( const void *  )
static
static page_entry* lookup_page_table_entry ( )
inlinestatic
Traverse the page table and find the entry for a page.
   Die (probably) if the object wasn't allocated via GC.   

References G, globals::lookup, and table.

static void move_ptes_to_front ( int  ,
int   
)
static

Referenced by ggc_pch_read().

static void move_ptes_to_front ( )
static
Move the PCH PTE entries just added to the end of by_depth, to the
   front.   

References globals::by_depth, globals::by_depth_in_use, globals::by_depth_max, free(), G, page_entry::index_by_depth, memcpy(), push_depth(), and globals::save_in_use.

static size_t page_group_index ( char *  ,
char *   
)
static
static size_t page_group_index ( )
inlinestatic
Compute the index for this page into the page group.   

References G, and globals::lg_pagesize.

static void poison_pages ( )
static
static void push_by_depth ( page_entry ,
unsigned long *   
)
static
static void push_by_depth ( )
inlinestatic
Push an entry onto G.by_depth and G.save_in_use.   

References globals::by_depth, globals::by_depth_in_use, globals::by_depth_max, G, and globals::save_in_use.

static void push_depth ( unsigned  int)
static
static void push_depth ( )
inlinestatic
Push an entry onto G.depth.   

References globals::depth, globals::depth_in_use, globals::depth_max, and G.

static void set_page_group_in_use ( page_group ,
char *   
)
static

Referenced by alloc_page().

static void set_page_group_in_use ( )
inlinestatic
Set and clear the in_use bit for this page in the page group.   

References page_group::allocation, page_group::in_use, and page_group_index().

static void set_page_table_entry ( void *  ,
page_entry  
)
static

Referenced by alloc_page(), free_page(), and ggc_pch_read().

static void set_page_table_entry ( )
static
Set the page table entry for a page.   

References G, globals::lookup, and table.

static void sweep_pages ( )
static
Free all empty pages.  Partially empty pages need no attention
   because the `mark' bit doubles as an `unused' bit.   

References globals::allocated, page_entry::context_depth, globals::context_depth, free_page(), G, ggc_recalculate_in_use_p(), last, page_entry::next, page_entry::num_free_objects, order, globals::page_tails, globals::pages, and page_entry::prev.

Referenced by ggc_collect().

static void validate_free_objects ( )
static

Variable Documentation

const size_t extra_order_size_table[]
static
Initial value:
{
MAX_ALIGNMENT * 3,
MAX_ALIGNMENT * 5,
MAX_ALIGNMENT * 6,
MAX_ALIGNMENT * 7,
MAX_ALIGNMENT * 9,
MAX_ALIGNMENT * 10,
MAX_ALIGNMENT * 11,
MAX_ALIGNMENT * 12,
MAX_ALIGNMENT * 13,
MAX_ALIGNMENT * 14,
MAX_ALIGNMENT * 15,
sizeof (struct tree_decl_non_common),
sizeof (struct tree_field_decl),
sizeof (struct tree_parm_decl),
sizeof (struct tree_var_decl),
sizeof (struct tree_type_non_common),
sizeof (struct function),
sizeof (struct basic_block_def),
sizeof (struct cgraph_node),
sizeof (struct loop),
}
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().

struct { ... } inverse_table[NUM_ORDERS]
The Ith entry is a pair of numbers (mult, shift) such that
   ((k * mult) >> shift) mod 2^32 == (k / OBJECT_SIZE(I)) mod 2^32,
   for all k evenly divisible by OBJECT_SIZE(I).   
size_t object_size_table[NUM_ORDERS]
static
The Ith entry is the size of an object on a page of order I.   
unsigned objects_per_page_table[NUM_ORDERS]
static
The Ith entry is the number of objects on a page or order I.   
unsigned char size_lookup[NUM_SIZE_LOOKUP]
static