CallGraph callgraph;
TypeUtil typeutil;
Set<FlatNode> tovisit;
- public Hashtable<FlatNode, Hashtable<PrefetchPair, Float>> prefetch_hash;
- public Hashtable<FlatNode, Hashtable<FlatNode, PairMap>> pmap_hash;
- Hashtable<PrefetchPair, Float> branch_prefetch_set;
- LinkedList<FlatNode> newvisited;
- Hashtable<FlatNode, HashSet<PrefetchPair>> pset1_hash;
- Hashtable<FlatNode, HashSet<PrefetchPair>> 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<FlatNode, Hashtable<PrefetchPair, Double>> prefetch_hash;//holds all flatnodes and corresponding prefetch set
+ public Hashtable<FlatNode, Hashtable<FlatNode, PairMap>> 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<FlatNode, Hashtable<PrefetchPair,Float>>();
+ prefetch_hash = new Hashtable<FlatNode, Hashtable<PrefetchPair,Double>>();
pmap_hash = new Hashtable<FlatNode, Hashtable<FlatNode, PairMap>>();
DoPrefetch();
prefetch_hash = null;
private void doMethodAnalysis(ClassDescriptor cn) {
Iterator methodit=cn.getMethods();
while(methodit.hasNext()) {
- newprefetchset = new Hashtable<FlatNode, HashSet<PrefetchPair>>();
- pset1_hash = new Hashtable<FlatNode, HashSet<PrefetchPair>>();
+ Hashtable<FlatNode, HashSet<PrefetchPair>> newprefetchset = new Hashtable<FlatNode, HashSet<PrefetchPair>>();
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<PrefetchPair, Float> nodehash = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> nodehash = new Hashtable<PrefetchPair, Double>();
/* 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()) {
* returns false : otherwise
*/
private void doChildNodeAnalysis(FlatNode curr) {
- Hashtable<PrefetchPair, Float> child_prefetch_set_copy = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> child_prefetch_set_copy = new Hashtable<PrefetchPair, Double>();
Hashtable<FlatNode, PairMap> parentpmap = new Hashtable<FlatNode, PairMap>();
FlatNode child_node = null;
if(curr.numNext() != 0) {
child_node = curr.getNext(0);
if(prefetch_hash.containsKey(child_node)) {
- child_prefetch_set_copy = (Hashtable<PrefetchPair,Float>) prefetch_hash.get(child_node).clone();
+ child_prefetch_set_copy = (Hashtable<PrefetchPair,Double>) prefetch_hash.get(child_node).clone();
}
}
processFlatElementNode(curr, child_prefetch_set_copy, parentpmap);
break;
case FKind.FlatCondBranch:
- branch_prefetch_set = new Hashtable<PrefetchPair,Float>();
+ Hashtable<PrefetchPair, Double> branch_prefetch_set = new Hashtable<PrefetchPair,Double>();
for (int i = 0; i < curr.numNext(); i++) {
- parentpmap = new Hashtable<FlatNode, PairMap>();
+ Hashtable<FlatNode, PairMap> branchparentpmap = new Hashtable<FlatNode, PairMap>();
child_node = curr.getNext(i);
if (prefetch_hash.containsKey(child_node)) {
- child_prefetch_set_copy = (Hashtable<PrefetchPair,Float>) prefetch_hash.get(child_node).clone();
+ child_prefetch_set_copy = (Hashtable<PrefetchPair,Double>) 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);
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<PrefetchPair, Float> oldPrefetchSet, Hashtable<PrefetchPair, Float>
+ private boolean comparePrefetchSets(Hashtable<PrefetchPair, Double> oldPrefetchSet, Hashtable<PrefetchPair, Double>
newPrefetchSet) {
boolean hasChanged = false;
PrefetchPair oldpp = null;
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;
* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatFieldNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> currcopy = new Hashtable<PrefetchPair, Float>();
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> currcopy = new Hashtable<PrefetchPair, Double>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
FlatFieldNode currffn = (FlatFieldNode) curr;
PairMap pm = new PairMap();
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);
}
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 {
}
} 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;
}
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;
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);
}
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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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
* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatElementNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> currcopy = new Hashtable<PrefetchPair, Float>();
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> currcopy = new Hashtable<PrefetchPair, Double>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
FlatElementNode currfen = (FlatElementNode) curr;
PairMap pm = new PairMap();
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<Descriptor> newdesc = new ArrayList<Descriptor>();
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 {
}
} 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
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;
/* 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);
}
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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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
* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatSetFieldNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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) */
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 {
/* 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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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
* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatSetElementNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
- PrefetchPair childpp = null;
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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)) {
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 {
/* 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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatOpNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
int index;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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*/
ArrayList<Descriptor> newdesc = new ArrayList<Descriptor>();
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 {
}
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<Descriptor> newdesc = new ArrayList<Descriptor>();
newdesc.addAll((ArrayList<Descriptor>)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 {
}
newdesc = null;
newpp = null;
- }else {
+ } else {
continue;
}
}
} 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<Descriptor> newdesc = new ArrayList<Descriptor>();
newdesc.addAll((ArrayList<Descriptor>)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 {
}
child_prefetch_set_copy.remove(newpp);
}
- }else {
+ } else {
continue;
}
}
/* 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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatLiteralNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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<Descriptor> copychilddesc = (ArrayList<Descriptor>) 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<TempDescriptor> td = (ArrayList<TempDescriptor>)((IndexDescriptor)o).tddesc;
ArrayList<Descriptor> newdesc = new ArrayList<Descriptor>();
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 {
/* 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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatMethod(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatCall(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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 {
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> child_prefetch_set_copy, int index,
- Hashtable<PrefetchPair,Float> branch_prefetch_set, Hashtable<FlatNode, PairMap> parentpmap) {
- boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();//temporary hash table
+ private void processFlatCondBranch(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy, int index,
+ Hashtable<PrefetchPair,Double> branch_prefetch_set, Hashtable<FlatNode, PairMap> parentpmap) {
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();//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");
}
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(index), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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<curr.numNext(); i++) {
+ FlatNode fn = (FlatNode) curr.getNext(i);
+ Hashtable<FlatNode, PairMap> 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<curr.numPrev(); i++) {
prefetch_hash.put(curr,branch_prefetch_set);
}
}
- /* Free heap memory */
- tocompare = null;
- pm = null;
}
/** If FlatNode is not concerned with the prefetch set of its Child then propagate
* prefetches up the FlatNode*/
- private void processDefaultCase(FlatNode curr, Hashtable<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processDefaultCase(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
PairMap pm = new PairMap();
Enumeration e = null;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
/* 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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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 */
/* 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<PrefetchPair, Float> child_prefetch_set_copy,
+ private void processFlatNewNode(FlatNode curr, Hashtable<PrefetchPair, Double> child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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);
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/** 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, Hashtable<PrefetchPair, Float>child_prefetch_set_copy,
+ private void processFlatCastNode(FlatNode curr, Hashtable<PrefetchPair, Double>child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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);
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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, Hashtable<PrefetchPair, Float>child_prefetch_set_copy,
+ private void processFlatTagDeclaration(FlatNode curr, Hashtable<PrefetchPair, Double>child_prefetch_set_copy,
Hashtable<FlatNode, PairMap> parentpmap) {
boolean pSetHasChanged = false;
- Hashtable<PrefetchPair, Float> tocompare = new Hashtable<PrefetchPair, Float>();
+ Hashtable<PrefetchPair, Double> tocompare = new Hashtable<PrefetchPair, Double>();
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);
}
if(!pm.isEmpty()) {
parentpmap.put(curr, pm);
}
- pmap_hash.put(curr.getNext(0), parentpmap);
+ if(!pmap_hash.isEmpty()) {
+ Hashtable<FlatNode, PairMap> 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);
/* 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<PrefetchPair, Float> currhash = (Hashtable) prefetch_hash.get(fn);
+ Hashtable<PrefetchPair, Double> currhash = (Hashtable) prefetch_hash.get(fn);
for(Enumeration pphash= currhash.keys(); pphash.hasMoreElements();) {
PrefetchPair pp = (PrefetchPair) pphash.nextElement();
System.out.print(pp.toString() + ", ");
}
}
- private void doInsPrefetchAnalysis(FlatMethod fm) {
+ private void doInsPrefetchAnalysis(FlatMethod fm, Hashtable<FlatNode, HashSet<PrefetchPair>> newprefetchset) {
+ Hashtable<FlatNode, HashSet<PrefetchPair>> pset1_hash = new Hashtable<FlatNode, HashSet<PrefetchPair>>();
HashSet<PrefetchPair> pset1_init = new HashSet<PrefetchPair>();
LinkedList<FlatNode> newtovisit = new LinkedList<FlatNode>();
- newvisited = new LinkedList<FlatNode>();
+ LinkedList<FlatNode> newvisited = new LinkedList<FlatNode>();
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<fn.numNext(); i++) {
FlatNode nn = fn.getNext(i);
}
}
- /* Free Heap Memory */
- pset1_init = null;
- newtovisit = null;
-
/* Delete redundant and subset prefetch pairs */
delSubsetPPairs();
-
+
/* Start with a top down sorted order of nodes */
while(!newvisited.isEmpty()) {
- applyPrefetchInsertRules((FlatNode) newvisited.getFirst());
+ applyPrefetchInsertRules((FlatNode) newvisited.getFirst(), newvisited, pset1_hash, newprefetchset);
newvisited.remove(0);
}
}
ppairs.remove(pp);
}
}
-
- /* Free heap memory */
- pplist = null;
- pplength = null;
- ppisMod = null;
}
}
* this function creates pset1 such that it contains prefetch pairs that have been prefetched at
* the previous nodes */
- private void applyPrefetchInsertRules(FlatNode fn) {
- HashSet<PrefetchPair> pset1 = new HashSet<PrefetchPair>();
- HashSet<PrefetchPair> pset2 = new HashSet<PrefetchPair>();
- HashSet<PrefetchPair> newpset = new HashSet<PrefetchPair>();
- Hashtable<PrefetchPair, Float> prefetchset = new Hashtable<PrefetchPair, Float>();
- 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<FlatNode> newvisited, Hashtable<FlatNode, HashSet<PrefetchPair>> pset1_hash,
+ Hashtable<FlatNode, HashSet<PrefetchPair>> newprefetchset) {
+
if(fn.kind() == FKind.FlatMethod) {
+ HashSet<PrefetchPair> pset1 = new HashSet<PrefetchPair>();
if(prefetch_hash.containsKey(fn)) {
- prefetchset = prefetch_hash.get(fn);
- e = prefetchset.keys();
- while(e.hasMoreElements()) {
+ Hashtable<PrefetchPair, Double> 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<fn.numNext(); j++) {
FlatNode nn = fn.getNext(j);
newvisited.addLast((FlatNode)nn);
}
+ pset1_hash.put(fn, pset1);
}
- pset1_hash.put(fn, pset1);
- if(pset1.size() > 0) {
- newprefetchset.put(fn, pset1);
- }
+ newprefetchset.put(fn, pset1);
}
- } else {
+ } else { /* Nodes other than Flat Method Node */
+ HashSet<PrefetchPair> pset2 = new HashSet<PrefetchPair>();
+ HashSet<PrefetchPair> newpset = new HashSet<PrefetchPair>();
if(prefetch_hash.containsKey(fn)) {
- prefetchset = prefetch_hash.get(fn);
+ Hashtable<PrefetchPair, Double> prefetchset = prefetch_hash.get(fn);
+ Hashtable<FlatNode, PairMap> ppairmaphash = pmap_hash.get(fn);
for(Enumeration epset = prefetchset.keys(); epset.hasMoreElements();) {
PrefetchPair pp = (PrefetchPair) epset.nextElement();
- /* Create pset2 */
- Hashtable<FlatNode, PairMap> ppairmaphash = new Hashtable<FlatNode, PairMap>();
- 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<fn.numPrev();i++) {
+ FlatNode parentnode=fn.getPrev(i);
+ PairMap pm = (PairMap) ppairmaphash.get(parentnode);
+ /* Build newpset */
+ if(pm!=null&&pm.getPair(pp) != null) {
+ PrefetchPair mappedpp = pm.getPair(pp);
+ if(prefetch_hash.get(parentnode).containsKey(mappedpp)) {
+ double prob = prefetch_hash.get(parentnode).get(mappedpp).doubleValue();
+ if(prob < PREFETCH_THRESHOLD_PROB)
+ mapprobIsLess = true;
}
+ } else {
+ mapprobIsLess = true;
}
- if(mapIsPresent) {
- pset2.add(pp);
- }
- }
-
- /* Create newprefetchset */
- if(pprobIsGreater = (prefetchset.get(pp).floatValue() > 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<PrefetchPair> pset1 = new HashSet<PrefetchPair>();
+ 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<fn.numNext(); i++) {
FlatNode nn = fn.getNext(i);
newvisited.addLast((FlatNode)nn);
}
+ pset1_hash.put(fn, pset1);
}
- pset1_hash.put(fn, pset1);
-
- /* To insert prefetch apply rule: if the newpset intersection pset2 is nonempty
+ /* To insert prefetch, apply rule: if the newpset minus pset2 is nonempty
* then insert a new prefetch node here*/
+
HashSet<PrefetchPair> s = new HashSet<PrefetchPair>();
- 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<FlatNode, HashSet<PrefetchPair>> 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<nn.numNext(); j++) {
- if(nn.getNext(j) == fn) {
- nn.setNext(j, fpn);
+ if(!isFNPresent) {
+ while(fn.numPrev() > 0) {
+ FlatNode nn = fn.getPrev(0);
+ for(int j = 0; j<nn.numNext(); j++) {
+ if(nn.getNext(j) == fn) {
+ nn.setNext(j, fpn);
+ }
}
}
+ fpn.addNext(fn);
}
- fpn.addNext(fn);
- }
- }
- }
+ } //end of else
+ } //End of if
+ } //end of while
}
private void doAnalysis() {
#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 */
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 *);
/* 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;
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);
dstmInit();
transInit();
+
+
if (master) {
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
//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
} 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++) {
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;
/* 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");
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;
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);
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;
}
/* 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]);
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;
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 */
int isArray;
char *ptr, *tmp;
objheader_t *objheader;
- short *endoffsets, *arryfields;
+ unsigned short *endoffsets;
+ short *arryfields;
prefetchpile_t *head = NULL;
ptr = (char *) 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];
}
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]));
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;
* 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 */
/* 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 */
}
}
-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;
}
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;
}
/* 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;
}
while(numbytes < size) {
numbytes += recv((int)sd, recvbuffer+numbytes, size-numbytes, 0);
}
-
+
control = *((char *) recvbuffer);
if(control == OBJECT_FOUND) {
numbytes = 0;
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 {
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;