From: yeom Date: Mon, 3 May 2010 18:52:49 +0000 (+0000) Subject: bring a snapshot before further changes of memory queue(OID and multiple enqueue... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c612e0f70cf8ae2afb21b39ae5a16cc9d90ad35f;p=IRC.git bring a snapshot before further changes of memory queue(OID and multiple enqueue case). --- diff --git a/Robust/src/Analysis/MLP/ConflictGraph.java b/Robust/src/Analysis/MLP/ConflictGraph.java index bb67390d..3903a2cf 100644 --- a/Robust/src/Analysis/MLP/ConflictGraph.java +++ b/Robust/src/Analysis/MLP/ConflictGraph.java @@ -10,30 +10,35 @@ import java.util.Set; import java.util.Map.Entry; import Analysis.OwnershipAnalysis.HeapRegionNode; +import Analysis.OwnershipAnalysis.OwnershipGraph; +import Analysis.OwnershipAnalysis.ReachabilitySet; +import Analysis.OwnershipAnalysis.TokenTuple; import IR.Flat.FlatMethod; import IR.Flat.FlatSESEEnterNode; import IR.Flat.TempDescriptor; public class ConflictGraph { - + static private int uniqueCliqueIDcount = 100; public Hashtable id2cn; + private OwnershipGraph og; - public ConflictGraph() { + public ConflictGraph(OwnershipGraph og) { id2cn = new Hashtable(); + this.og = og; } - - public boolean hasConflictEdge(){ - - Set keySet=id2cn.keySet(); + + public boolean hasConflictEdge() { + + Set keySet = id2cn.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); - ConflictNode node=id2cn.get(key); - if(node.getEdgeSet().size()>0){ + ConflictNode node = id2cn.get(key); + if (node.getEdgeSet().size() > 0) { return true; } - } + } return false; } @@ -49,574 +54,25 @@ public class ConflictGraph { } } - private boolean isWriteConflicts(StallSiteNode nodeA, LiveInNode nodeB) { - - boolean result = false; - StallSite stallSite = nodeA.getStallSite(); - - Set writeEffectsSet = nodeB.getWriteEffectsSet(); - Set readEffectsSet = nodeB.getReadEffectsSet(); - - if (writeEffectsSet != null) { - Iterator writeIter = writeEffectsSet.iterator(); - while (writeIter.hasNext()) { - SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIter - .next(); - String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); - String writeFieldName = seseEffectsKey.getFieldDescriptor(); - - if(writeFieldName.length()>0){ - HashSet stallSiteHRNSet = nodeA.getHRNSet(); - for (Iterator iterator = stallSiteHRNSet.iterator(); iterator - .hasNext();) { - HeapRegionNode stallHRN = (HeapRegionNode) iterator.next(); - if (stallHRN.getGloballyUniqueIdentifier().equals( - writeHeapRegionID)) { - - // check whether there are read or write effects of - // stall sites - - HashSet effectSet = stallSite.getEffectSet(); - for (Iterator iterator2 = effectSet.iterator(); iterator2 - .hasNext();) { - Effect effect = (Effect) iterator2.next(); - String stallEffectfieldName = effect.getField(); - - if (stallEffectfieldName.equals(writeFieldName)) { - result = result | true; - } - } - - } - } - }else{ - // no field name - - HashSet effectSet = stallSite.getEffectSet(); - for (Iterator iterator2 = effectSet.iterator(); iterator2 - .hasNext();) { - Effect effect = (Effect) iterator2.next(); - String stallEffectfieldName = effect.getField(); - - if (stallEffectfieldName.length()==0 && nodeB.getTempDescriptor().equals(nodeA.getStallSite().getTdA())) { - result = result | true; - } - } - - } - - } - - } - - if (readEffectsSet != null) { - Iterator readIter = readEffectsSet.iterator(); - while (readIter.hasNext()) { - - SESEEffectsKey seseEffectsKey = (SESEEffectsKey) readIter - .next(); - String readHeapRegionID = seseEffectsKey.getHRNUniqueId(); - String readFieldName = seseEffectsKey.getFieldDescriptor(); - - if(readFieldName.length()>0){ - HashSet stallSiteHRNSet = nodeA.getHRNSet(); - for (Iterator iterator = stallSiteHRNSet.iterator(); iterator - .hasNext();) { - HeapRegionNode stallHRN = (HeapRegionNode) iterator.next(); - if (stallHRN.getGloballyUniqueIdentifier().equals( - readHeapRegionID)) { - - HashSet effectSet = stallSite.getEffectSet(); - for (Iterator iterator2 = effectSet.iterator(); iterator2 - .hasNext();) { - Effect effect = (Effect) iterator2.next(); - String stallEffectfieldName = effect.getField(); - - if (effect.getEffectType().equals( - StallSite.WRITE_EFFECT)) { - if (stallEffectfieldName.equals(readFieldName)) { - result = result | true; - } - } - - } - - } - - } - }else{ - //no field - HashSet effectSet = stallSite.getEffectSet(); - for (Iterator iterator2 = effectSet.iterator(); iterator2 - .hasNext();) { - Effect effect = (Effect) iterator2.next(); - String stallEffectfieldName = effect.getField(); - - if (effect.getEffectType().equals( - StallSite.WRITE_EFFECT)) { - if (stallEffectfieldName.length()==0 && nodeB.getTempDescriptor().equals(nodeA.getStallSite().getTdA())) { - result = result | true; - } - } - - } - } - - - } - - } - - return result; - } - - private int determineWriteConflictsType(LiveInNode liveInNodeA, - LiveInNode liveInNodeB) { - - if(liveInNodeA.getSESEIdentifier()==liveInNodeB.getSESEIdentifier()){ - return ConflictEdge.NON_WRITE_CONFLICT; - } - - Set liveInHrnSetA = liveInNodeA.getHRNSet(); - Set liveInHrnSetB = liveInNodeB.getHRNSet(); - - boolean isPointingToSameRegion = compareHRNSet(liveInHrnSetA, - liveInHrnSetB); - - boolean isSharingReachability = false; - - Set liveInNodeReachabilitySetA = liveInNodeA.getReachabilitySet(); - Set liveInNodeReachabilitySetB = liveInNodeB.getReachabilitySet(); - - Set overlappedReachableRegionSet = calculateOverlappedReachableRegion( - liveInNodeReachabilitySetA, liveInNodeReachabilitySetB); - if (overlappedReachableRegionSet.size() > 0) { - isSharingReachability = true; - } - - if (isPointingToSameRegion && isSharingReachability) { - // two node share same reachability and points to same region, then - // it is fine grain conflicts - return ConflictEdge.FINE_GRAIN_EDGE; - } else if (isSharingReachability) { - // two node share same reachability but points to different region, - // then it is coarse grain conflicts -// System.out.println("##coarse:"); -// System.out.println(liveInNodeA.getSESEIdentifier()+" <-> "+liveInNodeB.getSESEIdentifier()); -// System.out.println(liveInNodeA.getID()+" <-> "+liveInNodeB.getID()); -// System.out.println("--"); - return ConflictEdge.COARSE_GRAIN_EDGE; - } else { - // otherwise, it is not write conflicts - return ConflictEdge.NON_WRITE_CONFLICT; - } - - } - private boolean compareHRNSet(Set setA, Set setB) { - - for (Iterator iterator = setA.iterator(); iterator.hasNext();) { - HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next(); - String gID = heapRegionNode.getGloballyUniqueIdentifier(); - boolean found = false; - for (Iterator iterator2 = setB.iterator(); iterator2.hasNext();) { - HeapRegionNode heapRegionNode2 = (HeapRegionNode) iterator2 - .next(); - if (heapRegionNode2.getGloballyUniqueIdentifier().equals(gID)) { - found = true; - } - } - if (!found) { - return false; - } - } - return true; - } - - private int determineWriteConflictsType(StallSiteNode stallNode, - LiveInNode liveInNode) { - - Set stallHrnSet = stallNode.getHRNSet(); - Set liveInHrnSet = liveInNode.getHRNSet(); - - boolean isPointingToSameRegion = compareHRNSet(stallHrnSet, - liveInHrnSet); - - boolean isSharingReachability = false; - - Set stallNodeReachabilitySet = stallNode.getReachabilitySet(); - Set liveInNodeReachabilitySet = liveInNode.getReachabilitySet(); - - Set overlappedReachableRegionSet = calculateOverlappedReachableRegion( - stallNodeReachabilitySet, liveInNodeReachabilitySet); - if (overlappedReachableRegionSet.size() > 0) { - isSharingReachability = true; - } - - if (isPointingToSameRegion && isSharingReachability) { - // two node share same reachability and points to same region, then - // it is fine grain conflicts - return ConflictEdge.FINE_GRAIN_EDGE; - } else if (isSharingReachability) { - // two node share same reachability but points to different region, - // then it is coarse grain conflicts - return ConflictEdge.COARSE_GRAIN_EDGE; - } else { - // otherwise, it is not write conflicts - return ConflictEdge.NON_WRITE_CONFLICT; - } - - } - - private boolean hasStrongUpdate(SESEEffectsKey writeEffect, - Set strongUpdateSet) { - - if(strongUpdateSet!=null){ - Iterator strongUpdateIter = strongUpdateSet.iterator(); - while (strongUpdateIter.hasNext()) { - SESEEffectsKey strongEffect = (SESEEffectsKey) strongUpdateIter - .next(); - - if (strongEffect.getHRNUniqueId().equals( - writeEffect.getHRNUniqueId()) - && strongEffect.getFieldDescriptor().equals( - writeEffect.getFieldDescriptor())) { - return true; - } - } - } - - return false; - } - - private boolean isWriteConflicts(LiveInNode nodeA, LiveInNode nodeB) { - - Set readEffectsSetA = nodeA.getReadEffectsSet(); - Set writeEffectsSetA = nodeA.getWriteEffectsSet(); - Set strongUpdateSetA = nodeA.getStrongUpdateSet(); - - Set readEffectsSetB = nodeB.getReadEffectsSet(); - Set writeEffectsSetB = nodeB.getWriteEffectsSet(); - Set strongUpdateSetB = nodeB.getStrongUpdateSet(); - - boolean result=false; - /* - System.out.println("nodeA="+nodeA); - System.out.println("readEffectsSetA="+readEffectsSetA); - System.out.println("writeEffectsSetA="+writeEffectsSetA); - System.out.println("strongUpdateSetA="+strongUpdateSetA); - System.out.println("nodeB="+nodeB); - System.out.println("readEffectsSetB="+readEffectsSetB); - System.out.println("writeEffectsSetB="+writeEffectsSetB); - System.out.println("strongUpdateSetB="+strongUpdateSetB); - System.out.println("--"); - */ - - // if node A has write effects on reading/writing regions of node B - if (writeEffectsSetA != null) { - Iterator writeIterA = writeEffectsSetA.iterator(); - while (writeIterA.hasNext()) { - SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterA - .next(); - -// if (!hasStrongUpdate(seseEffectsKey, strongUpdateSetA)) { - - String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); - String writeFieldName = seseEffectsKey.getFieldDescriptor(); - - if (readEffectsSetB != null) { - - if(writeFieldName.length()>0){ - Iterator readIterB = readEffectsSetB - .iterator(); - while (readIterB.hasNext()) { - SESEEffectsKey readingEffect = (SESEEffectsKey) readIterB - .next(); - - if (readingEffect.getHRNUniqueId().equals( - writeHeapRegionID) - && readingEffect.getFieldDescriptor() - .equals(writeFieldName)) { - result = result | true; - } - } - }else{ - //no field name - Iterator readIterB = readEffectsSetB - .iterator(); - while (readIterB.hasNext()) { - SESEEffectsKey readingEffect = (SESEEffectsKey) readIterB - .next(); - - if (readingEffect.getFieldDescriptor().length()==0 && nodeA.getTempDescriptor().equals(nodeB.getTempDescriptor())) { - result = result | true; - } - } - - } - - } - - if (writeEffectsSetB != null) { - Iterator writeIterB = writeEffectsSetB - .iterator(); - while (writeIterB.hasNext()) { - SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterB - .next(); - - if(writeFieldName.length()>0){ - if (writingEffect.getHRNUniqueId().equals( - writeHeapRegionID) - && writingEffect.getFieldDescriptor() - .equals(writeFieldName)) { - result = result | true; - } - }else{ - //no field - if (writingEffect.getFieldDescriptor().length()==0 && nodeA.getTempDescriptor().equals(nodeB.getTempDescriptor())) { - result = result | true; - } - } - - - } - } - -// } // end of if(hasStrong) - - } - } - - // if node B has write effects on reading regions of node A - if (writeEffectsSetB != null) { - Iterator writeIterB = writeEffectsSetB.iterator(); - while (writeIterB.hasNext()) { - SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterB - .next(); - - //if (!hasStrongUpdate(seseEffectsKey, strongUpdateSetB)) { - - String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); - String writeFieldName = seseEffectsKey.getFieldDescriptor(); - - if (readEffectsSetA != null) { - Iterator readIterA = readEffectsSetA - .iterator(); - while (readIterA.hasNext()) { - SESEEffectsKey readingEffect = (SESEEffectsKey) readIterA - .next(); - - if(writeFieldName.length()>0){ - if (readingEffect.getHRNUniqueId().equals( - writeHeapRegionID) - && readingEffect.getFieldDescriptor() - .equals(writeFieldName)) { - result = result | true; - } - }else{ - if (readingEffect.getFieldDescriptor().length()==0 && nodeA.getTempDescriptor().equals(nodeB.getTempDescriptor())) { - result = result | true; - } - } - - } - } - - if (writeEffectsSetA != null) { - Iterator writeIterA = writeEffectsSetA - .iterator(); - while (writeIterA.hasNext()) { - SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterA - .next(); - - if(writeFieldName.length()>0){ - if (writingEffect.getHRNUniqueId().equals( - writeHeapRegionID) - && writingEffect.getFieldDescriptor() - .equals(writeFieldName)) { - result = result | true; - } - }else{ - if (writingEffect.getFieldDescriptor().length()==0 && nodeA.getTempDescriptor().equals(nodeB.getTempDescriptor())) { - result = result | true; - } - } - - } - } - //} // if(hasStrong) - - } - } - return result; - } - - private boolean isSelfConflicted(LiveInNode liveInNode) { - - int strongUpdateCount = 0; - - if (liveInNode.getWriteEffectsSet() != null - && liveInNode.getWriteEffectsSet().size() > 0) { - - Set strongUpdateSet = liveInNode - .getStrongUpdateSet(); - - Iterator writeIter = liveInNode - .getWriteEffectsSet().iterator(); - while (writeIter.hasNext()) { - SESEEffectsKey writeEffect = (SESEEffectsKey) writeIter.next(); - if (hasStrongUpdate(writeEffect, strongUpdateSet)) { - strongUpdateCount++; - } - - if(writeEffect.isStrong()){ - return false; - } - } - - - if (liveInNode.getWriteEffectsSet().size() == strongUpdateCount) { - return false; - }else{ - return true; - } - - } - - return false; - } - - private boolean isSCC(LiveInNode liveInNode){ - - Set liveInHrnSet = liveInNode.getHRNSet(); -// for (Iterator iterator = liveInHrnSet.iterator(); iterator.hasNext();) { -// HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next(); -// System.out.println("hrn="+heapRegionNode.getGloballyUniqueIdentifier()); -// } - - Set liveInNodeReachabilitySet = liveInNode.getReachabilitySet(); - Set overlappedReachableRegionSet = calculateOverlappedReachableRegion(liveInNodeReachabilitySet,liveInNodeReachabilitySet); - - if(liveInHrnSet.size()>1){ - if(overlappedReachableRegionSet.size()>0){ - return true; - } - } - - return false; - } - - public void analyzePossibleConflicts(Set analyzedIDSet, - ConflictNode currentNode) { - - // compare with all nodes - - // examine the case where self-edge exists - if (currentNode instanceof LiveInNode) { - LiveInNode liveInNode = (LiveInNode) currentNode; -// if (liveInNode.getWriteEffectsSet() != null -// && liveInNode.getWriteEffectsSet().size() > 0) { -// addConflictEdge(ConflictEdge.FINE_GRAIN_EDGE, currentNode, -// currentNode); -// } - if(isSCC(liveInNode)){ - addConflictEdge(ConflictEdge.COARSE_GRAIN_EDGE, currentNode, - currentNode); - }else if(isSelfConflicted(liveInNode)){ - addConflictEdge(ConflictEdge.FINE_GRAIN_EDGE, currentNode, - currentNode); - } - - } - - Set> set = id2cn.entrySet(); - for (Iterator iterator = set.iterator(); iterator.hasNext();) { - Entry entry = (Entry) iterator - .next(); - - String entryNodeID = entry.getKey(); - ConflictNode entryNode = entry.getValue(); - - if ((!currentNode.getID().equals(entryNodeID)) - && !(analyzedIDSet.contains(currentNode.getID() - + entryNodeID) || analyzedIDSet - .contains(entryNodeID + currentNode.getID()))) { - - if (currentNode instanceof StallSiteNode - && entryNode instanceof LiveInNode) { - if (isWriteConflicts((StallSiteNode) currentNode, - (LiveInNode) entryNode)) { - int conflictType = determineWriteConflictsType( - (StallSiteNode) currentNode, - (LiveInNode) entryNode); - if (conflictType > 0) { - addConflictEdge(conflictType, currentNode, - entryNode); - } - } - analyzedIDSet.add(currentNode.getID() + entryNodeID); - - } else if (currentNode instanceof LiveInNode - && entryNode instanceof LiveInNode) { - if (isWriteConflicts((LiveInNode) currentNode, - (LiveInNode) entryNode)) { - - int conflictType = determineWriteConflictsType( - (LiveInNode) currentNode, - (LiveInNode) entryNode); - if (conflictType > 0) { - addConflictEdge(conflictType, currentNode, - entryNode); - } - } - analyzedIDSet.add(currentNode.getID() + entryNodeID); - } - - } - - } - - } - - public boolean containsTokenTuple(Set overlapSet, - String uniqueID) { - - for (Iterator iterator = overlapSet.iterator(); iterator.hasNext();) { - GloballyUniqueTokenTuple globallyUniqueTokenTuple = (GloballyUniqueTokenTuple) iterator - .next(); - if (globallyUniqueTokenTuple.getID().equals(uniqueID)) { - return true; - } - } - - return false; - - } - - private Set calculateOverlappedReachableRegion( - Set setA, Set setB) { - - Set returnSet = new HashSet(); - - for (Iterator iterator2 = setA.iterator(); iterator2.hasNext();) { - Set tokenTupleSetA = (Set) iterator2.next(); - - for (Iterator iterator3 = setB.iterator(); iterator3.hasNext();) { - Set tokenTupleSetB = (Set) iterator3.next(); - - if (tokenTupleSetA.equals(tokenTupleSetB)) { - // reachability states are overlapped - Iterator ttsIter = tokenTupleSetA.iterator(); - while (ttsIter.hasNext()) { - GloballyUniqueTokenTuple tt = (GloballyUniqueTokenTuple) ttsIter - .next(); - returnSet.add(tt); - } + + for (Iterator iterator = setA.iterator(); iterator.hasNext();) { + HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next(); + String gID = heapRegionNode.getGloballyUniqueIdentifier(); + boolean found = false; + for (Iterator iterator2 = setB.iterator(); iterator2.hasNext();) { + HeapRegionNode heapRegionNode2 = (HeapRegionNode) iterator2 + .next(); + if (heapRegionNode2.getGloballyUniqueIdentifier().equals(gID)) { + found = true; } } + if (!found) { + return false; + } } - return returnSet; + return true; } public String addStallNode(TempDescriptor td, FlatMethod fm, @@ -661,60 +117,47 @@ public class ConflictGraph { public void addConflictEdge(int type, ConflictNode nodeU, ConflictNode nodeV) { - // if there are two edges between the same node pair, coarse has a priority - HashSet set=nodeU.getEdgeSet(); - ConflictEdge toBeRemoved=null; + // if there are two edges between the same node pair, coarse has a + // priority + HashSet set = nodeU.getEdgeSet(); + ConflictEdge toBeRemoved = null; for (Iterator iterator = set.iterator(); iterator.hasNext();) { ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); - - if((conflictEdge.getVertexU().equals(nodeU) && conflictEdge.getVertexV().equals(nodeV)) || - (conflictEdge.getVertexU().equals(nodeV) && conflictEdge.getVertexV().equals(nodeU)) - ){ - if(conflictEdge.getType()==ConflictEdge.FINE_GRAIN_EDGE && type==ConflictEdge.COARSE_GRAIN_EDGE){ - toBeRemoved=conflictEdge; + + if ((conflictEdge.getVertexU().equals(nodeU) && conflictEdge + .getVertexV().equals(nodeV)) + || (conflictEdge.getVertexU().equals(nodeV) && conflictEdge + .getVertexV().equals(nodeU))) { + if (conflictEdge.getType() == ConflictEdge.FINE_GRAIN_EDGE + && type == ConflictEdge.COARSE_GRAIN_EDGE) { + toBeRemoved = conflictEdge; break; - }else if(conflictEdge.getType()==ConflictEdge.COARSE_GRAIN_EDGE && type==ConflictEdge.FINE_GRAIN_EDGE){ - //ignore + } else if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE + && type == ConflictEdge.FINE_GRAIN_EDGE) { + // ignore return; } } } - - if(toBeRemoved!=null){ + + if (toBeRemoved != null) { nodeU.getEdgeSet().remove(toBeRemoved); nodeV.getEdgeSet().remove(toBeRemoved); } - - + ConflictEdge newEdge = new ConflictEdge(nodeU, nodeV, type); nodeU.addEdge(newEdge); nodeV.addEdge(newEdge); } - public HashSet getLiveInNodeSet() { - HashSet resultSet = new HashSet(); - - Set keySet = id2cn.keySet(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - String key = (String) iterator.next(); - ConflictNode node = id2cn.get(key); - - if (node instanceof LiveInNode) { - resultSet.add((LiveInNode) node); - } - } - - return resultSet; - } - public Set getStallSiteWaitingElementSet( ParentChildConflictsMap conflictsMap, HashSet seseLockSet) { HashSet waitingElementSet = new HashSet(); Set> s = id2cn.entrySet(); Collection stallSites = conflictsMap.getStallMap().values(); - + for (Iterator iterator = stallSites.iterator(); iterator.hasNext();) { StallSite stallSite = (StallSite) iterator.next(); @@ -733,20 +176,26 @@ public class ConflictGraph { ConflictEdge conflictEdge = (ConflictEdge) iter2 .next(); - for (Iterator seseLockIter = seseLockSet - .iterator(); seseLockIter.hasNext();) { - SESELock seseLock = seseLockIter.next(); - if (seseLock.containsConflictNode(stallSiteNode) && seseLock.containsConflictEdge(conflictEdge)) { - WaitingElement newElement = new WaitingElement(); - newElement.setWaitingID(seseLock - .getID()); - if(isFineElement(newElement.getStatus())){ - newElement.setDynID(node.getTempDescriptor().toString()); - } - newElement.setStatus(seseLock.getNodeType(stallSiteNode)); - waitingElementSet.add(newElement); + for (Iterator seseLockIter = seseLockSet + .iterator(); seseLockIter.hasNext();) { + SESELock seseLock = seseLockIter.next(); + if (seseLock + .containsConflictNode(stallSiteNode) + && seseLock + .containsConflictEdge(conflictEdge)) { + WaitingElement newElement = new WaitingElement(); + newElement.setWaitingID(seseLock.getID()); + if (isFineElement(newElement.getStatus())) { + newElement + .setDynID(node + .getTempDescriptor() + .toString()); } + newElement.setStatus(seseLock + .getNodeType(stallSiteNode)); + waitingElementSet.add(newElement); } + } } } } @@ -757,58 +206,6 @@ public class ConflictGraph { return waitingElementSet; } - public Set getConnectedConflictNodeSet( - ParentChildConflictsMap conflictsMap) { - - HashSet nodeIDSet = new HashSet(); - - Set> s = id2cn.entrySet(); - - Collection stallSites = conflictsMap.getStallMap().values(); - for (Iterator iterator = stallSites.iterator(); iterator.hasNext();) { - StallSite stallSite = (StallSite) iterator.next(); - Iterator> i = s.iterator(); - while (i.hasNext()) { - Entry entry = i.next(); - ConflictNode node = entry.getValue(); - - if (node instanceof StallSiteNode) { - StallSiteNode stallSiteNode = (StallSiteNode) node; - if (stallSiteNode.getStallSite().equals(stallSite)) { - HashSet edgeSet = stallSiteNode - .getEdgeSet(); - for (Iterator iter2 = edgeSet.iterator(); iter2 - .hasNext();) { - ConflictEdge conflictEdge = (ConflictEdge) iter2 - .next(); - nodeIDSet - .addAll(getConnectedConflictNode(conflictEdge)); - } - } - } - } - } - - return nodeIDSet; - - } - - private Set getConnectedConflictNode(ConflictEdge conflictEdge) { - - HashSet nodeIDSet = new HashSet(); - - if (conflictEdge.getVertexU() instanceof LiveInNode) { - LiveInNode lin = (LiveInNode) conflictEdge.getVertexU(); - nodeIDSet.add(new Integer(lin.getSESEIdentifier())); - } - if (conflictEdge.getVertexV() instanceof LiveInNode) { - LiveInNode lin = (LiveInNode) conflictEdge.getVertexV(); - nodeIDSet.add(new Integer(lin.getSESEIdentifier())); - } - - return nodeIDSet; - } - private Set getConnectedConflictNode(ConflictEdge conflictEdge, int seseID) { @@ -901,21 +298,24 @@ public class ConflictGraph { .next(); for (Iterator seseLockIter = seseLockSet - .iterator(); seseLockIter.hasNext();) { - SESELock seseLock = seseLockIter.next(); - if (seseLock.containsConflictNode(liveInNode) && seseLock.containsConflictEdge(conflictEdge)) { - WaitingElement newElement = new WaitingElement(); - newElement.setWaitingID(seseLock.getID()); - newElement.setStatus(seseLock.getNodeType(liveInNode)); - if(isFineElement(newElement.getStatus())){ - // for fine waiting element, set temp descriptor to handle unresolved pointer case. - newElement.setDynID(node.getTempDescriptor().toString()); - newElement.setTempDesc(node.getTempDescriptor()); - } - if(!waitingElementSet.contains(newElement)){ - waitingElementSet.add(newElement); - } - + .iterator(); seseLockIter.hasNext();) { + SESELock seseLock = seseLockIter.next(); + if (seseLock.containsConflictNode(liveInNode) + && seseLock + .containsConflictEdge(conflictEdge)) { + WaitingElement newElement = new WaitingElement(); + newElement.setWaitingID(seseLock.getID()); + newElement.setStatus(seseLock + .getNodeType(liveInNode)); + if (isFineElement(newElement.getStatus())) { + newElement.setDynID(node + .getTempDescriptor().toString()); + newElement.setTempDesc(node.getTempDescriptor()); + } + if (!waitingElementSet.contains(newElement)) { + waitingElementSet.add(newElement); + } + } } } @@ -927,7 +327,7 @@ public class ConflictGraph { return waitingElementSet; } - + public boolean isFineElement(int type) { if (type == ConflictNode.FINE_READ || type == ConflictNode.FINE_WRITE || type == ConflictNode.PARENT_READ @@ -938,253 +338,728 @@ public class ConflictGraph { } } - public Set getAllocationSiteIDSetBySESEID(int seseID) { - // deprecated - HashSet allocSiteIDSet = new HashSet(); + public HashSet getEdgeSet() { + + HashSet returnSet = new HashSet(); + + Collection nodes = id2cn.values(); + for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { + ConflictNode conflictNode = (ConflictNode) iterator.next(); + returnSet.addAll(conflictNode.getEdgeSet()); + } + + return returnSet; + } + + public void writeGraph(String graphName, boolean filter) + throws java.io.IOException { + + graphName = graphName.replaceAll("[\\W]", ""); + + BufferedWriter bw = new BufferedWriter(new FileWriter(graphName + + ".dot")); + bw.write("graph " + graphName + " {\n"); + HashSet visited = new HashSet(); + // then visit every heap region node Set> s = id2cn.entrySet(); Iterator> i = s.iterator(); + HashSet addedSet = new HashSet(); + while (i.hasNext()) { Entry entry = i.next(); ConflictNode node = entry.getValue(); - if (node instanceof LiveInNode) { - LiveInNode liveInNode = (LiveInNode) node; - if (liveInNode.getSESEIdentifier() == seseID) { - HashSet edgeSet = liveInNode.getEdgeSet(); - for (Iterator iterator = edgeSet.iterator(); iterator - .hasNext();) { - ConflictEdge conflictEdge = (ConflictEdge) iterator + if (filter) { + if (node.getID().startsWith("___dst") + || node.getID().startsWith("___srctmp") + || node.getID().startsWith("___neverused") + || node.getID().startsWith("___temp")) { + + continue; + } + } + + String attributes = "["; + + attributes += "label=\"ID" + node.getID() + "\\n"; + + if (node instanceof StallSiteNode) { + attributes += "STALL SITE" + "\\n" + "\"]"; + } else { + attributes += "LIVE-IN" + "\\n" + "\"]"; + } + bw.write(entry.getKey() + attributes + ";\n"); + + HashSet edgeSet = node.getEdgeSet(); + for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { + ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); + + ConflictNode u = conflictEdge.getVertexU(); + ConflictNode v = conflictEdge.getVertexV(); + + if (filter) { + String uID = u.getID(); + String vID = v.getID(); + if (uID.startsWith("___dst") || uID.startsWith("___srctmp") + || uID.startsWith("___neverused") + || uID.startsWith("___temp") + || vID.startsWith("___dst") + || vID.startsWith("___srctmp") + || vID.startsWith("___neverused") + || vID.startsWith("___temp")) { + continue; + } + } + + if (!addedSet.contains(conflictEdge)) { + bw.write(" " + u.getID() + "--" + v.getID() + "[label=" + + conflictEdge.toGraphEdgeString() + + ",decorate];\n"); + addedSet.add(conflictEdge); + } + + } + } + + bw.write(" graphTitle[label=\"" + graphName + "\",shape=box];\n"); + + bw.write("}\n"); + bw.close(); + + } + + private int calculateConflictType(StallSiteNode nodeA, LiveInNode nodeB) { + + StallSite stallSite = nodeA.getStallSite(); + Set writeEffectsSet = nodeB.getWriteEffectsSet(); + Set readEffectsSet = nodeB.getReadEffectsSet(); + + int conflictType = 0; + + if (writeEffectsSet != null) { + Iterator writeIter = writeEffectsSet.iterator(); + while (writeIter.hasNext()) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIter + .next(); + String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); + String writeFieldName = seseEffectsKey.getFieldDescriptor(); + + HashSet stallSiteHRNSet = nodeA.getHRNSet(); + for (Iterator iterator = stallSiteHRNSet.iterator(); iterator + .hasNext();) { + HeapRegionNode stallHRN = (HeapRegionNode) iterator.next(); + if (stallHRN.getGloballyUniqueIdentifier().equals( + writeHeapRegionID)) { + // check whether there are read or write effects of + // stall sites + HashSet effectSet = stallSite.getEffectSet(); + for (Iterator iterator2 = effectSet.iterator(); iterator2 + .hasNext();) { + Effect effect = (Effect) iterator2.next(); + String stallEffectfieldName = effect.getField(); + + if (stallEffectfieldName.equals(writeFieldName)) { + int newType = determineConflictType(nodeA, + effect, nodeB, seseEffectsKey); + if (newType > conflictType) { + // coarse-grain conflict overrides + // fine-grain conflict + conflictType = newType; + } + } + } + } + } + + } + } + + if (readEffectsSet != null) { + Iterator readIter = readEffectsSet.iterator(); + while (readIter.hasNext()) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) readIter + .next(); + String readHeapRegionID = seseEffectsKey.getHRNUniqueId(); + String readFieldName = seseEffectsKey.getFieldDescriptor(); + + HashSet stallSiteHRNSet = nodeA.getHRNSet(); + for (Iterator iterator = stallSiteHRNSet.iterator(); iterator + .hasNext();) { + HeapRegionNode stallHRN = (HeapRegionNode) iterator.next(); + if (stallHRN.getGloballyUniqueIdentifier().equals( + readHeapRegionID)) { + + HashSet effectSet = stallSite.getEffectSet(); + for (Iterator iterator2 = effectSet.iterator(); iterator2 + .hasNext();) { + Effect effect = (Effect) iterator2.next(); + String stallEffectfieldName = effect.getField(); + + if (effect.getEffectType().equals( + StallSite.WRITE_EFFECT)) { + if (stallEffectfieldName.equals(readFieldName)) { + int newType = determineConflictType(nodeA, + effect, nodeB, seseEffectsKey); + if (newType > conflictType) { + // coarse-grain conflict overrides + // fine-grain conflict + conflictType = newType; + } + } + } + } + } + } + } + } +//System.out.println("%%%%%%%%%%%%%% RETURN conflictType="+conflictType); + return conflictType; + } + + private int calculateConflictType(LiveInNode nodeA, LiveInNode nodeB) { + + Set readEffectsSetA = nodeA.getReadEffectsSet(); + Set writeEffectsSetA = nodeA.getWriteEffectsSet(); + Set strongUpdateSetA = nodeA.getStrongUpdateSet(); + + Set readEffectsSetB = nodeB.getReadEffectsSet(); + Set writeEffectsSetB = nodeB.getWriteEffectsSet(); + Set strongUpdateSetB = nodeB.getStrongUpdateSet(); + + int conflictType = 0; + + // if node A has write effects on reading/writing regions of node B + if (writeEffectsSetA != null) { + Iterator writeIterA = writeEffectsSetA.iterator(); + while (writeIterA.hasNext()) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterA + .next(); + String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); + String writeFieldName = seseEffectsKey.getFieldDescriptor(); + + if (readEffectsSetB != null) { + + Iterator readIterB = readEffectsSetB + .iterator(); + while (readIterB.hasNext()) { + SESEEffectsKey readingEffect = (SESEEffectsKey) readIterB .next(); - // - getConnectedConflictNode(conflictEdge, seseID); - // - if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) { - allocSiteIDSet - .addAll(getHRNIdentifierSet(conflictEdge - .getVertexU())); - allocSiteIDSet - .addAll(getHRNIdentifierSet(conflictEdge - .getVertexV())); - } else {// it is fine-grain edge - allocSiteIDSet.addAll(getHRNIdentifierSet(node)); + + if (readingEffect.getHRNUniqueId().equals( + writeHeapRegionID) + && readingEffect.getFieldDescriptor().equals( + writeFieldName)) { + int newType = determineConflictType(nodeA, + seseEffectsKey, nodeB, readingEffect); + if (newType > conflictType) { + // coarse-grain conflict overrides fine-grain + // conflict + conflictType = newType; + } } } } - } - } - return allocSiteIDSet; + if (writeEffectsSetB != null) { + Iterator writeIterB = writeEffectsSetB + .iterator(); + while (writeIterB.hasNext()) { + SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterB + .next(); - } + if (writingEffect.getHRNUniqueId().equals( + writeHeapRegionID) + && writingEffect.getFieldDescriptor().equals( + writeFieldName)) { + int newType = determineConflictType(nodeA, + seseEffectsKey, nodeB, writingEffect); + if (newType > conflictType) { + // coarse-grain conflict overrides fine-grain + // conflict + conflictType = newType; + } + } - public Set getAllocationSiteIDSetofStallSite() { + } + } - HashSet allocSiteIDSet = new HashSet(); + } + } - Set> s = id2cn.entrySet(); - Iterator> i = s.iterator(); + // if node B has write effects on reading regions of node A + if (writeEffectsSetB != null) { + Iterator writeIterB = writeEffectsSetB.iterator(); + while (writeIterB.hasNext()) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterB + .next(); - while (i.hasNext()) { + // if (!hasStrongUpdate(seseEffectsKey, strongUpdateSetB)) { - Entry entry = i.next(); - ConflictNode node = entry.getValue(); + String writeHeapRegionID = seseEffectsKey.getHRNUniqueId(); + String writeFieldName = seseEffectsKey.getFieldDescriptor(); - if (node instanceof StallSiteNode) { - allocSiteIDSet.addAll(getHRNIdentifierSet(node)); - } + if (readEffectsSetA != null) { + Iterator readIterA = readEffectsSetA + .iterator(); + while (readIterA.hasNext()) { + SESEEffectsKey readingEffect = (SESEEffectsKey) readIterA + .next(); - } + if (readingEffect.getHRNUniqueId().equals( + writeHeapRegionID) + && readingEffect.getFieldDescriptor().equals( + writeFieldName)) { + int newType = determineConflictType(nodeA, + readingEffect, nodeB, seseEffectsKey); + if (newType > conflictType) { + // coarse-grain conflict overrides fine-grain + // conflict + conflictType = newType; + } + } - return allocSiteIDSet; + } + } - } + if (writeEffectsSetA != null) { + Iterator writeIterA = writeEffectsSetA + .iterator(); + while (writeIterA.hasNext()) { + SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterA + .next(); - public Set getAllocationSiteIDSet() { + if (writingEffect.getHRNUniqueId().equals( + writeHeapRegionID) + && writingEffect.getFieldDescriptor().equals( + writeFieldName)) { + int newType = determineConflictType(nodeA, + writingEffect, nodeB, seseEffectsKey); + if (newType > conflictType) { + // coarse-grain conflict overrides fine-grain + // conflict + conflictType = newType; + } + } - HashSet allocSiteIDSet = new HashSet(); + } + } - Set> s = id2cn.entrySet(); - Iterator> i = s.iterator(); + } + } + return conflictType; + } - while (i.hasNext()) { - Entry entry = i.next(); - ConflictNode node = entry.getValue(); + private Set getSameHeapRoot(Set setA, + Set setB) { - HashSet edgeSet = node.getEdgeSet(); - for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { - ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); - if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) { - allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge - .getVertexU())); - allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge - .getVertexV())); - } else {// it is fine-grain edge - allocSiteIDSet.addAll(getHRNIdentifierSet(node)); + Set retSet = new HashSet(); + + if (compareHRNSet(setA, setB)) { + for (Iterator iterator = setA.iterator(); iterator.hasNext();) { + HeapRegionNode heapRegionNode = (HeapRegionNode) iterator + .next(); + String gID = heapRegionNode.getGloballyUniqueIdentifier(); + boolean found = false; + for (Iterator iterator2 = setB.iterator(); iterator2.hasNext();) { + HeapRegionNode heapRegionNode2 = (HeapRegionNode) iterator2 + .next(); + if (heapRegionNode2.getGloballyUniqueIdentifier().equals( + gID)) { + retSet.add(heapRegionNode2); + } } } - } - return allocSiteIDSet; + return retSet; } + + private boolean isReachableFrom(HeapRegionNode root1, HeapRegionNode root2, + ReachabilitySet rset) { + + boolean reachable=false; + + TokenTuple h1 = new TokenTuple(root1.getID(), !root1.isSingleObject(), + TokenTuple.ARITY_ONE).makeCanonical(); + + TokenTuple h1plus = new TokenTuple(root1.getID(), !root1 + .isSingleObject(), TokenTuple.ARITY_ONEORMORE).makeCanonical(); + + TokenTuple h1star = new TokenTuple(root1.getID(), !root1 + .isSingleObject(), TokenTuple.ARITY_ZEROORMORE).makeCanonical(); + + TokenTuple h2 = new TokenTuple(root2.getID(), !root2.isSingleObject(), + TokenTuple.ARITY_ONE).makeCanonical(); + + TokenTuple h2plus = new TokenTuple(root2.getID(), !root2 + .isSingleObject(), TokenTuple.ARITY_ONEORMORE).makeCanonical(); + + TokenTuple h2star = new TokenTuple(root2.getID(), !root2 + .isSingleObject(), TokenTuple.ARITY_ZEROORMORE).makeCanonical(); + + // only do this one if they are different tokens + if( h1 != h2 && + rset.containsTupleSetWithBoth(h1, h2) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1plus, h2) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1star, h2) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1, h2plus) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1plus, h2plus) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1star, h2plus) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1, h2star) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1plus, h2star) ) { + reachable = true; + } + if( rset.containsTupleSetWithBoth(h1star, h2star) ) { + reachable = true; + } + + return reachable; - private HashSet getAllocSet(ConflictNode node) { - - HashSet returnSet = new HashSet(); - - if (node instanceof StallSiteNode) { - StallSiteNode stallSiteNode = (StallSiteNode) node; - Set hrnSet = stallSiteNode.getHRNSet(); - for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { - HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); - if (hrn.getAllocationSite() != null) { - returnSet.add(new Integer(hrn.getAllocationSite().getID())); + } + + private int determineConflictType(StallSiteNode stallSiteNodeA, + Effect effect, LiveInNode liveInNodeB, + SESEEffectsKey effectB) { + + Set liveInHrnSetA = stallSiteNodeA.getStallSite().getHRNSet(); + Set liveInHrnSetB = liveInNodeB.getHRNSet(); + + // check whether alloc site is reached from both heap roots + boolean isDisjoint=true; + HeapRegionNode effectHrn=og.gid2hrn.get(effectB.getHRNUniqueId()); + if(effectHrn.isSingleObject()){ + for (Iterator iterator = liveInHrnSetA.iterator(); iterator.hasNext();) { + HeapRegionNode r1 = (HeapRegionNode) iterator.next(); + for (Iterator iterator2 = liveInHrnSetB.iterator(); iterator2.hasNext();) { + HeapRegionNode r2 = (HeapRegionNode) iterator2.next(); + r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier()); + r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier()); + if(isReachableFrom(r1,r2,effectB.getRSet())){ + isDisjoint=false; + } } } - } else { - LiveInNode liveInNode = (LiveInNode) node; - Set hrnSet = liveInNode.getHRNSet(); - for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { - HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); - if (hrn.getAllocationSite() != null) { - returnSet.add(new Integer(hrn.getAllocationSite().getID())); - }else{ - returnSet.add(new Integer(hrn.getID())); - } + if(isDisjoint){ + return ConflictEdge.NON_WRITE_CONFLICT; } } + + /* + HeapRegionNode r1=liveInHrnSetA.iterator().next(); + HeapRegionNode r2=liveInHrnSetB.iterator().next(); + + r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier()); + r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier()); + + System.out.println("r1="+r1); + System.out.println("r2="+r2); + System.out.println("effectB="+effectB.getRSet()); + System.out.println("###STALL calculateConflictType2"); + if(!isReachableFrom(r1,r2,effectB.getRSet())){ + System.out.println("###STALL calculateConflictType3"); + return ConflictEdge.NON_WRITE_CONFLICT; + } + */ + Set entryHRNSet = getSameHeapRoot(liveInHrnSetA, + liveInHrnSetB); + if (entryHRNSet.size() == 0) { + return ConflictEdge.COARSE_GRAIN_EDGE; + } - return returnSet; - } - - private HashSet getHRNIdentifierSet(ConflictNode node) { + for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - HashSet returnSet = new HashSet(); + String entryIdentifier = hrn.getGloballyUniqueIdentifier(); + HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier); - if (node instanceof StallSiteNode) { - StallSiteNode stallSiteNode = (StallSiteNode) node; - Set hrnSet = stallSiteNode.getHRNSet(); - for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { - HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); - returnSet - .add(new Long(hrn.getGloballyUniqueIntegerIdentifier())); - } - } else { - LiveInNode liveInNode = (LiveInNode) node; - Set hrnSet = liveInNode.getHRNSet(); - for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) { - HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier()); - returnSet - .add(new Long(hrn.getGloballyUniqueIntegerIdentifier())); + TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN + .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical(); + + TokenTuple h1star = new TokenTuple(entryHRN.getID(), true, + TokenTuple.ARITY_ONEORMORE).makeCanonical(); + + if (effectB.getRSet().containsTuple(h1star)) { + return ConflictEdge.COARSE_GRAIN_EDGE; + }else if (effectB.getRSet().containsTuple(h1)) { + // rechability states contain heap root with arity 1 + return ConflictEdge.FINE_GRAIN_EDGE; } } - - return returnSet; - + return ConflictEdge.NON_WRITE_CONFLICT; } - public HashSet getEdgeSet() { + private int determineConflictType(LiveInNode liveInNodeA, + SESEEffectsKey effectA, LiveInNode liveInNodeB, + SESEEffectsKey effectB) { - HashSet returnSet = new HashSet(); + if (liveInNodeA.getSESEIdentifier() == liveInNodeB.getSESEIdentifier()) { + return ConflictEdge.NON_WRITE_CONFLICT; + } - Collection nodes = id2cn.values(); - for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { - ConflictNode conflictNode = (ConflictNode) iterator.next(); - returnSet.addAll(conflictNode.getEdgeSet()); + Set liveInHrnSetA = liveInNodeA.getHRNSet(); + Set liveInHrnSetB = liveInNodeB.getHRNSet(); + + // check whether alloc site is reached from both heap roots + boolean isDisjoint=true; + HeapRegionNode effectHrn=og.gid2hrn.get(effectB.getHRNUniqueId()); + if(effectHrn.isSingleObject()){ + for (Iterator iterator = liveInHrnSetA.iterator(); iterator.hasNext();) { + HeapRegionNode r1 = (HeapRegionNode) iterator.next(); + for (Iterator iterator2 = liveInHrnSetB.iterator(); iterator2.hasNext();) { + HeapRegionNode r2 = (HeapRegionNode) iterator2.next(); + r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier()); + r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier()); + + if(isReachableFrom(r1,r2,effectB.getRSet())){ + isDisjoint=false; + }else{ + } + } + } + if(isDisjoint){ + return ConflictEdge.NON_WRITE_CONFLICT; + } + } + + /* + HeapRegionNode r1=liveInHrnSetA.iterator().next(); + HeapRegionNode r2=liveInHrnSetB.iterator().next(); + +// r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier()); +// r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier()); + System.out.println("@@r1="+r1); + System.out.println("@@r2="+r2); + System.out.println("@@effectB="+effectA.getRSet()); + + if(!isReachableFrom(r1,r2,effectA.getRSet())){ + // two heap root are disjoint + return ConflictEdge.NON_WRITE_CONFLICT; + } + */ + + Set entryHRNSet = getSameHeapRoot(liveInHrnSetA, + liveInHrnSetB); + if (entryHRNSet.size() == 0) { + return ConflictEdge.COARSE_GRAIN_EDGE; } - return returnSet; - } + int count=0; + for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); + if(hrn.getType()!=null && hrn.getType().isImmutable()){ + count++; + } + } + if(count==entryHRNSet.size()){ + return ConflictEdge.FINE_GRAIN_EDGE; + } + + for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) { + HeapRegionNode hrn = (HeapRegionNode) iterator.next(); - static public int generateUniqueCliqueID() { - ++uniqueCliqueIDcount; - return uniqueCliqueIDcount; - } + String entryIdentifier = hrn.getGloballyUniqueIdentifier(); + HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier); - public void writeGraph(String graphName, boolean filter) - throws java.io.IOException { + TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN + .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical(); - graphName = graphName.replaceAll("[\\W]", ""); + TokenTuple h1star = new TokenTuple(entryHRN.getID(), true, + TokenTuple.ARITY_ONEORMORE).makeCanonical(); - BufferedWriter bw = new BufferedWriter(new FileWriter(graphName - + ".dot")); - bw.write("graph " + graphName + " {\n"); + if (effectA.getRSet().containsTuple(h1star)) { + return ConflictEdge.COARSE_GRAIN_EDGE; + } else if (effectA.getRSet().containsTuple(h1)) { + // rechability states contain heap root with arity 1 + return ConflictEdge.FINE_GRAIN_EDGE; + } - HashSet visited = new HashSet(); - // then visit every heap region node - Set> s = id2cn.entrySet(); - Iterator> i = s.iterator(); + } - HashSet addedSet = new HashSet(); + return ConflictEdge.NON_WRITE_CONFLICT; - while (i.hasNext()) { - Entry entry = i.next(); - ConflictNode node = entry.getValue(); + } + + private int calculateSelfConflictType(LiveInNode liveInNode) { + + // if strong update effect exists, it conflicts every effects of objects that are reachable from same heap root + Set strongUpdateSet = liveInNode.getStrongUpdateSet(); + if(strongUpdateSet!=null && strongUpdateSet.size()>0){ + return ConflictEdge.FINE_GRAIN_EDGE; + } + + if (liveInNode.getWriteEffectsSet() != null + && liveInNode.getWriteEffectsSet().size() > 0) { + + Set writeEffectsSet=liveInNode.getWriteEffectsSet(); + + int immuntableCount = 0; + for (Iterator iterator = liveInNode.getHRNSet() + .iterator(); iterator.hasNext();) { + HeapRegionNode root = iterator.next(); + if(root.getType()!=null && root.getType().isImmutable()){ + immuntableCount++; + } + } + if (immuntableCount == liveInNode.getHRNSet().size()) { + // in this case, heap root is a parameter heap region + return ConflictEdge.FINE_GRAIN_EDGE; + } + + + int paramCount = 0; + for (Iterator iterator = liveInNode.getHRNSet() + .iterator(); iterator.hasNext();) { + HeapRegionNode root = iterator.next(); + if (root.isParameter()) { + paramCount++; + } + } - if (filter) { - if (node.getID().startsWith("___dst") - || node.getID().startsWith("___srctmp") - || node.getID().startsWith("___neverused") - || node.getID().startsWith("___temp")) { + if (paramCount == liveInNode.getHRNSet().size()) { + // in this case, heap root is a parameter heap region + return ConflictEdge.FINE_GRAIN_EDGE; + } - continue; + if (liveInNode.getHRNSet().size()==1) { + HeapRegionNode hrn = liveInNode.getHRNSet().iterator().next(); + String entryIdentifier = hrn.getGloballyUniqueIdentifier(); + HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier); + + boolean containsStar=false; + for (Iterator iterator = writeEffectsSet.iterator(); iterator + .hasNext();) { + SESEEffectsKey effect = (SESEEffectsKey) iterator.next(); + TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN + .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical(); + TokenTuple h1star = new TokenTuple(entryHRN.getID(), true, TokenTuple.ARITY_ZEROORMORE).makeCanonical(); + if (effect.getRSet().containsTuple(h1star)) { + // rechability states contain heap root with arity star + containsStar=true; + } + } + if(containsStar){ + return ConflictEdge.COARSE_GRAIN_EDGE; + }else{ + return ConflictEdge.FINE_GRAIN_EDGE; + } + }else{ + return ConflictEdge.COARSE_GRAIN_EDGE; + } + + + /* + boolean containsAllTuple=true; + for (Iterator iterator2 = writeEffectsSet.iterator(); iterator2 + .hasNext();) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2 + .next(); + ReachabilitySet rset = seseEffectsKey.getRSet(); + Iterator tsetIter=rset.iterator(); + int countNotContained=0; + while (tsetIter.hasNext()) { + TokenTupleSet tokenTupleSet = (TokenTupleSet) tsetIter + .next(); + boolean found=true; + for (Iterator iterator = rootIDSet.iterator(); iterator + .hasNext();) { + Integer rootID = (Integer) iterator.next(); + if(tokenTupleSet.containsToken(rootID)==null){ + found=false; + } + } + if(!found){ + countNotContained++; + } } + if(countNotContained==rset.size()){ + containsAllTuple=false; + } + } + + if (containsAllTuple && liveInNode.getHRNSet().size() > 1) { + return ConflictEdge.COARSE_GRAIN_EDGE; + } else { + return ConflictEdge.FINE_GRAIN_EDGE; } + */ + + + + } + + return ConflictEdge.NON_WRITE_CONFLICT; - String attributes = "["; + } - attributes += "label=\"ID" + node.getID() + "\\n"; + public void analyzePossibleConflicts(Set analyzedIDSet, + ConflictNode currentNode) { - if (node instanceof StallSiteNode) { - attributes += "STALL SITE" + "\\n" + "\"]"; - } else { - attributes += "LIVE-IN" + "\\n" + "\"]"; + // compare with all nodes + // examine the case where self-edge exists + if (currentNode instanceof LiveInNode) { + LiveInNode liveInNode = (LiveInNode) currentNode; + int conflictType=calculateSelfConflictType(liveInNode); + if(conflictType>0){ + addConflictEdge(conflictType, currentNode, + currentNode); } - bw.write(entry.getKey() + attributes + ";\n"); + } - HashSet edgeSet = node.getEdgeSet(); - for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) { - ConflictEdge conflictEdge = (ConflictEdge) iterator.next(); + Set> set = id2cn.entrySet(); + for (Iterator iterator = set.iterator(); iterator.hasNext();) { + Entry entry = (Entry) iterator + .next(); - ConflictNode u = conflictEdge.getVertexU(); - ConflictNode v = conflictEdge.getVertexV(); + String entryNodeID = entry.getKey(); + ConflictNode entryNode = entry.getValue(); - if (filter) { - String uID = u.getID(); - String vID = v.getID(); - if (uID.startsWith("___dst") || uID.startsWith("___srctmp") - || uID.startsWith("___neverused") - || uID.startsWith("___temp") - || vID.startsWith("___dst") - || vID.startsWith("___srctmp") - || vID.startsWith("___neverused") - || vID.startsWith("___temp")) { - continue; + if ((!currentNode.getID().equals(entryNodeID)) + && !(analyzedIDSet.contains(currentNode.getID() + + entryNodeID) || analyzedIDSet + .contains(entryNodeID + currentNode.getID()))) { + + if (currentNode instanceof StallSiteNode + && entryNode instanceof LiveInNode) { + + int conflictType = calculateConflictType((StallSiteNode) currentNode, (LiveInNode) entryNode); + if (conflictType > 0) { + addConflictEdge(conflictType, currentNode, entryNode); } - } + + analyzedIDSet.add(currentNode.getID() + entryNodeID); - if (!addedSet.contains(conflictEdge)) { - bw.write(" " + u.getID() + "--" + v.getID() + "[label=" - + conflictEdge.toGraphEdgeString() - + ",decorate];\n"); - addedSet.add(conflictEdge); + } else if (currentNode instanceof LiveInNode + && entryNode instanceof LiveInNode) { + + int conflictType = calculateConflictType( + (LiveInNode) currentNode, (LiveInNode) entryNode); + if (conflictType > 0) { + addConflictEdge(conflictType, currentNode, entryNode); + } + analyzedIDSet.add(currentNode.getID() + entryNodeID); } } - } - - bw.write(" graphTitle[label=\"" + graphName + "\",shape=box];\n"); - bw.write("}\n"); - bw.close(); + } } @@ -1227,9 +1102,9 @@ class ConflictEdge { public int getType() { return type; } - - public String toString(){ - return getVertexU()+"-"+getVertexV(); + + public String toString() { + return getVertexU() + "-" + getVertexV(); } } \ No newline at end of file diff --git a/Robust/src/Analysis/MLP/GloballyUniqueTokenTuple.java b/Robust/src/Analysis/MLP/GloballyUniqueTokenTuple.java index adb270a7..a461c484 100644 --- a/Robust/src/Analysis/MLP/GloballyUniqueTokenTuple.java +++ b/Robust/src/Analysis/MLP/GloballyUniqueTokenTuple.java @@ -1,8 +1,9 @@ package Analysis.MLP; +import Analysis.OwnershipAnalysis.Canonical; import Analysis.OwnershipAnalysis.TokenTuple; -public class GloballyUniqueTokenTuple { +public class GloballyUniqueTokenTuple extends Canonical{ private Integer token; private boolean isMultiObject; diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index 0f805a46..95744071 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -331,7 +331,9 @@ public class MLPAnalysis { FlatNode key = (FlatNode) keyEnum.nextElement(); ConflictGraph cg=conflictGraphResults.get(key); try { - cg.writeGraph("ConflictGraphFor"+key, false); + if(cg.hasConflictEdge()){ + cg.writeGraph("ConflictGraphFor"+key, false); + } } catch (IOException e) { System.out.println("Error writing"); System.exit(0); @@ -1212,9 +1214,14 @@ public class MLPAnalysis { while (iter.hasNext()) { TempDescriptor td = iter.next(); LabelNode ln = og.td2ln.get(td); + + if(currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx().containsKey(td)){ + idx=currentSESE.getSeseEffectsSet().getInVarIdx(td); + } + if (ln != null) { int taint = (int) Math.pow(2, idx); - taintLabelNode(ln, taint); + taintLabelNode(ln, taint,currentSESE.getSeseEffectsSet()); currentSESE.getSeseEffectsSet().setInVarIdx(idx, td); // collects related allocation sites @@ -1365,20 +1372,22 @@ public class MLPAnalysis { case FKind.FlatFieldNode: { FlatFieldNode ffn = (FlatFieldNode) fn; + TempDescriptor dst = ffn.getDst(); TempDescriptor src = ffn.getSrc(); FieldDescriptor field = ffn.getField(); LabelNode srcLN = og.td2ln.get(src); if(srcLN!=null){ Iterator edgeIter=srcLN.iteratorToReferencees(); + int taintIdentifier=0; while (edgeIter.hasNext()) { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); HeapRegionNode refHRN=referenceEdge.getDst(); - int edgeTaint=referenceEdge.getSESETaintIdentifier(); + taintIdentifier=currentSESE.getSeseEffectsSet().getTaint(referenceEdge); +// taintIdentifier=referenceEdge.getSESETaintIdentifier(); // figure out which invar has related effects - int taint=referenceEdge.getSESETaintIdentifier(); Hashtable map=currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx(); Set keySet=map.keySet(); for (Iterator iterator = keySet.iterator(); iterator @@ -1386,13 +1395,26 @@ public class MLPAnalysis { TempDescriptor inVarTD = (TempDescriptor) iterator .next(); int inVarMask=(int) Math.pow(2, map.get(inVarTD).intValue()); - if((inVarMask&edgeTaint)>0){ + if((inVarMask&taintIdentifier)>0){ // found related invar, contribute effects currentSESE.readEffects(inVarTD, field.getSymbol(),src.getType(), refHRN); } } } + + // taint + if(!field.getType().isImmutable()){ + LabelNode dstLN = og.td2ln.get(dst); + edgeIter=dstLN.iteratorToReferencees(); + while (edgeIter.hasNext()) { + ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter + .next(); + currentSESE.getSeseEffectsSet().mapEdgeToTaint(referenceEdge, taintIdentifier); +// referenceEdge.unionSESETaintIdentifier(taintIdentifier); + } + } } + } break; @@ -1416,7 +1438,11 @@ public class MLPAnalysis { while (refEdgeIter.hasNext()) { ReferenceEdge edge = refEdgeIter.next(); int newTaint = (int) Math.pow(2, idx); - edge.unionSESETaintIdentifier(newTaint); +// System.out.println("fon="+fon); +// System.out.println(currentSESE+" src:"+src+"->"+"dest:"+dest+" with taint="+newTaint); +// System.out.println("referenceEdge="+edge); + currentSESE.getSeseEffectsSet().mapEdgeToTaint(edge, newTaint); +// System.out.println("after tainting="+edge.getSESETaintIdentifier()); } } } @@ -1437,10 +1463,10 @@ public class MLPAnalysis { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); HeapRegionNode dstHRN=referenceEdge.getDst(); - taintIdentifier=referenceEdge.getSESETaintIdentifier(); + taintIdentifier=currentSESE.getSeseEffectsSet().getTaint(referenceEdge); +// taintIdentifier=referenceEdge.getSESETaintIdentifier(); // figure out which invar has related effects - int taint=referenceEdge.getSESETaintIdentifier(); Hashtable map=currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx(); Set keySet=map.keySet(); for (Iterator iterator = keySet.iterator(); iterator @@ -1464,7 +1490,8 @@ public class MLPAnalysis { while (edgeIter.hasNext()) { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); - referenceEdge.unionSESETaintIdentifier(taintIdentifier); + currentSESE.getSeseEffectsSet().mapEdgeToTaint(referenceEdge, taintIdentifier); +// referenceEdge.unionSESETaintIdentifier(taintIdentifier); } } @@ -1486,7 +1513,8 @@ public class MLPAnalysis { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); HeapRegionNode dstHRN=referenceEdge.getDst(); - int edgeTaint=referenceEdge.getSESETaintIdentifier(); + int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge); +// int edgeTaint=referenceEdge.getSESETaintIdentifier(); // we can do a strong update here if one of two cases // holds @@ -1535,7 +1563,8 @@ public class MLPAnalysis { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); HeapRegionNode dstHRN=referenceEdge.getDst(); - int edgeTaint=referenceEdge.getSESETaintIdentifier(); + int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge); +// int edgeTaint=referenceEdge.getSESETaintIdentifier(); // we can do a strong update here if one of two cases // holds @@ -1638,7 +1667,8 @@ public class MLPAnalysis { ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter .next(); HeapRegionNode dstHRN=referenceEdge.getDst(); - int edgeTaint=referenceEdge.getSESETaintIdentifier(); + int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge); +// int edgeTaint=referenceEdge.getSESETaintIdentifier(); // figure out which invar has related effects Hashtable map = currentSESE @@ -1798,12 +1828,12 @@ public class MLPAnalysis { return new HashSet(); } - private void taintLabelNode(LabelNode ln, int identifier) { + private void taintLabelNode(LabelNode ln, int identifier, SESEEffectsSet effectSet) { Iterator edgeIter = ln.iteratorToReferencees(); while (edgeIter.hasNext()) { ReferenceEdge edge = edgeIter.next(); - edge.setSESETaintIdentifier(identifier); + effectSet.mapEdgeToTaint(edge, identifier); } } @@ -2174,6 +2204,7 @@ public class MLPAnalysis { while (mcIter.hasNext()) { MethodContext mc = mcIter.next(); + OwnershipGraph og=ownAnalysisForSESEConflicts.getOwnvershipGraphByMethodContext(mc); Set flatNodesToVisit = new HashSet(); flatNodesToVisit.add(fm); @@ -2209,7 +2240,7 @@ public class MLPAnalysis { .getCurrentSESE()); if (conflictGraph == null) { - conflictGraph = new ConflictGraph(); + conflictGraph = new ConflictGraph(og); } for (Iterator> iterator2 = entrySet .iterator(); iterator2.hasNext();) { @@ -2219,7 +2250,7 @@ public class MLPAnalysis { StallSite stallSite = entry.getValue(); // reachability set - OwnershipGraph og = ownAnalysisForSESEConflicts + og = ownAnalysisForSESEConflicts .getOwnvershipGraphByMethodContext(mc); Set reachabilitySet = calculateReachabilitySet(og, td); @@ -2295,6 +2326,62 @@ public class MLPAnalysis { return reachabilitySet; } + private ReachabilitySet packupStates(OwnershipGraph og, HeapRegionNode hrn) { + + ReachabilitySet betaSet = new ReachabilitySet().makeCanonical(); + + Iterator itrEdge = hrn.iteratorToReferencers(); + while (itrEdge.hasNext()) { + ReferenceEdge edge = itrEdge.next(); + betaSet = betaSet.union(edge.getBeta()); + } + + return betaSet; + + } + + private ReachabilitySet packupStates(OwnershipGraph og, AllocationSite as) { + + ReachabilitySet betaSet = new ReachabilitySet().makeCanonical(); + assert as!=null; + HeapRegionNode hrnSummary = og.id2hrn.get(as.getSummary()); + if(hrnSummary!=null){ + Iterator itrEdge = hrnSummary.iteratorToReferencers(); + while (itrEdge.hasNext()) { + ReferenceEdge edge = itrEdge.next(); + betaSet = betaSet.union(edge.getBeta()); + } + } + + // check for other nodes + for (int i = 0; i < as.getAllocationDepth(); ++i) { + + HeapRegionNode hrnIthOldest = og.id2hrn.get(as.getIthOldest(i)); +// betaSet = new ReachabilitySet().makeCanonical(); +// itrEdge = hrnIthOldest.iteratorToReferencees(); + Iterator itrEdge = hrnIthOldest.iteratorToReferencers(); + while (itrEdge.hasNext()) { + ReferenceEdge edge = itrEdge.next(); + betaSet = betaSet.union(edge.getBeta()); + } + } + + Iterator ttSetIter = betaSet.iterator(); + while (ttSetIter.hasNext()) { + TokenTupleSet tokenTupleSet = (TokenTupleSet) ttSetIter.next(); + Iterator iter = tokenTupleSet.iterator(); + while (iter.hasNext()) { + TokenTuple tt = (TokenTuple) iter.next(); + int token = tt.getToken(); + String uniqueID = og.id2hrn.get(new Integer(token)) + .getGloballyUniqueIdentifier(); + GloballyUniqueTokenTuple gtt = new GloballyUniqueTokenTuple( + uniqueID, tt); + } + } + return betaSet; + } + private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm, FlatNode fn,Hashtable invarMap) { @@ -2314,7 +2401,7 @@ public class MLPAnalysis { conflictGraph=conflictGraphResults.get(seseSummary.getCurrentParent()); if(conflictGraph==null){ - conflictGraph = new ConflictGraph(); + conflictGraph = new ConflictGraph(og); } @@ -2327,23 +2414,60 @@ public class MLPAnalysis { continue; } -// if(tempDescriptor.getType().isArray()){ -// -// } - // effects set SESEEffectsSet seseEffectsSet = fsen.getSeseEffectsSet(); Set readEffectsSet = seseEffectsSet .getReadingSet(tempDescriptor); + + if (readEffectsSet != null) { + for (Iterator iterator2 = readEffectsSet.iterator(); iterator2 + .hasNext();) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2 + .next(); + String uniqueID = seseEffectsKey.getHRNUniqueId(); + HeapRegionNode node = og.gid2hrn.get(uniqueID); + if(node.isParameter()){ + seseEffectsKey.setRSet(packupStates(og,node)); + }else{ + AllocationSite as = node.getAllocationSite(); + seseEffectsKey.setRSet(packupStates(og,as)); + } + } + } + + if (readEffectsSet != null) { + for (Iterator iterator2 = readEffectsSet.iterator(); iterator2 + .hasNext();) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2 + .next(); + } + } Set writeEffectsSet = seseEffectsSet .getWritingSet(tempDescriptor); + + if (writeEffectsSet != null) { + for (Iterator iterator2 = writeEffectsSet.iterator(); iterator2 + .hasNext();) { + SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2 + .next(); + String uniqueID = seseEffectsKey.getHRNUniqueId(); + HeapRegionNode node = og.gid2hrn.get(uniqueID); + + if(node.isParameter()){ + seseEffectsKey.setRSet(packupStates(og,node)); + }else{ + AllocationSite as = node.getAllocationSite(); + seseEffectsKey.setRSet(packupStates(og,as)); + } + } + } + Set strongUpdateSet = seseEffectsSet.getStrongUpdateSet(tempDescriptor); Set reachabilitySet = calculateReachabilitySet(og, tempDescriptor); // add new live-in node -// LabelNode ln = og.td2ln.get(tempDescriptor); OwnershipGraph lastOG = ownAnalysis .getOwnvershipGraphByMethodContext(mc); @@ -2356,7 +2480,16 @@ public class MLPAnalysis { while (refIter.hasNext()) { ReferenceEdge referenceEdge = (ReferenceEdge) refIter .next(); - hrnSet.add(referenceEdge.getDst()); + // + SESEEffectsSet seseEffects=fsen.getSeseEffectsSet(); + int taintIdentifier=fsen.getSeseEffectsSet().getTaint(referenceEdge); + int invarIdx=fsen.getSeseEffectsSet().getInVarIdx(tempDescriptor); + int inVarMask=(int) Math.pow(2,invarIdx); + if((inVarMask&taintIdentifier)>0){ + // find tainted edge, add heap root to live-in node + hrnSet.add(referenceEdge.getDst()); + } + // } conflictGraph.addLiveInNode(tempDescriptor, hrnSet, fsen, diff --git a/Robust/src/Analysis/MLP/SESEEffectsKey.java b/Robust/src/Analysis/MLP/SESEEffectsKey.java index dc824900..d26e5ebd 100644 --- a/Robust/src/Analysis/MLP/SESEEffectsKey.java +++ b/Robust/src/Analysis/MLP/SESEEffectsKey.java @@ -1,5 +1,6 @@ package Analysis.MLP; +import Analysis.OwnershipAnalysis.ReachabilitySet; import IR.TypeDescriptor; public class SESEEffectsKey { @@ -8,6 +9,7 @@ public class SESEEffectsKey { private TypeDescriptor td; private Integer hrnId; private String hrnUniqueId; + private ReachabilitySet rset; private boolean wStrong=false; public SESEEffectsKey(String fd, TypeDescriptor td, Integer hrnId, String hrnUniqueId) { @@ -17,6 +19,14 @@ public class SESEEffectsKey { this.hrnUniqueId=hrnUniqueId; } + public void setRSet(ReachabilitySet rset){ + this.rset=rset; + } + + public ReachabilitySet getRSet(){ + return rset; + } + public void setStrong(boolean wStrong){ this.wStrong=wStrong; } diff --git a/Robust/src/Analysis/MLP/SESEEffectsSet.java b/Robust/src/Analysis/MLP/SESEEffectsSet.java index e8f0da96..91a0cfa8 100644 --- a/Robust/src/Analysis/MLP/SESEEffectsSet.java +++ b/Robust/src/Analysis/MLP/SESEEffectsSet.java @@ -6,6 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Set; +import Analysis.OwnershipAnalysis.ReferenceEdge; import IR.Flat.TempDescriptor; public class SESEEffectsSet { @@ -13,12 +14,31 @@ public class SESEEffectsSet { private Hashtable> writeTable; private Hashtable> strongUpdateTable; private Hashtable mapTempDescToInVarIdx; + private Hashtable mapEdgeToTaint; public SESEEffectsSet() { readTable = new Hashtable>(); writeTable = new Hashtable>(); strongUpdateTable = new Hashtable>(); mapTempDescToInVarIdx = new Hashtable(); + mapEdgeToTaint = new Hashtable(); + } + + public int getTaint(ReferenceEdge edge){ + int taint=0; + if(mapEdgeToTaint.containsKey(edge)){ + taint=mapEdgeToTaint.get(edge).intValue(); + } + return taint; + } + + public void mapEdgeToTaint(ReferenceEdge edge, int newTaint){ + int taint=0; + if(mapEdgeToTaint.containsKey(edge)){ + taint=mapEdgeToTaint.get(edge).intValue(); + } + taint=taint | newTaint; + mapEdgeToTaint.put(edge, new Integer(taint)); } public void setInVarIdx(int idx, TempDescriptor td){ diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 5429938f..3c37e4a1 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -87,6 +87,8 @@ public class OwnershipGraph { // to know the access paths that allowed it, to prune edges when // mapping them back into the caller--an access path must appear public Hashtable< TempDescriptor, Set > temp2accessPaths; + + public Hashtable< String, HeapRegionNode > gid2hrn; public OwnershipGraph() { @@ -121,6 +123,8 @@ public class OwnershipGraph { outOfScopeLabels.add( getLabelNodeFromTemp( tdReturn ) ); temp2accessPaths = new Hashtable< TempDescriptor, Set >(); + + gid2hrn =new Hashtable< String, HeapRegionNode >(); } @@ -202,6 +206,7 @@ public class OwnershipGraph { description, globalIdentifier); id2hrn.put(id, hrn); + gid2hrn.put(globalIdentifier, hrn); return hrn; } @@ -3938,6 +3943,7 @@ public class OwnershipGraph { if( !id2hrn.containsKey(idA) ) { HeapRegionNode hrnB = hrnA.copy(); id2hrn.put(idA, hrnB); + gid2hrn.put(hrnA.getGloballyUniqueIdentifier(), hrnB); } else { // otherwise this is a node present in both graphs diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 0f8df474..85b4c1e3 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -367,7 +367,7 @@ public class BuildCode { outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); } else outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); - outmethod.println("1, NULL,"+"stringarray};"); + outmethod.println("1, NULL,"+"stringarray};"); if (state.DSM||state.SINGLETM) outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); else @@ -1450,8 +1450,8 @@ public class BuildCode { output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); else output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); - output.println(" INTPTR size;"); - output.println(" void * next;"); + output.println(" int size;"); + output.println(" void * next;"); for(int i=0; i itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator(); - while( itrStaticInVarSrcs.hasNext() ) { - SESEandAgePair srcPair = itrStaticInVarSrcs.next(); - outputStructs.println(" "+srcPair.getSESE().getSESErecordName()+"* "+srcPair+";"); - } - - // DYNAMIC stuff needs a source SESE ptr and offset - Iterator itrDynInVars = fsen.getDynamicInVarSet().iterator(); - while( itrDynInVars.hasNext() ) { - TempDescriptor dynInVar = itrDynInVars.next(); - outputStructs.println(" void* "+dynInVar+"_srcSESE;"); - outputStructs.println(" int "+dynInVar+"_srcOffset;"); - } + // DYNAMIC stuff was here + + // invar source taking was here // space for all in and out set primitives Set inSetAndOutSet = new HashSet(); @@ -1967,7 +1952,9 @@ public class BuildCode { while( itrPrims.hasNext() ) { TempDescriptor temp = itrPrims.next(); TypeDescriptor type = temp.getType(); - outputStructs.println(" "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";"); + if(!type.isPrimitive()){ + outputStructs.println(" "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";"); + } } for(int i=0; i itrDynInVars = fsen.getDynamicInVarSet().iterator(); + while( itrDynInVars.hasNext() ) { + TempDescriptor dynInVar = itrDynInVars.next(); +// outputStructs.println(" void* "+dynInVar+"_srcSESE;"); + outputStructs.println(" int "+dynInVar+"_srcOffset;"); + } + + itrPrims = inSetAndOutSetPrims.iterator(); + while( itrPrims.hasNext() ) { + TempDescriptor temp = itrPrims.next(); + TypeDescriptor type = temp.getType(); + if(type.isPrimitive()){ + outputStructs.println(" "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";"); + } + } + + outputStructs.println(" int prevSESECount;"); + + // DYNAMIC stuff needs a source SESE ptr and offset + itrDynInVars = fsen.getDynamicInVarSet().iterator(); + while( itrDynInVars.hasNext() ) { + TempDescriptor dynInVar = itrDynInVars.next(); + outputStructs.println(" void* "+dynInVar+"_srcSESE;"); +// outputStructs.println(" int "+dynInVar+"_srcOffset;"); + } + + // in-set source tracking + // in-vars that are READY come from parent, don't need anything + // stuff STATIC needs a custom SESE pointer for each age pair + Iterator itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator(); + while( itrStaticInVarSrcs.hasNext() ) { + SESEandAgePair srcPair = itrStaticInVarSrcs.next(); + outputStructs.println(" "+srcPair.getSESE().getSESErecordName()+"* "+srcPair+";"); + } + outputStructs.println("};\n"); @@ -2014,7 +2037,7 @@ public class BuildCode { if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); output.print(objecttemp.numPointers()+","); - output.print("(void*) &("+paramsprefix+"->size)"); + output.print("&(((SESEcommon*)(___params___))[1])"); for(int j=0; j0)) { output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();"); } - if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) + if (((state.MLP||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) { output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");"); @@ -3323,6 +3347,21 @@ public class BuildCode { output.println(" "+fsen.getSESErecordName()+"* seseToIssue = ("+ fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+ fsen.getSESErecordName()+" ) );"); + //eomgc need to set next, size +// output.println(" struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(seseToIssue))[1]);"); + output.println(" struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(seseToIssue))[1]);"); + // sizeof(int)*2 + sizeof(void*)*calculateSizeOfSESEParamList(fsen) + //output.println(" // sizeof(int)*2+sizeof(void*)*"+calculateSizeOfSESEParamList(fsen)); + //output.println(" // blah="+calculateSizeOfSESEParamSize(fsen)); + output.println(" (seseToIssue->common).offsetsize=sizeof(int)+sizeof(void*)+sizeof(void*)*"+calculateSizeOfSESEParamList(fsen)+calculateSizeOfSESEParamSize(fsen)+";"); + output.println(" gl->size="+calculateSizeOfSESEParamList(fsen)+";"); +// output.println(" gl->next = (struct garbagelist *)&___locals___;"); + output.println(" seseToIssue->prevSESECount="+calculatePrevSESECount(fsen)+";"); +// output.println(" seseToIssue->prevSESECount=50;"); + output.println(" gl->next = NULL;"); +// output.println(" seseToIssue->size = "+calculateSizeOfSESEParamList(fsen)+";"); +// output.println(" seseToIssue->next = &___locals___;"); + // and keep the thread-local sese stack up to date //output.println(" addNewItem( seseCallStack, (void*) seseToIssue);"); @@ -3378,7 +3417,14 @@ public class BuildCode { SESEandAgePair srcPair = staticSrcsItr.next(); output.println(" {"); output.println(" SESEcommon* src = (SESEcommon*)"+srcPair+";"); + //eomgc + if(GENERATEPRECISEGC){ + output.println(" stopforgc((struct garbagelist *)&___locals___);"); + } output.println(" pthread_mutex_lock( &(src->lock) );"); + if(GENERATEPRECISEGC){ + output.println(" restartaftergc();"); + } output.println(" if( !isEmpty( src->forwardList ) &&"); output.println(" seseToIssue == peekItem( src->forwardList ) ) {"); output.println(" printf( \"This shouldnt already be here\\n\");"); @@ -3409,7 +3455,14 @@ public class BuildCode { // the address off to the new child, because you're not done executing and // might change the variable, so copy it right now output.println(" if( src != NULL ) {"); + //eomgc + if(GENERATEPRECISEGC){ + output.println(" stopforgc((struct garbagelist *)&___locals___);"); + } output.println(" pthread_mutex_lock( &(src->lock) );"); + if(GENERATEPRECISEGC){ + output.println(" restartaftergc();"); + } output.println(" if( isEmpty( src->forwardList ) ||"); output.println(" seseToIssue != peekItem( src->forwardList ) ) {"); output.println(" if( !src->doneExecuting ) {"); @@ -3606,11 +3659,25 @@ public class BuildCode { // this SESE cannot be done until all of its children are done // so grab your own lock with the condition variable for watching // that the number of your running children is greater than zero + if (GENERATEPRECISEGC){ + output.println(" stopforgc((struct garbagelist *)&___locals___);"); + } output.println(" pthread_mutex_lock( &("+com+".lock) );"); + if (GENERATEPRECISEGC){ + output.println(" restartaftergc();"); + } output.println(" while( "+com+".numRunningChildren > 0 ) {"); + if (GENERATEPRECISEGC){ +// output.println(" stopforgc((struct garbagelist *)&(((SESEcommon*)(___params___))[1]));"); + output.println(" stopforgc((struct garbagelist *)&___locals___);"); + } output.println(" pthread_cond_wait( &("+com+".runningChildrenCond), &("+com+".lock) );"); + if (GENERATEPRECISEGC){ + output.println(" restartaftergc();"); + } output.println(" }"); + // copy out-set from local temps into the sese record Iterator itr = fsen.getOutVarSet().iterator(); while( itr.hasNext() ) { @@ -3699,7 +3766,13 @@ public class BuildCode { // last of all, decrement your parent's number of running children output.println(" if( "+paramsprefix+"->common.parent != NULL ) {"); output.println(" if (atomic_sub_and_test(1, &"+paramsprefix+"->common.parent->numRunningChildren)) {"); + if (GENERATEPRECISEGC){ + output.println(" stopforgc((struct garbagelist *)&___locals___);"); + } output.println(" pthread_mutex_lock( &("+paramsprefix+"->common.parent->lock) );"); + if (GENERATEPRECISEGC){ + output.println(" restartaftergc();"); + } output.println(" pthread_cond_signal( &("+paramsprefix+"->common.parent->runningChildrenCond) );"); output.println(" pthread_mutex_unlock( &("+paramsprefix+"->common.parent->lock) );"); output.println(" }"); @@ -3798,7 +3871,6 @@ public class BuildCode { output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); } else output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); - output.print(objectparams.numPointers()); output.print(", "+localsprefixaddr); if (md.getThis()!=null) { @@ -4005,8 +4077,12 @@ public class BuildCode { output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); } else throw new Error("Read from non-global/non-local in:"+lb.getExplanation()); - } else + } else{ +// DEBUG if(!ffn.getDst().getType().isPrimitive()){ +// DEBUG output.println("within((void*)"+generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+");"); +// DEBUG } output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); + } } @@ -4103,6 +4179,10 @@ public class BuildCode { output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); output.println("}"); } + +// DEBUG if(!fsfn.getField().getType().isPrimitive()){ +// DEBUG output.println("within((void*)"+generateTemp(fm,fsfn.getSrc(),lb)+");"); +// DEBUG } output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";"); } } @@ -4164,7 +4244,8 @@ public class BuildCode { } else throw new Error("Read from non-global/non-local in:"+lb.getExplanation()); } else { - output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); +// DEBUG output.println("within((void*)"+generateTemp(fm,fen.getSrc(),lb)+");"); + output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); } } @@ -4266,6 +4347,7 @@ public class BuildCode { output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); output.println("}"); } +// DEBUG output.println("within((void*)"+generateTemp(fm,fsen.getDst(),lb)+");"); output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";"); } } @@ -5055,6 +5137,93 @@ public class BuildCode { protected void outputTransCode(PrintWriter output) { } + + private int calculateSizeOfSESEParamList(FlatSESEEnterNode fsen){ + + Set tdSet=new HashSet(); + + for (Iterator iterator = fsen.getInVarSet().iterator(); iterator.hasNext();) { + TempDescriptor tempDescriptor = (TempDescriptor) iterator.next(); + if(!tempDescriptor.getType().isPrimitive() || tempDescriptor.getType().isArray()){ + tdSet.add(tempDescriptor); + } + } + + for (Iterator iterator = fsen.getOutVarSet().iterator(); iterator.hasNext();) { + TempDescriptor tempDescriptor = (TempDescriptor) iterator.next(); + if(!tempDescriptor.getType().isPrimitive() || tempDescriptor.getType().isArray()){ + tdSet.add(tempDescriptor); + } + } + + return tdSet.size(); + } + +private String calculateSizeOfSESEParamSize(FlatSESEEnterNode fsen){ + HashMap map=new HashMap(); + HashSet processed=new HashSet(); + String rtr=""; + + // space for all in and out set primitives + Set inSetAndOutSet = new HashSet(); + inSetAndOutSet.addAll( fsen.getInVarSet() ); + inSetAndOutSet.addAll( fsen.getOutVarSet() ); + + Set inSetAndOutSetPrims = new HashSet(); + + Iterator itr = inSetAndOutSet.iterator(); + while( itr.hasNext() ) { + TempDescriptor temp = itr.next(); + TypeDescriptor type = temp.getType(); + if( !type.isPtr() ) { + inSetAndOutSetPrims.add( temp ); + } + } + + Iterator itrPrims = inSetAndOutSetPrims.iterator(); + while( itrPrims.hasNext() ) { + TempDescriptor temp = itrPrims.next(); + TypeDescriptor type = temp.getType(); + if(type.isPrimitive()){ + Integer count=map.get(type.getSymbol()); + if(count==null){ + count=new Integer(1); + map.put(type.getSymbol(), count); + }else{ + map.put(type.getSymbol(), new Integer(count.intValue()+1)); + } + } + } + + Set keySet=map.keySet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + String key = (String) iterator.next(); + rtr+="+sizeof("+key+")*"+map.get(key); + } + return rtr; +} + +private int calculatePrevSESECount(FlatSESEEnterNode fsen){ + int count=0; + + // dynamic stuff + IteratoritrDynInVars = fsen.getDynamicInVarSet().iterator(); + while( itrDynInVars.hasNext() ) { + TempDescriptor dynInVar = itrDynInVars.next(); + count++; + } + + // in-set source tracking + Iterator itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator(); + while( itrStaticInVarSrcs.hasNext() ) { + SESEandAgePair srcPair = itrStaticInVarSrcs.next(); + count++; + } + + return count; +} + + } diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 8ca3a616..bc12ef06 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -11,6 +11,8 @@ #endif #ifdef MLP #include "workschedule.h" +extern struct QI * headqi; +extern struct QI * tailqi; #endif #ifdef DMALLOC @@ -64,6 +66,10 @@ __thread struct listitem litem; #endif #endif +#ifdef MLP +__thread SESEcommon* seseCommon; +#endif + //Need to check if pointers are transaction pointers //this also catches the special flag value of 1 for local copies #ifdef DSTM @@ -100,12 +106,15 @@ __thread struct listitem litem; dst=copy; } #else #define ENQUEUE(orig, dst) \ - void *copy; \ - if (gc_createcopy(orig,©)) \ - enqueue(copy);\ - dst=copy + if (orig>=curr_heapbase&&orignext=tmp; head=tmp; headindex=0; @@ -362,14 +371,14 @@ void collect(struct garbagelist * stackptr) { #if defined(STM)||defined(THREADS)||defined(MLP) memorybase=NULL; #endif - + /* Check current stack */ #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) { struct listitem *listptr=list; while(1) { #endif - + while(stackptr!=NULL) { int i; for(i=0; isize; i++) { @@ -383,6 +392,11 @@ void collect(struct garbagelist * stackptr) { #ifndef MAC //skip over us if (listptr==&litem) { +#ifdef MLP + // update forward list & memory queue for the current SESE + updateForwardList(((SESEcommon*)listptr->seseCommon)->forwardList,FALSE); + updateMemoryQueue((SESEcommon*)(listptr->seseCommon)); +#endif listptr=listptr->next; } #else @@ -393,7 +407,7 @@ void collect(struct garbagelist * stackptr) { } } #endif - + if (listptr!=NULL) { #ifdef THREADS void * orig=listptr->locklist; @@ -410,6 +424,11 @@ void collect(struct garbagelist * stackptr) { #endif #if defined(STM)||defined(THREADS)||defined(MLP) *(listptr->base)=NULL; +#endif +#ifdef MLP + // update forward list & memory queue for all running SESEs. + updateForwardList(((SESEcommon*)listptr->seseCommon)->forwardList,FALSE); + updateMemoryQueue((SESEcommon*)(listptr->seseCommon)); #endif stackptr=listptr->stackptr; listptr=listptr->next; @@ -516,6 +535,36 @@ void collect(struct garbagelist * stackptr) { } #endif +#ifdef MLP + { + // goes over ready-to-run SESEs + struct QI * qitem = headqi; + while(qitem!=NULL){ + SESEcommon* common=(SESEcommon*)qitem->value; + if(common==seseCommon){ + // skip the current running SESE + qitem=qitem->next; + continue; + } + struct garbagelist * gl=(struct garbagelist *)&(((SESEcommon*)(qitem->value))[1]); + struct garbagelist * glroot=gl; + // update its ascendant SESEs + updateAscendantSESE(gl); + + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + qitem=qitem->next; + } + } +#endif + + while(moreItems()) { void * ptr=dequeue(); void *cpy=ptr; @@ -575,6 +624,17 @@ void collect(struct garbagelist * stackptr) { fixtags(); #endif +#ifdef MLP + { + //rehash memory queues of current running SESEs + struct listitem *listptr=list; + while(listptr!=NULL){ + rehashMemoryQueue((SESEcommon*)(listptr->seseCommon)); + listptr=listptr->next; + } + } +#endif + #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) needtocollect=0; pthread_mutex_unlock(&gclistlock); @@ -757,7 +817,7 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) { /* Need to allocate base heap */ curr_heapbase=malloc(INITIALHEAPSIZE); if (curr_heapbase==NULL) { - printf("malloc failed. Garbage collector couldn't get enough memory. Try changing heap size.\n"); + printf("malloc failed. Garbage colletcor couldn't get enough memory. Try changing heap size.\n"); exit(-1); } #if defined(STM)||defined(THREADS)||defined(MLP) @@ -767,7 +827,7 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) { curr_heaptop=curr_heapbase+INITIALHEAPSIZE; curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(INITIALHEAPSIZE); curr_heapptr=curr_heapbase+size; - + to_heapbase=malloc(INITIALHEAPSIZE); if (to_heapbase==NULL) { printf("malloc failed. Garbage collector couldn't get enough memory. Try changing heap size.\n"); @@ -926,3 +986,138 @@ int gc_createcopy(void * orig, void ** copy_ptr) { } } } + +#ifdef MLP +updateForwardList(struct Queue *forwardList, int prevUpdate){ + + struct QueueItem * fqItem=getHead(forwardList); + while(fqItem!=NULL){ + struct garbagelist * gl=(struct garbagelist *)&(((SESEcommon*)(fqItem->objectptr))[1]); + if(prevUpdate==TRUE){ + updateAscendantSESE(gl); + } + // do something here + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + // iterate forwarding list of seseRec + SESEcommon *common=(SESEcommon*)fqItem->objectptr; + struct Queue* fList=common->forwardList; + updateForwardList(fList,prevUpdate); + fqItem=getNextQueueItem(fqItem); + } + +} + +updateMemoryQueue(SESEcommon_p seseParent){ + // update memory queue + int i,binidx; + for(i=0; inumMemoryQueue; i++){ + MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i]; + MemoryQueueItem *memoryItem=memoryQueue->head; + while(memoryItem!=NULL){ + if(memoryItem->type==HASHTABLE){ + Hashtable *ht=(Hashtable*)memoryItem; + for(binidx=0; binidxarray[binidx]; + BinItem *binItem=bin->head; + while(binItem!=NULL){ + if(binItem->type==READBIN){ + ReadBinItem* readBinItem=(ReadBinItem*)binItem; + int ridx; + for(ridx=0; ridxindex; ridx++){ + REntry *rentry=readBinItem->array[ridx]; + struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]); + updateAscendantSESE(gl); + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + } + }else{ //writebin + REntry *rentry=((WriteBinItem*)binItem)->val; + struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]); + updateAscendantSESE(gl); + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + } + binItem=binItem->next; + } + } + }else if(memoryItem->type==VECTOR){ + Vector *vt=(Vector*)memoryItem; + int idx; + for(idx=0; idxindex; idx++){ + REntry *rentry=vt->array[idx]; + struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]); + updateAscendantSESE(gl); + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + } + }else if(memoryItem->type==SINGLEITEM){ + SCC *scc=(SCC*)memoryItem; + REntry *rentry=scc->val; + struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(rentry->seseRec))[1]); + updateAscendantSESE(gl); + while(gl!=NULL) { + int i; + for(i=0; isize; i++) { + void * orig=gl->array[i]; + ENQUEUE(orig, gl->array[i]); + } + gl=gl->next; + } + } + memoryItem=memoryItem->next; + } + } + } + +updateAscendantSESE(struct garbagelist *gl){ + int offsetsize=*((int*)((void*)gl-sizeof(int))); + int prevSESECount=*((int*)((void*)gl+offsetsize)); + INTPTR tailaddr=(INTPTR)((void*)gl+offsetsize+sizeof(int)); + int prevIdx; + for(prevIdx=0; prevIdxsize; i++) { + void * orig=prevgl->array[i]; + ENQUEUE(orig, prevgl->array[i]); + } + prevgl=prevgl->next; + } + } + } +} +#endif + +int within(void *ptr){ //debug function + if(ptr>curr_heapptr || ptrunresolvedQueue=val;//released lock; } } + +void rehashMemoryQueue(SESEcommon_p seseParent){ + // update memory queue + int i,binidx; + for(i=0; inumMemoryQueue; i++){ + MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i]; + MemoryQueueItem *memoryItem=memoryQueue->head; + MemoryQueueItem *prevItem=NULL; + while(memoryItem!=NULL){ + if(memoryItem->type==HASHTABLE){ + //do re-hash! + Hashtable* ht=(Hashtable*)memoryItem; + Hashtable* newht=createHashtable(); + int binidx; + for(binidx=0; binidxarray[binidx]; + BinItem *binItem=bin->head; + //traverse over the list of each bin + while(binItem!=NULL){ + if(binItem->type==READBIN){ + ReadBinItem* readBinItem=(ReadBinItem*)binItem; + int ridx; + for(ridx=0; ridxindex; ridx++){ + REntry *rentry=readBinItem->array[ridx]; + int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer)); + int status=rentry->binitem->status; + ADDTABLEITEM(newht,rentry,TRUE); + rentry->binitem->status=status; // update bin status as before rehash + } + }else{//write bin + REntry *rentry=((WriteBinItem*)binItem)->val; + int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer)); + int status=rentry->binitem->status; + ADDTABLEITEM(newht,rentry,TRUE); + int newstatus=rentry->binitem->status; + //printf("[%d]old status=%d new status=%d\n",i,status,newstatus); + rentry->binitem->status=status; // update bin status as before rehash + } + binItem=binItem->next; + } + } + newht->item.status=ht->item.status; // update hashtable status + if(prevItem!=NULL){ + prevItem->next=(MemoryQueueItem*)newht; + }else{ + if(memoryQueue->head==memoryQueue->tail){ + memoryQueue->tail=(MemoryQueueItem*)newht; + } + memoryQueue->head=(MemoryQueueItem*)newht; + } + newht->item.next=ht->item.next; + } + prevItem=memoryItem; + memoryItem=memoryItem->next; + } + } + +} diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index 4348cd5c..7cf08a4c 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -158,7 +158,7 @@ typedef struct SESEcommon_t { struct MemoryQueue_t** memoryQueueArray; struct REntry_t* rentryArray[NUMRENTRY]; struct REntry_t* unresolvedRentryArray[NUMRENTRY]; - + int offsetsize; } SESEcommon; // a thread-local stack of SESEs and function to @@ -181,5 +181,6 @@ MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue); REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID); REntry* mlpCreateREntry(int type, void* seseToIssue); MemoryQueue* createMemoryQueue(); +void rehashMemoryQueue(SESEcommon_p seseParent); #endif /* __MLP_RUNTIME__ */ diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c index 785704ec..451b8a2d 100644 --- a/Robust/src/Runtime/workschedule.c +++ b/Robust/src/Runtime/workschedule.c @@ -58,13 +58,19 @@ pthread_mutex_t gclock; pthread_mutex_t gclistlock; pthread_cond_t gccond; +extern struct listitem * list; +extern __thread struct listitem litem; +extern __thread SESEcommon* seseCommon; + +/* struct QI { struct QI * next; void * value; }; -struct QI * head; -struct QI * tail; +struct QI * headqi; +struct QI * tailqi; +*/ /* // helper func @@ -189,22 +195,47 @@ void* workerMain( void* arg ) { pthread_mutex_lock( &systemLockOut ); // wait for work - if (head->next==NULL) { + if (headqi->next==NULL) { pthread_mutex_unlock( &systemLockOut ); sched_yield(); continue; } - struct QI * tmp=head; - head = head->next; - workUnit = head->value; + struct QI * tmp=headqi; + headqi = headqi->next; + workUnit = headqi->value; pthread_mutex_unlock( &systemLockOut ); free(tmp); // yield processor before moving on, just to exercise // system's out-of-order correctness //if( sched_yield() == -1 ) { printf( "Error thread trying to yield.\n" ); exit( -1 ); } //if( sched_yield() == -1 ) { printf( "Error thread trying to yield.\n" ); exit( -1 ); } + + + pthread_mutex_lock(&gclistlock); + threadcount++; + litem.seseCommon=(void*)workUnit; + litem.prev=NULL; + litem.next=list; + if(list!=NULL) + list->prev=&litem; + list=&litem; + seseCommon=(SESEcommon*)workUnit; + pthread_mutex_unlock(&gclistlock); workFunc( workUnit ); + + pthread_mutex_lock(&gclistlock); + threadcount--; + if (litem.prev==NULL) { + list=litem.next; + } else { + litem.prev->next=litem.next; + } + if (litem.next!=NULL) { + litem.next->prev=litem.prev; + } + pthread_mutex_unlock(&gclistlock); + } return NULL; @@ -273,8 +304,8 @@ void workScheduleInit( int numProcessors, workFunc = func; - head=tail=RUNMALLOC(sizeof(struct QI)); - head->next=NULL; + headqi=tailqi=RUNMALLOC(sizeof(struct QI)); + headqi->next=NULL; status = pthread_mutex_init( &systemLockIn, NULL ); status = pthread_mutex_init( &systemLockOut, NULL ); @@ -324,14 +355,13 @@ void workScheduleSubmit( void* workUnit ) { } pthread_mutex_unlock( &systemLock ); */ - struct QI* item=RUNMALLOC(sizeof(struct QI)); item->value=workUnit; item->next=NULL; pthread_mutex_lock ( &systemLockIn ); - tail->next=item; - tail=item; + tailqi->next=item; + tailqi=item; pthread_mutex_unlock( &systemLockIn ); } @@ -339,7 +369,8 @@ void workScheduleSubmit( void* workUnit ) { // really should be named "wait until work is finished" void workScheduleBegin() { - int i; + int i; + workerMain(NULL); // tell all workers to begin for( i = 0; i < numWorkers; ++i ) { diff --git a/Robust/src/Runtime/workschedule.h b/Robust/src/Runtime/workschedule.h index 41e26571..da0e3581 100644 --- a/Robust/src/Runtime/workschedule.h +++ b/Robust/src/Runtime/workschedule.h @@ -28,6 +28,13 @@ extern pthread_mutex_t gclock; extern pthread_mutex_t gclistlock; extern pthread_cond_t gccond; +struct QI { + struct QI * next; + void * value; +}; + +struct QI * headqi; +struct QI * tailqi; #endif /* __WORK_SCHEDULE__ */