[project @ 2005-04-12 09:17:47 by simonmar]
[ghc-hetmet.git] / ghc / includes / Storage.h
index 5c76094..aebc02b 100644 (file)
  *
  * ------------------------------------------------------------------------- */
 
-typedef struct _step {
+typedef struct step_ {
   unsigned int         no;             /* step number */
   bdescr *             blocks;         /* blocks in this step */
   unsigned int         n_blocks;       /* number of blocks */
-  struct _step *       to;             /* destination step for live objects */
-  struct _generation * gen;            /* generation this step belongs to */
+  struct step_ *       to;             /* destination step for live objects */
+  struct generation_ * gen;            /* generation this step belongs to */
   unsigned int         gen_no;          /* generation number (cached) */
   bdescr *             large_objects;  /* large objects (doubly linked) */
   unsigned int         n_large_blocks;  /* no. of blocks used by large objs */
@@ -75,16 +75,15 @@ typedef struct _step {
   bdescr *     bitmap;                 /* bitmap for compacting collection */
 } step;
 
-typedef struct _generation {
+typedef struct generation_ {
   unsigned int   no;                   /* generation number */
   step *         steps;                        /* steps */
   unsigned int   n_steps;              /* number of steps */
   unsigned int   max_blocks;           /* max blocks in step 0 */
-  StgMutClosure *mut_list;             /* mut objects in this gen (not G0)*/
-  StgMutClosure *mut_once_list;        /* objects that point to younger gens */
+  bdescr        *mut_list;             /* mut objects in this gen (not G0)*/
 
   /* temporary use during GC: */
-  StgMutClosure * saved_mut_list;
+  bdescr        *saved_mut_list;
 
   /* stats information */
   unsigned int collections;
@@ -188,56 +187,42 @@ extern void GarbageCollect(void (*get_roots)(evac_fn),rtsBool force_major_gc);
 
    -------------------------------------------------------------------------- */
 
-/*
- * Storage manager mutex
- */
-#if defined(SMP)
-extern Mutex sm_mutex;
-#define ACQUIRE_SM_LOCK   ACQUIRE_LOCK(&sm_mutex)
-#define RELEASE_SM_LOCK   RELEASE_LOCK(&sm_mutex)
-#else
-#define ACQUIRE_SM_LOCK
-#define RELEASE_SM_LOCK
-#endif
-
-/* ToDo: shouldn't recordMutable and recordOldToNewPtrs acquire some
- * kind of lock in the SMP case?
+/* ToDo: shouldn't recordMutable acquire some
+ * kind of lock in the SMP case?  Or do we need per-processor
+ * mutable lists?
  */
 INLINE_HEADER void
-recordMutable(StgMutClosure *p)
+recordMutableGen(StgClosure *p, generation *gen)
 {
-  bdescr *bd;
-
-#ifdef SMP
-  ASSERT(p->header.info == &stg_WHITEHOLE_info || closure_MUTABLE(p));
-#else
-  ASSERT(closure_MUTABLE(p));
-#endif
-
-  bd = Bdescr((P_)p);
-  if (bd->gen_no > 0) {
-    p->mut_link = RTS_DEREF(generations)[bd->gen_no].mut_list;
-    RTS_DEREF(generations)[bd->gen_no].mut_list = p;
-  }
+    bdescr *bd;
+
+    bd = gen->mut_list;
+    if (bd->free >= bd->start + BLOCK_SIZE_W) {
+       bdescr *new_bd;
+       new_bd = allocBlock();
+       new_bd->link = bd;
+       bd = new_bd;
+       gen->mut_list = bd;
+    }
+    *bd->free++ = (StgWord)p;
 }
 
 INLINE_HEADER void
-recordOldToNewPtrs(StgMutClosure *p)
+recordMutable(StgClosure *p)
 {
-  bdescr *bd;
-  
-  bd = Bdescr((P_)p);
-  if (bd->gen_no > 0) {
-    p->mut_link = RTS_DEREF(generations)[bd->gen_no].mut_once_list;
-    RTS_DEREF(generations)[bd->gen_no].mut_once_list = p;
-  }
+    bdescr *bd;
+    ASSERT(closure_MUTABLE(p));
+    bd = Bdescr((P_)p);
+    if (bd->gen_no > 0) recordMutableGen(p, &RTS_DEREF(generations)[bd->gen_no]);
 }
 
 /* -----------------------------------------------------------------------------
    The CAF table - used to let us revert CAFs in GHCi
    -------------------------------------------------------------------------- */
 
-void revertCAFs( void );
+/* set to disable CAF garbage collection in GHCi. */
+/* (needed when dynamic libraries are used). */
+extern rtsBool keepCAFs;
 
 /* -----------------------------------------------------------------------------
    DEBUGGING predicates for pointers
@@ -277,10 +262,10 @@ INLINE_HEADER StgOffset CONSTR_sizeW( nat p, nat np )
 { return sizeofW(StgHeader) + p + np; }
 
 INLINE_HEADER StgOffset THUNK_SELECTOR_sizeW ( void )
-{ return sizeofW(StgHeader) + MIN_UPD_SIZE; }
+{ return stg_max(sizeofW(StgHeader)+MIN_UPD_SIZE, sizeofW(StgSelector)); }
 
 INLINE_HEADER StgOffset BLACKHOLE_sizeW ( void )
-{ return sizeofW(StgHeader) + MIN_UPD_SIZE; }
+{ return sizeofW(StgHeader)+MIN_UPD_SIZE; }
 
 /* --------------------------------------------------------------------------
    Sizes of closures
@@ -347,19 +332,11 @@ INLINE_HEADER StgWord stack_frame_sizeW( StgClosure *frame )
    Nursery manipulation
    -------------------------------------------------------------------------- */
 
-extern void     allocNurseries ( void );
-extern void     resetNurseries ( void );
-extern bdescr * allocNursery   ( bdescr *last_bd, nat blocks );
-extern void     resizeNursery  ( nat blocks );
-extern void     tidyAllocateLists ( void );
-
-/* -----------------------------------------------------------------------------
-   MUTABLE LISTS
-   A mutable list is ended with END_MUT_LIST, so that we can use NULL
-   as an indication that an object is not on a mutable list.
-   ------------------------------------------------------------------------- */
-
-#define END_MUT_LIST ((StgMutClosure *)(void *)&stg_END_MUT_LIST_closure)
+extern void     allocNurseries     ( void );
+extern void     resetNurseries     ( void );
+extern void     resizeNurseries    ( nat blocks );
+extern void     tidyAllocateLists  ( void );
+extern lnat     countNurseryBlocks ( void );
 
 /* -----------------------------------------------------------------------------
    Functions from GC.c 
@@ -406,6 +383,7 @@ extern StgClosure * RTS_VAR(scavenged_static_objects);
 extern StgWeak    * RTS_VAR(old_weak_ptr_list);
 extern StgWeak    * RTS_VAR(weak_ptr_list);
 extern StgClosure * RTS_VAR(caf_list);
+extern StgClosure * RTS_VAR(revertible_caf_list);
 extern StgTSO     * RTS_VAR(resurrected_threads);
 
-#endif // STORAGE_H
+#endif /* STORAGE_H */