added test files
authoradash <adash>
Fri, 7 Dec 2007 18:42:17 +0000 (18:42 +0000)
committeradash <adash>
Fri, 7 Dec 2007 18:42:17 +0000 (18:42 +0000)
C code for prefetch- still needs some work
other minor changes

Robust/src/Analysis/Prefetch/PrefetchAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatPrefetchNode.java
Robust/src/Runtime/DSTM/interface/trans.c
Robust/src/Tests/Atomic2.java
Robust/src/Tests/Atomic3.java [new file with mode: 0644]
Robust/src/Tests/Prefetch/FieldPointer.java [new file with mode: 0644]

index c62040a468cfd4e0df9fec9c53e9e5f1cba07380..94210be7076866e2b05046d692d854e124d48b2b 100644 (file)
@@ -115,6 +115,7 @@ public class PrefetchAnalysis {
                        if(newprefetchset.size() > 0) {
                                addFlatPrefetchNode(newprefetchset);
                        }
+                       //printMethod(fm);
                }
        }
 
index 7d484a856952492d8cc0cf222a3f8a9e71c72b2d..61d1a2d6e38f3086dc25901864335d8b1faa4056 100644 (file)
@@ -33,6 +33,7 @@ public class BuildCode {
     public static boolean GENERATEPRECISEGC=false;
     public static String PREFIX="";
     public static String arraytype="ArrayObject";
+    public static int count = 0;
     Virtual virtualcalls;
     TypeUtil typeutil;
     private int maxtaskparams=0;
@@ -1421,37 +1422,128 @@ public class BuildCode {
     }
  
     public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
-       System.out.println("Inside generateFlatPrefetchNode()");
-       if (state.PREFETCH) {
-           System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp);
-           Iterator it = fpn.hspp.iterator();
-           for(;it.hasNext();) {
-                PrefetchPair pp = (PrefetchPair) it.next();
-                //TODO handle arrays in prefetch tuples, currently only handle fields
-                Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base);
-                System.out.println("DEBUG-> generateFlatPrefetchNode()" + statusbase);
-                if(statusbase == LocalityAnalysis.GLOBAL) {
-                    // Generate oid for base
-                } else {
-                    for(int i = 0; i<pp.desc.size(); i++) {
-                       Object o = pp.desc.get(i);
-                       if(!(o instanceof IndexDescriptor)) {
-                               FieldDescriptor fd = (FieldDescriptor) o;
-                               Integer statusfd = locality.getNodePreTempInfo(lb,fpn).get(fd);
-                               System.out.println("DEBUG-> generateFlatPrefetchNode() fd" + statusfd);
-                               //find out the locality of the fieldDescriptor
-                               if(statusfd == LocalityAnalysis.GLOBAL) {
-                                       //generate oid for it
-                               }
-                       }
-                    }
-                }
-             }
-             //Each temp descriptor can be an oid
-            //Find locality of each prefetch tuple in the FLatPrefetchNode
-            //Separate them as Local or Global
-            //generate oids and offset value for prefetch tuple
-       }
+           System.out.println("DEBUG -> Inside generateFlatPrefetchNode() " + fm.toString());
+           short[] arrayfields = null;
+           Vector fieldoffset = new Vector();
+           Vector oids = new Vector();
+           short offsetcount = 0;
+           int tuplecount = 0;
+           int i;
+          
+           if (state.PREFETCH) {
+                   System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp);
+                   Iterator it = fpn.hspp.iterator();
+                   output.println("/* prefetch */");
+                   /* TODO Get rid of this */
+                   /* The while loop below removes all prefetch tuples with arrays from the set of prefetches */
+                   while(it.hasNext()) {
+                           PrefetchPair pp = (PrefetchPair) it.next();
+                           for(i = 0; i < pp.desc.size(); i++) {
+                                   if(pp.getDescAt(i) instanceof IndexDescriptor) {
+                                           fpn.hspp.remove((PrefetchPair) pp);
+                                           it = fpn.hspp.iterator(); //May not be the best way ...replace coding in a better fashion
+                                           break;
+                                   }
+                           }
+                   }
+                   output.println("   int numtuples_" + count + " = " + fpn.getNumPairs() + ";");
+                   int[] endoffsetarry = new int[fpn.getNumPairs()];
+                   output.print("   unsigned int oidarray_" + count + "[] = {");
+                   it = fpn.hspp.iterator();
+                   while(it.hasNext()) {
+                           PrefetchPair pp = (PrefetchPair) it.next();
+                           offsetcount = 0;
+                           //TODO handle arrays in prefetch tuples, currently only handle fields
+                           Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base);
+                           FieldDescriptor fd = (FieldDescriptor)pp.desc.get(0);
+                           String oid = new String("(unsigned int) " + generateTemp(fm, pp.base, lb) + "->" + ((FieldDescriptor)fd).getSafeSymbol());
+                           oids.add(oid);
+                           for(i = 1; i < pp.desc.size(); i++) {
+                                   Object desc = pp.desc.get(i);
+                                   offsetcount++;
+                                   TypeDescriptor newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType();
+                                   String newfieldoffset = new String("(short)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+ 
+                                                   ((FieldDescriptor)desc).getSafeSymbol()+ "))");
+                                   fieldoffset.add(newfieldoffset);
+                           }
+                           if(tuplecount > 0) {
+                                   endoffsetarry[tuplecount] = endoffsetarry[tuplecount-1] + offsetcount;
+                           }else {
+                                   endoffsetarry[tuplecount] = offsetcount;
+                           }
+                           //if(statusbase == LocalityAnalysis.LOCAL) {
+                           if(statusbase == LocalityAnalysis.GLOBAL) {
+                                   System.out.println("DEBUG-> Is Global");
+                                   //Check to see if node is a inside or outside a transaction
+                                   /*
+                                      if(locality.getAtomic(lb).get(fpn).intValue() > 0) {
+                                   //TODO Is this correct ? or generate pointer code in C 
+                                   // return;
+                                   } else {
+                                   output.println("/* PP: " + generateTemp(fm, pp.base, lb));
+                                   }
+                                   */
+                                   // Generate oid for base
+                           } else {
+                                   for(i = 0; i<pp.desc.size(); i++) {
+                                           Object o = pp.desc.get(i);
+                                           if(!(o instanceof IndexDescriptor)) {
+                                                   //FieldDescriptor fd = (FieldDescriptor) o;
+                                                   Integer statusfd = locality.getNodePreTempInfo(lb,fpn).get(fd);
+                                                   //System.out.println("DEBUG-> generateFlatPrefetchNode() fd" + statusfd);
+                                                   //find out the locality of the fieldDescriptor
+                                                   if(statusfd == LocalityAnalysis.GLOBAL) {
+                                                           //generate oid for it
+                                                   }
+                                           }
+                                   }
+                           }
+                           tuplecount++;
+                   }
+                   /*Create C code for oid array */
+                   boolean needcomma=false;
+                   it = oids.iterator();
+                   while(it.hasNext()) {
+                           if (needcomma)
+                                   output.print(", ");
+                           output.print(it.next());
+                           needcomma=true;
+                   }
+                   output.println("};");
+                   /*Create C code for endoffset values */
+                   output.print("   unsigned short endoffsetarry_" + count +"[] = {");
+                   needcomma=false;
+                   for(i = 0; i<endoffsetarry.length; i++){
+                           if (needcomma)
+                                   output.print(", ");
+                           output.print(endoffsetarry[i]);
+                           needcomma=true;
+                   }
+                   output.println("};");
+                   /*Create C code for Field Offset Values */
+                   it = fieldoffset.iterator();
+                   output.print("   short fieldarry_" + count +"[] = {");
+                   needcomma=false;
+                   while(it.hasNext()) {
+                           if (needcomma)
+                                   output.print(", ");
+                           output.print(it.next());
+                           needcomma=true;
+                   }
+                   output.println("};");
+                   /* make the prefetch call to Runtime */
+                   output.println("   prefetch(&numtuples_"+count+ ", oidarray_"+count+ ", endoffsetarry_"+
+                                   count+", fieldarry_"+count+");");
+                   //Each temp descriptor can be an oid
+                   //Find locality of each prefetch tuple in the FLatPrefetchNode
+                   //Separate them as Local or Global
+                   //generate oids and offset value for prefetch tuple
+                   count++;
+           }   
     }   
 
     public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
@@ -1728,7 +1820,7 @@ public class BuildCode {
            } else if (status==LocalityAnalysis.EITHER) {
                //Code is reading from a null pointer
                output.println("if ("+generateTemp(fm, ffn.getSrc(),lb)+") {");
-               output.println("printf(\"BIG ERROR\n\");exit(-1);}");
+               output.println("printf(\"BIG ERROR\\n\");exit(-1);}");
                //This should throw a suitable null pointer error
                output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
            } else
@@ -1778,7 +1870,7 @@ public class BuildCode {
            } else if (statusdst.equals(LocalityAnalysis.EITHER)) {
                //writing to a null...bad
                output.println("if ("+dst+") {");
-               output.println("printf(\"BIG ERROR 2\n\");exit(-1);}");
+               output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}");
                if (srcglobal)
                    output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;");
                else
index 81a20d1d3fa5c0970ed2c09b8d9353bfde953299..c89bb90b189b8f487d56320844e6a1344008df67 100644 (file)
@@ -28,4 +28,8 @@ public class FlatPrefetchNode extends FlatNode {
        public HashSet<PrefetchPair> getPrefetchPairs() {
                return hspp;
        }
+
+       public int getNumPairs() {
+               return hspp.size();
+       }
 }
index d702c66bc346bd217469d829189dbdd7714f38b5..08088586472b504eb935aca725deabf5f6a71d3e 100644 (file)
@@ -1561,13 +1561,15 @@ void getPrefetchResponse(int count, int sd) {
 unsigned short getObjType(unsigned int oid)
 {
        objheader_t *objheader;
-       unsigned short numoffsets = 0;
+       unsigned short numoffset[] ={0};
+       short fieldoffset[] ={};
 
        if ((objheader = (objheader_t *) mhashSearch(oid)) == NULL)
        {
                if ((objheader = (objheader_t *) prehashSearch(oid)) == NULL)
                {
-                       prefetch(1, &oid, &numoffsets, NULL);
+                       //prefetch(1, &oid, &numoffsets, NULL);
+                       prefetch(1, &oid, numoffset, fieldoffset);
                        pthread_mutex_lock(&pflookup.lock);
                        while ((objheader = (objheader_t *) prehashSearch(oid)) == NULL)
                        {
index 4dbf173685be037fa8410ae22147c8f53ad5e992..c96ef202b669e389cf5047d20def94ba40f4748a 100644 (file)
@@ -3,7 +3,8 @@ public class Atomic2 extends Thread {
     }
     int count;
     public static void main(String[] st) {
-       int mid = (128<<24)|(200<<16)|(9<<8)|26;
+       //int mid = (128<<24)|(200<<16)|(9<<8)|26;
+       int mid = (128<<24)|(195<<16)|(175<<8)|70;
        Atomic2 t =null;
        atomic {
            t= global new Atomic2();
diff --git a/Robust/src/Tests/Atomic3.java b/Robust/src/Tests/Atomic3.java
new file mode 100644 (file)
index 0000000..0012863
--- /dev/null
@@ -0,0 +1,69 @@
+public class Atomic3 extends Thread {
+       public Atomic3() {
+       }
+       static Tree root;
+       Integer count;
+       public static void main(String[] st) {
+               int mid = (128<<24)|(195<<16)|(175<<8)|70;
+               int b;
+               Atomic3 at3 = null;
+               Integer z;
+               atomic {
+                       at3 = global new Atomic3();
+                       z = global new Integer(300);
+                       at3.root = global new Tree();
+                       at3.root.insert(z);
+                       b = at3.root.value.intValue();
+               }
+               atomic{
+                       at3.root.item = 2445;
+               }
+               System.printInt(b);
+               System.printString("\n");
+               System.printString("Starting\n");
+               at3.start(mid);
+               System.printString("Finished\n");
+               while(true) {
+                       ;
+               }
+       }
+
+       public int run() {
+               int a;
+               atomic {
+                       a = root.value.intValue();
+                       //a = root.item;
+               }
+               System.printInt(a);
+               System.printString("\n");
+       }
+}
+
+public class Tree {
+       public Integer value;
+       public int item;
+       public Tree left;
+       public Tree right;
+
+       public Tree() {
+       }
+
+       public Tree(Integer item) {
+               value = item;
+               left = null;
+               right = null;
+       }
+
+       public Tree(Integer item , Tree l, Tree r) {
+               value = item;
+               left =l;
+               right = r;
+       }
+
+       public Tree insert(Integer a) {
+               value = a;
+               left = null;
+               right = null;
+               return this;
+       }
+}
diff --git a/Robust/src/Tests/Prefetch/FieldPointer.java b/Robust/src/Tests/Prefetch/FieldPointer.java
new file mode 100644 (file)
index 0000000..c490f03
--- /dev/null
@@ -0,0 +1,46 @@
+public class FieldPointer {
+       Account x;
+       public FieldPointer() {
+       }
+
+       public static void main(String[] args) {
+               int bal;
+               FieldPointer fp = new FieldPointer();
+               fp.x = new Account();
+               fp.x.name = new String("TestAccount");
+               fp.x.accountid = new Integer(12345);
+               fp.x.balance = new Item();
+               fp.x.balance.i = new Integer(11000);
+               bal = fp.getBalance(fp.x.accountid);
+               if(bal < 7500) 
+                       bal = bal + fp.x.getBalance().intValue();
+               else 
+                       bal = fp.x.getBalance().intValue();
+               System.printInt(bal);
+       }
+
+       public int getBalance(Integer accountid) {
+               if(accountid.intValue() > 12000) {
+                       return 10000;
+               } else {
+                       return 5000;
+               }
+       }
+}
+
+public class Account {
+       String name;
+       Integer accountid;
+       Item balance;
+       public Account() {
+       }
+       public Integer getBalance() {
+               return balance.i;
+       }
+}
+
+public class Item {
+       Integer i;
+       public Item() {
+       }
+}