|
From: <sv...@va...> - 2005-07-17 17:56:28
|
Author: njn
Date: 2005-07-17 18:55:42 +0100 (Sun, 17 Jul 2005)
New Revision: 4152
Log:
Introduce get_bszB() and get_bszB_as_is() to factor out some common
combinations of function calls.
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 17:20:30 UTC (rev 4151)
+++ trunk/coregrind/m_mallocfree.c 2005-07-17 17:55:42 UTC (rev 4152)
@@ -210,7 +210,23 @@
return *(SizeT*)&lb[-sizeof(SizeT) + 1];
}
=20
+// Get a block's size as stored, ie with the in-use/free attribute.
+static __inline__
+SizeT get_bszB_as_is ( Block* b )
+{
+ SizeT bszB_lo =3D get_bszB_lo(b);
+ SizeT bszB_hi =3D get_bszB_hi(b);
+ vg_assert(bszB_lo =3D=3D bszB_hi);
+ return bszB_lo;
+}
=20
+// Get a block's plain size, ie. remove the in-use/free attribute.
+static __inline__
+SizeT get_bszB ( Block* b )
+{
+ return mk_plain_bszB(get_bszB_as_is(b));
+}
+
// 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__
@@ -628,20 +644,18 @@
static=20
void ppSuperblocks ( Arena* a )
{
- UInt i, blockno;
+ UInt i, blockno =3D 1;
+ Superblock* sb =3D a->sblocks;
SizeT b_bszB;
- Block* b;
- Superblock* sb =3D a->sblocks;
- blockno =3D 1;
=20
while (sb) {
VG_(printf)( "\n" );
VG_(printf)( "superblock %d at %p, sb->n_pl_bs =3D %d, next =3D %p=
\n",=20
blockno++, sb, sb->n_payload_bytes, sb->next );
- for (i =3D 0; i < sb->n_payload_bytes; i +=3D mk_plain_bszB(b_bszB=
)) {
- b =3D (Block*)&sb->payload_bytes[i];
- b_bszB =3D get_bszB_lo(b);
- VG_(printf)( " block at %d, bszB %d: ", i, mk_plain_bszB(b_bs=
zB) );
+ for (i =3D 0; i < sb->n_payload_bytes; i +=3D b_bszB) {
+ Block* b =3D (Block*)&sb->payload_bytes[i];
+ b_bszB =3D get_bszB(b);
+ VG_(printf)( " block at %d, bszB %d: ", i, b_bszB );
VG_(printf)( "%s, ", is_inuse_block(b) ? "inuse" : "free");
VG_(printf)( "%s\n", blockSane(a, b) ? "ok" : "BAD" );
}
@@ -678,7 +692,7 @@
for (i =3D 0; i < sb->n_payload_bytes; i +=3D mk_plain_bszB(b_bszB=
)) {
blockctr_sb++;
b =3D (Block*)&sb->payload_bytes[i];
- b_bszB =3D get_bszB_lo(b);
+ b_bszB =3D get_bszB_as_is(b);
if (!blockSane(a, b)) {
VG_(printf)("sanity_check_malloc_arena: sb %p, block %d (bsz=
B %d): "
" BAD\n", sb, i, b_bszB );
@@ -732,7 +746,7 @@
listno, b );
BOMB;
}
- b_pszB =3D bszB_to_pszB(a, mk_plain_bszB(get_bszB_lo(b)));
+ b_pszB =3D bszB_to_pszB(a, get_bszB(b));
if (b_pszB < list_min_pszB || b_pszB > list_max_pszB) {
VG_(printf)(=20
"sanity_check_malloc_arena: list %d at %p: "
@@ -890,7 +904,7 @@
b =3D a->freelist[lno];
if (NULL =3D=3D b) continue; // If this list is empty, try the n=
ext one.
while (True) {
- b_bszB =3D mk_plain_bszB(get_bszB_lo(b));
+ b_bszB =3D get_bszB(b);
if (b_bszB >=3D req_bszB) goto obtained_block; // success!
b =3D get_next_b(b);
if (b =3D=3D a->freelist[lno]) break; // traversed entire fre=
elist
@@ -918,7 +932,7 @@
vg_assert(b !=3D NULL);
vg_assert(lno < N_MALLOC_LISTS);
vg_assert(a->freelist[lno] !=3D NULL);
- b_bszB =3D mk_plain_bszB(get_bszB_lo(b));
+ b_bszB =3D get_bszB(b);
// req_bszB is the size of the block we are after. b_bszB is the
// size of what we've actually got. */
vg_assert(b_bszB >=3D req_bszB);
@@ -933,7 +947,7 @@
mkInuseBlock(a, b, req_bszB);
mkFreeBlock(a, &b[req_bszB], frag_bszB,=20
pszB_to_listNo(bszB_to_pszB(a, frag_bszB)));
- b_bszB =3D mk_plain_bszB(get_bszB_lo(b));
+ b_bszB =3D get_bszB(b);
} else {
// No, mark as in use and use as-is.
unlinkBlock(a, b, lno);
@@ -985,14 +999,14 @@
vg_assert(blockSane(a, b));
# endif
=20
- a->bytes_on_loan -=3D bszB_to_pszB(a, mk_plain_bszB(get_bszB_lo(b)));
+ a->bytes_on_loan -=3D bszB_to_pszB(a, get_bszB(b));
=20
sb =3D findSb( a, b );
sb_start =3D &sb->payload_bytes[0];
sb_end =3D &sb->payload_bytes[sb->n_payload_bytes - 1];
=20
// Put this chunk back on a list somewhere.
- b_bszB =3D get_bszB_lo(b);
+ b_bszB =3D get_bszB(b);
b_pszB =3D bszB_to_pszB(a, b_bszB);
b_listno =3D pszB_to_listNo(b_pszB);
mkFreeBlock( a, b, b_bszB, b_listno );
@@ -1003,10 +1017,9 @@
other_b =3D b + b_bszB;
if (other_b+min_useful_bszB(a)-1 <=3D (Block*)sb_end) {
// Ok, we have a successor, merge if it's not in use.
- other_bszB =3D get_bszB_lo(other_b);
+ other_bszB =3D get_bszB(other_b);
if (!is_inuse_block(other_b)) {
// VG_(printf)( "merge-successor\n");
- other_bszB =3D mk_plain_bszB(other_bszB);
# ifdef DEBUG_MALLOC
vg_assert(blockSane(a, other_b));
# endif
@@ -1028,10 +1041,9 @@
if (b >=3D (Block*)sb_start + min_useful_bszB(a)) {
// Ok, we have a predecessor, merge if it's not in use.
other_b =3D get_predecessor_block( b );
- other_bszB =3D get_bszB_lo(other_b);
+ other_bszB =3D get_bszB(other_b);
if (!is_inuse_block(other_b)) {
// VG_(printf)( "merge-predecessor\n");
- other_bszB =3D mk_plain_bszB(other_bszB);
unlinkBlock( a, b, b_listno );
unlinkBlock( a, other_b, pszB_to_listNo(bszB_to_pszB(a, other_b=
szB)) );
b =3D other_b;
@@ -1144,7 +1156,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, mk_plain_bszB(get_bszB_lo(base_b)))=
;
+ base_pszB_act =3D bszB_to_pszB(a, get_bszB(base_b));
=20
/* Create the fragment block, and put it back on the relevant free li=
st. */
mkFreeBlock ( a, base_b, frag_bszB,
@@ -1160,13 +1172,11 @@
=20
vg_assert(req_pszB
<=3D=20
- bszB_to_pszB(a, mk_plain_bszB(get_bszB_lo(
- get_payload_block(a, align_=
p))))
+ bszB_to_pszB(a, get_bszB(get_payload_block(a, align_p)))
);
=20
a->bytes_on_loan=20
- +=3D bszB_to_pszB(a, mk_plain_bszB(get_bszB_lo(
- get_payload_block(a, align_p))=
));
+ +=3D bszB_to_pszB(a, get_bszB(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
@@ -1188,7 +1198,7 @@
{
Arena* a =3D arenaId_to_ArenaP(aid);
Block* b =3D get_payload_block(a, ptr);
- return bszB_to_pszB(a, get_bszB_lo(b));
+ return bszB_to_pszB(a, get_bszB(b));
}
=20
=20
@@ -1236,7 +1246,7 @@
vg_assert(blockSane(a, b));
=20
vg_assert(is_inuse_block(b));
- old_bszB =3D mk_plain_bszB(get_bszB_lo(b));
+ old_bszB =3D get_bszB(b);
old_pszB =3D bszB_to_pszB(a, old_bszB);
=20
if (req_pszB <=3D old_pszB) {
|