Permalink
Browse files

FIX #38000 Store StgArrWords payload size in bytes

  • Loading branch information...
1 parent a0e32f1 commit 17c8229adf9f268097e4c87053d940a918c3a26f @aslatter aslatter committed Jan 1, 2010
@@ -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
@@ -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]
View
@@ -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)
@@ -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);
@@ -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; }
@@ -137,7 +137,7 @@ typedef struct StgBlockingQueue_ {
typedef struct {
StgHeader header;
- StgWord words;
+ StgWord bytes;
StgWord payload[FLEXIBLE_ARRAY];
} StgArrWords;
View
@@ -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) {
View
@@ -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; i<arr_words_words((StgArrWords *)obj); i++)
debugBelch("%lu", (lnat)((StgArrWords *)obj)->payload[i]);
debugBelch("\")\n");
break;
View
@@ -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; i<n; i++)
@@ -2817,7 +2817,7 @@ UnpackArray(StgWord ***bufptrP, StgClosure *graph)
ASSERT(info->type == 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; i<n; i++)
@@ -3928,7 +3928,7 @@ rtsPackBuffer *packBuffer;
/* ToDo: check whether this is really needed */
if (ip->type == 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);
}
View
@@ -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;
@@ -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;

0 comments on commit 17c8229

Please sign in to comment.