throw new Error("Incompatible with tasks!");
case FKind.FlatMethod:
+
+ case FKind.FlatOffsetNode:
+ //System.out.println("In FKind.FlatOffsetNode\n");
+ processOffsetNode((FlatOffsetNode)fn, currtable);
+ break;
+
default:
throw new Error();
}
for(int i=0; i<fc.numArgs(); i++) {
TempDescriptor arg=fc.getArg(i);
if(isnative&&(currtable.get(arg).equals(GLOBAL)||
- currtable.get(arg).equals(CONFLICT)))
+ currtable.get(arg).equals(CONFLICT))&& !(nodemd.getSymbol().equals("rangePrefetch"))) {
throw new Error("Potential call to native method "+md+" with global parameter:\n"+currlb.getExplanation());
+ }
lb.setGlobal(i,currtable.get(arg));
}
}
currtable.put(fon.getDest(), srcvalue);
}
+ void processOffsetNode(FlatOffsetNode fon, Hashtable<TempDescriptor, Integer> currtable) {
+ /* Just propagate value */
+ currtable.put(fon.getDst(), LOCAL);
+ }
+
void processCastNode(FlatCastNode fcn, Hashtable<TempDescriptor, Integer> currtable) {
currtable.put(fcn.getDst(), currtable.get(fcn.getSrc()));
}
processFlatSetFieldNode(curr, child_prefetch_set_copy);
break;
+ case FKind.FlatOffsetNode:
+ processDefaultCase(curr,child_prefetch_set_copy);
+ break;
+
default:
throw new Error("No such Flatnode kind");
}
public String toString() {
return String.valueOf(value);
}
-
+
public int hashCode() {
- return value;
+ return value;
}
public boolean equals(Object o) {
- if (o.getType()!=getType())
- return false;
- Integer s=(Integer)o;
- if (s.intValue()!=this.value)
- return false;
- return true;
+ if (o.getType()!=getType())
+ return false;
+ Integer s=(Integer)o;
+ if (s.intValue()!=this.value)
+ return false;
+ return true;
}
}
}
public static String valueOf(double x) {
- return valueOf((long)x);
+ return valueOf((long)x);
}
public static String valueOf(long x) {
public static native void printI(int status);
public static native void clearPrefetchCache();
+
+ public static native void rangePrefetch(Object o, short numoffset, short[] offsets); //TODO Complete this definition
+
}
import IR.Tree.DNFFlag;
import IR.Tree.DNFFlagAtom;
import IR.Tree.TagExpressionList;
+import IR.Tree.OffsetNode;
import IR.*;
import java.util.*;
import java.io.*;
import Analysis.Locality.LocalityBinding;
import Analysis.Prefetch.*;
+
public class BuildCode {
State state;
Hashtable temptovar;
TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task);
if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
+ //System.out.println("generateTemp returns " + td.getSafeSymbol());
return td.getSafeSymbol();
}
case FKind.FlatPrefetchNode:
generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
return;
+
+ case FKind.FlatOffsetNode:
+ generateFlatOffsetNode(fm, lb, (FlatOffsetNode)fn, output);
+ return;
}
throw new Error();
}
+ public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) {
+ output.println("/* FlatOffsetNode */");
+ ClassDescriptor cn = fofn.getClassDesc();
+ FieldDescriptor fd = fofn.getField();
+ System.out.println("ClassDescriptor cn =" + cn.toString() + " FieldDescriptor fd =" + fd.toString());
+ System.out.println("TempDescriptor td =" + fofn.getDst().toString() + "Type of TempDescriptor =" + fofn.getDst().getType());
+ output.println("((struct "+cn.getSafeSymbol() +" *)0)->"+ fd.getSafeSymbol()+";");
+ }
+
public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
if (state.PREFETCH) {
Vector oids = new Vector();
}
private void generateFlatLiteralNode(FlatMethod fm, LocalityBinding lb, FlatLiteralNode fln, PrintWriter output) {
+ if (fln.getType().isOffset()) {
+ if (fln.getValue() instanceof OffsetNode) {
+ OffsetNode ofn = (OffsetNode) fln.getValue();
+ output.println(generateTemp(fm, fln.getDst(),lb)+
+ " = (short) (&((struct "+ofn.getClassDesc().getSafeSymbol() +" *)0)->"+
+ ofn.getField().getSafeSymbol()+");");
+ }
+ output.println("/* offset */");
+ return;
+ }
if (fln.getValue()==null)
output.println(generateTemp(fm, fln.getDst(),lb)+"=0;");
else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) {
}
private NodePair flattenBlockExpressionNode(BlockExpressionNode en) {
+ //System.out.println("DEBUG -> inside flattenBlockExpressionNode\n");
TempDescriptor tmp=TempDescriptor.tempFactory("neverused",en.getExpression().getType());
return flattenExpressionNode(en.getExpression(),tmp);
}
return new NodePair(fln,fln);
}
+ private NodePair flattenOffsetNode(OffsetNode ofn, TempDescriptor out_temp) {
+ FlatLiteralNode fln = new FlatLiteralNode(ofn.getType(), ofn, out_temp);
+ return new NodePair(fln, fln);
+ /* Another possible approach
+ ClassDescriptor cd = ofn.getClassDesc();
+ FieldDescriptor fd = ofn.getField();
+ FlatOffsetNode fon = new FlatOffsetNode(fd, cd, out_temp);
+ TypeDescriptor type=new TypeDescriptor(ofn.getType());
+ System.out.println("TempDescriptor out_temp = " + out_temp.toString() + "Type of out_temp = " + out_temp.getType());
+ return new NodePair(fon, fon);
+ */
+ }
+
private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) {
TypeDescriptor td=con.getType();
if (!td.isArray()) {
}
FlatNode first=null;
FlatNode last=null;
- TempDescriptor src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
-
+ TempDescriptor src_tmp = src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
+
//Get src value
if (an.getSrc()!=null) {
NodePair np_src=flattenExpressionNode(an.getSrc(),src_tmp);
} else if (an.getDest().kind()==Kind.NameNode) {
//We could be assigning a field or variable
NameNode nn=(NameNode)an.getDest();
+
+
if (nn.getExpression()!=null) {
//It is a field
FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
}
FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
+
last.addNext(fon);
last=fon;
if (pre) {
fon.addNext(fon2);
last=fon2;
}
- return new NodePair(first, last);
- }
+ return new NodePair(first, last);
+ } //end of else
}
}
+
throw new Error();
}
case Kind.OpNode:
return flattenOpNode((OpNode)en,out_temp);
+
+ case Kind.OffsetNode:
+ return flattenOffsetNode((OffsetNode)en,out_temp);
}
throw new Error();
}
public static final int FlatAtomicExitNode=19;
public static final int FlatGlobalConvNode=20;
public static final int FlatPrefetchNode=21;
+ public static final int FlatOffsetNode=22;
}
public class BuildIR {
State state;
-
+
private int m_taskexitnum;
-
+
public BuildIR(State state) {
this.state=state;
this.m_taskexitnum = 0;
}
-
+
public void buildtree() {
for(Iterator it=state.parsetrees.iterator(); it.hasNext();) {
ParseNode pn=(ParseNode)it.next();
private TypeDescriptor parseTypeDescriptor(ParseNode pn) {
ParseNode tn=pn.getChild("type");
-
String type_st=tn.getTerminal();
if(type_st.equals("byte")) {
return state.getTypeDescriptor(TypeDescriptor.BYTE);
}
return min;
} else if (isNode(pn,"fieldaccess")) {
- ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild()); String fieldname=pn.getChild("field").getTerminal();
+ ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
+ String fieldname=pn.getChild("field").getTerminal();
return new FieldAccessNode(en,fieldname);
} else if (isNode(pn,"arrayaccess")) {
ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
return new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
} else if (isNode(pn,"cast2")) {
return new CastNode(parseExpression(pn.getChild("type").getFirstChild()),parseExpression(pn.getChild("exp").getFirstChild()));
+ } else if (isNode(pn, "getoffset")) {
+ TypeDescriptor td=parseTypeDescriptor(pn);
+ String fieldname = pn.getChild("field").getTerminal();
+ //System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ " fieldname= " + fieldname);
+ return new OffsetNode(td, fieldname);
} else {
System.out.println("---------------------");
System.out.println(pn.PPrint(3,true));
}
public BlockNode parseBlock(ParseNode pn) {
- this.m_taskexitnum = 0;
+ this.m_taskexitnum = 0;
if (pn==null||isEmpty(pn.getTerminal()))
return new BlockNode();
ParseNode bsn=pn.getChild("block_statement_list");
public final static int TaskExitNode=19;
public final static int TagDeclarationNode=20;
public final static int AtomicNode=21;
+ public final static int OffsetNode=22;
}
case Kind.OpNode:
checkOpNode(md,nametable,(OpNode)en,td);
return;
+
+ case Kind.OffsetNode:
+ checkOffsetNode(md, nametable, (OffsetNode)en, new TypeDescriptor(TypeDescriptor.OFFSET));
+ return;
}
throw new Error();
}
}
}
+ void checkOffsetNode(Descriptor md, SymbolTable nameTable, OffsetNode ofn, TypeDescriptor td) {
+ TypeDescriptor ltd = ofn.td;
+ //System.out.println("Testing TypeDescriptor ltd = " + ofn.td);
+ String fieldname = ofn.fieldname;
+ //System.out.println("Testing String fieldname = " + ofn.fieldname);
+ Descriptor d = (Descriptor) nameTable.get(fieldname);
+ //System.out.println("Testing Descriptor d = " + d.toString());
+
+ ClassDescriptor cd = null;
+ checkTypeDescriptor(ltd);
+ cd = ltd.getClassDesc();
+ ofn.setClassDesc(cd);
+ //System.out.println("Testing for ClassDescriptor cd = " + cd.toString());
+
+ FieldDescriptor fd=null;
+ if (ltd.isArray()&&fieldname.equals("length")) {
+ fd=FieldDescriptor.arrayLength;
+ } else {
+ fd=(FieldDescriptor) cd.getFieldTable().get(fieldname);
+ }
+ //System.out.println("Testing for FieldDescriptor fd = " + fd.toString());
+ ofn.setField(fd);
+ if (fd==null)
+ throw new Error("Unknown field "+fieldname + " in "+ofn.printNode(1)+" in "+md);
+ ofn.setType(td);
+ }
+
void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
boolean postinc=true;
if (an.getOperation().getBaseOp()==null||
Vector vfe;
Vector ccs;
int m_taskexitindex;
-
+
public TaskExitNode(Vector vfe, Vector ccs, int taskexitindex) {
this.vfe=vfe;
this.ccs=ccs;
}
public int getTaskExitIndex() {
- return m_taskexitindex;
+ return m_taskexitindex;
}
}
public static final int NULL=10;
public static final int TAG=11;
public static final int CLASS=12;
+ public static final int OFFSET=13;
int arraycount;
- int type;
+ private int type;
ClassDescriptor class_desc;
public boolean equals(Object o) {
return "double";
else if (isFloat())
return "float";
+ else if (isOffset())
+ return "short";
else throw new Error("Error Type: "+type);
}
return type==VOID;
}
+ public boolean isOffset() {
+ return type==OFFSET;
+ }
+
public boolean isPtr() {
return (isClass()||isNull()||isTag()||isArray());
}
return "null";
else if (type==TAG)
return TypeUtil.TagClass;
+ else if (type==OFFSET)
+ return "offset";
else throw new Error();
}
}
}
public boolean isSuperorType(TypeDescriptor possiblesuper, TypeDescriptor cd2) {
+ if (possiblesuper.isOffset() || cd2.isOffset()) return true;
//Matching type are always okay
if (possiblesuper.equals(cd2))
return true;
//Keywords for transactions
key_table.put("atomic", new Integer(Sym.ATOMIC));
key_table.put("global", new Integer(Sym.GLOBAL));
+ //Keywords for hacking prefetch calls in java
+ key_table.put("getoffset", new Integer(Sym.GETOFFSET));
}
}
"class", "const", "continue", "default", "do", "double", "else", "enum",
"extends", "external", "final", "finally",
"flag", //keyword for failure aware computation
- "float", "for", "global", "goto", "if",
+ "float", "for","getoffset", "global", "goto", "if",
"implements", "import", "instanceof", "int", "interface", "isavailable",
"long",
"native", "new", "optional", "package", "private", "protected", "public",
} else if (option.equals("-printflat"))
State.PRINTFLAT=true;
else if (option.equals("-printscheduling"))
- State.PRINTSCHEDULING=true;
+ State.PRINTSCHEDULING=true;
else if (option.equals("-printschedulesim"))
- State.PRINTSCHEDULESIM=true;
+ State.PRINTSCHEDULESIM=true;
else if (option.equals("-struct"))
state.structfile=args[++i];
else if (option.equals("-conscheck"))
System.out.println("-ownwritedots <all/final> -- write ownership graphs; can be all results or just final results");
System.out.println("-ownaliasfile <filename> -- write a text file showing all detected aliases in program tasks");
System.out.println("-optional -- enable optional arguments");
- System.out.println("-scheduling do task scheduling" );
+ System.out.println("-scheduling do task scheduling");
System.out.println("-multicore generate multi-core version binary");
System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1");
System.out.println("-raw generate raw version binary (should be used together with -multicore)");
tmpinindex = inint.indexOf(';');
int byObj = Integer.parseInt(inint.substring(0, tmpinindex));
if(byObj != -1) {
- tinfo.m_byObj = byObj;
+ tinfo.m_byObj = byObj;
}
inint = inint.substring(tmpinindex + 1);
while(inint.startsWith(" ")) {
- inint = inint.substring(1);
+ inint = inint.substring(1);
}
for(int i = 0; i < numofexits; i++) {
- String tmpinfo = null;
- if(i < numofexits - 1) {
- tmpinindex = inint.indexOf(';');
- tmpinfo = inint.substring(0, tmpinindex);
- inint = inint.substring(tmpinindex + 1);
- while(inint.startsWith(" ")) {
- inint = inint.substring(1);
- }
- } else {
- tmpinfo = inint;
+ String tmpinfo = null;
+ if(i < numofexits - 1) {
+ tmpinindex = inint.indexOf(';');
+ tmpinfo = inint.substring(0, tmpinindex);
+ inint = inint.substring(tmpinindex + 1);
+ while(inint.startsWith(" ")) {
+ inint = inint.substring(1);
}
-
- tmpinindex = tmpinfo.indexOf(',');
- tinfo.m_exetime[i] = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
- tmpinfo = tmpinfo.substring(tmpinindex + 1);
- while(tmpinfo.startsWith(" ")) {
- tmpinfo = tmpinfo.substring(1);
+ } else {
+ tmpinfo = inint;
+ }
+
+ tmpinindex = tmpinfo.indexOf(',');
+ tinfo.m_exetime[i] = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
+ tmpinfo = tmpinfo.substring(tmpinindex + 1);
+ while(tmpinfo.startsWith(" ")) {
+ tmpinfo = tmpinfo.substring(1);
+ }
+ tmpinindex = tmpinfo.indexOf(',');
+ tinfo.m_probability[i] = Double.parseDouble(tmpinfo.substring(0, tmpinindex));
+ tmpinfo = tmpinfo.substring(tmpinindex + 1);
+ while(tmpinfo.startsWith(" ")) {
+ tmpinfo = tmpinfo.substring(1);
+ }
+ tmpinindex = tmpinfo.indexOf(',');
+ int numofnobjs = 0;
+ if(tmpinindex == -1) {
+ numofnobjs = Integer.parseInt(tmpinfo);
+ if(numofnobjs != 0) {
+ System.err.println("Error profile data format!");
+ System.exit(-1);
}
- tmpinindex = tmpinfo.indexOf(',');
- tinfo.m_probability[i] = Double.parseDouble(tmpinfo.substring(0, tmpinindex));
+ } else {
+ tinfo.m_newobjinfo.setElementAt(new Hashtable<String,Integer>(), i);
+ numofnobjs = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
tmpinfo = tmpinfo.substring(tmpinindex + 1);
while(tmpinfo.startsWith(" ")) {
- tmpinfo = tmpinfo.substring(1);
+ tmpinfo = tmpinfo.substring(1);
}
- tmpinindex = tmpinfo.indexOf(',');
- int numofnobjs = 0;
- if(tmpinindex == -1) {
- numofnobjs = Integer.parseInt(tmpinfo);
- if(numofnobjs != 0) {
- System.err.println("Error profile data format!");
- System.exit(-1);
- }
- } else {
- tinfo.m_newobjinfo.setElementAt(new Hashtable<String,Integer>(), i);
- numofnobjs = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
+ for(int j = 0; j < numofnobjs; j++) {
+ tmpinindex = tmpinfo.indexOf(',');
+ String nobjtype = tmpinfo.substring(0, tmpinindex);
+ tmpinfo = tmpinfo.substring(tmpinindex + 1);
+ while(tmpinfo.startsWith(" ")) {
+ tmpinfo = tmpinfo.substring(1);
+ }
+ int objnum = 0;
+ if(j < numofnobjs - 1) {
+ tmpinindex = tmpinfo.indexOf(',');
+ objnum = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
tmpinfo = tmpinfo.substring(tmpinindex + 1);
while(tmpinfo.startsWith(" ")) {
- tmpinfo = tmpinfo.substring(1);
- }
- for(int j = 0; j < numofnobjs; j++) {
- tmpinindex = tmpinfo.indexOf(',');
- String nobjtype = tmpinfo.substring(0, tmpinindex);
- tmpinfo = tmpinfo.substring(tmpinindex + 1);
- while(tmpinfo.startsWith(" ")) {
- tmpinfo = tmpinfo.substring(1);
- }
- int objnum = 0;
- if(j < numofnobjs - 1) {
- tmpinindex = tmpinfo.indexOf(',');
- objnum = Integer.parseInt(tmpinfo.substring(0, tmpinindex));
- tmpinfo = tmpinfo.substring(tmpinindex + 1);
- while(tmpinfo.startsWith(" ")) {
- tmpinfo = tmpinfo.substring(1);
- }
- } else {
- objnum = Integer.parseInt(tmpinfo);
- }
- tinfo.m_newobjinfo.elementAt(i).put(nobjtype, objnum);
+ tmpinfo = tmpinfo.substring(1);
}
+ } else {
+ objnum = Integer.parseInt(tmpinfo);
+ }
+ tinfo.m_newobjinfo.elementAt(i).put(nobjtype, objnum);
}
+ }
}
taskinfos.put(inname, tinfo);
inindex = profiledata.indexOf('\n');
pfe.setProbability(idouble);
int newRate = 0;
if((taskinfo.m_newobjinfo.elementAt(pfe.getTaskExitIndex()) != null)
- && (taskinfo.m_newobjinfo.elementAt(pfe.getTaskExitIndex()).containsKey(cd.getSymbol()))) {
- newRate = taskinfo.m_newobjinfo.elementAt(pfe.getTaskExitIndex()).get(cd.getSymbol());
+ && (taskinfo.m_newobjinfo.elementAt(pfe.getTaskExitIndex()).containsKey(cd.getSymbol()))) {
+ newRate = taskinfo.m_newobjinfo.elementAt(pfe.getTaskExitIndex()).get(cd.getSymbol());
}
pfe.addNewObjInfo(cd, newRate, idouble);
if(taskinfo.m_byObj != -1) {
- ((FlagState)pfe.getSource()).setByObj(taskinfo.m_byObj);
+ ((FlagState)pfe.getSource()).setByObj(taskinfo.m_byObj);
}
}
fev = null;
double idouble = taskinfo.m_probability[edge.getTaskExitIndex()];
edge.setProbability(idouble);
if(taskinfo.m_byObj != -1) {
- ((FlagState)edge.getSource()).setByObj(taskinfo.m_byObj);
+ ((FlagState)edge.getSource()).setByObj(taskinfo.m_byObj);
}
}
}
Vector<Integer> selectedScheduling = new Vector<Integer>();
int processTime = Integer.MAX_VALUE;
if(schedulings.size() > 1500) {
- int index = 0;
- int upperbound = schedulings.size();
- long seed = 0;
- java.util.Random r = new java.util.Random(seed);
- for(int ii = 0; ii < 1500; ii++) {
- index = (int)((Math.abs((double)r.nextInt() / (double)Integer.MAX_VALUE)) * upperbound);
- System.out.println("Scheduling index:" + index);
- //System.err.println("Scheduling index:" + index);
- Vector<Schedule> scheduling = schedulings.elementAt(index);
- scheduleSimulator.setScheduling(scheduling);
- int tmpTime = scheduleSimulator.process();
- if(tmpTime < processTime) {
- selectedScheduling.clear();
- selectedScheduling.add(index);
- processTime = tmpTime;
- } else if(tmpTime == processTime) {
- selectedScheduling.add(index);
- }
- scheduling = null;
+ int index = 0;
+ int upperbound = schedulings.size();
+ long seed = 0;
+ java.util.Random r = new java.util.Random(seed);
+ for(int ii = 0; ii < 1500; ii++) {
+ index = (int)((Math.abs((double)r.nextInt() / (double)Integer.MAX_VALUE)) * upperbound);
+ System.out.println("Scheduling index:" + index);
+ //System.err.println("Scheduling index:" + index);
+ Vector<Schedule> scheduling = schedulings.elementAt(index);
+ scheduleSimulator.setScheduling(scheduling);
+ int tmpTime = scheduleSimulator.process();
+ if(tmpTime < processTime) {
+ selectedScheduling.clear();
+ selectedScheduling.add(index);
+ processTime = tmpTime;
+ } else if(tmpTime == processTime) {
+ selectedScheduling.add(index);
}
+ scheduling = null;
+ }
} else {
- Iterator it_scheduling = scheduleAnalysis.getSchedulingsIter();
- int index = 0;
- while(it_scheduling.hasNext()) {
- Vector<Schedule> scheduling = (Vector<Schedule>)it_scheduling.next();
- scheduleSimulator.setScheduling(scheduling);
- int tmpTime = scheduleSimulator.process();
- if(tmpTime < processTime) {
- selectedScheduling.clear();
- selectedScheduling.add(index);
- processTime = tmpTime;
- } else if(tmpTime == processTime) {
- selectedScheduling.add(index);
- }
- scheduling = null;
- index++;
+ Iterator it_scheduling = scheduleAnalysis.getSchedulingsIter();
+ int index = 0;
+ while(it_scheduling.hasNext()) {
+ Vector<Schedule> scheduling = (Vector<Schedule>)it_scheduling.next();
+ scheduleSimulator.setScheduling(scheduling);
+ int tmpTime = scheduleSimulator.process();
+ if(tmpTime < processTime) {
+ selectedScheduling.clear();
+ selectedScheduling.add(index);
+ processTime = tmpTime;
+ } else if(tmpTime == processTime) {
+ selectedScheduling.add(index);
}
+ scheduling = null;
+ index++;
+ }
}
System.out.print("Selected schedulings with least exectution time " + processTime + ": \n\t");
System.exit(l.numErrors());
}
}
-
+
static class TaskInfo {
- public int m_numofexits;
- public int[] m_exetime;
- public double[] m_probability;
- public Vector<Hashtable<String, Integer>> m_newobjinfo;
- public int m_byObj;
-
- public TaskInfo(int numofexits) {
- this.m_numofexits = numofexits;
- this.m_exetime = new int[this.m_numofexits];
- this.m_probability = new double[this.m_numofexits];
- this.m_newobjinfo = new Vector<Hashtable<String, Integer>>();
- for(int i = 0; i < this.m_numofexits; i++) {
- this.m_newobjinfo.add(null);
- }
- this.m_byObj = -1;
+ public int m_numofexits;
+ public int[] m_exetime;
+ public double[] m_probability;
+ public Vector<Hashtable<String, Integer>> m_newobjinfo;
+ public int m_byObj;
+
+ public TaskInfo(int numofexits) {
+ this.m_numofexits = numofexits;
+ this.m_exetime = new int[this.m_numofexits];
+ this.m_probability = new double[this.m_numofexits];
+ this.m_newobjinfo = new Vector<Hashtable<String, Integer>>();
+ for(int i = 0; i < this.m_numofexits; i++) {
+ this.m_newobjinfo.add(null);
}
+ this.m_byObj = -1;
+ }
}
}
//distributed transaction keywords
terminal ATOMIC;
terminal GLOBAL;
+terminal GETOFFSET;
non terminal ParseNode atomic_statement;
+non terminal ParseNode getoffset_expression;
start with goal;
| BOOLEAN_LITERAL:boolean_lit
{:
ParseNode pn=new ParseNode("literal");
- pn.addChild("boolean").setLiteral(boolean_lit);
+ pn.addChild("boole\1aan").setLiteral(boolean_lit);
RESULT=pn;
:}
| CHARACTER_LITERAL:char_lit
// RESULT=pn;
// :}
;
+
postfix_expression ::=
primary:exp {:
RESULT=exp; :}
// | conditional_or_expression QUESTION expression
// COLON conditional_expression
;
+getoffset_expression ::=
+ GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
+ ParseNode pn = new ParseNode("getoffset");
+ pn.addChild(type);
+ pn.addChild("field").addChild(id);
+ RESULT = pn;
+ :}
+ ;
+
assignment_expression ::=
conditional_expression:expr {:
RESULT=expr; :} |
assignment:assign {:
- RESULT=assign; :}
+ RESULT=assign; :} |
+ getoffset_expression:expr {:
+ RESULT=expr; :}
;
// semantic check necessary here to ensure a valid left-hand side.
// allowing a parenthesized variable here on the lhs was introduced in
Q: How can we represent offset, or index or typechecking .....in bytes i.e. short type number?
TODO : handle the NULL cases here
-
+Start range of prefetches
+--------------------------
+For e.g. Prefetches for array indices
+a[0].b, a[1].b, a[2].b = a . 0. 2. b .0
+
+For e.g. Prefetches for next field
+a.b.next.next.next = a.b.0.next.3
+
+Current : just do a Java system call to insert these prefetches manually
extern sockPoolHashTable_t *transPrefetchSockPool;
extern unsigned int myIpAddr;
-/* Steps for the new prefetch call */
// Function for new prefetch call
-void rangePrefetch(int prefetchsiteid, int ntuples, unsigned int *baseoids,
- unsigned short *numoffsets, short *offsets) {
+void rangePrefetch(unsigned int oid, short numoffset, short *offsets) {
// a[0][1] - a[3][1] = a.0.3
// a.f.h = a.f.h
// a.f.next.h = a.f.0.next.0.h
// a.f.next.next.h = a.f.next.2.h
+ printf("DEBUG-> Inside rangePrefetch\n");
/* Allocate memory in prefetch queue and push the block there */
- int qnodesize = 2*sizeof(int)+ ntuples *(sizeof(unsigned int) + sizeof(unsigned short)) + numoffsets[ntuples -1] * sizeof(short);
+ int qnodesize = sizeof(unsigned int) + sizeof(unsigned short) + numoffset * sizeof(short);
char *node = (char *) getmemory(qnodesize);
- int top = numoffsets[ntuples -1];
if(node == NULL)
return;
int index = 0;
- *((int *)(node)) = prefetchsiteid;
- *((int *)(node + sizeof(int))) = ntuples;
- index = 2 * sizeof(int);
- memcpy(node+index, baseoids, ntuples * sizeof(unsigned int));
- index = index + ntuples *(sizeof(unsigned int));
- memcpy(node+index, numoffsets, ntuples * sizeof(unsigned short));
- index = index + ntuples *(sizeof(unsigned short));
- memcpy(node+index, offsets, top * sizeof(short));
+ *(node+index) = oid;
+ index = index + (sizeof(unsigned int));
+ *(node+index) = numoffset;
+ index = index + (sizeof(short));
+ memcpy(node+index, offsets, numoffset * sizeof(short));
movehead(qnodesize);
}
/* Send Prefetch Request */
perMcPrefetchList_t *ptr = pilehead;
while(ptr != NULL) {
- sendRangePrefetchReq(ptr, sd);
- ptr = ptr->next;
+ sendRangePrefetchReq(ptr, sd);
+ ptr = ptr->next;
}
/* Deallocated pilehead */
// Iterate for each object
for (i = 0; i < ntuples; i++) {
int numoffset = (i == 0) ? endoffsets[0] : (endoffsets[i] - endoffsets[i-1]);
- int sizetmpObjSet = numoffset >> 1;
+ int sizetmpObjSet = numoffset >> 1;
unsigned short tmpobjset[sizetmpObjSet];
int l;
for (l = 0; l < sizetmpObjSet; l++) {
for (j = 0; j < numoffset; j++) {
// Iterate over each element to be visited
while (visited != tovisit) {
- if(chldOffstFrmBase[visited+1] == 0) {
- visited++;
- continue;
- }
-
- if (!isOidAvail(chldOffstFrmBase[visited+1])) {
- // Add to remote requests
- unsigned int oid = chldOffstFrmBase[visited+1];
- int machinenum = lhashSearch(oid);
- //TODO Group a bunch of oids to send in one prefetch request
- insertPrefetch(machinenum, oid, numoffset-j, offsets, &head);
- break;
- } else {
- // iterate over each offset
- int retval;
- if((retval = lookForObjs(chldOffstFrmBase, offsets, &j,
- &visited, &tovisit)) == 0) {
- printf("%s() Error: Object not found %s at line %d\n",
- __func__, __FILE__, __LINE__);
- }
- }
- visited++;
- }
+ if(chldOffstFrmBase[visited+1] == 0) {
+ visited++;
+ continue;
+ }
+
+ if (!isOidAvail(chldOffstFrmBase[visited+1])) {
+ // Add to remote requests
+ unsigned int oid = chldOffstFrmBase[visited+1];
+ int machinenum = lhashSearch(oid);
+ //TODO Group a bunch of oids to send in one prefetch request
+ insertPrefetch(machinenum, oid, numoffset-j, offsets, &head);
+ break;
+ } else {
+ // iterate over each offset
+ int retval;
+ if((retval = lookForObjs(chldOffstFrmBase, offsets, &j,
+ &visited, &tovisit)) == 0) {
+ printf("%s() Error: Object not found %s at line %d\n",
+ __func__, __FILE__, __LINE__);
+ }
+ }
+ visited++;
+ }
} // end iterate for each element of offsets
//Entire prefetch found locally
}
}
-int lookForObjs(int *chldOffstFrmBase, short *offsets,
- int *index, int *visited, int *tovisit) {
+int lookForObjs(int *chldOffstFrmBase, short *offsets,
+ int *index, int *visited, int *tovisit) {
objheader_t *header;
unsigned int oid = chldOffstFrmBase[*visited+1];
if((header = (objheader_t *)mhashSearch(oid))!= NULL) {
int i;
//check is stride +ve or negative
if(GET_STRIDEINC(offsets[(*index)]+1)) { //-ve stride
- for(i = startindex; i <= range+1; i = i - stride) {
- unsigned int oid = 0;
- if((i < 0 || i >= length)) {
- //if yes treat the object as found
- oid = 0;
- continue;
- } else {
- // compute new object
- oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*i)));
- }
- // add new object
- chldOffstFrmBase[*tovisit] = oid;
- *tovisit = *tovisit + 1;
- }
+ for(i = startindex; i <= range+1; i = i - stride) {
+ unsigned int oid = 0;
+ if((i < 0 || i >= length)) {
+ //if yes treat the object as found
+ oid = 0;
+ continue;
+ } else {
+ // compute new object
+ oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*i)));
+ }
+ // add new object
+ chldOffstFrmBase[*tovisit] = oid;
+ *tovisit = *tovisit + 1;
+ }
} else { //+ve stride
- for(i = startindex; i <= range; i = i + stride) {
- unsigned int oid = 0;
- if(i < 0 || i >= length) {
- //if yes treat the object as found
- oid = 0;
- continue;
- } else {
- // compute new object
- oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*i)));
- }
- // add new object
- chldOffstFrmBase[*tovisit] = oid;
- *tovisit = *tovisit + 1;
- }
+ for(i = startindex; i <= range; i = i + stride) {
+ unsigned int oid = 0;
+ if(i < 0 || i >= length) {
+ //if yes treat the object as found
+ oid = 0;
+ continue;
+ } else {
+ // compute new object
+ oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*i)));
+ }
+ // add new object
+ chldOffstFrmBase[*tovisit] = oid;
+ *tovisit = *tovisit + 1;
+ }
}
} else if(range == 0) {
if(startindex >=0 || startindex < length) {
- unsigned int oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*startindex)));
- // add new object
- chldOffstFrmBase[*tovisit] = oid;
- *tovisit = *tovisit + 1;
+ unsigned int oid = *((unsigned int *)(((char *)ao) + sizeof(struct ArrayObject) + (elementsize*startindex)));
+ // add new object
+ chldOffstFrmBase[*tovisit] = oid;
+ *tovisit = *tovisit + 1;
}
}
} else { //linked list
} else {
int i;
for(i = 0; i < range; i++) {
- oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + startindex));
- // add new object
- chldOffstFrmBase[*tovisit] = oid;
- *tovisit = *tovisit + 1;
+ oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + startindex));
+ // add new object
+ chldOffstFrmBase[*tovisit] = oid;
+ *tovisit = *tovisit + 1;
}
}
}
tmp->next = *head;
*head=tmp;
return;
- }
+ }
//keep looking
if (tmid < mid)
int matchstatus;
if ((*tmp)==NULL||((toid=(*tmp)->oid)>oid)) {
- objnode = (objOffsetPile_t *) malloc(sizeof(objOffsetPile_t));
- objnode->offsets = offsets;
- objnode->oid = oid;
- objnode->numoffset = numoffset;
- objnode->next = *tmp;
- *tmp = objnode;
- return;
- }
+ objnode = (objOffsetPile_t *) malloc(sizeof(objOffsetPile_t));
+ objnode->offsets = offsets;
+ objnode->oid = oid;
+ objnode->numoffset = numoffset;
+ objnode->next = *tmp;
+ *tmp = objnode;
+ return;
+ }
if (toid < oid)
- continue;
+ continue;
/* Fill list DS */
int i;
short * ooffset=(*tmp)->offsets;
for(i=0; i<numoffset; i++) {
- if (i>onumoffset) {
- //We've matched, let's just extend the current prefetch
- (*tmp)->numoffset=numoffset;
- (*tmp)->offsets=offsets;
- return;
- }
- if (ooffset[i]<offsets[i]) {
- goto oidloop;
- } else if (ooffset[i]>offsets[i]) {
- //Place item before the current one
- objnode = (objOffsetPile_t *) malloc(sizeof(objOffsetPile_t));
- objnode->offsets = offsets;
- objnode->oid = oid;
- objnode->numoffset = numoffset;
- objnode->next = *tmp;
- *tmp = objnode;
- return;
- }
+ if (i>onumoffset) {
+ //We've matched, let's just extend the current prefetch
+ (*tmp)->numoffset=numoffset;
+ (*tmp)->offsets=offsets;
+ return;
+ }
+ if (ooffset[i]<offsets[i]) {
+ goto oidloop;
+ } else if (ooffset[i]>offsets[i]) {
+ //Place item before the current one
+ objnode = (objOffsetPile_t *) malloc(sizeof(objOffsetPile_t));
+ objnode->offsets = offsets;
+ objnode->oid = oid;
+ objnode->numoffset = numoffset;
+ objnode->next = *tmp;
+ *tmp = objnode;
+ return;
+ }
}
//if we get to the end, we're already covered by this prefetch
return;
+#ifndef _PREFETCH_H_
+#define _PREFETCH_H_
#include "queue.h"
#include "dstm.h"
void proPrefetchQDealloc(perMcPrefetchList_t *);
/******** Process Queue Element functions ***********/
-void rangePrefetch(int, int, unsigned int *, unsigned short *, short *offset);
+//void rangePrefetch(int, int, unsigned int *, unsigned short *, short *offset);
+void rangePrefetch(unsigned int, short, short *);
void *transPrefetchNew();
perMcPrefetchList_t* checkIfLocal(char *ptr);
int isOidAvail(unsigned int oid);
int lookForObjs(int*, short *, int *, int *, int *);
-void insertPrefetch(int, unsigned int, short, short*, perMcPrefetchList_t **);
+void insertPrefetch(int, unsigned int, short, short*, perMcPrefetchList_t **);
void sendRangePrefetchReq(perMcPrefetchList_t *, int sd);
/************* Internal functions *******************/
int getsize(short *ptr, int n);
+
+#endif
#ifdef DSTM
#include "dstm.h"
#include "prelookup.h"
+#include "prefetch.h"
#endif
extern int classsize[];
void CALL00(___System______clearPrefetchCache____) {
prehashClear();
}
+
+void CALL12(___System______rangePrefetch____L___Object____S__AR_S, struct ___Object___ * ___o___, short ___numoffset___, struct ArrayObject * ___offsets___) {
+ /* Manual Prefetches to be inserted */
+ unsigned int oid;
+ oid = ((int *) VAR(___o___))[0];
+ int numoffset=VAR(___offsets___)->___length___;
+ int i;
+ short offArry[numoffset];
+ for(i = 0; i<numoffset; i++) {
+ offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + i * sizeof(short)));
+ //printf("Testing-> offArry[%d] = %d\n", i, offArry[i]);
+ }
+ rangePrefetch(oid, (short)numoffset, offArry);
+}
#endif
/* Object allocation function */
then
EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
fi
-FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c $DSMRUNTIME/dsmlock.c"
+FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c $DSMRUNTIME/dsmlock.c $DSMRUNTIME/prefetch.c"
fi
if $RECOVERFLAG