[uim-commit] r2400 - branches/r5rs/sigscheme

kzk at freedesktop.org kzk at freedesktop.org
Tue Dec 6 12:00:43 PST 2005


Author: kzk
Date: 2005-12-06 12:00:33 -0800 (Tue, 06 Dec 2005)
New Revision: 2400

Modified:
   branches/r5rs/sigscheme/sigschemetype-compact.h
   branches/r5rs/sigscheme/storage-gc.c
Log:
* sigscheme/sigschemetype-compact.h
  - (SCM_NEED_SWEEPP,
     SCM_SWEEP_PHASE_SYMBOLP,
     SCM_SWEEP_PHASE_STRINGP,
     SCM_SWEEP_PHASE_VECTORP,
     SCM_SWEEP_PHASE_PORTP,
     SCM_SWEEP_PHASE_CONTINUATIONP): new macro

* sigscheme/storage-gc.c
  - (sweep_compact_cell): new func
  - (finalize_heap, gc_sweep): use sweep_compact_cell when
    SCM_OBJ_COMPACT flag is on



Modified: branches/r5rs/sigscheme/sigschemetype-compact.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype-compact.h	2005-12-06 16:54:51 UTC (rev 2399)
+++ branches/r5rs/sigscheme/sigschemetype-compact.h	2005-12-06 20:00:33 UTC (rev 2400)
@@ -715,6 +715,17 @@
 #define SCM_CANBE_MARKED(a)   ((a) && !SCM_TAG_IMMP(a))
 #define SCM_STRIP_TAG_INFO(a) (SCM_CAST_UINT(a) & SCM_VALUE_MASK)
 
+/* When we sweep the object, we have no type information because the pointer is
+ * not tagged (raw pointer to heap). So, we see the S->cdr's GC bit and its value
+ * is 1, the object contains the pointer to be freed. */
+#define SCM_NEED_SWEEPP(a) (SCM_CAST_CDR_UINT(a) & SCM_GCBIT_MASK)
+/* directry see the S->cdr's tag */
+#define SCM_SWEEP_PHASE_SYMBOLP(a)       (SCM_TAG_OTHERS_SYMBOLP(a))
+#define SCM_SWEEP_PHASE_STRINGP(a)       (SCM_TAG_OTHERS_STRINGP(a))
+#define SCM_SWEEP_PHASE_VECTORP(a)       (SCM_TAG_OTHERS_VECTORP(a))
+#define SCM_SWEEP_PHASE_PORTP(a)         (SCM_TAG_OTHERS_PORTP(a))
+#define SCM_SWEEP_PHASE_CONTINUATIONP(a) (SCM_TAG_OTHERS_CONTINUATIONP(a))
+
 /*============================================================================
   Predefined Symbols
 ============================================================================*/

Modified: branches/r5rs/sigscheme/storage-gc.c
===================================================================
--- branches/r5rs/sigscheme/storage-gc.c	2005-12-06 16:54:51 UTC (rev 2399)
+++ branches/r5rs/sigscheme/storage-gc.c	2005-12-06 20:00:33 UTC (rev 2400)
@@ -145,11 +145,16 @@
 static void gc_mark(void);
 
 /* GC Sweep Related Functions */
-static void sweep_obj(ScmObj obj);
 static void gc_sweep(void);
 
 static void finalize_protected_var(void);
 
+#if SCM_OBJ_COMPACT
+static void sweep_compact_cell(ScmCell *cell);
+#else /* SCM_OBJ_COMPACT */
+static void sweep_obj(ScmObj obj);
+#endif /* SCM_OBJ_COMPACT */
+
 /*=======================================
   Function Implementations
 =======================================*/
@@ -323,10 +328,7 @@
         heap = scm_heaps[i];
         for (cell = &heap[0]; cell < &heap[SCM_HEAP_SIZE]; cell++) {
 #if SCM_OBJ_COMPACT
-            /* FIXME: we have no type information for obj here. So
-             * sweep_obj(obj) is inefficient since type information retrieval
-             * is expensive. Provide sweep_compact_cell(ScmCell *cell).
-             */
+            sweep_compact_cell(cell);
 #else
             sweep_obj((ScmObj)cell);
 #endif
@@ -468,12 +470,10 @@
 static void gc_mark_locations_n(ScmObj *start, int n)
 {
     ScmObj *objp;
-
     for (objp = start; objp < &start[n]; objp++) {
         if (is_pointer_to_heap(*objp))
             mark_obj(*objp);
     }
-
 }
 
 static void gc_mark_locations(ScmObj *start, ScmObj *end)
@@ -525,6 +525,35 @@
     gc_mark_symbol_hash();
 }
 
+#if SCM_OBJ_COMPACT
+static void sweep_compact_cell(ScmCell *cell)
+{
+    if (SCM_NEED_SWEEPP(cell)) {
+        if (SCM_SWEEP_PHASE_SYMBOLP(cell)) {
+            if (SCM_SYMBOL_NAME(cell))
+                free(SCM_SYMBOL_NAME(cell));
+        } else if (SCM_SWEEP_PHASE_STRINGP(cell)) {
+            if (SCM_STRING_STR(cell))
+                free(SCM_STRING_STR(cell));
+        } else if (SCM_SWEEP_PHASE_VECTORP(cell)) {
+            if (SCM_VECTOR_VEC(cell))
+                free(SCM_VECTOR_VEC(cell));
+        } else if (SCM_SWEEP_PHASE_PORTP(cell)) {
+            if (SCM_PORT_IMPL(cell))
+                SCM_PORT_CLOSE_IMPL(cell);
+        } else if (SCM_SWEEP_PHASE_CONTINUATIONP(cell)) {
+            /*
+             * Since continuation object is not so many, destructing the object by
+             * function call will not cost high. This function interface makes
+             * continuation module substitution easy without preparing
+             * module-specific header file which contains the module-specific
+             * destruction macro.
+             */
+            Scm_DestructContinuation(cell);
+        }
+    }
+}
+#else /* SCM_OBJ_COMPACT */
 static void sweep_obj(ScmObj obj)
 {
     switch (SCM_TYPE(obj)) {
@@ -573,6 +602,7 @@
         break;
     }
 }
+#endif /* SCM_OBJ_COMPACT */
 
 static void gc_sweep(void)
 {
@@ -597,11 +627,7 @@
                 SCM_DO_UNMARK(obj);
             } else {
 #if SCM_OBJ_COMPACT
-                /* FIXME: we have no type information for obj here. So
-                 * sweep_obj(obj) is inefficient since type information
-                 * retrieval is expensive. Provide sweep_compact_cell(ScmCell
-                 * *cell).
-                 */
+                sweep_compact_cell(cell);
 #else
                 sweep_obj(obj);
 #endif



More information about the uim-commit mailing list