summaryrefslogtreecommitdiff
path: root/compiler/codeGen
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-12-17 22:42:28 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-12-17 22:42:28 +0000
commit0417404f5d1230c9d291ea9f73e2831121c8ec99 (patch)
tree609f1be77f63606772e71ad84c7a92b205baaa9e /compiler/codeGen
parentfb783aeaa5bc1cc60e6bb551c1cd01a097b84fad (diff)
downloadhaskell-0417404f5d1230c9d291ea9f73e2831121c8ec99.tar.gz
Fix #650: use a card table to mark dirty sections of mutable arrays
The card table is an array of bytes, placed directly following the actual array data. This means that array reading is unaffected, but array writing needs to read the array size from the header in order to find the card table. We use a bytemap rather than a bitmap, because updating the card table must be multi-thread safe. Each byte refers to 128 entries of the array, but this is tunable by changing the constant MUT_ARR_PTRS_CARD_BITS in includes/Constants.h.
Diffstat (limited to 'compiler/codeGen')
-rw-r--r--compiler/codeGen/CgPrimOp.hs18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/codeGen/CgPrimOp.hs b/compiler/codeGen/CgPrimOp.hs
index 7f100e283b..c99bdb4a74 100644
--- a/compiler/codeGen/CgPrimOp.hs
+++ b/compiler/codeGen/CgPrimOp.hs
@@ -571,9 +571,21 @@ doWriteByteArrayOp _ _ _ _
doWritePtrArrayOp :: CmmExpr -> CmmExpr -> CmmExpr -> Code
doWritePtrArrayOp addr idx val
- = do stmtC (setInfo addr (CmmLit (CmmLabel mkMAP_DIRTY_infoLabel)))
- mkBasicIndexedWrite arrPtrsHdrSize Nothing bWord addr idx val
-
+ = do mkBasicIndexedWrite arrPtrsHdrSize Nothing bWord addr idx val
+ stmtC (setInfo addr (CmmLit (CmmLabel mkMAP_DIRTY_infoLabel)))
+ -- the write barrier. We must write a byte into the mark table:
+ -- bits8[a + header_size + StgMutArrPtrs_size(a) + x >> N]
+ stmtC $ CmmStore (
+ cmmOffsetExpr
+ (cmmOffsetExprW (cmmOffsetB addr arrPtrsHdrSize)
+ (loadArrPtrsSize addr))
+ (CmmMachOp mo_wordUShr [idx,
+ CmmLit (mkIntCLit mUT_ARR_PTRS_CARD_BITS)])
+ ) (CmmLit (CmmInt 1 W8))
+
+loadArrPtrsSize :: CmmExpr -> CmmExpr
+loadArrPtrsSize addr = CmmLoad (cmmOffsetB addr off) bWord
+ where off = fixedHdrSize*wORD_SIZE + oFFSET_StgMutArrPtrs_ptrs
mkBasicIndexedRead :: ByteOff -> Maybe MachOp -> CmmType
-> LocalReg -> CmmExpr -> CmmExpr -> Code