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

tkng at freedesktop.org tkng at freedesktop.org
Mon Jul 25 08:34:24 EST 2005


Author: tkng
Date: 2005-07-24 15:34:21 -0700 (Sun, 24 Jul 2005)
New Revision: 1025

Modified:
   branches/r5rs/sigscheme/datas.c
Log:
* sigscheme/datas.c: This commit will imporve GC a bit.
 - Now heap will be allocated four times of SCM_HEAP_SIZE
   for loop unrolling.
 - Global variable should not used for loop conditions.


Modified: branches/r5rs/sigscheme/datas.c
===================================================================
--- branches/r5rs/sigscheme/datas.c	2005-07-24 20:20:25 UTC (rev 1024)
+++ branches/r5rs/sigscheme/datas.c	2005-07-24 22:34:21 UTC (rev 1025)
@@ -90,7 +90,7 @@
 /*=======================================
   Variable Declarations
 =======================================*/
-static int           SCM_HEAP_SIZE = 16384;
+static int           SCM_HEAP_SIZE = 4096;  /* For times of SCM_HEAP_SIZE will actually be alloccated. */
 static int           scm_heap_num  = 64;
 static ScmObjHeap   *scm_heaps     = NULL;
 static ScmObj        scm_freelist  = NULL;
@@ -159,9 +159,10 @@
     int j = 0;
     ScmObj prev = NULL;
     ScmObj next = NULL;
+    int heap_size_local = HEAP_SIZE * 4;
 
 #if DEBUG_GC
-    printf("allocate_heap num:%d size:%d\n", num_heap, HEAP_SIZE);
+    printf("allocate_heap num:%d size:%d\n", num_heap, heap_size_local);
 #endif
 
     /* allocate heap */
@@ -171,13 +172,13 @@
     /* fill with zero and construct free_list */
     for (i = 0; i < num_heap; i++) {
         /* Initialize Heap */
-        (*heaps)[i] = (ScmObj)malloc_aligned(sizeof(ScmObjInternal) * HEAP_SIZE);
-        memset((*heaps)[i], 0, sizeof(ScmObjInternal) * HEAP_SIZE);
+        (*heaps)[i] = (ScmObj)malloc_aligned(sizeof(ScmObjInternal) * heap_size_local);
+        memset((*heaps)[i], 0, sizeof(ScmObjInternal) * heap_size_local);
 
         /* link in order */
         prev = NULL;
         next = NULL;
-        for (j = 0; j < HEAP_SIZE; j++) {
+        for (j = 0; j < heap_size_local; j++) {
             next = &(*heaps)[i][j];
 	    SCM_SETFREECELL(next);
 
@@ -186,7 +187,7 @@
 		SCM_SETFREECELL_CDR(prev, next);
 
             /* the last cons' cdr is freelist */
-            if (j == HEAP_SIZE - 1)
+            if (j ==  heap_size_local - 1)
 		SCM_SETFREECELL_CDR(next, (*freelist));
 
             prev = next;
@@ -203,6 +204,7 @@
     int    num_heap = 0;
     ScmObj prev     = NULL;
     ScmObj next     = NULL;
+    int heap_size_local = HEAP_SIZE * 4;
 
 #if DEBUG_GC
     printf("add_heap current num of heaps:%d\n", *orig_num_heap);
@@ -216,11 +218,11 @@
     (*heaps) = (ScmObj*)realloc((*heaps), sizeof(ScmObj) * num_heap);
 
     /* allocate heap */
-    (*heaps)[num_heap - 1] = (ScmObj)malloc_aligned(sizeof(ScmObjInternal) * HEAP_SIZE);
-    memset((*heaps)[num_heap - 1], 0, sizeof(ScmObjInternal) * HEAP_SIZE);
+    (*heaps)[num_heap - 1] = (ScmObj)malloc_aligned(sizeof(ScmObjInternal) * heap_size_local);
+    memset((*heaps)[num_heap - 1], 0, sizeof(ScmObjInternal) * heap_size_local);
     
     /* link in order */
-    for (i = 0; i < HEAP_SIZE; i++) {
+    for (i = 0; i < heap_size_local ; i++) {
         next = &(*heaps)[num_heap - 1][i];
 	SCM_SETFREECELL(next);
 
@@ -228,7 +230,7 @@
 	    SCM_SETFREECELL_CDR(prev, next);
 
         /* the last cons' cdr is freelist */
-        if (i == HEAP_SIZE - 1)
+        if (i == heap_size_local - 1)
 	    SCM_SETFREECELL_CDR(next, (*freelist));
 
         prev = next;
@@ -239,11 +241,13 @@
 
 static void finalize_heap(void)
 {
-    int i = 0;
-    int j = 0;
+    unsigned int i = 0;
+    unsigned int j = 0;
+    unsigned int heap_num_local = scm_heap_num;
+    unsigned int heap_size_local = SCM_HEAP_SIZE*4;
 
-    for (i = 0; i < scm_heap_num; i++) {
-	for (j = 0; j < SCM_HEAP_SIZE; j++) {
+    for (i = 0; i < heap_num_local; i++) {
+	for (j = 0; j < heap_size_local; j++) {
 	    sweep_obj(&scm_heaps[i][j]);
 	}
 	free(scm_heaps[i]);
@@ -254,11 +258,17 @@
 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++) {
+    unsigned int i = 0;
+    unsigned int j = 0;
+    unsigned int heap_num_local = scm_heap_num;
+    unsigned int heap_size_local = SCM_HEAP_SIZE;
+
+    for (i = 0; i < heap_num_local; i++) {
+	for (j = 0; j < heap_size_local; j++) {
 	    SCM_DO_UNMARK(&scm_heaps[i][j]);
+	    SCM_DO_UNMARK(&scm_heaps[i][j+1]);
+	    SCM_DO_UNMARK(&scm_heaps[i][j+2]);
+	    SCM_DO_UNMARK(&scm_heaps[i][j+3]);
 	}
     }
 }
@@ -340,12 +350,14 @@
 static int is_pointer_to_heap(ScmObj obj)
 {
     /* The core part of Conservative GC */
-    int i;
+    unsigned int i;
     ScmObj head = SCM_NIL;
-    for (i = 0; i < scm_heap_num; i++) {
+    unsigned int heap_num_local = scm_heap_num;
+    unsigned int heap_size_local = SCM_HEAP_SIZE * 4;
+    for (i = 0; i < heap_num_local; i++) {
 	if ((head = scm_heaps[i])
 	    && (head <= obj)
-	    && (obj  <  head + SCM_HEAP_SIZE)
+	    && (obj  <  head + heap_size_local)
 	    && ((((char*)obj - (char*)head) % sizeof(ScmObj)) == 0))
 	    return 1;
     }
@@ -377,8 +389,9 @@
     /* get size */
     size = end - start;
 
+#if DEBUG_GC
     printf("gc_mark_stack() : size = %d\n", size);
-
+#endif
     /* mark stack */
     for (i = 0; i < size; i++) {
         if (is_pointer_to_heap(start[i])) {
@@ -455,18 +468,20 @@
 
 static void gc_sweep(void)
 {
-    int i = 0;
-    int j = 0;
+    unsigned int i = 0;
+    unsigned int j = 0;
     int corrected_obj_num = 0;
+    unsigned int heap_num_local = scm_heap_num;
+    unsigned int heap_size_local = SCM_HEAP_SIZE * 4;
 
     ScmObj obj = SCM_NIL;
     ScmObj scm_new_freelist = SCM_NIL;
     /* iterate heaps */
-    for (i = 0; i < scm_heap_num; i++) {
+    for (i = 0; i < heap_num_local ; i++) {
 	corrected_obj_num = 0;
 	
 	/* iterate in heap */
-	for (j = 0; j < SCM_HEAP_SIZE; j++) {
+	for (j = 0; j < heap_size_local; j++) {
 	    obj = &scm_heaps[i][j];
 	    if (!SCM_IS_MARKED(obj)) {
 		sweep_obj(obj);



More information about the uim-commit mailing list