[greatly simplify garbage collection algorithm, trust underlying malloc implementation more.
John Meacham <john@repetae.net>**20100327185011
 Ignore-this: 6fcbd7449f187ab148d9c3c08232b2cd
] hunk ./src/data/rts/jhc_jgc.h 6
+// #if __GNUC_PREREQ__(2, 96)
+#define __predict_true(exp)     __builtin_expect(!!(exp), 1)
+#define __predict_false(exp)    __builtin_expect(!!(exp), 0)
+// #else
+// #define __predict_true(exp)     (exp)
+// #define __predict_false(exp)    (exp)
+// #endif
+
hunk ./src/data/rts/jhc_jgc.h 95
-static Pvoid_t gc_free = NULL;
+//static Pvoid_t gc_free = NULL;
hunk ./src/data/rts/jhc_jgc.h 98
-static size_t heap_threshold = 256;
+static size_t heap_threshold = 2048;
hunk ./src/data/rts/jhc_jgc.h 104
+unsigned number_allocs;
hunk ./src/data/rts/jhc_jgc.h 147
-        Word_t n_allocated,n_roots,n_free;
+        Word_t n_allocated,n_roots;
hunk ./src/data/rts/jhc_jgc.h 150
-        J1C(n_free,gc_free,0,-1);
-        fprintf(stderr,"allocated: %lu roots: %lu free: %lu mem_inuse: %lu heap_threshold: %lu gcs: %u\n",n_allocated,n_roots,n_free,(long unsigned)mem_inuse,(long unsigned)heap_threshold,number_gcs);
+//        J1C(n_free,gc_free,0,-1);
+        fprintf(stderr,"allocated: %5lu roots: %3lu mem_inuse: %5lu heap_threshold: %5lu gcs: %3u\n",n_allocated,n_roots,(long unsigned)mem_inuse,(long unsigned)heap_threshold,number_gcs);
hunk ./src/data/rts/jhc_jgc.h 179
-                        if(IS_LAZY(gc->ptrs[i])) {
-                                if(!IS_LAZY(GETHEAD(FROM_SPTR(gc->ptrs[i])))) {
-                                        number_redirects++;
-                                        debugf(" *");
-                                        gc->ptrs[i] = GETHEAD(FROM_SPTR(gc->ptrs[i]));
-                                        number_whnf++;
-                                }
-                        } else {
-                                number_whnf++;
-                        }
-                        if(!SHOULD_FOLLOW(gc->ptrs[i])) {
+                        //if(IS_LAZY(gc->ptrs[i])) {
+                        //        if(!IS_LAZY(GETHEAD(FROM_SPTR(gc->ptrs[i])))) {
+                        //                number_redirects++;
+                        //                debugf(" *");
+                        //                gc->ptrs[i] = GETHEAD(FROM_SPTR(gc->ptrs[i]));
+                        //                number_whnf++;
+                        //        }
+                        //} else {
+                        //        number_whnf++;
+                        //}
+                        if(__predict_false(!SHOULD_FOLLOW(gc->ptrs[i]))) {
hunk ./src/data/rts/jhc_jgc.h 205
-                if(r == 0) {
+                if(__predict_false(r == 0)) {
hunk ./src/data/rts/jhc_jgc.h 229
-                                if(!r)
+                                if(__predict_true(!r))
hunk ./src/data/rts/jhc_jgc.h 236
-        ix = 0;
-        Word_t w;
+//        Word_t w;
hunk ./src/data/rts/jhc_jgc.h 238
-        for((J1F(r,gc_free,ix)); r; (J1N(r,gc_free,ix))) {
-                int d; J1S(d,gc_allocated,ix);
-        }
-        J1FA(w,gc_free);
-        gc_free = gc_allocated;
+//        for((J1F(r,gc_free,ix)); r; (J1N(r,gc_free,ix))) {
+ //               int d; J1S(d,gc_allocated,ix);
+ //       }
+//        J1FA(w,gc_free);
+//        gc_free = gc_allocated;
hunk ./src/data/rts/jhc_jgc.h 244
-        gc_allocated = gc_black;
-#if JGC_STATUS
-        fprintf(stderr, "Ss: %3u Ws: %3u Ps: %4u Rs: %3u\n", number_stack, number_whnf, number_ptr, number_redirects);
-        gc_print_stats(gc);
-#endif
-#if 0
-        for((J1F(r,gc_free,ix)); r; (J1N(r,gc_free,ix))) {
+
+        for(ix = 0, (J1F(r,gc_allocated,ix)); r; (J1N(r,gc_allocated,ix))) {
hunk ./src/data/rts/jhc_jgc.h 248
-                J1U(r,gc_free,ix);
hunk ./src/data/rts/jhc_jgc.h 250
+        J1FA(r,gc_allocated);
+        gc_allocated = gc_black;
+#if JGC_STATUS
+        fprintf(stderr, "Ss: %5u Ws: %5u Ps: %5u Rs: %5u As: %5u ", number_stack, number_whnf, number_ptr, number_redirects, number_allocs);
+        number_allocs = 0;
+        gc_print_stats(gc);
hunk ./src/data/rts/jhc_jgc.h 260
+void *
+gc_alloc_tag(gc_t gc,unsigned count, unsigned nptrs, int tag)
+{
+        profile_push(&gc_alloc_time);
+        number_allocs++;
+        assert(nptrs <= count);
+        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);
+#endif
+                }
+        }
+        entry_t *e = malloc((count + 1)*GC_BASE);
+        mem_inuse += (count + 1)*GC_BASE;
+        e->u.v.count = count;
+        e->u.v.nptrs = nptrs;
+        e->u.v.tag = tag;
+        debugf("allocated: %p %i %i %i\n",(void *)e, count, nptrs, tag);
+        int r; J1S(r,gc_allocated,(Word_t)e / GC_BASE);
+        profile_pop(&gc_alloc_time);
+        return (void *)(e + 1);
+}
+
+
+/*
hunk ./src/data/rts/jhc_jgc.h 345
-
+*/