LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_garbageCollector.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 29 93.1 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : #include "opt_garbageCollector.h"
      11             : #include "mal_interpreter.h"
      12             : #include "mal_builder.h"
      13             : #include "mal_function.h"
      14             : #include "opt_prelude.h"
      15             : 
      16             : /* The garbage collector is focused on removing temporary BATs only.
      17             :  * Leaving some garbage on the stack is an issue.
      18             :  *
      19             :  * The end-of-life of a BAT may lay within block bracket. This calls
      20             :  * for care, as the block may trigger a loop and then the BATs should
      21             :  * still be there.
      22             :  *
      23             :  * The life time of such BATs is forcefully terminated after the block exit.
      24             :  */
      25             : 
      26             : str
      27      356714 : OPTgarbageCollectorImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      28             : {
      29             :         int i, limit;
      30             :         InstrPtr p;
      31             :         int actions = 0;
      32             :         str msg = MAL_SUCCEED;
      33             : 
      34             :         (void) stk;
      35      356714 :         if ( mb->inlineProp)
      36           0 :                 goto wrapup;
      37             : 
      38      356714 :         limit = mb->stop;
      39             : 
      40             : 
      41             :         // move SQL query definition to the front for event profiling tools
      42             :         p = NULL;
      43     9357642 :         for(i = 0; i < limit; i++)
      44     9114097 :                 if(mb->stmt[i] && getModuleId(mb->stmt[i]) == querylogRef && getFunctionId(mb->stmt[i]) == defineRef ){
      45             :                         p = getInstrPtr(mb,i);
      46             :                         break;
      47             :                 }
      48             : 
      49      356714 :         if( p != NULL){
      50      113204 :                 for(  ; i > 1; i--)
      51          35 :                         mb->stmt[i] = mb->stmt[i-1];
      52      113169 :                 mb->stmt[1] = p;
      53             :                 actions = 1;
      54             :         }
      55             : 
      56             :         // Actual garbage collection stuff, just mark them for re-assessment
      57             :         p = NULL;
      58    12208763 :         for (i = 0; i < limit; i++) {
      59    12208763 :                 p = getInstrPtr(mb, i);
      60    12208763 :                 p->gc &=  ~GARBAGECONTROL;
      61    12208763 :                 p->typechk = TYPE_UNKNOWN;
      62             :                 /* Set the program counter to ease profiling */
      63    12208763 :                 p->pc = i;
      64    12208763 :                 if ( p->token == ENDsymbol)
      65             :                         break;
      66             :         }
      67             : 
      68             :         //mnstr_printf(cntxt->fdout,"garbacollector limit %d ssize %d vtop %d vsize %d\n", limit, (int)(mb->ssize), mb->vtop, (int)(mb->vsize));
      69             :         /* A good MAL plan should end with an END instruction */
      70      356714 :         if( p && p->token != ENDsymbol){
      71           0 :                 throw(MAL, "optimizer.garbagecollector", SQLSTATE(42000) "Incorrect MAL plan encountered");
      72             :         }
      73             :         /* move sanity check to other optimizer */
      74      356714 :         getInstrPtr(mb,0)->gc |= GARBAGECONTROL;
      75             : 
      76             :         /* leave a consistent scope admin behind */
      77      356714 :         setVariableScope(mb);
      78             :         /* Defense line against incorrect plans */
      79      356714 :         if( actions > 0){
      80             :                 if (!msg)
      81      113169 :                         msg = chkTypes(cntxt->usermodule, mb, FALSE);
      82      113169 :                 if (!msg)
      83      113169 :                         msg = chkFlow(mb);
      84      113169 :                 if (!msg)
      85      113169 :                         msg = chkDeclarations(mb);
      86             :         }
      87             :         /* keep all actions taken as a post block comment */
      88      243545 : wrapup:
      89             :         /* keep actions taken as a fake argument*/
      90      356714 :         (void) pushInt(mb, pci, actions);
      91      356713 :         return msg;
      92             : }

Generated by: LCOV version 1.14