⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opt_garbagecollector.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
字号:
#line 93 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"#include "mal_config.h"#include "opt_garbageCollector.h"#include "mal_interpreter.h"	/* for showErrors() */#include "mal_builder.h"#include "opt_prelude.h"#line 147 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"static intOPTgarbageCollectorImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	int i, j, k, limit, done;	InstrPtr p, q, *stmt;	VarPtr v;	Client cntxt = MCgetClient();	Module s = cntxt->nspace;	int top = 0, blk = 1, actions = 0;	str joinPathRef= putName("joinPath",8);	(void) pci;	(void) stk;		/* to fool compilers */	setLifespan(mb);	stmt = (InstrPtr *) GDKmalloc(mb->ssize * sizeof(InstrPtr));	memcpy(stmt, mb->stmt, mb->ssize * sizeof(InstrPtr));	memset((char*) mb->stmt,0, mb->ssize * sizeof(InstrPtr));	limit = mb->stop;	/* move to stable start */	mb->stop = 0;	for (i = 0; i < limit; i++) {		p = stmt[i];		pushInstruction(mb, p);		for (j = p->retc; j < p->argc; j++) {			v = getVar(mb, getArg(p, j));			if (v->endLifespan == i && isaBatType(getArgType(mb, p, j))) {				/* avoid duplicate releases */				done = 0;				for (k = j - 1; k >= p->retc; k--)					if (getArg(p, j) == getArg(p, k))						done++;				if (done == 0 ){#ifdef DEBUG_OPT_GARBAGE				printf("remove the variable %s at %d\n", getArgName(mb,p,j),i);#endif					if (getVarScope(mb, getArg(p, j)) == blk) {						/* All persistent BATs are adviced for unmapping.						  They are recognized at compiletime using the bid						   property set by e.g. the sqloptimizer						*//*	Activation of this code block drastically reduced the workingset	on TPCH, with a severe performance drop.						int *bid= (int*) getPropertyValue(v->props,"bid");						if(bid) 							#line 116 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"{	q= newInstruction(NULL,ASSIGNsymbol);	setModuleId(q,batRef);	setFunctionId(q,putName("flush",5));	pushArgument(mb,q,getArg(p,j));	getArg(q,0) = newTmpVariable(mb,TYPE_any);	pushInstruction(mb,q);	typeChecker(s,mb,q,TRUE);}#line 197 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"						else*/							#line 109 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"{	q= newInstruction(NULL,ASSIGNsymbol);	getArg(q,0) = getArg(p,j);	pushNil(mb,q, TYPE_bat);	pushInstruction(mb,q);	typeChecker(s,mb,q,TRUE);}#line 200 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"						actions++;					}				}			} else 			/* reduce the memory footprint  for non-target arguments */			if(getArg(p,0)!= j &&  isaBatType(getArgType(mb, p, j))) {				/* don't touch persistent (SQL) BATs */				int *bid= (int*) getPropertyValue(v->props,"bid");				if( !bid ){					if( getModuleId(p) == algebraRef  && 						( getFunctionId(p) == joinRef ||						  getFunctionId(p) == joinPathRef ||						  getFunctionId(p) == sortRef ||						  getFunctionId(p) == selectRef ||						  getFunctionId(p) == kdifferenceRef ||						  getFunctionId(p) == kunionRef ||						  getFunctionId(p) == semijoinRef ) )						#line 136 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"{	q= newInstruction(NULL,ASSIGNsymbol);	setModuleId(q,batRef);	setFunctionId(q,putName("reduce",6));	pushArgument(mb,q,getArg(p,j));	getArg(q,0) = getArg(p,j);	pushInstruction(mb,q);	typeChecker(s,mb,q,TRUE);	actions++;}#line 218 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"					if( getModuleId(p)== aggrRef)						#line 136 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"{	q= newInstruction(NULL,ASSIGNsymbol);	setModuleId(q,batRef);	setFunctionId(q,putName("reduce",6));	pushArgument(mb,q,getArg(p,j));	getArg(q,0) = getArg(p,j);	pushInstruction(mb,q);	typeChecker(s,mb,q,TRUE);	actions++;}#line 220 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"					if( getModuleId(p)== groupRef)						#line 136 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"{	q= newInstruction(NULL,ASSIGNsymbol);	setModuleId(q,batRef);	setFunctionId(q,putName("reduce",6));	pushArgument(mb,q,getArg(p,j));	getArg(q,0) = getArg(p,j);	pushInstruction(mb,q);	typeChecker(s,mb,q,TRUE);	actions++;}#line 222 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"				}			}			if (blockStart(p)) {				blk++;				if (top < MAXDEPTH - 2) {				} else {					mb->errors++;					showException(MAL,"optimizer.garbageCollector",							 "Too deeply nested MAL program");				}			}			if (blockExit(p))				if (top > 0) {					top--;				}		}	}#ifdef DEBUG_OPT_GARBAGE	{		stream_printf(GDKout, "Garbage collected BAT variables \n");		printFunction(GDKout, mb, LIST_MAL_ALL);		stream_printf(GDKout, "End of GCoptimizer\n");	}#endif	GDKfree(stmt);	return actions;}#line 256 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"#line 254 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTgarbageCollector(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){	str modnme;	str fcnnme;	Module  scope=NULL;	Symbol s= NULL;	lng clk= GDKusec();	int actions = 0;	optimizerInit();	if( p )		removeInstruction(mb, p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"apply garbageCollector\n");	printFunction(GDKout,mb,LIST_MAL_ALL);#endif	if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"locate function garbageCollector\n");#endif		if( getArgType(mb,p,1) != TYPE_str ||			getArgType(mb,p,2) != TYPE_str ||			!isConstant(mb,getArg(p,1)) ||			!isConstant(mb,getArg(p,2))		) {			char buf[1024];			snprintf(buf,1024, "Optimizer requires constant string arguments\n");			throw(MAL, "optimizer.garbageCollector",buf);		}		if( stk != 0){			modnme= (str)getArgValue(stk,p,1);			fcnnme= (str)getArgValue(stk,p,2);		} else {			modnme= getArgDefault(mb,p,1);			fcnnme= getArgDefault(mb,p,2);		}		scope = findModule(MCgetClient()->nspace,putName(modnme,strlen(modnme)) );		if( scope)			s= findSymbolInModule(scope,putName(fcnnme,strlen(fcnnme)));		if( s == NULL) {			char buf[1024];			snprintf(buf,1024, "Could not find %s.%s\n",modnme,fcnnme);			throw(MAL, "optimizer.garbageCollector",buf);		}#ifdef _DEBUG_OPTIMIZER_		stream_printf(GDKout,"garbageCollector %s %d\n",modnme,fcnnme);#endif		mb = s->def;		stk= 0;	} 	if( mb->errors )		return MAL_SUCCEED;	addtoMalBlkHistory(mb);	actions= OPTgarbageCollectorImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_	stream_printf(GDKout,"finished garbageCollector %d\n",actions);	printFunction(GDKout,mb,LIST_MAL_ALL);#endif    optimizerCheck(mb, "optimizer.garbageCollector", actions, GDKusec() - clk,OPT_CHECK_ALL);	return MAL_SUCCEED;}#line 256 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"#line 258 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_garbageCollector.mx"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -