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

yamaken at freedesktop.org yamaken at freedesktop.org
Fri Dec 9 05:39:17 PST 2005


Author: yamaken
Date: 2005-12-09 05:39:13 -0800 (Fri, 09 Dec 2005)
New Revision: 2493

Modified:
   branches/r5rs/sigscheme/storage-gc.c
Log:
* sigscheme/storage-gc.c
  - (heaps_lowest, heaps_highest): New static variable
  - (add_heap, within_heapp): Improve average performance using
    heaps_lowest and heaps_highest


Modified: branches/r5rs/sigscheme/storage-gc.c
===================================================================
--- branches/r5rs/sigscheme/storage-gc.c	2005-12-09 13:23:49 UTC (rev 2492)
+++ branches/r5rs/sigscheme/storage-gc.c	2005-12-09 13:39:13 UTC (rev 2493)
@@ -103,6 +103,7 @@
 static size_t heap_size, heap_alloc_threshold;
 static int n_heaps, n_heaps_max;
 static ScmObjHeap *heaps;
+static ScmCell *heaps_lowest, *heaps_highest;
 static ScmObj freelist;
 
 static jmp_buf save_regs_buf;
@@ -280,6 +281,7 @@
     n_heaps_max = n_max;
     n_heaps = 0;
     heaps = NULL;
+    heaps_lowest = heaps_highest = NULL;
     freelist = SCM_NULL;
 
     /* preallocate heaps */
@@ -303,6 +305,12 @@
         ERR("memory exhausted"); /* FIXME: replace with fatal error handling */
     heaps[n_heaps++] = heap;
 
+    /* update the enclosure */
+    if (heaps_highest < &heap[heap_size])
+        heaps_highest = &heap[heap_size];
+    if (&heap[0] < heaps_lowest)
+        heaps_lowest = &heap[0];
+
     /* link in order */
     for (cell = &heap[0]; cell < &heap[heap_size]; cell++) {
         SCM_ENTYPE_FREECELL(cell);
@@ -416,9 +424,6 @@
 
 /* The core part of Conservative GC */
 
-/* TODO: improve average performance by maintaining max(heaps[all]) and
- * min(heaps[all]) at add_heap().
- */
 static int within_heapp(ScmObj obj)
 {
     ScmCell *heap, *ptr;
@@ -433,13 +438,18 @@
 #else
     ptr = obj;
 #endif
-    /* heaps must be aligned to sizeof(ScmCell) */
-    if ((uintptr_t)ptr % sizeof(ScmCell))
+    /*
+     * Reject by rough conditions:
+     * - heaps must be aligned to sizeof(ScmCell)
+     * - ptr is pointing to outside the enclosure which contain all heaps
+     */
+    if (((uintptr_t)ptr % sizeof(ScmCell))
+        || (ptr < heaps_lowest || heaps_highest <= ptr))
         return 0;
 
     for (i = 0; i < n_heaps; i++) {
         heap = heaps[i];
-        if (heap && heap <= ptr && ptr < &heap[heap_size])
+        if (heap && &heap[0] <= ptr && ptr < &heap[heap_size])
             return 1;
     }
 



More information about the uim-commit mailing list