Changeset: c933deb2964c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c933deb2964c Modified Files: monetdb5/mal/mal_instruction.c monetdb5/mal/mal_parser.c monetdb5/optimizer/opt_emptybind.c Branch: resource_management Log Message:
use temp allocator in emptybind optimizer further propagate extended freeInstructionX api diffs (270 lines): 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 @@ -201,7 +201,8 @@ resetMalBlk(MalBlkPtr mb) int i; for (i = 1/*MALCHUNK*/; i < mb->ssize; i++) { - //freeInstruction(mb->stmt[i]); + // ss + freeInstructionX(mb->stmt[i], mb); mb->stmt[i] = NULL; } #if 0 @@ -420,6 +421,7 @@ newInstructionArgs(MalBlkPtr mb, const c /* Flow of control instructions are always marked as an assignment * with modifier */ .token = ASSIGNsymbol, + .blk = NULL, }; memset(p->argv, 0, args * sizeof(p->argv[0])); p->argv[0] = -1; @@ -475,10 +477,9 @@ clrInstruction(InstrPtr p) void freeInstruction(InstrPtr p) { - MalBlkPtr mb_ptr = p->blk; - if (mb_ptr && mb_ptr->ma) { + if (p && p->blk && p->blk->ma) { size_t sz = (p->maxarg - 1)*(sizeof(p->argv[0])) + (sizeof(InstrRecord)); - sa_free(mb_ptr->ma, p, sz); + sa_free(p->blk->ma, p, sz); } //GDKfree(p); } @@ -486,10 +487,9 @@ freeInstruction(InstrPtr p) void freeInstructionX(InstrPtr p, MalBlkPtr mb) { - MalBlkPtr mb_ptr = (mb != NULL) ? mb : p->blk; - if (mb_ptr && mb_ptr->ma) { + if (p && mb && mb->ma) { size_t sz = (p->maxarg - 1)*(sizeof(p->argv[0])) + (sizeof(InstrRecord)); - sa_free(mb_ptr->ma, p, sz); + sa_free(mb->ma, p, sz); } } @@ -1163,18 +1163,18 @@ pushInstruction(MalBlkPtr mb, InstrPtr p for (i = 1; i < mb->stop; i++) { q = getInstrPtr(mb, i); if (q->token == REMsymbol) { - freeInstruction(q); + freeInstructionX(q, mb); mb->stmt[i] = p; return; } } - freeInstruction(getInstrPtr(mb, 0)); + freeInstructionX(getInstrPtr(mb, 0), mb); mb->stmt[0] = p; return; } } if (mb->stmt[mb->stop]) - freeInstruction(mb->stmt[mb->stop]); + freeInstructionX(mb->stmt[mb->stop], mb); p->pc = mb->stop; mb->stmt[mb->stop++] = p; } diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c --- a/monetdb5/mal/mal_parser.c +++ b/monetdb5/mal/mal_parser.c @@ -2040,10 +2040,10 @@ parseAssign(Client cntxt, int cntrl) i = cstToken(cntxt, curBlk, &cst); if (l == 0 || i) { parseError(cntxt, "<identifier> or <literal> expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } - GETvariable(freeInstruction(curInstr)); + GETvariable(freeInstructionX(curInstr, curBlk)); if (currChar(cntxt) == ':') { type = typeElm(cntxt, getVarType(curBlk, varid)); if (type < 0) @@ -2079,7 +2079,7 @@ parseAssign(Client cntxt, int cntrl) cntrl == RETURNsymbol || cntrl == EXITsymbol) { curInstr->argv[0] = getBarrierEnvelop(curBlk); if (currChar(cntxt) != ';') { - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); parseError(cntxt, "<identifier> or <literal> expected in control statement\n"); return; @@ -2088,7 +2088,7 @@ parseAssign(Client cntxt, int cntrl) return; } getArg(curInstr, 0) = newTmpVariable(curBlk, TYPE_any); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); parseError(cntxt, "<identifier> or <literal> expected\n"); return; } @@ -2099,7 +2099,7 @@ parseAssign(Client cntxt, int cntrl) } /* Get target variable details */ - GETvariable(freeInstruction(curInstr)); + GETvariable(freeInstructionX(curInstr, curBlk)); if (!(currChar(cntxt) == ':' && CURRENT(cntxt)[1] == '=')) { curInstr->argv[0] = varid; if (currChar(cntxt) == ':') { @@ -2154,7 +2154,7 @@ parseAssign(Client cntxt, int cntrl) arg = putNameLen(CURRENT(cntxt), l); if (arg == NULL) { parseError(cntxt, SQLSTATE(HY013) MAL_MALLOC_FAIL); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } advance(cntxt, l + 1); /* skip '.' too */ @@ -2167,19 +2167,19 @@ parseAssign(Client cntxt, int cntrl) setFunctionId(curInstr, putNameLen(((char *) CURRENT(cntxt)), i)); if (getFunctionId(curInstr) == NULL) { parseError(cntxt, SQLSTATE(HY013) MAL_MALLOC_FAIL); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } advance(cntxt, i); } else { parseError(cntxt, "<functionname> expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } skipSpace(cntxt); if (currChar(cntxt) != '(') { parseError(cntxt, "'(' expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } advance(cntxt, 1); @@ -2205,19 +2205,19 @@ parseAssign(Client cntxt, int cntrl) setFunctionId(curInstr, putNameLen(((char *) CURRENT(cntxt)), i)); if (getFunctionId(curInstr) == NULL) { parseError(cntxt, SQLSTATE(HY013) MAL_MALLOC_FAIL); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } advance(cntxt, i); curInstr->modname = putName("calc"); if (curInstr->modname == NULL) { parseError(cntxt, SQLSTATE(HY013) MAL_MALLOC_FAIL); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } if ((l = idLength(cntxt)) && !(l == 3 && strncmp(CURRENT(cntxt), "nil", 3) == 0)) { - GETvariable(freeInstruction(curInstr)); + GETvariable(freeInstructionX(curInstr, curBlk)); curInstr = pushArgument(curBlk, curInstr, varid); goto part3; } @@ -2228,17 +2228,17 @@ parseAssign(Client cntxt, int cntrl) goto part3; } parseError(cntxt, "<term> expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } else { skipSpace(cntxt); if (currChar(cntxt) == '(') { parseError(cntxt, "module name missing\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } else if (currChar(cntxt) != ';' && currChar(cntxt) != '#') { parseError(cntxt, "operator expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } pushInstruction(curBlk, curInstr); @@ -2249,14 +2249,14 @@ parseAssign(Client cntxt, int cntrl) if (currChar(cntxt) != ';') { parseError(cntxt, "';' expected\n"); skipToEnd(cntxt); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } skipToEnd(cntxt); if (cntrl == RETURNsymbol && !(curInstr->token == ASSIGNsymbol || getModuleId(curInstr) != 0)) { parseError(cntxt, "return assignment expected\n"); - freeInstruction(curInstr); + freeInstructionX(curInstr, curBlk); return; } pushInstruction(curBlk, curInstr); diff --git a/monetdb5/optimizer/opt_emptybind.c b/monetdb5/optimizer/opt_emptybind.c --- a/monetdb5/optimizer/opt_emptybind.c +++ b/monetdb5/optimizer/opt_emptybind.c @@ -68,20 +68,26 @@ OPTemptybindImplementation(Client cntxt, } // track of where 'emptybind' results are produced // reserve space for maximal number of emptybat variables created - empty = (int *) GDKzalloc((mb->vsize + extras) * sizeof(int)); + // empty = (int *) GDKzalloc((mb->vsize + extras) * sizeof(int)); + ma_open(cntxt->ta); + empty = (int *) ma_zalloc(cntxt->ta, (mb->vsize + extras) * sizeof(int)); if (empty == NULL) throw(MAL, "optimizer.emptybind", SQLSTATE(HY013) MAL_MALLOC_FAIL); - updated = (InstrPtr *) GDKzalloc(esize * sizeof(InstrPtr)); + // updated = (InstrPtr *) GDKzalloc(esize * sizeof(InstrPtr)); + size_t updated_size = esize * sizeof(InstrPtr); + updated = (InstrPtr *) ma_zalloc(cntxt->ta, updated_size); if (updated == 0) { - GDKfree(empty); + // GDKfree(empty); + ma_close(cntxt->ta); throw(MAL, "optimizer.emptybind", SQLSTATE(HY013) MAL_MALLOC_FAIL); } old = mb->stmt; if (newMalBlkStmt(mb, mb->ssize) < 0) { - GDKfree(empty); - GDKfree(updated); + // GDKfree(empty); + // GDKfree(updated); + ma_close(cntxt->ta); throw(MAL, "optimizer.emptybind", SQLSTATE(HY013) MAL_MALLOC_FAIL); } @@ -110,10 +116,14 @@ OPTemptybindImplementation(Client cntxt, if (getModuleId(p) == sqlRef && isUpdateInstruction(p)) { if (etop == esize) { InstrPtr *tmp = updated; - updated = GDKrealloc(updated, - (esize += 256) * sizeof(InstrPtr)); + //updated = GDKrealloc(updated, + // (esize += 256) * sizeof(InstrPtr)); + size_t old_size = updated_size; + updated = MA_RENEW_ARRAY(cntxt->ta, InstrPtr, updated, + (esize += 256) * sizeof(InstrPtr), old_size); if (updated == NULL) { - GDKfree(tmp); + // GDKfree(tmp); + updated = tmp; msg = createException(MAL, "optimizer.emptybind", SQLSTATE(HY013) MAL_MALLOC_FAIL); goto wrapup; @@ -289,8 +299,9 @@ OPTemptybindImplementation(Client cntxt, if (old[i]) pushInstruction(mb, old[i]); //GDKfree(old); - GDKfree(empty); - GDKfree(updated); + // GDKfree(empty); + // GDKfree(updated); + ma_close(cntxt->ta); /* Defense line against incorrect plans */ if (msg == MAL_SUCCEED) msg = chkTypes(cntxt->usermodule, mb, FALSE); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org