Changeset: 16b3a361abff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/16b3a361abff
Modified Files:
        gdk/gdk_utils.c
        monetdb5/mal/mal.h
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_resolve.c
        monetdb5/mal/mal_type.c
        monetdb5/mal/mal_type.h
        monetdb5/modules/mal/inspect.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/mdb.c
        monetdb5/modules/mal/remote.c
        monetdb5/optimizer/opt_multiplex.c
        sql/backends/monet5/sql.c
Branch: resource_management
Log Message:

use separate allocator for mal instructions


diffs (truncated from 857 to 300 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2493,4 +2493,6 @@ sa_free(allocator *sa, void *obj)
        sa->frees++;
        if (sz < SA_BLOCK_SIZE)
                sa_free_obj(sa, ptr, sz);
+       else
+               sa_free_blk(sa, ptr);
 }
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -183,6 +183,7 @@ typedef struct MALBLK {
        str errors;                                     /* left over errors */
        int maxarg;                                     /* keep track on the 
maximal arguments used */
        allocator *ma;                          /* mal blocks are fully 
allocated using a single allocator */
+       allocator *instr_allocator;     /* mal instructions allocator */
 
        /* During the run we keep track on the maximum number of concurrent 
threads and memory claim */
        ATOMIC_TYPE workers;
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -181,14 +181,14 @@ chkFlow(MalBlkPtr mb)
                        } else if (ps->typeresolved)
                                for (e = 0; e < p->retc; e++) {
                                        if (resolvedType(getArgType(mb, ps, e), 
getArgType(mb, p, e)) < 0) {
-                                               str tpname = 
getTypeName(getArgType(mb, p, e));
+                                               str tpname = 
getTypeName(mb->ma, getArgType(mb, p, e));
                                                msg = createException(MAL,
                                                                                
          "%s.%s RETURN type mismatch at type '%s'\n",
                                                                                
          getModuleId(p) ? getModuleId(p) :
                                                                                
          "",
                                                                                
          getFunctionId(p) ?
                                                                                
          getFunctionId(p) : "", tpname);
-                                               GDKfree(tpname);
+                                               // GDKfree(tpname);
                                                return msg;
                                        }
                                }
@@ -210,7 +210,7 @@ chkFlow(MalBlkPtr mb)
                                        str l = instruction2str(mb, 0, p, TRUE);
                                        msg = createException(MAL, "%s.%s 
signature misplaced\n!%s",
                                                                                
  getModuleId(p), getFunctionId(p), l);
-                                       GDKfree(l);
+                                       //GDKfree(l);
                                        return msg;
                                }
                        }
@@ -427,7 +427,7 @@ debugFunction(stream *fd, MalBlkPtr mb, 
                                }
                                mnstr_printf(fd, "\n");
                        }
-                       GDKfree(ps);
+                       //GDKfree(ps);
                } else
                        mnstr_printf(fd, "#failed instruction2str()\n");
        }
@@ -463,7 +463,7 @@ listFunction(stream *fd, MalBlkPtr mb, M
                                size_t l = strlen(ps);
                                if (l > len)
                                        len = l;
-                               GDKfree(ps);
+                               //GDKfree(ps);
                        } else
                                mnstr_printf(fd, "#failed instruction2str()\n");
                }
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -119,6 +119,7 @@ newMalBlk(int elements)
        MalBlkPtr mb;
        VarRecord *v;
        allocator *ma = ma_create(NULL);
+       allocator *instr_allocator = ma_create(ma);
 
        if (!ma)
                return NULL;
@@ -146,6 +147,7 @@ newMalBlk(int elements)
                .maxarg = MAXARG,               /* the minimum for each 
instruction */
                .workers = ATOMIC_VAR_INIT(1),
                .ma = ma,
+               .instr_allocator = instr_allocator
        };
        if (newMalBlkStmt(mb, elements) < 0) {
                ma_destroy(ma);
@@ -303,7 +305,7 @@ copyMalBlk(MalBlkPtr old)
 {
        MalBlkPtr mb;
        int i;
-       allocator *ma = ma_create(old->ma->pa);
+       allocator *ma = ma_create(NULL);
 
        if (!ma)
                return NULL;
@@ -405,7 +407,7 @@ newInstructionArgs(MalBlkPtr mb, const c
                return NULL;
        if (args <= 0)
                args = 1;
-       p = (InstrPtr)MA_NEW_ARRAY(mb->ma, char, args * sizeof(p->argv[0]) + 
offsetof(InstrRecord, argv));
+       p = (InstrPtr)MA_NEW_ARRAY(mb->instr_allocator, char, args * 
sizeof(p->argv[0]) + offsetof(InstrRecord, argv));
        if (p == NULL) {
                if (mb)
                        mb->errors = createMalException(mb, 0, TYPE,
@@ -479,7 +481,7 @@ void
 freeInstruction(MalBlkPtr mb, InstrPtr p)
 {
        assert(p && mb && mb->ma);
-       sa_free(mb->ma, p);
+       sa_free(mb->instr_allocator, p);
 }
 
 
@@ -938,8 +940,8 @@ defConstant(MalBlkPtr mb, int type, ValP
                msg = convertConstant(getBatType(type), cst);
                if (msg) {
                        str ft, tt;                     /* free old value */
-                       ft = getTypeName(otype);
-                       tt = getTypeName(type);
+                       ft = getTypeName(mb->ma, otype);
+                       tt = getTypeName(mb->ma, type);
                        if (ft && tt)
                                mb->errors = createMalException(mb, 0, TYPE,
                                                                                
                "constant coercion error from %s to %s",
@@ -947,8 +949,8 @@ defConstant(MalBlkPtr mb, int type, ValP
                        else
                                mb->errors = createMalException(mb, 0, TYPE,
                                                                                
                "constant coercion error");
-                       GDKfree(ft);
-                       GDKfree(tt);
+                       //GDKfree(ft);
+                       //GDKfree(tt);
                        freeException(msg);
                        VALclear(cst);          /* it could contain allocated 
space */
                        return -1;
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -852,7 +852,7 @@ runMALsequence(Client cntxt, MalBlkPtr m
                        if (w) {
                                ret = createException(MAL, "interpreter", 
"unknown operation:%s",
                                                                          w);
-                               GDKfree(w);
+                               //GDKfree(w);
                        } else {
                                ret = createException(MAL, "interpreter",
                                                                          
"failed instruction2str");
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -142,10 +142,10 @@ renderTerm(MalBlkPtr mb, MalStkPtr stk, 
        // special care should be taken with constants, they may have been 
casted
        if ((flg & LIST_MAL_TYPE) || (idx < p->retc) || isVarTypedef(mb, varid)
                || showtype) {
-               tpe = getTypeName(getVarType(mb, varid));
+               tpe = getTypeName(mb->ma, getVarType(mb, varid));
                if (tpe) {
                        strconcat_len(bufend, (buf + max_len) - bufend, ":", 
tpe, NULL);
-                       GDKfree(tpe);
+                       //GDKfree(tpe);
                }
        }
 }
@@ -291,12 +291,12 @@ fcnDefinition(MalBlkPtr mb, InstrPtr p, 
        if (p->retc == 1) {
                if (!copystring(&t, "):", &len))
                        return base;
-               tpe = getTypeName(getVarType(mb, getArg(p, 0)));
+               tpe = getTypeName(mb->ma, getVarType(mb, getArg(p, 0)));
                if (!copystring(&t, tpe, &len)) {
-                       GDKfree(tpe);
+                       //GDKfree(tpe);
                        return base;
                }
-               GDKfree(tpe);
+               //GDKfree(tpe);
                if (p->varargs & VARRETS && !copystring(&t, "...", &len))
                        return base;
        } else {
@@ -445,7 +445,7 @@ instruction2str(MalBlkPtr mb, MalStkPtr 
        str base, t;
        size_t len = 512 + (p->argc * 128);     /* max realistic line length 
estimate */
 
-       t = base = GDKmalloc(len);
+       t = base = ma_alloc(mb->ma, len);
        if (base == NULL)
                return NULL;
        if (!flg) {
@@ -622,16 +622,16 @@ str
 mal2str(MalBlkPtr mb, int first, int last)
 {
        str ps = NULL, *txt;
-       int i, j;
+       int i;
        size_t *len, totlen = 0;
 
-       txt = GDKmalloc(sizeof(str) * mb->stop);
-       len = GDKmalloc(sizeof(size_t) * mb->stop);
+       txt = ma_alloc(mb->ma, sizeof(str) * mb->stop);
+       len = ma_alloc(mb->ma, sizeof(size_t) * mb->stop);
 
        if (txt == NULL || len == NULL) {
                addMalException(mb, "mal2str: " MAL_MALLOC_FAIL);
-               GDKfree(txt);
-               GDKfree(len);
+               //GDKfree(txt);
+               //GDKfree(len);
                return NULL;
        }
        for (i = first; i < last; i++) {
@@ -648,20 +648,20 @@ mal2str(MalBlkPtr mb, int first, int las
                        totlen += len[i] = strlen(txt[i]);
                else {
                        addMalException(mb, "mal2str: " MAL_MALLOC_FAIL);
-                       GDKfree(len);
-                       for (j = first; j < i; j++)
-                               GDKfree(txt[j]);
-                       GDKfree(txt);
+                       //GDKfree(len);
+                       //for (j = first; j < i; j++)
+                       //      GDKfree(txt[j]);
+                       //GDKfree(txt);
                        return NULL;
                }
        }
-       ps = GDKmalloc(totlen + mb->stop + 1);
+       ps = ma_alloc(mb->ma, totlen + mb->stop + 1);
        if (ps == NULL) {
                addMalException(mb, "mal2str: " MAL_MALLOC_FAIL);
-               GDKfree(len);
-               for (i = first; i < last; i++)
-                       GDKfree(txt[i]);
-               GDKfree(txt);
+               //GDKfree(len);
+               //for (i = first; i < last; i++)
+               //      GDKfree(txt[i]);
+               //GDKfree(txt);
                return NULL;
        }
 
@@ -672,11 +672,11 @@ mal2str(MalBlkPtr mb, int first, int las
                        ps[totlen + len[i]] = '\n';
                        ps[totlen + len[i] + 1] = 0;
                        totlen += len[i] + 1;
-                       GDKfree(txt[i]);
+                       //GDKfree(txt[i]);
                }
        }
-       GDKfree(len);
-       GDKfree(txt);
+       //GDKfree(len);
+       //GDKfree(txt);
        return ps;
 }
 
@@ -691,7 +691,7 @@ printInstruction(stream *fd, MalBlkPtr m
        /* ps[strlen(ps)-1] = 0; remove '\n' */
        if (ps) {
                mnstr_printf(fd, "%s%s", (flg & LIST_MAL_MAPI ? "=" : ""), ps);
-               GDKfree(ps);
+               //GDKfree(ps);
        } else {
                mnstr_printf(fd, "#failed instruction2str()");
        }
@@ -708,7 +708,7 @@ traceInstruction(MalBlkPtr mb, MalStkPtr
                if (ps) {
                        TRC_DEBUG_ENDIF(MAL_OPTIMIZER, "%s%s\n",
                                                        (flg & LIST_MAL_MAPI ? 
"=" : ""), ps);
-                       GDKfree(ps);
+                       //GDKfree(ps);
                } else {
                        TRC_DEBUG_ENDIF(MAL_OPTIMIZER, "Failed 
instruction2str()\n");
                }
@@ -725,12 +725,13 @@ printSignature(stream *fd, Symbol s, int
                mnstr_printf(fd, "missing definition of %s\n", s->name);
                return;
        }
-       txt = GDKzalloc(MAXLISTING);    /* some slack for large blocks */
+       allocator *ma = s->def->ma;
+       txt = ma_zalloc(ma, MAXLISTING);        /* some slack for large blocks 
*/
        if (txt) {
                p = getSignature(s);
                (void) fcnDefinition(s->def, p, txt, flg, txt, MAXLISTING);
                mnstr_printf(fd, "%s\n", txt);
-               GDKfree(txt);
+               //GDKfree(txt);
        } else
                mnstr_printf(fd, "printSignature: " MAL_MALLOC_FAIL);
 }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -383,9 +383,9 @@ prepareMalEvent(Client cntxt, MalBlkPtr 
                                }
                                if (isaBatType(tpe)) {
                                        BAT *d = BATdescriptor(bid = 
stk->stk[getArg(pci, j)].val.bval);
-                                       tname = getTypeName(getBatType(tpe));
+                                       tname = getTypeName(mb->ma, 
getBatType(tpe));
                                        ok = logadd(&logbuf, 
",\"type\":\"bat[:%s]\"", tname);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to