[svn:parrot] r43812 - in branches/gc_encapsulate_part2: include/parrot src/gc src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Feb 9 13:50:25 UTC 2010
Author: bacek
Date: Tue Feb 9 13:50:25 2010
New Revision: 43812
URL: https://trac.parrot.org/parrot/changeset/43812
Log:
Encapsulate allocate/free bufferlike headers
Modified:
branches/gc_encapsulate_part2/include/parrot/gc_api.h
branches/gc_encapsulate_part2/src/gc/api.c
branches/gc_encapsulate_part2/src/gc/gc_ms.c
branches/gc_encapsulate_part2/src/gc/gc_private.h
branches/gc_encapsulate_part2/src/pmc/imageio.pmc
Modified: branches/gc_encapsulate_part2/include/parrot/gc_api.h
==============================================================================
--- branches/gc_encapsulate_part2/include/parrot/gc_api.h Tue Feb 9 13:49:58 2010 (r43811)
+++ branches/gc_encapsulate_part2/include/parrot/gc_api.h Tue Feb 9 13:50:25 2010 (r43812)
@@ -252,7 +252,7 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
-void * Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size)
+Buffer * Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size)
__attribute__nonnull__(1);
PARROT_WARN_UNUSED_RESULT
Modified: branches/gc_encapsulate_part2/src/gc/api.c
==============================================================================
--- branches/gc_encapsulate_part2/src/gc/api.c Tue Feb 9 13:49:58 2010 (r43811)
+++ branches/gc_encapsulate_part2/src/gc/api.c Tue Feb 9 13:50:25 2010 (r43812)
@@ -460,7 +460,7 @@
/*
-=item C<void * Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size)>
+=item C<Buffer * Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size)>
Returns a new buffer-like header from the appropriate sized pool.
A "bufferlike object" is an object that is considered to be isomorphic to the
@@ -473,14 +473,11 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
-void *
+Buffer *
Parrot_gc_new_bufferlike_header(PARROT_INTERP, size_t size)
{
ASSERT_ARGS(Parrot_gc_new_bufferlike_header)
-
- Fixed_Size_Pool * const pool = get_bufferlike_pool(interp, interp->mem_pools, size);
-
- return pool->get_free_object(interp, interp->mem_pools, pool);
+ return interp->gc_sys->allocate_bufferlike_header(interp, size);
}
/*
@@ -500,8 +497,7 @@
size_t size)
{
ASSERT_ARGS(Parrot_gc_free_bufferlike_header)
- Fixed_Size_Pool * const pool = get_bufferlike_pool(interp, interp->mem_pools, size);
- pool->add_free_object(interp, interp->mem_pools, pool, obj);
+ interp->gc_sys->free_bufferlike_header(interp, obj, size);
}
/*
@@ -684,9 +680,7 @@
=item C<void Parrot_gc_compact_memory_pool(PARROT_INTERP)>
-Scan the string pools and compact them. This does not perform a GC mark or
-sweep run, and does not check whether string buffers are still alive.
-Redirects to C<compact_pool>.
+Compact string pool if supported by GC.
=cut
@@ -696,7 +690,7 @@
Parrot_gc_compact_memory_pool(PARROT_INTERP)
{
ASSERT_ARGS(Parrot_gc_compact_memory_pool)
- compact_pool(interp, interp->mem_pools, interp->mem_pools->memory_pool);
+ interp->gc_sys->compact_string_pool(interp);
}
/*
Modified: branches/gc_encapsulate_part2/src/gc/gc_ms.c
==============================================================================
--- branches/gc_encapsulate_part2/src/gc/gc_ms.c Tue Feb 9 13:49:58 2010 (r43811)
+++ branches/gc_encapsulate_part2/src/gc/gc_ms.c Tue Feb 9 13:50:25 2010 (r43812)
@@ -46,6 +46,11 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*buffer);
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static Buffer * gc_ms_allocate_bufferlike_header(PARROT_INTERP, size_t size)
+ __attribute__nonnull__(1);
+
PARROT_CAN_RETURN_NULL
static PMC* gc_ms_allocate_pmc_header(PARROT_INTERP, UINTVAL flags)
__attribute__nonnull__(1);
@@ -69,6 +74,13 @@
__attribute__nonnull__(1)
__attribute__nonnull__(2);
+static void gc_ms_free_bufferlike_header(PARROT_INTERP,
+ ARGMOD(Buffer *obj),
+ size_t size)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*obj);
+
static void gc_ms_free_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -154,6 +166,9 @@
#define ASSERT_ARGS_gc_ms_allocate_buffer_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(buffer))
+#define ASSERT_ARGS_gc_ms_allocate_bufferlike_header \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_gc_ms_allocate_pmc_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_gc_ms_allocate_string_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -166,6 +181,9 @@
#define ASSERT_ARGS_gc_ms_finalize_memory_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(mem_pools))
+#define ASSERT_ARGS_gc_ms_free_bufferlike_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(obj))
#define ASSERT_ARGS_gc_ms_free_pmc_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pmc))
@@ -240,6 +258,7 @@
interp->gc_sys->init_pool = gc_ms_pool_init;
interp->gc_sys->do_gc_mark = gc_ms_mark_and_sweep;
+ interp->gc_sys->compact_string_pool = gc_ms_compact_memory_pool;
interp->gc_sys->allocate_pmc_header = gc_ms_allocate_pmc_header;
interp->gc_sys->free_pmc_header = gc_ms_free_pmc_header;
@@ -247,6 +266,9 @@
interp->gc_sys->allocate_string_header = gc_ms_allocate_string_header;
interp->gc_sys->free_string_header = gc_ms_free_string_header;
+ interp->gc_sys->allocate_bufferlike_header = gc_ms_allocate_bufferlike_header;
+ interp->gc_sys->free_bufferlike_header = gc_ms_free_bufferlike_header;
+
interp->gc_sys->allocate_pmc_attributes = gc_ms_allocate_pmc_attributes;
interp->gc_sys->free_pmc_attributes = gc_ms_free_pmc_attributes;
@@ -383,6 +405,25 @@
/*
+=item C<void gc_ms_compact_memory_pool(PARROT_INTERP)>
+
+Scan the string pools and compact them. This does not perform a GC mark or
+sweep run, and does not check whether string buffers are still alive.
+Redirects to C<compact_pool>.
+
+=cut
+
+*/
+
+void
+gc_ms_compact_memory_pool(PARROT_INTERP)
+{
+ ASSERT_ARGS(gc_ms_compact_memory_pool)
+ compact_pool(interp, interp->mem_pools, interp->mem_pools->memory_pool);
+}
+
+/*
+
=item C<static void gc_ms_finalize_memory_pools(PARROT_INTERP, Memory_Pools *
const mem_pools)>
@@ -502,6 +543,52 @@
}
}
+/*
+
+=item C<static Buffer * gc_ms_allocate_bufferlike_header(PARROT_INTERP, size_t
+size)>
+
+Returns a new buffer-like header from the appropriate sized pool.
+A "bufferlike object" is an object that is considered to be isomorphic to the
+PObj, so it will participate in normal GC. At the moment these are only used
+to create ListChunk objects in src/list.c.
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static Buffer *
+gc_ms_allocate_bufferlike_header(PARROT_INTERP, size_t size)
+{
+ ASSERT_ARGS(gc_ms_allocate_bufferlike_header)
+
+ Fixed_Size_Pool * const pool = get_bufferlike_pool(interp, interp->mem_pools, size);
+
+ return (Buffer *)pool->get_free_object(interp, interp->mem_pools, pool);
+}
+
+/*
+
+=item C<static void gc_ms_free_bufferlike_header(PARROT_INTERP, Buffer *obj,
+size_t size)>
+
+Free a bufferlike header that is not being used, so that Parrot can recycle
+it and use it again.
+
+=cut
+
+*/
+
+static void
+gc_ms_free_bufferlike_header(PARROT_INTERP, ARGMOD(Buffer *obj),
+ size_t size)
+{
+ ASSERT_ARGS(Parrot_gc_free_bufferlike_header)
+ Fixed_Size_Pool * const pool = get_bufferlike_pool(interp, interp->mem_pools, size);
+ pool->add_free_object(interp, interp->mem_pools, pool, obj);
+}
/*
Modified: branches/gc_encapsulate_part2/src/gc/gc_private.h
==============================================================================
--- branches/gc_encapsulate_part2/src/gc/gc_private.h Tue Feb 9 13:49:58 2010 (r43811)
+++ branches/gc_encapsulate_part2/src/gc/gc_private.h Tue Feb 9 13:50:25 2010 (r43812)
@@ -102,9 +102,11 @@
/** Function hooks that each subsystem MUST provide */
void (*finalize_gc_system) (PARROT_INTERP);
void (*destroy_child_interp)(Interp *dest_interp, Interp *child_interp);
+
void (*do_gc_mark)(PARROT_INTERP, UINTVAL flags);
- void (*init_pool)(PARROT_INTERP, struct Fixed_Size_Pool *);
+ void (*compact_string_pool)(PARROT_INTERP);
+ void (*init_pool)(PARROT_INTERP, struct Fixed_Size_Pool *);
PMC* (*allocate_pmc_header)(PARROT_INTERP, UINTVAL flags);
void (*free_pmc_header)(PARROT_INTERP, PMC *);
@@ -112,6 +114,9 @@
STRING* (*allocate_string_header)(PARROT_INTERP, UINTVAL flags);
void (*free_string_header)(PARROT_INTERP, STRING*);
+ Buffer* (*allocate_bufferlike_header)(PARROT_INTERP, size_t size);
+ void (*free_bufferlike_header)(PARROT_INTERP, Buffer*, size_t size);
+
void* (*allocate_pmc_attributes)(PARROT_INTERP, PMC *);
void (*free_pmc_attributes)(PARROT_INTERP, PMC *);
@@ -598,6 +603,9 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*str);
+void gc_ms_compact_memory_pool(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
void gc_ms_free_fixed_size_storage(PARROT_INTERP,
size_t size,
ARGMOD(void *data))
@@ -622,6 +630,8 @@
#define ASSERT_ARGS_gc_ms_allocate_string_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(str))
+#define ASSERT_ARGS_gc_ms_compact_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_gc_ms_free_fixed_size_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(data))
Modified: branches/gc_encapsulate_part2/src/pmc/imageio.pmc
==============================================================================
--- branches/gc_encapsulate_part2/src/pmc/imageio.pmc Tue Feb 9 13:49:58 2010 (r43811)
+++ branches/gc_encapsulate_part2/src/pmc/imageio.pmc Tue Feb 9 13:50:25 2010 (r43812)
@@ -76,7 +76,7 @@
len = FREEZE_BYTES_PER_ITEM;
PARROT_IMAGEIO(info)->buffer =
- (Buffer *)Parrot_gc_new_bufferlike_header(interp, sizeof (Buffer));
+ Parrot_gc_new_bufferlike_header(interp, sizeof (Buffer));
Parrot_gc_allocate_buffer_storage_aligned(interp,
PARROT_IMAGEIO(info)->buffer, len);
SET_VISIT_CURSOR(info, (char *)Buffer_bufstart(PARROT_IMAGEIO(info)->buffer));
More information about the parrot-commits
mailing list