[svn:parrot] r40013 - in trunk: config/gen/makefiles include/parrot src/gc

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Sun Jul 12 12:46:27 UTC 2009


Author: whiteknight
Date: Sun Jul 12 12:46:24 2009
New Revision: 40013
URL: https://trac.parrot.org/parrot/changeset/40013

Log:
[gc] add a new 'infinite memory' GC core, which is basically as simple a GC core as we can make. It is for demonstration purposes only, it should not be used for anything and actually fails some tests by design (timely destruction, closing/flushing of filehandles at finalization, etc).

Added:
   trunk/src/gc/gc_inf.c
Modified:
   trunk/config/gen/makefiles/root.in
   trunk/include/parrot/gc_api.h
   trunk/include/parrot/settings.h
   trunk/src/gc/alloc_resources.c
   trunk/src/gc/api.c
   trunk/src/gc/mark_sweep.c

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/config/gen/makefiles/root.in	Sun Jul 12 12:46:24 2009	(r40013)
@@ -413,6 +413,7 @@
     $(SRC_DIR)/gc/generational_ms$(O) \
     $(SRC_DIR)/gc/incremental_ms$(O) \
     $(SRC_DIR)/gc/gc_ms$(O) \
+    $(SRC_DIR)/gc/gc_inf$(O) \
     $(SRC_DIR)/gc/mark_sweep$(O) \
     $(SRC_DIR)/gc/system$(O) \
     $(SRC_DIR)/global$(O) \
@@ -1095,6 +1096,8 @@
 
 $(SRC_DIR)/gc/gc_ms$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/gc/gc_ms.c
 
+$(SRC_DIR)/gc/gc_inf$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/gc/gc_inf.c
+
 $(SRC_DIR)/gc/api$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/gc/gc_private.h
 
 $(SRC_DIR)/gc/generational_ms$(O) : $(GENERAL_H_FILES)

Modified: trunk/include/parrot/gc_api.h
==============================================================================
--- trunk/include/parrot/gc_api.h	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/include/parrot/gc_api.h	Sun Jul 12 12:46:24 2009	(r40013)
@@ -456,6 +456,9 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: src/gc/api.c */
 
+void Parrot_gc_inf_init(PARROT_INTERP);
+
+
 /* DEPRECATED. pobject_lives is being renamed to Parrot_gc_mark_PObj_alive.
    this macro is provided for compatibility until version 1.4 or later when
    it can be removed per the deprecation policy. See TT #664 for details */
@@ -491,6 +494,11 @@
 
 #endif
 
+#if PARROT_GC_INF
+#  define GC_WRITE_BARRIER(interp, agg, old, _new) do { } while (0)
+#  define GC_WRITE_BARRIER_KEY(interp, agg, old, old_key, _new, new_key) do { } while (0)
+#endif
+
 #endif /* PARROT_GC_API_H_GUARD */
 
 /*

Modified: trunk/include/parrot/settings.h
==============================================================================
--- trunk/include/parrot/settings.h	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/include/parrot/settings.h	Sun Jul 12 12:46:24 2009	(r40013)
@@ -39,8 +39,10 @@
  * 0 ... MS  stop-the-world mark & sweep
  * 1 ... IMS incremental mark & sweep
  * 2 ... GMS generational mark & sweep
+ * 3 ... INF infinite memory "collector"
  *
- * Please note that only 0 currently works.
+ * Please note that only 0 and 3 currently work (and INF doesn't really
+ * "work").
  */
 
 #define PARROT_GC_SUBSYSTEM 0
@@ -49,16 +51,25 @@
 #  define PARROT_GC_MS      1
 #  define PARROT_GC_IMS     0
 #  define PARROT_GC_GMS     0
+#  define PARROT_GC_INF     0
 #endif
 #if PARROT_GC_SUBSYSTEM == 1
 #  define PARROT_GC_MS      0
 #  define PARROT_GC_IMS     1
 #  define PARROT_GC_GMS     0
+#  define PARROT_GC_INF     0
 #endif
 #if PARROT_GC_SUBSYSTEM == 2
 #  define PARROT_GC_MS      0
 #  define PARROT_GC_IMS     0
 #  define PARROT_GC_GMS     1
+#  define PARROT_GC_INF     0
+#endif
+#if PARROT_GC_SUBSYSTEM == 3
+#  define PARROT_GC_MS      0
+#  define PARROT_GC_IMS     0
+#  define PARROT_GC_GMS     0
+#  define PARROT_GC_INF     1
 #endif
 
 /*

Modified: trunk/src/gc/alloc_resources.c
==============================================================================
--- trunk/src/gc/alloc_resources.c	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/src/gc/alloc_resources.c	Sun Jul 12 12:46:24 2009	(r40013)
@@ -199,7 +199,7 @@
         if (!interp->arena_base->gc_mark_block_level
         &&   interp->arena_base->mem_allocs_since_last_collect) {
             Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG);
-#if !PARROT_GC_IMS
+#if !PARROT_GC_IMS && !PARROT_GC_INF
             /* Compact the pool if allowed and worthwhile */
             if (pool->compact) {
                 /* don't bother reclaiming if it's just chicken feed */

Modified: trunk/src/gc/api.c
==============================================================================
--- trunk/src/gc/api.c	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/src/gc/api.c	Sun Jul 12 12:46:24 2009	(r40013)
@@ -276,6 +276,9 @@
 #if PARROT_GC_GMS
     Parrot_gc_gms_init(interp);
 #endif
+#if PARROT_GC_INF
+    Parrot_gc_inf_init(interp);
+#endif
 
     initialize_memory_pools(interp);
     initialize_header_pools(interp);

Added: trunk/src/gc/gc_inf.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/src/gc/gc_inf.c	Sun Jul 12 12:46:24 2009	(r40013)
@@ -0,0 +1,174 @@
+/*
+Copyright (C) 2001-2009, Parrot Foundation.
+$Id: gc_ms.c 39537 2009-06-13 19:17:13Z chromatic $
+
+=head1 NAME
+
+src/gc/gc_inf.c - A demonstration of an infinite memory garbage collector
+
+=head1 DESCRIPTION
+
+This code implements an example of a bare-bones "infinite memory" garbage
+collector. This is a learning tool only to demonstrate how to implement the
+GC API in a new core. DO NOT USE THIS CORE ANYWHERE FOR ANY REASON.
+
+Because this core never frees memory, some functionality is missing and some
+tests will fail: Tests for timely destruction, tests involving IO that is
+not manually flushed (the GC never calls the destroy VTABLE, so things never
+get flushed/closed automatically), etc.
+
+To enable this core, change the settings in include/parrot/settings.h
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+#include "gc_private.h"
+
+/* HEADERIZER HFILE: src/gc/gc_private.h */
+
+/* HEADERIZER BEGIN: static */
+/* HEADERIZER END: static */
+
+/*
+
+=head1 Functions
+
+=over 4
+
+=item C<void gc_inf_mark_and_sweep(PARROT_INTERP, UINTVAL flags)>
+
+This function would perform a GC run, if we needed to. Luckily we have
+infinite memory!
+
+=cut
+
+*/
+
+static void
+gc_inf_mark_and_sweep(SHIM_INTERP, UINTVAL flags)
+{
+}
+
+/*
+
+=item C<void gc_inf_add_free_object(SHIM_INTERP, Small_Object_Pool *pool,
+    void *to_add)>
+
+Manually frees a chunk of memory.
+
+=cut
+
+*/
+
+static void
+gc_inf_add_free_object(SHIM_INTERP, ARGMOD(Small_Object_Pool *pool),
+    ARGIN(void *to_add))
+{
+    if (to_add)
+        free(to_add);
+}
+
+/*
+
+=item C<void *gc_inf_get_free_object(PARROT_INTERP, Small_Object_Pool *pool)>
+
+Gets a new buffer from memory of the required size
+
+=cut
+
+*/
+
+static void *
+gc_inf_get_free_object(SHIM_INTERP, ARGMOD(Small_Object_Pool *pool))
+{
+    return calloc(pool->object_size, 1);
+}
+
+/*
+
+=item C<void gc_inf_alloc_objects(PARROT_INTERP, Small_Object_Pool *pool)>
+
+Allocates a new arena of objects from the system. Actually, it doesn't here.
+
+=cut
+
+*/
+
+static void
+gc_inf_alloc_objects(SHIM_INTERP, ARGMOD(Small_Object_Pool *pool))
+{
+}
+
+/*
+
+=item C<void gc_inf_more_traceable_objects(PARROT_INTERP, Small_Object_Pool *pool)>
+
+Would normally try to find new traceable objects by first running a GC sweep
+and then allocating a new arena from the system. Neither of these are
+necessary in the infinite memory collector
+
+=cut
+
+*/
+
+static void
+gc_inf_more_traceable_objects(SHIM_INTERP, ARGMOD(Small_Object_Pool *pool))
+{
+}
+
+/*
+
+=item C<void gc_inf_pool_init(PARROT_INTERP, Small_Object_Pool * pool)>
+
+Initializes the function pointers in a new pool
+
+=cut
+
+*/
+
+static void
+gc_inf_pool_init(SHIM_INTERP, ARGMOD(Small_Object_Pool *pool))
+{
+    pool->add_free_object = gc_inf_add_free_object;
+    pool->get_free_object = gc_inf_get_free_object;
+    pool->alloc_objects   = gc_inf_alloc_objects;
+    pool->more_objects    = gc_inf_more_traceable_objects;
+}
+
+/*
+
+=item C<void Parrot_gc_inf_init(PARROT_INTERP)>
+
+Initializes the infinite memory collector
+
+=cut
+
+*/
+
+void
+Parrot_gc_inf_init(PARROT_INTERP)
+{
+    Arenas * const arena_base     = interp->arena_base;
+
+    arena_base->do_gc_mark         = gc_inf_mark_and_sweep;
+    arena_base->finalize_gc_system = NULL;
+    arena_base->init_pool          = gc_inf_pool_init;
+}
+
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Modified: trunk/src/gc/mark_sweep.c
==============================================================================
--- trunk/src/gc/mark_sweep.c	Sun Jul 12 03:57:01 2009	(r40012)
+++ trunk/src/gc/mark_sweep.c	Sun Jul 12 12:46:24 2009	(r40013)
@@ -1082,6 +1082,8 @@
      * Use GS MS pool functions
      */
     gc_ms_pmc_ext_pool_init(arena_base->pmc_ext_pool);
+#elif PARROT_GC_INF
+    arena_base->init_pool(interp, arena_base->pmc_ext_pool);
 #else
     /* rational, consistant behavior (as yet unwritten) */
 #endif


More information about the parrot-commits mailing list