/* "Bag-of-pages" garbage collector for the GNU compiler.
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
- 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1999-2013 Free Software Foundation, Inc.
This file is part of GCC.
#define PAGE_L1_BITS (8)
#define PAGE_L2_BITS (32 - PAGE_L1_BITS - G.lg_pagesize)
-#define PAGE_L1_SIZE ((size_t) 1 << PAGE_L1_BITS)
-#define PAGE_L2_SIZE ((size_t) 1 << PAGE_L2_BITS)
+#define PAGE_L1_SIZE ((uintptr_t) 1 << PAGE_L1_BITS)
+#define PAGE_L2_SIZE ((uintptr_t) 1 << PAGE_L2_BITS)
#define LOOKUP_L1(p) \
- (((size_t) (p) >> (32 - PAGE_L1_BITS)) & ((1 << PAGE_L1_BITS) - 1))
+ (((uintptr_t) (p) >> (32 - PAGE_L1_BITS)) & ((1 << PAGE_L1_BITS) - 1))
#define LOOKUP_L2(p) \
- (((size_t) (p) >> G.lg_pagesize) & ((1 << PAGE_L2_BITS) - 1))
+ (((uintptr_t) (p) >> G.lg_pagesize) & ((1 << PAGE_L2_BITS) - 1))
/* The number of objects per allocation page, for objects on a page of
the indicated ORDER. */
struct free_object *free_object_list;
#endif
-#ifdef GATHER_STATISTICS
struct
{
/* Total GC-allocated memory. */
/* The overhead for each of the allocation orders. */
unsigned long long total_overhead_per_order[NUM_ORDERS];
} stats;
-#endif
} G;
/* The size in bytes required to maintain a bitmap for the objects
base = &G.lookup[0];
#else
page_table table = G.lookup;
- size_t high_bits = (size_t) p & ~ (size_t) 0xffffffff;
+ uintptr_t high_bits = (uintptr_t) p & ~ (uintptr_t) 0xffffffff;
while (1)
{
if (table == NULL)
base = &G.lookup[0];
#else
page_table table = G.lookup;
- size_t high_bits = (size_t) p & ~ (size_t) 0xffffffff;
+ uintptr_t high_bits = (uintptr_t) p & ~ (uintptr_t) 0xffffffff;
while (table->high_bits != high_bits)
table = table->next;
base = &table->table[0];
base = &G.lookup[0];
#else
page_table table;
- size_t high_bits = (size_t) p & ~ (size_t) 0xffffffff;
+ uintptr_t high_bits = (uintptr_t) p & ~ (uintptr_t) 0xffffffff;
for (table = G.lookup; table; table = table->next)
if (table->high_bits == high_bits)
goto found;
alloc_size = entry_size + G.pagesize - 1;
allocation = XNEWVEC (char, alloc_size);
- page = (char *) (((size_t) allocation + G.pagesize - 1) & -G.pagesize);
+ page = (char *) (((uintptr_t) allocation + G.pagesize - 1) & -G.pagesize);
head_slop = page - allocation;
if (multiple_pages)
tail_slop = ((size_t) allocation + alloc_size) & (G.pagesize - 1);
return size;
}
-/* Typed allocation function. Does nothing special in this collector. */
-
-void *
-ggc_alloc_typed_stat (enum gt_types_enum type ATTRIBUTE_UNUSED, size_t size
- MEM_STAT_DECL)
-{
- return ggc_internal_alloc_stat (size PASS_MEM_STAT);
-}
-
/* Allocate a chunk of memory of SIZE bytes. Its contents are undefined. */
void *
/* Calculate the object's address. */
result = entry->page + object_offset;
-#ifdef GATHER_STATISTICS
- ggc_record_overhead (OBJECT_SIZE (order), OBJECT_SIZE (order) - size,
- result PASS_MEM_STAT);
-#endif
+ if (GATHER_STATISTICS)
+ ggc_record_overhead (OBJECT_SIZE (order), OBJECT_SIZE (order) - size,
+ result FINAL_PASS_MEM_STAT);
#ifdef ENABLE_GC_CHECKING
/* Keep poisoning-by-writing-0xaf the object, in an attempt to keep the
/* For timevar statistics. */
timevar_ggc_mem_total += object_size;
-#ifdef GATHER_STATISTICS
- {
- size_t overhead = object_size - size;
+ if (GATHER_STATISTICS)
+ {
+ size_t overhead = object_size - size;
- G.stats.total_overhead += overhead;
- G.stats.total_allocated += object_size;
- G.stats.total_overhead_per_order[order] += overhead;
- G.stats.total_allocated_per_order[order] += object_size;
+ G.stats.total_overhead += overhead;
+ G.stats.total_allocated += object_size;
+ G.stats.total_overhead_per_order[order] += overhead;
+ G.stats.total_allocated_per_order[order] += object_size;
- if (size <= 32)
- {
- G.stats.total_overhead_under32 += overhead;
- G.stats.total_allocated_under32 += object_size;
- }
- if (size <= 64)
- {
- G.stats.total_overhead_under64 += overhead;
- G.stats.total_allocated_under64 += object_size;
- }
- if (size <= 128)
- {
- G.stats.total_overhead_under128 += overhead;
- G.stats.total_allocated_under128 += object_size;
- }
- }
-#endif
+ if (size <= 32)
+ {
+ G.stats.total_overhead_under32 += overhead;
+ G.stats.total_allocated_under32 += object_size;
+ }
+ if (size <= 64)
+ {
+ G.stats.total_overhead_under64 += overhead;
+ G.stats.total_allocated_under64 += object_size;
+ }
+ if (size <= 128)
+ {
+ G.stats.total_overhead_under128 += overhead;
+ G.stats.total_allocated_under128 += object_size;
+ }
+ }
if (GGC_DEBUG_LEVEL >= 3)
fprintf (G.debug_file,
return;
}
+
+/* User-callable entry points for marking string X. */
+
+void
+gt_ggc_mx (const char *& x)
+{
+ gt_ggc_m_S (x);
+}
+
+void
+gt_ggc_mx (unsigned char *& x)
+{
+ gt_ggc_m_S (x);
+}
+
+void
+gt_ggc_mx (unsigned char& x ATTRIBUTE_UNUSED)
+{
+}
+
/* 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. */
size_t order = pe->order;
size_t size = OBJECT_SIZE (order);
-#ifdef GATHER_STATISTICS
- ggc_free_overhead (p);
-#endif
+ if (GATHER_STATISTICS)
+ ggc_free_overhead (p);
if (GGC_DEBUG_LEVEL >= 3)
fprintf (G.debug_file,
{
char *p = alloc_anon (NULL, G.pagesize, true);
struct page_entry *e;
- if ((size_t)p & (G.pagesize - 1))
+ if ((uintptr_t)p & (G.pagesize - 1))
{
/* How losing. Discard this one and try another. If we still
can't get something useful, give up. */
p = alloc_anon (NULL, G.pagesize, true);
- gcc_assert (!((size_t)p & (G.pagesize - 1)));
+ gcc_assert (!((uintptr_t)p & (G.pagesize - 1)));
}
/* We have a good page, might as well hold onto it... */
size_t bitmap_size = BITMAP_SIZE (num_objects + 1);
/* The data should be page-aligned. */
- gcc_assert (!((size_t) p->page & (G.pagesize - 1)));
+ gcc_assert (!((uintptr_t) p->page & (G.pagesize - 1)));
/* Pages that aren't in the topmost context are not collected;
nevertheless, we need their in-use bit vectors to store GC
clear_marks ();
ggc_mark_roots ();
-#ifdef GATHER_STATISTICS
- ggc_prune_overhead_list ();
-#endif
+
+ if (GATHER_STATISTICS)
+ ggc_prune_overhead_list ();
+
poison_pages ();
validate_free_objects ();
sweep_pages ();
SCALE (G.allocated), STAT_LABEL(G.allocated),
SCALE (total_overhead), STAT_LABEL (total_overhead));
-#ifdef GATHER_STATISTICS
- {
- fprintf (stderr, "\nTotal allocations and overheads during the compilation process\n");
-
- fprintf (stderr, "Total Overhead: %10lld\n",
- G.stats.total_overhead);
- fprintf (stderr, "Total Allocated: %10lld\n",
- G.stats.total_allocated);
-
- fprintf (stderr, "Total Overhead under 32B: %10lld\n",
- G.stats.total_overhead_under32);
- fprintf (stderr, "Total Allocated under 32B: %10lld\n",
- G.stats.total_allocated_under32);
- fprintf (stderr, "Total Overhead under 64B: %10lld\n",
- G.stats.total_overhead_under64);
- fprintf (stderr, "Total Allocated under 64B: %10lld\n",
- G.stats.total_allocated_under64);
- fprintf (stderr, "Total Overhead under 128B: %10lld\n",
- G.stats.total_overhead_under128);
- fprintf (stderr, "Total Allocated under 128B: %10lld\n",
- G.stats.total_allocated_under128);
-
- for (i = 0; i < NUM_ORDERS; i++)
- if (G.stats.total_allocated_per_order[i])
- {
- fprintf (stderr, "Total Overhead page size %7lu: %10lld\n",
- (unsigned long) OBJECT_SIZE (i),
- G.stats.total_overhead_per_order[i]);
- fprintf (stderr, "Total Allocated page size %7lu: %10lld\n",
- (unsigned long) OBJECT_SIZE (i),
- G.stats.total_allocated_per_order[i]);
- }
+ if (GATHER_STATISTICS)
+ {
+ fprintf (stderr, "\nTotal allocations and overheads during the compilation process\n");
+
+ fprintf (stderr, "Total Overhead: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_overhead);
+ fprintf (stderr, "Total Allocated: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_allocated);
+
+ fprintf (stderr, "Total Overhead under 32B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_overhead_under32);
+ fprintf (stderr, "Total Allocated under 32B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_allocated_under32);
+ fprintf (stderr, "Total Overhead under 64B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_overhead_under64);
+ fprintf (stderr, "Total Allocated under 64B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_allocated_under64);
+ fprintf (stderr, "Total Overhead under 128B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_overhead_under128);
+ fprintf (stderr, "Total Allocated under 128B: %10" HOST_LONG_LONG_FORMAT "d\n",
+ G.stats.total_allocated_under128);
+
+ for (i = 0; i < NUM_ORDERS; i++)
+ if (G.stats.total_allocated_per_order[i])
+ {
+ fprintf (stderr, "Total Overhead page size %7lu: %10" HOST_LONG_LONG_FORMAT "d\n",
+ (unsigned long) OBJECT_SIZE (i),
+ G.stats.total_overhead_per_order[i]);
+ fprintf (stderr, "Total Allocated page size %7lu: %10" HOST_LONG_LONG_FORMAT "d\n",
+ (unsigned long) OBJECT_SIZE (i),
+ G.stats.total_allocated_per_order[i]);
+ }
}
-#endif
}
\f
struct ggc_pch_ondisk
struct ggc_pch_data
{
struct ggc_pch_ondisk d;
- size_t base[NUM_ORDERS];
+ uintptr_t base[NUM_ORDERS];
size_t written[NUM_ORDERS];
};
void
ggc_pch_count_object (struct ggc_pch_data *d, void *x ATTRIBUTE_UNUSED,
- size_t size, bool is_string ATTRIBUTE_UNUSED,
- enum gt_types_enum type ATTRIBUTE_UNUSED)
+ size_t size, bool is_string ATTRIBUTE_UNUSED)
{
unsigned order;
void
ggc_pch_this_base (struct ggc_pch_data *d, void *base)
{
- size_t a = (size_t) base;
+ uintptr_t a = (uintptr_t) base;
unsigned i;
for (i = 0; i < NUM_ORDERS; i++)
char *
ggc_pch_alloc_object (struct ggc_pch_data *d, void *x ATTRIBUTE_UNUSED,
- size_t size, bool is_string ATTRIBUTE_UNUSED,
- enum gt_types_enum type ATTRIBUTE_UNUSED)
+ size_t size, bool is_string ATTRIBUTE_UNUSED)
{
unsigned order;
char *result;
/* Update the statistics. */
G.allocated = G.allocated_last_gc = offs - (char *)addr;
}
-
-struct alloc_zone
-{
- int dummy;
-};
-
-struct alloc_zone rtl_zone;
-struct alloc_zone tree_zone;
-struct alloc_zone tree_id_zone;