[svn:parrot] r43319 - branches/boehm_gc/src/gc
bacek at svn.parrot.org
bacek at svn.parrot.org
Wed Dec 30 12:20:17 UTC 2009
Author: bacek
Date: Wed Dec 30 12:20:17 2009
New Revision: 43319
URL: https://trac.parrot.org/parrot/changeset/43319
Log:
Implement finalization and explicit collect in Boehm GC.
Modified:
branches/boehm_gc/src/gc/gc_boehm.c
Modified: branches/boehm_gc/src/gc/gc_boehm.c
==============================================================================
--- branches/boehm_gc/src/gc/gc_boehm.c Wed Dec 30 12:19:55 2009 (r43318)
+++ branches/boehm_gc/src/gc/gc_boehm.c Wed Dec 30 12:20:17 2009 (r43319)
@@ -38,9 +38,11 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*pool);
+static void gc_boehm_finalize_cb(GC_PTR obj, GC_PTR user_data);
PARROT_CANNOT_RETURN_NULL
-static void * gc_boehm_get_free_object(SHIM_INTERP,
+static void * gc_boehm_get_free_object(PARROT_INTERP,
ARGMOD(Fixed_Size_Pool *pool))
+ __attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*pool);
@@ -59,8 +61,10 @@
, PARROT_ASSERT_ARG(to_add))
#define ASSERT_ARGS_gc_boehm_alloc_objects __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_gc_boehm_finalize_cb __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_gc_boehm_get_free_object __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(pool))
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(pool))
#define ASSERT_ARGS_gc_boehm_mark_and_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_gc_boehm_more_traceable_objects \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -98,6 +102,7 @@
{
ASSERT_ARGS(gc_boehm_mark_and_sweep)
UNUSED(flags);
+ GC_gcollect();
}
/*
@@ -151,10 +156,13 @@
PARROT_CANNOT_RETURN_NULL
static void *
-gc_boehm_get_free_object(SHIM_INTERP, ARGMOD(Fixed_Size_Pool *pool))
+gc_boehm_get_free_object(PARROT_INTERP, ARGMOD(Fixed_Size_Pool *pool))
{
ASSERT_ARGS(gc_boehm_get_free_object)
- return GC_MALLOC(pool->object_size);
+ void *ret = GC_MALLOC(pool->object_size);
+ if (pool->object_size == sizeof(PMC))
+ GC_REGISTER_FINALIZER(ret, gc_boehm_finalize_cb, interp, NULL, NULL);
+ return ret;
}
/*
@@ -230,6 +238,18 @@
pool->more_objects = gc_boehm_more_traceable_objects;
}
+static void
+gc_boehm_finalize_cb(GC_PTR obj, GC_PTR user_data)
+{
+ //fprintf(stderr, "Finalize %p (%p)\n", obj, interp);
+ PMC *pmc = (PMC*)obj;
+ Parrot_Interp interp = (Parrot_Interp)user_data;
+
+ if (PObj_custom_destroy_TEST(pmc))
+ VTABLE_destroy(interp, pmc);
+
+}
+
/*
=item C<void Parrot_gc_boehm_init(PARROT_INTERP)>
More information about the parrot-commits
mailing list