From: bdemsky Date: Mon, 21 May 2007 02:36:50 +0000 (+0000) Subject: Changes: X-Git-Tag: preEdgeChange~582 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=797b76645a04a6bd4d51c2846612657054d0c73e;p=IRC.git Changes: (1) create tag analysis that determines which objects a given task can create (2) change makefile to build all current classes so partial makes should work (3) fix bugs in call graph (4) support passing tags into methods (5) support creating objects with tags inside of methods (6) fix other bugs --- diff --git a/Robust/src/Analysis/CallGraph/CallGraph.java b/Robust/src/Analysis/CallGraph/CallGraph.java index c8129723..72c0232e 100644 --- a/Robust/src/Analysis/CallGraph/CallGraph.java +++ b/Robust/src/Analysis/CallGraph/CallGraph.java @@ -7,6 +7,7 @@ import IR.Flat.FKind; import java.util.*; import IR.ClassDescriptor; import IR.MethodDescriptor; +import IR.TypeDescriptor; public class CallGraph { State state; @@ -50,6 +51,11 @@ public class CallGraph { } } + + public Set getMethods(MethodDescriptor md, TypeDescriptor type) { + return getMethods(md); + } + /** Given a call to MethodDescriptor, lists the methods which could actually be called due to virtual dispatch. */ public Set getMethods(MethodDescriptor md) { @@ -109,7 +115,8 @@ public class CallGraph { if (fn.kind()==FKind.FlatCall) { FlatCall fc=(FlatCall)fn; MethodDescriptor calledmethod=fc.getMethod(); - Set methodsthatcouldbecalled=getMethods(calledmethod); + Set methodsthatcouldbecalled=fc.getThis()==null?getMethods(calledmethod): + getMethods(calledmethod, fc.getThis().getType()); if (!methodmap.containsKey(md)) methodmap.put(md,new HashSet()); ((HashSet)methodmap.get(md)).addAll(methodsthatcouldbecalled); diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java index e66231c8..b9890f64 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java +++ b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java @@ -220,16 +220,24 @@ public class FlagState extends GraphNode { for (Enumeration en_tags=getTags();en_tags.hasMoreElements();){ TagDescriptor td=(TagDescriptor)en_tags.nextElement(); switch (tags.get(td).intValue()){ - case ONETAG: - label+=", "+td.toString()+"(1)"; - break; - case MULTITAGS: - label+=", "+td.toString()+"(n)"; - break; - default: - break; + case ONETAG: + if (label==null) + label=td.toString()+"(1)"; + else + label+=", "+td.toString()+"(1)"; + break; + case MULTITAGS: + if (label==null) + label=td.toString()+"(n)"; + else + label+=", "+td.toString()+"(n)"; + break; + default: + break; } } + if (label==null) + return ""; return label; } diff --git a/Robust/src/Analysis/TaskStateAnalysis/TagAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TagAnalysis.java new file mode 100644 index 00000000..72ad3b86 --- /dev/null +++ b/Robust/src/Analysis/TaskStateAnalysis/TagAnalysis.java @@ -0,0 +1,203 @@ +package Analysis.TaskStateAnalysis; + +import java.util.Hashtable; +import java.util.Stack; +import java.util.Set; +import java.util.HashSet; +import java.util.Iterator; +import Util.Edge; +import Analysis.CallGraph.CallGraph; +import IR.SymbolTable; +import IR.State; +import IR.TagDescriptor; +import IR.TaskDescriptor; +import IR.MethodDescriptor; +import IR.Flat.*; + +public class TagAnalysis { + State state; + Hashtable flagmap; + Stack tovisit; + Hashtable discovered; + Hashtable tasktotagbindings; + Hashtable tasktoflagstates; + CallGraph callgraph; + + public TagAnalysis(State state, CallGraph callgraph) { + this.state=state; + this.flagmap=new Hashtable(); + this.discovered=new Hashtable(); + this.tovisit=new Stack(); + this.tasktoflagstates=new Hashtable(); + this.tasktotagbindings=new Hashtable(); + this.callgraph=callgraph; + doAnalysis(); + } + + public Set getFlagStates(TaskDescriptor task) { + return (Set)tasktoflagstates.get(task); + } + + private void doAnalysis() { + Set rootset=computeRootSet(); + computeTagBindings(rootset); + TagBinding.SCC scc=TagBinding.DFS.computeSCC(discovered.keySet()); + for(int i=0;i tagdescriptors */ + Hashtable parammap=new Hashtable(); + int offset=md.isStatic()?0:1; + + for(int i=0;i=0) { + TagDescriptor tag=tb.getBinding(offsetindex); + + if (tag!=null) { + parammap.put(temp,tag); + } + } + } + HashSet newtags=new HashSet(); + computeCallsFlags(fm, parammap, newtags, tb.getAllocations()); + for(Iterator tagit=newtags.iterator();tagit.hasNext();) { + TagBinding newtag=(TagBinding)tagit.next(); + Edge e=new Edge(newtag); + tb.addEdge(e); + } + } + } +} diff --git a/Robust/src/Analysis/TaskStateAnalysis/TagBinding.java b/Robust/src/Analysis/TaskStateAnalysis/TagBinding.java new file mode 100644 index 00000000..6f8bbc5d --- /dev/null +++ b/Robust/src/Analysis/TaskStateAnalysis/TagBinding.java @@ -0,0 +1,65 @@ +package Analysis.TaskStateAnalysis; +import IR.MethodDescriptor; +import IR.TagDescriptor; +import Util.GraphNode; +import java.util.HashSet; +import java.util.Set; + +public class TagBinding extends GraphNode { + private MethodDescriptor md; + private TagDescriptor[] tdarray; + private HashSet allocations; + + public TagBinding(MethodDescriptor md) { + this.md=md; + tdarray=new TagDescriptor[md.numParameters()]; + allocations=new HashSet(); + } + + public String toString() { + String st=md.toString(); + for(int i=0;i toprocess; - + TagAnalysis taganalysis; + TypeUtil typeutil; - + /** * Class Constructor * * @param state a flattened State object * @see State */ - public TaskAnalysis(State state) + public TaskAnalysis(State state, TagAnalysis taganalysis) { this.state=state; this.typeutil=new TypeUtil(state); + this.taganalysis=taganalysis; } /** Builds a table of flags for each class in the Bristlecone program. @@ -154,7 +155,7 @@ public class TaskAnalysis { * @see FlagState */ - private void analyseTasks(FlagState fs) { +private void analyseTasks(FlagState fs) { ClassDescriptor cd=fs.getClassDescriptor(); Hashtable sourcenodes=(Hashtable)flagstates.get(cd); @@ -168,19 +169,17 @@ public class TaskAnalysis { System.out.println("Task: "+taskname); //*********** - - /** counter to keep track of the number of parameters (of the task being analyzed) that * are satisfied by the flagstate. */ int trigger_ctr=0; TempDescriptor temp=null; FlatMethod fm = state.getMethodFlat(td); - + for(int i=0; i < td.numParameters(); i++) { FlagExpressionNode fen=td.getFlag(td.getParameter(i)); TagExpressionList tel=td.getTag(td.getParameter(i)); - + /** Checking to see if the parameter is of the same type/class as the * flagstate's and also if the flagstate fs triggers the given task*/ if (typeutil.isSuperorType(td.getParamType(i).getClassDesc(),cd) @@ -197,70 +196,58 @@ public class TaskAnalysis { if (trigger_ctr>1) throw new Error("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task."); - + //** debug System.out.println("Task:" + taskname +" is triggered"); - - - //Iterating through the nodes - FlatNode fn=fm.methodEntryNode(); - - HashSet tovisit= new HashSet(); - HashSet visited= new HashSet(); - - tovisit.add(fn); - while(!tovisit.isEmpty()) { - FlatNode fn1 = (FlatNode)tovisit.iterator().next(); - tovisit.remove(fn1); - visited.add(fn1); - // Queue all of the next nodes - for(int i = 0; i < fn1.numNext(); i++) { - FlatNode nn=fn1.getNext(i); - if (!visited.contains(nn)) - tovisit.add(nn); + + + Set newstates=taganalysis.getFlagStates(td); + for(Iterator fsit=newstates.iterator();fsit.hasNext();) { + FlagState fsnew=(FlagState) fsit.next(); + if (! ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) { + ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew); + toprocess.add(fsnew); } + } + + //Iterating through the nodes + Set nodeset=fm.getNodeSet(); + + for(Iterator nodeit=nodeset.iterator();nodeit.hasNext();) { + FlatNode fn1 = (FlatNode) nodeit.next(); + if (fn1.kind()==FKind.FlatFlagActionNode) { FlatFlagActionNode ffan=(FlatFlagActionNode)fn1; if (ffan.getTaskType() == FlatFlagActionNode.PRE) { if (ffan.getTempFlagPairs().hasNext()||ffan.getTempTagPairs().hasNext()) throw new Error("PRE FlagActions not supported"); - } else if (ffan.getTaskType() == FlatFlagActionNode.NEWOBJECT) { - //*** - System.out.println("NEWOBJ"); - //*** - FlagState fsnew=evalNewObjNode(ffan); - //Have we seen this node yet - if(fsnew!=null){ - if (! ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) { - ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew); - toprocess.add(fsnew); - } - } + } else if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) { //*** System.out.println("TASKEXIT"); //*** - - Vector fsv_taskexit=evalTaskExitNode(ffan,cd,fs,temp); + + Vector fsv_taskexit=evalTaskExitNode(ffan,cd,fs,temp); for(Enumeration en=fsv_taskexit.elements();en.hasMoreElements();){ - FlagState fs_taskexit=(FlagState)en.nextElement(); - if (!sourcenodes.containsKey(fs_taskexit)) { - toprocess.add(fs_taskexit); - - } - //seen this node already - fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit); - FEdge newedge=new FEdge(fs_taskexit,taskname); - //FEdge newedge=new FEdge(fs_taskexit,td); - fs.addEdge(newedge); - } + FlagState fs_taskexit=(FlagState)en.nextElement(); + if (!sourcenodes.containsKey(fs_taskexit)) { + toprocess.add(fs_taskexit); + + } + //seen this node already + fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit); + FEdge newedge=new FEdge(fs_taskexit,taskname); + //FEdge newedge=new FEdge(fs_taskexit,td); + fs.addEdge(newedge); + } } } } } } + /** Determines whether the given flagstate satisfies a * single parameter in the given task. * @param fen FlagExpressionNode @@ -321,41 +308,41 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){ * @see FlagState */ - private FlagState evalNewObjNode(FlatNode nn){ +private FlagState evalNewObjNode(FlatNode nn){ - ClassDescriptor cd_new=((FlatNew)nn.getPrev(0)).getType().getClassDesc(); + ClassDescriptor cd_new=((FlatNew)nn.getPrev(0)).getType().getClassDesc(); - //TempDescriptor[] tdArray = ((FlatFlagActionNode)nn).readsTemps(); - - //if (tdArray.length==0) - // return null; - - //Under the safe assumption that all the temps in FFAN.NewObject node are of the same type(class) - //ClassDescriptor cd_new=tdArray[0].getType().getClassDesc(); - - FlagState fstemp=new FlagState(cd_new); - - for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) { - TempFlagPair tfp=(TempFlagPair)it_tfp.next(); - if (! (tfp.getFlag()==null))// condition checks if the new object was created without any flag setting - { - fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp)); - } - - else - break; - } - for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) { - TempTagPair ttp=(TempTagPair)it_ttp.next(); - if (! (ttp.getTag()==null)){ - fstemp=fstemp.setTag(ttp.getTag()); - } - else - break; - - } - return fstemp; + //TempDescriptor[] tdArray = ((FlatFlagActionNode)nn).readsTemps(); + + //if (tdArray.length==0) + // return null; + + //Under the safe assumption that all the temps in FFAN.NewObject node are of the same type(class) + //ClassDescriptor cd_new=tdArray[0].getType().getClassDesc(); + + FlagState fstemp=new FlagState(cd_new); + + for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) { + TempFlagPair tfp=(TempFlagPair)it_tfp.next(); + if (! (tfp.getFlag()==null))// condition checks if the new object was created without any flag setting + { + fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp)); + } + + else + break; + } + for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) { + TempTagPair ttp=(TempTagPair)it_ttp.next(); + if (! (ttp.getTag()==null)){ + fstemp=fstemp.setTag(ttp.getTag()); + } + else + break; + + } + return fstemp; } private Vector evalTaskExitNode(FlatNode nn,ClassDescriptor cd,FlagState fs, TempDescriptor temp){ diff --git a/Robust/src/Benchmarks/ChatTag/ChatServer.java b/Robust/src/Benchmarks/ChatTag/ChatServer.java index 90f21b53..184d75bb 100644 --- a/Robust/src/Benchmarks/ChatTag/ChatServer.java +++ b/Robust/src/Benchmarks/ChatTag/ChatServer.java @@ -8,10 +8,8 @@ task Startup(StartupObject s{initialstate}) { task AcceptConnection(ServerSocket ss{SocketPending}) { tag t=new tag(link); ChatSocket cs=new ChatSocket() {Initialized}{t}; - Socket s=new Socket() {}{t}; - cs.sock=s; - ss.accept(s); - s.write("Please choose a chatroom".getBytes()); + cs.sock=ss.accept(t); + cs.sock.write("Please choose a chatroom".getBytes()); } task ReadRequest(ChatSocket cs{Initialized}{link l}, Socket s{IOPending}{link l}) { diff --git a/Robust/src/ClassLibrary/ServerSocket.java b/Robust/src/ClassLibrary/ServerSocket.java index 51dd73e9..465ad340 100644 --- a/Robust/src/ClassLibrary/ServerSocket.java +++ b/Robust/src/ClassLibrary/ServerSocket.java @@ -17,6 +17,13 @@ public class ServerSocket { return s; } + public Socket accept(tag td) { + Socket s=new Socket(){}{td}; + int newfd=nativeaccept(s); + s.setFD(newfd); + return s; + } + /* Lets caller pass in their own Socket object. */ public void accept(Socket s) { int newfd=nativeaccept(s); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index e744e1f2..7e249e16 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -299,9 +299,11 @@ public class BuildCode { MethodDescriptor md=(MethodDescriptor)mainit.next(); if (md.numParameters()!=1) continue; - if (md.getParameter(0).getType().getArrayCount()!=1) + Descriptor pd=md.getParameter(0); + TypeDescriptor tpd=(pd instanceof TagVarDescriptor)?((TagVarDescriptor)pd).getType():((VarDescriptor)pd).getType(); + if (tpd.getArrayCount()!=1) continue; - if (!md.getParameter(0).getType().getSymbol().equals("String")) + if (!tpd.getSymbol().equals("String")) continue; if (!md.getModifiers().isStatic()) @@ -905,6 +907,9 @@ public class BuildCode { TempDescriptor temp=objecttemps.getPointer(i); if (temp.getType().isNull()) output.println(" void * "+temp.getSafeSymbol()+";"); + else if(temp.getType().isTag()) + output.println(" struct "+ + (new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol()+" * "+temp.getSafeSymbol()+";"); else output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";"); } @@ -1165,12 +1170,16 @@ public class BuildCode { output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis())); } for(int i=0;i