Merge branch 'master' of http://darcs.haskell.org/ghc
[ghc-hetmet.git] / includes / rts / storage / Block.h
index 849f99f..c73c9af 100644 (file)
  * on a 32-bit machine.
  */
 
+// Note: fields marked with [READ ONLY] must not be modified by the
+// client of the block allocator API.  All other fields can be
+// freely modified.
+
 #ifndef CMINUSMINUS
 typedef struct bdescr_ {
-  StgPtr start;                        /* start addr of memory */
-  StgPtr free;                 /* first free byte of memory */
-  struct bdescr_ *link;                /* used for chaining blocks together */
-  union { 
-      struct bdescr_ *back;    /* used (occasionally) for doubly-linked lists*/
-      StgWord *bitmap;
-      StgPtr  scan;             /* scan pointer for copying GC */
-  } u;
-  unsigned int gen_no;         /* generation */
-  struct step_ *step;          /* step */
-  StgWord32 blocks;            /* no. of blocks (if grp head, 0 otherwise) */
-  StgWord32 flags;              /* block is in to-space */
+
+    StgPtr start;              // [READ ONLY] start addr of memory
+
+    StgPtr free;               // first free byte of memory.
+                               // NB. during use this value should lie
+                               // between start and start + blocks *
+                               // BLOCK_SIZE.  Values outside this
+                               // range are reserved for use by the
+                               // block allocator.  In particular, the
+                               // value (StgPtr)(-1) is used to
+                               // indicate that a block is unallocated.
+
+    struct bdescr_ *link;      // used for chaining blocks together
+
+    union {
+        struct bdescr_ *back;  // used (occasionally) for doubly-linked lists
+        StgWord *bitmap;       // bitmap for marking GC
+        StgPtr  scan;          // scan pointer for copying GC
+    } u;
+
+    struct generation_ *gen;   // generation
+
+    StgWord16 gen_no;          // gen->no, cached
+    StgWord16 dest_no;         // number of destination generation
+    StgWord16 _pad1;
+
+    StgWord16 flags;           // block flags, see below
+
+    StgWord32 blocks;          // [READ ONLY] no. of blocks in a group
+                               // (if group head, 0 otherwise)
+
 #if SIZEOF_VOID_P == 8
-  StgWord32 _padding[2];
+    StgWord32 _padding[3];
 #else
-  StgWord32 _padding[0];
+    StgWord32 _padding[0];
 #endif
 } bdescr;
 #endif
@@ -94,6 +117,8 @@ typedef struct bdescr_ {
 #define BF_FRAGMENTED 64
 /* we know about this block (for finding leaks) */
 #define BF_KNOWN     128
+/* Block was swept in the last generation */
+#define BF_SWEPT     256
 
 /* Finding the block descriptor for a given block -------------------------- */
 
@@ -105,7 +130,8 @@ typedef struct bdescr_ {
 
 #else
 
-INLINE_HEADER bdescr *Bdescr(StgPtr p)
+EXTERN_INLINE bdescr *Bdescr(StgPtr p);
+EXTERN_INLINE bdescr *Bdescr(StgPtr p)
 {
   return (bdescr *)
     ((((W_)p &  MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) 
@@ -142,7 +168,9 @@ INLINE_HEADER bdescr *Bdescr(StgPtr p)
 
 /* Number of usable blocks in a megablock */
 
+#ifndef CMINUSMINUS // already defined in DerivedConstants.h
 #define BLOCKS_PER_MBLOCK ((MBLOCK_SIZE - FIRST_BLOCK_OFF) / BLOCK_SIZE)
+#endif
 
 /* How many blocks in this megablock group */