Mercurial > hg > CbC > CbC_gcc
diff gcc/ggc-page.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
line wrap: on
line diff
--- a/gcc/ggc-page.c Thu Oct 25 07:37:49 2018 +0900 +++ b/gcc/ggc-page.c Thu Feb 13 11:34:05 2020 +0900 @@ -1,5 +1,5 @@ /* "Bag-of-pages" garbage collector for the GNU compiler. - Copyright (C) 1999-2018 Free Software Foundation, Inc. + Copyright (C) 1999-2020 Free Software Foundation, Inc. This file is part of GCC. @@ -30,7 +30,6 @@ #include "flags.h" #include "ggc-internal.h" #include "timevar.h" -#include "params.h" #include "cgraph.h" #include "cfgloop.h" #include "plugin.h" @@ -200,7 +199,7 @@ sizeof (struct function), sizeof (struct basic_block_def), sizeof (struct cgraph_node), - sizeof (struct loop), + sizeof (class loop), }; /* The total number of orders. */ @@ -529,7 +528,6 @@ #endif static struct page_entry * alloc_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 *); @@ -943,8 +941,8 @@ if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "Allocating page at %p, object size=%lu, data %p-%p\n", - (void *) entry, (unsigned long) OBJECT_SIZE (order), page, - page + entry_size - 1); + (void *) entry, (unsigned long) OBJECT_SIZE (order), + (void *) page, (void *) (page + entry_size - 1)); return entry; } @@ -977,7 +975,7 @@ if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "Deallocating page at %p, data %p-%p\n", (void *) entry, - entry->page, entry->page + entry->bytes - 1); + (void *) entry->page, (void *) (entry->page + entry->bytes - 1)); /* Mark the page as inaccessible. Discard the handle to avoid handle leak. */ @@ -1016,6 +1014,8 @@ static void release_pages (void) { + size_t n1 = 0; + size_t n2 = 0; #ifdef USING_MADVISE page_entry *p, *start_p; char *start; @@ -1061,6 +1061,7 @@ else G.free_pages = p; G.bytes_mapped -= mapped_len; + n1 += len; continue; } prev = newprev; @@ -1092,6 +1093,7 @@ /* Don't count those pages as mapped to not touch the garbage collector unnecessarily. */ G.bytes_mapped -= len; + n2 += len; while (start_p != p) { start_p->discarded = true; @@ -1124,6 +1126,7 @@ } munmap (start, len); + n1 += len; G.bytes_mapped -= len; } @@ -1151,11 +1154,21 @@ { *gp = g->next; G.bytes_mapped -= g->alloc_size; + n1 += g->alloc_size; free (g->allocation); } else gp = &g->next; #endif + if (!quiet_flag && (n1 || n2)) + { + fprintf (stderr, " {GC"); + if (n1) + fprintf (stderr, " released %luk", (unsigned long)(n1 / 1024)); + if (n2) + fprintf (stderr, " madv_dontneed %luk", (unsigned long)(n2 / 1024)); + fprintf (stderr, "}"); + } } /* This table provides a fast way to determine ceil(log_2(size)) for @@ -2171,26 +2184,32 @@ total allocations haven't expanded much since the last collection. */ float allocated_last_gc = - MAX (G.allocated_last_gc, (size_t)PARAM_VALUE (GGC_MIN_HEAPSIZE) * 1024); - - float min_expand = allocated_last_gc * PARAM_VALUE (GGC_MIN_EXPAND) / 100; + MAX (G.allocated_last_gc, (size_t)param_ggc_min_heapsize * 1024); + + /* It is also good time to get memory block pool into limits. */ + memory_block_pool::trim (); + + float min_expand = allocated_last_gc * param_ggc_min_expand / 100; if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect) return; timevar_push (TV_GC); - if (!quiet_flag) - fprintf (stderr, " {GC %luk -> ", (unsigned long) G.allocated / 1024); if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "BEGIN COLLECTING\n"); /* Zero the total allocated bytes. This will be recalculated in the sweep phase. */ + size_t allocated = G.allocated; G.allocated = 0; /* Release the pages we freed the last time we collected, but didn't reuse in the interim. */ release_pages (); + /* Output this later so we do not interfere with release_pages. */ + if (!quiet_flag) + fprintf (stderr, " {GC %luk -> ", (unsigned long) allocated / 1024); + /* Indicate that we've seen collections at this context depth. */ G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1; @@ -2221,9 +2240,25 @@ fprintf (G.debug_file, "END COLLECTING\n"); } -/* Assume that all GGC memory is reachable and grow the limits for next collection. - With checking, trigger GGC so -Q compilation outputs how much of memory really is - reachable. */ +/* Return free pages to the system. */ + +void +ggc_trim () +{ + timevar_push (TV_GC); + G.allocated = 0; + sweep_pages (); + release_pages (); + if (!quiet_flag) + fprintf (stderr, " {GC trimmed to %luk, %luk mapped}", + (unsigned long) G.allocated / 1024, + (unsigned long) G.bytes_mapped / 1024); + timevar_pop (TV_GC); +} + +/* Assume that all GGC memory is reachable and grow the limits for next + collection. With checking, trigger GGC so -Q compilation outputs how much + of memory really is reachable. */ void ggc_grow (void) @@ -2234,17 +2269,9 @@ else ggc_collect (); if (!quiet_flag) - fprintf (stderr, " {GC start %luk} ", (unsigned long) G.allocated / 1024); + fprintf (stderr, " {GC %luk} ", (unsigned long) G.allocated / 1024); } -/* Print allocation statistics. */ -#define SCALE(x) ((unsigned long) ((x) < 1024*10 \ - ? (x) \ - : ((x) < 1024*1024*10 \ - ? (x) / 1024 \ - : (x) / (1024*1024)))) -#define STAT_LABEL(x) ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M')) - void ggc_print_statistics (void) { @@ -2296,53 +2323,62 @@ overhead += (sizeof (page_entry) - sizeof (long) + BITMAP_SIZE (OBJECTS_IN_PAGE (p) + 1)); } - fprintf (stderr, "%-8lu %10lu%c %10lu%c %10lu%c\n", - (unsigned long) OBJECT_SIZE (i), - SCALE (allocated), STAT_LABEL (allocated), - SCALE (in_use), STAT_LABEL (in_use), - SCALE (overhead), STAT_LABEL (overhead)); + fprintf (stderr, "%-8" PRIu64 " " PRsa (10) " " PRsa (10) " " + PRsa (10) "\n", + (uint64_t)OBJECT_SIZE (i), + SIZE_AMOUNT (allocated), + SIZE_AMOUNT (in_use), + SIZE_AMOUNT (overhead)); total_overhead += overhead; } - fprintf (stderr, "%-8s %10lu%c %10lu%c %10lu%c\n", "Total", - SCALE (G.bytes_mapped), STAT_LABEL (G.bytes_mapped), - SCALE (G.allocated), STAT_LABEL (G.allocated), - SCALE (total_overhead), STAT_LABEL (total_overhead)); + fprintf (stderr, "%-8s " PRsa (10) " " PRsa (10) " " PRsa (10) "\n", + "Total", + SIZE_AMOUNT (G.bytes_mapped), + SIZE_AMOUNT (G.allocated), + SIZE_AMOUNT (total_overhead)); 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); + fprintf (stderr, "Total Overhead: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_overhead)); + fprintf (stderr, "Total Allocated: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_allocated)); + + fprintf (stderr, "Total Overhead under 32B: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_overhead_under32)); + fprintf (stderr, "Total Allocated under 32B: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_allocated_under32)); + fprintf (stderr, "Total Overhead under 64B: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_overhead_under64)); + fprintf (stderr, "Total Allocated under 64B: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_allocated_under64)); + fprintf (stderr, "Total Overhead under 128B: " + PRsa (9) "\n", + SIZE_AMOUNT (G.stats.total_overhead_under128)); + fprintf (stderr, "Total Allocated under 128B: " + PRsa (9) "\n", + SIZE_AMOUNT (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 %9lu: %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 %9lu: %10" - HOST_LONG_LONG_FORMAT "d\n", - (unsigned long) OBJECT_SIZE (i), - G.stats.total_allocated_per_order[i]); + fprintf (stderr, "Total Overhead page size %9" PRIu64 ": " + PRsa (9) "\n", + (uint64_t)OBJECT_SIZE (i), + SIZE_AMOUNT (G.stats.total_overhead_per_order[i])); + fprintf (stderr, "Total Allocated page size %9" PRIu64 ": " + PRsa (9) "\n", + (uint64_t)OBJECT_SIZE (i), + SIZE_AMOUNT (G.stats.total_allocated_per_order[i])); } } } @@ -2454,7 +2490,7 @@ } if (fwrite (x, size, 1, f) != 1) - fatal_error (input_location, "can%'t write PCH file: %m"); + fatal_error (input_location, "cannot write PCH file: %m"); /* If SIZE is not the same as OBJECT_SIZE(order), then we need to pad the object out to OBJECT_SIZE(order). This happens for strings. */ @@ -2470,13 +2506,13 @@ if (padding <= sizeof (emptyBytes)) { if (fwrite (emptyBytes, 1, padding, f) != padding) - fatal_error (input_location, "can%'t write PCH file"); + fatal_error (input_location, "cannot write PCH file"); } else { /* Larger than our buffer? Just default to fseek. */ if (fseek (f, padding, SEEK_CUR) != 0) - fatal_error (input_location, "can%'t write PCH file"); + fatal_error (input_location, "cannot write PCH file"); } } @@ -2485,14 +2521,14 @@ && fseek (f, ROUND_UP_VALUE (d->d.totals[order] * OBJECT_SIZE (order), G.pagesize), SEEK_CUR) != 0) - fatal_error (input_location, "can%'t write PCH file: %m"); + fatal_error (input_location, "cannot write PCH file: %m"); } void ggc_pch_finish (struct ggc_pch_data *d, FILE *f) { if (fwrite (&d->d, sizeof (d->d), 1, f) != 1) - fatal_error (input_location, "can%'t write PCH file: %m"); + fatal_error (input_location, "cannot write PCH file: %m"); free (d); } @@ -2555,6 +2591,9 @@ count_old_page_tables = G.by_depth_in_use; + if (fread (&d, sizeof (d), 1, f) != 1) + fatal_error (input_location, "cannot read PCH file: %m"); + /* We've just read in a PCH file. So, every object that used to be allocated is now free. */ clear_marks (); @@ -2583,8 +2622,6 @@ /* Allocate the appropriate page-table entries for the pages read from the PCH file. */ - if (fread (&d, sizeof (d), 1, f) != 1) - fatal_error (input_location, "can%'t read PCH file: %m"); for (i = 0; i < NUM_ORDERS; i++) {