Permalink
Browse files

apply a patch from chromatic++ for testing

git-svn-id: https://svn.parrot.org/parrot/branches/compact_strings@45086 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
whiteknight
whiteknight committed Mar 21, 2010
1 parent bdfa722 commit e1e434fa60360dd2a0b7121fec736ac4d1403801
Showing with 36 additions and 16 deletions.
  1. +9 −12 src/gc/gc_ms.c
  2. +27 −4 src/gc/mark_sweep.c
View
@@ -849,18 +849,12 @@ gc_ms_allocate_buffer_storage(PARROT_INTERP,
ARGOUT(Buffer *buffer), size_t size)
{
ASSERT_ARGS(gc_ms_allocate_buffer_storage)
- size_t new_size;
- char *mem;
+ const size_t new_size = aligned_string_size(size);
+ const char *mem = (char *)Parrot_gc_allocate_fixed_size_storage(
+ interp, new_size);
- Buffer_buflen(buffer) = 0;
- Buffer_bufstart(buffer) = NULL;
- new_size = aligned_string_size(size);
- mem = (char *)mem_allocate(interp, interp->mem_pools, new_size,
- interp->mem_pools->memory_pool);
- mem = aligned_mem(buffer, mem);
- Buffer_bufstart(buffer) = mem;
- new_size -= sizeof (void*);
- Buffer_buflen(buffer) = new_size;
+ Buffer_bufstart(buffer) = aligned_mem(buffer, mem);
+ Buffer_buflen(buffer) = new_size - sizeof (void *);
}
/*
@@ -919,14 +913,17 @@ gc_ms_reallocate_buffer_storage(PARROT_INTERP, ARGMOD(Buffer *buffer),
else
pool->possibly_reclaimable += copysize;
- mem = (char *)mem_allocate(interp, interp->mem_pools, new_size, pool);
+ mem = (char *)Parrot_gc_allocate_fixed_size_storage(interp, new_size);
mem = aligned_mem(buffer, mem);
/* We shouldn't ever have a 0 from size, but we do. If we can track down
* those bugs, this can be removed which would make things cheaper */
if (copysize)
memcpy(mem, Buffer_bufstart(buffer), copysize);
+ Parrot_gc_free_fixed_size_storage(interp,
+ Buffer_buflen(buffer) + sizeof (void *), Buffer_bufstart(buffer));
+
Buffer_bufstart(buffer) = mem;
new_size -= sizeof (void *);
View
@@ -673,6 +673,28 @@ C<get_bufferlike_pool> internally, which in turn calls C<new_bufferlike_pool>.
*/
+static void
+free_string_header(PARROT_INTERP,
+ ARGIN(Memory_Pools *mem_pools),
+ ARGMOD(Fixed_Size_Pool *pool),
+ ARGMOD(PObj *p))
+{
+ /* ASSERT_ARGS(free_buffer) */
+ STRING *s = (STRING *)p;
+ INTVAL *ref_count = Buffer_bufrefcountptr(s);
+
+ *ref_count--;
+
+ if (*ref_count <= 0)
+ Parrot_gc_free_fixed_size_storage(interp, Buffer_buflen(s),
+ Buffer_bufstart(s));
+
+ Buffer_buflen(s) = 0;
+ Buffer_bufstart(s) = NULL;
+ Buffer_bufstart(s) = NULL;
+ s->strstart = NULL;
+}
+
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static Fixed_Size_Pool *
@@ -681,14 +703,15 @@ new_string_pool(PARROT_INTERP,
INTVAL constant)
{
ASSERT_ARGS(new_string_pool)
- Fixed_Size_Pool *pool;
+ const size_t size = sizeof (STRING);
+ Fixed_Size_Pool *pool = new_bufferlike_pool(interp, mem_pools, size);
+
if (constant) {
- pool = new_bufferlike_pool(interp, mem_pools, sizeof (STRING));
pool->gc_object = NULL;
- pool->mem_pool = mem_pools->constant_string_pool;
+ pool->mem_pool = mem_pools->constant_string_pool;
}
else
- pool = get_bufferlike_pool(interp, mem_pools, sizeof (STRING));
+ pool->gc_object = free_string_header;
pool->objects_per_alloc = STRING_HEADERS_PER_ALLOC;

0 comments on commit e1e434f

Please sign in to comment.