From: Antoine Latter Date: Fri, 1 Jan 2010 18:33:46 +0000 (+0000) Subject: FIX #38000 Store StgArrWords payload size in bytes X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=17c8229adf9f268097e4c87053d940a918c3a26f FIX #38000 Store StgArrWords payload size in bytes --- diff --git a/compiler/codeGen/CgPrimOp.hs b/compiler/codeGen/CgPrimOp.hs index c99bdb4..d0da575 100644 --- a/compiler/codeGen/CgPrimOp.hs +++ b/compiler/codeGen/CgPrimOp.hs @@ -143,16 +143,13 @@ emitPrimOp [] WriteMutVarOp [mutv,var] live CmmMayReturn -- #define sizzeofByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofByteArrayOp [arg] _ = stmtC $ - CmmAssign (CmmLocal res) (CmmMachOp mo_wordMul [ - cmmLoadIndexW arg fixedHdrSize bWord, - CmmLit (mkIntCLit wORD_SIZE) - ]) + CmmAssign (CmmLocal res) (cmmLoadIndexW arg fixedHdrSize bWord) -- #define sizzeofMutableByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofMutableByteArrayOp [arg] live = emitPrimOp [res] SizeofByteArrayOp [arg] live diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs index 9cabcb1..1c1fab1 100644 --- a/compiler/codeGen/StgCmmPrim.hs +++ b/compiler/codeGen/StgCmmPrim.hs @@ -217,16 +217,13 @@ emitPrimOp [] WriteMutVarOp [mutv,var] [(CmmReg (CmmGlobal BaseReg), AddrHint), (mutv,AddrHint)] -- #define sizzeofByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofByteArrayOp [arg] = emit $ - mkAssign (CmmLocal res) (CmmMachOp mo_wordMul [ - cmmLoadIndexW arg fixedHdrSize bWord, - CmmLit (mkIntCLit wORD_SIZE) - ]) + mkAssign (CmmLocal res) (cmmLoadIndexW arg fixedHdrSize bWord) -- #define sizzeofMutableByteArrayzh(r,a) \ --- r = (((StgArrWords *)(a))->words * sizeof(W_)) +-- r = ((StgArrWords *)(a))->bytes emitPrimOp [res] SizeofMutableByteArrayOp [arg] = emitPrimOp [res] SizeofByteArrayOp [arg] diff --git a/includes/Cmm.h b/includes/Cmm.h index 52b5bec..0088c1a 100644 --- a/includes/Cmm.h +++ b/includes/Cmm.h @@ -413,6 +413,9 @@ /* The offset of the payload of an array */ #define BYTE_ARR_CTS(arr) ((arr) + SIZEOF_StgArrWords) +/* The number of words allocated in an array payload */ +#define BYTE_ARR_WDS(arr) ROUNDUP_BYTES_TO_WDS(StgArrWords_bytes(arr)) + /* Getting/setting the info pointer of a closure */ #define SET_INFO(p,info) StgHeader_info(p) = info #define GET_INFO(p) StgHeader_info(p) diff --git a/includes/mkDerivedConstants.c b/includes/mkDerivedConstants.c index 7efcf47..c003a94 100644 --- a/includes/mkDerivedConstants.c +++ b/includes/mkDerivedConstants.c @@ -276,7 +276,7 @@ main(int argc, char *argv[]) closure_field(StgMutArrPtrs, size); closure_size(StgArrWords); - closure_field(StgArrWords, words); + closure_field(StgArrWords, bytes); closure_payload(StgArrWords, payload); closure_field(StgTSO, _link); diff --git a/includes/rts/storage/ClosureMacros.h b/includes/rts/storage/ClosureMacros.h index 56e7dca..fa6a2a5 100644 --- a/includes/rts/storage/ClosureMacros.h +++ b/includes/rts/storage/ClosureMacros.h @@ -127,7 +127,7 @@ #define SET_ARR_HDR(c,info,costCentreStack,n_words) \ SET_HDR(c,info,costCentreStack); \ - (c)->words = n_words; + (c)->bytes = n_words*sizeof(W_); // Use when changing a closure from one kind to another #define OVERWRITE_INFO(c, new_info) \ @@ -280,8 +280,11 @@ INLINE_HEADER StgOffset ap_sizeW( StgAP* x ) INLINE_HEADER StgOffset pap_sizeW( StgPAP* x ) { return PAP_sizeW(x->n_args); } +INLINE_HEADER StgWord arr_words_words( StgArrWords* x) +{ return ROUNDUP_BYTES_TO_WDS(x->bytes); } + INLINE_HEADER StgOffset arr_words_sizeW( StgArrWords* x ) -{ return sizeofW(StgArrWords) + x->words; } +{ return sizeofW(StgArrWords) + arr_words_words(x); } INLINE_HEADER StgOffset mut_arr_ptrs_sizeW( StgMutArrPtrs* x ) { return sizeofW(StgMutArrPtrs) + x->size; } diff --git a/includes/rts/storage/Closures.h b/includes/rts/storage/Closures.h index a0ff738..7671c7b 100644 --- a/includes/rts/storage/Closures.h +++ b/includes/rts/storage/Closures.h @@ -137,7 +137,7 @@ typedef struct StgBlockingQueue_ { typedef struct { StgHeader header; - StgWord words; + StgWord bytes; StgWord payload[FLEXIBLE_ARRAY]; } StgArrWords; diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm index e5427c7..029b2b7 100644 --- a/rts/PrimOps.cmm +++ b/rts/PrimOps.cmm @@ -64,7 +64,7 @@ stg_newByteArrayzh ("ptr" p) = foreign "C" allocate(MyCapability() "ptr",words) []; TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0); SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]); - StgArrWords_words(p) = payload_words; + StgArrWords_bytes(p) = n; RET_P(p); } @@ -73,10 +73,11 @@ stg_newByteArrayzh stg_newPinnedByteArrayzh { - W_ words, bytes, payload_words, p; + W_ words, n, bytes, payload_words, p; MAYBE_GC(NO_PTRS,stg_newPinnedByteArrayzh); - bytes = R1; + n = R1; + bytes = n; /* payload_words is what we will tell the profiler we had to allocate */ payload_words = ROUNDUP_BYTES_TO_WDS(bytes); /* When we actually allocate memory, we need to allow space for the @@ -96,18 +97,20 @@ stg_newPinnedByteArrayzh p = p + ((-p - SIZEOF_StgArrWords) & BA_MASK); SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]); - StgArrWords_words(p) = payload_words; + StgArrWords_bytes(p) = n; RET_P(p); } stg_newAlignedPinnedByteArrayzh { - W_ words, bytes, payload_words, p, alignment; + W_ words, n, bytes, payload_words, p, alignment; MAYBE_GC(NO_PTRS,stg_newAlignedPinnedByteArrayzh); - bytes = R1; + n = R1; alignment = R2; + bytes = n; + /* payload_words is what we will tell the profiler we had to allocate */ payload_words = ROUNDUP_BYTES_TO_WDS(bytes); @@ -129,7 +132,7 @@ stg_newAlignedPinnedByteArrayzh p = p + ((-p - SIZEOF_StgArrWords) & (alignment - 1)); SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]); - StgArrWords_words(p) = payload_words; + StgArrWords_bytes(p) = n; RET_P(p); } @@ -378,7 +381,7 @@ stg_mkWeakForeignEnvzh TICK_ALLOC_PRIM(SIZEOF_StgArrWords,WDS(payload_words),0); SET_HDR(p, stg_ARR_WORDS_info, W_[CCCS]); - StgArrWords_words(p) = payload_words; + StgArrWords_bytes(p) = WDS(payload_words); StgArrWords_payload(p,0) = fptr; StgArrWords_payload(p,1) = ptr; StgArrWords_payload(p,2) = eptr; @@ -1548,7 +1551,7 @@ stg_newBCOzh bitmap_arr = R5; - words = BYTES_TO_WDS(SIZEOF_StgBCO) + StgArrWords_words(bitmap_arr); + words = BYTES_TO_WDS(SIZEOF_StgBCO) + BYTE_ARR_WDS(bitmap_arr); bytes = WDS(words); ALLOC_PRIM( bytes, R1_PTR&R2_PTR&R3_PTR&R5_PTR, stg_newBCOzh ); @@ -1566,7 +1569,7 @@ stg_newBCOzh W_ i; i = 0; for: - if (i < StgArrWords_words(bitmap_arr)) { + if (i < BYTE_ARR_WDS(bitmap_arr)) { StgBCO_bitmap(bco,i) = StgArrWords_payload(bitmap_arr,i); i = i + 1; goto for; @@ -1660,7 +1663,7 @@ for: is promoted. */ SET_HDR(nptrs_arr, stg_ARR_WORDS_info, W_[CCCS]); - StgArrWords_words(nptrs_arr) = nptrs; + StgArrWords_bytes(nptrs_arr) = WDS(nptrs); p = 0; for2: if(p < nptrs) { diff --git a/rts/Printer.c b/rts/Printer.c index 9e772c4..b55f105 100644 --- a/rts/Printer.c +++ b/rts/Printer.c @@ -293,7 +293,7 @@ printClosure( StgClosure *obj ) for (i = 0; arrWordsGetChar(obj,i); ++i) { putchar(arrWordsGetChar(obj,i)); } */ - for (i=0; i<((StgArrWords *)obj)->words; i++) + for (i=0; ipayload[i]); debugBelch("\")\n"); break; diff --git a/rts/parallel/Pack.c b/rts/parallel/Pack.c index 43d309e..fe64a75 100644 --- a/rts/parallel/Pack.c +++ b/rts/parallel/Pack.c @@ -1278,7 +1278,7 @@ PackArray(StgClosure *closure) ASSERT(info->type == ARR_WORDS || info->type == MUT_ARR_PTRS || info->type == MUT_ARR_PTRS_FROZEN || info->type == MUT_VAR); - n = ((StgArrWords *)closure)->words; + n = arr_words_words(((StgArrWords *)closure)); // this includes the header!: arr_words_sizeW(stgCast(StgArrWords*,q)); IF_PAR_DEBUG(pack, @@ -1299,7 +1299,7 @@ PackArray(StgClosure *closure) if (RtsFlags.ParFlags.ParStats.Global && RtsFlags.GcFlags.giveStats > NO_GC_STATS) { globalParStats.tot_arrs++; - globalParStats.tot_arr_size += ((StgArrWords *)closure)->words; + globalParStats.tot_arr_size += arr_words_words(((StgArrWords *)closure)); } /* record offset of the closure and allocate a GA */ @@ -1313,7 +1313,7 @@ PackArray(StgClosure *closure) /* Pack the header (2 words: info ptr and the number of words to follow) */ Pack((StgWord)*(StgPtr)closure); - Pack(((StgArrWords *)closure)->words); + Pack(arr_words_words(((StgArrWords *)closure))); /* pack the payload of the closure (all non-ptrs) */ for (i=0; itype == ARR_WORDS || info->type == MUT_ARR_PTRS || info->type == MUT_ARR_PTRS_FROZEN || info->type == MUT_VAR)); - n = ((StgArrWords *)bufptr)->words; + n = arr_words_words(((StgArrWords *)bufptr)); // this includes the header!: arr_words_sizeW(stgCast(StgArrWords*,q)); IF_PAR_DEBUG(pack, @@ -2834,7 +2834,7 @@ UnpackArray(StgWord ***bufptrP, StgClosure *graph) /* Unpack the header (2 words: info ptr and the number of words to follow) */ ((StgArrWords *)graph)->header.info = (StgInfoTable*)*bufptr++; // assumes _HS==1; yuck! - ((StgArrWords *)graph)->words = (StgWord)*bufptr++; + ((StgArrWords *)graph)->bytes = ((StgWord)*bufptr++) * sizeof(StgWord); /* unpack the payload of the closure (all non-ptrs) */ for (i=0; itype == ARR_WORDS) { ptrs = vhs = 0; - nonptrs = ((StgArrWords *)bufptr)->words; + nonptrs = arr_words_words(((StgArrWords *)bufptr)); size = arr_words_sizeW((StgArrWords *)bufptr); } @@ -4087,7 +4087,7 @@ rtsPackBuffer *packBuffer; /* ToDo: check whether this is really needed */ if (ip->type == ARR_WORDS) { ptrs = vhs = 0; - nonptrs = ((StgArrWords *)bufptr)->words+1; // payload+words + nonptrs = arr_words_words(((StgArrWords *)bufptr))+1; // payload+words size = arr_words_sizeW((StgArrWords *)bufptr); ASSERT(size==_HS+vhs+nonptrs); } diff --git a/rts/parallel/Parallel.c b/rts/parallel/Parallel.c index 99a2bb2..55c22c7 100644 --- a/rts/parallel/Parallel.c +++ b/rts/parallel/Parallel.c @@ -1045,7 +1045,7 @@ get_closure_info(StgClosure* node, nat *size, nat *ptrs, nat *nonptrs, /* ToDo: check whether this can be merged with the default case */ *size = arr_words_sizeW((StgArrWords *)node); *ptrs = 0; - *nonptrs = ((StgArrWords *)node)->words; + *nonptrs = arr_words_words(((StgArrWords *)node)); *vhs = *size - *ptrs - *nonptrs - sizeofW(StgHeader); return info; diff --git a/rts/parallel/ParallelDebug.c b/rts/parallel/ParallelDebug.c index b357af6..5616a9a 100644 --- a/rts/parallel/ParallelDebug.c +++ b/rts/parallel/ParallelDebug.c @@ -1269,7 +1269,7 @@ PrintGraph_(StgClosure *p, int indent_level) case ARR_WORDS: /* an array of (non-mutable) words */ fprintf(stderr, "ARR_WORDS (%p) of %d non-ptrs (maybe a string?)\n", - p, ((StgArrWords *)q)->words); + p, arr_words_words((StgArrWords *)q)); break; case MUT_ARR_PTRS: @@ -1626,7 +1626,7 @@ GraphFingerPrint_(StgClosure *p, char *finger_print) case ARR_WORDS: { char str[6]; - sprintf(str,"%d",((StgArrWords*)p)->words); + sprintf(str,"%d",arr_words_words((StgArrWords*)p)); strcat(finger_print,str); } break;