Mercurial > hg > CbC > CbC_gcc
comparison gcc/ggc-page.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* "Bag-of-pages" garbage collector for the GNU compiler. | 1 /* "Bag-of-pages" garbage collector for the GNU compiler. |
2 Copyright (C) 1999-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1999-2020 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
28 #include "tm_p.h" | 28 #include "tm_p.h" |
29 #include "diagnostic-core.h" | 29 #include "diagnostic-core.h" |
30 #include "flags.h" | 30 #include "flags.h" |
31 #include "ggc-internal.h" | 31 #include "ggc-internal.h" |
32 #include "timevar.h" | 32 #include "timevar.h" |
33 #include "params.h" | |
34 #include "cgraph.h" | 33 #include "cgraph.h" |
35 #include "cfgloop.h" | 34 #include "cfgloop.h" |
36 #include "plugin.h" | 35 #include "plugin.h" |
37 | 36 |
38 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a | 37 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a |
198 sizeof (struct tree_var_decl), | 197 sizeof (struct tree_var_decl), |
199 sizeof (struct tree_type_non_common), | 198 sizeof (struct tree_type_non_common), |
200 sizeof (struct function), | 199 sizeof (struct function), |
201 sizeof (struct basic_block_def), | 200 sizeof (struct basic_block_def), |
202 sizeof (struct cgraph_node), | 201 sizeof (struct cgraph_node), |
203 sizeof (struct loop), | 202 sizeof (class loop), |
204 }; | 203 }; |
205 | 204 |
206 /* The total number of orders. */ | 205 /* The total number of orders. */ |
207 | 206 |
208 #define NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS) | 207 #define NUM_ORDERS (HOST_BITS_PER_PTR + NUM_EXTRA_ORDERS) |
527 static void set_page_group_in_use (page_group *, char *); | 526 static void set_page_group_in_use (page_group *, char *); |
528 static void clear_page_group_in_use (page_group *, char *); | 527 static void clear_page_group_in_use (page_group *, char *); |
529 #endif | 528 #endif |
530 static struct page_entry * alloc_page (unsigned); | 529 static struct page_entry * alloc_page (unsigned); |
531 static void free_page (struct page_entry *); | 530 static void free_page (struct page_entry *); |
532 static void release_pages (void); | |
533 static void clear_marks (void); | 531 static void clear_marks (void); |
534 static void sweep_pages (void); | 532 static void sweep_pages (void); |
535 static void ggc_recalculate_in_use_p (page_entry *); | 533 static void ggc_recalculate_in_use_p (page_entry *); |
536 static void compute_inverse (unsigned); | 534 static void compute_inverse (unsigned); |
537 static inline void adjust_depth (void); | 535 static inline void adjust_depth (void); |
941 set_page_table_entry (page, entry); | 939 set_page_table_entry (page, entry); |
942 | 940 |
943 if (GGC_DEBUG_LEVEL >= 2) | 941 if (GGC_DEBUG_LEVEL >= 2) |
944 fprintf (G.debug_file, | 942 fprintf (G.debug_file, |
945 "Allocating page at %p, object size=%lu, data %p-%p\n", | 943 "Allocating page at %p, object size=%lu, data %p-%p\n", |
946 (void *) entry, (unsigned long) OBJECT_SIZE (order), page, | 944 (void *) entry, (unsigned long) OBJECT_SIZE (order), |
947 page + entry_size - 1); | 945 (void *) page, (void *) (page + entry_size - 1)); |
948 | 946 |
949 return entry; | 947 return entry; |
950 } | 948 } |
951 | 949 |
952 /* Adjust the size of G.depth so that no index greater than the one | 950 /* Adjust the size of G.depth so that no index greater than the one |
975 free_page (page_entry *entry) | 973 free_page (page_entry *entry) |
976 { | 974 { |
977 if (GGC_DEBUG_LEVEL >= 2) | 975 if (GGC_DEBUG_LEVEL >= 2) |
978 fprintf (G.debug_file, | 976 fprintf (G.debug_file, |
979 "Deallocating page at %p, data %p-%p\n", (void *) entry, | 977 "Deallocating page at %p, data %p-%p\n", (void *) entry, |
980 entry->page, entry->page + entry->bytes - 1); | 978 (void *) entry->page, (void *) (entry->page + entry->bytes - 1)); |
981 | 979 |
982 /* Mark the page as inaccessible. Discard the handle to avoid handle | 980 /* Mark the page as inaccessible. Discard the handle to avoid handle |
983 leak. */ | 981 leak. */ |
984 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (entry->page, entry->bytes)); | 982 VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (entry->page, entry->bytes)); |
985 | 983 |
1014 /* Release the free page cache to the system. */ | 1012 /* Release the free page cache to the system. */ |
1015 | 1013 |
1016 static void | 1014 static void |
1017 release_pages (void) | 1015 release_pages (void) |
1018 { | 1016 { |
1017 size_t n1 = 0; | |
1018 size_t n2 = 0; | |
1019 #ifdef USING_MADVISE | 1019 #ifdef USING_MADVISE |
1020 page_entry *p, *start_p; | 1020 page_entry *p, *start_p; |
1021 char *start; | 1021 char *start; |
1022 size_t len; | 1022 size_t len; |
1023 size_t mapped_len; | 1023 size_t mapped_len; |
1059 if (prev) | 1059 if (prev) |
1060 prev->next = p; | 1060 prev->next = p; |
1061 else | 1061 else |
1062 G.free_pages = p; | 1062 G.free_pages = p; |
1063 G.bytes_mapped -= mapped_len; | 1063 G.bytes_mapped -= mapped_len; |
1064 n1 += len; | |
1064 continue; | 1065 continue; |
1065 } | 1066 } |
1066 prev = newprev; | 1067 prev = newprev; |
1067 } | 1068 } |
1068 | 1069 |
1090 process. Next time we can reuse it by just touching it. */ | 1091 process. Next time we can reuse it by just touching it. */ |
1091 madvise (start, len, MADV_DONTNEED); | 1092 madvise (start, len, MADV_DONTNEED); |
1092 /* Don't count those pages as mapped to not touch the garbage collector | 1093 /* Don't count those pages as mapped to not touch the garbage collector |
1093 unnecessarily. */ | 1094 unnecessarily. */ |
1094 G.bytes_mapped -= len; | 1095 G.bytes_mapped -= len; |
1096 n2 += len; | |
1095 while (start_p != p) | 1097 while (start_p != p) |
1096 { | 1098 { |
1097 start_p->discarded = true; | 1099 start_p->discarded = true; |
1098 start_p = start_p->next; | 1100 start_p = start_p->next; |
1099 } | 1101 } |
1122 free (p); | 1124 free (p); |
1123 p = next; | 1125 p = next; |
1124 } | 1126 } |
1125 | 1127 |
1126 munmap (start, len); | 1128 munmap (start, len); |
1129 n1 += len; | |
1127 G.bytes_mapped -= len; | 1130 G.bytes_mapped -= len; |
1128 } | 1131 } |
1129 | 1132 |
1130 G.free_pages = NULL; | 1133 G.free_pages = NULL; |
1131 #endif | 1134 #endif |
1149 while ((g = *gp) != NULL) | 1152 while ((g = *gp) != NULL) |
1150 if (g->in_use == 0) | 1153 if (g->in_use == 0) |
1151 { | 1154 { |
1152 *gp = g->next; | 1155 *gp = g->next; |
1153 G.bytes_mapped -= g->alloc_size; | 1156 G.bytes_mapped -= g->alloc_size; |
1157 n1 += g->alloc_size; | |
1154 free (g->allocation); | 1158 free (g->allocation); |
1155 } | 1159 } |
1156 else | 1160 else |
1157 gp = &g->next; | 1161 gp = &g->next; |
1158 #endif | 1162 #endif |
1163 if (!quiet_flag && (n1 || n2)) | |
1164 { | |
1165 fprintf (stderr, " {GC"); | |
1166 if (n1) | |
1167 fprintf (stderr, " released %luk", (unsigned long)(n1 / 1024)); | |
1168 if (n2) | |
1169 fprintf (stderr, " madv_dontneed %luk", (unsigned long)(n2 / 1024)); | |
1170 fprintf (stderr, "}"); | |
1171 } | |
1159 } | 1172 } |
1160 | 1173 |
1161 /* This table provides a fast way to determine ceil(log_2(size)) for | 1174 /* This table provides a fast way to determine ceil(log_2(size)) for |
1162 allocation requests. The minimum allocation size is eight bytes. */ | 1175 allocation requests. The minimum allocation size is eight bytes. */ |
1163 #define NUM_SIZE_LOOKUP 512 | 1176 #define NUM_SIZE_LOOKUP 512 |
2169 { | 2182 { |
2170 /* Avoid frequent unnecessary work by skipping collection if the | 2183 /* Avoid frequent unnecessary work by skipping collection if the |
2171 total allocations haven't expanded much since the last | 2184 total allocations haven't expanded much since the last |
2172 collection. */ | 2185 collection. */ |
2173 float allocated_last_gc = | 2186 float allocated_last_gc = |
2174 MAX (G.allocated_last_gc, (size_t)PARAM_VALUE (GGC_MIN_HEAPSIZE) * 1024); | 2187 MAX (G.allocated_last_gc, (size_t)param_ggc_min_heapsize * 1024); |
2175 | 2188 |
2176 float min_expand = allocated_last_gc * PARAM_VALUE (GGC_MIN_EXPAND) / 100; | 2189 /* It is also good time to get memory block pool into limits. */ |
2190 memory_block_pool::trim (); | |
2191 | |
2192 float min_expand = allocated_last_gc * param_ggc_min_expand / 100; | |
2177 if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect) | 2193 if (G.allocated < allocated_last_gc + min_expand && !ggc_force_collect) |
2178 return; | 2194 return; |
2179 | 2195 |
2180 timevar_push (TV_GC); | 2196 timevar_push (TV_GC); |
2181 if (!quiet_flag) | |
2182 fprintf (stderr, " {GC %luk -> ", (unsigned long) G.allocated / 1024); | |
2183 if (GGC_DEBUG_LEVEL >= 2) | 2197 if (GGC_DEBUG_LEVEL >= 2) |
2184 fprintf (G.debug_file, "BEGIN COLLECTING\n"); | 2198 fprintf (G.debug_file, "BEGIN COLLECTING\n"); |
2185 | 2199 |
2186 /* Zero the total allocated bytes. This will be recalculated in the | 2200 /* Zero the total allocated bytes. This will be recalculated in the |
2187 sweep phase. */ | 2201 sweep phase. */ |
2202 size_t allocated = G.allocated; | |
2188 G.allocated = 0; | 2203 G.allocated = 0; |
2189 | 2204 |
2190 /* Release the pages we freed the last time we collected, but didn't | 2205 /* Release the pages we freed the last time we collected, but didn't |
2191 reuse in the interim. */ | 2206 reuse in the interim. */ |
2192 release_pages (); | 2207 release_pages (); |
2208 | |
2209 /* Output this later so we do not interfere with release_pages. */ | |
2210 if (!quiet_flag) | |
2211 fprintf (stderr, " {GC %luk -> ", (unsigned long) allocated / 1024); | |
2193 | 2212 |
2194 /* Indicate that we've seen collections at this context depth. */ | 2213 /* Indicate that we've seen collections at this context depth. */ |
2195 G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1; | 2214 G.context_depth_collections = ((unsigned long)1 << (G.context_depth + 1)) - 1; |
2196 | 2215 |
2197 invoke_plugin_callbacks (PLUGIN_GGC_START, NULL); | 2216 invoke_plugin_callbacks (PLUGIN_GGC_START, NULL); |
2219 fprintf (stderr, "%luk}", (unsigned long) G.allocated / 1024); | 2238 fprintf (stderr, "%luk}", (unsigned long) G.allocated / 1024); |
2220 if (GGC_DEBUG_LEVEL >= 2) | 2239 if (GGC_DEBUG_LEVEL >= 2) |
2221 fprintf (G.debug_file, "END COLLECTING\n"); | 2240 fprintf (G.debug_file, "END COLLECTING\n"); |
2222 } | 2241 } |
2223 | 2242 |
2224 /* Assume that all GGC memory is reachable and grow the limits for next collection. | 2243 /* Return free pages to the system. */ |
2225 With checking, trigger GGC so -Q compilation outputs how much of memory really is | 2244 |
2226 reachable. */ | 2245 void |
2246 ggc_trim () | |
2247 { | |
2248 timevar_push (TV_GC); | |
2249 G.allocated = 0; | |
2250 sweep_pages (); | |
2251 release_pages (); | |
2252 if (!quiet_flag) | |
2253 fprintf (stderr, " {GC trimmed to %luk, %luk mapped}", | |
2254 (unsigned long) G.allocated / 1024, | |
2255 (unsigned long) G.bytes_mapped / 1024); | |
2256 timevar_pop (TV_GC); | |
2257 } | |
2258 | |
2259 /* Assume that all GGC memory is reachable and grow the limits for next | |
2260 collection. With checking, trigger GGC so -Q compilation outputs how much | |
2261 of memory really is reachable. */ | |
2227 | 2262 |
2228 void | 2263 void |
2229 ggc_grow (void) | 2264 ggc_grow (void) |
2230 { | 2265 { |
2231 if (!flag_checking) | 2266 if (!flag_checking) |
2232 G.allocated_last_gc = MAX (G.allocated_last_gc, | 2267 G.allocated_last_gc = MAX (G.allocated_last_gc, |
2233 G.allocated); | 2268 G.allocated); |
2234 else | 2269 else |
2235 ggc_collect (); | 2270 ggc_collect (); |
2236 if (!quiet_flag) | 2271 if (!quiet_flag) |
2237 fprintf (stderr, " {GC start %luk} ", (unsigned long) G.allocated / 1024); | 2272 fprintf (stderr, " {GC %luk} ", (unsigned long) G.allocated / 1024); |
2238 } | 2273 } |
2239 | |
2240 /* Print allocation statistics. */ | |
2241 #define SCALE(x) ((unsigned long) ((x) < 1024*10 \ | |
2242 ? (x) \ | |
2243 : ((x) < 1024*1024*10 \ | |
2244 ? (x) / 1024 \ | |
2245 : (x) / (1024*1024)))) | |
2246 #define STAT_LABEL(x) ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M')) | |
2247 | 2274 |
2248 void | 2275 void |
2249 ggc_print_statistics (void) | 2276 ggc_print_statistics (void) |
2250 { | 2277 { |
2251 struct ggc_statistics stats; | 2278 struct ggc_statistics stats; |
2294 (OBJECTS_IN_PAGE (p) - p->num_free_objects) * OBJECT_SIZE (i); | 2321 (OBJECTS_IN_PAGE (p) - p->num_free_objects) * OBJECT_SIZE (i); |
2295 | 2322 |
2296 overhead += (sizeof (page_entry) - sizeof (long) | 2323 overhead += (sizeof (page_entry) - sizeof (long) |
2297 + BITMAP_SIZE (OBJECTS_IN_PAGE (p) + 1)); | 2324 + BITMAP_SIZE (OBJECTS_IN_PAGE (p) + 1)); |
2298 } | 2325 } |
2299 fprintf (stderr, "%-8lu %10lu%c %10lu%c %10lu%c\n", | 2326 fprintf (stderr, "%-8" PRIu64 " " PRsa (10) " " PRsa (10) " " |
2300 (unsigned long) OBJECT_SIZE (i), | 2327 PRsa (10) "\n", |
2301 SCALE (allocated), STAT_LABEL (allocated), | 2328 (uint64_t)OBJECT_SIZE (i), |
2302 SCALE (in_use), STAT_LABEL (in_use), | 2329 SIZE_AMOUNT (allocated), |
2303 SCALE (overhead), STAT_LABEL (overhead)); | 2330 SIZE_AMOUNT (in_use), |
2331 SIZE_AMOUNT (overhead)); | |
2304 total_overhead += overhead; | 2332 total_overhead += overhead; |
2305 } | 2333 } |
2306 fprintf (stderr, "%-8s %10lu%c %10lu%c %10lu%c\n", "Total", | 2334 fprintf (stderr, "%-8s " PRsa (10) " " PRsa (10) " " PRsa (10) "\n", |
2307 SCALE (G.bytes_mapped), STAT_LABEL (G.bytes_mapped), | 2335 "Total", |
2308 SCALE (G.allocated), STAT_LABEL (G.allocated), | 2336 SIZE_AMOUNT (G.bytes_mapped), |
2309 SCALE (total_overhead), STAT_LABEL (total_overhead)); | 2337 SIZE_AMOUNT (G.allocated), |
2338 SIZE_AMOUNT (total_overhead)); | |
2310 | 2339 |
2311 if (GATHER_STATISTICS) | 2340 if (GATHER_STATISTICS) |
2312 { | 2341 { |
2313 fprintf (stderr, "\nTotal allocations and overheads during " | 2342 fprintf (stderr, "\nTotal allocations and overheads during " |
2314 "the compilation process\n"); | 2343 "the compilation process\n"); |
2315 | 2344 |
2316 fprintf (stderr, "Total Overhead: %10" | 2345 fprintf (stderr, "Total Overhead: " |
2317 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_overhead); | 2346 PRsa (9) "\n", |
2318 fprintf (stderr, "Total Allocated: %10" | 2347 SIZE_AMOUNT (G.stats.total_overhead)); |
2319 HOST_LONG_LONG_FORMAT "d\n", | 2348 fprintf (stderr, "Total Allocated: " |
2320 G.stats.total_allocated); | 2349 PRsa (9) "\n", |
2321 | 2350 SIZE_AMOUNT (G.stats.total_allocated)); |
2322 fprintf (stderr, "Total Overhead under 32B: %10" | 2351 |
2323 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_overhead_under32); | 2352 fprintf (stderr, "Total Overhead under 32B: " |
2324 fprintf (stderr, "Total Allocated under 32B: %10" | 2353 PRsa (9) "\n", |
2325 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_allocated_under32); | 2354 SIZE_AMOUNT (G.stats.total_overhead_under32)); |
2326 fprintf (stderr, "Total Overhead under 64B: %10" | 2355 fprintf (stderr, "Total Allocated under 32B: " |
2327 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_overhead_under64); | 2356 PRsa (9) "\n", |
2328 fprintf (stderr, "Total Allocated under 64B: %10" | 2357 SIZE_AMOUNT (G.stats.total_allocated_under32)); |
2329 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_allocated_under64); | 2358 fprintf (stderr, "Total Overhead under 64B: " |
2330 fprintf (stderr, "Total Overhead under 128B: %10" | 2359 PRsa (9) "\n", |
2331 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_overhead_under128); | 2360 SIZE_AMOUNT (G.stats.total_overhead_under64)); |
2332 fprintf (stderr, "Total Allocated under 128B: %10" | 2361 fprintf (stderr, "Total Allocated under 64B: " |
2333 HOST_LONG_LONG_FORMAT "d\n", G.stats.total_allocated_under128); | 2362 PRsa (9) "\n", |
2363 SIZE_AMOUNT (G.stats.total_allocated_under64)); | |
2364 fprintf (stderr, "Total Overhead under 128B: " | |
2365 PRsa (9) "\n", | |
2366 SIZE_AMOUNT (G.stats.total_overhead_under128)); | |
2367 fprintf (stderr, "Total Allocated under 128B: " | |
2368 PRsa (9) "\n", | |
2369 SIZE_AMOUNT (G.stats.total_allocated_under128)); | |
2334 | 2370 |
2335 for (i = 0; i < NUM_ORDERS; i++) | 2371 for (i = 0; i < NUM_ORDERS; i++) |
2336 if (G.stats.total_allocated_per_order[i]) | 2372 if (G.stats.total_allocated_per_order[i]) |
2337 { | 2373 { |
2338 fprintf (stderr, "Total Overhead page size %9lu: %10" | 2374 fprintf (stderr, "Total Overhead page size %9" PRIu64 ": " |
2339 HOST_LONG_LONG_FORMAT "d\n", | 2375 PRsa (9) "\n", |
2340 (unsigned long) OBJECT_SIZE (i), | 2376 (uint64_t)OBJECT_SIZE (i), |
2341 G.stats.total_overhead_per_order[i]); | 2377 SIZE_AMOUNT (G.stats.total_overhead_per_order[i])); |
2342 fprintf (stderr, "Total Allocated page size %9lu: %10" | 2378 fprintf (stderr, "Total Allocated page size %9" PRIu64 ": " |
2343 HOST_LONG_LONG_FORMAT "d\n", | 2379 PRsa (9) "\n", |
2344 (unsigned long) OBJECT_SIZE (i), | 2380 (uint64_t)OBJECT_SIZE (i), |
2345 G.stats.total_allocated_per_order[i]); | 2381 SIZE_AMOUNT (G.stats.total_allocated_per_order[i])); |
2346 } | 2382 } |
2347 } | 2383 } |
2348 } | 2384 } |
2349 | 2385 |
2350 struct ggc_pch_ondisk | 2386 struct ggc_pch_ondisk |
2452 while (size > OBJECT_SIZE (order)) | 2488 while (size > OBJECT_SIZE (order)) |
2453 order++; | 2489 order++; |
2454 } | 2490 } |
2455 | 2491 |
2456 if (fwrite (x, size, 1, f) != 1) | 2492 if (fwrite (x, size, 1, f) != 1) |
2457 fatal_error (input_location, "can%'t write PCH file: %m"); | 2493 fatal_error (input_location, "cannot write PCH file: %m"); |
2458 | 2494 |
2459 /* If SIZE is not the same as OBJECT_SIZE(order), then we need to pad the | 2495 /* If SIZE is not the same as OBJECT_SIZE(order), then we need to pad the |
2460 object out to OBJECT_SIZE(order). This happens for strings. */ | 2496 object out to OBJECT_SIZE(order). This happens for strings. */ |
2461 | 2497 |
2462 if (size != OBJECT_SIZE (order)) | 2498 if (size != OBJECT_SIZE (order)) |
2468 permits us to do the padding with fwrite() rather than fseek(), and | 2504 permits us to do the padding with fwrite() rather than fseek(), and |
2469 limits the chance the OS may try to flush any outstanding writes. */ | 2505 limits the chance the OS may try to flush any outstanding writes. */ |
2470 if (padding <= sizeof (emptyBytes)) | 2506 if (padding <= sizeof (emptyBytes)) |
2471 { | 2507 { |
2472 if (fwrite (emptyBytes, 1, padding, f) != padding) | 2508 if (fwrite (emptyBytes, 1, padding, f) != padding) |
2473 fatal_error (input_location, "can%'t write PCH file"); | 2509 fatal_error (input_location, "cannot write PCH file"); |
2474 } | 2510 } |
2475 else | 2511 else |
2476 { | 2512 { |
2477 /* Larger than our buffer? Just default to fseek. */ | 2513 /* Larger than our buffer? Just default to fseek. */ |
2478 if (fseek (f, padding, SEEK_CUR) != 0) | 2514 if (fseek (f, padding, SEEK_CUR) != 0) |
2479 fatal_error (input_location, "can%'t write PCH file"); | 2515 fatal_error (input_location, "cannot write PCH file"); |
2480 } | 2516 } |
2481 } | 2517 } |
2482 | 2518 |
2483 d->written[order]++; | 2519 d->written[order]++; |
2484 if (d->written[order] == d->d.totals[order] | 2520 if (d->written[order] == d->d.totals[order] |
2485 && fseek (f, ROUND_UP_VALUE (d->d.totals[order] * OBJECT_SIZE (order), | 2521 && fseek (f, ROUND_UP_VALUE (d->d.totals[order] * OBJECT_SIZE (order), |
2486 G.pagesize), | 2522 G.pagesize), |
2487 SEEK_CUR) != 0) | 2523 SEEK_CUR) != 0) |
2488 fatal_error (input_location, "can%'t write PCH file: %m"); | 2524 fatal_error (input_location, "cannot write PCH file: %m"); |
2489 } | 2525 } |
2490 | 2526 |
2491 void | 2527 void |
2492 ggc_pch_finish (struct ggc_pch_data *d, FILE *f) | 2528 ggc_pch_finish (struct ggc_pch_data *d, FILE *f) |
2493 { | 2529 { |
2494 if (fwrite (&d->d, sizeof (d->d), 1, f) != 1) | 2530 if (fwrite (&d->d, sizeof (d->d), 1, f) != 1) |
2495 fatal_error (input_location, "can%'t write PCH file: %m"); | 2531 fatal_error (input_location, "cannot write PCH file: %m"); |
2496 free (d); | 2532 free (d); |
2497 } | 2533 } |
2498 | 2534 |
2499 /* Move the PCH PTE entries just added to the end of by_depth, to the | 2535 /* Move the PCH PTE entries just added to the end of by_depth, to the |
2500 front. */ | 2536 front. */ |
2553 unsigned long count_old_page_tables; | 2589 unsigned long count_old_page_tables; |
2554 unsigned long count_new_page_tables; | 2590 unsigned long count_new_page_tables; |
2555 | 2591 |
2556 count_old_page_tables = G.by_depth_in_use; | 2592 count_old_page_tables = G.by_depth_in_use; |
2557 | 2593 |
2594 if (fread (&d, sizeof (d), 1, f) != 1) | |
2595 fatal_error (input_location, "cannot read PCH file: %m"); | |
2596 | |
2558 /* We've just read in a PCH file. So, every object that used to be | 2597 /* We've just read in a PCH file. So, every object that used to be |
2559 allocated is now free. */ | 2598 allocated is now free. */ |
2560 clear_marks (); | 2599 clear_marks (); |
2561 #ifdef ENABLE_GC_CHECKING | 2600 #ifdef ENABLE_GC_CHECKING |
2562 poison_pages (); | 2601 poison_pages (); |
2581 p->context_depth = G.context_depth; | 2620 p->context_depth = G.context_depth; |
2582 } | 2621 } |
2583 | 2622 |
2584 /* Allocate the appropriate page-table entries for the pages read from | 2623 /* Allocate the appropriate page-table entries for the pages read from |
2585 the PCH file. */ | 2624 the PCH file. */ |
2586 if (fread (&d, sizeof (d), 1, f) != 1) | |
2587 fatal_error (input_location, "can%'t read PCH file: %m"); | |
2588 | 2625 |
2589 for (i = 0; i < NUM_ORDERS; i++) | 2626 for (i = 0; i < NUM_ORDERS; i++) |
2590 { | 2627 { |
2591 struct page_entry *entry; | 2628 struct page_entry *entry; |
2592 char *pte; | 2629 char *pte; |