From 6559cd4dbf1fa75797489cb57850471d9a6145f3 Mon Sep 17 00:00:00 2001 From: adash Date: Mon, 4 May 2009 19:21:12 +0000 Subject: [PATCH] do a make tabbing protect stats insde bounds add function to stm for instrumentation ---- still working on locks --- Robust/src/ClassLibrary/Character.java | 23 +-- Robust/src/ClassLibrary/FileInputStream.java | 6 +- Robust/src/ClassLibrary/HashMapIterator.java | 4 +- Robust/src/ClassLibrary/Hashtable.java | 2 +- Robust/src/ClassLibrary/Integer.java | 4 +- Robust/src/ClassLibrary/Iterator.java | 8 +- Robust/src/ClassLibrary/LinkedList.java | 68 +++---- .../src/ClassLibrary/PushbackInputStream.java | 18 +- .../src/ClassLibrary/SocketInputStream.java | 30 +-- Robust/src/ClassLibrary/String.java | 16 +- Robust/src/ClassLibrary/System.java | 6 +- Robust/src/ClassLibrary/Vector.java | 2 +- Robust/src/IR/Flat/BuildCode.java | 189 +++++++++--------- Robust/src/Runtime/STM/stm.c | 186 +++++++++++------ Robust/src/Runtime/STM/stmlookup.c | 26 +-- Robust/src/Runtime/STM/tm.h | 40 ++-- Robust/src/Runtime/runtime.c | 8 +- Robust/src/buildscript | 1 + 18 files changed, 352 insertions(+), 285 deletions(-) diff --git a/Robust/src/ClassLibrary/Character.java b/Robust/src/ClassLibrary/Character.java index 521a174e..1febbc3c 100644 --- a/Robust/src/ClassLibrary/Character.java +++ b/Robust/src/ClassLibrary/Character.java @@ -16,12 +16,12 @@ public class Character { } char value; - - public Character( char c ) { + + public Character(char c) { value = c; } - public Character( Character c ) { + public Character(Character c) { value = c.value; } @@ -32,15 +32,14 @@ public class Character { public static boolean isWhitespace(char character) { boolean returnValue; if ( (character == '\t') || - (character == '\n') || - (character == ' ') || - (character == '\u000C') || - (character == '\u001C') || - (character == '\u001D') || - (character == '\u001E') || - (character == '\u001F')) - { - returnValue = true; + (character == '\n') || + (character == ' ') || + (character == '\u000C') || + (character == '\u001C') || + (character == '\u001D') || + (character == '\u001E') || + (character == '\u001F')) { + returnValue = true; } else { returnValue = false; } diff --git a/Robust/src/ClassLibrary/FileInputStream.java b/Robust/src/ClassLibrary/FileInputStream.java index eeda05dd..44d88892 100644 --- a/Robust/src/ClassLibrary/FileInputStream.java +++ b/Robust/src/ClassLibrary/FileInputStream.java @@ -43,11 +43,11 @@ public class FileInputStream extends InputStream { public String readLine() { String line = ""; int c = read(); - + // if we're already at the end of the file // or there is an error, don't even return // the empty string - if( c <= 0 ) { + if( c <= 0 ) { return null; } @@ -57,7 +57,7 @@ public class FileInputStream extends InputStream { c = read(); } - // peek and consume characters that are carriage + // peek and consume characters that are carriage // returns or line feeds so the whole line is read // and returned, and none of the line-ending chars c = peek(); diff --git a/Robust/src/ClassLibrary/HashMapIterator.java b/Robust/src/ClassLibrary/HashMapIterator.java index e297cf5f..f540d335 100644 --- a/Robust/src/ClassLibrary/HashMapIterator.java +++ b/Robust/src/ClassLibrary/HashMapIterator.java @@ -45,7 +45,7 @@ class HashMapIterator extends Iterator { } public void remove() { - System.out.println( "HashMapIterator.remove() not implemented." ); - System.exit( -1 ); + System.out.println("HashMapIterator.remove() not implemented."); + System.exit(-1); } } diff --git a/Robust/src/ClassLibrary/Hashtable.java b/Robust/src/ClassLibrary/Hashtable.java index a8043524..9ecbdadd 100644 --- a/Robust/src/ClassLibrary/Hashtable.java +++ b/Robust/src/ClassLibrary/Hashtable.java @@ -1,7 +1,7 @@ public class Hashtable extends HashMap { public Hashtable() { - HashMap(16, 0.75f); + HashMap(16, 0.75f); } public Hashtable(int initialCapacity) { diff --git a/Robust/src/ClassLibrary/Integer.java b/Robust/src/ClassLibrary/Integer.java index 831e78f9..7bb38585 100644 --- a/Robust/src/ClassLibrary/Integer.java +++ b/Robust/src/ClassLibrary/Integer.java @@ -77,8 +77,8 @@ public class Integer { return String.valueOf(value); } - public static String toString( int i ) { - Integer I = new Integer( i ); + public static String toString(int i) { + Integer I = new Integer(i); return I.toString(); } diff --git a/Robust/src/ClassLibrary/Iterator.java b/Robust/src/ClassLibrary/Iterator.java index e88a4854..f80ed50d 100644 --- a/Robust/src/ClassLibrary/Iterator.java +++ b/Robust/src/ClassLibrary/Iterator.java @@ -1,16 +1,16 @@ public class Iterator { boolean hasNext() { - System.out.println( "Iterator is an abstract class." ); + System.out.println("Iterator is an abstract class."); System.exit(-1); } Object next() { - System.out.println( "Iterator is an abstract class." ); + System.out.println("Iterator is an abstract class."); System.exit(-1); } void remove() { - System.out.println( "Iterator is an abstract class." ); + System.out.println("Iterator is an abstract class."); System.exit(-1); - } + } } diff --git a/Robust/src/ClassLibrary/LinkedList.java b/Robust/src/ClassLibrary/LinkedList.java index 72f57dd2..e2af0104 100644 --- a/Robust/src/ClassLibrary/LinkedList.java +++ b/Robust/src/ClassLibrary/LinkedList.java @@ -3,9 +3,9 @@ public class LinkedListElement { public LinkedListElement prev; public Object element; - public LinkedListElement( Object e, - LinkedListElement n, - LinkedListElement p ) { + public LinkedListElement(Object e, + LinkedListElement n, + LinkedListElement p) { element = e; next = n; prev = p; @@ -21,32 +21,32 @@ public class LinkedList { clear(); } - public add( Object o ) { + public add(Object o) { if( tail == null ) { - head = new LinkedListElement( o, null, null ); + head = new LinkedListElement(o, null, null); tail = head; } else { - tail.next = new LinkedListElement( o, null, tail ); + tail.next = new LinkedListElement(o, null, tail); tail = tail.next; } size++; } - public addFirst( Object o ) { + public addFirst(Object o) { if( head == null ) { - head = new LinkedListElement( o, null, null ); + head = new LinkedListElement(o, null, null); tail = head; } else { - head.prev = new LinkedListElement( o, head, null ); + head.prev = new LinkedListElement(o, head, null); head = head.prev; } size++; } - public addLast( Object o ) { - add( o ); + public addLast(Object o) { + add(o); } public clear() { @@ -64,26 +64,26 @@ public class LinkedList { } public Object clone() { - System.out.println( "LinkedList.clone() not implemented." ); + System.out.println("LinkedList.clone() not implemented."); System.exit(-1); } - public boolean contains( Object o ) { + public boolean contains(Object o) { LinkedListElement e = head; if (o==null) { while(e!=null) { if (e.element==null) { return true; - } - e=e.next; + } + e=e.next; } return false; } else { while( e != null ) { - if (o.equals(e.element)) { - return true; - } - e = e.next; + if (o.equals(e.element)) { + return true; + } + e = e.next; } } return false; @@ -100,7 +100,7 @@ public class LinkedList { if( tail == null ) { return null; } - return tail.element; + return tail.element; } public Object element() { @@ -121,7 +121,7 @@ public class LinkedList { public Object removeFirst() { if( head == null ) { - System.out.println( "LinkedList: illegal removeFirst()" ); + System.out.println("LinkedList: illegal removeFirst()"); System.exit(-1); } Object o = head.element; @@ -137,7 +137,7 @@ public class LinkedList { public Object removeLast() { if( tail == null ) { - System.out.println( "LinkedList: illegal removeLast()" ); + System.out.println("LinkedList: illegal removeLast()"); System.exit(-1); } Object o = tail.element; @@ -151,9 +151,9 @@ public class LinkedList { return o; } - public void remove( Object o ) { + public void remove(Object o) { if( head == null ) { - System.out.println( "LinkedList: illegal remove( Object o )" ); + System.out.println("LinkedList: illegal remove( Object o )"); System.exit(-1); } LinkedListElement e = head; @@ -170,8 +170,8 @@ public class LinkedList { } e = e.next; } - System.out.println( "LinkedList: illegal remove( Object o ), "+o+" not found" ); - System.exit(-1); + System.out.println("LinkedList: illegal remove( Object o ), "+o+" not found"); + System.exit(-1); } public Object pop() { @@ -180,12 +180,12 @@ public class LinkedList { return o; } - public void push( Object o ) { - addFirst( o ); + public void push(Object o) { + addFirst(o); } public Iterator iterator() { - return new LinkedListIterator( this ); + return new LinkedListIterator(this); } } @@ -193,8 +193,8 @@ public class LinkedListIterator extends Iterator { LinkedList ll; LinkedListElement itr; Object removeable; - - public LinkedListIterator( LinkedList ll ) { + + public LinkedListIterator(LinkedList ll) { this.ll = ll; itr = ll.head; removeable = null; @@ -206,7 +206,7 @@ public class LinkedListIterator extends Iterator { public Object next() { if( itr == null ) { - System.out.println( "LinkedListIterator: illegal next()" ); + System.out.println("LinkedListIterator: illegal next()"); System.exit(-1); } removeable = itr.element; @@ -216,10 +216,10 @@ public class LinkedListIterator extends Iterator { public void remove() { if( removeable == null ) { - System.out.println( "LinkedListIterator: illegal remove()" ); + System.out.println("LinkedListIterator: illegal remove()"); System.exit(-1); } - ll.remove( removeable ); + ll.remove(removeable); removeable = null; } } diff --git a/Robust/src/ClassLibrary/PushbackInputStream.java b/Robust/src/ClassLibrary/PushbackInputStream.java index fb29b416..3e3d52f1 100644 --- a/Robust/src/ClassLibrary/PushbackInputStream.java +++ b/Robust/src/ClassLibrary/PushbackInputStream.java @@ -19,7 +19,7 @@ public class PushbackInputStream { private int bottom; private int[] stack; - + public PushbackInputStream(FileInputStream fis) { in = fis; max = 1000; @@ -32,7 +32,7 @@ public class PushbackInputStream { stack = new int[max]; } - + public int read() { int v; @@ -47,11 +47,11 @@ public class PushbackInputStream { // put whatever it is in the ring buffer ring[index] = v; - + // keep ring buffer index - ++index; - if( index == max ) { - index = 0; + ++index; + if( index == max ) { + index = 0; } // user gets what they want @@ -64,11 +64,11 @@ public class PushbackInputStream { // the unread stack can only get so high if( top == max ) { - System.printString( "PushbackInputStream: max reached" ); - System.exit( -1 ); + System.printString("PushbackInputStream: max reached"); + System.exit(-1); } // put it on the unread stack stack[top] = ring[index]; - } + } } \ No newline at end of file diff --git a/Robust/src/ClassLibrary/SocketInputStream.java b/Robust/src/ClassLibrary/SocketInputStream.java index 97afc287..807cab6d 100644 --- a/Robust/src/ClassLibrary/SocketInputStream.java +++ b/Robust/src/ClassLibrary/SocketInputStream.java @@ -17,21 +17,21 @@ public class SocketInputStream extends InputStream { } public int readAll(byte[] b) { - int offset=read(b); - if (offset<0) - return offset; - int toread=b.length-offset; - while(toread>0) { - byte[] t=new byte[toread]; - int rd=read(t); - if (rd<0) - return rd; - for(int i=0;i0) { + byte[] t=new byte[toread]; + int rd=read(t); + if (rd<0) + return rd; + for(int i=0; i= 0; j++) { long basePower = 1; for(int x=0; x 0; k--) { - if(k == i) //if a decimal point was previously found - { //insert it where its meant to be - output.append((char)46); + if(k == i) { //if a decimal point was previously found + //insert it where its meant to be + output.append((char)46); } long basePower = 1; for(int x=0; x<(k-1); x++) { - basePower*= 10; + basePower*= 10; } nodecimal = ((long) (valueA - decimal) / basePower); decimal += nodecimal*basePower; @@ -375,11 +375,11 @@ public class String { return new String(chararray); } - public int compareTo( String s ) { + public int compareTo(String s) { int lenDiff = this.length() - s.length(); if( lenDiff != 0 ) { return lenDiff; - } + } for( int i = 0; i < this.length(); ++i ) { int valDiff = this.charAt(i) - s.charAt(i); if( valDiff != 0 ) { diff --git a/Robust/src/ClassLibrary/System.java b/Robust/src/ClassLibrary/System.java index 9e43bd40..ef6caa03 100644 --- a/Robust/src/ClassLibrary/System.java +++ b/Robust/src/ClassLibrary/System.java @@ -11,7 +11,7 @@ public class System { public static void println(String s) { System.printString(s+"\n"); } - + public static void println(Object o) { System.printString(""+o+"\n"); } @@ -23,7 +23,7 @@ public class System { public static void println(double o) { System.printString(""+o+"\n"); } - + public static void print(String s) { System.printString(s); } @@ -39,7 +39,7 @@ public class System { public static void print(double o) { System.printString(""+o); } - + public static void error() { System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n"); } diff --git a/Robust/src/ClassLibrary/Vector.java b/Robust/src/ClassLibrary/Vector.java index f4d1f954..42ab24f9 100644 --- a/Robust/src/ClassLibrary/Vector.java +++ b/Robust/src/ClassLibrary/Vector.java @@ -9,7 +9,7 @@ public class Vector { array=new Object[10]; } - public Vector( int size ) { + public Vector(int size) { capacityIncrement=0; this.size=0; array=new Object[size]; diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 86a790b1..ea2363f0 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -72,7 +72,7 @@ public class BuildCode { state=st; callgraph=new CallGraph(state); if (state.SINGLETM) - oidstr="___objlocation___"; + oidstr="___objlocation___"; this.temptovar=temptovar; paramstable=new Hashtable(); tempstable=new Hashtable(); @@ -188,8 +188,8 @@ public class BuildCode { nonSESEpass = false; while( !setSESEtoGen.isEmpty() ) { FlatSESEEnterNode fsen = setSESEtoGen.iterator().next(); - setSESEtoGen.remove( fsen ); - generateMethodSESE( fsen, fsen.getEnclosingFlatMeth(), null, outmethod ); + setSESEtoGen.remove(fsen); + generateMethodSESE(fsen, fsen.getEnclosingFlatMeth(), null, outmethod); } } else { assert setSESEtoGen.isEmpty(); @@ -235,16 +235,16 @@ public class BuildCode { outmethod.println("int main(int argc, const char *argv[]) {"); outmethod.println(" int i;"); if (state.DSM) { - outmethod.println("#ifdef TRANSSTATS \n"); - outmethod.println("handle();\n"); - outmethod.println("#endif\n"); + outmethod.println("#ifdef TRANSSTATS \n"); + outmethod.println("handle();\n"); + outmethod.println("#endif\n"); } if (state.THREAD||state.DSM||state.SINGLETM) { outmethod.println("initializethreads();"); - outmethod.println("#ifdef STMSTATS \n"); - outmethod.println(" for(i=0; i0;level--) { + for(; level>0; level--) { TypeDescriptor supertd=new TypeDescriptor(objectclass); supertd.setArrayCount(level); type=state.getArrayNumber(supertd); @@ -969,8 +973,7 @@ public class BuildCode { if (lb!=null) { paramstable.put(lb, objectparams); backuptable.put(lb, new Hashtable()); - } - else if (md!=null) + } else if (md!=null) paramstable.put(md, objectparams); else paramstable.put(task, objectparams); @@ -1479,48 +1482,48 @@ public class BuildCode { } } - generateCode( fm.getNext(0), fm, lb, null, output ); + generateCode(fm.getNext(0), fm, lb, null, output); output.println("}\n\n"); } - protected void generateMethodSESE( FlatSESEEnterNode fsen, - FlatMethod fm, - LocalityBinding lb, - PrintWriter output ) { + protected void generateMethodSESE(FlatSESEEnterNode fsen, + FlatMethod fm, + LocalityBinding lb, + PrintWriter output) { //output.println( "void _SESE"+fsen.getPrettyIdentifier()+ - //" {\n" ); + //" {\n" ); //generateCode( fsen.getNext(0), fm, lb, fsen.getFlatExit(), output ); //output.println( "}\n\n" ); /* - output.println("struct sese"+faen.getPrettyIdentifier()+"in {"); - Iterator itr = faen.getInVarSet().iterator(); - while( itr.hasNext() ) { - TempDescriptor td = itr.next(); - output.println(" "+td+";"); - } - output.println("}"); + output.println("struct sese"+faen.getPrettyIdentifier()+"in {"); + Iterator itr = faen.getInVarSet().iterator(); + while( itr.hasNext() ) { + TempDescriptor td = itr.next(); + output.println(" "+td+";"); + } + output.println("}"); - output.println("struct sese"+faen.getPrettyIdentifier()+"out {"); - itr = faen.getOutVarSet().iterator(); - while( itr.hasNext() ) { - TempDescriptor td = itr.next(); - output.println(" "+td+";"); - } - output.println("}"); - */ + output.println("struct sese"+faen.getPrettyIdentifier()+"out {"); + itr = faen.getOutVarSet().iterator(); + while( itr.hasNext() ) { + TempDescriptor td = itr.next(); + output.println(" "+td+";"); + } + output.println("}"); + */ } - protected void generateCode( FlatNode first, - FlatMethod fm, - LocalityBinding lb, - FlatSESEExitNode stop, - PrintWriter output ) { + protected void generateCode(FlatNode first, + FlatMethod fm, + LocalityBinding lb, + FlatSESEExitNode stop, + PrintWriter output) { /* Assign labels to FlatNode's if necessary.*/ Hashtable nodetolabel=assignLabels(first); @@ -1534,10 +1537,12 @@ public class BuildCode { if (current_node==null) { current_node=(FlatNode)tovisit.iterator().next(); tovisit.remove(current_node); - } else if (tovisit.contains(current_node)){ - tovisit.remove(current_node); + } else if (tovisit.contains(current_node)) { + tovisit.remove(current_node); + } + if(current_node==stop) { + return; } - if(current_node==stop) { return; } visited.add(current_node); if (nodetolabel.containsKey(current_node)) output.println("L"+nodetolabel.get(current_node)+":"); @@ -1565,7 +1570,7 @@ public class BuildCode { nextnode=fsen.getFlatExit().getNext(0); } else { output.print(" "); - generateFlatNode(fm, lb, current_node, output); + generateFlatNode(fm, lb, current_node, output); nextnode=current_node.getNext(0); } if (visited.contains(nextnode)) { @@ -1726,7 +1731,7 @@ public class BuildCode { if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) { output.println("if (needtocollect) checkcollect2(&"+localsprefix+");"); } else - output.println("if (needtocollect) checkcollect(&"+localsprefix+");"); + output.println("if (needtocollect) checkcollect(&"+localsprefix+");"); } else output.println("/* nop */"); return; @@ -1929,11 +1934,11 @@ public class BuildCode { return; /* Have to generate flat globalconv */ if (fgcn.getMakePtr()) { - if (state.DSM) { - output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } else { - output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } + if (state.DSM) { + output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");"); + } else { + output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");"); + } } else { /* Need to convert to OID */ if (fgcn.doConvert()) { @@ -1951,7 +1956,7 @@ public class BuildCode { } else { type=fion.getType().getClassDesc().getId(); } - + if (fion.getType().getSymbol().equals(TypeUtil.ObjectClass)) output.println(generateTemp(fm, fion.getDst(), lb)+"=1;"); else @@ -1967,7 +1972,7 @@ public class BuildCode { TempDescriptor tmp=tmpit.next(); output.println(generateTemp(fm, backuptable.get(lb).get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); } - + output.println("goto transstart"+faen.getIdentifier()+";"); /******* Print code to retry aborted transaction *******/ @@ -1982,7 +1987,7 @@ public class BuildCode { if (state.DSM) { /********* Need to revert local object store ********/ String revertptr=generateTemp(fm, reverttable.get(lb),lb); - + output.println("while ("+revertptr+") {"); output.println("struct ___Object___ * tmpptr;"); output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); @@ -1994,7 +1999,7 @@ public class BuildCode { output.println("transstart"+faen.getIdentifier()+":"); output.println("transStart();"); - + if (state.ABORTREADERS) { output.println("if (_setjmp(aborttrans)) {"); output.println(" goto transretry"+faen.getIdentifier()+"; }"); @@ -2016,7 +2021,7 @@ public class BuildCode { output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); if (state.DSM) { output.println("} else {"); - /* Need to commit local object store */ + /* Need to commit local object store */ output.println("while ("+revertptr+") {"); output.println("struct ___Object___ * tmpptr;"); output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); @@ -2029,7 +2034,7 @@ public class BuildCode { public void generateSESE(FlatMethod fm, LocalityBinding lb, FlatSESEEnterNode faen, PrintWriter output) { - + } @@ -2219,8 +2224,8 @@ public class BuildCode { output.println(dst+"="+ src +"->"+field+ ";"); if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&& - ((dc==null)||dc.getNeedTrans(lb, ffn))&& - locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) { + ((dc==null)||dc.getNeedTrans(lb, ffn))&& + locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) { output.println("TRANSREAD("+dst+", "+dst+");"); } } else if (state.DSM) { @@ -2289,14 +2294,14 @@ public class BuildCode { if (srcptr&&!fsfn.getSrc().getType().isNull()) { output.println("{"); if ((dc==null)||dc.getNeedSrcTrans(lb, fsfn)&& - locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) { + locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) { output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); } else { output.println("INTPTR srcoid=(INTPTR)"+src+";"); } } if (wb.needBarrier(fsfn)&& - locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) { + locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) { output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;"); } if (srcptr&!fsfn.getSrc().getType().isNull()) { @@ -2390,8 +2395,8 @@ public class BuildCode { output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&& - ((dc==null)||dc.getNeedTrans(lb, fen))&& - locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) { + ((dc==null)||dc.getNeedTrans(lb, fen))&& + locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) { output.println("TRANSREAD("+dst+", "+dst+");"); } } else if (state.DSM) { @@ -2442,7 +2447,7 @@ public class BuildCode { if (state.SINGLETM && locality.getAtomic(lb).get(fsen).intValue()>0) { //Transaction set element case if (wb.needBarrier(fsen)&& - locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) { + locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) { output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___objstatus___))|=DIRTY;"); } if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) { diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index 2d92cbd2..ed87d172 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -1,10 +1,10 @@ /* ============================================================ - * singleTMCommit.c + * singleTMCommit.c * - single thread commit on local machine * ============================================================= * Copyright (c) 2009, University of California, Irvine, USA. * All rights reserved. - * Author: Alokika Dash + * Author: Alokika Dash * adash@uci.edu * ============================================================= * @@ -23,14 +23,14 @@ int numTransAbort = 0; int nSoftAbort = 0; int nSoftAbortCommit = 0; int nSoftAbortAbort = 0; -int typesCausingAbort[TOTALNUMCLASSANDARRAY]; #endif #ifdef STMSTATS +int typesCausingAbort[TOTALNUMCLASSANDARRAY]; /******Keep track of objects and types causing aborts******/ #define DEBUGSTMSTAT(args...) { \ - printf(args); \ - fflush(stdout); \ + printf(args); \ + fflush(stdout); \ } #else #define DEBUGSTMSTAT(args...) @@ -45,7 +45,7 @@ int typesCausingAbort[TOTALNUMCLASSANDARRAY]; /* ================================================== * stmStartup - * This function starts up the transaction runtime. + * This function starts up the transaction runtime. * ================================================== */ int stmStartup() { @@ -92,7 +92,7 @@ void objstrDelete(objstr_t *store) { /* ================================================= * transStart - * This function initializes things required in the + * This function initializes things required in the * transaction start * ================================================= */ @@ -102,7 +102,7 @@ void transStart() { /* ======================================================= * transCreateObj - * This function creates objects in the transaction record + * This function creates objects in the transaction record * ======================================================= */ objheader_t *transCreateObj(void * ptr, unsigned int size) { @@ -151,7 +151,7 @@ void *objstrAlloc(unsigned int size) { size+=(8-(size&7)); } - for(;i<2;i++) { + for(; i<2; i++) { if (OSFREE(store)>=size) { tmp=store->top; store->top +=size; @@ -162,7 +162,7 @@ void *objstrAlloc(unsigned int size) { } { - unsigned int newsize=size>DEFAULT_OBJ_STORE_SIZE?size:DEFAULT_OBJ_STORE_SIZE; + unsigned int newsize=size>DEFAULT_OBJ_STORE_SIZE ? size : DEFAULT_OBJ_STORE_SIZE; objstr_t **otmp=&t_reserve; objstr_t *ptr; while((ptr=*otmp)!=NULL) { @@ -175,7 +175,7 @@ void *objstrAlloc(unsigned int size) { return &ptr[1]; } } - + objstr_t *os=(objstr_t *)calloc(1,(sizeof(objstr_t) + newsize)); void *nptr=&os[1]; os->next=t_cache; @@ -199,7 +199,7 @@ __attribute__((pure)) void *transRead(void * oid) { /* Read from the main heap */ //No lock for now - objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t)); + objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t)); GETSIZE(size, header); size += sizeof(objheader_t); objcopy = (objheader_t *) objstrAlloc(size); @@ -228,7 +228,7 @@ void freenewobjs() { * transCommit * - This function initiates the transaction commit process * - goes through the transaction cache and decides - * - a final response + * - a final response * ================================================================ */ int transCommit() { @@ -271,7 +271,7 @@ int transCommit() { #endif softaborted++; if (softaborted>4) { - //retry if to many soft aborts + //retry if too many soft aborts freenewobjs(); objstrReset(); t_chashreset(); @@ -322,26 +322,27 @@ int traverseCache() { while(curr != NULL) { //if the first bin in hash table is empty if(curr->key == NULL) - break; + break; objheader_t * headeraddr=&((objheader_t *) curr->val)[-1]; - objheader_t *header=(objheader_t *) (((char *)curr->key)-sizeof(objheader_t)); + objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t)); unsigned int version = headeraddr->version; - + if(STATUS(headeraddr) & DIRTY) { /* Read from the main heap and compare versions */ if(write_trylock(&header->lock)) { //can aquire write lock - if (version == header->version) {/* versions match */ + if (version == header->version) { /* versions match */ /* Keep track of objects locked */ oidwrlocked[numoidwrlocked++] = OID(header); - } else { + } else { oidwrlocked[numoidwrlocked++] = OID(header); transAbortProcess(oidwrlocked, numoidwrlocked); #ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, size, (void *)(curr->next), NULL, 'w'); #endif DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -350,17 +351,18 @@ int traverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ -#ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; -#endif if(version == header->version) { /* versions match */ softabort=1; } else { transAbortProcess(oidwrlocked, numoidwrlocked); +#ifdef STMSTATS + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, size, (void *)(curr->next), NULL, 'w'); +#endif DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -379,20 +381,21 @@ int traverseCache() { //THIS IS THE SERIALIZATION POINT ***** - for(i=0;ilock>0) { //not write locked - if(version != header->version) {/* versions do not match */ + if(version != header->version) { /* versions do not match */ oidrdlocked[numoidrdlocked++] = OID(header); transAbortProcess(oidwrlocked, numoidwrlocked); #ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, numoidrdlocked, oidrdlocked, (void *) oidrdversion, 'r'); #endif DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -401,17 +404,18 @@ int traverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ -#ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; -#endif //do increment as we didn't get lock if(version == header->version) { softabort=1; } else { transAbortProcess(oidwrlocked, numoidwrlocked); +#ifdef STMSTATS + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, numoidrdlocked, oidrdlocked, (void *) oidrdversion, 'r'); +#endif DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -421,7 +425,7 @@ int traverseCache() { } } } - + /* Decide the final response */ if (softabort) { transAbortProcess(oidwrlocked, numoidwrlocked); @@ -477,24 +481,25 @@ int alttraverseCache() { while(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)); + objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t)); unsigned int version = headeraddr->version; - + if(STATUS(headeraddr) & DIRTY) { /* Read from the main heap and compare versions */ if(write_trylock(&header->lock)) { //can aquire write lock - if (version == header->version) {/* versions match */ + if (version == header->version) { /* versions match */ /* Keep track of objects locked */ oidwrlocked[numoidwrlocked++] = OID(header); - } else { + } else { oidwrlocked[numoidwrlocked++] = OID(header); transAbortProcess(oidwrlocked, numoidwrlocked); #ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(0, 1, (void *) curr->next, NULL, 'w'); #endif DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -509,11 +514,12 @@ int alttraverseCache() { } else { transAbortProcess(oidwrlocked, numoidwrlocked); #ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(0, 1, (void *) curr->next, NULL, 'w'); #endif DEBUGSTM("WR Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("WR Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -530,18 +536,19 @@ int alttraverseCache() { curr = curr->lnext; } //THIS IS THE SERIALIZATION POINT ***** - for(i=0;ilock>=0) { if(version != header->version) { transAbortProcess(oidwrlocked, numoidwrlocked); #ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, numoidrdlocked, oidrdlocked, (void *)oidrdversion, 'r'); #endif DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -550,16 +557,17 @@ int alttraverseCache() { return TRANS_ABORT; } } else { /* cannot aquire lock */ -#ifdef STMSTATS - header->abortCount++; - (typesCausingAbort[TYPE(header)])++; -#endif if(version == header->version) { softabort=1; } else { transAbortProcess(oidwrlocked, numoidwrlocked); +#ifdef STMSTATS + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + getTotalAbortCount(i+1, numoidrdlocked, oidrdlocked, (void *)oidrdversion, 'r'); +#endif DEBUGSTM("RD Abort: rd: %u wr: %u tot: %u type: %u ver: %u\n", numoidrdlocked, numoidwrlocked, c_numelements, TYPE(header), header->version); - DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); + DEBUGSTMSTAT("RD Abort: Access Count: %u AbortCount: %u type: %u ver: %u \n", header->accessCount, header->abortCount, TYPE(header), header->version); if (c_numelements>=200) { free(oidrdlocked); free(oidrdversion); @@ -569,7 +577,7 @@ int alttraverseCache() { } } } - + /* Decide the final response */ if (softabort) { transAbortProcess(oidwrlocked, numoidwrlocked); @@ -623,16 +631,16 @@ int transCommitProcess(void ** oidwrlocked, int numoidwrlocked) { struct objlist *ptr=newobjs; while(ptr!=NULL) { int max=ptr->offset; - for(i=0;iobjs[i])->___objstatus___=0; } ptr=ptr->next; } - + /* Copy from transaction cache -> main object store */ for (i = 0; i < numoidwrlocked; i++) { - /* Read from the main heap */ + /* Read from the main heap */ header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t)); int tmpsize; GETSIZE(tmpsize, header); @@ -643,12 +651,64 @@ int transCommitProcess(void ** oidwrlocked, int numoidwrlocked) { memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___)); header->version += 1; } - + /* Release write locks */ for(i=0; i< numoidwrlocked; i++) { - header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t)); + header = (objheader_t *)(((char *)(oidwrlocked[i])) - sizeof(objheader_t)); write_unlock(&header->lock); } return 0; } +/** ======================================================================================== + * getTotalAbortCount + * params : start: start index of the loop + * : stop: stop index of the loop + * : startptr: pointer that points to where to start looking in the array/ linked list + * 'r'/'w' if found when visiting objects read/ objects modified + * ========================================================================================= + **/ +#ifdef STMSTATS +void getTotalAbortCount(int start, int stop, void *startptr, void *checkptr, char type) { + printf("Inside %s()\n", __func__); + int i; + if(type == 'w') { + int isFirstTime = 0; + chashlistnode_t *curr = (chashlistnode_t *) startptr; + chashlistnode_t *ptr = c_table; + for(i = start; i < stop; i++) { + if(!isFirstTime) + curr = &ptr[i]; + /* Inner loop to traverse the linked list of the cache lookupTable */ + while(curr != NULL) { + if(curr->key == NULL) + break; + objheader_t * headeraddr=&((objheader_t *) curr->val)[-1]; + objheader_t *header=(objheader_t *)(((char *)curr->key)-sizeof(objheader_t)); + unsigned int version = headeraddr->version; + /* versions do not match */ + if(version != header->version) { + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + } + curr = curr->next; + } + isFirstTime = 1; + } + } else { + /* Go through oids read that are locked */ + for(i = start; i < stop; i++) { + objheader_t *header = ((void **)startptr)[i]; + unsigned int version = ((int *)checkptr)[i]; + if(version != header->version) { /* versions do not match */ + header->abortCount++; + (typesCausingAbort[TYPE(header)])++; + } + } + } +} +#else +void getTotalAbortCount(int start, int stop, void *startptr, void *checkptr, char type) { + return; +} +#endif diff --git a/Robust/src/Runtime/STM/stmlookup.c b/Robust/src/Runtime/STM/stmlookup.c index 024e39de..f770c779 100644 --- a/Robust/src/Runtime/STM/stmlookup.c +++ b/Robust/src/Runtime/STM/stmlookup.c @@ -16,7 +16,7 @@ void t_chashCreate(unsigned int size, double loadfactor) { int i; // Allocate space for the hash table - + c_table = calloc(size, sizeof(chashlistnode_t)); c_loadfactor = loadfactor; @@ -119,7 +119,7 @@ unsigned int t_chashResize(unsigned int newsize) { int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable unsigned int i,index; unsigned int mask; - + ptr = c_table; oldsize = c_size; c_list=NULL; @@ -140,7 +140,7 @@ unsigned int t_chashResize(unsigned int newsize) { do { //Inner loop to go through linked lists void * key; chashlistnode_t *tmp,*next; - + if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0 break; //key = val =0 for element if not present within the hash table } @@ -153,16 +153,16 @@ unsigned int t_chashResize(unsigned int newsize) { tmp->val = curr->val; tmp->lnext=c_list; c_list=tmp; - }/* - NOTE: Add this case if you change this... - This case currently never happens because of the way things rehash.... - else if (isfirst) { - chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t)); - newnode->key = curr->key; - newnode->val = curr->val; - newnode->next = tmp->next; - tmp->next=newnode; - } */ + } /* + NOTE: Add this case if you change this... + This case currently never happens because of the way things rehash.... + else if (isfirst) { + chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t)); + newnode->key = curr->key; + newnode->val = curr->val; + newnode->next = tmp->next; + tmp->next=newnode; + } */ else { curr->next=tmp->next; tmp->next=curr; diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 8579375e..1fe0380c 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -5,14 +5,9 @@ * Control Messages * ================== */ -#define TRANS_AGREE 10 -#define TRANS_DISAGREE 11 #define TRANS_SOFT_ABORT 12 #define TRANS_ABORT 13 #define TRANS_COMMIT 14 -#define READ_OBJ 15 -#define THREAD_NOTIFY 16 -#define THREAD_RESPONSE 17 /* ======================== @@ -25,13 +20,13 @@ #include #include #include -#include "threadnotify.h" +//#include "threadnotify.h" #include "stmlookup.h" #include "dsmlock.h" /* ================================== * Bit designation for status field - * of object header + * of object header * ================================== */ #define DIRTY 0x01 @@ -88,20 +83,20 @@ typedef struct objheader { #define OSUSED(x) (((unsigned INTPTR)(x)->top)-((unsigned INTPTR) (x+1))) #define OSFREE(x) ((x)->size-OSUSED(x)) #define TRANSREAD(x,y) { \ - void * inputvalue;\ -if ((inputvalue=y)==NULL) x=NULL;\ -else { \ -chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; \ -do { \ - if (cnodetmp->key==inputvalue) {x=cnodetmp->val;break;} \ -cnodetmp=cnodetmp->next;\ - if (cnodetmp==NULL) {if (((struct ___Object___*)inputvalue)->___objstatus___&NEW) {x=inputvalue;break;} else \ -{x=transRead(inputvalue); asm volatile("":"=m"(c_table),"=m"(c_mask));break;}} \ -} while(1);\ -}} + void * inputvalue; \ + if ((inputvalue=y)==NULL) x=NULL;\ + else { \ + chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; \ + do { \ + if (cnodetmp->key==inputvalue) {x=cnodetmp->val; break;} \ + cnodetmp=cnodetmp->next; \ + if (cnodetmp==NULL) {if (((struct ___Object___*)inputvalue)->___objstatus___&NEW) {x=inputvalue; break;} else \ + {x=transRead(inputvalue); asm volatile ("" : "=m" (c_table),"=m" (c_mask)); break;}} \ + } while(1); \ + }} /* ================================= - * Data structures + * Data structures * ================================= */ typedef struct objstr { @@ -122,18 +117,22 @@ extern __thread objstr_t *t_cache; extern __thread objstr_t *t_reserve; -#ifdef TRANSSTATS /*********************************** * Global Variables for statistics **********************************/ +#ifdef TRANSSTATS extern int numTransCommit; extern int numTransAbort; extern int nSoftAbort; extern int nSoftAbortAbort; extern int nSoftAbortCommit; +#endif + +#ifdef STMSTATS extern int typesCausingAbort[]; #endif + /* ================================ * Functions used * ================================ @@ -153,5 +152,6 @@ int alttraverseCache(); int transAbortProcess(void **, int); int transCommmitProcess(void **, int); void randomdelay(int); +void getTotalAbortCount(int, int, void *, void *, char); #endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index abbac360..af5a49b5 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -16,7 +16,7 @@ #include "tm.h" #include /* Global barrier for STM */ -pthread_barrier_t barrier; +pthread_barrier_t barrier; pthread_barrierattr_t attr; #endif #include @@ -113,11 +113,13 @@ void CALL11(___System______exit____I,int ___status___, int ___status___) { #ifdef STM printf("nSoftAbortCommit = %d\n", nSoftAbortCommit); printf("nSoftAbortAbort = %d\n", nSoftAbortAbort); +#ifdef STMSTATS int i; for(i=0; i