[add per-object caches
John Meacham <john@repetae.net>**20100406031420
 Ignore-this: 45c6b4a60189de924fda323bba3ca461
] hunk ./src/C/FromGrin2.hs 1
-
+{-# LANGUAGE RecordWildCards #-}
hunk ./src/C/FromGrin2.hs 52
---    } 
+--    }
hunk ./src/C/FromGrin2.hs 59
---    wAllocs :: Set.Set AllocInfo,
+    wAllocs :: Set.Set Atom,
hunk ./src/C/FromGrin2.hs 138
-compileGrin grin = (LBS.fromChunks [hsffi_h,jhc_rts_header_h,jhc_jgc_h,jhc_rts_alloc_c,jhc_rts_c,jhc_rts2_c,jhc_jgc_c,BS.fromString generateArchAssertions,BS.fromString $ P.render ans, BS.fromString "\n"], snub (reqLibraries req))  where
-    ans = vcat $ includes ++ [text "", enum_tag_t, header,cafs, buildConstants cpr grin finalHcHash, body]
+compileGrin grin = (LBS.fromChunks code, snub (reqLibraries req))  where
+    code = [
+        hsffi_h,
+        jhc_rts_header_h,
+        jhc_jgc_h,
+        jhc_rts_alloc_c,
+        jhc_rts_c,
+        jhc_rts2_c,
+        jhc_jgc_c,
+        BS.fromString generateArchAssertions,
+        BS.fromString $ P.render ans,
+        BS.fromString "\n"
+        ]
+    ans = vcat $ includes ++ jgcs ++ [text "", enum_tag_t, header,cafs, buildConstants cpr grin finalHcHash, body]
+    jgcs = [ text "struct s_cache *" <> tshow (nodeCacheName m) <> char ';' | m <- Set.toList wAllocs]
hunk ./src/C/FromGrin2.hs 156
-    ((cafs',finalHcHash,Written { wRequires = req, wFunctions = fm, wEnums = wenum, wStructures = sm, wTags = ts }),cpr) = runC grin $ go >> mapM convertCAF (grinCafs grin)
+    ((cafs',finalHcHash,Written { wRequires = req, wFunctions = fm, wEnums = wenum, wStructures = sm, wTags = ts, .. }),cpr) = runC grin $ go >> mapM convertCAF (grinCafs grin)
hunk ./src/C/FromGrin2.hs 792
-        let wmalloc = jhc_malloc (not sf && t `Map.notMember` cpr) nptrs
+        let wmalloc = jhc_malloc (reference (toExpression $ nodeCacheName t)) (not sf && t `Map.notMember` cpr) nptrs
hunk ./src/C/FromGrin2.hs 802
-                return (mempty,v)
-            False -> do ty `newTmpVar` malloc
-        tmp <- if region == region_stack then return (reference tmp) else return tmp
+                return (mempty,reference v)
+            False -> do
+                tell mempty { wAllocs = Set.singleton t }
+                ty `newTmpVar` malloc
hunk ./src/C/FromGrin2.hs 910
-jhc_malloc has_tag nptrs sz | fopts FO.Jgc = functionCall (name "gc_alloc_tag") [v_gc,tbsize sz, toExpression nptrs, toExpression has_tag]
+jhc_malloc ntn has_tag nptrs sz | fopts FO.Jgc = functionCall (name "gc_alloc_tag") [v_gc,ntn, tbsize sz, toExpression nptrs, toExpression has_tag]
hunk ./src/C/FromGrin2.hs 912
-jhc_malloc _ 0 sz = functionCall (name "jhc_malloc_atomic") [sz]
-jhc_malloc _ _ sz = functionCall (name "jhc_malloc") [sz]
+jhc_malloc _ _ 0 sz = functionCall (name "jhc_malloc_atomic") [sz]
+jhc_malloc _ _ _ sz = functionCall (name "jhc_malloc") [sz]
hunk ./src/C/FromGrin2.hs 915
-jhc_malloc_ptrs sz | fopts FO.Jgc =  functionCall (name "gc_alloc_tag") [v_gc,tbsize sz, tbsize sz, toExpression False]
+jhc_malloc_ptrs sz | fopts FO.Jgc =  functionCall (name "gc_alloc_tag") [v_gc,nullPtr,tbsize sz, tbsize sz, toExpression False]
hunk ./src/C/FromGrin2.hs 975
+nodeCacheName a = toName ('c':fromAtom a)
hunk ./src/data/rts/jhc_jgc.c 22
-static void gc_perform_gc(gc_t gc);
-static void *gc_alloc_tag(gc_t gc,unsigned count, unsigned nptrs, int tag);
-
hunk ./src/data/rts/jhc_jgc.c 214
-gc_alloc_tag(gc_t gc,unsigned count, unsigned nptrs, int tag)
+gc_alloc_tag(gc_t gc,struct s_cache **sc, unsigned count, unsigned nptrs, int tag)
hunk ./src/data/rts/jhc_jgc.c 228
-        entry_t *e = s_alloc(find_cache(arena, GC_BASE*(count + 1), 0));
+        entry_t *e = s_alloc(find_cache(sc, arena, GC_BASE*(count + 1), 0));
hunk ./src/data/rts/jhc_jgc.h 57
+struct s_cache;
hunk ./src/data/rts/jhc_jgc.h 60
-static void *gc_alloc_tag(gc_t gc,unsigned count, unsigned nptrs, int tag);
+static void *gc_alloc_tag(gc_t gc,struct s_cache **sc, unsigned count, unsigned nptrs, int tag);
hunk ./src/data/rts/jhc_rts_alloc.c 90
+#define jhc_malloc_fini() do { } while(0)
hunk ./src/data/rts/slub.c 18
+
+static Pvoid_t  gc_inheap; // whether the page is a heap page
+
hunk ./src/data/rts/slub.c 82
+        int r;
+        J1S(r, gc_inheap, (uintptr_t)arena->base/PAGESIZE + found);
+        assert(r);
hunk ./src/data/rts/slub.c 105
-                //int excess = BITARRAY_SIZE(sc->num_entries)*BITS_PER_UNIT - sc->num_entries;
hunk ./src/data/rts/slub.c 107
-
hunk ./src/data/rts/slub.c 108
-                //printf("Creating New Page: %p\n", pg);
hunk ./src/data/rts/slub.c 157
+static void
+clear_used_bits(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) {
+                        pg->num_free = sc->num_entries;
+                        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);
+                }
+        }
+}
+
+static bool
+s_set_used_bit(void *val)
+{
+        assert(val);
+        struct s_page *pg = S_PAGE(val);
+        unsigned int offset = ((uintptr_t *)val - (uintptr_t *)pg) - pg->color;
+        if(BIT_IS_UNSET(pg->used,offset/(pg->size/sizeof(uintptr_t)))) {
+                pg->num_free--;
+                BIT_SET(pg->used,offset/(pg->size/sizeof(uintptr_t)));
+                return true;
+        }
+        return false;
+}
+
hunk ./src/data/rts/slub.c 187
-find_cache(struct s_arena *arena, unsigned short size, unsigned short num_ptrs)
+find_cache(struct s_cache **rsc, struct s_arena *arena, unsigned short size, unsigned short num_ptrs)
hunk ./src/data/rts/slub.c 189
+        if(rsc && *rsc)
+                return *rsc;
hunk ./src/data/rts/slub.c 194
-                        return sc;
+                        goto found;
hunk ./src/data/rts/slub.c 196
-        return new_cache(arena,size,num_ptrs);
+        sc = new_cache(arena,size,num_ptrs);
+found:
+        if(rsc)
+                *rsc = sc;
+        return sc;