|
From: <sv...@va...> - 2005-07-17 18:12:03
|
Author: njn
Date: 2005-07-17 19:12:00 +0100 (Sun, 17 Jul 2005)
New Revision: 4154
Log:
Introduced get_pszB() to cover several common cases.
Modified:
trunk/coregrind/m_mallocfree.c
Modified: trunk/coregrind/m_mallocfree.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_mallocfree.c 2005-07-17 18:00:57 UTC (rev 4153)
+++ trunk/coregrind/m_mallocfree.c 2005-07-17 18:12:00 UTC (rev 4154)
@@ -194,6 +194,45 @@
return &b2[mk_plain_bszB(get_bszB_lo(b)) - 1];
}
=20
+// Return the lower, upper and total overhead in bytes for a block.
+// These are determined purely by which arena the block lives in.
+static __inline__
+SizeT overhead_szB_lo ( Arena* a )
+{
+ return sizeof(SizeT) + sizeof(void*) + a->rz_szB;
+}
+static __inline__
+SizeT overhead_szB_hi ( Arena* a )
+{
+ return a->rz_szB + sizeof(void*) + sizeof(SizeT);
+}
+static __inline__
+SizeT overhead_szB ( Arena* a )
+{
+ return overhead_szB_lo(a) + overhead_szB_hi(a);
+}
+
+// Return the minimum bszB for a block in this arena. Can have zero-len=
gth
+// payloads, so it's the size of the admin bytes.
+static __inline__
+SizeT min_useful_bszB ( Arena* a )
+{
+ return overhead_szB(a);
+}
+
+// Convert payload size <--> block size (both in bytes).
+static __inline__
+SizeT pszB_to_bszB ( Arena* a, SizeT pszB )
+{
+ return pszB + overhead_szB(a);
+}
+static __inline__
+SizeT bszB_to_pszB ( Arena* a, SizeT bszB )
+{
+ vg_assert(bszB >=3D overhead_szB(a));
+ return bszB - overhead_szB(a);
+}
+
// Set and get the upper size field of a block.
static __inline__
void set_bszB_hi ( Block* b, SizeT bszB )
@@ -227,23 +266,12 @@
return mk_plain_bszB(get_bszB_as_is(b));
}
=20
-// Return the lower, upper and total overhead in bytes for a block.
-// These are determined purely by which arena the block lives in.
+// Get a block's payload size.
static __inline__
-SizeT overhead_szB_lo ( Arena* a )
+SizeT get_pszB ( Arena* a, Block* b )
{
- return sizeof(SizeT) + sizeof(void*) + a->rz_szB;
+ return bszB_to_pszB(a, get_bszB(b));
}
-static __inline__
-SizeT overhead_szB_hi ( Arena* a )
-{
- return a->rz_szB + sizeof(void*) + sizeof(SizeT);
-}
-static __inline__
-SizeT overhead_szB ( Arena* a )
-{
- return overhead_szB_lo(a) + overhead_szB_hi(a);
-}
=20
// Given the addr of a block, return the addr of its payload.
static __inline__
@@ -323,28 +351,6 @@
}
=20
=20
-// Return the minimum bszB for a block in this arena. Can have zero-len=
gth
-// payloads, so it's the size of the admin bytes.
-static __inline__
-SizeT min_useful_bszB ( Arena* a )
-{
- return overhead_szB(a);
-}
-
-// Convert payload size <--> block size (both in bytes).
-static __inline__
-SizeT pszB_to_bszB ( Arena* a, SizeT pszB )
-{
- return pszB + overhead_szB(a);
-}
-static __inline__
-SizeT bszB_to_pszB ( Arena* a, SizeT bszB )
-{
- vg_assert(bszB >=3D overhead_szB(a));
- return bszB - overhead_szB(a);
-}
-
-
/*------------------------------------------------------------*/
/*--- Arena management ---*/
/*------------------------------------------------------------*/
@@ -746,7 +752,7 @@
listno, b );
BOMB;
}
- b_pszB =3D bszB_to_pszB(a, get_bszB(b));
+ b_pszB =3D get_pszB(a, b);
if (b_pszB < list_min_pszB || b_pszB > list_max_pszB) {
VG_(printf)(=20
"sanity_check_malloc_arena: list %d at %p: "
@@ -1156,7 +1162,7 @@
vg_assert(frag_bszB >=3D min_useful_bszB(a));
=20
/* The actual payload size of the block we are going to split. */
- base_pszB_act =3D bszB_to_pszB(a, get_bszB(base_b));
+ base_pszB_act =3D get_pszB(a, base_b);
=20
/* Create the fragment block, and put it back on the relevant free li=
st. */
mkFreeBlock ( a, base_b, frag_bszB,
@@ -1170,12 +1176,9 @@
/* Final sanity checks. */
vg_assert( is_inuse_block(get_payload_block(a, align_p)) );
=20
- vg_assert(req_pszB
- <=3D=20
- bszB_to_pszB(a, get_bszB(get_payload_block(a, align_p)))
- );
+ vg_assert(req_pszB <=3D get_pszB(a, get_payload_block(a, align_p)));
=20
- a->bytes_on_loan +=3D bszB_to_pszB(a, get_bszB(get_payload_block(a, a=
lign_p)));
+ a->bytes_on_loan +=3D get_pszB(a, get_payload_block(a, align_p));
if (a->bytes_on_loan > a->bytes_on_loan_max)
a->bytes_on_loan_max =3D a->bytes_on_loan;
=20
@@ -1197,7 +1200,7 @@
{
Arena* a =3D arenaId_to_ArenaP(aid);
Block* b =3D get_payload_block(a, ptr);
- return bszB_to_pszB(a, get_bszB(b));
+ return get_pszB(a, b);
}
=20
=20
@@ -1230,7 +1233,7 @@
void* VG_(arena_realloc) ( ArenaId aid, void* ptr, SizeT req_pszB )
{
Arena* a;
- SizeT old_bszB, old_pszB;
+ SizeT old_pszB;
UChar *p_new;
Block* b;
=20
@@ -1245,8 +1248,7 @@
vg_assert(blockSane(a, b));
=20
vg_assert(is_inuse_block(b));
- old_bszB =3D get_bszB(b);
- old_pszB =3D bszB_to_pszB(a, old_bszB);
+ old_pszB =3D get_pszB(a, b);
=20
if (req_pszB <=3D old_pszB) {
VGP_POPCC(VgpMalloc);
|