This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: Add ggc_free to ggc-zone
On Jan 30, 2004, at 6:39 PM, Richard Henderson wrote:
On Fri, Jan 30, 2004 at 06:25:00PM -0500, Daniel Berlin wrote:
It just means the page won't be freed if you put it in the wrong zone,
at worst (and this is only the case for small objects). It'll still
be
reused.
That is the main point, though it'd be nice to figure out
a better solution. Something to think about....
I'm working on it.
In the meantime, to avoid problems later on/hacks, i'm simply just
going to make ggc_free only do something for large objects (which can
be freed directly).
That's objects > 32767 bytes, which *should* cover all the objects we
actually care about ggc_free doing something for ATM.
It'll be a noop for objects < 32767.
--Dan
Index: ggc-zone.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-zone.c,v
retrieving revision 2.12
diff -u -3 -p -r2.12 ggc-zone.c
--- ggc-zone.c 21 Jan 2004 20:40:02 -0000 2.12
+++ ggc-zone.c 30 Jan 2004 23:49:18 -0000
@@ -734,6 +735,27 @@ ggc_alloc_zone (size_t size, struct allo
return ggc_alloc_zone_1 (size, zone, -1);
}
+/* Poison the chunk. */
+#ifdef ENABLE_GC_CHECKING
+#define poison_chunk(CHUNK, SIZE) \
+ memset ((CHUNK)->u.data, 0xa5, (SIZE))
+#else
+#define poison_chunk(CHUNK, SIZE)
+#endif
+
+/* Free the object at P. */
+
+void
+ggc_free (void *p)
+{
+ struct alloc_chunk *chunk;
+
+ chunk = (struct alloc_chunk *) ((char *)p - CHUNK_OVERHEAD);
+ /* Poison the chunk. */
+ poison_chunk (chunk, ggc_get_size (p));
+ if (chunk->large)
+ free (p);
+}
/* If P is not marked, mark it and return false. Otherwise return
true.
P must have been allocated by the GC allocator; it mustn't point to
static objects, stack variables, or memory allocated with malloc.
*/
@@ -931,13 +953,6 @@ ggc_pop_context (void)
for (zone = G.zones; zone; zone = zone->next_zone)
ggc_pop_context_1 (zone);
}
-/* Poison the chunk. */
-#ifdef ENABLE_GC_CHECKING
-#define poison_chunk(CHUNK, SIZE) \
- memset ((CHUNK)->u.data, 0xa5, (SIZE))
-#else
-#define poison_chunk(CHUNK, SIZE)
-#endif
/* Free all empty pages and objects within a page for a given zone */