OSDN Git Service

2003-06-06 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / ggc-common.c
index 5b0e330..adf2fd0 100644 (file)
@@ -1,5 +1,6 @@
 /* Simple garbage collection for the GNU compiler.
-   Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -38,7 +39,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 #ifdef ENABLE_VALGRIND_CHECKING
-#include <valgrind.h>
+# ifdef HAVE_MEMCHECK_H
+# include <memcheck.h>
+# else
+# include <valgrind.h>
+# endif
 #else
 /* Avoid #ifdef:s when we can help it.  */
 #define VALGRIND_DISCARD(x)
@@ -108,7 +113,7 @@ ggc_mark_roots ()
       if (*cti->base)
        {
          ggc_set_mark (*cti->base);
-         htab_traverse (*cti->base, ggc_htab_delete, (PTR) cti);
+         htab_traverse_noresize (*cti->base, ggc_htab_delete, (PTR) cti);
          ggc_set_mark ((*cti->base)->entries);
        }
 }
@@ -406,7 +411,7 @@ write_pch_globals (tab, state)
            {
              if (fwrite (&ptr, sizeof (void *), 1, state->f) 
                  != 1)
-               fatal_io_error ("can't write PCH file");
+               fatal_error ("can't write PCH file: %m");
            }
          else
            {
@@ -414,7 +419,7 @@ write_pch_globals (tab, state)
                                             POINTER_HASH (ptr));
              if (fwrite (&new_ptr->new_addr, sizeof (void *), 1, state->f) 
                  != 1)
-               fatal_io_error ("can't write PCH file");
+               fatal_error ("can't write PCH file: %m");
            }
        }
 }
@@ -491,7 +496,7 @@ gt_pch_save (f)
   for (rt = gt_pch_scalar_rtab; *rt; rt++)
     for (rti = *rt; rti->base != NULL; rti++)
       if (fwrite (rti->base, rti->stride, 1, f) != 1)
-       fatal_io_error ("can't write PCH file");
+       fatal_error ("can't write PCH file: %m");
 
   /* Write out all the global pointers, after translation.  */
   write_pch_globals (gt_ggc_rtab, &state);
@@ -504,17 +509,17 @@ gt_pch_save (f)
     long o;
     o = ftell (state.f) + sizeof (mmi);
     if (o == -1)
-      fatal_io_error ("can't get position in PCH file");
+      fatal_error ("can't get position in PCH file: %m");
     mmi.offset = page_size - o % page_size;
     if (mmi.offset == page_size)
       mmi.offset = 0;
     mmi.offset += o;
   }
   if (fwrite (&mmi, sizeof (mmi), 1, state.f) != 1)
-    fatal_io_error ("can't write PCH file");
+    fatal_error ("can't write PCH file: %m");
   if (mmi.offset != 0
       && fseek (state.f, mmi.offset, SEEK_SET) != 0)
-    fatal_io_error ("can't write padding to PCH file");
+    fatal_error ("can't write padding to PCH file: %m");
 
   /* Actually write out the objects.  */
   for (i = 0; i < state.count; i++)
@@ -538,6 +543,7 @@ gt_pch_save (f)
        memcpy (state.ptrs[i]->obj, this_object, state.ptrs[i]->size);
     }
   ggc_pch_finish (state.d, state.f);
+  gt_pch_fixup_stringpool ();
 
   free (state.ptrs);
   htab_delete (saving_htab);
@@ -566,7 +572,7 @@ gt_pch_restore (f)
   for (rt = gt_pch_scalar_rtab; *rt; rt++)
     for (rti = *rt; rti->base != NULL; rti++)
       if (fread (rti->base, rti->stride, 1, f) != 1)
-       fatal_io_error ("can't read PCH file");
+       fatal_error ("can't read PCH file: %m");
 
   /* Read in all the global pointers, in 6 easy loops.  */
   for (rt = gt_ggc_rtab; *rt; rt++)
@@ -574,17 +580,17 @@ gt_pch_restore (f)
       for (i = 0; i < rti->nelt; i++)
        if (fread ((char *)rti->base + rti->stride * i,
                   sizeof (void *), 1, f) != 1)
-         fatal_io_error ("can't read PCH file");
+         fatal_error ("can't read PCH file: %m");
 
   for (rt = gt_pch_cache_rtab; *rt; rt++)
     for (rti = *rt; rti->base != NULL; rti++)
       for (i = 0; i < rti->nelt; i++)
        if (fread ((char *)rti->base + rti->stride * i,
                   sizeof (void *), 1, f) != 1)
-         fatal_io_error ("can't read PCH file");
+         fatal_error ("can't read PCH file: %m");
 
   if (fread (&mmi, sizeof (mmi), 1, f) != 1)
-    fatal_io_error ("can't read PCH file");
+    fatal_error ("can't read PCH file: %m");
   
 #if HAVE_MMAP_FILE
   addr = mmap (mmi.preferred_base, mmi.size, 
@@ -598,10 +604,10 @@ gt_pch_restore (f)
       addr = xmalloc (mmi.size);
       if (fseek (f, mmi.offset, SEEK_SET) != 0
          || fread (&mmi, mmi.size, 1, f) != 1)
-       fatal_io_error ("can't read PCH file");
+       fatal_error ("can't read PCH file: %m");
     }
   else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
-    fatal_io_error ("can't read PCH file");
+    fatal_error ("can't read PCH file: %m");
 
   ggc_pch_read (f, addr);
 
@@ -640,19 +646,19 @@ ggc_rlimit_bound (limit)
   struct rlimit rlim;
 # ifdef RLIMIT_RSS
   if (getrlimit (RLIMIT_RSS, &rlim) == 0
-      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur != (rlim_t) RLIM_INFINITY
       && rlim.rlim_cur < limit)
     limit = rlim.rlim_cur;
 # endif
 # ifdef RLIMIT_DATA
   if (getrlimit (RLIMIT_DATA, &rlim) == 0
-      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur != (rlim_t) RLIM_INFINITY
       && rlim.rlim_cur < limit)
     limit = rlim.rlim_cur;
 # endif
 # ifdef RLIMIT_AS
   if (getrlimit (RLIMIT_AS, &rlim) == 0
-      && rlim.rlim_cur != RLIM_INFINITY
+      && rlim.rlim_cur != (rlim_t) RLIM_INFINITY
       && rlim.rlim_cur < limit)
     limit = rlim.rlim_cur;
 # endif
@@ -689,7 +695,7 @@ ggc_min_heapsize_heuristic()
   /* Adjust for rlimits.  */
   min_heap_kbytes = ggc_rlimit_bound (min_heap_kbytes);
 
-  min_heap_kbytes /= 1024; /* convert to Kbytes. */
+  min_heap_kbytes /= 1024; /* convert to Kbytes.  */
   
   /* The heuristic is RAM/8, with a lower bound of 4M and an upper
      bound of 128M (when RAM >= 1GB).  */