Changeset: e6fe94ede0bd for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e6fe94ede0bd Modified Files: clients/Tests/exports.stable.out monetdb5/mal/mal_client.c monetdb5/mal/mal_debugger.c monetdb5/mal/mal_function.c monetdb5/mal/mal_instruction.h monetdb5/mal/mal_module.c monetdb5/mal/mal_module.h monetdb5/mal/mal_parser.c monetdb5/mal/mal_resolve.c monetdb5/mal/mal_session.c monetdb5/modules/mal/inspect.c monetdb5/modules/mal/manual.c monetdb5/optimizer/opt_macro.c sql/backends/monet5/sql_gencode.c Branch: default Log Message:
Cleanup of module structures All modules are defined global, unless named 'user'; The global modules are put on a chain and never removed. They are also indexed for speedy access by name. diffs (truncated from 764 to 300 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 @@ -2026,7 +2026,6 @@ void deleteSymbol(Module scope, Symbol p str deltaRef; str dense_rankRef; str depositRef; -void deriveModule(Module scope, str nme); malType destinationType(MalBlkPtr mb, InstrPtr p); str diffRef; str disconnectRef; @@ -2061,7 +2060,6 @@ void freeException(str); void freeInstruction(InstrPtr p); void freeMalBlk(MalBlkPtr mb); void freeModule(Module cur); -void freeModuleList(Module cur); void freeStack(MalStkPtr stk); void freeSymbol(Symbol s); void freeSymbolList(Symbol s); @@ -2096,6 +2094,7 @@ int getIntConstant(MalBlkPtr mb, int val int getLngConstant(MalBlkPtr mb, lng val); MalBlkPtr getMalBlkHistory(MalBlkPtr mb, int idx); lng getMemoryClaim(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int i, int flag); +Module getModuleChain(void); str getName(const char *nme); str getNameLen(const char *nme, size_t len); int getOidConstant(MalBlkPtr mb, oid val); @@ -2272,6 +2271,7 @@ int mnstr_writeInt_wrap(Stream *S, int * str mnstr_writeIntwrap(void *ret, Stream *S, int *data); int mnstr_write_string(Stream *S, str data); str mnstr_write_stringwrap(void *ret, Stream *S, str *data); +Module moduleIndex[256][256]; char monet_characteristics[PATHLENGTH]; char monet_cwd[PATHLENGTH]; size_t monet_memory; @@ -2426,7 +2426,6 @@ str setAccessRef; void setArgType(MalBlkPtr mb, InstrPtr p, int i, int tpe); InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid); void setHeartbeat(int delay); -void setModuleJump(str nme, Module cur); void setPolymorphic(InstrPtr p, int tpe, int force); void setReturnArgument(InstrPtr p, int varid); str setScenario(Client c, str nme); diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c --- a/monetdb5/mal/mal_client.c +++ b/monetdb5/mal/mal_client.c @@ -342,7 +342,6 @@ MCforkClient(Client father) /* reuse the scopes wherever possible */ if (son->nspace == 0) son->nspace = newModule(NULL, putName("child")); - son->nspace->outer = father->nspace->outer; } return son; } diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c --- a/monetdb5/mal/mal_debugger.c +++ b/monetdb5/mal/mal_debugger.c @@ -517,7 +517,7 @@ retryRead: continue; } for (i = 0; i < MAXSCOPE; i++) { - fs = fsym->subscope[i]; + fs = fsym->space[i]; while (fs != NULL) { printSignature(out, fs, 0); fs = fs->peer; @@ -525,13 +525,10 @@ retryRead: } continue; } else{ - Module s; - mnstr_printf(out,"#"); - for( s= cntxt->nspace; s; s= s->outer) { - mnstr_printf(out,"%s",s->name); - if( s->subscope==0) mnstr_printf(out,"?"); - if(s->outer) mnstr_printf(out,","); - } + Module m; + mnstr_printf(out,"#%s ",cntxt->nspace->name); + for( m = getModuleChain(); m; m = m->next) + mnstr_printf(out,"%s ",m->name); mnstr_printf(out,"\n"); } } @@ -586,7 +583,7 @@ retryRead: continue; } for (i = 0; i < MAXSCOPE; i++) { - fs = fsym->subscope[i]; + fs = fsym->space[i]; while (fs != NULL) { printStack(out, fs->def, 0); fs = fs->peer; @@ -603,7 +600,7 @@ retryRead: } /* display the overloaded symbol definition */ for (i = 0; i < MAXSCOPE; i++) { - fs = fsym->subscope[i]; + fs = fsym->space[i]; while (fs != NULL) { if (strcmp(fs->name, fcnname) == 0) printStack(out, fs->def, 0); @@ -874,7 +871,7 @@ retryRead: continue; } for (i = 0; i < MAXSCOPE; i++) { - fs = fsym->subscope[i]; + fs = fsym->space[i]; while (fs != NULL) { printFunction(out, fs->def, 0, lstng); fs = fs->peer; 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 @@ -54,9 +54,9 @@ Symbol getFunctionSymbol(Module scope, Module m; Symbol s; - for(m= findModule(scope,getModuleId(p)); m; m= m->outer) + for(m= findModule(scope,getModuleId(p)); m; m= m->link) if(idcmp(m->name, getModuleId(p))==0 ) { - s= m->subscope[(int)(getSubScope(getFunctionId(p)))]; + s= m->space[getSymbolIndex(getFunctionId(p))]; for(; s; s= s->peer) if( getSignature(s)->fcn == p->fcn) return s; @@ -358,14 +358,14 @@ insertSymbolBefore(Module scope, Symbol if (c) scope = c; } - t = getSubScope(getFunctionId(sig)); - assert(scope->subscope != NULL); - assert(scope->subscope[t] != NULL); - s = scope->subscope[t]; + t = getSymbolIndex(getFunctionId(sig)); + assert(scope->space != NULL); + assert(scope->space[t] != NULL); + s = scope->space[t]; prg->skip = before->skip; prg->peer = before; if (s == before) { - scope->subscope[t] = prg; + scope->space[t] = prg; } else { for (;;) { assert(s != NULL); diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h --- a/monetdb5/mal/mal_instruction.h +++ b/monetdb5/mal/mal_instruction.h @@ -22,9 +22,9 @@ #define DEBUG_MAL_INSTR /* #define DEBUG_REDUCE */ #define MAXARG 4 /* BEWARE the code depends on this knowledge */ -#define STMT_INCREMENT 512 +#define STMT_INCREMENT 256 #define MAL_VAR_WINDOW 32 -#define MAXVARS 512 /* >= STMT_INCREMENT */ +#define MAXVARS STMT_INCREMENT /* >= STMT_INCREMENT */ #define MAXLISTING 64*1024 /* Allocation of space assumes a rather exotic number of diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c --- a/monetdb5/mal/mal_module.c +++ b/monetdb5/mal/mal_module.c @@ -8,7 +8,6 @@ /* * (author) M. L. Kersten - * For documentation see website */ #include "monetdb_config.h" @@ -20,37 +19,47 @@ #include "mal_listing.h" #include "mal_private.h" -Module mal_scope; /* the root of the tree */ -Module scopeJump[256][256]; /* to speedup access to correct scope */ +// SHOULD BE PROTECTED WITH LOCKS +/* + * Definition of a new module may interfere with concurrent actions. + * A jump table is mainted to provide a quick start in the module + * table to find the correct one. + * + * All modules are persistent during a server session + */ +Module moduleIndex[256][256]; /* to speedup access to correct scope */ +Module moduleChain; /* keep the modules in a chain as well */ -static void newSubScope(Module scope){ - scope->subscope = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); +static void newModuleSpace(Module scope){ + scope->space = (Symbol *) GDKzalloc(MAXSCOPE * sizeof(Symbol)); +} + +Module +getModuleChain(void){ + return moduleChain; } void mal_module_reset(void) { - freeModuleList(mal_scope); - mal_scope = NULL; - memset((char*) scopeJump, 0, 256 * 256); -} -/* - * Definition of a new module scope may interfere with concurrent - * actions of multiple threads. This calls for a secure update - * of the scope tree structure. - * A jump table is mainted to provide a quick start in the module - * table to find the correct one. This simple scheme safes about - * 100ms/100K calls - */ + Module m,n; -static void clrModuleJump(str nme, Module cur){ - if( scopeJump[(int)(*nme)][(int)(*(nme+1))]== cur) - scopeJump[(int)(*nme)][(int)(*(nme+1))]= cur->sibling; + for( m = moduleChain; m; ){ + n = m->next; + freeModule(m); + m= n; + } + memset((char*) moduleIndex, 0, 256 * 256 * sizeof(Module)); } -void setModuleJump(str nme, Module cur){ - cur->sibling= scopeJump[(int)(*nme)][(int)(*(nme+1))]; - scopeJump[(int)(*nme)][(int)(*(nme+1))]= cur; +static void clrModuleIndex(str nme, Module cur){ + if( moduleIndex[(int)(*nme)][(int)(*(nme+1))]== cur) + moduleIndex[(int)(*nme)][(int)(*(nme+1))]= cur->link; +} + +static void setModuleIndex(str nme, Module cur){ + cur->link= moduleIndex[(int)(*nme)][(int)(*(nme+1))]; + moduleIndex[(int)(*nme)][(int)(*(nme+1))]= cur; } /* @@ -69,82 +78,61 @@ Module newModule(Module scope, str nme){ GDKerror("newModule:"MAL_MALLOC_FAIL); } else { cur->name = nme; - cur->outer = NULL; - cur->sibling = NULL; - cur->subscope = NULL; + cur->next = NULL; + cur->link = NULL; + cur->space = NULL; cur->isAtomModule = FALSE; } if ( cur == NULL) return scope; - newSubScope(cur); - if( scope != NULL){ - cur->outer = scope->outer; - scope->outer= cur; - setModuleJump(nme,cur); + newModuleSpace(cur); + // User modules are never global + if( strcmp(nme,"user")){ + setModuleIndex(nme,cur); + if ( moduleChain) + cur->next = moduleChain; + moduleChain = cur; } return cur; } /* - * The scope can be fixed. This is used by the parser to avoid creation of - * a string structure when possible. Subsequently we can - * replace the module name in the instructions to become a pointer - * to the scope directly. - * Reading a module often calls for opening a scope level - * if it didn't exist. + * The scope can be fixed. This is used by the parser. + * Reading a module often calls for creation first. */ Module fixModule(Module scope, str nme){ - Module s= scope; - if( scopeJump[(int)(*nme)][(int)(*(nme+1))]) - s= scopeJump[(int)(*nme)][(int)(*(nme+1))]; + Module s= 0; + + if( strcmp(nme,"user")==0) + return scope; + if( moduleIndex[(int)(*nme)][(int)(*(nme+1))]) + s= moduleIndex[(int)(*nme)][(int)(*(nme+1))]; while(s != NULL){ if( nme == s->name ) return s; - s= s->outer; + s= s->link; } return newModule(scope, nme); } /* _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list