From: bdemsky Date: Thu, 26 Jul 2007 06:43:55 +0000 (+0000) Subject: Add beginning of support for dsm X-Git-Tag: preEdgeChange~512 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=e06f8a20f93f04ebd682d65a415f7c0f022aa4d2;hp=da446b8ec35c1423f6300ca9f2378ace88d7fcbb Add beginning of support for dsm --- diff --git a/Robust/src/Analysis/Locality/LocalityAnalysis.java b/Robust/src/Analysis/Locality/LocalityAnalysis.java index 8d74ae39..3f2bcb97 100644 --- a/Robust/src/Analysis/Locality/LocalityAnalysis.java +++ b/Robust/src/Analysis/Locality/LocalityAnalysis.java @@ -9,6 +9,7 @@ import java.util.Arrays; import Analysis.CallGraph.CallGraph; import IR.SymbolTable; import IR.State; +import IR.TypeUtil; import IR.MethodDescriptor; import IR.Flat.*; @@ -39,30 +40,32 @@ public class LocalityAnalysis { } private void computeLocalityBindings() { - LocalityBinding lb=new LocalityBinding(typeutil.getMain(), false); - tovisit.add(lb); - discovered.put(lb, lb); + LocalityBinding lbmain=new LocalityBinding(typeutil.getMain(), false); + tovisit.add(lbmain); + discovered.put(lbmain, lbmain); while(!tovisit.empty()) { LocalityBinding lb=(LocalityBinding) tovisit.pop(); MethodDescriptor md=lb.getMethod(); - computeCallsFlags(md, lb); + Hashtable> temptable=new Hashtable>(); + Hashtable atomictable=new Hashtable(); + computeCallsFlags(md, lb, temptable, atomictable); } } - public Hashtable> computeCallsFlags(MethodDescriptor md, LocalityBinding lb) { + public void computeCallsFlags(MethodDescriptor md, LocalityBinding lb, Hashtable> temptable, Hashtable atomictable) { FlatMethod fm=state.getMethodFlat(md); HashSet tovisit=new HashSet(); - Hashtable> temptable=new Hashtable>(); tovisit.add(fm.getNext(0)); { // Build table for initial node Hashtable table=new Hashtable(); temptable.put(fm, table); + atomictable.put(fm, lb.isAtomic()?1:0); for(int i=0;i currtable=new Hashtable(); + int atomicstate=0; for(int i=0;i prevtable=temptable.get(prevnode); @@ -83,49 +90,55 @@ public class LocalityAnalysis { currtable.put(temp, newint); } } + atomictable.put(fn, atomicstate); // Process this node switch(fn.kind()) { - case FlatCall: - processCall(md, (FlatCall)fn, currtable); + case FKind.FlatAtomicEnterNode: + processAtomicEnterNode((FlatAtomicEnterNode)fn, atomictable); + break; + case FKind.FlatAtomicExitNode: + processAtomicExitNode((FlatAtomicExitNode)fn, atomictable); + break; + case FKind.FlatCall: + processCall(lb, (FlatCall)fn, currtable, isAtomic(atomictable, fn)); break; - case FlatFieldNode: - processFieldNode((FlatFieldNode)fn, currtable); + case FKind.FlatFieldNode: + processFieldNode((FlatFieldNode)fn, isAtomic(atomictable, fn), currtable); break; - case FlatSetFieldNode: - processSetFieldNode((FlatSetFieldNode)fn, currtable); + case FKind.FlatSetFieldNode: + processSetFieldNode((FlatSetFieldNode)fn, isAtomic(atomictable,fn), currtable); break; - case FlatNew: - processNew((FlatNew)fn, currtable); + case FKind.FlatNew: + processNew((FlatNew)fn, isAtomic(atomictable, fn), currtable); break; - case FlatOpNode: + case FKind.FlatOpNode: processOpNode((FlatOpNode)fn, currtable); break; - case FlatCastNode: + case FKind.FlatCastNode: processCastNode((FlatCastNode)fn, currtable); break; - case FlatLiteralNode: + case FKind.FlatLiteralNode: processLiteralNode((FlatLiteralNode)fn, currtable); break; - case FlatReturnNode: - processReturnNode((FlatReturnNode)fn, currtable); + case FKind.FlatReturnNode: + processReturnNode(lb, (FlatReturnNode)fn, currtable); break; - case FlatSetElementNode: - processSetElement((FlatSetElementNode)fn, currtable); + case FKind.FlatSetElementNode: + processSetElementNode((FlatSetElementNode)fn, currtable, isAtomic(atomictable, fn)); break; - case FlatElementNode: - processElement((FlatElementNode)fn, currtable); + case FKind.FlatElementNode: + processElementNode((FlatElementNode)fn, currtable, isAtomic(atomictable, fn)); break; - - case FlatCondBranch: - case FlatBackEdge: - case FlatNop: + case FKind.FlatCondBranch: + case FKind.FlatBackEdge: + case FKind.FlatNop: //No action needed for these break; - case FlatFlagActionNode: - case FlatCheckNode: - case FlatTagDeclaration: + case FKind.FlatFlagActionNode: + case FKind.FlatCheckNode: + case FKind.FlatTagDeclaration: throw new Error("Incompatible with tasks!"); - case FlatMethod: + case FKind.FlatMethod: default: throw new Error(); } @@ -134,12 +147,16 @@ public class LocalityAnalysis { // Update table for this node temptable.put(fn, currtable); for(int i=0;i atomictable, FlatNode fn) { + return atomictable.get(fn).intValue()>0; + } + private static Integer merge(Integer a, Integer b) { if (a==null||a.equals(EITHER)) return b; @@ -150,14 +167,14 @@ public class LocalityAnalysis { return CONFLICT; } - void processCall(LocalityBinding currlb, FlatCall fc, boolean transaction, Hashtable currtable) { + void processCall(LocalityBinding currlb, FlatCall fc, Hashtable currtable, boolean isatomic) { MethodDescriptor nodemd=fc.getMethod(); Set methodset=fc.getThis()==null?callgraph.getMethods(nodemd): callgraph.getMethods(nodemd, fc.getThis().getType()); Integer currreturnval=null; for(Iterator methodit=methodset.iterator();methodit.hasNext();) { MethodDescriptor md=(MethodDescriptor) methodit.next(); - LocalityBinding lb=new LocalityBinding(md, transaction); + LocalityBinding lb=new LocalityBinding(md, isatomic); for(int i=0;i currtable) { + void processFieldNode(FlatFieldNode ffn, boolean transaction, Hashtable currtable) { Integer type=currtable.get(ffn.getSrc()); TempDescriptor dst=ffn.getDst(); if (type.equals(LOCAL)) { @@ -195,7 +212,7 @@ public class LocalityAnalysis { currtable.put(dst,LOCAL); } else if (type.equals(GLOBAL)) { if (!transaction) - throw Error("Global access outside of a transaction"); + throw new Error("Global access outside of a transaction"); if (ffn.getField().getType().isPrimitive()) currtable.put(dst, LOCAL); // primitives are local else @@ -211,12 +228,12 @@ public class LocalityAnalysis { } //need to handle primitives - void processSetFieldNode(LocalityBinding lb, FlatSetFieldNode fsfn, boolean transaction, Hashtable currtable) { - Integer srctype=currtable.get(ffn.getSrc()); - Integer dsttype=currtable.get(ffn.getDst()); + void processSetFieldNode(FlatSetFieldNode fsfn, boolean transaction, Hashtable currtable) { + Integer srctype=currtable.get(fsfn.getSrc()); + Integer dsttype=currtable.get(fsfn.getDst()); if (dsttype.equals(LOCAL)) { - if (ffn.getField().isGlobal()) { + if (fsfn.getField().isGlobal()) { if (!(srctype.equals(GLOBAL)||srctype.equals(EITHER))) throw new Error("Writing possible local reference to global field"); } else { @@ -225,7 +242,7 @@ public class LocalityAnalysis { } } else if (dsttype.equals(GLOBAL)) { if (!transaction) - throw Error("Global access outside of a transaction"); + throw new Error("Global access outside of a transaction"); //okay to store primitives in global object if (srctype.equals(LOCAL) && fsfn.getField().getType().isPrimitive()) return; @@ -239,7 +256,7 @@ public class LocalityAnalysis { } } - void processNew(LocalityBinding lb, FlatNew fn, boolean transaction, Hashtable currtable) { + void processNew(FlatNew fn, boolean transaction, Hashtable currtable) { if (fn.isGlobal()&&!transaction) { throw new Error("Allocating global object outside of transaction"); } @@ -255,7 +272,7 @@ public class LocalityAnalysis { } void processCastNode(FlatCastNode fcn, Hashtable currtable) { - currtable.put(fon.getDest(), currtable.get(fon.getSrc())); + currtable.put(fcn.getDst(), currtable.get(fcn.getSrc())); } void processLiteralNode(FlatLiteralNode fln, Hashtable currtable) { @@ -273,7 +290,7 @@ public class LocalityAnalysis { } } - void processSetElementNode(FlatSetElementNode fsen, Hashtable currtable) { + void processSetElementNode(FlatSetElementNode fsen, Hashtable currtable, boolean isatomic) { Integer srctype=currtable.get(fsen.getSrc()); Integer dsttype=currtable.get(fsen.getDst()); @@ -283,8 +300,8 @@ public class LocalityAnalysis { } else if (dsttype.equals(GLOBAL)) { if (!(srctype.equals(GLOBAL)||srctype.equals(EITHER))) throw new Error("Writing possible local reference to global object"); - if (!transaction) - throw Error("Global access outside of a transaction"); + if (!isatomic) + throw new Error("Global access outside of a transaction"); } else if (dsttype.equals(EITHER)) { if (srctype.equals(CONFLICT)) throw new Error("Using reference that could be local or global"); @@ -293,14 +310,14 @@ public class LocalityAnalysis { } } - void processElementNode(FlatElementNode fen, Hashtable currtable) { + void processElementNode(FlatElementNode fen, Hashtable currtable, boolean isatomic) { Integer type=currtable.get(fen.getSrc()); TempDescriptor dst=fen.getDst(); if (type.equals(LOCAL)) { currtable.put(dst,LOCAL); } else if (type.equals(GLOBAL)) { - if (!transaction) - throw Error("Global access outside of a transaction"); + if (!isatomic) + throw new Error("Global access outside of a transaction"); currtable.put(dst, GLOBAL); } else if (type.equals(EITHER)) { currtable.put(dst, EITHER); @@ -308,4 +325,13 @@ public class LocalityAnalysis { throw new Error("Access to object that could be either global or local"); } } + void processAtomicEnterNode(FlatAtomicEnterNode fen, Hashtable atomictable) { + int atomic=atomictable.get(fen).intValue(); + atomictable.put(fen, new Integer(atomic+1)); + } + + void processAtomicExitNode(FlatAtomicExitNode fen, Hashtable atomictable) { + int atomic=atomictable.get(fen).intValue(); + atomictable.put(fen, new Integer(atomic-1)); + } } diff --git a/Robust/src/Analysis/Locality/LocalityBinding.java b/Robust/src/Analysis/Locality/LocalityBinding.java index 5df96d9e..b89a46b1 100644 --- a/Robust/src/Analysis/Locality/LocalityBinding.java +++ b/Robust/src/Analysis/Locality/LocalityBinding.java @@ -4,23 +4,27 @@ import IR.MethodDescriptor; public class LocalityBinding { private MethodDescriptor md; private Integer[] isglobal; - private boolean istransaction; + private boolean isatomic; private Integer isglobalreturn; private Integer isglobalthis; - public LocalityBinding(MethodDescriptor md, boolean transaction) { + public LocalityBinding(MethodDescriptor md, boolean atomic) { this.md=md; - isglobal=new boolean[md.numParameters()]; - istransaction=transaction; + isglobal=new Integer[md.numParameters()]; + isatomic=atomic; } public String toString() { String st=md.toString()+" "; for(int i=0;i1) { - NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0); + NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); fn.addNext(np.getBegin()); return new NodePair(first,np.getEnd()); } else @@ -252,7 +262,7 @@ public class BuildFlat { } } - private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i) { + private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i, boolean isglobal) { TempDescriptor index=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT)); TempDescriptor tmpone=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT)); FlatNop fnop=new FlatNop();//last node @@ -268,7 +278,7 @@ public class BuildFlat { FlatCondBranch fcb=new FlatCondBranch(tmpbool); //is index