From: adash Date: Thu, 20 Mar 2008 22:07:52 +0000 (+0000) Subject: a)Fix prefetch analysis bugs X-Git-Tag: preEdgeChange~223 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=00557b7ce3fcb91fcc6956550cd773ed9d85d853;p=IRC.git a)Fix prefetch analysis bugs b)Enable only one socket connection per remote machine for sending prefetch requests --- diff --git a/Robust/src/Analysis/Prefetch/IndexDescriptor.java b/Robust/src/Analysis/Prefetch/IndexDescriptor.java index 78d3c316..0f53e32b 100644 --- a/Robust/src/Analysis/Prefetch/IndexDescriptor.java +++ b/Robust/src/Analysis/Prefetch/IndexDescriptor.java @@ -53,7 +53,7 @@ public class IndexDescriptor extends Descriptor { } public TempDescriptor getTempDescAt(int index) { - return (TempDescriptor) tddesc.get(index); + return ((TempDescriptor) (tddesc.get(index))); } public int getOffset() { diff --git a/Robust/src/Analysis/Prefetch/PairMap.java b/Robust/src/Analysis/Prefetch/PairMap.java index a350cb8d..e896b995 100644 --- a/Robust/src/Analysis/Prefetch/PairMap.java +++ b/Robust/src/Analysis/Prefetch/PairMap.java @@ -42,14 +42,24 @@ public class PairMap { return hashcode; } - public String pairMapToString() { + public int size() { + return mappair.size(); + } + + public boolean contains(PrefetchPair ppKey) { + if(mappair.containsKey(ppKey)) + return true; + return false; + } + + public String toString() { String label = null; Set mapping = mappair.entrySet(); Iterator it = mapping.iterator(); label = "Mappings are: "; for(;it.hasNext();) { Object o = it.next(); - label += o.toString() + " "; + label += o.toString() + " , "; } return label; } diff --git a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java index 97017bcc..3e808081 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java +++ b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java @@ -18,23 +18,19 @@ public class PrefetchAnalysis { CallGraph callgraph; TypeUtil typeutil; Set tovisit; - public Hashtable> prefetch_hash; - public Hashtable> pmap_hash; - Hashtable branch_prefetch_set; - LinkedList newvisited; - Hashtable> pset1_hash; - Hashtable> newprefetchset; - public static final int PROB_DIFF = 10; - public static final float ANALYSIS_THRESHOLD_PROB = (float)0.10; - public static final float PREFETCH_THRESHOLD_PROB = (float)0.30; - public static final float BRANCH_TRUE_EDGE_PROB = (float)0.5; - public static final float BRANCH_FALSE_EDGE_PROB = (float)0.5; - + public Hashtable> prefetch_hash;//holds all flatnodes and corresponding prefetch set + public Hashtable> pmap_hash;//holds all flatnodes and mappings between child prefetch pair and parent prefetch pair + public static final double PROB_DIFF = 0.05; //threshold for difference in probabilities during first phase of analysis + public static final double ANALYSIS_THRESHOLD_PROB = 0.10; //threshold for prefetches to stop propagating during first phase of analysis + public static final double PREFETCH_THRESHOLD_PROB = 0.30;//threshold for prefetches to stop propagating while applying prefetch rules during second phase of analysis + public static final double BRANCH_TRUE_EDGE_PROB = 0.5; + public static final double BRANCH_FALSE_EDGE_PROB = 0.5; + public PrefetchAnalysis(State state, CallGraph callgraph, TypeUtil typeutil) { this.typeutil=typeutil; this.state=state; this.callgraph=callgraph; - prefetch_hash = new Hashtable>(); + prefetch_hash = new Hashtable>(); pmap_hash = new Hashtable>(); DoPrefetch(); prefetch_hash = null; @@ -108,33 +104,29 @@ public class PrefetchAnalysis { private void doMethodAnalysis(ClassDescriptor cn) { Iterator methodit=cn.getMethods(); while(methodit.hasNext()) { - newprefetchset = new Hashtable>(); - pset1_hash = new Hashtable>(); + Hashtable> newprefetchset = new Hashtable>(); MethodDescriptor md=(MethodDescriptor)methodit.next(); FlatMethod fm=state.getMethodFlat(md); doFlatNodeAnalysis(fm); - doInsPrefetchAnalysis(fm); + doInsPrefetchAnalysis(fm, newprefetchset); if(newprefetchset.size() > 0) { addFlatPrefetchNode(newprefetchset); } newprefetchset = null; - pset1_hash = null; } } /** This function calls analysis for every node in a method */ private void doFlatNodeAnalysis(FlatMethod fm) { tovisit = fm.getNodeSet(); - Hashtable nodehash = new Hashtable(); + Hashtable nodehash = new Hashtable(); /* Create Empty Prefetch Sets for all flat nodes in the global hashtable */ while(!tovisit.isEmpty()) { FlatNode fn = (FlatNode)tovisit.iterator().next(); prefetch_hash.put(fn, nodehash); tovisit.remove(fn); } - nodehash = null; - /* Visit and process nodes */ tovisit = fm.getNodeSet(); while(!tovisit.isEmpty()) { @@ -151,13 +143,13 @@ public class PrefetchAnalysis { * returns false : otherwise */ private void doChildNodeAnalysis(FlatNode curr) { - Hashtable child_prefetch_set_copy = new Hashtable(); + Hashtable child_prefetch_set_copy = new Hashtable(); Hashtable parentpmap = new Hashtable(); FlatNode child_node = null; if(curr.numNext() != 0) { child_node = curr.getNext(0); if(prefetch_hash.containsKey(child_node)) { - child_prefetch_set_copy = (Hashtable) prefetch_hash.get(child_node).clone(); + child_prefetch_set_copy = (Hashtable) prefetch_hash.get(child_node).clone(); } } @@ -190,17 +182,15 @@ public class PrefetchAnalysis { processFlatElementNode(curr, child_prefetch_set_copy, parentpmap); break; case FKind.FlatCondBranch: - branch_prefetch_set = new Hashtable(); + Hashtable branch_prefetch_set = new Hashtable(); for (int i = 0; i < curr.numNext(); i++) { - parentpmap = new Hashtable(); + Hashtable branchparentpmap = new Hashtable(); child_node = curr.getNext(i); if (prefetch_hash.containsKey(child_node)) { - child_prefetch_set_copy = (Hashtable) prefetch_hash.get(child_node).clone(); + child_prefetch_set_copy = (Hashtable) prefetch_hash.get(child_node).clone(); } - processFlatCondBranch(curr, child_prefetch_set_copy, i, branch_prefetch_set, parentpmap); - parentpmap = null; + processFlatCondBranch(curr, child_prefetch_set_copy, i, branch_prefetch_set, branchparentpmap); } - branch_prefetch_set = null; break; case FKind.FlatOpNode: processFlatOpNode(curr, child_prefetch_set_copy, parentpmap); @@ -236,20 +226,15 @@ public class PrefetchAnalysis { processFlatTagDeclaration(curr, child_prefetch_set_copy, parentpmap); break; default: - System.out.println("NO SUCH FLATNODE"); - break; + throw new Error("No such Flatnode kind"); } - - /* Free Heap Memory */ - child_prefetch_set_copy = null; - parentpmap = null; } /**This function compares all the prefetch pairs in a Prefetch set hashtable and * returns: true if something has changed in the new Prefetch set else * returns: false */ - private boolean comparePrefetchSets(Hashtable oldPrefetchSet, Hashtable + private boolean comparePrefetchSets(Hashtable oldPrefetchSet, Hashtable newPrefetchSet) { boolean hasChanged = false; PrefetchPair oldpp = null; @@ -264,14 +249,13 @@ public class PrefetchAnalysis { Enumeration e = newPrefetchSet.keys(); while(e.hasMoreElements()) { newpp = (PrefetchPair) e.nextElement(); - float newprob = newPrefetchSet.get(newpp); + double newprob = newPrefetchSet.get(newpp).doubleValue(); for(Enumeration elem = oldPrefetchSet.keys(); elem.hasMoreElements();) { oldpp = (PrefetchPair) elem.nextElement(); if(oldpp.equals(newpp)) { /*Compare the difference in their probabilities */ - float oldprob = oldPrefetchSet.get(oldpp); - int diff = (int) ((newprob - oldprob)/oldprob)*100; - if(diff >= PROB_DIFF) { + double oldprob = oldPrefetchSet.get(oldpp).doubleValue(); + if(((newprob - oldprob) > PROB_DIFF) || (newprob >= PREFETCH_THRESHOLD_PROB && oldprob < PREFETCH_THRESHOLD_PROB)) { return true; } break; @@ -288,11 +272,11 @@ public class PrefetchAnalysis { * If old prefetch set is not same as new prefetch set then enqueue the parents * of the current FlatFieldNode * */ - private void processFlatFieldNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatFieldNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable currcopy = new Hashtable(); - Hashtable tocompare = new Hashtable(); + Hashtable currcopy = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatFieldNode currffn = (FlatFieldNode) curr; PairMap pm = new PairMap(); @@ -301,7 +285,7 @@ public class PrefetchAnalysis { TempDescriptor currffn_src = currffn.getSrc(); if (currffn_field.getType().isPtr()) { PrefetchPair pp = new PrefetchPair(currffn_src, (Descriptor) currffn_field); - Float prob = new Float((float)1.0); + Double prob = new Double(1.0); currcopy.put(pp, prob); } @@ -317,13 +301,13 @@ public class PrefetchAnalysis { newdesc.add(currffn.getField()); newdesc.addAll(childpp.desc); PrefetchPair newpp = new PrefetchPair(currffn.getSrc(), newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -335,6 +319,8 @@ public class PrefetchAnalysis { } } else if(childpp.base == currffn.getDst() && (childpp.getDesc() == null)) { child_prefetch_set_copy.remove(childpp); + } else if(isTempDescFound(childpp, currffn.getDst())) { + child_prefetch_set_copy.remove(childpp); } else { continue; } @@ -348,8 +334,6 @@ public class PrefetchAnalysis { for(e = currcopy.keys(); e.hasMoreElements();) { currpp = (PrefetchPair) e.nextElement(); if(currpp.equals(childpp)) { - Float prob = currcopy.get(currpp).floatValue(); - currcopy.put(currpp, prob); pm.addPair(childpp, currpp); child_prefetch_set_copy.remove(childpp); break; @@ -361,7 +345,7 @@ public class PrefetchAnalysis { ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -370,7 +354,7 @@ public class PrefetchAnalysis { e = currcopy.keys(); while(e.hasMoreElements()) { currpp = (PrefetchPair) e.nextElement(); - tocompare.put(currpp, currcopy.get(currpp)); + tocompare.put(currpp, currcopy.get(currpp).doubleValue()); currcopy.remove(currpp); } @@ -378,7 +362,18 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -390,11 +385,6 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - - /* Free Heap Memory */ - currcopy = null; - tocompare = null; - pm = null; } /** This function processes the prefetch set of a FlatElementNode @@ -402,12 +392,12 @@ public class PrefetchAnalysis { * It compares the old prefetch set with this new prefetch set and enqueues the parents * of the current node if change occurs and updates the global flatnode hash table * */ - private void processFlatElementNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatElementNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable currcopy = new Hashtable(); - Hashtable tocompare = new Hashtable(); + Hashtable currcopy = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatElementNode currfen = (FlatElementNode) curr; PairMap pm = new PairMap(); @@ -418,29 +408,28 @@ public class PrefetchAnalysis { TempDescriptor currfen_src = currfen.getSrc(); if(currfen.getDst().getType().isPtr()) { PrefetchPair pp = new PrefetchPair(currfen_src, (Descriptor) idesc); - Float prob = new Float((float)1.0); + Double prob = new Double(1.0); currcopy.put(pp, prob); } /* Get each prefetch pair of the child and match it with the destination temp descriptor of curr FlatFieldNode */ Enumeration ecld = child_prefetch_set_copy.keys(); PrefetchPair currpp = null; - PrefetchPair childpp = null; while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if (childpp.base == currfen.getDst() && (childpp.getDesc()!= null)) { if (currfen.getDst().getType().isPtr()) { ArrayList newdesc = new ArrayList(); newdesc.add((Descriptor)idesc); newdesc.addAll(childpp.desc); PrefetchPair newpp = new PrefetchPair(currfen.getSrc(), newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -452,6 +441,10 @@ public class PrefetchAnalysis { } } else if(childpp.base == currfen.getDst() && (childpp.getDesc() == null)) { child_prefetch_set_copy.remove(childpp); + } else if(isTempDescFound(childpp, currfen.getDst())) { + child_prefetch_set_copy.remove(childpp); + } else { + continue; } } /* Check if curr prefetch set and the child prefetch set have same prefetch pairs @@ -459,12 +452,10 @@ public class PrefetchAnalysis { ecld = child_prefetch_set_copy.keys(); Enumeration e = null; while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); for(e = currcopy.keys(); e.hasMoreElements();) { currpp = (PrefetchPair) e.nextElement(); if(currpp.equals(childpp)) { - Float prob = currcopy.get(currpp).floatValue(); - currcopy.put(currpp, prob); pm.addPair(childpp, currpp); child_prefetch_set_copy.remove(childpp); break; @@ -475,8 +466,8 @@ public class PrefetchAnalysis { /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -485,7 +476,7 @@ public class PrefetchAnalysis { e = currcopy.keys(); while(e.hasMoreElements()) { currpp = (PrefetchPair) e.nextElement(); - tocompare.put(currpp, currcopy.get(currpp)); + tocompare.put(currpp, currcopy.get(currpp).doubleValue()); currcopy.remove(currpp); } @@ -493,7 +484,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -505,11 +506,6 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - - /* Free heap memory */ - currcopy = null; - tocompare = null; - pm = null; } /** This function processes the prefetch set of a FlatSetFieldNode @@ -517,17 +513,16 @@ public class PrefetchAnalysis { * It compares the old prefetch set with this new prefetch set and enqueues the parents * of the current node if change occurs and then updates the global flatnode hash table * */ - private void processFlatSetFieldNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatSetFieldNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatSetFieldNode currfsfn = (FlatSetFieldNode) curr; - PrefetchPair childpp = null; PairMap pm = new PairMap(); Enumeration ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if(childpp.base == currfsfn.getDst()) { int size = childpp.desc.size(); if(size >=2) { /*e.g. x.f = g (with child prefetches x.f.g, x.f[0].j) */ @@ -537,14 +532,14 @@ public class PrefetchAnalysis { newdesc.add(i,childpp.desc.get(i+1)); } PrefetchPair newpp = new PrefetchPair(currfsfn.getSrc(), newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs in newly generated prefetch pair * to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -567,8 +562,8 @@ public class PrefetchAnalysis { /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -577,7 +572,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -589,10 +594,6 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function processes the prefetch set of a FlatSetElementNode @@ -600,17 +601,16 @@ public class PrefetchAnalysis { * It compares the old prefetch set with this new prefetch set and enqueues the parents * of the current node if change occurs and then updates the global flatnode hash table * */ - private void processFlatSetElementNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatSetElementNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); - PrefetchPair childpp = null; + Hashtable tocompare = new Hashtable(); FlatSetElementNode currfsen = (FlatSetElementNode) curr; PairMap pm = new PairMap(); Enumeration ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if (childpp.base == currfsen.getDst()){ int sizedesc = childpp.desc.size(); if((childpp.getDescAt(0) instanceof IndexDescriptor)) { @@ -623,13 +623,13 @@ public class PrefetchAnalysis { newdesc.add(i,childpp.desc.get(i+1)); } PrefetchPair newpp = new PrefetchPair(currfsen.getSrc(), newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -650,8 +650,8 @@ public class PrefetchAnalysis { /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -660,7 +660,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -672,28 +682,24 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function applies rules and does analysis for a FlatOpNode * And updates the global prefetch hashtable * */ - private void processFlatOpNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatOpNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; int index; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatOpNode currfopn = (FlatOpNode) curr; Enumeration ecld = null; - PrefetchPair childpp = null; PairMap pm = new PairMap(); - if(currfopn.getOp().getOp()== Operation.ASSIGN) { + if(currfopn.getOp().getOp() == Operation.ASSIGN) { ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); PrefetchPair copyofchildpp = (PrefetchPair) childpp.clone(); /* For cases like x=y with child prefetch set x[i].z,x.g*/ @@ -701,13 +707,13 @@ public class PrefetchAnalysis { ArrayList newdesc = new ArrayList(); newdesc.addAll(childpp.desc); PrefetchPair newpp = new PrefetchPair(currfopn.getLeft(), newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -716,20 +722,18 @@ public class PrefetchAnalysis { } child_prefetch_set_copy.remove(newpp); } - newdesc = null; - newpp = null; - /* For cases like x=y with child prefetch set r[i].x, r[x].p, r[p+x].q*/ + /* For cases like x=y with child prefetch set r[x].p, r[p+x].q where x is a tempdescriptor*/ } else if(isTempDescFound(copyofchildpp, currfopn.getDest())) { ArrayList newdesc = new ArrayList(); newdesc.addAll((ArrayList)getNewDesc(copyofchildpp, currfopn.getDest(), currfopn.getLeft())); PrefetchPair newpp = new PrefetchPair(childpp.base, newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability*/ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -740,7 +744,7 @@ public class PrefetchAnalysis { } newdesc = null; newpp = null; - }else { + } else { continue; } } @@ -748,20 +752,20 @@ public class PrefetchAnalysis { } else if(currfopn.getRight()!=null && (currfopn.getOp().getOp() == Operation.ADD)) { ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); PrefetchPair copyofchildpp = (PrefetchPair) childpp.clone(); if(isTempDescFound(copyofchildpp, currfopn.getDest())) { ArrayList newdesc = new ArrayList(); newdesc.addAll((ArrayList)getNewDesc(copyofchildpp, currfopn.getDest(), currfopn.getLeft(), currfopn.getRight())); PrefetchPair newpp = new PrefetchPair(childpp.base, newdesc); - Float newprob = child_prefetch_set_copy.get(childpp).floatValue(); + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability*/ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -770,7 +774,7 @@ public class PrefetchAnalysis { } child_prefetch_set_copy.remove(newpp); } - }else { + } else { continue; } } @@ -781,8 +785,8 @@ public class PrefetchAnalysis { /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -791,7 +795,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -803,33 +817,28 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function processes a FlatLiteralNode where cases such as * for e.g. i = 0 with child prefetch sets a[i].r, a[j+i].r or a[j].b[i].r * are handled */ - private void processFlatLiteralNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatLiteralNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatLiteralNode currfln = (FlatLiteralNode) curr; Enumeration ecld = null; - PrefetchPair childpp = null; PairMap pm = new PairMap(); if(currfln.getType().isIntegerType()) { ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); PrefetchPair copyofchildpp = (PrefetchPair) childpp.clone(); if(isTempDescFound(copyofchildpp,currfln.getDst())) { ArrayList copychilddesc = (ArrayList) copyofchildpp.getDesc(); int sizetempdesc = copychilddesc.size(); - ListIterator it = copychilddesc.listIterator(); - for(;it.hasNext();) { + for(ListIterator it = copychilddesc.listIterator();it.hasNext();) { Object o = it.next(); if(o instanceof IndexDescriptor) { ArrayList td = (ArrayList)((IndexDescriptor)o).tddesc; @@ -844,13 +853,13 @@ public class PrefetchAnalysis { ArrayList newdesc = new ArrayList(); newdesc.addAll(copychilddesc); PrefetchPair newpp = new PrefetchPair(childpp.base, newdesc); - Float newprob = (child_prefetch_set_copy.get(childpp)).floatValue(); + Double newprob = (child_prefetch_set_copy.get(childpp)).doubleValue(); tocompare.put(newpp, newprob); pm.addPair(childpp, newpp); child_prefetch_set_copy.remove(childpp); /* Check for independence of prefetch pairs to compute new probability */ if(child_prefetch_set_copy.containsKey(newpp)) { - newprob = (float)(1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).floatValue()) * (1.0 - tocompare.get(newpp).floatValue()))); + newprob = (1.0 - ((1.0 - child_prefetch_set_copy.get(newpp).doubleValue()) * (1.0 - tocompare.get(newpp).doubleValue()))); if(newprob < ANALYSIS_THRESHOLD_PROB) { tocompare.remove(newpp); } else { @@ -866,8 +875,8 @@ public class PrefetchAnalysis { /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -876,7 +885,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -888,27 +907,23 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function processes a FlatMethod where the method propagates * the entire prefetch set of its child node */ - private void processFlatMethod(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatMethod(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatMethod currfm = (FlatMethod) curr; Enumeration ecld = null; - PrefetchPair childpp = null; PairMap pm = new PairMap(); /* Merge child prefetch pairs */ ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -917,7 +932,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -926,29 +951,26 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - tocompare = null; - pm = null; } /** This Function processes the FlatCalls * It currently drops the propagation of those prefetchpairs whose base is * same as the destination of the FlatCall */ - private void processFlatCall(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatCall(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatCall currfcn = (FlatCall) curr; PairMap pm = new PairMap(); Enumeration ecld = null; - PrefetchPair childpp = null; ecld = child_prefetch_set_copy.keys(); while(ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); PrefetchPair copyofchildpp = (PrefetchPair) childpp.clone(); if(currfcn.getReturnTemp() != childpp.base) { - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } else { @@ -960,7 +982,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the orginal prefetch pairs */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -972,46 +1004,35 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function handles the processes the FlatNode of type FlatCondBranch * It combines prefetches of both child elements and create a new hash table called * branch_prefetch_set to contains the entries of both its children */ - private void processFlatCondBranch(FlatNode curr, Hashtable child_prefetch_set_copy, int index, - Hashtable branch_prefetch_set, Hashtable parentpmap) { - boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable();//temporary hash table + private void processFlatCondBranch(FlatNode curr, Hashtable child_prefetch_set_copy, int index, + Hashtable branch_prefetch_set, Hashtable parentpmap) { + Hashtable tocompare = new Hashtable();//temporary hash table FlatCondBranch currfcb = (FlatCondBranch) curr; - Float newprob = new Float((float)0.0); PairMap pm = new PairMap(); - PrefetchPair childpp = null; - PrefetchPair pp = null; Enumeration ecld = null; ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); /* True Edge */ if(index == 0) { - newprob = child_prefetch_set_copy.get(childpp).floatValue() * BRANCH_TRUE_EDGE_PROB; - if(newprob >= ANALYSIS_THRESHOLD_PROB) { - tocompare.put(childpp, newprob); - pm.addPair(childpp, childpp); - } + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue() * currfcb.getTrueProb(); + tocompare.put(childpp, newprob); + pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } else if(index == 1) { /* False Edge */ - newprob = child_prefetch_set_copy.get(childpp).floatValue() * BRANCH_FALSE_EDGE_PROB; - if(newprob >= ANALYSIS_THRESHOLD_PROB) { - tocompare.put(childpp, newprob); - pm.addPair(childpp, childpp); - } + Double newprob = child_prefetch_set_copy.get(childpp).doubleValue() * currfcb.getFalseProb(); + tocompare.put(childpp, newprob); + pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } else { - System.out.println("DEBUG-> No more children of the FlatCondBranchNode present"); + throw new Error("processFlatCondBranch() has only two child edges"); } } @@ -1019,45 +1040,70 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(index), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(index)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(index), pairmapping); + } else { + pmap_hash.put(curr.getNext(index), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(index), parentpmap); + } /* Update branch_prefetch_set (global hash table) to combine all prefetch pairs from childnodes of the * cond branch that is currently stored in the tocompare hash table */ if(!tocompare.isEmpty()) { - if(index == 0) { + if(index == 0) { /* True Edge */ branch_prefetch_set.putAll(tocompare); - }else if(index == 1) { + }else if(index == 1) { /* False Edge */ if(branch_prefetch_set.isEmpty()) { branch_prefetch_set.putAll(tocompare); } else { Enumeration e = tocompare.keys(); while(e.hasMoreElements()) { - pp = (PrefetchPair) e.nextElement(); + PrefetchPair pp = (PrefetchPair) e.nextElement(); if(branch_prefetch_set.containsKey(pp)) { - newprob = (float)(branch_prefetch_set.get(pp).floatValue() + tocompare.get(pp).floatValue()); + Double newprob = (branch_prefetch_set.get(pp).doubleValue() + tocompare.get(pp).doubleValue()); if(newprob < ANALYSIS_THRESHOLD_PROB) { branch_prefetch_set.remove(pp); } else { branch_prefetch_set.put(pp, newprob); } - tocompare.remove(pp); + } else { + branch_prefetch_set.put(pp,tocompare.get(pp).doubleValue()); } - } - e = tocompare.keys(); - while(e.hasMoreElements()) { - pp = (PrefetchPair) e.nextElement(); - branch_prefetch_set.put(pp,tocompare.get(pp)); tocompare.remove(pp); } } } else { - System.out.println("DEBUG-> No more children of the FlatCondBranchNode present"); + throw new Error("processFlatCondBranch() has only two child edges"); } } /* Compare prefetch sets and enqueue parent nodes: Only possible after combining prefetch pairs of both child nodes * into branch_prefetch_set hashtable*/ if(index == 1) { + boolean pSetHasChanged = false; + /* Delete the prefetch pairs below threshold */ + for(Iterator it = branch_prefetch_set.keySet().iterator(); it.hasNext();) { + PrefetchPair pp = (PrefetchPair) it.next(); + if(branch_prefetch_set.get(pp).doubleValue() < ANALYSIS_THRESHOLD_PROB) { + /* Delete pair mappings of PSChild-> PSParent for these prefetch pairs */ + for(int i = 0; i pairmap = pmap_hash.get(fn); + PairMap childpm = pairmap.get(curr); + if(childpm!=null && childpm.contains(pp)) { + childpm.removePair(pp); + } + } + branch_prefetch_set.remove(pp); + it = branch_prefetch_set.keySet().iterator(); + } + } + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), branch_prefetch_set); if(pSetHasChanged) { for(int i=0; i child_prefetch_set_copy, + private void processDefaultCase(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; PairMap pm = new PairMap(); Enumeration e = null; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); /* Propagate all child nodes */ for(e = child_prefetch_set_copy.keys(); e.hasMoreElements();) { PrefetchPair childpp = (PrefetchPair) e.nextElement(); - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -1094,7 +1137,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } } /* Compare with old Prefetch sets */ @@ -1106,29 +1159,27 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This functions processes for FlatNewNode * for e.g x = NEW(foo) followed by childnode with prefetch set x.f * then drop the prefetches beyond this FlatNewNode */ - private void processFlatNewNode(FlatNode curr, Hashtable child_prefetch_set_copy, + private void processFlatNewNode(FlatNode curr, Hashtable child_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatNew currfnn = (FlatNew) curr; - Float newprob = new Float((float)0.0); + Double newprob = new Double(0.0); PairMap pm = new PairMap(); - PrefetchPair childpp = null; Enumeration ecld = null; ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if(childpp.base == currfnn.getDst()){ child_prefetch_set_copy.remove(childpp); + } else if(isTempDescFound(childpp, currfnn.getDst())) { + child_prefetch_set_copy.remove(childpp); } else { tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); pm.addPair(childpp, childpp); @@ -1140,7 +1191,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the old prefetch set */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -1158,21 +1219,22 @@ public class PrefetchAnalysis { /** This functions processes for FlatCastNode * for e.g x = (cast type) y followed by childnode with prefetch set x.f * then drop the prefetches beyond this FlatCastNode */ - private void processFlatCastNode(FlatNode curr, Hashtablechild_prefetch_set_copy, + private void processFlatCastNode(FlatNode curr, Hashtablechild_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatCastNode currfcn = (FlatCastNode) curr; - Float newprob = new Float((float)0.0); + Double newprob = new Double(0.0); PairMap pm = new PairMap(); - PrefetchPair childpp = null; Enumeration ecld = null; ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if(childpp.base == currfcn.getDst()){ child_prefetch_set_copy.remove(childpp); + } else if(isTempDescFound(childpp, currfcn.getDst())) { + child_prefetch_set_copy.remove(childpp); } else { tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); pm.addPair(childpp, childpp); @@ -1184,7 +1246,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the old prefetch set */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -1197,31 +1269,29 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - /* Free heap memory */ - tocompare = null; - pm = null; } /** This functions processes for FlatTagDeclaration * for e.g x = (cast type) y followed by childnode with prefetch set x.f * then drop the prefetches beyond this FlatTagDeclaration */ - private void processFlatTagDeclaration(FlatNode curr, Hashtablechild_prefetch_set_copy, + private void processFlatTagDeclaration(FlatNode curr, Hashtablechild_prefetch_set_copy, Hashtable parentpmap) { boolean pSetHasChanged = false; - Hashtable tocompare = new Hashtable(); + Hashtable tocompare = new Hashtable(); FlatTagDeclaration currftd = (FlatTagDeclaration) curr; - Float newprob = new Float((float)0.0); + Double newprob = new Double(0.0); PairMap pm = new PairMap(); - PrefetchPair childpp = null; Enumeration ecld = null; ecld = child_prefetch_set_copy.keys(); while (ecld.hasMoreElements()) { - childpp = (PrefetchPair) ecld.nextElement(); + PrefetchPair childpp = (PrefetchPair) ecld.nextElement(); if(childpp.base == currftd.getDst()){ child_prefetch_set_copy.remove(childpp); + } else if(isTempDescFound(childpp, currftd.getDst())) { + child_prefetch_set_copy.remove(childpp); } else { - tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + tocompare.put(childpp, child_prefetch_set_copy.get(childpp).doubleValue()); pm.addPair(childpp, childpp); child_prefetch_set_copy.remove(childpp); } @@ -1231,7 +1301,17 @@ public class PrefetchAnalysis { if(!pm.isEmpty()) { parentpmap.put(curr, pm); } - pmap_hash.put(curr.getNext(0), parentpmap); + if(!pmap_hash.isEmpty()) { + Hashtable pairmapping = pmap_hash.get(curr.getNext(0)); + if(pairmapping != null) { + pairmapping.put(curr, pm); + pmap_hash.put(curr.getNext(0), pairmapping); + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } + } else { + pmap_hash.put(curr.getNext(0), parentpmap); + } /* Compare with the old prefetch set */ pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); @@ -1244,17 +1324,13 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } - - /* Free heap memory */ - tocompare = null; - pm = null; } /** This function prints the Prefetch pairs of a given flatnode */ private void printPrefetchPairs(FlatNode fn) { if(prefetch_hash.containsKey(fn)) { System.out.print("Prefetch" + "("); - Hashtable currhash = (Hashtable) prefetch_hash.get(fn); + Hashtable currhash = (Hashtable) prefetch_hash.get(fn); for(Enumeration pphash= currhash.keys(); pphash.hasMoreElements();) { PrefetchPair pp = (PrefetchPair) pphash.nextElement(); System.out.print(pp.toString() + ", "); @@ -1265,16 +1341,17 @@ public class PrefetchAnalysis { } } - private void doInsPrefetchAnalysis(FlatMethod fm) { + private void doInsPrefetchAnalysis(FlatMethod fm, Hashtable> newprefetchset) { + Hashtable> pset1_hash = new Hashtable>(); HashSet pset1_init = new HashSet(); LinkedList newtovisit = new LinkedList(); - newvisited = new LinkedList(); + LinkedList newvisited = new LinkedList(); newtovisit.addLast((FlatNode)fm); while(!newtovisit.isEmpty()) { FlatNode fn = (FlatNode) newtovisit.iterator().next(); newtovisit.remove(0); - pset1_hash.put(fn, pset1_init); + pset1_hash.put(fn, pset1_init); //Initialize pset1_hash newvisited.addLast(fn); for(int i=0; i pset1 = new HashSet(); - HashSet pset2 = new HashSet(); - HashSet newpset = new HashSet(); - Hashtable prefetchset = new Hashtable(); - boolean ppairIsPresent = false; - boolean mapIsPresent = true; - boolean pprobIsGreater = false; - boolean mapprobIsLess = false; - boolean probIsLess = false; - boolean pSet1HasChanged = false; - Enumeration e = null; - /* Create pset1 */ + private void applyPrefetchInsertRules(FlatNode fn, LinkedList newvisited, Hashtable> pset1_hash, + Hashtable> newprefetchset) { + if(fn.kind() == FKind.FlatMethod) { + HashSet pset1 = new HashSet(); if(prefetch_hash.containsKey(fn)) { - prefetchset = prefetch_hash.get(fn); - e = prefetchset.keys(); - while(e.hasMoreElements()) { + Hashtable prefetchset = prefetch_hash.get(fn); + for(Enumeration e = prefetchset.keys();e.hasMoreElements();) { PrefetchPair pp = (PrefetchPair) e.nextElement(); /* Apply initial rule */ - if(((float)prefetchset.get(pp).floatValue()) > PREFETCH_THRESHOLD_PROB) { + if(prefetchset.get(pp).doubleValue() >= PREFETCH_THRESHOLD_PROB) { pset1.add(pp); } } - /* Enqueue child node is Pset1 has changed */ - pSet1HasChanged = comparePSet1(pset1_hash.get(fn), pset1); - if(pSet1HasChanged) { + /* Enqueue child node if Pset1 has changed */ + if (comparePSet1(pset1_hash.get(fn), pset1)) { for(int j=0; j 0) { - newprefetchset.put(fn, pset1); - } + newprefetchset.put(fn, pset1); } - } else { + } else { /* Nodes other than Flat Method Node */ + HashSet pset2 = new HashSet(); + HashSet newpset = new HashSet(); if(prefetch_hash.containsKey(fn)) { - prefetchset = prefetch_hash.get(fn); + Hashtable prefetchset = prefetch_hash.get(fn); + Hashtable ppairmaphash = pmap_hash.get(fn); for(Enumeration epset = prefetchset.keys(); epset.hasMoreElements();) { PrefetchPair pp = (PrefetchPair) epset.nextElement(); - /* Create pset2 */ - Hashtable ppairmaphash = new Hashtable(); - ppairmaphash = pmap_hash.get(fn); - if(!ppairmaphash.isEmpty()) { - e = ppairmaphash.keys(); - while(e.hasMoreElements()) { - FlatNode parentnode = (FlatNode) e.nextElement(); - PairMap pm = (PairMap) ppairmaphash.get(parentnode); - if(pset1_hash.containsKey(parentnode)) { - HashSet pset = pset1_hash.get(parentnode); - if(!pset.isEmpty()) { - if(ppairIsPresent = (pset.contains((PrefetchPair) pm.getPair(pp)))) { - mapIsPresent = ppairIsPresent && mapIsPresent; - } - } else { - mapIsPresent = false; - } + boolean pprobIsGreater = (prefetchset.get(pp).doubleValue() >= PREFETCH_THRESHOLD_PROB); + boolean mapprobIsLess=false; + boolean mapIsPresent=true; + for(int i=0;i PREFETCH_THRESHOLD_PROB)) { - ppairmaphash = pmap_hash.get(fn); - if(!ppairmaphash.isEmpty()) { - e = ppairmaphash.keys(); - while(e.hasMoreElements()) { - FlatNode parentnode = (FlatNode) e.nextElement(); - PairMap pm = (PairMap) ppairmaphash.get(parentnode); - PrefetchPair mappedpp = pm.getPair(pp); - if(mappedpp != null) { - if(prefetch_hash.get(parentnode).containsKey(mappedpp)) { - float prob = (float)prefetch_hash.get(parentnode).get(mappedpp).floatValue(); - if(probIsLess = (prob < PREFETCH_THRESHOLD_PROB)) - mapprobIsLess = mapprobIsLess || probIsLess; - } + /* Build pset2 */ + if(pset1_hash.containsKey(parentnode)) { + if(pm !=null) { + HashSet pset = pset1_hash.get(parentnode); + if(pset.isEmpty()) { + continue; } else { - mapprobIsLess = false; + if(!pset.contains((PrefetchPair) pm.getPair(pp))) + mapIsPresent = false; } } } else { - mapprobIsLess = true; + throw new Error("applyPrefetchInsertRules() Parent node not present in pset1_hash: Not Possible"); } } - if(pprobIsGreater && mapprobIsLess) { + + if(mapIsPresent) + pset2.add(pp); + + if(pprobIsGreater && mapprobIsLess) newpset.add(pp); - } } + } else { + throw new Error("applyPrefetchInsertRules() fn: " +fn+ "not found"); } - if(!pset2.isEmpty()) - pset1.addAll(pset2); - if(!newpset.isEmpty()) - pset1.addAll(newpset); + + HashSet pset1 = new HashSet(); + pset1.addAll(pset2); + pset1.addAll(newpset); /* Enqueue child node if Pset1 has changed */ - pSet1HasChanged = comparePSet1(pset1_hash.get(fn), pset1); - if(pSet1HasChanged) { + if (comparePSet1(pset1_hash.get(fn), pset1)) { for(int i=0; i s = new HashSet(); - if(!newpset.isEmpty()) { - if(!pset2.isEmpty()) { - for(Iterator it = newpset.iterator(); it.hasNext();) { - PrefetchPair pp = (PrefetchPair) it.next(); - if(!pset2.contains(pp)) { - s.add(pp); - } - } - } else { - for(Iterator it = newpset.iterator(); it.hasNext();) { - PrefetchPair pp = (PrefetchPair) it.next(); - s.add(pp); - } + for(Iterator it = newpset.iterator(); it.hasNext();) { + PrefetchPair pp = (PrefetchPair) it.next(); + if(!pset2.contains(pp)) { + s.add(pp); } } - if(s.size() > 0) { - newprefetchset.put(fn, s); - } + newprefetchset.put(fn, s); } - - /* Free heap memory */ - pset1 = null; - pset2 = null; - newpset = null; - prefetchset = null; } private void addFlatPrefetchNode(Hashtable> newprefetchset) { - int i; Enumeration e = null; e = newprefetchset.keys(); boolean isFNPresent = false; /* Detects presence of FlatNew node */ - /* This modifies the graph */ + /* This modifies the Flat representation graph */ while(e.hasMoreElements()) { FlatNode fn = (FlatNode) e.nextElement(); FlatPrefetchNode fpn = new FlatPrefetchNode(); - for(i = 0; i< newprefetchset.get(fn).size(); i++) { + if(newprefetchset.get(fn).size() > 0) { fpn.insAllpp((HashSet)newprefetchset.get(fn)); - } - if(fn.kind() == FKind.FlatMethod) { - FlatNode nn = fn.getNext(0); - fn.setNext(0, fpn); - fpn.addNext(nn); - } else { - /* Check if previous node of this FlatNode is a NEW node - * If yes, delete this flatnode and its prefetch set from hash table - * This eliminates prefetches for NULL ptrs*/ - for(i = 0; i< fn.numPrev(); i++) { - FlatNode nn = fn.getPrev(i); - if(nn.kind() == FKind.FlatNew) { - isFNPresent = true; + if(fn.kind() == FKind.FlatMethod) { + FlatNode nn = fn.getNext(0); + fn.setNext(0, fpn); + fpn.addNext(nn); + } else { + /* Check if previous node of this FlatNode is a NEW node + * If yes, delete this flatnode and its prefetch set from hash table + * This eliminates prefetches for NULL ptrs*/ + for(int i = 0; i< fn.numPrev(); i++) { + FlatNode nn = fn.getPrev(i); + if(nn.kind() == FKind.FlatNew) { + isFNPresent = true; + } } - } - if(!isFNPresent) { - while(fn.numPrev() > 0) { - FlatNode nn = fn.getPrev(0); - for(int j = 0; j 0) { + FlatNode nn = fn.getPrev(0); + for(int j = 0; j desc; public PrefetchPair(){ + base = new TempDescriptor(""); desc = new ArrayList(); } @@ -101,15 +102,16 @@ public class PrefetchPair { public Object clone() { PrefetchPair newpp = new PrefetchPair(); + ArrayList td = null; newpp.base = this.base; - ArrayList td = new ArrayList(); - for(int i = 0; i(); + for(int j = 0; j < ((IndexDescriptor)o).tddesc.size(); j++) { + td.add(((IndexDescriptor)o).getTempDescAt(j)); } IndexDescriptor idesc = new IndexDescriptor(); idesc.tddesc = td; diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 0f61a9dd..ca41c728 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1499,8 +1499,10 @@ public class BuildCode { } output.println("};"); /* make the prefetch call to Runtime */ - output.println(" prefetch((int) numtuples_"+count+ ", oidarray_"+count+ ", endoffsetarry_"+ - count+", fieldarry_"+count+");"); + if(tuplecount > 0) { + output.println(" prefetch((int) numtuples_"+count+ ", oidarray_"+count+ ", endoffsetarry_"+ + count+", fieldarry_"+count+");"); + } count++; } diff --git a/Robust/src/IR/Operation.java b/Robust/src/IR/Operation.java index bc93b5f8..8e03682c 100644 --- a/Robust/src/IR/Operation.java +++ b/Robust/src/IR/Operation.java @@ -135,7 +135,7 @@ public class Operation { return "<<"; else if (operation==RIGHTSHIFT) return ">>"; - else if (operation==RIGHTSHIFT) + else if (operation==URIGHTSHIFT) return ">>>"; else if (operation==SUB) return "-"; diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index 31deba12..09684f9c 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -186,6 +186,12 @@ typedef struct local_thread_data_array { trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */ } local_thread_data_array_t; +//Structure to store mid and socketid information +typedef struct midSocketInfo { + unsigned int mid; + int sockid; +} midSocketInfo_t; + /* Initialize main object store and lookup tables, start server thread. */ int dstmInit(void); @@ -229,7 +235,6 @@ void *transRequest(void *); //the C routine that the thread will execute when TR void decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants void *getRemoteObj(transrecord_t *, unsigned int, unsigned int); - void *handleLocalReq(void *); int transComProcess(local_thread_data_array_t *); int transAbortProcess(local_thread_data_array_t *); @@ -243,7 +248,7 @@ prefetchpile_t *foundLocal(prefetchqelem_t *); prefetchpile_t *makePreGroups(prefetchqelem_t *, int *); void checkPreCache(prefetchqelem_t *, int *, unsigned int, int); int transPrefetchProcess(transrecord_t *, int **, short); -void sendPrefetchReq(prefetchpile_t*); +void sendPrefetchReq(prefetchpile_t*, int); int getPrefetchResponse(int); unsigned short getObjType(unsigned int oid); int startRemoteThread(unsigned int oid, unsigned int mid); diff --git a/Robust/src/Runtime/DSTM/interface/dstmserver.c b/Robust/src/Runtime/DSTM/interface/dstmserver.c index 1988c502..e76ab19f 100644 --- a/Robust/src/Runtime/DSTM/interface/dstmserver.c +++ b/Robust/src/Runtime/DSTM/interface/dstmserver.c @@ -27,7 +27,6 @@ extern int classsize[]; objstr_t *mainobjstore; pthread_mutex_t mainobjstore_mutex; pthread_mutexattr_t mainobjstore_mutex_attr; /* Attribute for lock to make it a recursive lock */ -pthread_mutex_t threadnotify_mutex = PTHREAD_MUTEX_INITIALIZER; /* This function initializes the main objects store and creates the * global machine and location lookup table */ @@ -189,10 +188,22 @@ void *dstmAccept(void *acceptfd) } break; case TRANS_PREFETCH: - if((val = prefetchReq((int)acceptfd)) != 0) { - printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__); - pthread_exit(NULL); - } + do { + if((val = prefetchReq((int)acceptfd)) != 0) { + printf("Error: In prefetchReq() %s, %d\n", __FILE__, __LINE__); + pthread_exit(NULL); + } + + if((retval = recv((int)acceptfd, &control, sizeof(char), 0)) < 0) { + printf("%s() Error: Receiving control = %d at %s, %d\n", __func__, control, __FILE__, __LINE__); + pthread_exit(NULL); + } else if(retval == 0) { + printf("%s() Error: socket closed at the requesting side\n"); + pthread_exit(NULL); + } + + } while (control == TRANS_PREFETCH); + break; case TRANS_PREFETCH_RESPONSE: if((val = getPrefetchResponse((int) acceptfd)) != 0) { @@ -268,7 +279,6 @@ void *dstmAccept(void *acceptfd) /* Close connection */ if (close((int)acceptfd) == -1) perror("close"); - pthread_exit(NULL); } @@ -306,7 +316,7 @@ int readClientReq(trans_commit_data_t *transinfo, int acceptfd) { /* Read oid and version tuples for those objects that are not modified in the transaction */ int numread = fixed.numread; - N = numread * (sizeof(unsigned int) + sizeof(short)); + N = numread * (sizeof(unsigned int) + sizeof(unsigned short)); char objread[N]; if(numread != 0) { //If pile contains more than one object to be read, // keep reading all objects @@ -473,7 +483,7 @@ char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigne /* Process each oid in the machine pile/ group per thread */ for (i = 0; i < fixed->numread + fixed->nummod; i++) { if (i < fixed->numread) {//Objs only read and not modified - int incr = sizeof(unsigned int) + sizeof(short);// Offset that points to next position in the objread array + int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array incr *= i; oid = *((unsigned int *)(objread + incr)); incr += sizeof(unsigned int); @@ -676,7 +686,7 @@ int prefetchReq(int acceptfd) { int length, sd; char *recvbuffer, *sendbuffer, control; unsigned int oid, mid; - unsigned short *offsetarry; + short *offsetarry; objheader_t *header; struct sockaddr_in remoteAddr; @@ -693,12 +703,12 @@ int prefetchReq(int acceptfd) { while(numbytes < size) { numbytes += recv((int)acceptfd, recvbuffer+numbytes, size-numbytes, 0); } - + oid = *((unsigned int *) recvbuffer); mid = *((unsigned int *) (recvbuffer + sizeof(unsigned int))); size = size - (2 * sizeof(unsigned int)); numoffset = size / sizeof(short); - if((offsetarry = calloc(numoffset, sizeof(unsigned short))) == NULL) { + if((offsetarry = calloc(numoffset, sizeof(short))) == NULL) { printf("Calloc error at %s,%d\n", __FILE__, __LINE__); free(recvbuffer); return -1; @@ -709,7 +719,7 @@ int prefetchReq(int acceptfd) { /* Create socket to send information */ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("prefetchReq():socket()"); - return; + return -1; } bzero(&remoteAddr, sizeof(remoteAddr)); remoteAddr.sin_family = AF_INET; @@ -779,6 +789,12 @@ int prefetchReq(int acceptfd) { } if(isArray == 1) { int elementsize = classsize[TYPE(header)]; + struct ArrayObject *ao = (struct ArrayObject *) (((char *)header) + sizeof(objheader_t)); + unsigned short length = ao->___length___; + /* Check if array out of bounds */ + if(offsetarry[i]< 0 || offsetarry[i] >= length) { + break; + } oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*offsetarry[i]))); } else { oid = *((unsigned int *)(((char *)header) + sizeof(objheader_t) + offsetarry[i])); diff --git a/Robust/src/Runtime/DSTM/interface/mcpileq.h b/Robust/src/Runtime/DSTM/interface/mcpileq.h index 26a3de2c..fa58eb0f 100644 --- a/Robust/src/Runtime/DSTM/interface/mcpileq.h +++ b/Robust/src/Runtime/DSTM/interface/mcpileq.h @@ -16,7 +16,7 @@ typedef struct objpile { //Structure for prefetching tuples generated by the compiler typedef struct prefetchpile { - int mid; + unsigned int mid; objpile_t *objpiles; struct prefetchpile *next; }prefetchpile_t; diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index eec4a90b..e9d2d90b 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -23,8 +23,9 @@ #endif #define LISTEN_PORT 2156 -#define NUM_THREADS 10 +#define NUM_THREADS 1 #define PREFETCH_CACHE_SIZE 1048576 //1MB +#define NUM_MACHINES 2 #define CONFIG_FILENAME "dstm.conf" /* Global Variables */ @@ -47,8 +48,11 @@ int myIndexInHostArray; unsigned int oidsPerBlock; unsigned int oidMin; unsigned int oidMax; -void *mlist[10000]; -pthread_mutex_t mlock = PTHREAD_MUTEX_INITIALIZER; + +/* Global variables to track mapping of socketid and remote mid */ +midSocketInfo_t midSocketArray[NUM_MACHINES]; +int sockCount = 0; +int sockIdFound; void printhex(unsigned char *, int); plistnode_t *createPiles(transrecord_t *); @@ -93,7 +97,7 @@ void prefetch(int ntuples, unsigned int *oids, unsigned short *endoffsets, short /* Allocate for the queue node*/ char *node; if(ntuples > 0) { - qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(unsigned short); + qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short); if((node = calloc(1, qnodesize)) == NULL) { printf("Calloc Error %s, %d\n", __FILE__, __LINE__); return; @@ -106,7 +110,7 @@ void prefetch(int ntuples, unsigned int *oids, unsigned short *endoffsets, short len += ntuples * sizeof(unsigned int); memcpy(node + len, endoffsets, ntuples*sizeof(unsigned short)); len += ntuples * sizeof(unsigned short); - memcpy(node + len, arrayfields, endoffsets[ntuples-1]*sizeof(unsigned short)); + memcpy(node + len, arrayfields, endoffsets[ntuples-1]*sizeof(short)); /* Lock and insert into primary prefetch queue */ pthread_mutex_lock(&pqueue.qlock); pre_enqueue((prefetchqelem_t *)node); @@ -131,6 +135,8 @@ int dstmStartup(const char * option) { dstmInit(); transInit(); + + if (master) { pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -189,6 +195,7 @@ void transInit() { //Create prefetch cache lookup table if(prehashCreate(HASH_SIZE, LOADFACTOR)) return; //Failure + //Initialize primary shared queue queueInit(); //Initialize machine pile w/prefetch oids and offsets shared queue @@ -200,6 +207,12 @@ void transInit() { } while(retval!=0); pthread_detach(tPrefetch); + //Initialize mid to socketid mapping array + for(t = 0; t < NUM_MACHINES; t++) { + midSocketArray[t].mid = 0; + midSocketArray[t].sockid = 0; + } + //Create and Initialize a pool of threads /* Threads are active for the entire period runtime is running */ for(t = 0; t< NUM_THREADS; t++) { @@ -340,8 +353,8 @@ objheader_t *transRead(transrecord_t *record, unsigned int oid) { printf("Error: %s() No machine found for oid =% %s,%dx\n",__func__, machinenumber, __FILE__, __LINE__); return NULL; } - objcopy = getRemoteObj(record, machinenumber, oid); + if(objcopy == NULL) { printf("Error: Object not found in Remote location %s, %d\n", __FILE__, __LINE__); return NULL; @@ -690,7 +703,7 @@ void *transRequest(void *threadarg) { /* Send oids and version number tuples for objects that are read */ { - int size=(sizeof(unsigned int)+sizeof(short))*tdata->buffer->f.numread; + int size=(sizeof(unsigned int)+sizeof(unsigned short))*tdata->buffer->f.numread; if (send(sd, tdata->buffer->objread, size, MSG_NOSIGNAL) < size) { perror("Error sending tuples for thread\n"); @@ -866,12 +879,11 @@ char sendResponse(thread_data_array_t *tdata, int sd) { void *getRemoteObj(transrecord_t *record, unsigned int mnum, unsigned int oid) { int sd, size, val; struct sockaddr_in serv_addr; - char control; char machineip[16]; + char control; objheader_t *h; void *objcopy; - if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("Error in socket\n"); return NULL; @@ -884,31 +896,33 @@ void *getRemoteObj(transrecord_t *record, unsigned int mnum, unsigned int oid) { machineip[15] = '\0'; serv_addr.sin_addr.s_addr = inet_addr(machineip); - /* Open connection */ + // Open connection if (connect(sd, (struct sockaddr *) &serv_addr, sizeof(struct sockaddr)) < 0) { perror("getRemoteObj() Error in connect\n"); return NULL; } + char readrequest[sizeof(char)+sizeof(unsigned int)]; readrequest[0] = READ_REQUEST; *((unsigned int *)(&readrequest[1])) = oid; if (send(sd, readrequest, sizeof(readrequest), MSG_NOSIGNAL) < sizeof(readrequest)) { - perror("Error sending message\n"); + perror("getRemoteObj(): error sending message\n"); return NULL; } /* Read response from the Participant */ if((val = read(sd, &control, sizeof(char))) <= 0) { - perror("No control response for getRemoteObj sent\n"); + printf("getRemoteObj(): error no response, %d\n", val); return NULL; } + switch(control) { case OBJECT_NOT_FOUND: return NULL; case OBJECT_FOUND: /* Read object if found into local cache */ if((val = read(sd, &size, sizeof(int))) <= 0) { - perror("No size is read from the participant\n"); + perror("getRemoteObj(): error in reading size\n"); return NULL; } objcopy = objstrAlloc(record->cache, size); @@ -916,20 +930,15 @@ void *getRemoteObj(transrecord_t *record, unsigned int mnum, unsigned int oid) { while (sum < size) { sum += read(sd, (char *)objcopy+sum, size-sum); } - /* - if((val = read(sd, (char *)objcopy, size)) <= 0) { - perror("No objects are read from the remote participant\n"); - return NULL; - } - */ /* Insert into cache's lookup table */ chashInsert(record->lookupTable, oid, objcopy); break; default: - printf("Error in recv request from participant on a READ_REQUEST %s, %d\n",__FILE__, __LINE__); + printf("Error: in recv response from participant on a READ_REQUEST %s, %d\n",__FILE__, __LINE__); return NULL; } - /* Close connection */ + + //Close connection close(sd); return objcopy; } @@ -961,10 +970,10 @@ void *handleLocalReq(void *threadarg) { /* Process each oid in the machine pile/ group per thread */ for (i = 0; i < localtdata->tdata->buffer->f.numread + localtdata->tdata->buffer->f.nummod; i++) { if (i < localtdata->tdata->buffer->f.numread) { - int incr = sizeof(unsigned int) + sizeof(short);// Offset that points to next position in the objread array + int incr = sizeof(unsigned int) + sizeof(unsigned short);// Offset that points to next position in the objread array incr *= i; oid = *((unsigned int *)(((char *)localtdata->tdata->buffer->objread) + incr)); - version = *((short *)(((char *)localtdata->tdata->buffer->objread) + incr + sizeof(unsigned int))); + version = *((unsigned short *)(((char *)localtdata->tdata->buffer->objread) + incr + sizeof(unsigned int))); } else { // Objects Modified int tmpsize; headptr = (objheader_t *) chashSearch(localtdata->tdata->rec->lookupTable, localtdata->tdata->buffer->oidmod[i-numread]); @@ -1152,7 +1161,8 @@ void checkPrefetchTuples(prefetchqelem_t *node) { char *ptr, *tmp; int ntuples, slength; unsigned int *oid; - short *endoffsets, *arryfields; + unsigned short *endoffsets; + short *arryfields; /* Check for the case x.y.z and a.b.c are same oids */ ptr = (char *) node; @@ -1215,7 +1225,8 @@ prefetchpile_t *makePreGroups(prefetchqelem_t *node, int *numoffset) { char *ptr; int ntuples, i, machinenum, count=0; unsigned int *oid; - short *endoffsets, *arryfields, *offset; + unsigned short *endoffsets; + short *arryfields, *offset; prefetchpile_t *head = NULL, *tmp = NULL; /* Check for the case x.y.z and a.b.c are same oids */ @@ -1273,7 +1284,8 @@ prefetchpile_t *foundLocal(prefetchqelem_t *node) { int isArray; char *ptr, *tmp; objheader_t *objheader; - short *endoffsets, *arryfields; + unsigned short *endoffsets; + short *arryfields; prefetchpile_t *head = NULL; ptr = (char *) node; @@ -1281,7 +1293,7 @@ prefetchpile_t *foundLocal(prefetchqelem_t *node) { oid = GET_PTR_OID(ptr); endoffsets = GET_PTR_EOFF(ptr, ntuples); arryfields = GET_PTR_ARRYFLD(ptr, ntuples); - + /* Find offset length for each tuple */ int numoffset[ntuples];//Number of offsets for each tuple numoffset[0] = endoffsets[0]; @@ -1330,6 +1342,12 @@ prefetchpile_t *foundLocal(prefetchqelem_t *node) { } if(isArray == 1) { int elementsize = classsize[TYPE(objheader)]; + struct ArrayObject *ao = (struct ArrayObject *) (tmp + sizeof(objheader_t)); + unsigned short length = ao->___length___; + /* Check if array out of bounds */ + if(arryfields[arryfieldindex] < 0 || arryfields[arryfieldindex]>= length) { + break; + } objoid = *((unsigned int *)(tmp + sizeof(objheader_t) + sizeof(struct ArrayObject) + (elementsize*arryfields[arryfieldindex]))); } else { objoid = *((unsigned int *)(tmp + sizeof(objheader_t) + arryfields[arryfieldindex])); @@ -1379,7 +1397,8 @@ void checkPreCache(prefetchqelem_t *node, int *numoffset, unsigned int objoid, i char *ptr, *tmp; int ntuples, i, k, flag=0, isArray =0, arryfieldindex, val; unsigned int * oid; - short *endoffsets, *arryfields; + unsigned short *endoffsets; + short *arryfields; objheader_t *header; ptr = (char *) node; @@ -1500,11 +1519,15 @@ void *transPrefetch(void *t) { * The thread is active throughout the period of runtime */ void *mcqProcess(void *threadid) { - int tid; + int tid, i; prefetchpile_t *mcpilenode; + struct sockaddr_in remoteAddr; + int sd; tid = (int) threadid; while(1) { + + sockIdFound = 0; /* Lock mutex of mc pile queue */ pthread_mutex_lock(&mcqueue.qlock); /* When mc pile queue is empty, wait */ @@ -1520,10 +1543,48 @@ void *mcqProcess(void *threadid) { /* Unlock mutex */ pthread_mutex_unlock(&mcqueue.qlock); - /*Initiate connection to remote host and send request */ - /* Process Request */ + /*Initiate connection to remote host and send prefetch request */ if(mcpilenode->mid != myIpAddr) { - sendPrefetchReq(mcpilenode); + /* Check to see if socket exists */ + for(i = 0; i < NUM_MACHINES; i++) { + if(midSocketArray[i].mid == mcpilenode->mid) { + sendPrefetchReq(mcpilenode, midSocketArray[i].sockid); + sockIdFound = 1; + break; + } + } + + if(sockIdFound == 0) { + if(sockCount < NUM_MACHINES) { + /* Open Socket */ + if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + printf("%s() Error: In creating socket at %s, %d\n", __func__, __FILE__, __LINE__); + return; + } + + bzero(&remoteAddr, sizeof(remoteAddr)); + remoteAddr.sin_family = AF_INET; + remoteAddr.sin_port = htons(LISTEN_PORT); + remoteAddr.sin_addr.s_addr = htonl(mcpilenode->mid); + + /* Open Connection */ + if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) { + printf("%s():error %d connecting to %s:%d\n", __func__, errno, + inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT); + close(sd); + return; + } + + midSocketArray[sockCount].mid = mcpilenode->mid; + midSocketArray[sockCount].sockid = sd; + sendPrefetchReq(mcpilenode, midSocketArray[sockCount].sockid); + sockCount++; + } else { + //TODO Fix for connecting to more than 2 machines && close socket + printf("%s(): Error: Currently works for only 2 machines\n", __func__); + return; + } + } } /* Deallocate the machine queue pile node */ @@ -1531,39 +1592,15 @@ void *mcqProcess(void *threadid) { } } -void sendPrefetchReq(prefetchpile_t *mcpilenode) { - int sd, i, off, len, endpair, count = 0; - struct sockaddr_in remoteAddr; +void sendPrefetchReq(prefetchpile_t *mcpilenode, int sd) { + int i, off, len, endpair, count = 0; char machineip[16], control; objpile_t *tmp; - unsigned int mid; - - /* Send Trans Prefetch Request */ - if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("Error in socket for SEND_PREFETCH_REQUEST\n"); - return; - } - - mid = mcpilenode->mid; - - bzero(&remoteAddr, sizeof(remoteAddr)); - remoteAddr.sin_family = AF_INET; - remoteAddr.sin_port = htons(LISTEN_PORT); - remoteAddr.sin_addr.s_addr = htonl(mid); - - /* Open Connection */ - if (connect(sd, (struct sockaddr *)&remoteAddr, sizeof(remoteAddr)) < 0) { - printf("%s():error %d connecting to %s:%d\n", __func__, errno, - inet_ntoa(remoteAddr.sin_addr), LISTEN_PORT); - close(sd); - return; - } /* Send TRANS_PREFETCH control message */ control = TRANS_PREFETCH; if(send(sd, &control, sizeof(char), MSG_NOSIGNAL) < sizeof(char)) { - perror("Error in sending prefetch control\n"); - close(sd); + perror("sendPrefetchReq() Sending TRANS_PREFETCH"); return; } @@ -1572,23 +1609,21 @@ void sendPrefetchReq(prefetchpile_t *mcpilenode) { while(tmp != NULL) { off = 0; count++; /* Keeps track of the number of oid and offset tuples sent per remote machine */ - len = sizeof(int) + sizeof(unsigned int) + sizeof(unsigned int) + ((tmp->numoffset) * sizeof(unsigned short)); + len = sizeof(int) + sizeof(unsigned int) + sizeof(unsigned int) + ((tmp->numoffset) * sizeof(short)); char oidnoffset[len]; bzero(oidnoffset, len); - *((unsigned int*)oidnoffset) = len; + *((int*)oidnoffset) = len; off = sizeof(int); - *((unsigned int *)((char *)oidnoffset + off)) = tmp->oid; + *((unsigned int *)(oidnoffset + off)) = tmp->oid; off += sizeof(unsigned int); - *((unsigned int *)((char *)oidnoffset + off)) = myIpAddr; //Recently added as of 03/03/2008 at 6:00pm + *((unsigned int *)(oidnoffset + off)) = myIpAddr; off += sizeof(unsigned int); for(i = 0; i < tmp->numoffset; i++) { - *((unsigned short*)((char *)oidnoffset + off)) = tmp->offset[i]; - off+=sizeof(unsigned short); + *((short*)(oidnoffset + off)) = tmp->offset[i]; + off+=sizeof(short); } - if (send(sd, oidnoffset, len , MSG_NOSIGNAL) < len) { - perror("Error sending fixed bytes for thread\n"); - close(sd); + perror("Sending oids and offsets"); return; } @@ -1598,12 +1633,10 @@ void sendPrefetchReq(prefetchpile_t *mcpilenode) { /* Send a special char -1 to represent the end of sending oids + offset pair to remote machine */ endpair = -1; if (send(sd, &endpair, sizeof(int), MSG_NOSIGNAL) < sizeof(int)) { - perror("Error sending fixed bytes for thread\n"); - close(sd); + perror("Error sending endpair\n"); return; } - close(sd); return; } @@ -1626,7 +1659,7 @@ int getPrefetchResponse(int sd) { while(numbytes < size) { numbytes += recv((int)sd, recvbuffer+numbytes, size-numbytes, 0); } - + control = *((char *) recvbuffer); if(control == OBJECT_FOUND) { numbytes = 0; @@ -1665,7 +1698,7 @@ int getPrefetchResponse(int sd) { oid = *((unsigned int *)(recvbuffer + sizeof(char))); /* TODO: For each object not found query DHT for new location and retrieve the object */ /* Throw an error */ - printf("OBJECT NOT FOUND.... THIS SHOULD NOT HAPPEN...TERMINATE PROGRAM\n"); + printf("OBJECT %x NOT FOUND.... THIS SHOULD NOT HAPPEN...TERMINATE PROGRAM\n", oid); free(recvbuffer); exit(-1); } else { @@ -1871,7 +1904,7 @@ int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int n int sock,i; objheader_t *objheader; struct sockaddr_in remoteAddr; - char msg[1 + numoid * (sizeof(short) + sizeof(unsigned int)) + 3 * sizeof(unsigned int)]; + char msg[1 + numoid * (sizeof(unsigned short) + sizeof(unsigned int)) + 3 * sizeof(unsigned int)]; char *ptr; int bytesSent; int status, size;