lots of changes for dsm now that william's stuff is checked in
authorbdemsky <bdemsky>
Wed, 15 Aug 2007 01:13:52 +0000 (01:13 +0000)
committerbdemsky <bdemsky>
Wed, 15 Aug 2007 01:13:52 +0000 (01:13 +0000)
Robust/src/Analysis/Locality/GenerateConversions.java
Robust/src/Analysis/Locality/LocalityAnalysis.java
Robust/src/Analysis/Locality/LocalityBinding.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/TempDescriptor.java
Robust/src/IR/Virtual.java
Robust/src/Main/Main.java
Robust/src/Runtime/DSTM/interface/localobjects.c
Robust/src/Runtime/DSTM/interface/localobjects.h
Robust/src/buildscript

index 8585773b97c7fda9729b32d11535833339bb4fc9..74bfe1e7c208b55424f90d394edf84e5ea9ad4a3 100644 (file)
@@ -61,6 +61,8 @@ public class GenerateConversions {
            HashSet<TempNodePair> tempset=new HashSet<TempNodePair>();
            for(int i=0;i<fn.numPrev();i++) {
                FlatNode fnprev=fn.getPrev(i);
+               if (!nodetotnpair.containsKey(fnprev))
+                   continue;
                Set<TempNodePair> prevset=nodetotnpair.get(fnprev);
                for(Iterator<TempNodePair> it=prevset.iterator();it.hasNext();) {
                    TempNodePair tnp=it.next();
@@ -112,7 +114,7 @@ public class GenerateConversions {
        toprocess=fm.getNodeSet();
        for(Iterator<FlatNode> it=toprocess.iterator();it.hasNext();) {
            FlatNode fn=it.next();
-           if (atomictab.get(fn).intValue()==0&&
+           if (atomictab.get(fn).intValue()==0&&fn.numPrev()>0&&
                atomictab.get(fn.getPrev(0)).intValue()>0) {
                //sanity check
                assert(fn.kind()==FKind.FlatAtomicExitNode);
index 86078d2e2691bb150c3dcf2c1eb49da53f257443..a780a3a0c57a721ae9ee8d72991e1c727504a455 100644 (file)
@@ -18,6 +18,7 @@ public class LocalityAnalysis {
     Hashtable<LocalityBinding, Hashtable<FlatNode, Integer>> atomictab;
     Hashtable<LocalityBinding, Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>> tempstosave;
     Hashtable<ClassDescriptor, Set<LocalityBinding>> classtolb;
+    Hashtable<MethodDescriptor, Set<LocalityBinding>> methodtolb;
 
     CallGraph callgraph;
     TypeUtil typeutil;
@@ -37,6 +38,7 @@ public class LocalityAnalysis {
        this.callgraph=callgraph;
        this.tempstosave=new Hashtable<LocalityBinding, Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>>();
        this.classtolb=new Hashtable<ClassDescriptor, Set<LocalityBinding>>();
+       this.methodtolb=new Hashtable<MethodDescriptor, Set<LocalityBinding>>();
        doAnalysis();
     }
 
@@ -46,6 +48,12 @@ public class LocalityAnalysis {
        return classtolb.get(cd);
     }
 
+    /** This method returns a set of LocalityBindings for the parameter method. */
+       
+    public Set<LocalityBinding> getMethodBindings(MethodDescriptor md) {
+       return methodtolb.get(md);
+    }
+
     /** This method returns a set of LocalityBindings.  A
      * LocalityBinding specifies a context a method can be invoked in.
      * It specifies whether the method is in a transaction and whether
@@ -106,6 +114,10 @@ public class LocalityAnalysis {
            classtolb.put(lbmain.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
        classtolb.get(lbmain.getMethod().getClassDesc()).add(lbmain);
 
+       if (!methodtolb.containsKey(lbmain.getMethod()))
+           methodtolb.put(lbmain.getMethod(), new HashSet<LocalityBinding>());
+       methodtolb.get(lbmain.getMethod()).add(lbmain);
+
        while(!lbtovisit.empty()) {
            LocalityBinding lb=(LocalityBinding) lbtovisit.pop();
            Integer returnglobal=lb.getGlobalReturn();
@@ -291,6 +303,9 @@ public class LocalityAnalysis {
                if (!classtolb.containsKey(lb.getMethod().getClassDesc()))
                    classtolb.put(lb.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
                classtolb.get(lb.getMethod().getClassDesc()).add(lb);
+               if (!methodtolb.containsKey(lb.getMethod()))
+                   methodtolb.put(lb.getMethod(), new HashSet<LocalityBinding>());
+               methodtolb.get(lb.getMethod()).add(lb);
            } else
                lb=discovered.get(lb);
            Integer returnval=lb.getGlobalReturn();
index cfd9c5d450392422f5e1c6ff06d4733489933992..9dd6af0eb886a49b9e028f4ce65f38fdec381b8a 100644 (file)
@@ -37,15 +37,15 @@ public class LocalityBinding {
     }
     
     public String getSignature() {
-       if (md.getModifiers().isNative())
-           return "";
-
        String st="_";
        if (isatomic) {
            st+="A";
        } else
            st+="N";
-       st+=globalToString(isglobalthis);
+       if (isglobalthis==null)
+           st+="N";
+       else
+           st+=globalToString(isglobalthis);
        for(int i=0;i<isglobal.length;i++) {
            st+=globalToString(isglobal[i]);
        }
@@ -111,6 +111,22 @@ public class LocalityBinding {
        return isatomic;
     }
 
+    public boolean contextMatches(LocalityBinding lb) {
+       if (isglobal.length!=lb.isglobal.length)
+           return false;
+       for(int i=0;i<isglobal.length;i++)
+           if (!isglobal[i].equals(lb.isglobal[i]))
+               return false;
+       
+       if (isglobalthis==null) {
+           if (lb.isglobalthis!=null)
+               return false;
+       } else
+           if (!isglobalthis.equals(lb.isglobalthis))
+               return false;
+       return (isatomic==lb.isatomic);
+    }
+
     public boolean equals(Object o) {
        if (o instanceof LocalityBinding) {
            LocalityBinding lb=(LocalityBinding)o;
@@ -119,8 +135,13 @@ public class LocalityBinding {
            for(int i=0;i<isglobal.length;i++)
                if (!isglobal[i].equals(lb.isglobal[i]))
                    return false;
-           if (!isglobalthis.equals(lb.isglobalthis))
-               return false;
+
+           if (isglobalthis==null) {
+               if (lb.isglobalthis!=null)
+                   return false;
+           } else
+               if (!isglobalthis.equals(lb.isglobalthis))
+                   return false;
            return (isatomic==lb.isatomic);
        }
        return false;
index be5f1ca4679d1153caba54158ebfaeab38812b9c..76f8e03c405527b386b73fb6baae9f1de5f6f890 100644 (file)
@@ -37,22 +37,26 @@ public class BuildCode {
     TypeDescriptor[] arraytable;
     LocalityAnalysis locality;
     Hashtable<TempDescriptor, TempDescriptor> backuptable;
+    Hashtable<LocalityBinding, TempDescriptor> reverttable;
 
     public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) {
+       this(st, temptovar, typeutil, null);
+    }
+
+    public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) {
        state=st;
        this.temptovar=temptovar;
-       paramstable=new Hashtable();    
+       paramstable=new Hashtable();
        tempstable=new Hashtable();
        fieldorder=new Hashtable();
        flagorder=new Hashtable();
        this.typeutil=typeutil;
-       virtualcalls=new Virtual(state);
-    }
-
-    public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) {
-       this(st, temptovar, typeutil);
-       this.locality=locality;
-       this.backuptable=new Hashtable<TempDescriptor, TempDescriptor>();
+       virtualcalls=new Virtual(state,locality);
+       if (locality!=null) {
+           this.locality=locality;
+           this.backuptable=new Hashtable<TempDescriptor, TempDescriptor>();
+           this.reverttable=new Hashtable<LocalityBinding, TempDescriptor>();
+       }
     }
 
     /** The buildCode method outputs C code for all the methods.  The Flat
@@ -174,22 +178,37 @@ public class BuildCode {
     private void outputMainMethod(PrintWriter outmethod) {
        outmethod.println("int main(int argc, const char *argv[]) {");
        outmethod.println("  int i;");
-       if (GENERATEPRECISEGC) {
-           outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
+       if (state.DSM) {
+           outmethod.println("if (dstmStart(argv[0])) {");
+           if (GENERATEPRECISEGC) {
+               outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);");
+           } else {
+               outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);");
+           }
        } else {
-           outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
+           if (GENERATEPRECISEGC) {
+               outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
+           } else {
+               outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
+           }
        }
        if (state.THREAD) {
            outmethod.println("initializethreads();");
        }
-       outmethod.println("  for(i=1;i<argc;i++) {");
+       if (state.DSM) {
+           outmethod.println("  for(i=2;i<argc;i++) {");
+       } else 
+           outmethod.println("  for(i=1;i<argc;i++) {");
        outmethod.println("    int length=strlen(argv[i]);");
        if (GENERATEPRECISEGC) {
            outmethod.println("    struct ___String___ *newstring=NewString(NULL, argv[i], length);");
        } else {
            outmethod.println("    struct ___String___ *newstring=NewString(argv[i], length);");
        }
-       outmethod.println("    ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
+       if (state.DSM)
+           outmethod.println("    ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-2]=newstring;");
+       else
+           outmethod.println("    ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
        outmethod.println("  }");
        
        
@@ -204,7 +223,11 @@ public class BuildCode {
        } else
            outmethod.println("     "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
        outmethod.println("   }");
-       
+
+       if (state.DSM) {
+           outmethod.println("}");
+       }
+
        if (state.THREAD) {
            outmethod.println("pthread_mutex_lock(&gclistlock);");
            outmethod.println("threadcount--;");
@@ -212,6 +235,8 @@ public class BuildCode {
            outmethod.println("pthread_mutex_unlock(&gclistlock);");
            outmethod.println("pthread_exit(NULL);");
        }
+
+
        outmethod.println("}");
     }
 
@@ -255,6 +280,8 @@ public class BuildCode {
        outmethod.println("#include \"methodheaders.h\"");
        outmethod.println("#include \"virtualtable.h\"");
        outmethod.println("#include <runtime.h>");
+       if (state.DSM)
+           outmethod.println("#include \"localobjects.h\"");
        if (state.THREAD)
            outmethod.println("#include <thread.h>");
        if (state.main!=null) {
@@ -556,13 +583,21 @@ public class BuildCode {
            if (virtualcalls.getMethodCount(cd)>maxcount)
                maxcount=virtualcalls.getMethodCount(cd);
        }
-       MethodDescriptor[][] virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount];
+       MethodDescriptor[][] virtualtable=null;
+       LocalityBinding[][] lbvirtualtable=null;
+       if (state.DSM)
+           lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount];
+       else
+           virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount];
 
        /* Fill in virtual table */
        classit=state.getClassSymbolTable().getDescriptorsIterator();
        while(classit.hasNext()) {
            ClassDescriptor cd=(ClassDescriptor)classit.next();
-           fillinRow(cd, virtualtable, cd.getId());
+           if (state.DSM)
+               fillinRow(cd, lbvirtualtable, cd.getId());
+           else
+               fillinRow(cd, virtualtable, cd.getId());
        }
 
        ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
@@ -570,7 +605,10 @@ public class BuildCode {
        while(arrayit.hasNext()) {
            TypeDescriptor td=(TypeDescriptor)arrayit.next();
            int id=state.getArrayNumber(td);
-           fillinRow(objectcd, virtualtable, id+state.numClasses());
+           if (state.DSM)
+               fillinRow(objectcd, lbvirtualtable, id+state.numClasses());
+           else
+               fillinRow(objectcd, virtualtable, id+state.numClasses());
        }
        
        outvirtual.print("void * virtualtable[]={");
@@ -579,7 +617,11 @@ public class BuildCode {
            for(int j=0;j<maxcount;j++) {
                if (needcomma)
                    outvirtual.print(", ");
-               if (virtualtable[i][j]!=null) {
+               if (state.DSM&&lbvirtualtable[i][j]!=null) {
+                   LocalityBinding lb=lbvirtualtable[i][j];
+                   MethodDescriptor md=lb.getMethod();
+                   outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
+               } else if (!state.DSM&&virtualtable[i][j]!=null) {
                    MethodDescriptor md=virtualtable[i][j];
                    outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
                } else {
@@ -607,6 +649,24 @@ public class BuildCode {
        }
     }
 
+    private void fillinRow(ClassDescriptor cd, LocalityBinding[][] virtualtable, int rownum) {
+       /* Get inherited methods */
+       if (cd.getSuperDesc()!=null)
+           fillinRow(cd.getSuperDesc(), virtualtable, rownum);
+       /* Override them with our methods */
+       if (locality.getClassBindings(cd)!=null)
+           for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator();lbit.hasNext();) {
+               LocalityBinding lb=lbit.next();
+               MethodDescriptor md=lb.getMethod();
+               //Is the method static or a constructor
+               if (md.isStatic()||md.getReturnType()==null)
+                   continue;
+               int methodnum=virtualcalls.getLocalityNumber(lb);
+               virtualtable[rownum][methodnum]=lb;
+           }
+    }
+
+
     /** Generate array that contains the sizes of class objects.  The
      * object allocation functions in the runtime use this
      * information. */
@@ -708,7 +768,7 @@ public class BuildCode {
        }
 
        /* Create backup temps */
-       if (state.DSM)
+       if (state.DSM) {
            for(Iterator<TempDescriptor> tmpit=backuptable.values().iterator();tmpit.hasNext();) {
                TempDescriptor tmp=tmpit.next();
                TypeDescriptor type=tmp.getType();
@@ -717,6 +777,12 @@ public class BuildCode {
                else
                    objecttemps.addPrim(tmp);
            }
+           /* Create temp to hold revert table */
+           if (lb.getHasAtomic()) {
+               TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass));
+               reverttable.put(lb, reverttmp);
+           }
+       }
     }
 
     /** This method outputs the following information about classes
@@ -766,7 +832,7 @@ public class BuildCode {
                output.println(", ");
            TypeDescriptor tdelement=arraytable[i].dereference();
            if (tdelement.isArray()||tdelement.isClass())
-               output.print("((int *)1)");
+               output.print("((unsigned int *)1)");
            else
                output.print("0");
            needcomma=true;
@@ -900,11 +966,13 @@ public class BuildCode {
 
        if (state.DSM) {
            /* Cycle through LocalityBindings */
-           for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cn).iterator();lbit.hasNext();) {
-               LocalityBinding lb=lbit.next();
-               MethodDescriptor md=lb.getMethod();
-               generateMethod(cn, md, lb, headersout, output);
-           }
+           Set<LocalityBinding> lbset=locality.getClassBindings(cn);
+           if (lbset!=null)
+               for(Iterator<LocalityBinding> lbit=lbset.iterator();lbit.hasNext();) {
+                   LocalityBinding lb=lbit.next();
+                   MethodDescriptor md=lb.getMethod();
+                   generateMethod(cn, md, lb, headersout, output);
+               }
        } else {
            /* Cycle through methods */
            for(Iterator methodit=cn.getMethods();methodit.hasNext();) {
@@ -917,7 +985,7 @@ public class BuildCode {
 
     private void generateMethod(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter headersout, PrintWriter output) {
        FlatMethod fm=state.getMethodFlat(md);
-       generateTempStructs(fm, null);
+       generateTempStructs(fm, lb);
        
        ParamsObject objectparams=(ParamsObject) paramstable.get(md);
        TempObject objecttemps=(TempObject) tempstable.get(md);
@@ -1059,7 +1127,7 @@ public class BuildCode {
        }
     }
 
-    /** Generate code for FlatMethod fm. */
+    /***** Generate code for FlatMethod fm. *****/
 
     private void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) {
        MethodDescriptor md=fm.getMethod();
@@ -1224,11 +1292,14 @@ public class BuildCode {
        case FKind.FlatAtomicExitNode:
            generateFlatAtomicExitNode(fm, lb, (FlatAtomicExitNode) fn, output);
            return;
+       case FKind.FlatGlobalConvNode:
+           generateFlatGlobalConvNode(fm, lb, (FlatGlobalConvNode) fn, output);
+           return;
        case FKind.FlatTagDeclaration:
            generateFlatTagDeclaration(fm, (FlatTagDeclaration) fn,output);
            return;
        case FKind.FlatCall:
-           generateFlatCall(fm, (FlatCall) fn,output);
+           generateFlatCall(fm, lb, (FlatCall) fn,output);
            return;
        case FKind.FlatFieldNode:
            generateFlatFieldNode(fm, lb, (FlatFieldNode) fn,output);
@@ -1277,6 +1348,18 @@ public class BuildCode {
 
     }
     
+    public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
+       if (lb!=fgcn.getLocality())
+           return;
+       /* Have to generate flat globalconv */
+       if (fgcn.getMakePtr()) {
+           output.println(generateTemp(fm, fgcn.getSrc())+"=transRead(trans,"+generateTemp(fm, fgcn.getSrc())+");");
+       } else {
+           /* Need to convert to OID */
+           output.println(generateTemp(fm, fgcn.getSrc())+"=OID("+generateTemp(fm, fgcn.getSrc())+");");
+       }
+    }
+
     public void generateFlatAtomicEnterNode(FlatMethod fm,  LocalityBinding lb, FlatAtomicEnterNode faen, PrintWriter output) {
        /* Check to see if we need to generate code for this atomic */
        if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0)
@@ -1297,7 +1380,15 @@ public class BuildCode {
            output.println(generateTemp(fm, tmp)+"="+generateTemp(fm,backuptable.get(tmp))+";");
        }
 
-       /* Need to revert local object store */
+       /********* Need to revert local object store ********/
+       String revertptr=generateTemp(fm, reverttable.get(lb));
+       
+       output.println("while ("+revertptr+") {");
+       output.println("struct ___Object___ * tmpptr;");
+       output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
+       output.println("REVERT_OBJ("+revertptr+");");
+       output.println(revertptr+"=tmpptr;");
+       output.println("}");
 
        /******* Tell the runtime to start the transaction *******/
        
@@ -1309,11 +1400,21 @@ public class BuildCode {
        /* Check to see if we need to generate code for this atomic */
        if (locality.getAtomic(lb).get(faen).intValue()>0)
            return;
-       output.println("if (transCommit(trans))");
+       //store the revert list before we lose the transaction object
+       String revertptr=generateTemp(fm, reverttable.get(lb));
+       output.println(revertptr+"=trans->revertlist;");
+       output.println("if (transCommit(trans)) {");
        /* Transaction aborts if it returns true */
        output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
+       output.println("} else {");
        /* Need to commit local object store */
-       //TODO
+       output.println("while ("+revertptr+") {");
+       output.println("struct ___Object___ * tmpptr;");
+       output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
+       output.println("COMMIT_OBJ("+revertptr+");");
+       output.println(revertptr+"=tmpptr;");
+       output.println("}");
+       output.println("}");
     }
 
     private void generateFlatCheckNode(FlatMethod fm,  FlatCheckNode fcn, PrintWriter output) {
@@ -1340,7 +1441,7 @@ public class BuildCode {
        }
     }
 
-    private void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) {
+    private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) {
        MethodDescriptor md=fc.getMethod();
        ParamsObject objectparams=(ParamsObject) paramstable.get(md);
        ClassDescriptor cn=md.getClassDesc();
@@ -1504,7 +1605,7 @@ public class BuildCode {
     private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) {
        if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
            throw new Error("Can't set array length");
-       if (state.DSM) {
+       if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) {
            Integer statussrc=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst());
            Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst());
            boolean srcglobal=statusdst==LocalityAnalysis.GLOBAL;
@@ -1529,7 +1630,10 @@ public class BuildCode {
                /* Link object into list */
                output.println(dst+"->"+nextobjstr+"=trans->localtrans;");
                output.println("trans->localtrans="+dst+";");
-               output.println("OBJECT_COPY("+dst+");");
+               if (GENERATEPRECISEGC)
+                   output.println("COPY_OBJ((struct garbagelist *)&"+localsprefix+",(struct ___Object___ *)"+dst+");");
+               else
+                   output.println("COPY_OBJ("+dst+");");
                output.println("}");
                if (srcglobal)
                    output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;");
index 40faaa4c829b6a8e6eb9ff7162f8e589a052f2aa..a25fdb83458fd73bf603d945790eb97fe6a0e4d3 100644 (file)
@@ -18,6 +18,11 @@ public class TempDescriptor extends Descriptor {
        type=td;
     }
 
+    public TempDescriptor(String name, ClassDescriptor cd) {
+       this(name);
+       type=new TypeDescriptor(cd);
+    }
+
     public TempDescriptor(String name, TypeDescriptor type, TagDescriptor td) {
        this(name);
        this.type=type;
index 11d027b50b87f66606441fd6bf0ad75b1c1f3398..39822908c7cab7eec46648110361f458c2cdd25a 100644 (file)
@@ -1,23 +1,35 @@
 package IR;
 import java.util.*;
+import Analysis.Locality.LocalityBinding;
+import Analysis.Locality.LocalityAnalysis;
 
 public class Virtual {
     State state;
-    Hashtable methodnumber;
-    Hashtable classmethodcount;
-      
+    LocalityAnalysis locality;
+    Hashtable<MethodDescriptor, Integer> methodnumber;
+    Hashtable<ClassDescriptor, Integer> classmethodcount;
+    Hashtable<LocalityBinding, Integer> localitynumber;
+
     public int getMethodNumber(MethodDescriptor md) {
-       return ((Integer)methodnumber.get(md)).intValue();
+       return methodnumber.get(md).intValue();
     }
-
+    
     public int getMethodCount(ClassDescriptor md) {
-       return ((Integer)classmethodcount.get(md)).intValue();
+       return classmethodcount.get(md).intValue();
+    }
+    
+    public int getLocalityNumber(LocalityBinding lb) {
+       return localitynumber.get(lb).intValue();
     }
 
-    public Virtual(State state) {
+    public Virtual(State state, LocalityAnalysis locality) {
        this.state=state;
-       methodnumber=new Hashtable();
-       classmethodcount=new Hashtable();
+       this.locality=locality;
+       classmethodcount=new Hashtable<ClassDescriptor, Integer>();
+       if (state.DSM)
+           localitynumber=new Hashtable<LocalityBinding, Integer>();
+       else
+           methodnumber=new Hashtable<MethodDescriptor, Integer>();
        doAnalysis();
     }
 
@@ -25,13 +37,61 @@ public class Virtual {
        Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
        while(classit.hasNext()) {
            ClassDescriptor cd=(ClassDescriptor)classit.next();
-           numberMethods(cd);
+           if (state.DSM)
+               numberLocality(cd);
+           else
+               numberMethods(cd);
        }
     }
 
+    private int numberLocality(ClassDescriptor cd) {
+       if (classmethodcount.containsKey(cd))
+           return classmethodcount.get(cd).intValue();
+       ClassDescriptor superdesc=cd.getSuperDesc();
+       int start=0;
+       if (superdesc!=null)
+           start=numberLocality(superdesc);
+
+       if (locality.getClassBindings(cd)!=null)
+           for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator();lbit.hasNext();) {
+               LocalityBinding lb=lbit.next();
+               MethodDescriptor md=lb.getMethod();
+               //Is it a static method or constructor
+               if (md.isStatic()||md.getReturnType()==null)
+                   continue;
+               
+               if (superdesc!=null) {
+                   Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
+                   boolean foundmatch=false;
+                   for(Iterator matchit=possiblematches.iterator();matchit.hasNext();) {
+                       MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
+                       if (md.matches(matchmd)) {
+                           Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
+                           if (lbset!=null)
+                               for(Iterator<LocalityBinding> suplbit=lbset.iterator();suplbit.hasNext();) {
+                                   LocalityBinding suplb=suplbit.next();
+                                   if (lb.contextMatches(suplb)) {
+                                       foundmatch=true;
+                                       localitynumber.put(lb, localitynumber.get(suplb));
+                                       break;
+                                   }
+                               }
+                           break;
+                       }
+                   }
+                   if (!foundmatch)
+                       localitynumber.put(lb, new Integer(start++));
+               } else {
+                   localitynumber.put(lb, new Integer(start++));
+               }
+           }
+       classmethodcount.put(cd, new Integer(start));
+       return start;
+    }
+
     private int numberMethods(ClassDescriptor cd) {
        if (classmethodcount.containsKey(cd))
-           return ((Integer)classmethodcount.get(cd)).intValue();
+           return classmethodcount.get(cd).intValue();
        ClassDescriptor superdesc=cd.getSuperDesc();
        int start=0;
        if (superdesc!=null)
index 0221524ec3dbd10d44da28285c669963d4221645..6e7f80fc36e90a1007d60ff23b5e6ea9f555200d 100644 (file)
@@ -97,6 +97,9 @@ public class Main {
       if (state.TASK) {
          readSourceFile(state, ClassLibraryPrefix+"Object.java");
          readSourceFile(state, ClassLibraryPrefix+"TagDescriptor.java");
+      } else if (state.DSM) {
+         readSourceFile(state, ClassLibraryPrefix+"ThreadDSM.java");
+         readSourceFile(state, ClassLibraryPrefix+"ObjectJavaDSM.java");
       } else {
          if (state.THREAD) {
              readSourceFile(state, ClassLibraryPrefix+"Thread.java");
@@ -157,11 +160,12 @@ public class Main {
          CallGraph callgraph=new CallGraph(state);
          LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
          GenerateConversions gc=new GenerateConversions(la, state);
+         BuildCode bc=new BuildCode(state, bf.getMap(), tu, la);
+         bc.buildCode();
+      } else {
+         BuildCode bc=new BuildCode(state, bf.getMap(), tu);
+         bc.buildCode();
       }
-
-      BuildCode bc=new BuildCode(state, bf.getMap(), tu);
-      bc.buildCode();
-      
       System.exit(0);
   }
     
index 5c3e8b04d2e1dfd76d38afcaa9ffb3633f588a76..f1c465359397d92f082b170cd2ecc60214739b85 100644 (file)
@@ -1,14 +1,16 @@
 #include "localobjects.h"
+#include <string.h>
+
 void REVERT_OBJ(struct ___Object___ * obj) {
   int type=((int *)obj)[0];
-  struct ___Object___ * copyobj=obj->localcopy;
+  struct ___Object___ * copyobj=obj->___localcopy___;
   if (type<NUMCLASSES) {
     /* We have a normal object */
     int size=classsize[type];
     memcpy(obj, copyobj, size);
   } else {
     /* We have an array */
-    struct ArrayObject *ao=(struct ArrayObject *)orig;
+    struct ArrayObject *ao=(struct ArrayObject *)obj;
     int elementsize=classsize[type];
     int length=ao->___length___;
     int size=sizeof(struct ArrayObject)+length*elementsize;
@@ -27,23 +29,25 @@ void COPY_OBJ(struct ___Object___ *obj) {
     int size=classsize[type];
 #ifdef PRECISE_GC
     int ptrarray[]={1, (int) gl, (int) obj};
-    struct ___Object___ * newobj=mygcmalloc(ptrarray, size);
+    struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
 #else
     struct ___Object___ * newobj=FREEMALLOC(size);
 #endif
     memcpy(newobj, (struct ___Object___ *) ptrarray[1], size);
-    ((struct ___Object___*)ptrarray[1])->localcopy=newobj;
+    ((struct ___Object___*)ptrarray[1])->___localcopy___=newobj;
   } else {
     /* We have an array */
-    struct ArrayObject *ao=(struct ArrayObject *)orig;
+    struct ArrayObject *ao=(struct ArrayObject *)obj;
     int elementsize=classsize[type];
     int length=ao->___length___;
     int size=sizeof(struct ArrayObject)+length*elementsize;
 #ifdef PRECISE_GC
     int ptrarray[]={1, (int) gl, (int) obj};
-    struct ___Object___ * newobj=mygcmalloc(ptrarray, size);
+    struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
 #else
     struct ___Object___ * newobj=FREEMALLOC(size);
 #endif
-    ((struct ___Object___*)ptrarray[1])->localcopy=newobj;
+    memcpy(newobj, (struct ___Object___ *) ptrarray[1], size);
+    ((struct ___Object___*)ptrarray[1])->___localcopy___=newobj;
+  }
 }
index 2e35a765988f9b3ef50c67fcd76671c0799ab634..d32095ba627fc0516aee342c8b27d6ac85c62099 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef LOCALOBJECT_H
-#include LOCALOBJECT_H
+#define LOCALOBJECT_H
 #include "structdefs.h"
+#include "garbage.h"
 void REVERT_OBJ(struct ___Object___ *);
 #define COMMIT_OBJ(obj) obj->localcopy=NULL
 
index 1c73bf726b4b30bd08df3a1123ae3bfd015b1ccc..69000d15c82cbaf2a0f5490142ae4d9649334b2a 100755 (executable)
@@ -2,6 +2,7 @@
 
 printhelp() {
 echo -dsm distributed shared memory
+echo -mac distributed shared memory mac support
 echo -check generate check code
 echo -dmalloc link in dmalloc
 echo -recover compile task code
@@ -22,8 +23,10 @@ echo -help help
 }
 
 ROBUSTROOT=~/research/Robust/src
+DSMRUNTIME=$ROBUSTROOT/Runtime/DSTM/interface/
 REPAIRROOT=~/research/Repair/RepairCompiler/
 CURDIR=`pwd`
+DSMFLAG=false
 CHECKFLAG=false
 RECOVERFLAG=false
 USEDMALLOC=false
@@ -58,6 +61,10 @@ shift
 elif [[ $1 = '-dsm' ]]
 then
 JAVAOPTS="$JAVAOPTS -dsm"
+DSMFLAG=true
+elif [[ $1 = '-mac' ]]
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -DMAC"
 elif [[ $1 = '-taskstate' ]]
 then
 JAVAOPTS="$JAVAOPTS -taskstate"
@@ -183,6 +190,12 @@ $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/option.c \
 $ROBUSTROOT/Runtime/garbage.c $ROBUSTROOT/Runtime/socket.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
 
+if $DSMFLAG
+then
+EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -I$DSMRUNTIME"
+FILES="$FILES $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c"
+fi
+
 if $RECOVERFLAG
 then
 EXTRAOPTIONS="$EXTRAOPTIONS -DTASK"