add likely/unlikely branch hints
authorbdemsky <bdemsky>
Fri, 30 Oct 2009 19:48:43 +0000 (19:48 +0000)
committerbdemsky <bdemsky>
Fri, 30 Oct 2009 19:48:43 +0000 (19:48 +0000)
fix gc/transaction interaction bug --- check at transaction abort whether we need to gc

Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/STM/commit.c
Robust/src/Runtime/runtime.h

index 86539904dcbbea5839882915242d3f75f69fab5f..5299961bfa1939023344a48fe141f73d332db7fc 100644 (file)
@@ -1751,10 +1751,9 @@ public class BuildCode {
          output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
        else if (this.state.MULTICOREGC) {
          output.println("if(gcflag) gc("+localsprefixaddr+");");
-       } else if (state.SINGLETM) {
+       } else {
          output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
-       } else
-         output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
+       }
       }
     }
 
@@ -2090,11 +2089,9 @@ public class BuildCode {
       if (callgraph.getAllMethods(md).contains(md)) {
         if(this.state.MULTICOREGC) {
           output.println("if(gcflag) gc("+localsprefixaddr+");");
-        } else if (state.SINGLETM) {
+        } else {
          output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
-       } else {
-          output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
-        }
+       }
       }
     }    
 
@@ -2723,10 +2720,9 @@ public class BuildCode {
          output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
        } else if(this.state.MULTICOREGC) {
          output.println("if (gcflag) gc("+localsprefixaddr+");");
-       } else if (state.SINGLETM) {
+       } else {
          output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
-       } else
-         output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
+       }
       } else
        output.println("/* nop */");
       break;
@@ -3083,6 +3079,8 @@ public class BuildCode {
     } else
       output.println("if (transCommit()) {");
     /* Transaction aborts if it returns true */
+    output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
+    
     output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
     if (state.DSM) {
       output.println("} else {");
@@ -3812,7 +3810,7 @@ public class BuildCode {
       type=elementtype.getSafeSymbol()+" ";
 
     if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) {
-      output.println("if (((unsigned int)"+generateTemp(fm, fen.getIndex(),lb)+") >= "+generateTemp(fm,fen.getSrc(),lb) + "->___length___)");
+      output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex(),lb)+") >= "+generateTemp(fm,fen.getSrc(),lb) + "->___length___))");
       output.println("failedboundschk();");
     }
     if (state.SINGLETM) {
@@ -3872,7 +3870,7 @@ public class BuildCode {
       type=elementtype.getSafeSymbol()+" ";
 
     if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) {
-      output.println("if (((unsigned int)"+generateTemp(fm, fsen.getIndex(),lb)+") >= "+generateTemp(fm,fsen.getDst(),lb) + "->___length___)");
+      output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex(),lb)+") >= "+generateTemp(fm,fsen.getDst(),lb) + "->___length___))");
       output.println("failedboundschk();");
     }
 
index f727267444e5e8728fd5473224e8c0e2a454d11a..a6e5f38a26ad8a9286dee1d658899bfad7225009 100644 (file)
@@ -61,12 +61,12 @@ int transCommit() {
     /* Look through all the objects in the transaction hash table */
     int finalResponse;
 #ifdef DELAYCOMP
-    if (c_numelements<(c_size>>1))
+    if (c_numelements<(c_size>>3))
       finalResponse=alttraverseCache(commitmethod, primitives, locals, params);
     else
       finalResponse=traverseCache(commitmethod, primitives, locals, params);
 #else
-    if (c_numelements<(c_size>>1))
+    if (c_numelements<(c_size>>3))
       finalResponse=alttraverseCache();
     else
       finalResponse=traverseCache();
@@ -92,6 +92,7 @@ int transCommit() {
 #ifdef SANDBOX
       abortenabled=1;
 #endif
+
       return TRANS_ABORT;
     }
     if(finalResponse == TRANS_COMMIT) {
index fca662c426c187f6fb8740ac54ce4666ee7be595..d3dcc04a1fd3d1680d1e926d3516a3f4e4219574 100644 (file)
@@ -25,6 +25,10 @@ extern int failurecount;
 extern void * curr_heapbase;
 extern void * curr_heaptop;
 
+#define likely(x) __builtin_expect((x),1)
+#define unlikely(x) __builtin_expect((x),0)
+
+
 #define TAGARRAYINTERVAL 10
 #define OBJECTARRAYINTERVAL 10