From cf728bc77e1140db593da27850a194003a631eaa Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 2 Oct 2007 23:41:27 +0000 Subject: [PATCH] fix optional arguments...lots of changes --- .../TaskStateAnalysis/FlagComparator.java | 30 + .../TaskStateAnalysis/SafetyAnalysis.java | 14 +- .../Analysis/TaskStateAnalysis/TaskIndex.java | 7 + Robust/src/IR/Flat/BuildCode.java | 411 +++--- Robust/src/IR/State.java | 26 +- Robust/src/Main/Main.java | 5 +- Robust/src/Makefile | 3 +- Robust/src/Runtime/DSTM/docs/prefetch | 5 +- Robust/src/Runtime/ObjectHash.c | 42 +- Robust/src/Runtime/ObjectHash.h | 12 +- Robust/src/Runtime/runtime.c | 19 +- Robust/src/Runtime/runtime.h | 28 +- Robust/src/Runtime/task.c | 1235 ++++++++++------- 13 files changed, 1131 insertions(+), 706 deletions(-) create mode 100644 Robust/src/Analysis/TaskStateAnalysis/FlagComparator.java diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagComparator.java b/Robust/src/Analysis/TaskStateAnalysis/FlagComparator.java new file mode 100644 index 00000000..1519d975 --- /dev/null +++ b/Robust/src/Analysis/TaskStateAnalysis/FlagComparator.java @@ -0,0 +1,30 @@ +package Analysis.TaskStateAnalysis; +import java.util.Hashtable; +import java.util.Comparator; +import java.util.Iterator; +import IR.FlagDescriptor; + +/**Note: this comparator imposes orderings that are inconsistent with equals.*/ + +public class FlagComparator implements Comparator { + Hashtable flaginfo; + public FlagComparator(Hashtable flaginfo) { + this.flaginfo=flaginfo; + } + + public int compare(Object o1, Object o2) { + int fs1=getFlagInt((FlagState)o1); + int fs2=getFlagInt((FlagState)o2); + return fs1-fs2; + } + + public int getFlagInt(FlagState fs) { + int flagid=0; + for(Iterator flags = fs.getFlags(); flags.hasNext();){ + FlagDescriptor flagd = (FlagDescriptor)flags.next(); + int id=1<<((Integer)flaginfo.get(flagd)).intValue(); + flagid|=id; + } + return flagid; + } +} diff --git a/Robust/src/Analysis/TaskStateAnalysis/SafetyAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/SafetyAnalysis.java index ffb118ff..f1cbdb21 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/SafetyAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/SafetyAnalysis.java @@ -15,10 +15,10 @@ public class SafetyAnalysis { private State state; private TaskAnalysis taskanalysis; private Hashtable> optionaltaskdescriptors; + private Hashtable>> fstotimap; private ClassDescriptor processedclass; - public Hashtable>> getResult() { return safeexecution; } @@ -39,6 +39,7 @@ public class SafetyAnalysis { this.state = state; this.taskanalysis = taskanalysis; this.optionaltaskdescriptors = new Hashtable(); + this.fstotimap=new Hashtable>>(); } /* Builds map of fs -> EGTasknodes that can fire on fs for class cd */ @@ -56,6 +57,16 @@ public class SafetyAnalysis { return table; } + + public Set getOptions(FlagState fs, TaskDescriptor td, int index) { + return fstotimap.get(fs).get(new TaskIndex(td, index)); + } + + public Set getTaskIndex(FlagState fs) { + return fstotimap.get(fs).keySet(); + } + + /* Builds map of fs -> set of fs that depend on this fs */ private Hashtable> buildUseMap(ClassDescriptor cd) { @@ -182,6 +193,7 @@ public class SafetyAnalysis { tovisit.addAll(fsusemap.get(fs)); } } + fstotimap.put(fs, timap); } private HashSet createIntersection(Set A, Set B, ClassDescriptor cd){ diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskIndex.java b/Robust/src/Analysis/TaskStateAnalysis/TaskIndex.java index a87f31c6..02b64190 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskIndex.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskIndex.java @@ -21,4 +21,11 @@ public class TaskIndex { } return false; } + + public TaskDescriptor getTask() { + return td; + } + public int getIndex() { + return index; + } } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 3d97da60..2d8db249 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -8,8 +8,11 @@ import java.util.*; import java.io.*; import Util.Relation; import Analysis.TaskStateAnalysis.FlagState; +import Analysis.TaskStateAnalysis.FlagComparator; import Analysis.TaskStateAnalysis.OptionalTaskDescriptor; import Analysis.TaskStateAnalysis.Predicate; +import Analysis.TaskStateAnalysis.SafetyAnalysis; +import Analysis.TaskStateAnalysis.TaskIndex; import Analysis.Locality.LocalityAnalysis; import Analysis.Locality.LocalityBinding; @@ -38,12 +41,18 @@ public class BuildCode { LocalityAnalysis locality; Hashtable backuptable; Hashtable reverttable; + SafetyAnalysis sa; - public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) { - this(st, temptovar, typeutil, null); + public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa) { + this(st, temptovar, typeutil, null, sa); } public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) { + this(st, temptovar, typeutil, locality, null); + } + + public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa) { + this.sa=sa; state=st; this.temptovar=temptovar; paramstable=new Hashtable(); @@ -405,8 +414,8 @@ public class BuildCode { outclassdefs.println(" int flag;"); outclassdefs.println(" void * flagptr;"); if(state.OPTIONAL){ - outclassdefs.println(" int numexitfses;"); - outclassdefs.println(" int * exitfses;"); + outclassdefs.println(" int numfses;"); + outclassdefs.println(" int * fses;"); } } printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs); @@ -980,12 +989,8 @@ public class BuildCode { classdefout.println(" int flag;"); classdefout.println(" void * flagptr;"); if (state.OPTIONAL){ - classdefout.println(" int failedstatus;"); - classdefout.println(" int hashcode;"); - classdefout.println(" int numexitfses;"); - classdefout.println(" int * exitfses;"); - classdefout.println(" int numotds;"); - classdefout.println(" struct optionaltaskdescriptor ** otds;"); + classdefout.println(" int numfses;"); + classdefout.println(" int * fses;"); } } printClassStruct(cn, classdefout); @@ -2067,16 +2072,13 @@ public class BuildCode { } } - void generateOptionalArrays(PrintWriter output, PrintWriter headers, Hashtable> safeexecution, Hashtable optionaltaskdescriptors) { - + void generateOptionalHeader(PrintWriter headers) { + //GENERATE HEADERS headers.println("#include \"task.h\"\n\n"); headers.println("#ifndef _OPTIONAL_STRUCT_"); headers.println("#define _OPTIONAL_STRUCT_"); - - - //STRUCT PREDICATEMEMBER headers.println("struct predicatemember{"); headers.println("int type;"); @@ -2085,28 +2087,30 @@ public class BuildCode { headers.println("int numtags;"); headers.println("int * tags;\n};\n\n"); - /*//STRUCT EXITSTATES - headers.println("struct exitstates{"); - headers.println("int numflagstates;"); - headers.println("int * flagstatearray;\n};\n\n");*///appeared to be useless - //STRUCT OPTIONALTASKDESCRIPTOR headers.println("struct optionaltaskdescriptor{"); headers.println("struct taskdescriptor * task;"); + headers.println("int index;"); headers.println("int numenterflags;"); headers.println("int * enterflags;"); headers.println("int numpredicatemembers;"); headers.println("struct predicatemember ** predicatememberarray;"); - //headers.println("int numexitstates;"); - //headers.println("int numTotal;"); - //headers.println("struct exitstates ** exitstatesarray;\n};\n\n"); - headers.println("\n};\n\n"); - + headers.println("};\n\n"); + + //STRUCT TASKFAILURE + headers.println("struct taskfailure {"); + headers.println("struct taskdescriptor * task;"); + headers.println("int index;"); + headers.println("int numoptionaltaskdescriptors;"); + headers.println("struct optionaltaskdescriptor ** optionaltaskdescriptorarray;\n};\n\n"); + //STRUCT FSANALYSISWRAPPER headers.println("struct fsanalysiswrapper{"); headers.println("int flags;"); headers.println("int numtags;"); headers.println("int * tags;"); + headers.println("int numtaskfailures;"); + headers.println("struct taskfailure ** taskfailurearray;"); headers.println("int numoptionaltaskdescriptors;"); headers.println("struct optionaltaskdescriptor ** optionaltaskdescriptorarray;\n};\n\n"); @@ -2126,12 +2130,104 @@ public class BuildCode { headers.println("extern struct taskdescriptor task_"+td.getSafeSymbol()+";"); } - + } + + int generateOptionalPredicate(Predicate predicate, OptionalTaskDescriptor otd, ClassDescriptor cdtemp, PrintWriter output) { + int predicateindex = 0; + //iterate through the classes concerned by the predicate + Set c_vard = predicate.vardescriptors; + Hashtable slotnumber=new Hashtable(); + int current_slot=0; + + for(Iterator vard_it = c_vard.iterator(); vard_it.hasNext();){ + VarDescriptor vard = (VarDescriptor)vard_it.next(); + TypeDescriptor typed = vard.getType(); + + //generate for flags + HashSet fen_hashset = predicate.flags.get(vard.getSymbol()); + output.println("int predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={"); + int numberterms=0; + if (fen_hashset!=null){ + for (Iterator fen_it = fen_hashset.iterator(); fen_it.hasNext();){ + FlagExpressionNode fen = (FlagExpressionNode)fen_it.next(); + if (fen!=null) { + DNFFlag dflag=fen.getDNF(); + numberterms+=dflag.size(); + + Hashtable flags=(Hashtable)flagorder.get(typed.getClassDesc()); + + for(int j=0;j>> safeexecution, Hashtable optionaltaskdescriptors) { + generateOptionalHeader(headers); //GENERATE STRUCTS - if (state.OPTIONAL) - output.println("#include \"optionalstruct.h\"\n\n"); + output.println("#include \"optionalstruct.h\"\n\n"); + output.println("#include \"stdlib.h\"\n"); + HashSet processedcd = new HashSet(); - int maxotd=0; Enumeration e = safeexecution.keys(); while (e.hasMoreElements()) { @@ -2140,17 +2236,7 @@ public class BuildCode { ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement(); Hashtable flaginfo=(Hashtable)flagorder.get(cdtemp);//will be used several times - //////////////////////////DEBUG - System.out.println(cdtemp.getSymbol()+" "+cdtemp.getId()); - for(Iterator flags = cdtemp.getFlags(); flags.hasNext();){ - FlagDescriptor flagd = (FlagDescriptor)flags.next(); - int flagid=1<<((Integer)flaginfo.get(flagd)).intValue(); - System.out.println(" Flag "+flagd.getSymbol()+" 0x"+Integer.toHexString(flagid)+" int "+flagid); - } - /////////////////////////// - //Generate the struct of optionals - if((Hashtable)optionaltaskdescriptors.get(cdtemp)==null) System.out.println("Was in cd :"+cdtemp.getSymbol()); Collection c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values(); numotd = c_otd.size(); if(maxotd fsset=new TreeSet(); + //iterate through possible FSes corresponding to + //the state when entering - - //generate an array that stores the entire predicate - output.println("struct predicatemember * predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={"); - for( int j = 0; j it=fsset.iterator();it.hasNext();) { + if(needcomma) + output.print(", "); + output.println(it.next()); + } + output.println("};\n"); - //generate optionaltaskdescriptor that actually includes exit fses, predicate and the task concerned + //generate optionaltaskdescriptor that actually + //includes exit fses, predicate and the task + //concerned output.println("struct optionaltaskdescriptor optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={"); output.println("&task_"+otd.td.getSafeSymbol()+","); - output.println("/*number of enter flags*/"+fsnumber+","); + output.println("/*index*/"+otd.getIndex()+","); + output.println("/*number of enter flags*/"+fsset.size()+","); output.println("enterflag_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+","); output.println("/*number of members */"+predicateindex+","); output.println("predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+","); output.println("};\n"); } - } - else continue; // if there is no optionals, there is no need to build the rest of the struct + } else + continue; + // if there is no optionals, there is no need to build the rest of the struct output.println("struct optionaltaskdescriptor * otdarray"+cdtemp.getSafeSymbol()+"[]={"); c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values(); - int x=0; if( !c_otd.isEmpty() ){ + boolean needcomma=false; for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){ OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next(); - if(x!=0) output.println(","); - x++; + if(needcomma) + output.println(","); + needcomma=true; output.println("&optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol()); } } output.println("};\n"); - //get all the possible falgstates reachable by an object + //get all the possible flagstates reachable by an object Hashtable hashtbtemp = safeexecution.get(cdtemp); - Enumeration fses = hashtbtemp.keys(); int fscounter = 0; - while(fses.hasMoreElements()){ - FlagState fs = (FlagState)fses.nextElement(); + TreeSet fsts=new TreeSet(new FlagComparator(flaginfo)); + fsts.addAll(hashtbtemp.keySet()); + for(Iterator fsit=fsts.iterator();fsit.hasNext();) { + FlagState fs = (FlagState)fsit.next(); fscounter++; //get the set of OptionalTaskDescriptors corresponding - HashSet availabletasks = (HashSet)hashtbtemp.get(fs); - //iterate through the OptionalTaskDescriptors and store the pointers to the optionals struct (see on top) into an array + HashSet availabletasks = (HashSet)hashtbtemp.get(fs); + //iterate through the OptionalTaskDescriptors and + //store the pointers to the optionals struct (see on + //top) into an array output.println("struct optionaltaskdescriptor * optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {"); - for(Iterator mos = availabletasks.iterator(); mos.hasNext();){ - OptionalTaskDescriptor mm = (OptionalTaskDescriptor)mos.next(); - if(!mos.hasNext()) output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()); - - else output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()+","); + for(Iterator mos = ordertd(availabletasks).iterator(); mos.hasNext();){ + OptionalTaskDescriptor mm = mos.next(); + if(!mos.hasNext()) + output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()); + else + output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()+","); } output.println("};\n"); @@ -2314,10 +2337,9 @@ public class BuildCode { for(Iterator flags = fs.getFlags(); flags.hasNext();){ FlagDescriptor flagd = (FlagDescriptor)flags.next(); int id=1<<((Integer)flaginfo.get(flagd)).intValue(); - flagid+=id; + flagid|=id; } - //process tag information int tagcounter = 0; @@ -2335,13 +2357,50 @@ public class BuildCode { } output.println("};"); - + Set tiset=sa.getTaskIndex(fs); + for(Iterator itti=tiset.iterator();itti.hasNext();) { + TaskIndex ti=itti.next(); + Set otdset=sa.getOptions(fs, ti.getTask(), ti.getIndex()); + + output.print("struct optionaltaskdescriptor * optionaltaskfailure_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+"_array[] = {"); + boolean needcomma=false; + for(Iterator otdit=ordertd(otdset).iterator();otdit.hasNext();) { + OptionalTaskDescriptor otd=otdit.next(); + if(needcomma) + output.print(", "); + needcomma=true; + output.println("&optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol()); + } + output.println("};"); + + output.print("struct taskfailure taskfailure_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+" = {"); + output.print("&task_"+ti.getTask().getSafeSymbol()+", "); + output.print(ti.getIndex()+", "); + output.print(otdset.size()+", "); + output.print("optionaltaskfailure_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+"_array"); + output.println("};"); + } + + tiset=sa.getTaskIndex(fs); + boolean needcomma=false; + output.println("struct taskfailure * taskfailurearray"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={"); + for(Iterator itti=tiset.iterator();itti.hasNext();) { + TaskIndex ti=itti.next(); + if (needcomma) + output.print(", "); + needcomma=true; + output.print("&taskfailure_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()); + } + output.println("};\n"); + //Store the result in fsanalysiswrapper output.println("struct fsanalysiswrapper fsanalysiswrapper_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"={"); output.println("/*flag*/"+flagid+","); output.println("/* number of tags*/"+tagcounter+","); output.println("tags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+","); + output.println("/* numtask failures */"+tiset.size()+","); + output.println("taskfailurearray"+fscounter+"_"+cdtemp.getSafeSymbol()+","); output.println("/* number of optionaltaskdescriptors */"+availabletasks.size()+","); output.println("optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol()); output.println("};\n"); @@ -2350,12 +2409,14 @@ public class BuildCode { //Build the array of fsanalysiswrappers output.println("struct fsanalysiswrapper * fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"[] = {"); + boolean needcomma=false; for(int i = 0; i0) + output.print(", "); + if (processedcd.contains(cn)) + output.print("&classanalysiswrapper_"+cn.getSafeSymbol()); + else + output.print("NULL"); } output.println("};"); - output.println("int numclasses="+processedcd.size()+";"); - headers.println("extern numclasses;"); - output.println("int maxotd="+maxotd+";"); - headers.println("extern maxotd;"); + output.println("#define MAXOTD "+maxotd); headers.println("#endif"); - - } - + + public List ordertd(Set otdset) { + Relation r=new Relation(); + for(Iteratorotdit=otdset.iterator();otdit.hasNext();) { + OptionalTaskDescriptor otd=otdit.next(); + TaskIndex ti=new TaskIndex(otd.td, otd.getIndex()); + r.put(ti, otd); + } + + LinkedList l=new LinkedList(); + for(Iterator it=r.keySet().iterator();it.hasNext();) { + Set s=r.get(it.next()); + for(Iterator it2=s.iterator();it2.hasNext();) { + OptionalTaskDescriptor otd=(OptionalTaskDescriptor)it2.next(); + l.add(otd); + } + } + + return l; + } } diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index 8fb9d969..0b803a97 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -3,6 +3,7 @@ import IR.Tree.*; import IR.Flat.*; import IR.*; import java.util.*; +import Analysis.TaskStateAnalysis.*; public class State { public State() { @@ -14,27 +15,26 @@ public class State { this.arraytypes=new HashSet(); this.arraytonumber=new Hashtable(); this.tagmap=new Hashtable(); - this.analysisresult=new Hashtable(); - this.optionaltaskdescriptors=new Hashtable(); } public void addParseNode(ParseNode parsetree) { parsetrees.add(parsetree); } - public void storeAnalysisResult(Hashtable result){ - analysisresult = result; + public void storeAnalysisResult(Hashtable>> analysisresults) { + this.analysisresults=analysisresults; } - - public void storeOptionalTaskDescriptors(Hashtable optionaltaskdescriptors){ - this.optionaltaskdescriptors=optionaltaskdescriptors; + + public Hashtable>> getAnalysisResult() { + return analysisresults; } - public Hashtable getAnalysisResult(){ - return analysisresult; + + public void storeOptionalTaskDescriptors(Hashtable> optionaltaskdescriptors){ + this.optionaltaskdescriptors=optionaltaskdescriptors; } - - public Hashtable getOptionalTaskDescriptors(){ + + public Hashtable> getOptionalTaskDescriptors(){ return optionaltaskdescriptors; } @@ -64,8 +64,8 @@ public class State { private int arraycount=0; - private Hashtable analysisresult; - private Hashtable optionaltaskdescriptors; + private Hashtable> optionaltaskdescriptors; + private Hashtable>> analysisresults; private Hashtable tagmap; private int numtags=0; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 126d21a5..c924259d 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -131,6 +131,7 @@ public class Main { BuildFlat bf=new BuildFlat(state,tu); bf.buildFlat(); + SafetyAnalysis sa=null; if (state.TASKSTATE) { CallGraph callgraph=new CallGraph(state); @@ -143,7 +144,7 @@ public class Main { if (state.OPTIONAL) { ExecutionGraph et=new ExecutionGraph(state, ta); et.createExecutionGraph(); - SafetyAnalysis sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta); + sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta); sa.doAnalysis(); state.storeAnalysisResult(sa.getResult()); state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors()); @@ -169,7 +170,7 @@ public class Main { BuildCode bc=new BuildCode(state, bf.getMap(), tu, la); bc.buildCode(); } else { - BuildCode bc=new BuildCode(state, bf.getMap(), tu); + BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa); bc.buildCode(); } System.exit(0); diff --git a/Robust/src/Makefile b/Robust/src/Makefile index de977953..174a43ad 100644 --- a/Robust/src/Makefile +++ b/Robust/src/Makefile @@ -69,6 +69,7 @@ Analysis/TaskStateAnalysis/TaskAnalysis.class \ Analysis/TaskStateAnalysis/TaskEdges.class \ Analysis/TaskStateAnalysis/TaskGraph.class \ Analysis/TaskStateAnalysis/TaskNode.class \ +Analysis/TaskStateAnalysis/FlagComparator.class \ Analysis/TaskStateAnalysis/TaskNodeNamer.class Util/Edge.class \ Util/GraphNode.class Util/Namer.class Util/Relation.class \ Interface/HTTPHeader.class Interface/HTTPResponse.class \ @@ -100,7 +101,7 @@ javadoc: javadoc -classpath ../cup:.:$(CLASSPATH) -sourcepath . -private -d javadoc Lex Util IR IR.Tree IR.Flat Analysis Analysis.CallGraph Analysis.Flag Analysis.TaskStateAnalysis Analysis.Locality Main clean: - rm IR/*.class IR/Tree/*.class Main/*.class Lex/*.class Parse/*.class Parse/Sym.java Parse/Parser.java IR/Flat/*.class classdefs.h methodheaders.h methods.c structdefs.h virtualtable.h task.h taskdefs.c taskdefs.h Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class + rm IR/*.class IR/Tree/*.class Main/*.class Lex/*.class Parse/*.class Parse/Sym.java Parse/Parser.java IR/Flat/*.class classdefs.h methodheaders.h methods.c structdefs.h virtualtable.h task.h taskdefs.c taskdefs.h Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class Analysis/Prefetch/*.class cleandoc: rm -rf javadoc \ No newline at end of file diff --git a/Robust/src/Runtime/DSTM/docs/prefetch b/Robust/src/Runtime/DSTM/docs/prefetch index 7fa3fbde..3fa9baf7 100644 --- a/Robust/src/Runtime/DSTM/docs/prefetch +++ b/Robust/src/Runtime/DSTM/docs/prefetch @@ -1,4 +1,7 @@ 1. Start with flat representation -2. Analyze representation to figure out where to insert prefetches + +*** 2. Analyze representation to figure out where to insert prefetches + 3. Use analysis results to insert prefetch nodes into the flat representation + 4. Modify BuildCode to generate C code from our new flatprefetchnodes \ No newline at end of file diff --git a/Robust/src/Runtime/ObjectHash.c b/Robust/src/Runtime/ObjectHash.c index cd7ad2dc..cfbf92ba 100755 --- a/Robust/src/Runtime/ObjectHash.c +++ b/Robust/src/Runtime/ObjectHash.c @@ -102,7 +102,7 @@ void ObjectHashrehash(struct ObjectHash * thisvar) { thisvar->bucket=newbucket; } -int ObjectHashadd(struct ObjectHash * thisvar,int key, int data, int data2) { +int ObjectHashadd(struct ObjectHash * thisvar,int key, int data, int data2, int data3, int data4) { /* Rehash code */ unsigned int hashkey; struct ObjectNode **ptr; @@ -133,6 +133,8 @@ int ObjectHashadd(struct ObjectHash * thisvar,int key, int data, int data2) { struct ObjectNode *node=RUNMALLOC(sizeof(struct ObjectNode)); node->data=data; node->data2=data2; + node->data3=data3; + node->data4=data4; node->key=key; node->next=(*ptr); *ptr=node; @@ -197,7 +199,7 @@ int ObjectHashcount(struct ObjectHash *thisvar,int key) { return count; } -int ObjectHashget(struct ObjectHash *thisvar, int key, int *data, int *data2) { +int ObjectHashget(struct ObjectHash *thisvar, int key, int *data, int *data2, int *data3, int *data4) { unsigned int hashkey = (unsigned int)key % thisvar->size; struct ObjectNode *ptr = thisvar->bucket[hashkey]; @@ -205,6 +207,8 @@ int ObjectHashget(struct ObjectHash *thisvar, int key, int *data, int *data2) { if (ptr->key == key) { *data = ptr->data; *data2 = ptr->data2; + *data3 = ptr->data3; + *data4 = ptr->data4; return 1; /* success */ } ptr = ptr->next; @@ -213,6 +217,24 @@ int ObjectHashget(struct ObjectHash *thisvar, int key, int *data, int *data2) { return 0; /* failure */ } +int ObjectHashupdate(struct ObjectHash *thisvar, int key, int data, int data2, int data3, int data4) { + unsigned int hashkey = (unsigned int)key % thisvar->size; + + struct ObjectNode *ptr = thisvar->bucket[hashkey]; + while (ptr) { + if (ptr->key == key) { + ptr->data=data; + ptr->data2=data2; + ptr->data3=data3; + ptr->data4=data4; + return 1; /* success */ + } + ptr = ptr->next; + } + return 0; /* failure */ +} + + inline struct ObjectIterator * noargallocateObjectIterator() { return (struct ObjectIterator*)RUNMALLOC(sizeof(struct ObjectIterator)); } @@ -235,3 +257,19 @@ inline int Objnext(struct ObjectIterator *thisvar) { inline int Objkey(struct ObjectIterator *thisvar) { return thisvar->cur->key; } + +inline int Objdata(struct ObjectIterator *thisvar) { + return thisvar->cur->data; +} + +inline int Objdata2(struct ObjectIterator *thisvar) { + return thisvar->cur->data2; +} + +inline int Objdata3(struct ObjectIterator *thisvar) { + return thisvar->cur->data3; +} + +inline int Objdata4(struct ObjectIterator *thisvar) { + return thisvar->cur->data4; +} diff --git a/Robust/src/Runtime/ObjectHash.h b/Robust/src/Runtime/ObjectHash.h index 23a05fce..6128f78d 100755 --- a/Robust/src/Runtime/ObjectHash.h +++ b/Robust/src/Runtime/ObjectHash.h @@ -23,11 +23,11 @@ void ObjectHashaddChild(struct ObjectHash *thisvar, struct ObjectHash * child); void freeObjectHash(struct ObjectHash *); void ObjectHashrehash(struct ObjectHash * thisvar); -int ObjectHashadd(struct ObjectHash *, int key, int data, int data2); +int ObjectHashadd(struct ObjectHash *, int key, int data, int data2, int data3, int data4); int ObjectHashremove(struct ObjectHash *,int key); bool ObjectHashcontainskey(struct ObjectHash *,int key); bool ObjectHashcontainskeydata(struct ObjectHash *,int key, int data); -int ObjectHashget(struct ObjectHash *,int key, int* data, int* data2); +int ObjectHashget(struct ObjectHash *,int key, int* data, int* data2, int * data3, int* data4); void ObjectHashaddParent(struct ObjectHash *,struct ObjectHash* parent); int ObjectHashfirstkey(struct ObjectHash *); struct ObjectIterator* ObjectHashcreateiterator(struct ObjectHash *); @@ -53,6 +53,8 @@ struct ObjectNode { int key; int data; int data2; + int data3; + int data4; }; struct ObjectIterator { @@ -69,4 +71,10 @@ inline int Objnext(struct ObjectIterator *thisvar); inline int Objkey(struct ObjectIterator *thisvar); +inline int Objdata(struct ObjectIterator *thisvar); +inline int Objdata2(struct ObjectIterator *thisvar); +inline int Objdata3(struct ObjectIterator *thisvar); +inline int Objdata4(struct ObjectIterator *thisvar); + + #endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 9422b681..3917da59 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -28,9 +28,6 @@ int instaccum=0; #include "dmalloc.h" #endif - - - void exithandler(int sig, siginfo_t *info, void * uap) { exit(0); } @@ -129,6 +126,9 @@ void * allocate_new(void * ptr, int type) { v->tid=0; v->lockentry=0; v->lockcount=0; +#endif +#ifdef OPTIONAL + v->fses=0; #endif return v; } @@ -147,14 +147,20 @@ struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { v->tid=0; v->lockentry=0; v->lockcount=0; +#endif +#ifdef OPTIONAL + v->fses=0; #endif return v; } #else void * allocate_new(int type) { - void * v=FREEMALLOC(classsize[type]); - *((int *)v)=type; + struct ___Object___ * v=FREEMALLOC(classsize[type]); + v->type=type; +#ifdef OPTIONAL + v->fses=0; +#endif return v; } @@ -164,6 +170,9 @@ struct ArrayObject * allocate_newarray(int type, int length) { struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]); v->type=type; v->___length___=length; +#ifdef OPTIONAL + v->fses=0; +#endif return v; } #endif diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 96cc3087..af2c7901 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -17,6 +17,12 @@ extern int failurecount; #define ARRAYGET(array, type, index) \ ((type *)(&(& array->___length___)[1]))[index] +#ifdef OPTIONAL +#define OPTARG(x) , x +#else +#define OPTARG(x) +#endif + #ifdef DSTM void * allocate_newglobal(transrecord_t *, int type); struct ArrayObject * allocate_newarrayglobal(transrecord_t *, int type, int length); @@ -73,6 +79,16 @@ void createstartupobject(); #include "optionalstruct.h" #endif +#ifdef OPTIONAL +struct failedtasklist { + struct taskdescriptor *task; + int index; + int numflags; + int *flags; + struct failedtasklist *next; +}; +#endif + void flagorand(void * ptr, int ormask, int andmask); void flagorandinit(void * ptr, int ormask, int andmask); void executetasks(); @@ -82,6 +98,9 @@ struct tagobjectiterator { int istag; /* 0 if object iterator, 1 if tag iterator */ struct ObjectIterator it; /* Object iterator */ struct ObjectHash * objectset; +#ifdef OPTIONAL + int failedstate; +#endif int slot; int tagobjindex; /* Index for tag or object depending on use */ /*if tag we have an object binding */ @@ -108,18 +127,21 @@ struct taskparamdescriptor { struct taskdescriptor * task; int numParameters; void ** parameterArray; +#ifdef OPTIONAL + int * failed; +#endif }; int hashCodetpd(struct taskparamdescriptor *); int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *); void toiReset(struct tagobjectiterator * it); -int toiHasNext(struct tagobjectiterator *it, void ** objectarray); -void toiNext(struct tagobjectiterator *it , void ** objectarray); +int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)); +void toiNext(struct tagobjectiterator *it , void ** objectarray OPTARG(int * failed)); void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams); void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams); void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter); -void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr); +int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags); #endif diff --git a/Robust/src/Runtime/task.c b/Robust/src/Runtime/task.c index 5986ae9e..dcb93c5c 100644 --- a/Robust/src/Runtime/task.c +++ b/Robust/src/Runtime/task.c @@ -97,6 +97,12 @@ int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd for(i=0;inumParameters;i++) if(ftd1->parameterArray[i]!=ftd2->parameterArray[i]) return 0; +#ifdef OPTIONAL + for(i=0;inumParameters;i++) { + if(ftd1->failed[i]!=ftd2->failed[i]) + return 0; + } +#endif return 1; } @@ -161,7 +167,6 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { { struct ___Object___ * tagset=tagd->flagptr; - if(tagset==NULL) { tagd->flagptr=obj; } else if (tagset->type!=OBJECTARRAYTYPE) { @@ -286,517 +291,592 @@ struct ___TagDescriptor___ * allocate_tag(int index) { void flagbody(struct ___Object___ *ptr, int flag); #ifdef OPTIONAL -void enqueueoptional(struct ___Object___ * currobj); - -struct optionaltaskdescriptor *** makeintersectionotd(int num, struct fsanalysiswrapper ** wrapperarray, int *result){ - int i,j,k; - (*result)=0; - struct optionaltaskdescriptor *** bigtmparray = RUNMALLOC(sizeof(struct optionaltaskdescriptor **)*maxotd); - struct fsanalysiswrapper * tmpwrapper; - struct fsanalysiswrapper * firstwrapper = wrapperarray[0];/*we are sure that num>0*/ - /*we check if the otd of the first wrapper is contained in all others*/ - for(i=0; inumoptionaltaskdescriptors; i++){ - struct optionaltaskdescriptor ** tmparray = RUNMALLOC(sizeof(struct optionaltaskdescriptor *) * num); - struct optionaltaskdescriptor * otd = firstwrapper->optionaltaskdescriptorarray[i]; - tmparray[0]=otd; - for(j=1; jnumoptionaltaskdescriptors; k++){ - struct optionaltaskdescriptor * tmpotd=tmpwrapper->optionaltaskdescriptorarray[k]; - if(otd->task->name == tmpotd->task->name){ - tmparray[j]=tmpotd; - goto nextwrapper; - } - RUNFREE(tmparray); - goto nextotd; - } - nextwrapper: - ; - } - bigtmparray[(*result)]=tmparray; - (*result)++; - nextotd: - ; - } - - {/*now allocate the good size for otdarray and put the otds*/ - struct optionaltaskdescriptor *** otdarray = RUNMALLOC(sizeof(struct optionaltaskdescriptor *) * (*result)); - for(i=0; i<(*result); i++) - otdarray[i]=bigtmparray[i]; - - RUNFREE(bigtmparray); - return otdarray; - } -} +void enqueueoptional(struct ___Object___ * currobj, int numfailedfses, int * failedfses, struct taskdescriptor * task, int index); #endif + int flagcomp(const int *val1, const int *val2) { + return (*val1)-(*val2); + } void flagorand(void * ptr, int ormask, int andmask) { - int oldflag=((int *)ptr)[1]; - int flag=ormask|oldflag; #ifdef OPTIONAL struct ___Object___ * obj = (struct ___Object___ *)ptr; - if(obj->failedstatus==1){/*store the information about exitfses*/ - int i,j,counter=0, offset=0; - for(i=0; inumotds; i++){ - counter+=obj->otds[i]->numenterflags; - } - obj->numexitfses=counter; - if(obj->exitfses!=NULL) RUNFREE(obj->exitfses); - obj->exitfses= RUNMALLOC(sizeof(int) * counter); - for(i=0; inumotds; i++){ - for(j=0; jotds[i]->numenterflags; j++){ - oldflag=obj->otds[i]->enterflags[j]; - flag=ormask|oldflag; - flag&=andmask; - obj->exitfses[j+offset]=flag; + if(obj->numfses){/*store the information about fses*/ + int flag, i, j,counter, offset=0; + for(i=0;inumfses;i++) { + int oldoffset; + counter=obj->fses[offset++]; + oldoffset=offset; + for(j=0;jfses[offset]; + obj->fses[offset++]=(flag|ormask)&andmask; } - offset+=obj->otds[i]->numenterflags; + qsort(&obj->fses[oldoffset], sizeof(int), counter, (int (*)(const void *, const void *)) &flagcomp); } - enqueueoptional(ptr); + enqueueoptional(obj, 0, NULL, NULL, 0); } else #endif { - flag&=andmask; - flagbody(ptr, flag); + int oldflag=((int *)ptr)[1]; + int flag=ormask|oldflag; + flag&=andmask; + flagbody(ptr, flag); } } void intflagorand(void * ptr, int ormask, int andmask) { - int oldflag=((int *)ptr)[1]; - int flag=ormask|oldflag; #ifdef OPTIONAL struct ___Object___ * obj = (struct ___Object___ *)ptr; - if(obj->failedstatus==1) {/*store the information about exitfses*/ - int i,j,counter=0, offset=0; - for(i=0; inumotds; i++) { - counter+=obj->otds[i]->numenterflags; - } - obj->numexitfses=counter; - if(obj->exitfses!=NULL) - RUNFREE(obj->exitfses); - obj->exitfses= RUNMALLOC(sizeof(int) * counter); - for(i=0; inumotds; i++) { - for(j=0; jotds[i]->numenterflags; j++){ - oldflag=obj->otds[i]->enterflags[j]; - flag=ormask|oldflag; - flag&=andmask; - obj->exitfses[j+offset]=flag; + if(obj->numfses) {/*store the information about fses*/ + int flag, i, j,counter, offset=0; + for(i=0;inumfses;i++) { + int oldoffset; + counter=obj->fses[offset++]; + oldoffset=offset; + for(j=0;jfses[offset]; + obj->fses[offset++]=(flag|ormask)&andmask; } - offset+=obj->otds[i]->numenterflags; + qsort(&obj->fses[oldoffset], sizeof(int), counter, (int (*)(const void *, const void *)) &flagcomp); } - enqueueoptional(ptr); + enqueueoptional(obj, 0, NULL, NULL, 0); } else #endif { - flag&=andmask; - if (flag==oldflag) /* Don't do anything */ - return; - else flagbody(ptr, flag); + int oldflag=((int *)ptr)[1]; + int flag=ormask|oldflag; + flag&=andmask; + if (flag==oldflag) /* Don't do anything */ + return; + else flagbody(ptr, flag); } } void flagorandinit(void * ptr, int ormask, int andmask) { int oldflag=((int *)ptr)[1]; int flag=ormask|oldflag; + flag&=andmask; + flagbody(ptr,flag); +} + +void flagbody(struct ___Object___ *ptr, int flag) { + struct parameterwrapper *flagptr=(struct parameterwrapper *)ptr->flagptr; + ptr->flag=flag; + + /*Remove object from all queues */ + while(flagptr!=NULL) { + struct parameterwrapper *next; + int UNUSED, UNUSED2, UNUSED3; + ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, &UNUSED, &UNUSED2, &UNUSED3); + ObjectHashremove(flagptr->objectset, (int)ptr); + flagptr=next; + } + + { + struct QueueItem *tmpptr; + struct parameterwrapper * parameter=objectqueues[ptr->type]; + int i; + struct parameterwrapper * prevptr=NULL; + struct ___Object___ *tagptr=ptr->___tags___; + + /* Outer loop iterates through all parameter queues an object of + this type could be in. */ + + while(parameter!=NULL) { + /* Check tags */ + if (parameter->numbertags>0) { + if (tagptr==NULL) + goto nextloop;//that means the object has no tag but that param needs tag + else if(tagptr->type==TAGTYPE) {//one tag + struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr; + for(i=0;inumbertags;i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + if (tagid!=tagptr->flag) + goto nextloop; /*We don't have this tag */ + } + } else {//multiple tags + struct ArrayObject * ao=(struct ArrayObject *) tagptr; + for(i=0;inumbertags;i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + int j; + for(j=0;j___cachedCode___;j++) { + if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, i)->flag) + goto foundtag; + } + goto nextloop; + foundtag: + ; + } + } + } + + /* Check flags */ + for(i=0;inumberofterms;i++) { + int andmask=parameter->intarray[i*2]; + int checkmask=parameter->intarray[i*2+1]; + if ((flag&andmask)==checkmask) { + enqueuetasks(parameter, prevptr, ptr, NULL, 0); + prevptr=parameter; + break; + } + } + nextloop: + parameter=parameter->next; + } + ptr->flagptr=prevptr; + } +} + #ifdef OPTIONAL - struct ___Object___ * obj = (struct ___Object___ *)ptr; - if(obj->failedstatus==1){/*store the information about exitfses*/ - int i,j,counter=0, offset=0; - for(i=0; inumotds; i++){ - counter+=obj->otds[i]->numenterflags; + +int checktags(struct ___Object___ * currobj, struct fsanalysiswrapper * fswrapper) { + /* Check Tags */ + struct ___Object___ * tagptr = currobj->___tags___; + if(fswrapper->numtags>0){ + if (tagptr==NULL) + return 0; //that means the object has no tag but that param + //needs tag + else if(tagptr->type==TAGTYPE) {//one tag + if(fswrapper->numtags!=1) + return 0; //we don't have the right number of tags + struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr; + if (fswrapper->tags[0]!=tagptr->flag) + return 0; + } else { //multiple tags + struct ArrayObject * ao=(struct ArrayObject *) tagptr; + int tag_counter=0; + int foundtag=0; + + if(ao->___length___!=fswrapper->numtags) + return 0;//we don't have the right number of tags + for(tag_counter=0;tag_counternumtags;tag_counter++) { + int tagid=fswrapper->tags[tag_counter]; + int j; + for(j=0;j___cachedCode___;j++) { + if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, tag_counter)->flag) + return 1; + } + return 0; + } } - obj->numexitfses=counter; - if(obj->exitfses!=NULL) RUNFREE(obj->exitfses); - obj->exitfses= RUNMALLOC(sizeof(int) * counter); - for(i=0; inumotds; i++){ - for(j=0; jotds[i]->numenterflags; j++){ - oldflag=obj->otds[i]->enterflags[j]; - flag=ormask|oldflag; - flag&=andmask; - obj->exitfses[j+offset]=flag; + } + return 1; +} + +int getlength(int *flist, int len) { + int count=0; + int i; + for(i=0;iotds[i]->numenterflags; + i++; + j++; + count++; } - enqueueoptional(ptr); } - else -#endif - { - flag&=andmask; - flagbody(ptr,flag); + return count; +} + +/* Merge flags from ftlmerge into ftl. */ +void mergeitems(struct failedtasklist *ftl, struct failedtasklist *ftlmerge) { + int length=0; + int i,j; + int *mergedlist; + int offset=0; + for(i=0;inumflags;i++) { + int len=ftl->flags[offset++]; + int offsetmerge=0; + for(j=0;jnumflags;j++) { + int lenmerge=ftlmerge->flags[offsetmerge++]; + length+=1+domerge(&ftl->flags[offset],len,&ftlmerge->flags[offsetmerge],lenmerge, NULL); + offsetmerge+=lenmerge; + } + offset+=len; + } + mergedlist=RUNMALLOC(sizeof(int)*length); + + offset=0; + length=0; + for(i=0;inumflags;i++) { + int len=ftl->flags[offset++]; + int offsetmerge=0; + for(j=0;jnumflags;j++) { + int lenmerge=ftlmerge->flags[offsetmerge++]; + int size=domerge(&ftl->flags[offset],len,&ftlmerge->flags[offsetmerge],lenmerge,&mergedlist[length+1]); + mergedlist[length]=size; + length+=size+1; } + } + RUNFREE(ftl->flags); + ftl->flags=mergedlist; + ftl->numflags*=ftlmerge->numflags; } -#ifdef OPTIONAL - removeoptionalfromqueues(int hashcode, struct ___Object___ * currobj, struct parameterwrapper * flagptr){/*find a better way to free the useless instances of the object*/ - while(flagptr!=NULL) { - struct ___Object___ *temp=NULL; - struct parameterwrapper *ptr; - struct ObjectNode * node = flagptr->objectset->listhead; - while(node!=NULL){ - temp=(struct ___Object___ *)node->key; - if(temp->failedstatus==1 && temp->hashcode==currobj->hashcode){ - if(temp!=currobj){ - ObjectHashremove(flagptr->objectset, (int)temp);//remove from wrapper - //delete the fields that wont be removed by the GC. - if(temp->exitfses!=NULL) RUNFREE(temp->exitfses); - if(temp->otds!=NULL) RUNFREE(temp->otds); - goto nextwrapper; - } - else{ - //remove from wrapper - ObjectHashremove(flagptr->objectset, (int)temp); - goto nextwrapper; - } - } - node=node->next; - } - nextwrapper: - ; - flagptr=flagptr->next; - } - } -#endif - - void flagbody(struct ___Object___ *ptr, int flag) { - struct parameterwrapper *flagptr=(struct parameterwrapper *)ptr->flagptr; - ptr->flag=flag; - - /*Remove object from all queues */ - while(flagptr!=NULL) { - struct parameterwrapper *next; - struct ___Object___ * tag=ptr->___tags___; - int FIXME; - ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, &FIXME); - ObjectHashremove(flagptr->objectset, (int)ptr); - flagptr=next; - } - - { - struct QueueItem *tmpptr; - struct parameterwrapper * parameter=objectqueues[ptr->type]; - int i; - struct parameterwrapper * prevptr=NULL; - struct ___Object___ *tagptr=ptr->___tags___; - - /* Outer loop iterates through all parameter queues an object of - this type could be in. */ - - while(parameter!=NULL) { - /* Check tags */ - if (parameter->numbertags>0) { - if (tagptr==NULL) - goto nextloop;//that means the object has no tag but that param needs tag - else if(tagptr->type==TAGTYPE) {//one tag - struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr; - for(i=0;inumbertags;i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - if (tagid!=tagptr->flag) - goto nextloop; /*We don't have this tag */ - } - } else {//multiple tags - struct ArrayObject * ao=(struct ArrayObject *) tagptr; - for(i=0;inumbertags;i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - int j; - for(j=0;j___cachedCode___;j++) { - if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, i)->flag) - goto foundtag; - } - goto nextloop; - foundtag: - ; - } - } - } - - /* Check flags */ - for(i=0;inumberofterms;i++) { - int andmask=parameter->intarray[i*2]; - int checkmask=parameter->intarray[i*2+1]; - if ((flag&andmask)==checkmask) { - enqueuetasks(parameter, prevptr, ptr); - prevptr=parameter; - break; - } - } - nextloop: - parameter=parameter->next; - } - ptr->flagptr=prevptr; - } - } - -#ifdef OPTIONAL - - void enqueueoptional(struct ___Object___ * currobj){ - - struct classanalysiswrapper * classwrapper=NULL; - struct fsanalysiswrapper * fswrapper=NULL; - int counter=0; - int numoptionaltaskdescriptors=0; - struct optionaltaskdescriptor *** optionaltaskdescriptorarray=NULL; - struct fsanalysiswrapper ** goodfswrappersarray=NULL; - int numgoodfswrappers=0; -#ifdef DEBUG - if(currobj->numexitfses==0) - printf("Handling failed object\nType : %i\nFlag : 0x%x\n", currobj->type, currobj->flag); - else{ - printf("Handling failed object\nType : %i\n", currobj->type); - int fscount=0; - for(fscount=0; fscountnumexitfses; fscount++) - printf("Flag : 0x%x\n", currobj->exitfses[fscount]); - } - struct ___Object___ * tagptr = currobj->___tags___; - if(tagptr!=NULL){ - if(tagptr->type==TAGTYPE) { - printf("Tag : %i\n", tagptr->flag);} - else { - struct ArrayObject * ao=(struct ArrayObject *) tagptr; - int numbertags = ao->___length___; - for(counter=0; counterfailedstatus = 1; - - /*test what optionaltaskdescriptors are available, - find the class corresponding*/ - - for(counter = 0; countertype == classwrapper->type) - goto classchecked; - } -#ifdef DEBUG - printf("No task will use this parameter as optional\n"); -#endif - removeoptionalfromqueues(currobj->hashcode,currobj, objectqueues[currobj->type]); - goto nothingtodo; - classchecked: - ; -#ifdef DEBUG - printf("Found the class, search through fses\n"); -#endif - /*search through fses*/ - goodfswrappersarray = RUNMALLOC(sizeof(struct fsanalysiswrapper *) * classwrapper->numfsanalysiswrappers); /*max number of good fswrappers*/ - if(goodfswrappersarray == NULL){ - fprintf(stderr, "ERROR : \"struct fsanalysiswrapper ** goodfswrappersarray\" is a NULL pointer\n, Analysis has been skipped, check Runtime/task.c, function enqueueoptional\n"); - removeoptionalfromqueues(currobj->hashcode,currobj, objectqueues[currobj->type]); - goto nothingtodo; - } - for(counter = 0; counternumfsanalysiswrappers; counter++){ - /*test the FS of the object (include flags and tags)*/ - fswrapper = classwrapper->fsanalysiswrapperarray[counter]; - if(fswrapper == NULL){ - fprintf(stderr, "ERROR : struct fsanalysiswrapper * is a NULL pointer\n, Analysis has been skipped, check Runtime/task.c, function enqueueoptional\n"); - removeoptionalfromqueues(currobj->hashcode,currobj, objectqueues[currobj->type]); - goto nothingtodo; - } - /*check tags*/ - struct ___Object___ * tagptr = currobj->___tags___; - if(fswrapper->numtags>0){ - if (tagptr==NULL) - goto nextloop;//that means the object has no tag but that param needs tag - else if(tagptr->type==TAGTYPE) {//one tag - if(fswrapper->numtags!=1) goto nextloop;//we don't have the right number of tags - struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr; - if (fswrapper->tags[0]!=tagptr->flag) - goto nextloop; - } - else {//multiple tags - struct ArrayObject * ao=(struct ArrayObject *) tagptr; - int tag_counter=0; - if(ao->___length___!=fswrapper->numtags) goto nextloop;//we don't have the right number of tags - for(tag_counter=0;tag_counternumtags;tag_counter++) { - int tagid=fswrapper->tags[tag_counter]; - int j; - for(j=0;j___cachedCode___;j++) { - if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, tag_counter)->flag) - goto foundtag; - } - goto nextloop; - foundtag: - ; ; - } - } - } - - //check flags - if(currobj->numexitfses==0){/*first time the method is invoqued*/ - if( currobj->flag == fswrapper->flags){ - int otdc; - optionaltaskdescriptorarray = RUNMALLOC(sizeof(struct optionaltaskdescriptor **) * fswrapper->numoptionaltaskdescriptors); - numoptionaltaskdescriptors = fswrapper->numoptionaltaskdescriptors; - for(otdc = 0; otdcnumoptionaltaskdescriptors; otdc++){ - struct optionaltaskdescriptor ** tmpptr = RUNMALLOC(sizeof(struct optionaltaskdescriptor *)); - tmpptr[0] = fswrapper->optionaltaskdescriptorarray[otdc]; - optionaltaskdescriptorarray[otdc] = tmpptr; - } - numgoodfswrappers=1; - goto fschecked; - } - } - else if(currobj->numexitfses==1){/*one fs exit*/ - if(currobj->exitfses[0] == fswrapper->flags){ - int otdc; - optionaltaskdescriptorarray = RUNMALLOC(sizeof(struct optionaltaskdescriptor **) * fswrapper->numoptionaltaskdescriptors); - numoptionaltaskdescriptors = fswrapper->numoptionaltaskdescriptors; - for(otdc = 0; otdcnumoptionaltaskdescriptors; otdc++){ - struct optionaltaskdescriptor ** tmpptr = RUNMALLOC(sizeof(struct optionaltaskdescriptor *)); - tmpptr[0] = fswrapper->optionaltaskdescriptorarray[otdc]; - optionaltaskdescriptorarray[otdc] = tmpptr; - } - numgoodfswrappers=1; - goto fschecked; - } - } - else{ - int fscount=0; - for(fscount=0; fscountnumexitfses; fscount++){ - - if( currobj->exitfses[fscount] == fswrapper->flags ){/*see if the fswraper correspond to one of the fses*/ - goodfswrappersarray[numgoodfswrappers]=fswrapper; - numgoodfswrappers++; - } - } - if(counter==classwrapper->numfsanalysiswrappers-1) goto makeintersection; /*last fswrapper*/ - } - nextloop: - ; - } - nofs: - ; -#ifdef DEBUG - printf("FS not found, Nothing more to do\n"); -#endif - removeoptionalfromqueues(currobj->hashcode,currobj, objectqueues[currobj->type]); - goto nothingtodo; - makeintersection: - ; - if(numgoodfswrappers==0 || numgoodfswrappers==1) goto nofs; /*nothing has been found, we expect more than one wrapper for multiple flags*/ - optionaltaskdescriptorarray = makeintersectionotd(numgoodfswrappers, goodfswrappersarray, &numoptionaltaskdescriptors); - if(optionaltaskdescriptorarray==NULL){ - fprintf(stderr, "ERROR : struct optionaltaskdescriptor ** is a NULL pointer\n, Analysis has been skipped, check Runtime/task.c, function enqueueoptional\n"); - goto nothingtodo; - } - - fschecked: - ; -#ifdef DEBUG - printf("FS(es) found, intersection created, %i potential tasks :\n", numoptionaltaskdescriptors); - - - /*find the parameterwrapper corresponding to the potential task*/ - for(counter = 0; countertask->name); - } - -#endif - { - struct parameterwrapper * prevptr = NULL; - struct parameterwrapper * flagptr = objectqueues[currobj->type]; - removeoptionalfromqueues(currobj->hashcode,currobj, flagptr); - /*process for each otd*/ - for(counter = 0; countertype]; - struct optionaltaskdescriptor ** tmpptr = optionaltaskdescriptorarray[counter]; - struct optionaltaskdescriptor * currotd = tmpptr[0]; - int otd_counter=0; - while(parameter->task != currotd->task) - parameter=parameter->next; -#ifdef DEBUG - printf("found parameterwrapper for task : %s\n", parameter->task->name); -#endif - - struct ___Object___ * newobj = RUNMALLOC(sizeof(struct ___Object___)); - (*newobj)=(*currobj); - newobj->numotds=numgoodfswrappers; - newobj->otds=RUNMALLOC(sizeof(struct optionaltaskdescriptor *) * numgoodfswrappers); - for(otd_counter=0; otd_counterotds[otd_counter]=tmpptr[otd_counter]; - } - enqueuetasks(parameter, prevptr, newobj); - prevptr = parameter; - - nextotd: - ; - } - - } - nothingtodo: - - /*if(currobj->exitfses!=NULL) RUNFREE(currobj->exitfses); - if(currobj->otds!=NULL) RUNFREE(currobj->otds);*///there has been a problem just before the program exit, maybe due to the GC ? - RUNFREE(optionaltaskdescriptorarray); - ; - } +void mergefailedlists(struct failedtasklist **andlist, struct failedtasklist *list) { + struct failedtasklist *tmpptr; + while((*andlist)!=NULL) { + struct failedtasklist *searchftl=list; + while(searchftl!=NULL) { + if ((*andlist)->task==searchftl->task&& + (*andlist)->index==searchftl->index) { + mergeitems(*andlist, searchftl); + break; + } + searchftl=searchftl->next; + } + if (searchftl==NULL) { + //didn't find andlist + tmpptr=*andlist; + *andlist=(*andlist)->next;//splice item out of list + RUNFREE(tmpptr->flags); //free the item + RUNFREE(tmpptr); + } else { + andlist=&((*andlist)->next); //iterate to next item + } + } + //free the list we're searching + while(list!=NULL) { + tmpptr=list->next; + RUNFREE(list->flags); + RUNFREE(list); + list=tmpptr; + } +} + +struct failedtasklist * processfailstate(struct classanalysiswrapper * classwrapper, struct taskdescriptor *task, int index, struct ___Object___ * currobj, int flagstate) { + struct failedtasklist *list=NULL; + int i,h; + struct fsanalysiswrapper *fswrapper=NULL; + for(h=0;hnumfsanalysiswrappers;h++) { + struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h]; + if (tmp->flags==flagstate&&checktags(currobj, tmp)) { + //we only match exactly here + fswrapper=tmp; + break; + } + } + if (fswrapper==NULL) + return list; + for(i=0;inumtaskfailures;i++) { + int j; + struct taskfailure * taskfail=fswrapper->taskfailurearray[i]; + if (taskfail->task==task&&taskfail->index==index) { + int start=0; + while(startnumoptionaltaskdescriptors) { + struct taskdescriptor *currtask=NULL; + struct failedtasklist *tmpftl; + int currindex; + int totallength=0; + int *enterflags; + int numenterflags, offset; + struct parameterwrapper *pw; + for(j=start;jnumoptionaltaskdescriptors;j++) { + struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[j]; + if(currtask==NULL) { + currtask=otd->task; + currindex=otd->index; + } else if (currtask!=otd->task||currindex!=otd->index) + break; + totallength+=otd->numenterflags; + } + pw=currtask->descriptorarray[currindex]->queue; + enterflags=RUNMALLOC(totallength*sizeof(int)); + numenterflags=j-start; + offset=0; + for(start;startoptionaltaskdescriptorarray[start]; + enterflags[offset++]=otd->numenterflags; + memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int)); + offset+=otd->numenterflags; + } + tmpftl=RUNMALLOC(sizeof(struct failedtasklist)); + tmpftl->next=list; + tmpftl->task=currtask; + tmpftl->numflags=numenterflags; + tmpftl->flags=enterflags; + list=tmpftl; + } + } + } + return list; +} + +struct failedtasklist * processnormfailstate(struct classanalysiswrapper * classwrapper, struct ___Object___ * currobj, int flagstate) { + struct failedtasklist *list=NULL; + int i,h; + int start=0; + struct fsanalysiswrapper *fswrapper=NULL; + for(h=0;hnumfsanalysiswrappers;h++) { + struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h]; + if (tmp->flags==flagstate&&checktags(currobj, tmp)) { + //we only match exactly here + fswrapper=tmp; + break; + } + } + if(fswrapper==NULL) + return NULL; - /*we need to check if the object is optional, in this case, test the predicate*/ - /*here is the code for predicate checking*/ - /*The code has not been tested. I don't even know if it is working or efficient but it is a lead... - if(currotd->numpredicatemembers == 0){ - printf("this task can be fired\n"); - goto enqueuetask; - } - else{ - int pred_counter; - int predicatetrue = 0; - for(pred_counter = 0; pred_counternumpredicatemembers; pred_counter++){ - struct predicatemember * currpred = currotd->predicatememberarray[pred_counter]; - printf("predicate type : %i\n", currpred->type); - - //test if the predicate member is true - struct parameterwrapper * paramwrapper = objectqueues[currpred->type]; - while(paramwrapper!=NULL){ - struct ObjectIterator * it = allocateObjectIterator(paramwrapper->objectset->listhead); - do{ - struct ___Object___ * obj = (struct ___Object___ *)Objkey(it); - printf("obj type : %i\n", obj->type); - if(obj->type == currpred->type){ - //test the predicate - printf("predicate to test\n"); - //only if good - goto enqueuetask; - } - Objnext(it); - }while(ObjhasNext(it)); - paramwrapper=paramwrapper->next; - } - printf("not the good predicate"); - //goto endanalysis - } - //the predicate members have to be all true - }*/ + while(startnumoptionaltaskdescriptors) { + struct taskdescriptor *currtask=NULL; + struct failedtasklist *tmpftl; + int j; + int currindex; + int totallength=0; + int *enterflags; + int numenterflags, offset; + struct parameterwrapper *pw; + for(j=start;jnumoptionaltaskdescriptors;j++) { + struct optionaltaskdescriptor *otd=fswrapper->optionaltaskdescriptorarray[j]; + if(currtask==NULL) { + currtask=otd->task; + currindex=otd->index; + } else if (currtask!=otd->task||currindex!=otd->index) + break; + totallength+=otd->numenterflags; + } + pw=currtask->descriptorarray[currindex]->queue; + enterflags=RUNMALLOC(totallength*sizeof(int)); + numenterflags=j-start; + offset=0; + for(start;startoptionaltaskdescriptorarray[start]; + enterflags[offset++]=otd->numenterflags; + memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int)); + offset+=otd->numenterflags; + } + tmpftl=RUNMALLOC(sizeof(struct failedtasklist)); + tmpftl->next=list; + tmpftl->task=currtask; + tmpftl->numflags=numenterflags; + tmpftl->flags=enterflags; + list=tmpftl; + } + return list; +} + + + +void enqueuelist(struct ___Object___ * currobj, struct failedtasklist * andlist) { + while(andlist!=NULL) { + struct failedtasklist *tmp=andlist; + struct parameterwrapper *pw=andlist->task->descriptorarray[andlist->index]->queue; + struct parmaeterwrapper *next; + int * flags; + int numflags; + int isnonfailed; + + if (enqueuetasks(pw, currobj->flagptr, currobj, tmp->flags, tmp->numflags)) + currobj->flagptr=pw; + + andlist=andlist->next; + RUNFREE(tmp); + } +} + +void enqueueoptional(struct ___Object___ * currobj, int numfailedfses, int * failedfses, struct taskdescriptor * task, int index) { + struct classanalysiswrapper * classwrapper=NULL; + + /*test what optionaltaskdescriptors are available, find the class + corresponding*/ + if (classanalysiswrapperarray[currobj->type]!=NULL) { + classwrapper = classanalysiswrapperarray[currobj->type]; + } else + return; + + if(task!=NULL) { + /* We have a failure */ + if (failedfses==NULL) { + /* Failed in normal state */ + /*first time the method is invoked*/ + int i,h; + struct fsanalysiswrapper *fswrapper=NULL; + + for(h=0;hnumfsanalysiswrappers;h++) { + struct fsanalysiswrapper * tmp=classwrapper->fsanalysiswrapperarray[h]; + if (tmp->flags==currobj->flag&&checktags(currobj, tmp)) { + //we only match exactly here + fswrapper=tmp; + break; + } + } + if(fswrapper==NULL) //nothing to do in this state + return; + for(i=0;inumtaskfailures;i++) { + int j; + struct taskfailure * taskfail=fswrapper->taskfailurearray[i]; + if (taskfail->task==task&&taskfail->index==index) { + int start=0; + while(startnumoptionaltaskdescriptors) { + struct taskdescriptor *currtask=NULL; + int currindex; + int totallength=0; + int *enterflags; + int numenterflags, offset; + struct parameterwrapper *pw; + for(j=start;jnumoptionaltaskdescriptors;j++) { + struct optionaltaskdescriptor *otd=taskfail->optionaltaskdescriptorarray[j]; + if(currtask==NULL) { + currtask=otd->task; + currindex=otd->index; + } else if (currtask!=otd->task||currindex!=otd->index) + break; + totallength+=otd->numenterflags; + } + pw=currtask->descriptorarray[currindex]->queue; + enterflags=RUNMALLOC(totallength*sizeof(int)); + numenterflags=j-start; + + offset=0; + for(start;startoptionaltaskdescriptorarray[start]; + enterflags[offset++]=otd->numenterflags; + memcpy(&enterflags[offset], otd->enterflags, otd->numenterflags*sizeof(int)); + offset+=otd->numenterflags; + } + //Enqueue this one + if (enqueuetasks(pw, currobj->flagptr, currobj, enterflags, numenterflags)) + currobj->flagptr=pw; + } + } + } + } else { + /* Failed in failed state */ + int i; + int offset=0; + for(i=0;iflagptr; + + /*Remove object from all queues */ + while(flagptr!=NULL) { + struct parameterwrapper *next; + int UNUSED, UNUSED2, UNUSED3; + ObjectHashget(flagptr->objectset, (int) currobj, (int *) &next, &UNUSED, &UNUSED2, &UNUSED3); + ObjectHashremove(flagptr->objectset, (int)currobj); + flagptr=next; + } + + /* Failed in failed state */ + int i; + int offset=0; + for(i=0;inumfses;i++) { + int numfses=currobj->fses[offset++]; + int j; + struct failedtasklist *andlist=NULL; + for(j=0;jfses[offset++]; + struct failedtasklist *currlist=processnormfailstate(classwrapper, currobj, flagstate); + if (andlist==NULL) + andlist=currlist; + else + mergefailedlists(&andlist, currlist); + } + enqueuelist(currobj, andlist); + } + } +} + #endif - void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr) { +int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) { void * taskpointerarray[MAXTASKPARAMS]; +#ifdef OPTIONAL + int failed[MAXTASKPARAMS]; +#endif int j; int numparams=parameter->task->numParameters; int numiterators=parameter->task->numTotal-1; + int retval=1; + int addnormal=1; + int adderror=1; struct taskdescriptor * task=parameter->task; - ObjectHashadd(parameter->objectset, (int) ptr, (int) prevptr, 0);//this add the object to parameterwrapper - + if (ObjectHashcontainskey(parameter->objectset, (int) ptr)) { + /* The object is already here...or it with the existing item */ + int * oldflags; + int oldnumflags; + int oldptr; + int oldstatus; + int *mergedflags; + ObjectHashget(parameter->objectset, (int) ptr, & oldptr, (int *) &oldflags, &oldnumflags, &oldstatus); + mergedflags=domergeor(oldflags, oldnumflags, enterflags, numenterflags); + ObjectHashupdate(parameter->objectset, (int) ptr, oldptr, mergedflags, oldnumflags+numenterflags, oldstatus||(enterflags==NULL)); + + RUNFREE(oldflags); + RUNFREE(enterflags); + + //only add if truly needed + if (oldstatus) + addnormal=0; + if (oldnumflags>0) + adderror=0; + + retval=0; + } else { + ObjectHashadd(parameter->objectset, (int) ptr, (int) prevptr, (int) enterflags, numenterflags, enterflags==NULL);//this add the object to parameterwrapper + } + /* Add enqueued object to parameter vector */ taskpointerarray[parameter->slot]=ptr; +#ifdef OPTIONAL + failed[parameter->slot]=(enterflags!=NULL); +#endif /* Reset iterators */ for(j=0;jiterators[j], taskpointerarray)) - toiNext(¶meter->iterators[j], taskpointerarray); + if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))) + toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)); else if (j>0) { /* Need to backtrack */ toiReset(¶meter->iterators[j]); @@ -815,7 +895,7 @@ void flagorandinit(void * ptr, int ormask, int andmask) { goto backtrackinit; } else { /* Nothing to enqueue */ - return; + return retval; } } @@ -827,15 +907,14 @@ void flagorandinit(void * ptr, int ormask, int andmask) { tpd->task=task; tpd->numParameters=numiterators+1; tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1)); - for(j=0;j<=numiterators;j++){ #ifdef OPTIONAL -#ifdef DEBUG - struct ___Object___ * obj = (struct ___Object___ *)taskpointerarray[j]; - if(obj->failedstatus==1) - printf("parameter %i used as optional for task %s\n", obj->type, task->name); -#endif + tpd->failed=RUNMALLOC(sizeof(int)*(numiterators+1)); #endif + for(j=0;j<=numiterators;j++){ tpd->parameterArray[j]=taskpointerarray[j];//store the actual parameters +#ifdef OPTIONAL + tpd->failed[j]=failed[j]; +#endif } /* Enqueue task */ if ((!gencontains(failedtasks, tpd)&&!gencontains(activetasks,tpd))) { @@ -847,12 +926,12 @@ void flagorandinit(void * ptr, int ormask, int andmask) { /* This loop iterates to the next parameter combination */ if (numiterators==0) - return; + return retval; for(j=numiterators-1; jiterators[j], taskpointerarray)) - toiNext(¶meter->iterators[j], taskpointerarray); + if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))) + toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed)); else if (j>0) { /* Need to backtrack */ toiReset(¶meter->iterators[j]); @@ -860,10 +939,11 @@ void flagorandinit(void * ptr, int ormask, int andmask) { goto backtrackinc; } else { /* Nothing more to enqueue */ - return; + return retval; } } } + return retval; } /* Handler for signals. The signals catch null pointer errors and @@ -906,8 +986,24 @@ void removereadfd(int fd) { #define OFFSET 0 #endif +#ifdef OPTIONAL + int * fsescopy(int *src, int len) { + int *dst; + if (src==NULL) + return NULL; + dst=RUNMALLOC(len*sizeof(int)); + memcpy(dst, src, len*sizeof(int)); + return dst; + } +#endif + void executetasks() { void * taskpointerarray[MAXTASKPARAMS+OFFSET]; +#ifdef OPTIONAL + int * fsesarray[MAXTASKPARAMS]; + int * oldfsesarray[MAXTASKPARAMS]; + int numfsesarray[MAXTASKPARAMS]; +#endif /* Set up signal handlers */ struct sigaction sig; @@ -980,25 +1076,34 @@ void executetasks() { int j; /* Check that object is still in queue */ #ifdef OPTIONAL - struct ___Object___ * obj = (struct ___Object___ *)parameter; - if(obj->failedstatus==1){ - struct ___Object___ *temp=NULL; - struct parameterwrapper * ptr; - struct ObjectNode * node = pw->objectset->listhead; - while(node!=NULL){ - temp=(struct ___Object___ *)node->key; - if(temp->failedstatus==1 && temp->hashcode==obj->hashcode){ - if(temp==obj) - goto parameterpresent; + { + int UNUSED, UNUSED2; + int *flags; + int numflags, isnonfailed; + int failed=currtpd->failed[i]; + if (!ObjectHashget(pw->objectset, (int) parameter, &UNUSED, (int *) &flags, &numflags, &isnonfailed)) { + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd->failed); + RUNFREE(currtpd); + goto newtask; + } else { + if (failed&&(flags!=NULL)) { + //Failed parameter + fsesarray[i]=flags; + numfsesarray[i]=numflags; + } else if (!failed && isnonfailed) { + //Non-failed parameter + fsesarray[i]=NULL; + numfsesarray[i]=0; + } else { + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd->failed); + RUNFREE(currtpd); + goto newtask; } - node=node->next; } - RUNFREE(currtpd->parameterArray); - RUNFREE(currtpd); - goto newtask; } - else -#endif +#else { if (!ObjectHashcontainskey(pw->objectset, (int) parameter)) { RUNFREE(currtpd->parameterArray); @@ -1006,6 +1111,7 @@ void executetasks() { goto newtask; } } +#endif parameterpresent: ; /* Check that object still has necessary tags */ @@ -1042,20 +1148,13 @@ void executetasks() { restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse); #ifdef OPTIONAL -#ifdef DEBUG - printf("%i object(s) restored\n", currtpd->task->numParameters); -#endif - for(counter=0; countertask->numParameters; counter++){ - //remove the object from the previous parameterwrapper (maybe not necessary) - //do a new instance of the object. It allows the restored object to be used by other tasks as a non optional arg. - struct ___Object___ * currobj = RUNMALLOC(sizeof(struct ___Object___)); - (*currobj)=(*(struct ___Object___ *)currtpd->parameterArray[counter]); - currobj->numexitfses = 0; - currobj->exitfses = NULL; - currobj->otds=NULL; - currobj->hashcode=(int)currobj; - enqueueoptional( currobj ); + //enqueue as failed + enqueueoptional(currtpd->parameterArray[counter], numfsesarray[counter], fsesarray[counter], currtpd->task, counter); + + //free fses copies + if (fsesarray[counter]!=NULL) + RUNFREE(fsesarray[counter]); } #endif freeRuntimeHash(forward); @@ -1074,6 +1173,14 @@ void executetasks() { #ifdef PRECISE_GC ((int *)taskpointerarray)[0]=currtpd->task->numParameters; taskpointerarray[1]=NULL; +#endif +#ifdef OPTIONAL + //get the task flags set + for(i=0;ifses; + fsesarray[i]=fsescopy(fsesarray[i], numfsesarray[i]); + ((struct ___Object___ *)taskpointerarray[i+OFFSET])->fses=fsesarray[i]; + } #endif if(debugtask){ printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount)); @@ -1081,7 +1188,13 @@ void executetasks() { printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount)); } else ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray); - + + for(i=0;itagobjindex=0; } else if (it->numtags>0) { it->tagobjindex=0; +#ifdef OPTIONAL + it->failedstate=0; +#endif } else { ObjectHashiterator(it->objectset, &it->it); +#ifdef OPTIONAL + it->failedstate=0; +#endif } } -int toiHasNext(struct tagobjectiterator *it, void ** objectarray) { +int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) { if (it->istag) { /* Iterate tag */ /* Get object with tags */ @@ -1290,11 +1409,50 @@ int toiHasNext(struct tagobjectiterator *it, void ** objectarray) { if (!containstag(objptr,tag2)) return 0; } +#ifdef OPTIONAL + if (it->failedstate==1) { + int UNUSED, UNUSED2; + int * flags; + int isnonfailed; + ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed); + if (flags!=NULL) { + return 1; + } else { + it->tagobjindex++; + it->failedstate=0; + return 0; + } + } else { + int UNUSED, UNUSED2; + int * flags; + int isnonfailed; + ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed); + if (!isnonfailed) { + it->failedstate=1; + } + return 1; + } +#endif return 1; } else { struct ArrayObject *ao=(struct ArrayObject *) objptr; int tagindex; int i; +#ifdef OPTIONAL + if (it->failedstate==1) { + int UNUSED, UNUSED2; + int * flags; + int isnonfailed; + struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, it->tagobjindex); + ObjectHashget(it->objectset, (int) objptr, &UNUSED, (int *) &flags, &UNUSED2, &isnonfailed); + if (flags!=NULL) { + return 1; + } else { + it->failedstate=0; + it->tagobjindex++; + } + } +#endif for(tagindex=it->tagobjindex;tagindex___cachedCode___;tagindex++) { struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex); if (!ObjectHashcontainskey(it->objectset, (int) objptr)) @@ -1304,6 +1462,18 @@ int toiHasNext(struct tagobjectiterator *it, void ** objectarray) { if (!containstag(objptr,tag2)) goto nexttag; } +#ifdef OPTIONAL + { + int UNUSED, UNUSED2; + int flags, isnonfailed; + struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex); + ObjectHashget(it->objectset, (int) objptr, &UNUSED, &flags, &UNUSED2, &isnonfailed); + if (!isnonfailed) { + it->failedstate=1; + } + } +#endif + it->tagobjindex=tagindex; return 1; nexttag: ; @@ -1312,7 +1482,26 @@ int toiHasNext(struct tagobjectiterator *it, void ** objectarray) { return 0; } } else { +#ifdef OPTIONAL + if (it->failedstate==1) { + if (Objdata2(&it->it)) + return 1; + else { + it->failedstate=0; + Objnext(&it->it); + } + } + if (ObjhasNext(&it->it)) { + if (!Objdata4(&it->it)) { + //failed state only + it->failedstate=1; + } + return 1; + } else + return 0; +#else return ObjhasNext(&it->it); +#endif } } @@ -1330,7 +1519,7 @@ int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) { return objptr==ptr; } -void toiNext(struct tagobjectiterator *it , void ** objectarray) { +void toiNext(struct tagobjectiterator *it , void ** objectarray OPTARG(int * failed)) { /* hasNext has all of the intelligence */ if(it->istag) { /* Iterate tag */ @@ -1349,18 +1538,48 @@ void toiNext(struct tagobjectiterator *it , void ** objectarray) { struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]]; struct ___Object___ *objptr=tag->flagptr; if (objptr->type!=OBJECTARRAYTYPE) { +#ifdef OPTIONAL + failed[it->slot]=it->failedstate; + objectarray[it->slot]=objptr; + if (it->failedstate==0) { + it->failedstate=1; + } else { + it->failedstate=0; + it->tagobjindex++; + } +#else it->tagobjindex++; objectarray[it->slot]=objptr; +#endif } else { struct ArrayObject *ao=(struct ArrayObject *) objptr; +#ifdef OPTIONAL + failed[it->slot]=it->failedstate; + objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex); + if (it->failedstate==0) { + it->failedstate=1; + } else { + it->failedstate=0; + it->tagobjindex++; + } +#else objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++); +#endif } } else { /* Iterate object */ objectarray[it->slot]=(void *)Objkey(&it->it); +#ifdef OPTIONAL + failed[it->slot]=it->failedstate; + if (it->failedstate==0) { + it->failedstate=1; + } else { + it->failedstate=0; + Objnext(&it->it); + } +#else Objnext(&it->it); +#endif } } - - #endif -- 2.34.1