diff options
author | Geoffrey Keating <geoffk@apple.com> | 2003-07-29 23:36:53 +0000 |
---|---|---|
committer | Geoffrey Keating <geoffk@gcc.gnu.org> | 2003-07-29 23:36:53 +0000 |
commit | 18c8152070f9939739b297a4f133db1ca2387b6d (patch) | |
tree | a81081c458d46be162c522a5f484e4265c5c1d47 /gcc/ggc-common.c | |
parent | 8f9b40094d6e960d965e632f6537bf6eaa980ab5 (diff) | |
download | gcc-18c8152070f9939739b297a4f133db1ca2387b6d.zip gcc-18c8152070f9939739b297a4f133db1ca2387b6d.tar.gz gcc-18c8152070f9939739b297a4f133db1ca2387b6d.tar.bz2 |
c-common.c (allow_pch): Remove.
2003-07-29 Geoffrey Keating <geoffk@apple.com>
* c-common.c (allow_pch): Remove.
* c-common.h (allow_pch): Remove.
(c_common_no_more_pch): Declare.
* c-lex.c (c_lex): Call c_common_no_more_pch when appropriate.
* c-pch.c: Include hosthooks.h.
(c_common_valid_pch): Don't check allow_pch.
(c_common_read_pch): Clear valid_pch to prevent reading PCH files.
(c_common_no_more_pch): New.
* ggc-common.c: Include hosthooks.h.
(gt_pch_save): Call gt_pch_get_address.
(gt_pch_restore): Call gt_pch_use_address.
* hooks.c (hook_voidp_size_t_null): New.
(hook_bool_voidp_size_t_false): New.
* hooks.h (hook_voidp_size_t_null): New.
(hook_bool_voidp_size_t_false): New.
* hosthooks-def.h (HOST_HOOKS_GT_PCH_GET_ADDRESS): New.
(HOST_HOOKS_GT_PCH_USE_ADDRESS): New.
(HOST_HOOKS_INITIALIZER): Add HOST_HOOKS_GT_PCH_GET_ADDRESS,
HOST_HOOKS_GT_PCH_USE_ADDRESS.
* hosthooks.h (struct host_hooks): Add gt_pch_get_address,
gt_pch_use_address.
* doc/hostconfig.texi (Host Common): Document
HOST_HOOKS_GT_PCH_GET_ADDRESS, HOST_HOOKS_GT_PCH_USE_ADDRESS.
* Makefile.in (c-pch.o): Depend on hosthooks.h.
(ggc-common.o): Likewise.
* config/rs6000/host-darwin.c (HOST_HOOKS_GT_PCH_GET_ADDRESS): Define.
(HOST_HOOKS_GT_PCH_USE_ADDRESS): Define.
(pch_address_space): New.
(darwin_rs6000_gt_pch_get_address): New.
(darwin_rs6000_gt_pch_use_address): New.
Index: cp/ChangeLog
2003-07-29 Geoffrey Keating <geoffk@apple.com>
* parser.c (cp_lexer_new_main): Use c_common_no_more_pch instead
of setting valid_pch by hand.
From-SVN: r69944
Diffstat (limited to 'gcc/ggc-common.c')
-rw-r--r-- | gcc/ggc-common.c | 125 |
1 files changed, 80 insertions, 45 deletions
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c index 3163c15..2848118 100644 --- a/gcc/ggc-common.c +++ b/gcc/ggc-common.c @@ -29,6 +29,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "ggc.h" #include "toplev.h" #include "params.h" +#include "hosthooks.h" #ifdef HAVE_SYS_RESOURCE_H # include <sys/resource.h> @@ -450,19 +451,24 @@ gt_pch_save (FILE *f) mmi.size = ggc_pch_total_size (state.d); - /* 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. */ + /* 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.) */ + mmi.preferred_base = host_hooks.gt_pch_get_address (mmi.size); + #if HAVE_MMAP_FILE - mmi.preferred_base = mmap (NULL, mmi.size, - PROT_READ | PROT_WRITE, MAP_PRIVATE, - fileno (state.f), 0); - if (mmi.preferred_base == (void *) MAP_FAILED) - mmi.preferred_base = NULL; - else - munmap (mmi.preferred_base, mmi.size); -#else /* HAVE_MMAP_FILE */ - mmi.preferred_base = NULL; + if (mmi.preferred_base == NULL) + { + mmi.preferred_base = mmap (NULL, mmi.size, + PROT_READ | PROT_WRITE, MAP_PRIVATE, + fileno (state.f), 0); + if (mmi.preferred_base == (void *) MAP_FAILED) + mmi.preferred_base = NULL; + else + munmap (mmi.preferred_base, mmi.size); + } #endif /* HAVE_MMAP_FILE */ ggc_pch_this_base (state.d, mmi.preferred_base); @@ -539,6 +545,7 @@ gt_pch_restore (FILE *f) size_t i; struct mmap_info mmi; void *addr; + bool needs_read; /* Delete any deletable objects. This makes ggc_pch_read much faster, as it can be sure that no GCable objects remain other @@ -571,47 +578,75 @@ gt_pch_restore (FILE *f) if (fread (&mmi, sizeof (mmi), 1, f) != 1) fatal_error ("can't read PCH file: %m"); + if (host_hooks.gt_pch_use_address (mmi.preferred_base, mmi.size)) + { #if HAVE_MMAP_FILE - addr = mmap (mmi.preferred_base, mmi.size, - PROT_READ | PROT_WRITE, MAP_PRIVATE, - fileno (f), mmi.offset); + void *mmap_result; -#if HAVE_MINCORE - if (addr != mmi.preferred_base) - { - size_t page_size = getpagesize(); - char one_byte; - - if (addr != (void *) MAP_FAILED) - munmap (addr, mmi.size); - - /* We really want to be mapped at mmi.preferred_base - so we're going to resort to MAP_FIXED. But before, - make sure that we can do so without destroying a - previously mapped area, by looping over all pages - that would be affected by the fixed mapping. */ - errno = 0; - - for (i = 0; i < mmi.size; i+= page_size) - if (mincore ((char *)mmi.preferred_base + i, page_size, (void *)&one_byte) == -1 - && errno == ENOMEM) - continue; /* The page is not mapped. */ - else - break; - - if (i >= mmi.size) - addr = mmap (mmi.preferred_base, mmi.size, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, - fileno (f), mmi.offset); + mmap_result = mmap (mmi.preferred_base, mmi.size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, + fileno (f), mmi.offset); + + /* The file might not be mmap-able. */ + needs_read = mmap_result == MAP_FAILED; + + /* Sanity check for broken MAP_FIXED. */ + if (! needs_read && mmap_result != mmi.preferred_base) + abort (); +#else + needs_read = true; +#endif + addr = mmi.preferred_base; } + else + { +#if HAVE_MMAP_FILE + addr = mmap (mmi.preferred_base, mmi.size, + PROT_READ | PROT_WRITE, MAP_PRIVATE, + fileno (f), mmi.offset); + +#if HAVE_MINCORE + if (addr != mmi.preferred_base) + { + size_t page_size = getpagesize(); + char one_byte; + + if (addr != (void *) MAP_FAILED) + munmap (addr, mmi.size); + + /* We really want to be mapped at mmi.preferred_base + so we're going to resort to MAP_FIXED. But before, + make sure that we can do so without destroying a + previously mapped area, by looping over all pages + that would be affected by the fixed mapping. */ + errno = 0; + + for (i = 0; i < mmi.size; i+= page_size) + if (mincore ((char *)mmi.preferred_base + i, page_size, + (void *)&one_byte) == -1 + && errno == ENOMEM) + continue; /* The page is not mapped. */ + else + break; + + if (i >= mmi.size) + addr = mmap (mmi.preferred_base, mmi.size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, + fileno (f), mmi.offset); + } #endif /* HAVE_MINCORE */ + + needs_read = addr == (void *) MAP_FAILED; #else /* HAVE_MMAP_FILE */ - addr = MAP_FAILED; + needs_read = true; #endif /* HAVE_MMAP_FILE */ - if (addr == (void *) MAP_FAILED) + if (needs_read) + addr = xmalloc (mmi.size); + } + + if (needs_read) { - addr = xmalloc (mmi.size); if (fseek (f, mmi.offset, SEEK_SET) != 0 || fread (&mmi, mmi.size, 1, f) != 1) fatal_error ("can't read PCH file: %m"); |