From 9ff7d02d27765c85305dd0572a43ed0b88339a24 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 30 Oct 2009 19:48:43 +0000 Subject: [PATCH] add likely/unlikely branch hints fix gc/transaction interaction bug --- check at transaction abort whether we need to gc --- Robust/src/IR/Flat/BuildCode.java | 22 ++++++++++------------ Robust/src/Runtime/STM/commit.c | 5 +++-- Robust/src/Runtime/runtime.h | 4 ++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 86539904..5299961b 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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();"); } diff --git a/Robust/src/Runtime/STM/commit.c b/Robust/src/Runtime/STM/commit.c index f7272674..a6e5f38a 100644 --- a/Robust/src/Runtime/STM/commit.c +++ b/Robust/src/Runtime/STM/commit.c @@ -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) { diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index fca662c4..d3dcc04a 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -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 -- 2.34.1