From d2178dde3360bf7dd63d3f54794ad54501f7796f Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 18 Feb 2009 08:54:42 +0000 Subject: [PATCH] Massive commit... Changes: 1) Put Class Library files in directories by when we use them 2) Change class paths in buildscript 3) Only load/compile classes that we actually use --- .../TaskStateAnalysis/TaskAnalysis.java | 4 +- .../TaskStateAnalysis/TaskTagAnalysis.java | 4 +- .../{ => Bristlecone}/Object.java | 0 .../{ => Bristlecone}/ServerSocket.java | 0 .../{ => Bristlecone}/Socket.java | 0 .../{ => Bristlecone}/StartupObject.java | 0 .../{ => Bristlecone}/TagDescriptor.java | 0 .../{ObjectJavaNT.java => Java/Object.java} | 0 .../ServerSocket.java} | 0 .../{SocketJava.java => Java/Socket.java} | 0 .../ClassLibrary/{ => JavaDSM}/Barrier.java | 0 .../ClassLibrary/JavaDSM/BarrierClient.java | 54 ++++++++ .../{ => JavaDSM}/DistributedHashMap.java | 0 .../Object.java} | 0 .../{ThreadDSM.java => JavaDSM/Thread.java} | 0 .../Object.java} | 0 .../ClassLibrary/{ => JavaThread}/Thread.java | 0 Robust/src/ClassLibrary/ObjectFC.java | 31 ----- Robust/src/IR/State.java | 4 + Robust/src/IR/TagVarDescriptor.java | 1 + Robust/src/IR/Tree/BuildIR.java | 15 +- Robust/src/IR/Tree/SemanticCheck.java | 60 ++++---- Robust/src/IR/TypeUtil.java | 55 ++++++-- Robust/src/Main/Main.java | 128 +++++++----------- Robust/src/buildscript | 31 ++++- 25 files changed, 226 insertions(+), 161 deletions(-) rename Robust/src/ClassLibrary/{ => Bristlecone}/Object.java (100%) rename Robust/src/ClassLibrary/{ => Bristlecone}/ServerSocket.java (100%) rename Robust/src/ClassLibrary/{ => Bristlecone}/Socket.java (100%) rename Robust/src/ClassLibrary/{ => Bristlecone}/StartupObject.java (100%) rename Robust/src/ClassLibrary/{ => Bristlecone}/TagDescriptor.java (100%) rename Robust/src/ClassLibrary/{ObjectJavaNT.java => Java/Object.java} (100%) rename Robust/src/ClassLibrary/{ServerSocketJava.java => Java/ServerSocket.java} (100%) rename Robust/src/ClassLibrary/{SocketJava.java => Java/Socket.java} (100%) rename Robust/src/ClassLibrary/{ => JavaDSM}/Barrier.java (100%) create mode 100644 Robust/src/ClassLibrary/JavaDSM/BarrierClient.java rename Robust/src/ClassLibrary/{ => JavaDSM}/DistributedHashMap.java (100%) rename Robust/src/ClassLibrary/{ObjectJavaDSM.java => JavaDSM/Object.java} (100%) rename Robust/src/ClassLibrary/{ThreadDSM.java => JavaDSM/Thread.java} (100%) rename Robust/src/ClassLibrary/{ObjectJava.java => JavaThread/Object.java} (100%) rename Robust/src/ClassLibrary/{ => JavaThread}/Thread.java (100%) delete mode 100644 Robust/src/ClassLibrary/ObjectFC.java diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java index be82555b..6081ae0f 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java @@ -25,9 +25,9 @@ public class TaskAnalysis { * @param state a flattened State object * @see State */ - public TaskAnalysis(State state, TagAnalysis taganalysis) { + public TaskAnalysis(State state, TagAnalysis taganalysis, TypeUtil typeutil) { this.state=state; - this.typeutil=new TypeUtil(state); + this.typeutil=typeutil; this.taganalysis=taganalysis; } diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskTagAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TaskTagAnalysis.java index 6a2d3aab..602cd7ea 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskTagAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskTagAnalysis.java @@ -23,9 +23,9 @@ public class TaskTagAnalysis { * Class Constructor * */ - public TaskTagAnalysis(State state, TagAnalysis taganalysis) { + public TaskTagAnalysis(State state, TagAnalysis taganalysis, TypeUtil typeutil) { this.state=state; - this.typeutil=new TypeUtil(state); + this.typeutil=typeutil; this.taganalysis=taganalysis; this.flaginfo=new FlagInfo(state); this.toprocess=new HashSet(); diff --git a/Robust/src/ClassLibrary/Object.java b/Robust/src/ClassLibrary/Bristlecone/Object.java similarity index 100% rename from Robust/src/ClassLibrary/Object.java rename to Robust/src/ClassLibrary/Bristlecone/Object.java diff --git a/Robust/src/ClassLibrary/ServerSocket.java b/Robust/src/ClassLibrary/Bristlecone/ServerSocket.java similarity index 100% rename from Robust/src/ClassLibrary/ServerSocket.java rename to Robust/src/ClassLibrary/Bristlecone/ServerSocket.java diff --git a/Robust/src/ClassLibrary/Socket.java b/Robust/src/ClassLibrary/Bristlecone/Socket.java similarity index 100% rename from Robust/src/ClassLibrary/Socket.java rename to Robust/src/ClassLibrary/Bristlecone/Socket.java diff --git a/Robust/src/ClassLibrary/StartupObject.java b/Robust/src/ClassLibrary/Bristlecone/StartupObject.java similarity index 100% rename from Robust/src/ClassLibrary/StartupObject.java rename to Robust/src/ClassLibrary/Bristlecone/StartupObject.java diff --git a/Robust/src/ClassLibrary/TagDescriptor.java b/Robust/src/ClassLibrary/Bristlecone/TagDescriptor.java similarity index 100% rename from Robust/src/ClassLibrary/TagDescriptor.java rename to Robust/src/ClassLibrary/Bristlecone/TagDescriptor.java diff --git a/Robust/src/ClassLibrary/ObjectJavaNT.java b/Robust/src/ClassLibrary/Java/Object.java similarity index 100% rename from Robust/src/ClassLibrary/ObjectJavaNT.java rename to Robust/src/ClassLibrary/Java/Object.java diff --git a/Robust/src/ClassLibrary/ServerSocketJava.java b/Robust/src/ClassLibrary/Java/ServerSocket.java similarity index 100% rename from Robust/src/ClassLibrary/ServerSocketJava.java rename to Robust/src/ClassLibrary/Java/ServerSocket.java diff --git a/Robust/src/ClassLibrary/SocketJava.java b/Robust/src/ClassLibrary/Java/Socket.java similarity index 100% rename from Robust/src/ClassLibrary/SocketJava.java rename to Robust/src/ClassLibrary/Java/Socket.java diff --git a/Robust/src/ClassLibrary/Barrier.java b/Robust/src/ClassLibrary/JavaDSM/Barrier.java similarity index 100% rename from Robust/src/ClassLibrary/Barrier.java rename to Robust/src/ClassLibrary/JavaDSM/Barrier.java diff --git a/Robust/src/ClassLibrary/JavaDSM/BarrierClient.java b/Robust/src/ClassLibrary/JavaDSM/BarrierClient.java new file mode 100644 index 00000000..145391fe --- /dev/null +++ b/Robust/src/ClassLibrary/JavaDSM/BarrierClient.java @@ -0,0 +1,54 @@ +public class Barrier { + int numthreads; + int entercount; + boolean cleared; + + public Barrier(int n) { + numthreads=n; + cleared = false; + entercount = 0; + } + + public Barrier() { + } + + public void reset() { + cleared = false; + entercount = 0; + } + + public static void enterBarrier(Barrier b) { + int tmp; + boolean retry=true, ret1=false, ret2=true;; + + do { + atomic { + if (!b.cleared) { + b.entercount++; + tmp = b.entercount; + if (tmp==b.numthreads) { + if(b.numthreads > 1) + b.cleared=true; + b.entercount--; + ret1 = true; + } + retry=false; + } + } + } while(retry); + if (ret1) { + return; + } + while(ret2) { + atomic { + if (b.cleared) { + b.entercount--; + int count = b.entercount; + if (count==0) + b.cleared=false; + ret2=false; + } + } + } + } +} diff --git a/Robust/src/ClassLibrary/DistributedHashMap.java b/Robust/src/ClassLibrary/JavaDSM/DistributedHashMap.java similarity index 100% rename from Robust/src/ClassLibrary/DistributedHashMap.java rename to Robust/src/ClassLibrary/JavaDSM/DistributedHashMap.java diff --git a/Robust/src/ClassLibrary/ObjectJavaDSM.java b/Robust/src/ClassLibrary/JavaDSM/Object.java similarity index 100% rename from Robust/src/ClassLibrary/ObjectJavaDSM.java rename to Robust/src/ClassLibrary/JavaDSM/Object.java diff --git a/Robust/src/ClassLibrary/ThreadDSM.java b/Robust/src/ClassLibrary/JavaDSM/Thread.java similarity index 100% rename from Robust/src/ClassLibrary/ThreadDSM.java rename to Robust/src/ClassLibrary/JavaDSM/Thread.java diff --git a/Robust/src/ClassLibrary/ObjectJava.java b/Robust/src/ClassLibrary/JavaThread/Object.java similarity index 100% rename from Robust/src/ClassLibrary/ObjectJava.java rename to Robust/src/ClassLibrary/JavaThread/Object.java diff --git a/Robust/src/ClassLibrary/Thread.java b/Robust/src/ClassLibrary/JavaThread/Thread.java similarity index 100% rename from Robust/src/ClassLibrary/Thread.java rename to Robust/src/ClassLibrary/JavaThread/Thread.java diff --git a/Robust/src/ClassLibrary/ObjectFC.java b/Robust/src/ClassLibrary/ObjectFC.java deleted file mode 100644 index ae2c437a..00000000 --- a/Robust/src/ClassLibrary/ObjectFC.java +++ /dev/null @@ -1,31 +0,0 @@ -public class Object { - public int cachedCode; //first field has to be a primitive - public boolean cachedHash; - public Object nextobject; /* Oid */ - public Object localcopy; - private Object tags; - - public native int nativehashCode(); - - public int hashCode() { - if (!cachedHash) { - cachedCode=nativehashCode(); - cachedHash=true; - } - return cachedCode; - } - - /* DON'T USE THIS METHOD UNLESS NECESSARY */ - /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ - public native int getType(); - - public String toString() { - return "Object"+hashCode(); - } - - public boolean equals(Object o) { - if (o==this) - return true; - return false; - } -} diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index e02d09d9..ef5aa45d 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -8,6 +8,7 @@ import Analysis.TaskStateAnalysis.*; public class State { public State() { this.classes=new SymbolTable(); + this.discclass=new HashSet(); this.tasks=new SymbolTable(); this.treemethodmap=new Hashtable(); this.flatmethodmap=new Hashtable(); @@ -17,6 +18,7 @@ public class State { this.tagmap=new Hashtable(); this.selfloops=new HashSet(); this.excprefetch=new HashSet(); + this.classpath=new Vector(); } public void addParseNode(ParseNode parsetree) { @@ -79,6 +81,8 @@ public class State { public HashSet selfloops; public HashSet excprefetch; + public Vector classpath; + public HashSet discclass; public SymbolTable classes; public SymbolTable tasks; public Set parsetrees; diff --git a/Robust/src/IR/TagVarDescriptor.java b/Robust/src/IR/TagVarDescriptor.java index 4cca52da..f076b3c1 100644 --- a/Robust/src/IR/TagVarDescriptor.java +++ b/Robust/src/IR/TagVarDescriptor.java @@ -17,6 +17,7 @@ public class TagVarDescriptor extends Descriptor { this.identifier=identifier; this.safename = "___" + name + "___"; this.uniqueid=count++; + throw new Error(); } public String getName() { diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 12149c3e..2e61224f 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -13,18 +13,18 @@ public class BuildIR { this.m_taskexitnum = 0; } - public void buildtree() { - for(Iterator it=state.parsetrees.iterator(); it.hasNext();) { - ParseNode pn=(ParseNode)it.next(); + public void buildtree(ParseNode pn) { parseFile(pn); - } } + Vector singleimports; + Vector multiimports; + NameDescriptor packages; + /** Parse the classes in this file */ public void parseFile(ParseNode pn) { - NameDescriptor packages; - Vector singleimports=new Vector(); - Vector multiimports=new Vector(); + singleimports=new Vector(); + multiimports=new Vector(); ParseNode ipn=pn.getChild("imports").getChild("import_decls_list"); if (ipn!=null) { @@ -396,6 +396,7 @@ public class BuildIR { return new LiteralNode(literaltype, literal_obj); } else if (isNode(pn,"createobject")) { TypeDescriptor td=parseTypeDescriptor(pn); + Vector args=parseArgumentList(pn); boolean isglobal=pn.getChild("global")!=null; String disjointId=null; diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index d2fc664c..59bc63ac 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -6,60 +6,70 @@ import IR.*; public class SemanticCheck { State state; TypeUtil typeutil; - Stack loopstack; + Stack loopstack; + HashSet toanalyze; + HashSet completed; public SemanticCheck(State state, TypeUtil tu) { this.state=state; this.typeutil=tu; this.loopstack=new Stack(); + this.toanalyze=new HashSet(); + this.completed=new HashSet(); } - public void semanticCheck() { - SymbolTable classtable=state.getClassSymbolTable(); - Iterator it=classtable.getDescriptorsIterator(); - // Do descriptors first - while(it.hasNext()) { - ClassDescriptor cd=(ClassDescriptor)it.next(); + public ClassDescriptor getClass(String classname) { + ClassDescriptor cd=typeutil.getClass(classname, toanalyze); + if (!completed.contains(cd)) { + completed.add(cd); //System.out.println("Checking class: "+cd); //Set superclass link up if (cd.getSuper()!=null) { - cd.setSuper(typeutil.getClass(cd.getSuper())); + cd.setSuper(getClass(cd.getSuper())); // Link together Field, Method, and Flag tables so classes // inherit these from their superclasses cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable()); cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable()); cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable()); } - + /* Check to see that fields are well typed */ for(Iterator field_it=cd.getFields(); field_it.hasNext();) { FieldDescriptor fd=(FieldDescriptor)field_it.next(); //System.out.println("Checking field: "+fd); checkField(cd,fd); } - + for(Iterator method_it=cd.getMethods(); method_it.hasNext();) { MethodDescriptor md=(MethodDescriptor)method_it.next(); checkMethod(cd,md); } } + return cd; + } - it=classtable.getDescriptorsIterator(); - // Do descriptors first - while(it.hasNext()) { - ClassDescriptor cd=(ClassDescriptor)it.next(); - for(Iterator method_it=cd.getMethods(); method_it.hasNext();) { - MethodDescriptor md=(MethodDescriptor)method_it.next(); - checkMethodBody(cd,md); - } - } + public void semanticCheck() { + SymbolTable classtable=state.getClassSymbolTable(); + toanalyze.addAll(classtable.getValueSet()); + //Start with any tasks for(Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator(); task_it.hasNext();) { TaskDescriptor td=(TaskDescriptor)task_it.next(); checkTask(td); } + + // Do methods next + while(!toanalyze.isEmpty()) { + ClassDescriptor cd=(ClassDescriptor)toanalyze.iterator().next(); + toanalyze.remove(cd); + for(Iterator method_it=cd.getMethods(); method_it.hasNext();) { + MethodDescriptor md=(MethodDescriptor)method_it.next(); + checkMethodBody(cd,md); + } + } + } public void checkTypeDescriptor(TypeDescriptor td) { @@ -67,7 +77,7 @@ public class SemanticCheck { return; /* Done */ else if (td.isClass()) { String name=td.toString(); - ClassDescriptor field_cd=(ClassDescriptor)state.getClassSymbolTable().get(name); + ClassDescriptor field_cd=getClass(name); if (field_cd==null) throw new Error("Undefined class "+name); td.setClassDescriptor(field_cd); @@ -412,7 +422,7 @@ public class SemanticCheck { if (cn.getType()==null) { NameDescriptor typenamed=cn.getTypeName().getName(); String typename=typenamed.toString(); - TypeDescriptor ntd=new TypeDescriptor(typeutil.getClass(typename)); + TypeDescriptor ntd=new TypeDescriptor(getClass(typename)); cn.setType(ntd); } @@ -491,7 +501,7 @@ public class SemanticCheck { } else if (o instanceof Character) { ln.setType(new TypeDescriptor(TypeDescriptor.CHAR)); } else if (o instanceof String) { - ln.setType(new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass))); + ln.setType(new TypeDescriptor(getClass(TypeUtil.StringClass))); } if (td!=null) @@ -599,7 +609,7 @@ public class SemanticCheck { if (an.getDest().getType().isString()&&an.getOperation().getOp()==AssignOperation.PLUSEQ) { //String add - ClassDescriptor stringcl=typeutil.getClass(TypeUtil.StringClass); + ClassDescriptor stringcl=getClass(TypeUtil.StringClass); TypeDescriptor stringtd=new TypeDescriptor(stringcl); NameDescriptor nd=new NameDescriptor("String"); NameDescriptor valuend=new NameDescriptor(nd, "valueOf"); @@ -788,7 +798,7 @@ NextMethod: typetolookin=min.getExpression().getType(); } else { //we have a type - ClassDescriptor cd=typeutil.getClass(min.getBaseName().getSymbol()); + ClassDescriptor cd=getClass(min.getBaseName().getSymbol()); if (cd==null) throw new Error("md = "+ md.toString()+ " "+min.getBaseName()+" undefined"); typetolookin=new TypeDescriptor(cd); @@ -976,7 +986,7 @@ NextMethod: case Operation.ADD: if (ltd.isString()||rtd.isString()) { - ClassDescriptor stringcl=typeutil.getClass(TypeUtil.StringClass); + ClassDescriptor stringcl=getClass(TypeUtil.StringClass); TypeDescriptor stringtd=new TypeDescriptor(stringcl); NameDescriptor nd=new NameDescriptor("String"); NameDescriptor valuend=new NameDescriptor(nd, "valueOf"); diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 91fd0fdc..0bda49cb 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -1,5 +1,8 @@ package IR; import java.util.*; +import IR.Tree.*; +import java.io.File; +import Main.Main; public class TypeUtil { public static final String StringClass="String"; @@ -10,32 +13,62 @@ public class TypeUtil { State state; Hashtable supertable; Hashtable subclasstable; + BuildIR bir; - public TypeUtil(State state) { + public TypeUtil(State state, BuildIR bir) { this.state=state; + this.bir=bir; createTables(); } + public void addNewClass(String cl) { + if (state.discclass.contains(cl)) + return; + for(int i=0;i