|
From: <sv...@va...> - 2008-03-23 16:18:26
|
Author: bart
Date: 2008-03-23 16:15:43 +0000 (Sun, 23 Mar 2008)
New Revision: 7763
Log:
bm_merge2() now shares unmodified second level bitmaps instead of copying these.
Modified:
branches/DRDDEV/exp-drd/drd_bitmap.c
branches/DRDDEV/exp-drd/drd_bitmap.h
Modified: branches/DRDDEV/exp-drd/drd_bitmap.c
===================================================================
--- branches/DRDDEV/exp-drd/drd_bitmap.c 2008-03-23 15:47:03 UTC (rev 7762)
+++ branches/DRDDEV/exp-drd/drd_bitmap.c 2008-03-23 16:15:43 UTC (rev 7763)
@@ -631,37 +631,35 @@
bm2->oset = tmp;
}
+/** Merge bitmaps *lhs and *rhs into *lhs. */
void bm_merge2(struct bitmap* const lhs,
const struct bitmap* const rhs)
{
struct bitmap2* bm2l;
- const struct bitmap2ref* bm2l_ref;
- const struct bitmap2* bm2r;
+ struct bitmap2ref* bm2l_ref;
+ struct bitmap2* bm2r;
const struct bitmap2ref* bm2r_ref;
- // First step: allocate any missing bitmaps in *lhs.
VG_(OSetGen_ResetIter)(rhs->oset);
- for ( ; (bm2r_ref = VG_(OSetGen_Next)(rhs->oset)) != 0; )
- {
- bm2r = bm2r_ref->bm2;
- bm2_lookup_or_insert(lhs, bm2r->addr);
- }
- VG_(OSetGen_ResetIter)(lhs->oset);
- VG_(OSetGen_ResetIter)(rhs->oset);
-
for ( ; (bm2r_ref = VG_(OSetGen_Next)(rhs->oset)) != 0; )
{
bm2r = bm2r_ref->bm2;
- do
+ bm2l_ref = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr);
+ if (bm2l_ref)
{
- bm2l_ref = VG_(OSetGen_Next)(lhs->oset);
bm2l = bm2l_ref->bm2;
- } while (bm2l->addr < bm2r->addr);
-
- tl_assert(bm2l->addr == bm2r->addr);
-
- bm2_merge(bm2l, bm2r);
+ if (bm2l != bm2r)
+ {
+ if (bm2l->refcnt > 1)
+ bm2l = bm2_make_exclusive(lhs, bm2l_ref);
+ bm2_merge(bm2l, bm2r);
+ }
+ }
+ else
+ {
+ bm2_insert_addref(lhs, bm2r);
+ }
}
}
@@ -847,7 +845,10 @@
{
unsigned k;
+ tl_assert(bm2l);
+ tl_assert(bm2r);
tl_assert(bm2l->addr == bm2r->addr);
+ tl_assert(bm2l->refcnt == 1);
for (k = 0; k < BITMAP1_UWORD_COUNT; k++)
{
Modified: branches/DRDDEV/exp-drd/drd_bitmap.h
===================================================================
--- branches/DRDDEV/exp-drd/drd_bitmap.h 2008-03-23 15:47:03 UTC (rev 7762)
+++ branches/DRDDEV/exp-drd/drd_bitmap.h 2008-03-23 16:15:43 UTC (rev 7763)
@@ -297,6 +297,30 @@
return bm2;
}
+/** Insert a new node in bitmap bm that points to the second level bitmap
+ * *bm2. This means that *bm2 becomes shared over two or more bitmaps.
+ */
+static __inline__
+struct bitmap2* bm2_insert_addref(const struct bitmap* const bm,
+ struct bitmap2* const bm2)
+{
+ struct bitmap2ref* bm2ref;
+
+ tl_assert(bm);
+ tl_assert(VG_(OSetGen_Lookup)(bm->oset, &bm2->addr) == 0);
+ bm2ref = VG_(OSetGen_AllocNode)(bm->oset, sizeof(*bm2ref));
+ bm2ref->addr = bm2->addr;
+ bm2ref->bm2 = bm2;
+ bm2->refcnt++;
+ VG_(OSetGen_Insert)(bm->oset, bm2ref);
+
+ ((struct bitmap*)bm)->last_lookup_a1 = bm2->addr;
+ ((struct bitmap*)bm)->last_lookup_bm2ref = bm2ref;
+ ((struct bitmap*)bm)->last_lookup_bm2 = bm2;
+
+ return bm2;
+}
+
/** Look up the address a1 in bitmap bm, and insert it if not found.
* The returned second level bitmap may not be modified.
*
|