Changeset: afc023dbb9a5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/afc023dbb9a5
Modified Files:
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_bbp.c
        gdk/gdk_cand.c
        gdk/gdk_project.c
Branch: Jul2021
Log Message:

Fixes to heap reference counting.


diffs (133 lines):

diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -328,7 +328,6 @@ VIEWreset(BAT *b)
                .parentid = b->batCacheid,
                .farmid = BBPselectfarm(b->batRole, b->ttype, offheap),
        };
-       ATOMIC_INIT(&tail->refs, 1);
        settailname(tail, nme, b->ttype, b->twidth);
        if (b->ttype && HEAPalloc(tail, cnt, Tsize(b), Tsize(b)) != 
GDK_SUCCEED) {
                GDKfree(tail);
@@ -348,7 +347,6 @@ VIEWreset(BAT *b)
                        .farmid = BBPselectfarm(b->batRole, b->ttype, varheap),
                        .parentid = b->batCacheid,
                };
-               ATOMIC_INIT(&th->refs, 1);
                strconcat_len(th->filename, sizeof(th->filename),
                              nme, ".theap", NULL);
                if (ATOMheap(b->ttype, th, cnt) != GDK_SUCCEED) {
@@ -358,7 +356,9 @@ VIEWreset(BAT *b)
                        BBPunfix(v->batCacheid);
                        return GDK_FAIL;
                }
+               ATOMIC_INIT(&th->refs, 1);
        }
+       ATOMIC_INIT(&tail->refs, 1);
 
        BAT bak = *b;           /* backup copy */
 
@@ -382,11 +382,9 @@ VIEWreset(BAT *b)
        if (BATappend2(b, v, NULL, false, false) != GDK_SUCCEED) {
                /* clean up the mess */
                if (th) {
-                       HEAPfree(th, true);
-                       GDKfree(th);
+                       HEAPdecref(th, true);
                }
-               HEAPfree(tail, true);
-               GDKfree(tail);
+               HEAPdecref(tail, true);
                *b = bak;
                BBPunfix(v->batCacheid);
                return GDK_FAIL;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -115,7 +115,6 @@ BATcreatedesc(oid hseq, int tt, bool hea
 
        if (heapnames) {
                assert(bn->theap != NULL);
-               ATOMIC_INIT(&bn->theap->refs, 1);
                bn->theap->parentid = bn->batCacheid;
                bn->theap->farmid = BBPselectfarm(role, bn->ttype, offheap);
 
@@ -135,6 +134,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
                                      sizeof(bn->tvheap->filename),
                                      nme, ".theap", NULL);
                }
+               ATOMIC_INIT(&bn->theap->refs, 1);
        } else {
                assert(bn->theap == NULL);
        }
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -531,6 +531,8 @@ vheapinit(BAT *b, const char *buf, int h
                           "%n",
                           &free, &size, &storage, &n) < 3) {
                        TRC_CRITICAL(GDK, "invalid format for BBP.dir on line 
%d", lineno);
+                       GDKfree(b->theap);
+                       b->tvheap = NULL;
                        return -1;
                }
                b->tvheap->free = (size_t) free;
@@ -2221,8 +2223,8 @@ incref(bat i, bool logical, bool lock)
                        if (b->theap != pb->theap) {
                                HEAPincref(pb->theap);
                                HEAPdecref(b->theap, false);
+                               b->theap = pb->theap;
                        }
-                       b->theap = pb->theap;
                }
                /* done loading, release descriptor */
                BBP_status_off(i, BBPLOADING);
diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c
--- a/gdk/gdk_cand.c
+++ b/gdk/gdk_cand.c
@@ -1328,6 +1328,7 @@ BATnegcands(BUN nr, BAT *odels)
                memcpy(r, Tloc(odels, lo), sizeof(oid) * (hi - lo));
        }
        bn->batDirtydesc = true;
+       assert(bn->tvheap == NULL);
        bn->tvheap = dels;
        BATsetcount(bn, bn->batCount - (hi - lo));
        TRC_DEBUG(ALGO, "BATnegcands(cands=" ALGOBATFMT ","
@@ -1416,6 +1417,7 @@ BATmaskedcands(oid hseq, BUN nr, BAT *ma
        }
        if (cnt > 0) {
                ATOMIC_INIT(&msks->refs, 1);
+               assert(bn->tvheap == NULL);
                bn->tvheap = msks;
                bn->tseqbase += (oid) c->firstbit;
        } else {
@@ -1507,6 +1509,7 @@ BATunmask(BAT *b)
                        dels->free = sizeof(ccand_t) + n * sizeof(oid);
                        dels->dirty = true;
                        ATOMIC_INIT(&dels->refs, 1);
+                       assert(bn->tvheap == NULL);
                        bn->tvheap = dels;
                }
                BATsetcount(bn, n=BATcount(b));
diff --git a/gdk/gdk_project.c b/gdk/gdk_project.c
--- a/gdk/gdk_project.c
+++ b/gdk/gdk_project.c
@@ -375,8 +375,8 @@ project_str(BAT *restrict l, struct cand
        if (r1->tvheap == r2->tvheap) {
                h1off = 0;
                BBPshare(r1->tvheap->parentid);
-               HEAPfree(bn->tvheap, true);
-               GDKfree(bn->tvheap);
+               HEAPdecref(bn->tvheap, true);
+               HEAPincref(r1->tvheap);
                bn->tvheap = r1->tvheap;
        } else {
                v = (v + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1);
@@ -991,6 +991,7 @@ BATprojectchain(BAT **bats)
                        bn->tkey = false;
                        MT_lock_set(&b->theaplock);
                        BBPshare(b->tvheap->parentid);
+                       assert(bn->tvheap == NULL);
                        bn->tvheap = b->tvheap;
                        HEAPincref(b->tvheap);
                        MT_lock_unset(&b->theaplock);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to