[add support for using a supplimental stack for garbage collectable pointers rather than the C stack
John Meacham <john@repetae.net>**20100329205156
 Ignore-this: 6fba6d1e4ac1412da75ad9e161f93652
] hunk ./src/data/rts/jhc_jgc.h 7
-#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
+#if 1
+#  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 44
+#ifdef JHC_JGC_STACK
hunk ./src/data/rts/jhc_jgc.h 47
-
-#define gc_count(ty)  (TO_BLOCKS(sizeof(ty)))
-#define gc_mk_alloc_tag(ty, np, tag) static inline ty *gc_alloc_ ## ty(gc_t gc) { ty *x = gc_alloc(gc,gc_count(ty),np); gc_tag(x) = tag; return x; }
-#define gc_mk_alloc(ty, np) gc_mk_alloc_tag(ty,np,0)
-#define gc_mk_alloc_tag_s(ty, np, tag) static inline ty *gc_alloc_ ## ty ## _s(gc_t gc, ty v) { ty *x = gc_alloc(gc,gc_count(ty),np); gc_tag(x) = tag; *x = v; return x; }
-#define gc_tag(p) (((entry_header_t *)((void *)p - sizeof(void *)))->tag)
+#else
+#define gc_frame0(gc,n,...) void *ptrs[n] = { __VA_ARGS__ }; for(int i = 0; i < n; i++) gc[i] = (sptr_t)ptrs[i]; gc_t sgc = gc;  gc_t gc = sgc + n;
+#endif
hunk ./src/data/rts/jhc_jgc.h 79
-static Pvoid_t  gc_roots = NULL;        // extra roots in addition to the stack
-static Pvoid_t  gc_allocated = NULL;    // black set of currently allocated memory
+static Pvoid_t  gc_roots       = NULL;  // extra roots in addition to the stack
+static Pvoid_t  gc_allocated   = NULL;  // black set of currently allocated memory
hunk ./src/data/rts/jhc_jgc.h 131
+static void
+gc_add_grey(Pvoid_t gc_grey[1], struct stack *stack, uintptr_t ix)
+{
+        int r;
+        J1U(r, gc_allocated, ix);
+        if(r) {
+                J1S(r, *gc_grey, ix);
+                if(r)
+                        stack->stack[stack->ptr++] = (uintptr_t)ix * GC_ALIGNMENT;
+        }
+}
+
hunk ./src/data/rts/jhc_jgc.h 162
-                J1U(r, gc_allocated, ix);
-                if(r) {
-                        J1S(r, gc_grey, ix);
-                        if(r)
-                                stack.stack[stack.ptr++] = (uintptr_t)ix * GC_ALIGNMENT;
-                }
+                gc_add_grey(&gc_grey, &stack, ix);
hunk ./src/data/rts/jhc_jgc.h 166
+#ifdef JHC_JGC_STACK
hunk ./src/data/rts/jhc_jgc.h 191
-                        ix = (Word_t)e / GC_ALIGNMENT;
-                        J1U(r,gc_allocated,ix);
-                        if(r) {
-                                J1S(r,gc_grey,ix);
+                        gc_add_grey(&gc_grey, &stack, (uintptr_t)e / GC_ALIGNMENT);
+                }
+        }
+#else
+        stack_check(&stack, gc - gc_stack_base);
+        number_stack = gc - gc_stack_base;
+        for(int i = 0; i < number_stack; i++) {
+                debugf(" |");
+                // TODO - short circuit redirects on stack
+                sptr_t ptr = gc_stack_base[i];
+                if(P_LAZY == GET_PTYPE(ptr)) {
+                        if(!IS_LAZY(GETHEAD(FROM_SPTR(ptr)))) {
+                                J1U(r,gc_allocated,((uintptr_t)FROM_SPTR(ptr) - sizeof(entry_t))/GC_ALIGNMENT);
hunk ./src/data/rts/jhc_jgc.h 205
-                                        stack.stack[stack.ptr++] = (uintptr_t)ix * GC_ALIGNMENT;
+                                        J1S(r,gc_grey,((uintptr_t)FROM_SPTR(ptr) - sizeof(entry_t))/GC_ALIGNMENT);
+                                number_redirects++;
+                                debugf(" *");
+                                ptr = (sptr_t)GETHEAD(FROM_SPTR(ptr));
hunk ./src/data/rts/jhc_jgc.h 211
+                if(__predict_false(!SHOULD_FOLLOW(ptr))) {
+                        debugf(" -");
+                        continue;
+                }
+                number_ptr++;
+                entry_t *e = (entry_t *)FROM_SPTR(ptr) - 1;
+                debugf(" %p",(void *)e);
+                ix = (Word_t)e / GC_ALIGNMENT;
+                gc_add_grey(&gc_grey, &stack, ix);
hunk ./src/data/rts/jhc_jgc.h 221
+#endif
hunk ./src/data/rts/jhc_jgc.h 226
-                //J1T(r,gc_grey,ix);
-                //assert(r);
hunk ./src/data/rts/jhc_jgc.h 239
-                        if(SHOULD_FOLLOW(e->ptrs[i])) {
+                        if(__predict_true(SHOULD_FOLLOW(e->ptrs[i]))) {
hunk ./src/data/rts/jhc_jgc.h 242
-                                Word_t ix = (Word_t)ptr / GC_ALIGNMENT;
-                                J1U(r,gc_allocated,ix);
-                                if(r) {
-                                        J1S(r,gc_grey,ix);
-                                        if(r)
-                                                stack.stack[stack.ptr++] = (uintptr_t)ix * GC_ALIGNMENT;
-                                }
+                                gc_add_grey(&gc_grey, &stack, (uintptr_t)ptr / GC_ALIGNMENT);
hunk ./src/data/rts/jhc_jgc.h 259
-                fprintf(stderr,"live: %5lu root: %3lu inuse: %6lu threshold: %6lu\n",n_allocated,n_roots,(long unsigned)mem_inuse,(long unsigned)heap_threshold);
+#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);
hunk ./src/data/rts/jhc_rts_alloc.c 82
-static inline void
-jhc_malloc_init(void) { return; }
+#define jhc_malloc_init() do { } while(0)
hunk ./src/data/rts/jhc_rts_alloc.c 147
+#ifdef JHC_JGC_STACK
hunk ./src/data/rts/jhc_rts_alloc.c 149
+#else
+typedef void* *gc_t;
+#endif
hunk ./src/data/rts/jhc_rts_alloc.c 154
+#ifndef JHC_JGC_STACK
+static gc_t gc_stack_base;
+#undef jhc_malloc_init
+static void
+jhc_malloc_init(void) {
+        saved_gc = gc_stack_base = malloc(8*8192*sizeof(gc_stack_base[0]));
+}
+
+#endif
+