Changeset: 93b1024a1a5c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/93b1024a1a5c
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk.h
gdk/gdk_align.c
gdk/gdk_bat.c
gdk/gdk_batop.c
Branch: default
Log Message:
New function COLcopy2, like COLcopy, but can specify sharing vheap is ok.
The new possibility is used by BATsort since vheap data is then shared
between original and sorted copy, but the ordering is of course
potentially different.
diffs (182 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -244,6 +244,7 @@ gdk_return BUNreplace(BAT *b, oid left,
gdk_return BUNreplacemulti(BAT *b, const oid *positions, const void *values,
BUN count, bool force) __attribute__((__warn_unused_result__));
gdk_return BUNreplacemultiincr(BAT *b, oid position, const void *values, BUN
count, bool force) __attribute__((__warn_unused_result__));
BAT *COLcopy(BAT *b, int tt, bool writable, role_t role);
+BAT *COLcopy2(BAT *b, int tt, bool writable, bool mayshare, role_t role);
BAT *COLnew(oid hseq, int tltype, BUN capacity, role_t role)
__attribute__((__warn_unused_result__));
BAT *COLnew2(oid hseq, int tt, BUN cap, role_t role, uint16_t width)
__attribute__((__warn_unused_result__));
size_t GDK_mem_maxsize;
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -850,6 +850,7 @@ gdk_export restrict_t BATgetaccess(BAT *
gdk_export gdk_return BATclear(BAT *b, bool force);
gdk_export BAT *COLcopy(BAT *b, int tt, bool writable, role_t role);
+gdk_export BAT *COLcopy2(BAT *b, int tt, bool writable, bool mayshare, role_t
role);
gdk_export gdk_return BATgroup(BAT **groups, BAT **extents, BAT **histo, BAT
*b, BAT *s, BAT *g, BAT *e, BAT *h)
__attribute__((__access__(write_only, 1)))
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -213,8 +213,7 @@ VIEWcreate(oid seq, BAT *b, BUN l, BUN h
/*
* The BATmaterialize routine produces in-place materialized version
- * of a void bat (which should not be a VIEW) (later we should add the
- * code for VIEWs).
+ * of a void bat.
*/
gdk_return
@@ -226,7 +225,6 @@ BATmaterialize(BAT *b, BUN cap)
oid t, *x;
BATcheck(b, GDK_FAIL);
- assert(!isVIEW(b));
if (cap == BUN_NONE || cap < BATcapacity(b))
cap = BATcapacity(b);
MT_lock_set(&b->theaplock);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -634,7 +634,7 @@ wrongtype(int t1, int t2)
* do inline array[T] inserts.
*/
BAT *
-COLcopy(BAT *b, int tt, bool writable, role_t role)
+COLcopy2(BAT *b, int tt, bool writable, bool mayshare, role_t role)
{
bool slowcopy = false;
BAT *bn = NULL;
@@ -643,6 +643,11 @@ COLcopy(BAT *b, int tt, bool writable, r
BATcheck(b, NULL);
+ /* can't share vheap when persistent */
+ assert(!mayshare || role == TRANSIENT);
+ if (mayshare && role != TRANSIENT)
+ mayshare = false;
+
/* maybe a bit ugly to change the requested bat type?? */
if (b->ttype == TYPE_void && !writable)
tt = TYPE_void;
@@ -712,26 +717,29 @@ COLcopy(BAT *b, int tt, bool writable, r
if (ATOMsize(tt) != ATOMsize(bi.type)) {
/* oops, void materialization */
slowcopy = true;
- } else if (bi.h && bi.h->parentid != b->batCacheid &&
- BATcapacity(BBP_desc(bi.h->parentid)) > bi.count +
bi.count) {
- /* reduced slice view: do not copy too much
- * garbage */
- slowcopy = true;
- } else if (bi.vh && bi.vh->parentid != b->batCacheid &&
- BATcount(BBP_desc(bi.vh->parentid)) > bi.count +
bi.count) {
- /* reduced vheap view: do not copy too much
- * garbage; this really is a heuristic since the
- * vheap could be used completely, even if the
- * offset heap is only (less than) half the size
- * of the parent's offset heap */
- slowcopy = true;
+ mayshare = false;
+ } else if (!mayshare) {
+ if (bi.h && bi.h->parentid != b->batCacheid &&
+ BATcapacity(BBP_desc(bi.h->parentid)) > bi.count +
bi.count) {
+ /* reduced slice view: do not copy too much
+ * garbage */
+ slowcopy = true;
+ } else if (bi.vh && bi.vh->parentid != b->batCacheid &&
+ BATcount(BBP_desc(bi.vh->parentid)) >
bi.count + bi.count) {
+ /* reduced vheap view: do not copy too much
+ * garbage; this really is a heuristic since the
+ * vheap could be used completely, even if the
+ * offset heap is only (less than) half the size
+ * of the parent's offset heap */
+ slowcopy = true;
+ }
}
bn = COLnew2(b->hseqbase, tt, bi.count, role, bi.width);
if (bn == NULL) {
goto bunins_failed;
}
- if (bn->tvheap != NULL && bn->tvheap->base == NULL) {
+ if (bn->tvheap != NULL && bn->tvheap->base == NULL &&
!mayshare) {
/* this combination can happen since the last
* argument of COLnew2 not being zero triggers a
* skip in the allocation of the tvheap */
@@ -746,20 +754,26 @@ COLcopy(BAT *b, int tt, bool writable, r
bn->theap->free = 0;
} else if (!slowcopy) {
/* case (3): just copy the heaps */
- if (bn->tvheap && HEAPextend(bn->tvheap, bi.vhfree,
true) != GDK_SUCCEED) {
- goto bunins_failed;
+ if (bn->tvheap) {
+ if (mayshare) {
+ HEAPincref(bi.vh);
+ HEAPdecref(bn->tvheap, true);
+ BBPretain(bi.vh->parentid);
+ bn->tvheap = bi.vh;
+ } else {
+ if (HEAPextend(bn->tvheap, bi.vhfree,
true) != GDK_SUCCEED)
+ goto bunins_failed;
+ memcpy(bn->tvheap->base, bi.vh->base,
bi.vhfree);
+ bn->tvheap->free = bi.vhfree;
+ bn->tvheap->dirty = true;
+ bn->tascii = bi.ascii;
+ if (ATOMstorage(b->ttype) == TYPE_str
&& bi.vhfree >= GDK_STRHASHSIZE)
+ memcpy(bn->tvheap->base,
strhash, GDK_STRHASHSIZE);
+ }
}
memcpy(bn->theap->base, bi.base, bi.hfree);
bn->theap->free = bi.hfree;
bn->theap->dirty = true;
- if (bn->tvheap) {
- memcpy(bn->tvheap->base, bi.vh->base,
bi.vhfree);
- bn->tvheap->free = bi.vhfree;
- bn->tvheap->dirty = true;
- bn->tascii = bi.ascii;
- if (ATOMstorage(b->ttype) == TYPE_str &&
bi.vhfree >= GDK_STRHASHSIZE)
- memcpy(bn->tvheap->base, strhash,
GDK_STRHASHSIZE);
- }
/* make sure we use the correct capacity */
if (ATOMstorage(bn->ttype) == TYPE_msk)
@@ -886,6 +900,12 @@ COLcopy(BAT *b, int tt, bool writable, r
return NULL;
}
+BAT *
+COLcopy(BAT *b, int tt, bool writable, role_t role)
+{
+ return COLcopy2(b, tt, writable, false, role);
+}
+
/* Append an array of values of length count to the bat. For
* fixed-sized values, `values' is an array of values, for
* variable-sized values, `values' is an array of pointers to values.
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -2703,7 +2703,7 @@ BATsort(BAT **sorted, BAT **order, BAT *
if (bn == NULL)
goto error;
if (bn->ttype == TYPE_void || isVIEW(bn)) {
- BAT *b2 = COLcopy(bn, ATOMtype(bn->ttype), true,
TRANSIENT);
+ BAT *b2 = COLcopy2(bn, ATOMtype(bn->ttype), true, true,
TRANSIENT);
BBPunfix(bn->batCacheid);
bn = b2;
}
@@ -2715,7 +2715,7 @@ BATsort(BAT **sorted, BAT **order, BAT *
pb = NULL;
}
} else {
- bn = COLcopy(b, b->ttype, true, TRANSIENT);
+ bn = COLcopy2(b, b->ttype, true, true, TRANSIENT);
}
if (bn == NULL)
goto error;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]