OSDN Git Service

2004-10-27 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / gcc / ggc-zone.c
index fc605f4..311fff6 100644 (file)
@@ -146,10 +146,13 @@ struct alloc_chunk {
   unsigned int magic;
 #endif
   unsigned int type:1;
-  unsigned int typecode:14;
-  unsigned int large:1;
-  unsigned int size:15;
   unsigned int mark:1;
+  unsigned char large;
+  unsigned short size;
+  /* Right now, on 32-bit hosts we don't have enough room to save the
+     typecode unless we make the one remaining flag into a bitfield.
+     There's a performance cost to that, so we don't do it until we're
+     ready to use the type information for something.  */
   union {
     struct alloc_chunk *next_free;
     char data[1];
@@ -365,8 +368,7 @@ ggc_allocated_p (const void *p)
   struct alloc_chunk *chunk;
   chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
 #ifdef COOKIE_CHECKING
-  if (chunk->magic != CHUNK_MAGIC)
-    abort ();
+  gcc_assert (chunk->magic == CHUNK_MAGIC);
 #endif
   if (chunk->type == 1)
     return true;  
@@ -575,13 +577,11 @@ free_chunk (struct alloc_chunk *chunk, size_t size, struct alloc_zone *zone)
   size_t bin = 0;
 
   bin = SIZE_BIN_DOWN (size);
-  if (bin == 0)
-    abort ();
+  gcc_assert (bin);
   if (bin > NUM_FREE_BINS)
     bin = 0;
 #ifdef COOKIE_CHECKING
-  if (chunk->magic != CHUNK_MAGIC && chunk->magic != DEADCHUNK_MAGIC)
-    abort ();
+  gcc_assert (chunk->magic == CHUNK_MAGIC || chunk->magic == DEADCHUNK_MAGIC);
   chunk->magic = DEADCHUNK_MAGIC;
 #endif
   chunk->u.next_free = zone->free_chunks[bin];
@@ -594,7 +594,8 @@ free_chunk (struct alloc_chunk *chunk, size_t size, struct alloc_zone *zone)
 /* Allocate a chunk of memory of SIZE bytes.  */
 
 static void *
-ggc_alloc_zone_1 (size_t orig_size, struct alloc_zone *zone, short type
+ggc_alloc_zone_1 (size_t orig_size, struct alloc_zone *zone,
+                 short type ATTRIBUTE_UNUSED
                  MEM_STAT_DECL)
 {
   size_t bin = 0;
@@ -696,7 +697,8 @@ ggc_alloc_zone_1 (size_t orig_size, struct alloc_zone *zone, short type
 #endif
   chunk->type = 1;
   chunk->mark = 0;
-  chunk->typecode = type;
+  /* We could save TYPE in the chunk, but we don't use that for
+     anything yet.  */
   result = chunk->u.data;
 
 #ifdef ENABLE_GC_CHECKING
@@ -825,8 +827,7 @@ ggc_set_mark (const void *p)
 
   chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
 #ifdef COOKIE_CHECKING
-  if (chunk->magic != CHUNK_MAGIC)
-    abort ();
+  gcc_assert (chunk->magic == CHUNK_MAGIC);
 #endif
   if (chunk->mark)
     return 1;
@@ -849,8 +850,7 @@ ggc_marked_p (const void *p)
 
   chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
 #ifdef COOKIE_CHECKING
-  if (chunk->magic != CHUNK_MAGIC)
-    abort ();
+  gcc_assert (chunk->magic == CHUNK_MAGIC);
 #endif
   return chunk->mark;
 }
@@ -864,8 +864,7 @@ ggc_get_size (const void *p)
 
   chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
 #ifdef COOKIE_CHECKING
-  if (chunk->magic != CHUNK_MAGIC)
-    abort ();
+  gcc_assert (chunk->magic == CHUNK_MAGIC);
 #endif
   if (chunk->large)
     return chunk->size * 1024;
@@ -890,8 +889,7 @@ init_ggc (void)
   G.lg_pagesize = exact_log2 (G.pagesize);
 #ifdef HAVE_MMAP_DEV_ZERO
   G.dev_zero_fd = open ("/dev/zero", O_RDONLY);
-  if (G.dev_zero_fd == -1)
-    abort ();
+  gcc_assert (G.dev_zero_fd != -1);
 #endif
 
 #if 0
@@ -915,8 +913,7 @@ init_ggc (void)
           can't get something useful, give up.  */
 
        p = alloc_anon (NULL, G.pagesize, &main_zone);
-       if ((size_t)p & (G.pagesize - 1))
-         abort ();
+       gcc_assert (!((size_t)p & (G.pagesize - 1)));
       }
 
     /* We have a good page, might as well hold onto it...  */
@@ -948,13 +945,11 @@ destroy_ggc_zone (struct alloc_zone * dead_zone)
   struct alloc_zone *z;
 
   for (z = G.zones; z && z->next_zone != dead_zone; z = z->next_zone)
-    /* Just find that zone.  */ ;
+    /* Just find that zone.  */
+    continue;
 
-#ifdef ENABLE_CHECKING
   /* We should have found the zone in the list.  Anything else is fatal.  */
-  if (!z)
-    abort ();
-#endif
+  gcc_assert (z);
 
   /* z is dead, baby. z is dead.  */
   z->dead= true;
@@ -970,8 +965,7 @@ ggc_push_context (void)
   for (zone = G.zones; zone; zone = zone->next_zone)
     ++(zone->context_depth);
   /* Die on wrap.  */
-  if (main_zone.context_depth >= HOST_BITS_PER_LONG)
-    abort ();
+  gcc_assert (main_zone.context_depth < HOST_BITS_PER_LONG);
 }
 
 /* Decrement the `GC context'.  All objects allocated since the
@@ -1199,8 +1193,8 @@ check_cookies (void)
              struct alloc_chunk *end = (struct alloc_chunk *)(p->page + G.pagesize);
              do
                {
-                 if (chunk->magic != CHUNK_MAGIC && chunk->magic != DEADCHUNK_MAGIC)
-                   abort ();
+                 gcc_assert (chunk->magic == CHUNK_MAGIC
+                             || chunk->magic == DEADCHUNK_MAGIC);
                  chunk = (struct alloc_chunk *)(chunk->u.data + chunk->size);
                }
              while (chunk < end);
@@ -1329,8 +1323,7 @@ ggc_collect (void)
          printf ("Zone `%s' is dead and will be freed.\n", dead_zone->name);
 
          /* The zone must be empty.  */
-         if (dead_zone->allocated != 0)
-           abort ();
+         gcc_assert (!dead_zone->allocated);
 
          /* Unchain the dead zone, release all its pages and free it.  */
          zone->next_zone = zone->next_zone->next_zone;
@@ -1410,10 +1403,7 @@ ggc_print_statistics (void)
              in_use += p->bytes - CHUNK_OVERHEAD;
              chunk = (struct alloc_chunk *) p->page;
              overhead += CHUNK_OVERHEAD;
-             if (!chunk->type)
-               abort ();
-             if (chunk->mark)
-               abort ();
+             gcc_assert (chunk->type && !chunk->mark);
              continue;
            }
 
@@ -1424,8 +1414,7 @@ ggc_print_statistics (void)
              overhead += CHUNK_OVERHEAD;
              if (chunk->type)
                in_use += chunk->size;
-             if (chunk->mark)
-               abort ();
+             gcc_assert (!chunk->mark);
            }
        }
       fprintf (stderr, "%20s %10lu%c %10lu%c %10lu%c\n",
@@ -1434,8 +1423,7 @@ ggc_print_statistics (void)
               SCALE (in_use), LABEL (in_use),
               SCALE (overhead), LABEL (overhead));
 
-      if (in_use != zone->allocated)
-       abort ();
+      gcc_assert (in_use == zone->allocated);
 
       total_overhead += overhead;
       total_allocated += zone->allocated;