--- /dev/null
+package Analysis.TaskStateAnalysis;
+import IR.*;
+import Analysis.TaskStateAnalysis.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import java.util.*;
+import Util.Edge;
+
+
+public class EGEdge extends Edge{
+ EGTaskNode target;
+
+
+ public EGEdge(EGTaskNode target){
+ super(target);
+ this.target = target;
+ }
+
+ public EGTaskNode getTarget(){
+ return target;
+ }
+
+ public int hashCode(){
+ return target.hashCode();
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof EGEdge) {
+ EGEdge e=(EGEdge)o;
+ return e.target.equals(target);
+ }
+ return false;
+ }
+
+
+}
private int type = 0;
private FlagState fs;
private TaskDescriptor td;
-
+ protected HashSet edges = new HashSet();
public EGTaskNode(){
super("default");
this.fs = null;
this.fs = fs;
this.td = td;
}
+
+ public int hashCode(){
+ return getLabel().hashCode();
+ }
+
+ public boolean equals(Object o){
+ if(o instanceof EGTaskNode){
+ EGTaskNode tn=(EGTaskNode) o;
+ return (tn.getLabel().compareTo(this.getLabel())==0) ? true : false;
+ }
+ return false;
+ }
+ public HashSet getEdgeSet(){
+ return edges;
+ }
+
+ public void addEdge(EGEdge newedge) {
+ newedge.setSource(this);
+ edges.add(newedge);
+ EGTaskNode tonode=newedge.getTarget();
+ tonode.inedges.addElement(newedge);
+ }
+
+ public Iterator edges(){
+ return edges.iterator();
+ }
+
public TaskDescriptor getTD(){
return td;
}
}
}
- //clean the graph to remove doubles due to reinjection of non totally processed fses in the fifo
- graph = clean(graph);
}
}
//link to the parent.
if (graph.containsKey(key2)){
target = (EGTaskNode)graph.get(key2);
- TEdge newedge=new TEdge(target);
+ EGEdge newedge=new EGEdge(target);
tn.addEdge(newedge);
}
else {
- TEdge newedge=new TEdge(target);
+ EGEdge newedge=new EGEdge(target);
tn.addEdge(newedge);
}
//put child in graph
}
if (graph.containsKey(key2)){
target = (EGTaskNode)graph.get(key2);
- TEdge newedge=new TEdge(target);
+ EGEdge newedge=new EGEdge(target);
tn.addEdge(newedge);
}
else {
- TEdge newedge=new TEdge(target);
+ EGEdge newedge=new EGEdge(target);
tn.addEdge(newedge);
}
graph.put(key2, target);
}
}
- //removes the duplicated edges
- private Hashtable clean(Hashtable ht){
- Hashtable cleaned = new Hashtable();
- Collection c = ht.values();
- for ( Iterator it = c.iterator(); it.hasNext();){
- EGTaskNode tn = (EGTaskNode)it.next();
- Vector v = tn.getEdgeVector();
- v = removeDouble(v);
- tn.removeAllEdges();
- tn.addEdge(v);
- cleaned.put(tn.getuid(), tn);
- }
- return cleaned;
- }
-
- //removes all the edge doubles in vector v
- private Vector removeDouble(Vector v){
-
- Vector vcleaned = new Vector();
- for (Iterator it = v.iterator(); it.hasNext();){
-
- TEdge edge = (TEdge)it.next();
- int contains = 0;
- for (Iterator it2 = vcleaned.iterator(); it2.hasNext();){
- if (((EGTaskNode)edge.getTarget()).getuid()==((EGTaskNode)((TEdge)it2.next()).getTarget()).getuid()) contains = 1;
- }
-
- if (contains == 0) vcleaned.add(edge);
- }
-
- return vcleaned;
- }
-
//test if a flagstate has been entirely processed
private boolean isFinished(FlagState fs){
for(Iterator it2 = tn.edges();it2.hasNext();){
- output.println("\t"+tn.getLabel()+" -> "+((EGTaskNode)((TEdge)it2.next()).getTarget()).getLabel()+";");
+ output.println("\t"+tn.getLabel()+" -> "+((EGTaskNode)((EGEdge)it2.next()).getTarget()).getLabel()+";");
}
}
}
--- /dev/null
+package Analysis.TaskStateAnalysis;
+import java.util.*;
+import IR.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import java.io.*;
+import Util.Edge;
+
+public class MyOptional{
+ public TaskDescriptor td;
+ public HashSet flagstates;
+ public int depth;
+ public HashSet<Hashtable> exitfses;
+ public Predicate predicate;
+
+ protected MyOptional(TaskDescriptor td, HashSet flagstates, int depth, Predicate predicate){
+ this.td = td;
+ this.flagstates = flagstates;
+ this.depth = depth;
+ this.exitfses = new HashSet();
+ this.predicate = predicate;
+
+ }
+
+ public boolean equals(Object o){
+ if (o instanceof MyOptional) {
+ MyOptional myo = (MyOptional) o;
+ if (this.td.getSymbol().compareTo(myo.td.getSymbol())==0)
+ if(this.flagstates.equals(myo.flagstates))
+ return true;
+ return false;
+ }
+ else return false;
+
+ }
+
+ public int hashCode() {
+ return td.hashCode()+flagstates.hashCode()+exitfses.hashCode();
+ }
+
+ public String tostring() {
+ return "Optional task "+td.getSymbol();
+ }
+
+}
--- /dev/null
+package Analysis.TaskStateAnalysis;
+import java.util.*;
+import IR.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import Util.Edge;
+
+public class Predicate{
+ public HashSet vardescriptors;
+ public Hashtable<VarDescriptor, HashSet<FlagExpressionNode>> flags;
+ public Hashtable<VarDescriptor, TagExpressionList> tags; //if there is a tag change, we stop the analysis
+
+ public Predicate(){
+ this.vardescriptors = new HashSet();
+ this.flags = new Hashtable();
+ this.tags = new Hashtable();
+ }
+}
private String classname;
private State state;
private TaskAnalysis taskanalysis;
- //private Hashtable<Integer, HashSet> visited;
- //private static int analysisid=0;
+ private Hashtable<ClassDescriptor, HashSet> myoptionals;
+
+ private ClassDescriptor processedclass;
+
+
+ public Hashtable<ClassDescriptor, Hashtable<FlagState, HashSet>> getResult(){
+ return safeexecution;
+ }
+
+ public Hashtable<ClassDescriptor, HashSet> getMyOptionals(){
+ return myoptionals;
+ }
/*Structure that stores a possible optional
task which would be safe to execute and
the possible flagstates the object could
be in before executing the task during an
execution without failure*/
-
- public class MyOptional{
- public TaskDescriptor td;
- public HashSet flagstates;
- public int depth;
- public HashSet<Hashtable> exitfses;
- public Predicate predicate;
-
- protected MyOptional(TaskDescriptor td, HashSet flagstates, int depth, Predicate predicate){
- this.td = td;
- this.flagstates = flagstates;
- this.depth = depth;
- this.exitfses = new HashSet();
- this.predicate = predicate;
- }
-
- public boolean equal(MyOptional myo){
- if (this.td.getSymbol().compareTo(myo.td.getSymbol())==0)
- if(this.depth == myo.depth)
- if(this.flagstates.equals(myo.flagstates))
- return true;
- return false;
- }
- }
-
- public class Predicate{
- public HashSet vardescriptors;
- public Hashtable<VarDescriptor, HashSet<FlagExpressionNode>> flags;
- public Hashtable<VarDescriptor, TagExpressionList> tags; //if there is a tag change, we stop the analysis
-
- public Predicate(){
- this.vardescriptors = new HashSet();
- this.flags = new Hashtable();
- this.tags = new Hashtable();
- }
- }
-
+
/*Constructor*/
public SafetyAnalysis(Hashtable executiongraph, State state, TaskAnalysis taskanalysis){
this.executiongraph = executiongraph;
this.reducedgraph = new Hashtable();
this.state = state;
this.taskanalysis = taskanalysis;
- //this.visited = new Hashtable();
+ this.myoptionals = new Hashtable();
}
/*finds the the source node in the execution graph*/
while (e.hasMoreElements()) {
System.out.println("\nAnalysing class :");
- ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
- classname = cdtemp.getSymbol();
+ processedclass=(ClassDescriptor)e.nextElement();
+ classname = processedclass.getSymbol();
+ HashSet newhashset = new HashSet();
+ myoptionals.put(processedclass, newhashset);
Hashtable cdhashtable = new Hashtable();
System.out.println("\t"+classname+ "\n");
createDOTFile( classname );
reducedgraph.clear();
- Collection fses = ((Hashtable)taskanalysis.flagstates.get(cdtemp)).values();
+ Collection fses = ((Hashtable)taskanalysis.flagstates.get(processedclass)).values();
Iterator itfses = fses.iterator();
while (itfses.hasNext()) {
FlagState fs = (FlagState)itfses.next();
cdhashtable.put(fs, availabletasks);
}
- safeexecution.put(cdtemp, cdhashtable);
+ safeexecution.put(processedclass, cdhashtable);
}
System.out.println("\t\t------------");
}
}
+
+ System.out.println("\n\n\n\tMyoptionals contains : ");
+ for(Iterator myoit = myoptionals.get(cdtemp).iterator(); myoit.hasNext();){
+ MyOptional mm = (MyOptional)myoit.next();
+ System.out.println("\t\tTASK "+mm.td.getSymbol()+"\n");
+ System.out.println("\t\tDepth : "+mm.depth);
+ System.out.println("\t\twith flags :");
+ for(Iterator myfses = mm.flagstates.iterator(); myfses.hasNext();){
+ System.out.println("\t\t\t"+((FlagState)myfses.next()).getTextLabel());
+ }
+ System.out.println("\t\tand exitflags :");
+ for(Iterator fseshash = mm.exitfses.iterator(); fseshash.hasNext();){
+ HashSet temphs = (HashSet)fseshash.next();
+ System.out.println("");
+ for(Iterator exfses = temphs.iterator(); exfses.hasNext();){
+ System.out.println("\t\t\t"+((FlagState)exfses.next()).getTextLabel());
+ }
+ }
+ Predicate predicate = mm.predicate;
+ System.out.println("\t\tPredicate constains :");
+ for(Iterator varit = predicate.vardescriptors.iterator(); varit.hasNext();){
+ VarDescriptor vard = (VarDescriptor)varit.next();
+ System.out.println("\t\t\tClass "+vard.getType().getClassDesc().getSymbol());
+ }
+ System.out.println("\t\t------------");
+ }
}
+
+
}
/*Marks the executiongraph :
extremity.mark();
//calls doGraphMarking recursively with the next nodes as params
for( Iterator it = extremity.edges(); it.hasNext(); ){
- TEdge edge = (TEdge)it.next();
+ EGEdge edge = (EGEdge)it.next();
doGraphMarking((EGTaskNode)edge.getTarget());
}
}
private void testIfOptional(EGTaskNode tn){
for(Iterator edges = tn.edges(); edges.hasNext();){
- TEdge edge = (TEdge)edges.next();
+ EGEdge edge = (EGEdge)edges.next();
EGTaskNode nexttn = (EGTaskNode)edge.getTarget();
if (nexttn.getTD()!=null)
if(nexttn.getTD().isOptional(classname))
private void testIfMultiple(EGTaskNode tn){
for(Iterator edges = tn.edges(); edges.hasNext();){
- TEdge edge = (TEdge)edges.next();
+ EGEdge edge = (EGEdge)edges.next();
EGTaskNode nexttn = (EGTaskNode)edge.getTarget();
+ if (nexttn.getTD() == null ) return;//to be fixed
if( nexttn.getTD().numParameters() > 1 ){
nexttn.setMultipleParams();
}
//maybe a little bug to fix
private void testIfRuntime(EGTaskNode tn){
for(Iterator edges = tn.edges(); edges.hasNext();){
- TEdge edge = (TEdge)edges.next();
+ EGEdge edge = (EGEdge)edges.next();
EGTaskNode nexttn = (EGTaskNode)edge.getTarget();
if( ((String)nexttn.getName()).compareTo("Runtime") == 0 )
nexttn.setAND();
Vector vtemp = new Vector();
Vector tomark = new Vector();
for(Iterator edges = tn.edges(); edges.hasNext();){
- TEdge edge = (TEdge)edges.next();
+ EGEdge edge = (EGEdge)edges.next();
EGTaskNode nexttn = (EGTaskNode)edge.getTarget();
int contains = 0;
for (Iterator it = vtemp.iterator(); it.hasNext();){
//maybe little bug to fix
private void testIfNextIsSelfLoop(EGTaskNode tn){
for(Iterator edges = tn.edges(); edges.hasNext();){
- TEdge edge = (TEdge)edges.next();
+ EGEdge edge = (EGEdge)edges.next();
EGTaskNode nexttn = (EGTaskNode)edge.getTarget();
if(nexttn.isSelfLoop()) nexttn.setAND();
}
if( !((Iterator)tn.edges()).hasNext() || tn.isSelfLoop()){
HashSet fstemp = new HashSet();
fstemp.add(tn.getFS());
- MyOptional mo = new MyOptional(tn.getTD(), fstemp, depth, temppredicate);
+ MyOptional mo = new MyOptional(tn.getTD(), fstemp, depth, temppredicate);
+ myoptionals.get(processedclass).add(mo);
temp.add(mo);
return temp;
}
HashSet fstemp = new HashSet();
fstemp.add(tn.getFS());
MyOptional mo = new MyOptional(tn.getTD(), fstemp, depth, temppredicate);
+ myoptionals.get(processedclass).add(mo);
temp = computeEdges(tn, newdepth, newhashset, temppredicate);
temp.add(mo);
return temp;
/*check if there has been a tag Change*/
private boolean tagChange(EGTaskNode tn){
+ if(tn.getTD() == null) return false;//to be fixed
FlatMethod fm = state.getMethodFlat(tn.getTD());
FlatNode fn = (FlatNode)fm;
Hashtable andlist = new Hashtable();
Vector orlist = new Vector();
for(Iterator edges = tn.edges(); edges.hasNext();){
- EGTaskNode tntemp = (EGTaskNode)((TEdge)edges.next()).getTarget();
+ EGTaskNode tntemp = (EGTaskNode)((EGEdge)edges.next()).getTarget();
if(tntemp.type() == OR) orlist.add(tntemp);
else if(tntemp.type() == AND){
if(andlist.containsKey(tntemp.getName())){
return A;
}
- private void removeDoubles( HashSet A ){
+ /*private void removeDoubles( HashSet A ){
//remove duplicated MyOptionals (might happend in few cases)
Vector toremove = new Vector();
int i = 0;
for(Iterator itA3 = itA2; itA3.hasNext();){
MyOptional myA2 = (MyOptional)itA3.next();
if(myA2.equal(myA)){
- myA.depth = (myA.depth < myA2.depth) ? myA.depth : myA2.depth;
+ //myA.depth = (myA.depth < myA2.depth) ? myA.depth : myA2.depth;
toremove.add(myA2);
System.out.println("removed!");
}
}
for( Iterator it = toremove.iterator(); it.hasNext();)
A.remove(it.next());
- }
+ }*/
private HashSet createIntersection( HashSet A, HashSet B){
HashSet result = new HashSet();
for(Iterator varit = B.vardescriptors.iterator(); varit.hasNext();){
VarDescriptor vd = (VarDescriptor)varit.next();
if(result.vardescriptors.contains(vd))System.out.println("Already in ");
- else result.vardescriptors.add(vd);
+ else {
+ System.out.println("Not already in...");
+ result.vardescriptors.add(vd);
+ }
}
for(Iterator varit = result.vardescriptors.iterator(); varit.hasNext();){
VarDescriptor vd = (VarDescriptor)varit.next();
import java.util.*;
import java.io.*;
import Util.Relation;
+import Analysis.TaskStateAnalysis.FlagState;
+import Analysis.TaskStateAnalysis.MyOptional;
public class BuildCode {
State state;
private int maxtaskparams=0;
ClassDescriptor[] cdarray;
TypeDescriptor[] arraytable;
-
+
public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) {
state=st;
this.temptovar=temptovar;
if (state.TASK)
outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
+ if (state.TASK&&state.OPTIONAL){
+ generateOptionalArrays(outoptionalarrays, state.getAnalysisResult(), state.getMyOptionals());
+ outoptionalarrays.close();
+ }
+
/* Output structure definitions for repair tool */
if (state.structfile!=null) {
outstructs.close();
outmethod.close();
+
- if (state.TASK&&state.OPTIONAL) {
- generateOptionalArrays(outoptionalarrays);
- outoptionalarrays.close();
- }
}
private int maxcount=0;
}
}
- void generateOptionalArrays(PrintWriter output) {
+ void generateOptionalArrays(PrintWriter output, Hashtable<ClassDescriptor, Hashtable<FlagState, HashSet>> safeexecution, Hashtable myoptionals) {
- SymbolTable classes = state.getClassSymbolTable();
+ /* SymbolTable classes = state.getClassSymbolTable();
for( Iterator it = classes.getAllDescriptorsIterator(); it.hasNext();){
ClassDescriptor cd = (ClassDescriptor)it.next();
output.println("Class "+cd.getSymbol());
int flagid=1<<((Integer)flags.get(fd)).intValue();
output.println("\tFlag associated with "+fd.getSymbol()+" : 0x"+Integer.toHexString(flagid)+" bx"+Integer.toBinaryString(flagid));
}
- }
+ }*/
+
+
+ int fscounter = 0;
+ int myocounter = 0;
+ int classescounter = 0;
+ Enumeration e = safeexecution.keys();
+ while (e.hasMoreElements()) {
+ //get the class
+ ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
+ for(Iterator myoit = ((HashSet)myoptionals.get(cdtemp)).iterator(); myoit.hasNext();){
+ MyOptional myo = (MyOptional)myoit.next();
+ output.println("struct myoptional myoptional_"+"/*ID to determine*/"+"_"+"cdtemp.getsafeSymbol()"+"={");
+ //insert code to generate the myoptional
+ output.println("};");
+ }
+ classescounter++;
+ Hashtable hashtbtemp = safeexecution.get(cdtemp);
+ Enumeration fses = hashtbtemp.keys();
+ while(fses.hasMoreElements()){
+ //get all the possible falgstates reachable by an object
+ FlagState fs = (FlagState)fses.nextElement();
+ fscounter++;
+ //get the set of MyOptionnals
+ HashSet availabletasks = (HashSet)hashtbtemp.get(fs);
+ //iterate through the MyOptionals
+ for(Iterator mos = availabletasks.iterator(); mos.hasNext();){
+ MyOptional mm = (MyOptional)mos.next();
+ myocounter++;
+ }
+ output.println("struct myoptional * myoptionals_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {");
+ for(int i=0; i<myocounter; i++){
+ if(i==myocounter-1) output.println("&myoptional_"+"/*ID to determine*/"+"_"+cdtemp.getSafeSymbol()+"};");
+
+ else output.println("&myoptional_"+"/*ID to determine*/"+"_"+cdtemp.getSafeSymbol()+",");
+ }
+ myocounter = 0;
+ output.println("int flagstatednf_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
+ for(Iterator flags = fs.getFlags(); flags.hasNext();){
+ FlagDescriptor flagd = (FlagDescriptor)flags.next();
+ //process the fs, maybe add int tagstate[]
+ }
+ output.println("};");
+ output.println("struct structB structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"={");
+ output.println("/* number of dnf terms (to add)*/,");
+ output.println("flagstatednf_"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+ output.println("/* number of tags (to add)*/,");
+ output.println("tags_"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+ output.println("/* number of myoptionals */,");
+ output.println("myoptionals_FS"+fscounter+"_"+cdtemp.getSafeSymbol());
+ output.println("};");
+ }
+ output.println("struct structB * structBs_"+cdtemp.getSafeSymbol()+"[] = {");
+ for(int i = 0; i<fscounter; i++){
+ if(i==fscounter-1) output.println("&structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"};");
+
+ else output.println("&structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+ }
+ fscounter = 0;
+ output.println("struct structA structA_"+cdtemp.getSafeSymbol()+"={");
+ output.println("/* class identifier */,");
+ output.println("structBs_"+cdtemp.getSafeSymbol()+"};");
+ }
+ output.println("struct structA * classesarray[]={");
+ e = safeexecution.keys();
+ int j = 0;
+ while (e.hasMoreElements()) {
+ ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
+ j++;
+ if(j==classescounter) output.println("&structA_"+cdtemp.getSafeSymbol()+"};");
+ else output.println("&structA_"+cdtemp.getSafeSymbol()+",");
+ }
+ output.println("int numclasses = "+classescounter+";");
+
}
-
+
}
this.arraytypes=new HashSet();
this.arraytonumber=new Hashtable();
this.tagmap=new Hashtable();
+ this.analysisresult=new Hashtable();
+ this.myoptionals=new Hashtable();
}
public void addParseNode(ParseNode parsetree) {
parsetrees.add(parsetree);
}
+ public void storeAnalysisResult(Hashtable result){
+ analysisresult = result;
+ }
+
+ public void storeMyOptionals(Hashtable myoptionals){
+ this.myoptionals=myoptionals;
+ }
+
+ public Hashtable getAnalysisResult(){
+ return analysisresult;
+ }
+
+ public Hashtable getMyOptionals(){
+ return myoptionals;
+ }
+
/** Boolean flag which indicates whether compiler is compiling a task-based
* program. */
public boolean WEBINTERFACE=false;
private int numtasks=0;
private int arraycount=0;
+ private Hashtable analysisresult;
+ private Hashtable myoptionals;
+
private Hashtable tagmap;
private int numtags=0;
BuildFlat bf=new BuildFlat(state,tu);
bf.buildFlat();
-
if (state.TASKSTATE) {
CallGraph callgraph=new CallGraph(state);
TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
ta.taskAnalysis();
TaskGraph tg=new TaskGraph(state, ta);
tg.createDOTfiles();
-
+
if (state.OPTIONAL) {
ExecutionGraph et=new ExecutionGraph(state, ta);
et.createExecutionGraph();
SafetyAnalysis sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta);
sa.buildPath();
+ state.storeAnalysisResult(sa.getResult());
+ state.storeMyOptionals(sa.getMyOptionals());
}
-
+
if (state.WEBINTERFACE) {
GarbageAnalysis ga=new GarbageAnalysis(state, ta);
WebInterface wi=new WebInterface(state, ta, tg, ga, taganalysis);
JhttpServer serve=new JhttpServer(8000,wi);
serve.run();
}
-
-
+
+
}
+
if (state.DSM) {
CallGraph callgraph=new CallGraph(state);
LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
}
-
+
BuildCode bc=new BuildCode(state, bf.getMap(), tu);
bc.buildCode();
+
System.exit(0);
}
-
+
/** Reads in a source file and adds the parse tree to the state object. */
private static void readSourceFile(State state, String sourcefile) throws Exception {