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

kzk at freedesktop.org kzk at freedesktop.org
Mon Aug 8 01:28:26 EST 2005


Author: kzk
Date: 2005-08-07 08:28:22 -0700 (Sun, 07 Aug 2005)
New Revision: 1155

Modified:
   branches/r5rs/sigscheme/datas.c
   branches/r5rs/sigscheme/sigschemetype.h
Log:
* Optimize gc_preprocess(). This patch is created by
  Jun Inoue <jun.lambda at gmail.com>. Thank you!

* sigscheme/sigschemetype.h
  - (enum GCMark): removed
  - (SCM_DO_MARK, SCM_DO_UNMARK, SCM_IS_MARKED): removed

* sigscheme/datas.c
  - commented out codes around posix_memalign
  - (SCM_UNMARKER, SCM_INITIAL_MARKER, SCM_IS_MARKED,
     SCM_IS_UNMARKED, SCM_DO_MARK, SCM_DO_UNMARK,
     SCM_MARK_CORRUPT): new func
  - (malloc_aligned): comment out posix_memalign
  - (gc_preprocess): optimize!


Modified: branches/r5rs/sigscheme/datas.c
===================================================================
--- branches/r5rs/sigscheme/datas.c	2005-08-07 10:18:58 UTC (rev 1154)
+++ branches/r5rs/sigscheme/datas.c	2005-08-07 15:28:22 UTC (rev 1155)
@@ -70,8 +70,8 @@
 #include <malloc.h>
 #endif
 
+/*
 #ifndef posix_memalign
-/*
  * Cited from manpage of posix_memalign(3) of glibc:
  * 
  * CONFORMING TO
@@ -79,9 +79,9 @@
  *     obsolete in BSD 4.3, and as legacy in SUSv2. It  no  longer  occurs  in
  *     SUSv3.   The  function memalign() appears in SunOS 4.1.3 but not in BSD
  *     4.4.  The function posix_memalign() comes from POSIX 1003.1d.
- */
 #error "posix_memalign(3) is not available in this system"
 #endif
+ */
 
 /*=======================================
   Local Include
@@ -111,6 +111,14 @@
     VALNAME = scm_freelist;						\
     scm_freelist = SCM_FREECELL_CDR(scm_freelist);			\
 
+#define SCM_UNMARKER        0
+#define SCM_INITIAL_MARKER  (SCM_UNMARKER + 1)
+#define SCM_IS_MARKED(a)    (SCM_MARK(a) == scm_cur_marker)
+#define SCM_IS_UNMARKED(a)  (!SCM_IS_MARKED)
+#define SCM_DO_MARK(a)      (SCM_MARK(a) = scm_cur_marker)
+#define SCM_DO_UNMARK(a)    (SCM_MARK(a) = SCM_UNMARKER)
+#define SCM_MARK_CORRUPT(a) ((unsigned)SCM_MARK(a) > (unsigned)scm_cur_marker)
+
 /*=======================================
   Variable Declarations
 =======================================*/
@@ -119,6 +127,8 @@
 static ScmObjHeap   *scm_heaps     = NULL;
 static ScmObj        scm_freelist  = NULL;
 
+static int           scm_cur_marker = SCM_INITIAL_MARKER;
+
 static jmp_buf save_regs_buf;
 ScmObj *stack_start_pointer = NULL;
 
@@ -171,9 +181,13 @@
 
 static void *malloc_aligned(size_t size)
 {
-    /* TODO : Need to reserch System Dependency! */
     void *p;
-    posix_memalign(&p, 16, size);
+    /* 2005/08/08  Kazuki Ohta  <mover at hct.zaq.ne.jp>
+     * commented out "posix_memalign"
+     *
+     * posix_memalign(&p, 16, size);
+     */
+    p = malloc(size);
     return p;
 }
 
@@ -278,12 +292,21 @@
 
 static void gc_preprocess(void)
 {
-    /* Initialize Mark Table */
-    int  i = 0;
-    long j = 0;
-    for (i = 0; i < scm_heap_num; i++) {
-	for (j = 0; j < SCM_HEAP_SIZE; j++) {
-	    SCM_DO_UNMARK(&scm_heaps[i][j]);
+    ++scm_cur_marker;		/* make everything unmarked */
+
+    if (scm_cur_marker == SCM_UNMARKER) {
+	/* We've been running long enough to do
+	 * (1 << (sizeof(int)*8)) - 1 GCs, yay! */
+	int  i = 0;
+	long j = 0;
+
+	scm_cur_marker = SCM_INITIAL_MARKER;
+
+	/* unmark everything */
+	for (i = 0; i < scm_heap_num; i++) {
+	    for (j = 0; j < SCM_HEAP_SIZE; j++) {
+		SCM_DO_UNMARK(&scm_heaps[i][j]);
+	    }
 	}
     }
 }
@@ -509,6 +532,7 @@
 	/* iterate in heap */
 	for (j = 0; j < SCM_HEAP_SIZE; j++) {
 	    obj = &scm_heaps[i][j];
+	    sigassert (!SCM_MARK_CORRUPT (obj));
 	    if (!SCM_IS_MARKED(obj)) {
 		sweep_obj(obj);
 

Modified: branches/r5rs/sigscheme/sigschemetype.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype.h	2005-08-07 10:18:58 UTC (rev 1154)
+++ branches/r5rs/sigscheme/sigschemetype.h	2005-08-07 15:28:22 UTC (rev 1155)
@@ -80,12 +80,6 @@
     ARGNUM_2N        = 9  /* all args are evaluated with each 2 objs */
 };
 
-/* GC Mark Flag */
-enum GCMark {
-    GC_Unmarked = 0,
-    GC_Marked = 1
-};
-
 /* ScmPort direction */
 enum ScmPortDirection {
     PORT_INPUT  = 0,
@@ -130,7 +124,7 @@
 typedef ScmObjInternal *ScmObj;
 struct ScmObjInternal_ {
     enum ScmObjType type;
-    enum GCMark gcmark;
+    int gcmark;
 
     union {
         struct {
@@ -227,9 +221,6 @@
 #define SCM_GETTYPE(a)       ((a)->type)
 #define SCM_SETTYPE(a, objtype) ((a)->type = (objtype))
 #define SCM_MARK(a) ((a)->gcmark)
-#define SCM_DO_MARK(a) (SCM_MARK(a) = GC_Marked)
-#define SCM_DO_UNMARK(a) (SCM_MARK(a) = GC_Unmarked)
-#define SCM_IS_MARKED(a) (SCM_MARK(a) == GC_Marked)
 
 #define SCM_INTP(a)  (SCM_GETTYPE(a) == ScmInt)
 #define SCM_INT(a)   (sigassert(SCM_INTP(a)), (a))



More information about the uim-commit mailing list