Changeset: 817328b74e2f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=817328b74e2f
Modified Files:
        monetdb5/mal/Makefile.ag
        monetdb5/mal/mal_interpreter.mx
Branch: default
Log Message:

partial de-Mx mal_interpreter
Move the performance profiling to the runtime module.


diffs (truncated from 795 to 300 lines):

diff --git a/monetdb5/mal/Makefile.ag b/monetdb5/mal/Makefile.ag
--- a/monetdb5/mal/Makefile.ag
+++ b/monetdb5/mal/Makefile.ag
@@ -38,6 +38,7 @@ lib_mal = {
                mal_factory.c mal_factory.h \
                mal_function.c mal_function.h \
                mal_import.c mal_import.h \
+               mal_runtime.c mal_runtime.h \
                mal_instruction.c mal_instruction.h \
                mal_interpreter.mx \
                mal_linker.c mal_linker.h \
diff --git a/monetdb5/mal/mal_interpreter.mx b/monetdb5/mal/mal_interpreter.mx
--- a/monetdb5/mal/mal_interpreter.mx
+++ b/monetdb5/mal/mal_interpreter.mx
@@ -17,20 +17,6 @@ Copyright August 2008-2012 MonetDB B.V.
 All Rights Reserved.
 @
 
-@c
-/*
- * @a M. Kersten
- * @v 0.0
- * @* The MAL Interpreter
- * The MAL interpreter always works in the context of a single user session,
- * which provides for storage access to global variables and modules.
- * @menu
- * * MAL API::
- * * Exception Handling::
- * * Garbage Collection::
- * * Stack Management::
- * @end menu
- */
 @h
 #ifndef _MAL_INTERPRET_H
 #define _MAL_INTERPRET_H
@@ -66,7 +52,14 @@ mal_export lng getVolume(MalStkPtr stk, 
 mal_export ptr getArgReference(MalStkPtr stk, InstrPtr pci, int k);
 
 @c
+/*
+ * Author M. Kersten
+ * The MAL Interpreter
+ * The MAL interpreter always works in the context of a single user session,
+ * which provides for storage access to global variables and modules.
+ */
 #include "monetdb_config.h"
+#include "mal_runtime.h"
 #include "mal_interpreter.h"
 #include "mal_listing.h"
 #include "mal_debugger.h"   /* for mdbStep() */
@@ -77,7 +70,6 @@ mal_export ptr getArgReference(MalStkPtr
 #define FAST 1
 
 static str runMALsequence(Client cntxt, MalBlkPtr mb, int startpc, int stoppc, 
MalStkPtr stk, MalStkPtr env, InstrPtr pcicaller);
-static void displayVolume(Client cntxt, lng vol);
 
 #define USE_DFLOW_ADMISSION
 /* does not seem to have a major impact */
@@ -191,22 +183,21 @@ updateBigFoot(Client cntxt, int bid, int
  * Also we cannot overwrite values on the stack as this maybe part of a
  * sequence of factory calls.
  */
-@= initStack
-       for (i = @1; i < mb->vtop; i++) {
-               lhs = &stk->stk[i];
-               if (isVarConstant(mb, i) > 0) {
-                       if (!isVarDisabled(mb, i)) {
-                               rhs = &getVarConstant(mb, i);
-                               VALcopy(lhs, rhs);
-                       }
-               } else {
-                       lhs->vtype = getVarGDKType(mb, i);
-                       lhs->val.pval = 0;
-                       lhs->len = 0;
-               }
-       }
-@
-@c
+#define initStack(S)\
+       for (i = S; i < mb->vtop; i++) {\
+               lhs = &stk->stk[i];\
+               if (isVarConstant(mb, i) > 0) {\
+                       if (!isVarDisabled(mb, i)) {\
+                               rhs = &getVarConstant(mb, i);\
+                               VALcopy(lhs, rhs);\
+                       }\
+               } else {\
+                       lhs->vtype = getVarGDKType(mb, i);\
+                       lhs->val.pval = 0;\
+                       lhs->len = 0;\
+               }\
+       }\
+
 static int
 isNotUsedIn(InstrPtr p, int start, int a)
 {
@@ -231,7 +222,7 @@ prepareMALstack(MalBlkPtr mb, int size)
        stk->stksize = size;
        stk->blk = mb;
 
-       @:initStack(0)@
+       initStack(0);
        return stk;
 }
 
@@ -243,8 +234,9 @@ str runMAL(Client cntxt, MalBlkPtr mb, i
        ValPtr lhs, rhs;
        InstrPtr pci = getInstrPtr(mb, 0);
        str ret;
-       @:performanceVariables@
+       RuntimeProfileRecord runtimeProfile;
 
+       runtimeProfileInit(mb, &runtimeProfile);
        if (mb->errors) {
                showErrors(cntxt);
                if (cntxt->itrace == 0) /* permit debugger analysis */
@@ -271,7 +263,7 @@ str runMAL(Client cntxt, MalBlkPtr mb, i
                if (mb->vtop > stk->stksize)
                        showScriptException(cntxt->fdout, mb, 0, MAL, "stack 
too small\n");
                pci = pcicaller;
-               @:initStack(env->stkbot)@
+               initStack(env->stkbot);
        } else {
                stk = prepareMALstack(mb, mb->vsize);
                if (stk == 0)
@@ -339,7 +331,8 @@ str runMAL(Client cntxt, MalBlkPtr mb, i
                env->cmd = stk->cmd;
        if (!stk->keepAlive && garbageControl(getInstrPtr(mb, 0)))
                garbageCollector(cntxt, mb, stk, env != stk);
-       @:endProfile(stk) @
+       if (cntxt->qtimeout && time(NULL) - stk->clock.tv_usec > 
cntxt->qtimeout)
+               throw(MAL, "mal.interpreter", RUNTIME_QRY_TIMEOUT);
        if (stk && stk != env)
                GDKfree(stk);
        return ret;
@@ -392,8 +385,9 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
        int i;
        ValPtr lhs;
        InstrPtr pci = getInstrPtr(mb, 0);
-       @:performanceVariables@
+       RuntimeProfileRecord runtimeProfile;
 
+       runtimeProfileInit(mb, &runtimeProfile);
 #ifdef DEBUG_CALLMAL
        mnstr_printf(cntxt->fdout, "callMAL\n");
        printInstruction(cntxt->fdout, mb, 0, pci, LIST_MAL_ALL);
@@ -431,7 +425,8 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
        default:
                throw(MAL, "mal.interpreter", RUNTIME_UNKNOWN_INSTRUCTION);
        }
-       @:endProfile(stk)@
+       if (cntxt->qtimeout && time(NULL) - stk->clock.tv_usec > 
cntxt->qtimeout)
+               throw(MAL, "mal.interpreter", RUNTIME_QRY_TIMEOUT);
        return ret;
 }
 /*
@@ -452,28 +447,21 @@ str runMALsequence(Client cntxt, MalBlkP
        ValPtr backup = GDKzalloc(mb->maxarg * sizeof(ValRecord));
        int *garbage = (int*)GDKzalloc(mb->maxarg * sizeof(int));
        lng oldtimer = 0;
-       struct Mallinfo oldMemory;
        int stkpc = 0;
        MT_Lock *lock = NULL;
        int tid = 0;
+       RuntimeProfileRecord runtimeProfile;
 
-#ifdef HAVE_SYS_RESOURCE_H
-       int oldinblock = 0;
-       int oldoublock = 0;
-       struct rusage oldResource;
-#endif
-       @:performanceVariables@
-
+       runtimeProfileInit(mb, &runtimeProfile);
        if (stk == NULL)
                throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
        if (cntxt->flags & timerFlag)
                oldtimer = cntxt->timer = GDKusec();
-       oldMemory.arena = 0;
 
        /* also produce event record for start of function */
        if ( startpc == 1 ) {
                stkpc = 0;
-               @:beginProfile(stk,1)@
+               runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 1);
        }
        stkpc = startpc;
        exceptionVar = -1;
@@ -494,7 +482,9 @@ str runMALsequence(Client cntxt, MalBlkP
                        if (malProfileMode + cntxt->itrace)
                                goto workslow;
 
-                               @:MALrecycleStart(stk)@ {
+                       if (pci->recycle > 0)
+                               stk->clk = GDKusec();
+                       if (!RECYCLEentry(cntxt, mb, stk, pci)){
                                @:MALinterpret(FAST)@
                        }
                        @:MALflowofcontrol(FAST,continue)@
@@ -532,20 +522,19 @@ workslow:
                                        /* ignore debugger waiting time*/
                                        t = GDKusec() - t;
                                        oldtimer += t;
-#ifdef HAVE_SYS_RESOURCE_H
-                                       getrusage(RUSAGE_SELF, &oldResource);
-#endif
-                                       if (cntxt->flags & memoryFlag)
-                                               oldMemory = MT_mallinfo();
                                }
                        }
 
-                       @:beginProfile(stk,1)@
-                       @:MALrecycleStart(stk)@ {
+                       runtimeProfileBegin(cntxt, mb, stk, stkpc, 
&runtimeProfile, 1);
+                       if (pci->recycle > 0)
+                               stk->clk = GDKusec();
+                       if (!RECYCLEentry(cntxt, mb, stk, pci)){
                                @:MALinterpret(SLOW)@
                        }
                        @:MALflowofcontrol(SLOW,continue)@
-                       @:endProfile(stk)@
+                       runtimeProfileExit(cntxt, mb, stk, stkpc, 
&runtimeProfile);
+                       if (cntxt->qtimeout && time(NULL) - stk->clock.tv_usec 
> cntxt->qtimeout)
+                               throw(MAL, "mal.interpreter", 
RUNTIME_QRY_TIMEOUT);
                }
        }
        if (exceptionVar >= 0) {
@@ -953,21 +942,11 @@ DFLOWstep(FlowTask *t, FlowStatus fs)
        int startpc = fs->pc;
        InstrPtr pci;
        lng oldtimer = 0;
-       struct Mallinfo oldMemory;
        MT_Lock *lock = &flow->done->l;
        int tid = t->id, prevpc = 0;
+       RuntimeProfileRecord runtimeProfile;
 
-#ifdef HAVE_SYS_RESOURCE_H
-       int oldinblock = 0;
-       int oldoublock = 0;
-       struct rusage oldResource;
-#endif
-       @:performanceVariables@
-
-       if (cntxt->flags & memoryFlag)
-               oldMemory = MT_mallinfo();
-       else
-               oldMemory.arena = 0;
+       runtimeProfileInit(mb, &runtimeProfile);
        if (stk == NULL || stkpc < 0)
                throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
 
@@ -996,39 +975,36 @@ DFLOWstep(FlowTask *t, FlowStatus fs)
                        /* ignore debugger waiting time*/
                        tm = GDKusec() - tm;
                        oldtimer += tm;
-#ifdef HAVE_SYS_RESOURCE_H
-                       getrusage(RUSAGE_SELF, &oldResource);
-#endif
-                       if (cntxt->flags & memoryFlag)
-                               oldMemory = MT_mallinfo();
                }
        }
 
-       @:beginProfile(t,0)@
+       runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 0);
        FREE_EXCEPTION(ret);
        ret = MAL_SUCCEED;
-       @:MALrecycleStart(t)@ {
-               @:beginProfile(t,1)@
+       if (pci->recycle > 0)
+               t->clk = GDKusec();
+       if (!RECYCLEentry(cntxt, mb, stk, pci)){
+               runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 1);
                /*
                 * @-
                 * The number of instructions allowed is severely limited.
                 * We don't allow sequential flow control here, which is 
enforced by the dataflow optimizer;
                 */
                switch (pci->token) {
-               case ASSIGNsymbol: 
-                       @:assignStmt(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@ 
+               case ASSIGNsymbol:
+                       @:assignStmt(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@
                        break;
-               case PATcall: 
-                       @:patterncall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@ 
+               case PATcall:
+                       @:patterncall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@
                        break;
-               case CMDcall: 
-                       @:commandcall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@ 
+               case CMDcall:
+                       @:commandcall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@
                        break;
-               case FACcall: 
-                       @:factorycall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@ 
+               case FACcall:
+                       @:factorycall(FAST,fs->pc = -fs->pc; GDKfree(backup); 
GDKfree(garbage); return ret,t)@
                        break;
-               case FCNcall: 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to