Author: yamakenz
Date: Mon Aug  6 03:35:21 2007
New Revision: 4790

Modified:
   sigscheme-trunk/src/sigschemeinternal.h
   sigscheme-trunk/src/storage-common.h
   sigscheme-trunk/src/storage-compact.h
   sigscheme-trunk/src/storage-fatty.h
   sigscheme-trunk/src/storage-gc.c

Log:
* src/sigschemeinternal.h
  - (SCM_RECLAIM_CELL): Removed
* src/storage-common.h
  - (SCM_CELL_FREECELLP, SCM_CELL_RECLAIM_CELL): New macro
* src/storage-compact.h
  - (SCM_INIT, SCM_SAL_FREECELL_NEXT): Add SCM_DROP_TAG(o) to accept proper
    FreeCell object. This is required to make scm_gc_protectedp() working
  - (SCM_SAL_RECLAIM_CELL): Removed
  - (SCM_ISAL_CELL_FREECELLP, SCM_ISAL_CELL_RECLAIM_CELL): New macro
* src/storage-fatty.h
  - (SCM_SAL_RECLAIM_CELL): Removed
  - (SCM_ISAL_CELL_FREECELLP, SCM_ISAL_CELL_RECLAIM_CELL): New macro
* src/storage-gc.c
  - (scm_gc_protectedp): Fix broken freecell detection on storage-compact
  - (add_heap): Follow the change of SCM_RECLAIM_CELL() ->
    SCM_CELL_RECLAIM_CELL()
  - (gc_sweep):
    * Ditto
    * Fix duplicated freecell linking on scm_gc_protectedp()


Modified: sigscheme-trunk/src/sigschemeinternal.h
==============================================================================
--- sigscheme-trunk/src/sigschemeinternal.h     (original)
+++ sigscheme-trunk/src/sigschemeinternal.h     Mon Aug  6 03:35:21 2007
@@ -236,10 +236,6 @@
 #define SCM_FREECELL_SET_FREESLOT(o, v) SCM_SAL_FREECELL_SET_FREESLOT((o), (v))
 #define SCM_FREECELL_CLEAR_FREESLOT(o)  SCM_SAL_FREECELL_CLEAR_FREESLOT((o))
 
-/* For optimized operation: Cleanup a destructed ScmCell *cell to a freecell
- * and chain it into freelist. */
-#define SCM_RECLAIM_CELL(cell, next)    SCM_SAL_RECLAIM_CELL((cell), (next))
-
 #if 0
 /* for future cleanup */
 #define SCM_CELL_MARKEDP(cell)   SCM_SAL_CELL_MARKEDP(cell)

Modified: sigscheme-trunk/src/storage-common.h
==============================================================================
--- sigscheme-trunk/src/storage-common.h        (original)
+++ sigscheme-trunk/src/storage-common.h        Mon Aug  6 03:35:21 2007
@@ -48,6 +48,24 @@
 #endif
 
 /*=======================================
+  Internal SAL
+=======================================*/
+#define SCM_CELL_FREECELLP(c)                                           \
+    SCM_TYPESAFE_MACRO(SCM_ISAL_CELL_FREECELLP,                         \
+                       int,                                             \
+                       (ScmCell *),                                     \
+                       (c))
+
+/* For optimized operation: Cleanup a destructed ScmCell *c to a freecell,
+ * chain it into freelist and returns ScmObj for c. */
+#define SCM_CELL_RECLAIM_CELL(c, next)                                  \
+    SCM_TYPESAFE_MACRO(SCM_ISAL_CELL_RECLAIM_CELL,                      \
+                       ScmObj,                                          \
+                       (ScmCell *, ScmObj),                             \
+                       ((c), (next)))
+
+
+/*=======================================
   Object Creators
 =======================================*/
 #if !SCM_SAL_HAS_IMMEDIATE_INT_ONLY

Modified: sigscheme-trunk/src/storage-compact.h
==============================================================================
--- sigscheme-trunk/src/storage-compact.h       (original)
+++ sigscheme-trunk/src/storage-compact.h       Mon Aug  6 03:35:21 2007
@@ -258,10 +258,10 @@
 #define SCM_Y(o)        (SCM_PTR(o)->obj_y)
 #define SCM_SET_X(o, x) (SCM_X(o) = (x))
 #define SCM_SET_Y(o, y) (SCM_Y(o) = (y))
-#define SCM_INIT(o, x, y, ptag)                 \
-    (SCM_SET_X((o), (x)),                       \
-     SCM_SET_Y((o), (y)),                       \
-     (o) |= (ptag))
+#define SCM_INIT(o, x, y, ptag)                                         \
+    (SCM_SET_X(SCM_DROP_TAG(o), (x)),                                   \
+     SCM_SET_Y(SCM_DROP_TAG(o), (y)),                                   \
+     (o) = SCM_DROP_TAG(o) | (ptag))
 
 #define SCM_SAL_EQ(a, b) ((a) == (b))
 
@@ -905,21 +905,20 @@
 #endif /* SCM_USE_HYGIENIC_MACRO */
 
 
-/* Each argument except for SCM_SAL_FREECELLP() must be an untagged pointer to
- * a cell.
- *
- * TODO: If we assume, as we currently safely can, that the GC never
- * marks a free cell (GC takes place until all freecells are used up),
- * we can leave obj_y untouched.  That optimization, however, has to
- * be coordinated with storage-gc.c.
- */
+/* TODO: If we assume that the GC never marks a free cell (GC takes place until
+ * all freecells are used up), we can leave obj_y untouched.  That
+ * optimization, however, has to be coordinated with storage-gc.c. */
 #define SCM_MTAG_FREECELL         SCM_MAKE_MTAG_L2(7, 3)
-#define SCM_SAL_FREECELL_NEXT(o)  (SCM_X(o))
+#define SCM_SAL_FREECELL_NEXT(o)  (SCM_X(SCM_DROP_TAG(o)))
 #define SCM_SAL_FREECELLP(o)                                            \
     (!SCM_IMMP(o) && SCM_Y(SCM_DROP_TAG(o)) == SCM_MTAG_FREECELL)
-#define SCM_SAL_RECLAIM_CELL(o, next)                           \
-    (SCM_SET_X((o), (ScmObj)(next)), SCM_SET_Y((o), SCM_MTAG_FREECELL))
 
+#define SCM_ISAL_CELL_FREECELLP(c)                                      \
+    (SCM_Y(c) == SCM_MTAG_FREECELL)
+#define SCM_ISAL_CELL_RECLAIM_CELL(c, next)                             \
+    (SCM_SET_X((c), (SCM_NULLP(next) ? (next) : ((next) | SCM_PTAG_MISC))), \
+     SCM_SET_Y((c), SCM_MTAG_FREECELL),                                 \
+     ((ScmObj)(c) | SCM_PTAG_MISC))
 
 /* Typecode determination (slow but universally applicable). */
 SCM_EXPORT enum ScmObjType scm_type(ScmObj obj);

Modified: sigscheme-trunk/src/storage-fatty.h
==============================================================================
--- sigscheme-trunk/src/storage-fatty.h (original)
+++ sigscheme-trunk/src/storage-fatty.h Mon Aug  6 03:35:21 2007
@@ -457,13 +457,13 @@
 #define SCM_SAL_FREECELL_CLEAR_FREESLOT(o)                                   \
     SCM_SAL_FREECELL_SET_FREESLOT((o), SCM_FALSE)
 
-#define SCM_SAL_RECLAIM_CELL(cell, next)                                     \
-    do {                                                                     \
-        SCM_ENTYPE((cell), ScmFreeCell);                                     \
-        SCM_UNMARK(cell);                                                    \
-        SCM_FREECELL_SET_NEXT((cell), (next));                               \
-        SCM_FREECELL_CLEAR_FREESLOT(cell);                                   \
-    } while (/* CONSTCOND */ 0)
+#define SCM_ISAL_CELL_FREECELLP(c)     (SCM_FREECELLP(c))
+#define SCM_ISAL_CELL_RECLAIM_CELL(c, next)                             \
+    (SCM_ENTYPE((c), ScmFreeCell),                                      \
+     SCM_UNMARK(c),                                                     \
+     SCM_FREECELL_SET_NEXT((c), (next)),                                \
+     SCM_FREECELL_CLEAR_FREESLOT(c),                                    \
+     (ScmObj)(c))
 
 #define SCM_SAL_MARKEDP(o)   ((o)->attr.v.gcmark)
 #define SCM_SAL_UNMARKEDP(o) (!SCM_MARKEDP(o))

Modified: sigscheme-trunk/src/storage-gc.c
==============================================================================
--- sigscheme-trunk/src/storage-gc.c    (original)
+++ sigscheme-trunk/src/storage-gc.c    Mon Aug  6 03:35:21 2007
@@ -305,7 +305,11 @@
     }
     gc_sweep();
 
+#if SCM_USE_STORAGE_COMPACT
+    return !SCM_CELL_FREECELLP(SCM_UNTAG_PTR(obj));
+#else
     return !SCM_FREECELLP(obj);
+#endif
 }
 
 SCM_EXPORT void *
@@ -365,8 +369,8 @@
 
     /* link in order */
     for (cell = &heap[0]; cell < &heap[l_heap_size - 1]; cell++)
-        SCM_RECLAIM_CELL(cell, cell + 1);
-    SCM_RECLAIM_CELL(cell, l_freelist);
+        SCM_CELL_RECLAIM_CELL(cell, (ScmObj)(cell + 1));
+    SCM_CELL_RECLAIM_CELL(cell, l_freelist);
     /* assumes that (ScmCell *) can be being ScmObj */
     l_freelist = (ScmObj)heap;
 }
@@ -816,10 +820,11 @@
 
             if (SCM_MARKEDP(obj)) {
                 SCM_UNMARK(obj);
-            } else {
+            } else if (!SCM_CELL_FREECELLP(cell)) {
+                /* scm_gc_protectedp() causes GC sweep on heaps that contain
+                 * freecells. So !SCM_CELL_FREECELLP(cell) is required. */
                 free_cell(cell);
-                SCM_RECLAIM_CELL(cell, new_freelist);
-                new_freelist = (ScmObj)cell;
+                new_freelist = SCM_CELL_RECLAIM_CELL(cell, new_freelist);
                 n_collected++;
             }
         }

Reply via email to