/** 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 */
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);
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\"");
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\"");
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 */");
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) {
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
/******* 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) {
__thread struct objlist * newobjs;
#ifdef SANDBOX
-__thread jmp_buf aborttrans;
-__thread int abortenabled;
+#include "sandbox.h"
#endif
#ifdef DELAYCOMP
}
}
-#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