[start using bits in pages directly as grey set
John Meacham <john@repetae.net>**20100406223210
 Ignore-this: d49718e6c79fb8f529aa1404624b0bdd
] hunk ./src/data/rts/jhc_jgc.c 14
-
hunk ./src/data/rts/jhc_jgc.c 31
+#define TO_GCPTR(x) (void *)((uintptr_t)FROM_SPTR(x) - sizeof(entry_t))
+
hunk ./src/data/rts/jhc_jgc.c 43
+gc_check_heap(void *s)
+{
+        int r; J1T(r,gc_inheap,(uintptr_t)s / PAGESIZE);
+        return r;
+}
+
+static void
hunk ./src/data/rts/jhc_jgc.c 53
-                int r; J1S(r,gc_roots,(((Word_t)root - sizeof(entry_t)) / GC_ALIGNMENT));
-                return (bool)r;
-        } else
-                return false;
+                void * nroot = TO_GCPTR(root);
+                if(gc_check_heap((void *)nroot)) {
+                        int r; J1S(r,gc_roots,(Word_t)nroot);
+                }
+        }
+        //       if(SHOULD_FOLLOW(root)) {
+        //                       int r; J1S(r,gc_roots,(((Word_t)root - sizeof(entry_t)) / GC_ALIGNMENT));
+        //               return (bool)r;
+        //       } else
+        //               return false;
hunk ./src/data/rts/jhc_jgc.c 65
-
hunk ./src/data/rts/jhc_jgc.c 87
+/*
hunk ./src/data/rts/jhc_jgc.c 99
+*/
+
+static void
+gc_add_grey(struct stack *stack, void *s)
+{
+        if(gc_check_heap(s) && s_set_used_bit(s))
+                stack->stack[stack->ptr++] = (uintptr_t)s;
+}
hunk ./src/data/rts/jhc_jgc.c 119
-        Pvoid_t gc_grey = NULL;
+        clear_used_bits(arena);
+//        Pvoid_t gc_grey = NULL;
hunk ./src/data/rts/jhc_jgc.c 127
-                debugf(" %p", (void *)(ix * GC_ALIGNMENT));
-                gc_add_grey(&gc_grey, &stack, ix);
+                debugf(" %p", (void *)ix);
+                gc_add_grey(&stack, (void *)ix);
hunk ./src/data/rts/jhc_jgc.c 169
+                                if(gc_check_heap(ptr)) {
+                                        s_set_used_bit(TO_GCPTR(ptr));
+                                }
+                                /*
hunk ./src/data/rts/jhc_jgc.c 176
+                                        */
hunk ./src/data/rts/jhc_jgc.c 187
-                entry_t *e = (entry_t *)FROM_SPTR(ptr) - 1;
+                entry_t *e = (entry_t *)TO_GCPTR(ptr); // (entry_t *)FROM_SPTR(ptr) - 1;
hunk ./src/data/rts/jhc_jgc.c 189
-                ix = (Word_t)e / GC_ALIGNMENT;
-                gc_add_grey(&gc_grey, &stack, ix);
+                //ix = (Word_t)e / GC_ALIGNMENT;
+                gc_add_grey(&stack, e);
hunk ./src/data/rts/jhc_jgc.c 196
-                uintptr_t ix = stack.stack[--stack.ptr] / GC_ALIGNMENT;
-                debugf("Processing Grey: %p\n",(void *)(ix * GC_ALIGNMENT));
+                //uintptr_t ix = stack.stack[--stack.ptr] / GC_ALIGNMENT;
+                //debugf("Processing Grey: %p\n",(void *)(ix * GC_ALIGNMENT));
+                entry_t *e = (entry_t *)stack.stack[--stack.ptr];
+                debugf("Processing Grey: %p\n",e);
hunk ./src/data/rts/jhc_jgc.c 201
-                entry_t *e = (entry_t *)(ix * GC_ALIGNMENT);
hunk ./src/data/rts/jhc_jgc.c 212
-                                entry_t * ptr = (entry_t *)(FROM_SPTR(e->ptrs[i])) - 1;
+                                entry_t * ptr = (entry_t *)TO_GCPTR(e->ptrs[i]);
hunk ./src/data/rts/jhc_jgc.c 214
-                                gc_add_grey(&gc_grey, &stack, (uintptr_t)ptr / GC_ALIGNMENT);
+                                gc_add_grey( &stack, ptr);
hunk ./src/data/rts/jhc_jgc.c 219
-        for(ix = 0, (J1F(r,gc_allocated,ix)); r; (J1N(r,gc_allocated,ix))) {
-                entry_t *e = (entry_t *)(ix * GC_ALIGNMENT);
-                mem_inuse -= (e->u.v.count + 1)*GC_BASE;
-                debugf("Freeing: %p\n", e);
-                s_free(e);
+        //for(ix = 0, (J1F(r,gc_allocated,ix)); r; (J1N(r,gc_allocated,ix))) {
+        //        entry_t *e = (entry_t *)(ix * GC_ALIGNMENT);
+        //        mem_inuse -= (e->u.v.count + 1)*GC_BASE;
+        //        debugf("Freeing: %p\n", e);
+        //        s_free(e);
hunk ./src/data/rts/jhc_jgc.c 225
-        }
-        J1FA(r,gc_allocated);
-        gc_allocated = gc_grey;
+        //}
+        //J1FA(r,gc_allocated);
+        //gc_allocated = gc_grey;
+        s_cleanup_pages(arena);
hunk ./src/data/rts/jhc_jgc.c 230
+#ifdef JHC_JGC_STACK
+                void * gc_stack_base = &gc_stack_base;
+#endif
+
hunk ./src/data/rts/jhc_jgc.c 238
-#ifdef JHC_JGC_STACK
-                void * gc_stack_base = &gc_stack_base;
-#endif
-                fprintf(stderr,"live: %5lu root: %3lu inuse: %6lu threshold: %6lu %p %p\n",n_allocated,n_roots,(long unsigned)mem_inuse,(long unsigned)heap_threshold, gc_stack_base, gc);
+                fprintf(stderr,"live: %5lu root: %3lu inuse: %6lu threshold: %6lu %p %p\n",arena->num_used,n_roots,(long unsigned)mem_inuse,(long unsigned)heap_threshold, gc_stack_base, gc);
hunk ./src/data/rts/jhc_jgc.c 250
-        if(__predict_false(mem_inuse > heap_threshold)) {
-                gc_perform_gc(gc);
-                if(__predict_false(mem_inuse > ((heap_threshold * 6) / 10))) {
-                        heap_threshold *= 2;
-                        if(JGC_STATUS)
-                                fprintf(stderr, "Increasing heap threshold to %u bytes because mem usage is %u.\n", (unsigned) heap_threshold, (unsigned)mem_inuse);
-                }
-        }
+//        static int c;
+        //if(__predict_false(mem_inuse > heap_threshold)) {
+//        if(c++ % 100000 == 0) {
+ //               gc_perform_gc(gc);
+            //    if(__predict_false(mem_inuse > ((heap_threshold * 6) / 10))) {
+             //           heap_threshold *= 2;
+             //           if(JGC_STATUS)
+             //                   fprintf(stderr, "Increasing heap threshold to %u bytes because mem usage is %u.\n", (unsigned) heap_threshold, (unsigned)mem_inuse);
+             //   }
+ //       }
hunk ./src/data/rts/jhc_jgc.c 261
-        entry_t *e = s_alloc(find_cache(sc, arena, GC_BASE*(count + 1), 0));
+        entry_t *e = s_alloc(gc, find_cache(sc, arena, GC_BASE*(count + 1), 0));
hunk ./src/data/rts/jhc_jgc.c 267
-        int r; J1S(r,gc_allocated,(Word_t)e / GC_ALIGNMENT);
+//        int r; J1S(r,gc_allocated,(Word_t)e / GC_ALIGNMENT);
hunk ./src/data/rts/jhc_jgc.c 281
-#else 
+#else
hunk ./src/data/rts/jhc_jgc.h 10
-#define JGC_STATUS 0
+#define JGC_STATUS 1
hunk ./src/data/rts/slub.c 53
-inline static int
+static int
hunk ./src/data/rts/slub.c 74
-struct s_page *
-get_free_page(struct s_arena *arena) {
+/* page allocator */
+
+static unsigned page_threshold = 4;
+
+static struct s_page *
+get_free_page(gc_t gc, struct s_arena *arena) {
+        if(arena->num_used >= page_threshold) {
+                gc_perform_gc(gc);
+                // if we are stil using 80% of the heap after a gc, raise the threshold.
+                if(arena->num_used * 10 >= page_threshold * 8) {
+                        page_threshold *= 2;
+                }
+        }
hunk ./src/data/rts/slub.c 92
-        return (struct s_page *)(arena->base + PAGESIZE*found);
hunk ./src/data/rts/slub.c 94
-        assert(r);
+        arena->num_used++;
+        return (struct s_page *)(arena->base + PAGESIZE*found);
hunk ./src/data/rts/slub.c 98
-void *
-s_alloc(struct s_cache *sc)
+static void
+s_cleanup_pages(struct s_arena *arena) {
+        struct s_cache *sc = SLIST_FIRST(&arena->caches);
+        for(;sc;sc = SLIST_NEXT(sc,next)) {
+                struct s_page *pg;
+                TAILQ_FOREACH(pg,&sc->pages,tailq) {
+                        if(pg->num_free == sc->num_entries) {
+                                TAILQ_REMOVE(&sc->pages,pg,tailq);
+                                BIT_UNSET(arena->used,((uintptr_t)pg - (uintptr_t)arena->base) / PAGESIZE);
+                                arena->num_used--;
+                        }
+                }
+        }
+}
+
+
+
+static void *
+s_alloc(gc_t gc, struct s_cache *sc)
hunk ./src/data/rts/slub.c 120
-
-        TAILQ_FOREACH(pg,&sc->pages,tailq) {
+        TAILQ_FOREACH(pg,&sc->pages,tailq)
hunk ./src/data/rts/slub.c 123
-        }
-        if(!pg) {
-                pg = get_free_page(sc->arena);
-                assert(pg);
-                pg->num_free = sc->num_entries;
-                pg->color = sc->color;
-                pg->size = sc->size;
-                pg->next_free = 0;
-                memset(pg->used,0,BITARRAY_SIZE_IN_BYTES(sc->num_entries));
-                for(int i = BITARRAY_SIZE(sc->num_entries)*BITS_PER_UNIT - 1; i >= sc->num_entries; i--)
-                        BIT_SET(pg->used,i);
-                TAILQ_INSERT_HEAD(&sc->pages,pg,tailq);
+        if(__predict_false(!pg)) {
+        pg = get_free_page(gc, sc->arena);
+        assert(pg);
+        pg->num_free = sc->num_entries;
+        pg->color = sc->color;
+        pg->size = sc->size;
+        pg->next_free = 0;
+        memset(pg->used,0,BITARRAY_SIZE_IN_BYTES(sc->num_entries));
+        for(int i = BITARRAY_SIZE(sc->num_entries)*BITS_PER_UNIT - 1; i >= sc->num_entries; i--)
+                BIT_SET(pg->used,i);
+        TAILQ_INSERT_HEAD(&sc->pages,pg,tailq);
hunk ./src/data/rts/slub.c 142
-//        printf("s_alloc: val: %p s_page: %p size: %i color: %i found: %i num_free: %i\n", val, pg, pg->size, pg->color, found, pg->num_free);
+        //        printf("s_alloc: val: %p s_page: %p size: %i color: %i found: %i num_free: %i\n", val, pg, pg->size, pg->color, found, pg->num_free);
hunk ./src/data/rts/slub.c 144
-        if(!pg->num_free) {
+        if(__predict_false(0 == pg->num_free)) {
hunk ./src/data/rts/slub.c 153
-void
+static void
hunk ./src/data/rts/slub.c 166
-struct s_cache *
+static struct s_cache *
hunk ./src/data/rts/slub.c 183
+// clear all used bits, must be followed by a marking phase.
hunk ./src/data/rts/slub.c 199
+// set a used bit. returns true if the
+// tagged node should be scanned by the GC.
+// this happens when the used bit was not previously set
+// and the node contains internal pointers.
+
hunk ./src/data/rts/slub.c 208
+        // TODO - check if there are internal pointers
hunk ./src/data/rts/slub.c 219
-struct s_cache *
+static struct s_cache *
hunk ./src/data/rts/slub.c 222
-        if(rsc && *rsc)
+        if(__predict_true(rsc && *rsc)) {
+      //          printf("s_cached: %p\n", rsc);
hunk ./src/data/rts/slub.c 225
+        }
+       // printf("s_new: %p\n", rsc);
hunk ./src/data/rts/slub.c 266
-    