changes
authorbdemsky <bdemsky>
Fri, 9 Oct 2009 07:27:37 +0000 (07:27 +0000)
committerbdemsky <bdemsky>
Fri, 9 Oct 2009 07:27:37 +0000 (07:27 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/STM/stm.c
Robust/src/Runtime/STM/tm.h

index 0cac7b65b266715e43b76ece9ba9dac2a5f2d40a..223d673075372b6c331f3c8870f539392e7b1e1f 100644 (file)
@@ -125,6 +125,7 @@ public class BuildCode {
   /** The buildCode method outputs C code for all the methods.  The Flat
    * versions of the methods must already be generated and stored in
    * the State object. */
+  PrintWriter outsandbox=null;
 
   public void buildCode() {
     /* Create output streams to write to */
@@ -140,6 +141,9 @@ public class BuildCode {
     PrintWriter optionalheaders=null;
 
     try {
+      if (state.SANDBOX) {
+       outsandbox=new PrintWriter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true);
+      }
       outstructs=new PrintWriter(new FileOutputStream(PREFIX+"structdefs.h"), true);
       outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
       outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
@@ -170,6 +174,9 @@ public class BuildCode {
     outmethodheader.println("#include \"structdefs.h\"");
     if (state.DSM)
       outmethodheader.println("#include \"dstm.h\"");
+    if (state.SANDBOX) {
+      outmethodheader.println("#include \"sandbox.h\"");
+    }
     if (state.SINGLETM) {
       outmethodheader.println("#include \"tm.h\"");
       outmethodheader.println("#include \"delaycomp.h\"");
@@ -441,6 +448,9 @@ public class BuildCode {
     outmethod.println("#include \"methodheaders.h\"");
     outmethod.println("#include \"virtualtable.h\"");
     outmethod.println("#include \"runtime.h\"");
+    if (state.SANDBOX) {
+      outmethod.println("#include \"sandboxdefs.c\"");
+    }
     if (state.DSM) {
       outmethod.println("#include \"addPrefetchEnhance.h\"");
       outmethod.println("#include \"localobjects.h\"");
@@ -2565,13 +2575,16 @@ public class BuildCode {
       break;
 
     case FKind.FlatBackEdge:
+      if (state.SINGLETM&&state.SANDBOX&&locality.getAtomic(locality.getAtomic(lb).get(fn).intValue()>0)) {
+       output.println("if ((--transaction_check_counter)<=0) checkObjects();");
+      }
       if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
           || (this.state.MULTICOREGC)) {
        if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) {
          output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
        } else if(this.state.MULTICOREGC) {
-      output.println("if (gcflag) gc("+localsprefixaddr+");");
-    } else
+         output.println("if (gcflag) gc("+localsprefixaddr+");");
+       } else
          output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
       } else
        output.println("/* nop */");
@@ -2821,6 +2834,7 @@ public class BuildCode {
       output.println(generateTemp(fm, fion.getDst(), lb)+"=instanceof("+generateTemp(fm,fion.getSrc(),lb)+","+type+");");
   }
 
+  int sandboxcounter=0;
   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==null) {
@@ -2832,6 +2846,11 @@ public class BuildCode {
       return;
 
 
+    if (state.SANDBOX) {
+      outsandbox.println("int atomiccounter"+sandboxcounter+"=LOW_CHECK_FREQUENCY;");
+      output.println("counter_reset_pointer=&atomiccounter"+sandboxcounter+";");
+    }
+
     if (state.DELAYCOMP) {
       AtomicRecord ar=atomicmethodmap.get(faen);
       //copy in
@@ -2879,6 +2898,10 @@ public class BuildCode {
     /******* Tell the runtime to start the transaction *******/
 
     output.println("transstart"+faen.getIdentifier()+":");
+    if (state.SANDBOX) {
+      output.println("transaction_check_counter=*counter_reset_pointer;");
+      sandboxcounter++;
+    }
     output.println("transStart();");
 
     if (state.ABORTREADERS||state.SANDBOX) {
index 6795af2898e64e40a18840e22c9e833c9174c0a9..57c97d6b2fdb080e5c65c2506070aa9a3c87b414 100644 (file)
@@ -20,8 +20,7 @@ __thread objstr_t *t_reserve;
 __thread struct objlist * newobjs;
 
 #ifdef SANDBOX
-__thread jmp_buf aborttrans;
-__thread int abortenabled;
+#include "sandbox.h"
 #endif
 
 #ifdef DELAYCOMP
@@ -300,38 +299,6 @@ void *objstrAlloc(unsigned int size) {
   }
 }
 
-#ifdef SANDBOX
-/* Do sandboxing */
-void errorhandler(int sig, struct sigcontext ctx) {
-  printf("Error\n");
-  if (abortenabled&&checktrans())
-    longjmp(aborttrans, 1);
-  threadhandler(sig, ctx);
-}
-
-int checktrans() {
-  /* Create info to keep track of objects that can be locked */
-  chashlistnode_t *curr = c_list;
-
-  /* Inner loop to traverse the linked list of the cache lookupTable */
-  while(likely(curr != NULL)) {
-    //if the first bin in hash table is empty
-    objheader_t * headeraddr=&((objheader_t *) curr->val)[-1];
-    objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t));
-    unsigned int version = headeraddr->version;
-    
-    if (header->lock==0) {
-      return 1;
-    }
-    CFENCE;
-    if (version!=header->version) {
-      return 1;
-    }
-    curr = curr->lnext;
-  }
-  return 0;
-}
-#endif
 
 /* =============================================================
  * transRead
index 9f7847abf5da3a184a8d078bda0d78117adc88bd..5f3a4f7bc4d35ebc4040a69043487986619fdad5 100644 (file)
@@ -217,11 +217,6 @@ int getReadAbortCount(int, int, void*, int*, int*, int, objheader_t*, int*);
 objheader_t * needLock(objheader_t *, void *);
 #endif
 #ifdef SANDBOX
-#include <setjmp.h>
-#include <signal.h>
-extern __thread jmp_buf aborttrans;
-extern __thread int abortenabled;
-int checktrans();
-void errorhandler(int sig, struct sigcontext ctx);
+#include "sandbox.h"
 #endif
 #endif