Changeset: a366753c101f for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a366753c101f Modified Files: monetdb5/extras/mal_optimizer_template/opt_sql_append.c monetdb5/mal/Tests/tst060.malC monetdb5/mal/Tests/tst060.stable.out monetdb5/mal/mal_builder.c monetdb5/mal/mal_builder.h monetdb5/mal/mal_function.c monetdb5/mal/mal_instruction.c monetdb5/mal/mal_instruction.h monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_parser.c monetdb5/mal/mal_resolve.c monetdb5/mal/mal_session.c monetdb5/modules/mal/orderidx.c monetdb5/optimizer/opt_dataflow.c monetdb5/optimizer/opt_emptybind.c monetdb5/optimizer/opt_generator.c monetdb5/optimizer/opt_json.c monetdb5/optimizer/opt_matpack.c monetdb5/optimizer/opt_mergetable.c monetdb5/optimizer/opt_mitosis.c monetdb5/optimizer/opt_multiplex.c monetdb5/optimizer/opt_pushselect.c monetdb5/optimizer/opt_remap.c monetdb5/optimizer/opt_remoteQueries.c monetdb5/optimizer/opt_volcano.c sql/backends/monet5/sql_execute.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_statement.c Branch: malupgrade Log Message:
Simplifying the MAL allocation policy Reducing the side effects and pool management. New MAL instructions are not taken from the MAL block, but directly from GDKzalloc. PushInstruction should preferrably be done after all arguments has been collected in the structure. Otherwise, we may have to scan the complete block for the replacement position. Failure to allocate a MALinstruction or variable leads to GDKfatal. This means we can safely use the returns of the corresponding functions. diffs (truncated from 1540 to 300 lines): diff --git a/monetdb5/extras/mal_optimizer_template/opt_sql_append.c b/monetdb5/extras/mal_optimizer_template/opt_sql_append.c --- a/monetdb5/extras/mal_optimizer_template/opt_sql_append.c +++ b/monetdb5/extras/mal_optimizer_template/opt_sql_append.c @@ -180,7 +180,7 @@ OPTsql_appendImplementation(Client cntxt * setArgType(mb,q1,TYPE_lng) */ /* it will be added to the block and even my * re-use MAL instructions */ - q1 = newInstruction(mb,aggrRef,countRef); + q1 = newInstruction(aggrRef,countRef); getArg(q1,0) = newTmpVariable(mb, TYPE_lng); q1 = pushArgument(mb, q1, getArg(p, 5)); pushInstruction(mb, q1); @@ -189,7 +189,7 @@ OPTsql_appendImplementation(Client cntxt /* push new v2 := algebra.slice( v0, 0, v1 ); */ /* use mal_builder.h primitives * q1 = newStmt(mb, algebraRef,sliceRef); */ - q2 = newInstruction(mb,algebraRef, sliceRef); + q2 = newInstruction(algebraRef, sliceRef); getArg(q2,0) = newTmpVariable(mb, TYPE_any); q2 = pushArgument(mb, q2, getArg(p, 5)); q2 = pushLng(mb, q2, 0); @@ -199,7 +199,6 @@ OPTsql_appendImplementation(Client cntxt /* push modified v3 := sql.append( ..., ..., ..., ..., v2 ); */ getArg(p, 5) = getArg(q2, 0); pushInstruction(mb, p); - actions++; continue; } diff --git a/monetdb5/mal/Tests/tst060.malC b/monetdb5/mal/Tests/tst060.malC --- a/monetdb5/mal/Tests/tst060.malC +++ b/monetdb5/mal/Tests/tst060.malC @@ -1,11 +1,22 @@ -# garbage collection strins +# garbage collection strings +# +function tst(); + s0:= "hello"; + s0:= "world"; + b1:= s0 == "world"; + s1:= s0; +barrier b1; + s2:= s1; + s1:= "bye"; +exit b1; + io.print(s1); - s0:= "hello"; - s0:= "world"; - b1:= s0 == "world"; - s1:= s0; -barrier b1; - s2:= s1; - s1:= "bye"; -exit b1; - io.print(s1); + t:= "0"; +barrier i:=0; + t:= t + "0"; + redo i:= iterator.next(1,1000); +exit i; + io.print(t); +end tst; +tst(); + diff --git a/monetdb5/mal/Tests/tst060.stable.out b/monetdb5/mal/Tests/tst060.stable.out --- a/monetdb5/mal/Tests/tst060.stable.out +++ b/monetdb5/mal/Tests/tst060.stable.out @@ -29,6 +29,7 @@ Ready. # io.print(s1); [ "bye" ] +[ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000 ] # 07:58:48 > # 07:58:48 > Done. diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c --- a/monetdb5/mal/mal_builder.c +++ b/monetdb5/mal/mal_builder.c @@ -23,59 +23,41 @@ InstrPtr newAssignment(MalBlkPtr mb) { - InstrPtr q = newInstruction(mb,NULL,NULL); + InstrPtr q = newInstruction(NULL,NULL); - if (q == NULL) - return NULL; if ((getArg(q,0)= newTmpVariable(mb,TYPE_any)) < 0) { freeInstruction(q); return NULL; } pushInstruction(mb, q); - if (mb->errors) { - freeInstruction(q); - return NULL; - } return q; } InstrPtr newStmt(MalBlkPtr mb, const char *module, const char *name) { - InstrPtr q = newInstruction(mb, putName(module), putName(name)); + InstrPtr q = newInstruction(putName(module), putName(name)); - if (q == NULL) - return NULL; setDestVar(q, newTmpVariable(mb, TYPE_any)); if (getDestVar(q) < 0) { freeInstruction(q); return NULL; } pushInstruction(mb, q); - if (mb->errors) { - freeInstruction(q); - return NULL; - } return q; } InstrPtr newReturnStmt(MalBlkPtr mb) { - InstrPtr q = newInstruction(mb, NULL,NULL); + InstrPtr q = newInstruction(NULL,NULL); - if (q == NULL) - return NULL; if ((getArg(q,0)= newTmpVariable(mb,TYPE_any)) < 0) { freeInstruction(q); return NULL; } + q->barrier= RETURNsymbol; pushInstruction(mb, q); - if (mb->errors) { - freeInstruction(q); - return NULL; - } - q->barrier= RETURNsymbol; return q; } @@ -84,7 +66,7 @@ newFcnCall(MalBlkPtr mb, char *mod, char { InstrPtr q = newAssignment(mb); - if (q == NULL || mod == NULL || fcn == NULL) + if (mod == NULL || fcn == NULL) return NULL; setModuleId(q, putName(mod)); setFunctionId(q, putName(fcn)); @@ -94,11 +76,9 @@ newFcnCall(MalBlkPtr mb, char *mod, char InstrPtr newComment(MalBlkPtr mb, const char *val) { - InstrPtr q = newInstruction(mb, NULL,NULL); + InstrPtr q = newInstruction(NULL,NULL); ValRecord cst; - if (q == NULL) - return NULL; q->token = REMsymbol; q->barrier = 0; cst.vtype= TYPE_str; @@ -124,8 +104,6 @@ newCatchStmt(MalBlkPtr mb, str nme) InstrPtr q = newAssignment(mb); int i= findVariable(mb,nme); - if (q == NULL) - return NULL; q->barrier = CATCHsymbol; if ( i< 0) { if ((getArg(q,0)= newVariable(mb, nme, strlen(nme),TYPE_str)) < 0) { @@ -142,8 +120,6 @@ newRaiseStmt(MalBlkPtr mb, str nme) InstrPtr q = newAssignment(mb); int i= findVariable(mb,nme); - if (q == NULL) - return NULL; q->barrier = RAISEsymbol; if ( i< 0) { if ((getArg(q,0)= newVariable(mb, nme, strlen(nme),TYPE_str)) < 0) { @@ -161,8 +137,6 @@ newExitStmt(MalBlkPtr mb, str nme) InstrPtr q = newAssignment(mb); int i= findVariable(mb,nme); - if (q == NULL) - return NULL; q->barrier = EXITsymbol; if ( i< 0) { if ((getArg(q,0)= newVariable(mb, nme,strlen(nme),TYPE_str)) < 0) { @@ -174,6 +148,21 @@ newExitStmt(MalBlkPtr mb, str nme) return q; } +InstrPtr +pushEndInstruction(MalBlkPtr mb) +{ + InstrPtr p; + + p = newInstruction(NULL, NULL); + p->token = ENDsymbol; + p->barrier = 0; + p->argc = 0; + p->retc = 0; + p->argv[0] = 0; + pushInstruction(mb, p); + return p; +} + int getIntConstant(MalBlkPtr mb, int val) { diff --git a/monetdb5/mal/mal_builder.h b/monetdb5/mal/mal_builder.h --- a/monetdb5/mal/mal_builder.h +++ b/monetdb5/mal/mal_builder.h @@ -21,6 +21,7 @@ mal_export InstrPtr newExitStmt(MalBlkPt mal_export InstrPtr newReturnStmt(MalBlkPtr mb); mal_export InstrPtr newFcnCall(MalBlkPtr mb, char *mod, char *fcn); mal_export InstrPtr pushSht(MalBlkPtr mb, InstrPtr q, sht val); +mal_export InstrPtr pushEndInstruction(MalBlkPtr mb); mal_export InstrPtr pushInt(MalBlkPtr mb, InstrPtr q, int val); mal_export InstrPtr pushLng(MalBlkPtr mb, InstrPtr q, lng val); #ifdef HAVE_HGE 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 @@ -33,7 +33,7 @@ Symbol newFunction(str mod, str nme,int return NULL; } - p = newInstruction(NULL,mod,nme); + p = newInstruction(mod,nme); p->token = kind; p->barrier = 0; if (p == NULL) { 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 @@ -401,35 +401,28 @@ prepareMalBlk(MalBlkPtr mb, str s) trimexpand(mb, cnt, cnt); } +/* The MAL records should be managed from a pool to + * avoid repeated alloc/free and reduce probability of + * memory fragmentation. (todo) + * The complicating factor is their variable size, + * which leads to growing records as a result of pushArguments + * Allocation of an instruction should always succeed. + */ InstrPtr -newInstruction(MalBlkPtr mb, str modnme, str fcnnme) +newInstruction(str modnme, str fcnnme) { InstrPtr p = NULL; - if (mb && mb->stop < mb->ssize) { - p = mb->stmt[mb->stop]; - - if (p && p->maxarg < MAXARG) { - assert(0); - p = NULL; - } - mb->stmt[mb->stop] = NULL; + p = GDKzalloc(MAXARG * sizeof(p->argv[0]) + offsetof(InstrRecord, argv)); + if (p == NULL) { + showException(GDKout, MAL, "newEndInstruction", "memory allocation failure"); + GDKfatal("newEndInstruction memory allocation failure"); + return NULL; } - if (p == NULL) { - p = GDKzalloc(MAXARG * sizeof(p->argv[0]) + offsetof(InstrRecord, argv)); - if (p == NULL) { - showException(GDKout, MAL, "pushEndInstruction", "memory allocation failure"); - return NULL; - } - p->maxarg = MAXARG; - } + p->maxarg = MAXARG; p->typechk = TYPE_UNKNOWN; setModuleId(p, modnme); setFunctionId(p, fcnnme); - p->fcn = NULL; - p->blk = NULL; - p->polymorphic = 0; - p->varargs = 0; p->argc = 1; p->retc = 1; p->mitosis = -1; @@ -437,9 +430,6 @@ newInstruction(MalBlkPtr mb, str modnme, /* Flow of control instructions are always marked as an assignment * with modifier */ p->token = ASSIGNsymbol; - p->barrier = 0; - p->gc = 0; - p->jump = 0; return p; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list