From e5d9814224956ac1180e8548ad46f54a619f21ff Mon Sep 17 00:00:00 2001
From: yeom <yeom>
Date: Wed, 13 Jan 2010 19:09:05 +0000
Subject: [PATCH] changes in SESE lock scheme using clique covering.

---
 Robust/src/Analysis/MLP/ConflictGraph.java    | 528 +++++++++++++++---
 Robust/src/Analysis/MLP/ConflictNode.java     |   2 +-
 Robust/src/Analysis/MLP/MLPAnalysis.java      | 202 +++----
 Robust/src/Analysis/MLP/SESELock.java         |  70 +++
 Robust/src/Analysis/MLP/WaitingElement.java   |  39 ++
 .../OwnershipAnalysis/AllocationSite.java     |   4 +
 Robust/src/IR/Flat/BuildCode.java             | 245 ++++----
 Robust/src/Runtime/mlp_runtime.c              | 108 ++++
 Robust/src/Runtime/mlp_runtime.h              |  12 +-
 9 files changed, 923 insertions(+), 287 deletions(-)
 create mode 100644 Robust/src/Analysis/MLP/SESELock.java
 create mode 100644 Robust/src/Analysis/MLP/WaitingElement.java

diff --git a/Robust/src/Analysis/MLP/ConflictGraph.java b/Robust/src/Analysis/MLP/ConflictGraph.java
index 49ad68ba..138fe11e 100644
--- a/Robust/src/Analysis/MLP/ConflictGraph.java
+++ b/Robust/src/Analysis/MLP/ConflictGraph.java
@@ -16,12 +16,189 @@ import IR.Flat.TempDescriptor;
 
 public class ConflictGraph {
 
+	static private int uniqueCliqueIDcount = 100;
+
 	public Hashtable<String, ConflictNode> id2cn;
 
 	public ConflictGraph() {
 		id2cn = new Hashtable<String, ConflictNode>();
 	}
 
+	public void addPseudoEdgeBetweenReadOnlyNode() {
+
+		Collection<ConflictNode> conflictNodes = id2cn.values();
+		Set<String> analyzedIDSet = new HashSet<String>();
+
+		for (Iterator iterator = conflictNodes.iterator(); iterator.hasNext();) {
+			ConflictNode conflictNode = (ConflictNode) iterator.next();
+			if (isReadOnly(conflictNode)
+					&& conflictNode.getEdgeSet().size() > 0) {
+
+				for (Iterator<ConflictNode> iter = id2cn.values().iterator(); iter
+						.hasNext();) {
+					ConflictNode nextNode = iter.next();
+
+					if (!conflictNode.equals(nextNode)
+							&& nextNode.getEdgeSet().size() > 0
+							&& !analyzedIDSet.contains(conflictNode.getID()
+									+ nextNode.getID())
+							&& !analyzedIDSet.contains(nextNode.getID()
+									+ conflictNode.getID())
+							&& isReadOnly(nextNode)) {
+						if (hasSameReadEffects(conflictNode, nextNode)) {
+							addConflictEdge(ConflictEdge.PSEUDO_EDGE,
+									conflictNode, nextNode);
+						}
+					}
+					analyzedIDSet.add(conflictNode.getID() + nextNode.getID());
+				}
+			}
+		}
+	}
+
+	private boolean hasSameReadEffects(ConflictNode nodeA, ConflictNode nodeB) {
+		
+		StallSiteNode stallSiteNode = null;
+		LiveInNode liveInNode = null;
+		
+		if(nodeA instanceof StallSiteNode && nodeB instanceof StallSiteNode){
+			return hasSameReadEffects((StallSiteNode)nodeA,(StallSiteNode)nodeB);
+		}
+
+		if (nodeA instanceof StallSiteNode) {
+			stallSiteNode = (StallSiteNode) nodeA;
+		} else {
+			liveInNode = (LiveInNode) nodeA;
+		}
+
+		if (nodeB instanceof StallSiteNode) {
+			stallSiteNode = (StallSiteNode) nodeB;
+		} else {
+			liveInNode = (LiveInNode) nodeB;
+		}
+
+		if (stallSiteNode != null) {
+			return hasSameReadEffects(stallSiteNode, liveInNode);
+		} else {
+			return hasSameReadEffects((LiveInNode) nodeA, (LiveInNode) nodeB);
+		}
+
+	}
+
+	private boolean hasSameReadEffects(LiveInNode linA, LiveInNode linB) {
+
+		Set<SESEEffectsKey> readSetA = linA.getReadEffectsSet();
+		Set<SESEEffectsKey> readSetB = linB.getReadEffectsSet();
+
+		boolean returnValue=true;
+		for (Iterator iterator = readSetA.iterator(); iterator.hasNext();) {
+			SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator.next();
+
+			for (Iterator iterator2 = readSetB.iterator(); iterator2.hasNext();) {
+				SESEEffectsKey opr = (SESEEffectsKey) iterator2.next();
+				if (!(seseEffectsKey.getHRNUniqueId()
+						.equals(opr.getHRNUniqueId())
+						&& seseEffectsKey.getFieldDescriptor().equals(
+								opr.getFieldDescriptor()))) {
+					returnValue=false;
+				}
+			}
+		}
+		return returnValue;
+	}
+	
+	private boolean hasSameReadEffects(StallSiteNode ssnA, StallSiteNode ssnB) {
+		
+		HashSet<Effect> effectSetA = ssnA.getStallSite().getEffectSet();
+		HashSet<HeapRegionNode> nodeSetA = ssnA.getStallSite().getHRNSet();
+		HashSet<Effect> effectSetB = ssnB.getStallSite().getEffectSet();
+		HashSet<HeapRegionNode> nodeSetB = ssnA.getStallSite().getHRNSet();
+		boolean returnValue=true;
+		
+		for (Iterator iteratorA = effectSetA.iterator(); iteratorA.hasNext();) {
+			Effect effectKeyA = (Effect) iteratorA.next();
+			for (Iterator iterator2A = nodeSetA.iterator(); iterator2A.hasNext();) {
+				HeapRegionNode hrnA = (HeapRegionNode) iterator2A.next();
+				
+				for (Iterator iteratorB = effectSetB.iterator(); iteratorB.hasNext();) {
+					Effect effectKeyB = (Effect) iteratorB.next();
+					for (Iterator iterator2B = nodeSetB.iterator(); iterator2B.hasNext();) {
+						HeapRegionNode hrnB = (HeapRegionNode) iterator2B.next();
+						
+						if(!(hrnA.getGloballyUniqueIdentifier().equals(hrnB.getGloballyUniqueIdentifier()) && effectKeyA.getField().equals(effectKeyB.getField()))){
+							returnValue=false;
+						}
+					}
+				}
+				
+			}
+			
+		}
+		
+		return returnValue;
+	}
+
+	private boolean hasSameReadEffects(StallSiteNode ssnA, LiveInNode linB) {
+
+		HashSet<Effect> effectSetA = ssnA.getStallSite().getEffectSet();
+		HashSet<HeapRegionNode> nodeSetA = ssnA.getStallSite().getHRNSet();
+
+		Set<SESEEffectsKey> readSetB = linB.getReadEffectsSet();
+		if(readSetB==null){
+			return false;
+		}
+		
+		boolean returnValue=true;
+
+		for (Iterator iterator = effectSetA.iterator(); iterator.hasNext();) {
+			Effect effectKey = (Effect) iterator.next();
+			for (Iterator iterator2 = nodeSetA.iterator(); iterator2.hasNext();) {
+				HeapRegionNode hrn = (HeapRegionNode) iterator2.next();
+
+				for (Iterator iterator3 = readSetB.iterator(); iterator3
+						.hasNext();) {
+					SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator3
+							.next();
+
+					if (!(seseEffectsKey.getHRNUniqueId().equals(
+							hrn.getGloballyUniqueIdentifier())
+							&& seseEffectsKey.getFieldDescriptor().equals(
+									effectKey.getField()))) {
+						returnValue=false;
+					}
+
+				}
+
+			}
+		}
+
+		return returnValue;
+	}
+
+	private boolean isReadOnly(ConflictNode node) {
+
+		if (node instanceof StallSiteNode) {
+			StallSiteNode stallSiteNode = (StallSiteNode) node;
+			HashSet<Effect> effectSet = stallSiteNode.getStallSite()
+					.getEffectSet();
+			for (Iterator iterator = effectSet.iterator(); iterator.hasNext();) {
+				Effect effect = (Effect) iterator.next();
+				if (effect.getEffectType().equals(StallSite.WRITE_EFFECT)) {
+					return false;
+				}
+			}
+		} else {
+			LiveInNode liveInNode = (LiveInNode) node;
+			Set<SESEEffectsKey> writeEffectSet = liveInNode
+					.getWriteEffectsSet();
+			if (writeEffectSet != null && writeEffectSet.size() > 0) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
 	public void analyzeConflicts() {
 
 		Set<String> keySet = id2cn.keySet();
@@ -41,7 +218,7 @@ public class ConflictGraph {
 
 		Set<SESEEffectsKey> writeEffectsSet = nodeB.getWriteEffectsSet();
 		Set<SESEEffectsKey> readEffectsSet = nodeB.getReadEffectsSet();
-		
+
 		if (writeEffectsSet != null) {
 			Iterator<SESEEffectsKey> writeIter = writeEffectsSet.iterator();
 			while (writeIter.hasNext()) {
@@ -75,7 +252,7 @@ public class ConflictGraph {
 				}
 
 			}
-			
+
 		}
 
 		if (readEffectsSet != null) {
@@ -114,7 +291,7 @@ public class ConflictGraph {
 				}
 
 			}
-						
+
 		}
 
 		return result;
@@ -310,16 +487,17 @@ public class ConflictGraph {
 			ConflictNode currentNode) {
 
 		// compare with all nodes
-		
+
 		// examine the case where self-edge exists
-		if(currentNode instanceof LiveInNode){
-			LiveInNode liveInNode=(LiveInNode)currentNode;
-			//Set<SESEEffectsSet> writeSet=liveInNode.getWriteEffectsSet();
-			
-			if(liveInNode.getWriteEffectsSet()!=null && liveInNode.getWriteEffectsSet().size()>0){
+		if (currentNode instanceof LiveInNode) {
+			LiveInNode liveInNode = (LiveInNode) currentNode;
+			// Set<SESEEffectsSet> writeSet=liveInNode.getWriteEffectsSet();
+
+			if (liveInNode.getWriteEffectsSet() != null
+					&& liveInNode.getWriteEffectsSet().size() > 0) {
 				addConflictEdge(ConflictEdge.FINE_GRAIN_EDGE, currentNode,
-				currentNode);
-			}			
+						currentNode);
+			}
 		}
 		//
 
@@ -330,7 +508,7 @@ public class ConflictGraph {
 
 			String entryNodeID = entry.getKey();
 			ConflictNode entryNode = entry.getValue();
-			
+
 			if ((!currentNode.getID().equals(entryNodeID))
 					&& !(analyzedIDSet.contains(currentNode.getID()
 							+ entryNodeID) || analyzedIDSet
@@ -476,15 +654,14 @@ public class ConflictGraph {
 		return resultSet;
 	}
 	
-	public Set<Integer> getConnectedConflictNodeSet(ParentChildConflictsMap conflictsMap){
-		
-		HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+	public Set<WaitingElement> getStallSiteWaitingElementSet(ParentChildConflictsMap conflictsMap, HashSet<SESELock> seseLockSet){
 		
+		HashSet<WaitingElement> waitingElementSet = new HashSet<WaitingElement>();
 		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
+		Collection<StallSite> stallSites = conflictsMap.getStallMap().values();
 		
-		
-		Collection<StallSite> stallSites=conflictsMap.getStallMap().values();
 		for (Iterator iterator = stallSites.iterator(); iterator.hasNext();) {
+
 			StallSite stallSite = (StallSite) iterator.next();
 			Iterator<Entry<String, ConflictNode>> i = s.iterator();
 			while (i.hasNext()) {
@@ -494,36 +671,115 @@ public class ConflictGraph {
 				if (node instanceof StallSiteNode) {
 					StallSiteNode stallSiteNode = (StallSiteNode) node;
 					if (stallSiteNode.getStallSite().equals(stallSite)) {
-						HashSet<ConflictEdge> edgeSet = stallSiteNode.getEdgeSet();
-						for (Iterator iter2 = edgeSet.iterator(); iter2.hasNext();) {
-							ConflictEdge conflictEdge = (ConflictEdge) iter2.next();
-							nodeIDSet.addAll(getConnectedConflictNode(conflictEdge));
+						HashSet<ConflictEdge> edgeSet = stallSiteNode
+								.getEdgeSet();
+						for (Iterator iter2 = edgeSet.iterator(); iter2
+								.hasNext();) {
+							ConflictEdge conflictEdge = (ConflictEdge) iter2
+									.next();
+							
+							int type=-1;
+							HashSet<Integer> allocSet = new HashSet<Integer>();
+							
+							if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) {
+								if (isReadOnly(node)) {
+									type = 2; // coarse read
+								} else {
+									type = 3; // coarse write
+								}
+
+								allocSet.addAll(getAllocSet(conflictEdge
+										.getVertexU()));
+								allocSet.addAll(getAllocSet(conflictEdge
+										.getVertexV()));
+
+							} else if(conflictEdge.getType() == ConflictEdge.FINE_GRAIN_EDGE){// it is fine-grain edge
+								allocSet.addAll(getAllocSet(node));
+								if (isReadOnly(node)) {
+									//fine-grain read
+									type=0;
+								} else {
+									//fine-grain write
+									type=1;
+								}
+							}
+							
+							if(type>-1){
+								 for (Iterator<SESELock> seseLockIter = seseLockSet.iterator(); seseLockIter.hasNext();) {
+									 SESELock seseLock=seseLockIter.next();
+									 if(seseLock.containsConflictNode(stallSiteNode)){
+										 WaitingElement newElement=new WaitingElement();
+										 newElement.setAllocList(allocSet);
+										 newElement.setWaitingID(seseLock.getID());
+										 newElement.setStatus(type);
+										 waitingElementSet.add(newElement);
+									 }
+								 }
+							}
+
 						}
 					}
 				}
 			}
+			
 		}
 		
-		return nodeIDSet;
 		
+		return waitingElementSet;
 	}
-	
-	private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge){
-		
+
+	public Set<Integer> getConnectedConflictNodeSet(
+			ParentChildConflictsMap conflictsMap) {
+
 		HashSet<Integer> nodeIDSet = new HashSet<Integer>();
-		
-		if(conflictEdge.getVertexU() instanceof LiveInNode){
-			LiveInNode lin=(LiveInNode)conflictEdge.getVertexU();
+
+		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
+
+		Collection<StallSite> stallSites = conflictsMap.getStallMap().values();
+		for (Iterator iterator = stallSites.iterator(); iterator.hasNext();) {
+			StallSite stallSite = (StallSite) iterator.next();
+			Iterator<Entry<String, ConflictNode>> i = s.iterator();
+			while (i.hasNext()) {
+				Entry<String, ConflictNode> entry = i.next();
+				ConflictNode node = entry.getValue();
+
+				if (node instanceof StallSiteNode) {
+					StallSiteNode stallSiteNode = (StallSiteNode) node;
+					if (stallSiteNode.getStallSite().equals(stallSite)) {
+						HashSet<ConflictEdge> edgeSet = stallSiteNode
+								.getEdgeSet();
+						for (Iterator iter2 = edgeSet.iterator(); iter2
+								.hasNext();) {
+							ConflictEdge conflictEdge = (ConflictEdge) iter2
+									.next();
+							nodeIDSet
+									.addAll(getConnectedConflictNode(conflictEdge));
+						}
+					}
+				}
+			}
+		}
+
+		return nodeIDSet;
+
+	}
+
+	private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge) {
+
+		HashSet<Integer> nodeIDSet = new HashSet<Integer>();
+
+		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();
+		if (conflictEdge.getVertexV() instanceof LiveInNode) {
+			LiveInNode lin = (LiveInNode) conflictEdge.getVertexV();
 			nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
 		}
-		
+
 		return nodeIDSet;
 	}
-	
+
 	private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge,
 			int seseID) {
 
@@ -560,14 +816,14 @@ public class ConflictGraph {
 
 		return nodeIDSet;
 	}
-	
-	public Set<Integer> getConnectedConflictNodeSet(int seseID){
-		
+
+	public Set<Integer> getConnectedConflictNodeSet(int seseID) {
+
 		HashSet<Integer> nodeIDSet = new HashSet<Integer>();
-		
+
 		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
 		Iterator<Entry<String, ConflictNode>> i = s.iterator();
-		
+
 		while (i.hasNext()) {
 			Entry<String, ConflictNode> entry = i.next();
 			ConflictNode node = entry.getValue();
@@ -576,22 +832,96 @@ public class ConflictGraph {
 				LiveInNode liveInNode = (LiveInNode) node;
 				if (liveInNode.getSESEIdentifier() == seseID) {
 					HashSet<ConflictEdge> edgeSet = liveInNode.getEdgeSet();
-					for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
-						ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
+					for (Iterator iterator = edgeSet.iterator(); iterator
+							.hasNext();) {
+						ConflictEdge conflictEdge = (ConflictEdge) iterator
+								.next();
 						//
-						nodeIDSet.addAll(getConnectedConflictNode(conflictEdge,seseID));
+						nodeIDSet.addAll(getConnectedConflictNode(conflictEdge,
+								seseID));
 						//
 					}
 				}
 			}
 		}
-		
+
 		return nodeIDSet;
+
+	}
+
+	public Set<WaitingElement> getWaitingElementSetBySESEID(int seseID,
+			HashSet<SESELock> seseLockSet) {
+
+		HashSet<WaitingElement> waitingElementSet = new HashSet<WaitingElement>();
 		
+		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
+		Iterator<Entry<String, ConflictNode>> i = s.iterator();
+
+		while (i.hasNext()) {
+			Entry<String, ConflictNode> entry = i.next();
+			ConflictNode node = entry.getValue();
+
+			if (node instanceof LiveInNode) {
+				LiveInNode liveInNode = (LiveInNode) node;
+				if (liveInNode.getSESEIdentifier() == seseID) {
+					
+					HashSet<ConflictEdge> edgeSet = liveInNode.getEdgeSet();
+
+					for (Iterator iterator = edgeSet.iterator(); iterator
+							.hasNext();) {
+						ConflictEdge conflictEdge = (ConflictEdge) iterator
+								.next();
+						int type=-1;
+						HashSet<Integer> allocSet = new HashSet<Integer>();
+						
+						if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE) {
+							if (isReadOnly(node)) {
+								type = 2; // coarse read
+							} else {
+								type = 3; // coarse write
+							}
+
+							allocSet.addAll(getAllocSet(conflictEdge
+									.getVertexU()));
+							allocSet.addAll(getAllocSet(conflictEdge
+									.getVertexV()));
+
+						} else if(conflictEdge.getType() == ConflictEdge.FINE_GRAIN_EDGE){// it is fine-grain edge
+							allocSet.addAll(getAllocSet(node));
+							if (isReadOnly(node)) {
+								//fine-grain read
+								type=0;
+							} else {
+								//fine-grain write
+								type=1;
+							}
+						}
+						
+						if(type>-1){
+							
+							 for (Iterator<SESELock> seseLockIter = seseLockSet.iterator(); seseLockIter.hasNext();) {
+								 SESELock seseLock=seseLockIter.next();
+								 if(seseLock.containsConflictNode(liveInNode)){
+									 WaitingElement newElement=new WaitingElement();
+									 newElement.setAllocList(allocSet);
+									 newElement.setWaitingID(seseLock.getID());
+									 newElement.setStatus(type);
+									 waitingElementSet.add(newElement);
+								 }
+							 }
+						}
+					}
+
+				}
+			}
+
+		}
+
+		return waitingElementSet;
 	}
 
 	public Set<Long> getAllocationSiteIDSetBySESEID(int seseID) {
-
+		// deprecated
 		HashSet<Long> allocSiteIDSet = new HashSet<Long>();
 
 		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
@@ -605,19 +935,25 @@ public class ConflictGraph {
 				LiveInNode liveInNode = (LiveInNode) node;
 				if (liveInNode.getSESEIdentifier() == seseID) {
 					HashSet<ConflictEdge> edgeSet = liveInNode.getEdgeSet();
-					for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
-						ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
+					for (Iterator iterator = edgeSet.iterator(); iterator
+							.hasNext();) {
+						ConflictEdge conflictEdge = (ConflictEdge) iterator
+								.next();
 						//
-						getConnectedConflictNode(conflictEdge,seseID);
+						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(conflictEdge
+											.getVertexU()));
+							allocSiteIDSet
+									.addAll(getHRNIdentifierSet(conflictEdge
+											.getVertexV()));
+						} else {// it is fine-grain edge
 							allocSiteIDSet.addAll(getHRNIdentifierSet(node));
 						}
 					}
-					
+
 				}
 			}
 		}
@@ -625,29 +961,29 @@ public class ConflictGraph {
 		return allocSiteIDSet;
 
 	}
-	
+
 	public Set<Long> getAllocationSiteIDSetofStallSite() {
-		
+
 		HashSet<Long> allocSiteIDSet = new HashSet<Long>();
 
 		Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
 		Iterator<Entry<String, ConflictNode>> i = s.iterator();
-		
+
 		while (i.hasNext()) {
-			
+
 			Entry<String, ConflictNode> entry = i.next();
 			ConflictNode node = entry.getValue();
-			
-			if(node instanceof StallSiteNode){
+
+			if (node instanceof StallSiteNode) {
 				allocSiteIDSet.addAll(getHRNIdentifierSet(node));
 			}
-			
+
 		}
-		
+
 		return allocSiteIDSet;
-		
+
 	}
-	
+
 	public Set<Long> getAllocationSiteIDSet() {
 
 		HashSet<Long> allocSiteIDSet = new HashSet<Long>();
@@ -658,14 +994,16 @@ public class ConflictGraph {
 		while (i.hasNext()) {
 			Entry<String, ConflictNode> entry = i.next();
 			ConflictNode node = entry.getValue();
-			
+
 			HashSet<ConflictEdge> 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(conflictEdge
+							.getVertexU()));
+					allocSiteIDSet.addAll(getHRNIdentifierSet(conflictEdge
+							.getVertexV()));
+				} else {// it is fine-grain edge
 					allocSiteIDSet.addAll(getHRNIdentifierSet(node));
 				}
 			}
@@ -676,6 +1014,31 @@ public class ConflictGraph {
 
 	}
 
+	private HashSet<Integer> getAllocSet(ConflictNode node) {
+
+		HashSet<Integer> returnSet = new HashSet<Integer>();
+
+		if (node instanceof StallSiteNode) {
+			StallSiteNode stallSiteNode = (StallSiteNode) node;
+			Set<HeapRegionNode> hrnSet = stallSiteNode.getHRNSet();
+			for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
+				HeapRegionNode hrn = (HeapRegionNode) iterator.next();
+				// allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
+				returnSet.add(new Integer(hrn.getAllocationSite().getID()));
+			}
+		} else {
+			LiveInNode liveInNode = (LiveInNode) node;
+			Set<HeapRegionNode> hrnSet = liveInNode.getHRNSet();
+			for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
+				HeapRegionNode hrn = (HeapRegionNode) iterator.next();
+				// allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
+				returnSet.add(new Integer(hrn.getAllocationSite().getID()));
+			}
+		}
+
+		return returnSet;
+	}
+
 	private HashSet<Long> getHRNIdentifierSet(ConflictNode node) {
 
 		HashSet<Long> returnSet = new HashSet<Long>();
@@ -686,8 +1049,8 @@ public class ConflictGraph {
 			for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
 				HeapRegionNode hrn = (HeapRegionNode) iterator.next();
 				// allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
-				returnSet.add(new Long(hrn
-						.getGloballyUniqueIntegerIdentifier()));
+				returnSet
+						.add(new Long(hrn.getGloballyUniqueIntegerIdentifier()));
 			}
 		} else {
 			LiveInNode liveInNode = (LiveInNode) node;
@@ -695,8 +1058,8 @@ public class ConflictGraph {
 			for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
 				HeapRegionNode hrn = (HeapRegionNode) iterator.next();
 				// allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
-				returnSet.add(new Long(hrn
-						.getGloballyUniqueIntegerIdentifier()));
+				returnSet
+						.add(new Long(hrn.getGloballyUniqueIntegerIdentifier()));
 			}
 		}
 
@@ -704,6 +1067,24 @@ public class ConflictGraph {
 
 	}
 
+	public HashSet<ConflictEdge> getEdgeSet() {
+
+		HashSet<ConflictEdge> returnSet = new HashSet<ConflictEdge>();
+
+		Collection<ConflictNode> nodes = id2cn.values();
+		for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
+			ConflictNode conflictNode = (ConflictNode) iterator.next();
+			returnSet.addAll(conflictNode.getEdgeSet());
+		}
+
+		return returnSet;
+	}
+
+	static public int generateUniqueCliqueID() {
+		++uniqueCliqueIDcount;
+		return uniqueCliqueIDcount;
+	}
+
 	public void writeGraph(String graphName, boolean filter)
 			throws java.io.IOException {
 
@@ -767,9 +1148,9 @@ public class ConflictGraph {
 				}
 
 				if (!addedSet.contains(conflictEdge)) {
-					bw.write(" " + u.getID() + "--" + v.getID() + "[label=\""
+					bw.write(" " + u.getID() + "--" + v.getID() + "[label="
 							+ conflictEdge.toGraphEdgeString()
-							+ "\",decorate];\n");
+							+ ",decorate];\n");
 					addedSet.add(conflictEdge);
 				}
 
@@ -794,6 +1175,7 @@ class ConflictEdge {
 	public static final int NON_WRITE_CONFLICT = 0;
 	public static final int FINE_GRAIN_EDGE = 1;
 	public static final int COARSE_GRAIN_EDGE = 2;
+	public static final int PSEUDO_EDGE = 3;
 
 	public ConflictEdge(ConflictNode u, ConflictNode v, int type) {
 		this.u = u;
@@ -803,9 +1185,13 @@ class ConflictEdge {
 
 	public String toGraphEdgeString() {
 		if (type == FINE_GRAIN_EDGE) {
-			return "F_CONFLICT";
+			return "\"F_CONFLICT\"";
+		} else if (type == COARSE_GRAIN_EDGE) {
+			return "\"C_CONFLICT\"";
+		} else if (type == PSEUDO_EDGE) {
+			return "\"P_CONFLICT\", style=dotted";
 		} else {
-			return "C_CONFLICT";
+			return "CONFLICT\"";
 		}
 	}
 
diff --git a/Robust/src/Analysis/MLP/ConflictNode.java b/Robust/src/Analysis/MLP/ConflictNode.java
index 5b2973a1..bfeb2f51 100644
--- a/Robust/src/Analysis/MLP/ConflictNode.java
+++ b/Robust/src/Analysis/MLP/ConflictNode.java
@@ -15,7 +15,7 @@ public abstract class ConflictNode {
 	public ConflictNode() {
 		edgeSet = new HashSet<ConflictEdge>();
 	}
-
+	
 	public TempDescriptor getTempDescriptor() {
 		return td;
 	}
diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java
index 81aa04c9..b4ef4021 100644
--- a/Robust/src/Analysis/MLP/MLPAnalysis.java
+++ b/Robust/src/Analysis/MLP/MLPAnalysis.java
@@ -106,6 +106,7 @@ public class MLPAnalysis {
   private HashSet<PreEffectsKey> preeffectsSet;
   private Hashtable<FlatNode, Boolean> isAfterChildSESEIndicatorMap;
   private Hashtable<FlatNode, SESESummary> seseSummaryMap;
+  private Hashtable<ConflictGraph, HashSet<SESELock>> conflictGraphLockMap;
 
   public static int maxSESEage = -1;
 
@@ -167,6 +168,7 @@ public class MLPAnalysis {
     
     seseSummaryMap= new Hashtable<FlatNode, SESESummary>();
     isAfterChildSESEIndicatorMap= new Hashtable<FlatNode, Boolean>();
+    conflictGraphLockMap=new Hashtable<ConflictGraph, HashSet<SESELock>>();
 
     FlatMethod fmMain = state.getMethodFlat( typeUtil.getMain() );
 
@@ -298,6 +300,9 @@ public class MLPAnalysis {
         //	postSESEConflictsForward(javaCallGraph);
     	// another pass for making graph
     	makeConflictGraph();
+    	
+    	// lock synthesis
+    	synthesizeLocks();
     	/*
     	methItr = ownAnalysis.descriptorsToAnalyze.iterator();
     	while (methItr.hasNext()) {
@@ -1189,6 +1194,14 @@ public class MLPAnalysis {
 			if (!fsen.getIsCallerSESEplaceholder()) {
 				// uniquely taint each live-in variable
 				Set<TempDescriptor> set = fsen.getInVarSet();
+				//
+//				Set<TempDescriptor> tempSet=fsen.getOutVarSet();
+//				for (Iterator iterator = tempSet.iterator(); iterator.hasNext();) {
+//					TempDescriptor tempDescriptor = (TempDescriptor) iterator
+//							.next();
+//					set.add(tempDescriptor);
+//				}
+				//
 				Iterator<TempDescriptor> iter = set.iterator();
 				int idx = 0;
 				while (iter.hasNext()) {
@@ -1343,7 +1356,7 @@ public class MLPAnalysis {
 				while (affectedIter.hasNext()) {
 					TempDescriptor affectedTD = affectedIter.next();
 
-					if (currentSESE.getInVarSet().contains(affectedTD)) {
+					if (currentSESE.getInVarSet().contains(affectedTD) || ((!currentSESE.getInVarSet().contains(affectedTD)) && currentSESE.getOutVarSet().contains(affectedTD)) ) {
 
 						HashSet<HeapRegionNode> hrnSet = getReferenceHeapIDSet(
 								og, affectedTD);
@@ -1474,7 +1487,7 @@ public class MLPAnalysis {
 
 				while (affectedIter.hasNext()) {
 					TempDescriptor affectedTD = affectedIter.next();
-					if (currentSESE.getInVarSet().contains(affectedTD)) {
+					if (currentSESE.getInVarSet().contains(affectedTD) || ((!currentSESE.getInVarSet().contains(affectedTD)) && currentSESE.getOutVarSet().contains(affectedTD)) ) {
 
 						HashSet<HeapRegionNode> hrnSet = getReferenceHeapIDSet(
 								og, affectedTD);
@@ -1491,7 +1504,6 @@ public class MLPAnalysis {
 
 									HeapRegionNode refHRN = og.id2hrn
 											.get(referenceEdge.getDst().getID());
-									System.out.println("refHRN=" + refHRN);
 									currentSESE.writeEffects(affectedTD, field
 											.getSymbol(), dst.getType(),
 											refHRN, strongUpdate);
@@ -1650,7 +1662,6 @@ public class MLPAnalysis {
 
 										HeapRegionNode refHRN = og.id2hrn
 												.get(hrnID);
-
 										currentSESE.writeEffects(affectedTD,
 												key.getFieldDescriptor(), key
 														.getTypeDescriptor(),
@@ -1677,7 +1688,6 @@ public class MLPAnalysis {
 
 										HeapRegionNode refHRN = og.id2hrn
 												.get(hrnID);
-
 										currentSESE.writeEffects(affectedTD,
 												key.getFieldDescriptor(), key
 														.getTypeDescriptor(),
@@ -1921,84 +1931,82 @@ public class MLPAnalysis {
 		return sorted;
 	}
 	
-	private void makeConflictGraph2(FlatMethod fm) {
-
-		HashSet<MethodContext> mcSet = ownAnalysisForSESEConflicts
-				.getAllMethodContextSetByDescriptor(fm.getMethod());
-		Iterator<MethodContext> mcIter = mcSet.iterator();
-
-		while (mcIter.hasNext()) {
-			MethodContext mc = mcIter.next();
-
-			Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-			flatNodesToVisit.add(fm);
-
-			Set<FlatNode> visited = new HashSet<FlatNode>();
-			
-			SESESummary summary = new SESESummary(null, fm);
-			seseSummaryMap.put(fm, summary);
-
-			while (!flatNodesToVisit.isEmpty()) {
-				Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
-				FlatNode fn = fnItr.next();
-
-				flatNodesToVisit.remove(fn);
-				visited.add(fn);
-			
-				// ///////////////////////////////////////////////////////////////////////
-				// Adding Stall Node of current program statement
-				ParentChildConflictsMap currentConflictsMap = conflictsResults
-						.get(fn);
-
-				Hashtable<TempDescriptor, StallSite> stallMap = currentConflictsMap
-						.getStallMap();
-				Set<Entry<TempDescriptor, StallSite>> entrySet = stallMap
-						.entrySet();
-				
-				
-				SESESummary seseSummary=seseSummaryMap.get(fn);
-				
-				ConflictGraph conflictGraph=null;
-				conflictGraph=conflictGraphResults.get(seseSummary.getCurrentSESE());
-				
-				if(conflictGraph==null){
-					conflictGraph = new ConflictGraph();
-				}
-				for (Iterator<Entry<TempDescriptor, StallSite>> iterator2 = entrySet
-						.iterator(); iterator2.hasNext();) {
-					Entry<TempDescriptor, StallSite> entry = iterator2.next();
-					TempDescriptor td = entry.getKey();
-					StallSite stallSite = entry.getValue();
-
-					// reachability set
-					OwnershipGraph og = ownAnalysisForSESEConflicts
-							.getOwnvershipGraphByMethodContext(mc);
-					Set<Set> reachabilitySet = calculateReachabilitySet(og, td);
-					conflictGraph.addStallNode(td, fm, stallSite,
-							reachabilitySet);
-					
-				}
-				
-				if(conflictGraph.id2cn.size()>0){
-					conflictGraphResults.put(seseSummary.getCurrentSESE(), conflictGraph);
-				}
-
-				conflictGraph_nodeAction(mc, fm, fn);
-				
-				for (int i = 0; i < fn.numNext(); i++) {
-					FlatNode nn = fn.getNext(i);
-					if (!visited.contains(nn)) {
-						flatNodesToVisit.add(nn);
+	private void calculateCliqueCovering(ConflictGraph conflictGraph) {
+
+		HashSet<ConflictEdge> tocover = conflictGraph.getEdgeSet();
+		HashSet<SESELock> lockSet=new HashSet<SESELock>();
+
+		while (!tocover.isEmpty()) {
+			ConflictEdge edge = (ConflictEdge) tocover.iterator().next();
+			tocover.remove(edge);
+
+			SESELock seseLock = new SESELock();
+			seseLock.addEdge(edge);
+
+			boolean changed = false;
+			do {
+				changed = false;
+				for (Iterator edgeit = tocover.iterator(); edgeit.hasNext();) {
+					ConflictEdge newEdge = (ConflictEdge) edgeit.next();
+					if (newEdge.getVertexU() == newEdge.getVertexV()
+							&& seseLock.containsConflictNode(newEdge
+									.getVertexU())) {
+						// for self-edge case
+						tocover.remove(newEdge);
+						changed = true;
+						break;// exit iterator loop
+					} else if (seseLock.testEdge(newEdge)) {
+
+						ConflictNode nodeToAdd = seseLock
+								.containsConflictNode(newEdge.getVertexU()) ? newEdge
+								.getVertexV()
+								: newEdge.getVertexU();
+
+						for (Iterator newEdgeIter = nodeToAdd.getEdgeSet()
+								.iterator(); newEdgeIter.hasNext();) {
+							ConflictEdge ne = (ConflictEdge) newEdgeIter.next();
+							if (seseLock.containsConflictNode(ne.getVertexU())) {
+								tocover.remove(ne);
+							} else if (seseLock.containsConflictNode(ne
+									.getVertexV())) {
+								tocover.remove(ne);
+							}
+						}
+						// Add in new node to lockset
+						seseLock.addEdge(newEdge);
+						changed = true;
+						break; // exit iterator loop
 					}
-				}
-			} // end of while(flatNodesToVisit)
-
-		} // end of while(mcIter)
 
-		// decide fine-grain edge or coarse-grain edge among all vertexes by pair-wise comparison
+				}
+			} while (changed);
+			seseLock.setID(ConflictGraph.generateUniqueCliqueID());
+			lockSet.add(seseLock);
 
+		}// end of while
+		
+		//build map from synthsized locks to conflict graph
+		conflictGraphLockMap.put(conflictGraph, lockSet);
+		
 	}
+
 	
+	private void synthesizeLocks(){
+		
+//		conflictGraphResults.put(seseSummary.getCurrentSESE(),
+//				conflictGraph);
+		
+		Set<Entry<FlatNode,ConflictGraph>> graphEntrySet=conflictGraphResults.entrySet();
+		for (Iterator iterator = graphEntrySet.iterator(); iterator.hasNext();) {
+			Entry<FlatNode, ConflictGraph> graphEntry = (Entry<FlatNode, ConflictGraph>) iterator
+					.next();
+			FlatNode sese=graphEntry.getKey();
+			ConflictGraph conflictGraph=graphEntry.getValue();
+			calculateCliqueCovering(conflictGraph);
+		}
+		
+	}
+
 	private void makeConflictGraph() {
 		Iterator<Descriptor> methItr = ownAnalysis.descriptorsToAnalyze
 				.iterator();
@@ -2089,6 +2097,16 @@ public class MLPAnalysis {
 			FlatNode flatNode = (FlatNode) keyEnum1.nextElement();
 			ConflictGraph conflictGraph=conflictGraphResults.get(flatNode);
 			conflictGraph.analyzeConflicts();
+			conflictGraph.addPseudoEdgeBetweenReadOnlyNode();
+			conflictGraphResults.put(flatNode, conflictGraph);
+		}
+		
+		// add pseudo-edge for a pair of read-only node
+    	keyEnum1=conflictGraphResults.keys();
+		while (keyEnum1.hasMoreElements()) {
+			FlatNode flatNode = (FlatNode) keyEnum1.nextElement();
+			ConflictGraph conflictGraph=conflictGraphResults.get(flatNode);
+//			conflictGraph.analyzeConflicts();
 			conflictGraphResults.put(flatNode, conflictGraph);
 		}
 		
@@ -2128,23 +2146,6 @@ public class MLPAnalysis {
 		return reachabilitySet;
 	}
 	
-	private void conflictGraph_nodeAction2(MethodContext mc, FlatMethod fm,
-			FlatNode fn, ConflictGraph graph,
-			ParentChildConflictsMap currentConflictsMap) {
-		
-		switch (fn.kind()) {
-
-		case FKind.FlatSESEEnterNode: {
-			
-		}break;
-		
-		
-		
-		}
-		
-		
-	}
-	
 	private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm,
 			FlatNode fn) {
 
@@ -2184,7 +2185,12 @@ public class MLPAnalysis {
 							tempDescriptor);
 
 					// add new live-in node
-					LabelNode ln = og.td2ln.get(tempDescriptor);
+//					LabelNode ln = og.td2ln.get(tempDescriptor);
+					
+					OwnershipGraph lastOG = ownAnalysis
+					.getOwnvershipGraphByMethodContext(mc);
+					LabelNode ln = lastOG.td2ln.get(tempDescriptor);
+					
 					Set<HeapRegionNode> hrnSet = new HashSet<HeapRegionNode>();
 					Iterator<ReferenceEdge> refIter = ln
 							.iteratorToReferencees();
@@ -3406,4 +3412,8 @@ public class MLPAnalysis {
 	  return seseSummaryMap;
   }
   
+  public Hashtable<ConflictGraph, HashSet<SESELock>> getConflictGraphLockMap(){
+	  return conflictGraphLockMap;
+  }
+  
 }
diff --git a/Robust/src/Analysis/MLP/SESELock.java b/Robust/src/Analysis/MLP/SESELock.java
new file mode 100644
index 00000000..ce37cf0e
--- /dev/null
+++ b/Robust/src/Analysis/MLP/SESELock.java
@@ -0,0 +1,70 @@
+package Analysis.MLP;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class SESELock {
+	
+	private HashSet<ConflictNode> conflictNodeSet;
+	private int id;
+	
+	public SESELock(){
+		conflictNodeSet=new HashSet<ConflictNode>();
+	}
+	
+	public void addEdge(ConflictEdge edge){
+		conflictNodeSet.add(edge.getVertexU());
+		conflictNodeSet.add(edge.getVertexV());
+	}
+	
+	public int getID(){
+		return id;
+	}
+	
+	public void setID(int id){
+		this.id=id;
+	}
+	
+	public boolean containsConflictNode(ConflictNode node){
+		
+		return conflictNodeSet.contains(node);		
+		
+	}
+	
+	
+	public boolean testEdge(ConflictEdge newEdge){
+		
+		
+		if( !conflictNodeSet.contains(newEdge.getVertexU()) && !conflictNodeSet.contains(newEdge.getVertexV()) ){
+			return false;
+		}
+		
+		ConflictNode nodeToAdd=conflictNodeSet.contains(newEdge.getVertexU())?newEdge.getVertexV():newEdge.getVertexU();
+		
+		HashSet<ConflictNode> nodeSet=new HashSet<ConflictNode>(conflictNodeSet);
+
+		for(Iterator edgeIter=nodeToAdd.getEdgeSet().iterator();edgeIter.hasNext();){
+			ConflictEdge edge=(ConflictEdge)edgeIter.next();
+			if(nodeSet.contains(edge.getVertexU())){
+				nodeSet.remove(edge.getVertexU());
+			}else if(nodeSet.contains(edge.getVertexV())){
+				nodeSet.remove(edge.getVertexV());
+			}
+		}
+		
+		return nodeSet.isEmpty();
+		
+	}
+	
+	public String toString(){
+		String rtr="";
+		
+		for (Iterator<ConflictNode> iterator = conflictNodeSet.iterator(); iterator.hasNext();) {
+			ConflictNode node = (ConflictNode) iterator.next();
+			rtr+=" "+node;
+		}
+		
+		return rtr;
+	}
+
+}
diff --git a/Robust/src/Analysis/MLP/WaitingElement.java b/Robust/src/Analysis/MLP/WaitingElement.java
new file mode 100644
index 00000000..ccaf4fa2
--- /dev/null
+++ b/Robust/src/Analysis/MLP/WaitingElement.java
@@ -0,0 +1,39 @@
+package Analysis.MLP;
+
+import java.util.HashSet;
+
+public class WaitingElement {
+
+	private int waitingID;
+	private int status;
+	private HashSet<Integer> allocList;
+
+	public WaitingElement() {
+		this.allocList = new HashSet<Integer>();
+	}
+
+	public void setWaitingID(int waitingID) {
+		this.waitingID = waitingID;
+	}
+
+	public int getWaitingID() {
+		return waitingID;
+	}
+
+	public void setStatus(int status) {
+		this.status = status;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+
+	public HashSet<Integer> getAllocList() {
+		return allocList;
+	}
+
+	public void setAllocList(HashSet<Integer> allocList) {
+		this.allocList.addAll(allocList);
+	}
+
+}
\ No newline at end of file
diff --git a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java
index d6616e67..5e5ae9f2 100644
--- a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java
+++ b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java
@@ -206,4 +206,8 @@ public class AllocationSite {
   public boolean getFlag(){
 	  return flag;
   }
+  
+  public int getID(){
+	  return id;
+  }
 }
diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java
index 14a6fe39..f423bb98 100644
--- a/Robust/src/IR/Flat/BuildCode.java
+++ b/Robust/src/IR/Flat/BuildCode.java
@@ -30,9 +30,11 @@ import Analysis.Locality.TypeAnalysis;
 import Analysis.MLP.ConflictGraph;
 import Analysis.MLP.MLPAnalysis;
 import Analysis.MLP.ParentChildConflictsMap;
+import Analysis.MLP.SESELock;
 import Analysis.MLP.VariableSourceToken;
 import Analysis.MLP.CodePlan;
 import Analysis.MLP.SESEandAgePair;
+import Analysis.MLP.WaitingElement;
 
 public class BuildCode {
   State state;
@@ -1785,25 +1787,27 @@ public class BuildCode {
       // set up related allocation sites's waiting queues
       // eom
       output.println("   /* set up waiting queues */");
-      output.println("   int numRelatedAllocSites=0;");    		
+      output.println("   int numRelatedWaitingQueue=0;");
+      output.println("   int waitingQueueItemID=0;");
       ConflictGraph graph=null;
       graph=mlpa.getConflictGraphResults().get(fm);
       if(graph!=null){
-    	  Set<Long> allocSet=graph.getAllocationSiteIDSet();
+    	  HashSet<SESELock> lockSet=mlpa.getConflictGraphLockMap().get(graph);
     	  
-    	  if(allocSet.size()>0){
-    		  output.println("   numRelatedAllocSites="+allocSet.size()+";");    		  
-        	  output.println("   seseCaller->numRelatedAllocSites=numRelatedAllocSites;");        	  
-        	  output.println("   seseCaller->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);");
-        	  int idx=0;
-        	  for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) {
-        		 Long allocID = (Long) iterator.next();
-      			output.println("   seseCaller->allocSiteArray["+idx+"].id="+allocID+";");
+    	  if(lockSet.size()>0){
+    		  output.println("   numRelatedWaitingQueue="+lockSet.size()+";");    	
+    		  output.println("   seseCaller->numRelatedWaitingQueue=numRelatedWaitingQueue;");
+    		  output.println("   seseCaller->allocSiteArray=mlpCreateAllocSiteArray(numRelatedWaitingQueue);");
+    		  int idx=0;
+        	  for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
+        		SESELock seseLock = (SESELock) iterator.next();
+      			output.println("   seseCaller->allocSiteArray["+idx+"].id="+seseLock.getID()+";");
       			idx++;
           	  }
         	  output.println();
     	  }
       }
+      
     }
 
 
@@ -2088,33 +2092,33 @@ public class BuildCode {
     // set up related allocation sites's waiting queues
     // eom
     output.println("   /* set up waiting queues */");
-    output.println("   int numRelatedAllocSites=0;");    		
+    output.println("   int numRelatedWaitingQueue=0;");
+    output.println("   int waitingQueueItemID=0;");
     ConflictGraph graph=null;
     graph=mlpa.getConflictGraphResults().get(fsen);
 	if (graph != null) {
 		output.println("   {");
 		output.println("   SESEcommon* parentCommon = &(___params___->common);");
-		Set<Long> allocSet = graph.getAllocationSiteIDSet();
-		if (allocSet.size() > 0) {
-			output.println("   numRelatedAllocSites=" + allocSet.size()
+		HashSet<SESELock> lockSet=mlpa.getConflictGraphLockMap().get(graph);
+	  	  
+		if (lockSet.size() > 0) {
+			output.println("   numRelatedWaitingQueue=" + lockSet.size()
 					+ ";");
 			output
-					.println("   parentCommon->numRelatedAllocSites=numRelatedAllocSites;");
+					.println("   parentCommon->numRelatedWaitingQueue=numRelatedWaitingQueue;");
 			output
-					.println("   parentCommon->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);");
+					.println("   parentCommon->allocSiteArray=mlpCreateAllocSiteArray(numRelatedWaitingQueue);");
 			int idx = 0;
-			for (Iterator iterator = allocSet.iterator(); iterator
-					.hasNext();) {
-				Long allocID = (Long) iterator.next();
+			for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
+				SESELock seseLock = (SESELock) iterator.next();
 				output.println("   parentCommon->allocSiteArray[" + idx
-						+ "].id=" + allocID + ";");
+						+ "].id=" + seseLock.getID() + ";");
 				idx++;
 			}
 			output.println();
 		}
 		output.println("   }");
 	}
-    
 
     // copy in-set into place, ready vars were already 
     // copied when the SESE was issued
@@ -2728,65 +2732,65 @@ public class BuildCode {
     
     ParentChildConflictsMap conflictsMap=mlpa.getConflictsResults().get(fn);
     
-		if (conflictsMap != null) {
+	if (conflictsMap != null) {
 
-			Set<Long> allocSet = conflictsMap
-					.getAllocationSiteIDSetofStallSite();
+		Set<Long> allocSet = conflictsMap
+				.getAllocationSiteIDSetofStallSite();
+		
+		if (allocSet.size() > 0) {
 			
-			if (allocSet.size() > 0) {
-				
-				FlatNode enclosingFlatNode=null;
-				if( currentSESE.getIsCallerSESEplaceholder() && currentSESE.getParent()==null){
-					enclosingFlatNode=currentSESE.getfmEnclosing();
-				}else{
-					enclosingFlatNode=currentSESE;
-				}
-				
-				ConflictGraph graph=mlpa.getConflictGraphResults().get(enclosingFlatNode);
-				Set<Integer> connectedSet=graph.getConnectedConflictNodeSet(conflictsMap);
-
-				if(connectedSet.size()>0){
-					output.println("   /*  stall on parent's stall sites */");
-					output.println("   //"+connectedSet);
-					output.println("  {");
-					output.println("     pthread_mutex_lock( &(seseCaller->lock) );");
-				    //
-					output.println("     ConflictNode* node;");
-					for (Iterator iterator = connectedSet.iterator(); iterator
-							.hasNext();) {
-						Integer integer = (Integer) iterator.next();
-						//output.print(" "+integer);
-						if(integer.intValue()<0){
-							output.println("     node=mlpCreateConflictNode(seseCaller->classID);");
-						}else{
-							output.println("     node=mlpCreateConflictNode( "+integer+" );");
-						}
-						output.println("     addNewConflictNode(node, seseCaller->connectedList);");
-					}
-					//
+			FlatNode enclosingFlatNode=null;
+			if( currentSESE.getIsCallerSESEplaceholder() && currentSESE.getParent()==null){
+				enclosingFlatNode=currentSESE.getfmEnclosing();
+			}else{
+				enclosingFlatNode=currentSESE;
+			}
+			
+			ConflictGraph graph=mlpa.getConflictGraphResults().get(enclosingFlatNode);
+			HashSet<SESELock> seseLockSet=mlpa.getConflictGraphLockMap().get(graph);
+			Set<WaitingElement> waitingElementSet=graph.getStallSiteWaitingElementSet(conflictsMap, seseLockSet);
+
+			if(waitingElementSet.size()>0){
+				output.println("   /*  stall on parent's stall sites */");
+				output.println("  {");
+				output.println("     pthread_mutex_lock( &(seseCaller->lock) );");
+				output.println("     ConflictNode* node;");
+				output.println("     struct Queue* list=NULL;");
+				output.println("     WaitingElement* newElement=NULL;");
+				output.println("     struct QueueItem* newQItem=NULL;");
+				output.println("     waitingQueueItemID++;");
+				output.println("     psem_init( &(seseCaller->memoryStallSiteSem) );");
+				output.println("     int qIdx;");
+				output.println("     int takeCount=0;");
+				for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+					WaitingElement waitingElement = (WaitingElement) iterator.next();
 					
-					output.println("     psem_init( &(seseCaller->memoryStallSiteSem) );");
-					output.println("     int qIdx;");
-					output.println("     int takeCount=0;");
-					for (Iterator iterator = allocSet.iterator(); iterator
-							.hasNext();) {
-						Long allocID = (Long) iterator.next();
-						output.println("     qIdx=getQueueIdx(seseCaller->allocSiteArray,numRelatedAllocSites,"
-										+ allocID + ");");
-						output.println("     if(qIdx!=-1 && !isEmpty(seseCaller->allocSiteArray[qIdx].waitingQueue)){");
-						output.println("        addNewItemBack(seseCaller->allocSiteArray[qIdx].waitingQueue,seseCaller);");
-						output.println("        takeCount++;");
-						output.println("     }");
+					output.println("     qIdx=getQueueIdx(seseCaller->allocSiteArray,numRelatedWaitingQueue,"
+									+ waitingElement.getWaitingID() + ");");
+					output.println("     if(qIdx!=-1 && !isEmpty(seseCaller->allocSiteArray[qIdx].waitingQueue)){");
+					output.println("     list=createQueue();");
+					for (Iterator iterator2 = waitingElement.getAllocList().iterator(); iterator2.hasNext();) {
+						Integer allocID = (Integer) iterator2	.next();
+						output.println("     node=mlpCreateConflictNode( "+ allocID + " );");
+						output.println("     addNewItem(list,node);");
 					}
-					output.println("     pthread_mutex_unlock( &(seseCaller->lock) );");
-					output.println("     if( takeCount>0 ){");
-					output.println("        psem_take( &(seseCaller->memoryStallSiteSem) );");
+					output.println("     newElement=mlpCreateWaitingElement( "+ waitingElement.getStatus()
+							+ ", seseCaller, list, waitingQueueItemID );");
+					output.println("        addNewItemBack(seseCaller->allocSiteArray[qIdx].waitingQueue,newElement);");
+					output.println("        takeCount++;");
 					output.println("     }");
-					output.println("  }");
+	
 				}
-
+				
+				output.println("     pthread_mutex_unlock( &(seseCaller->lock) );");
+				output.println("     if( takeCount>0 ){");
+				output.println("        psem_take( &(seseCaller->memoryStallSiteSem) );");
+				output.println("     }");
+				output.println("  }");
 			}
+
 		}
+	} // end of if (conflictsMap != null) {		
       }     
     }
 
@@ -3397,44 +3401,47 @@ public class BuildCode {
         }
     }
 		if (graph != null) {
+			
+			HashSet<SESELock> seseLockSet=mlpa.getConflictGraphLockMap().get(graph);
+			
 			output.println();
 			output.println("     /*add waiting queue element*/");
 			output.println("     struct Queue*  newWaitingItemQueue=createQueue();");
-			output.println("     struct QueueItem* newQItem=NULL;");
-
-			Set<Long> allocSet = graph.getAllocationSiteIDSetBySESEID(fsen
-					.getIdentifier());
-			Set<Integer> connectedSet=graph.getConnectedConflictNodeSet(fsen
-					.getIdentifier());
 			
-			if (allocSet.size() > 0) {
+			Set<WaitingElement> waitingQueueSet=graph.getWaitingElementSetBySESEID(fsen
+					.getIdentifier(),seseLockSet);
+			if (waitingQueueSet.size() > 0) {
 				output.println("     {");
-				
+				output.println("     waitingQueueItemID++;");
 				output.println("     ConflictNode* node;");
-				for (Iterator iterator = connectedSet.iterator(); iterator
-						.hasNext();) {
-					Integer integer = (Integer) iterator.next();
-					if(integer.intValue()<0){
-						output.println("     node=mlpCreateConflictNode(parentCommon->classID);");
-					}else{
-						output.println("     node=mlpCreateConflictNode( "+integer+" );");
-					}
-					output.println("     addNewItem(seseToIssue->common.connectedList,node);");
-				}
-				
+				output.println("     WaitingElement* newElement=NULL;");
+				output.println("     struct Queue* list=NULL;");
+				output.println("     struct QueueItem* newQItem=NULL;");
 				output
 						.println("     pthread_mutex_lock( &(parentCommon->lock) );");
-
-				for (Iterator iterator = allocSet.iterator(); iterator
+				for (Iterator iterator = waitingQueueSet.iterator(); iterator
 						.hasNext();) {
-					Long allocID = (Long) iterator.next();
+					WaitingElement waitingElement = (WaitingElement) iterator.next();
+					output.println("     list=createQueue();");
+					for (Iterator iterator2 = waitingElement.getAllocList().iterator(); iterator2
+							.hasNext();) {
+						Integer allocID = (Integer) iterator2
+								.next();
+						output.println("     node=mlpCreateConflictNode( "+allocID+" );");
+						output.println("     addNewItem(list,node);");
+					}
+					output.println("     seseToIssue->common.waitingQueueItemID=waitingQueueItemID;");
+					output.println("     newElement=mlpCreateWaitingElement( "+waitingElement.getStatus()+", seseToIssue, list, waitingQueueItemID );");
+					
+					output
+							.println("     newQItem=addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedWaitingQueue,"
+									+ waitingElement.getWaitingID() + ",newElement);");
 					output
-							.println("     newQItem=addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,"
-									+ allocID
-									+ ",seseToIssue);");
-					output.println("     addNewItem(newWaitingItemQueue,newQItem);");
+							.println("     addNewItem(newWaitingItemQueue,newQItem);");
 					output
 							.println("     ++(seseToIssue->common.unresolvedDependencies);");
+					output
+					.println();
 				}
 				output
 						.println("     pthread_mutex_unlock( &(parentCommon->lock) );");
@@ -3446,17 +3453,15 @@ public class BuildCode {
 			output.println("      pthread_mutex_lock( &(parentCommon->lock)  );");
 			output.println("      if( !isEmpty(newWaitingItemQueue) ){");
 			output.println("         int idx;");
-			output.println("         for(idx = 0 ; idx < numRelatedAllocSites ; idx++){");
+			output.println("         for(idx = 0 ; idx < numRelatedWaitingQueue ; idx++){");
 			output.println("            struct Queue *allocQueue=parentCommon->allocSiteArray[idx].waitingQueue;");
 			output.println("            if( !isEmpty(allocQueue) ){");
 			output.println("               struct QueueItem* nextQItem=getHead(allocQueue);");
 			output.println("               while( nextQItem != NULL ){");
-			output.println("                  if(contains(newWaitingItemQueue,nextQItem) && resolveWaitingQueue(allocQueue,nextQItem)){");
+			output.println("                  if(contains(newWaitingItemQueue,nextQItem) && isRunnable(allocQueue,nextQItem)){");
 			output.println("                     --(seseToIssue->common.unresolvedDependencies);");
-			output.println("                     nextQItem=NULL;");
-			output.println("                  }else{");
-			output.println("                     nextQItem=getNextQueueItem(nextQItem);");
 			output.println("                  }");
+			output.println("                     nextQItem=getNextQueueItem(nextQItem);");
 			output.println("               }");
 			output.println("         }");
 			output.println("       }");
@@ -3464,6 +3469,7 @@ public class BuildCode {
 			output.println("     }");
 			output.println("     }");
 			output.println();
+			
 		}
 
     // before potentially adding this SESE to other forwarding lists,
@@ -3661,6 +3667,7 @@ public class BuildCode {
     // eom
     // clean up its lock element from waiting queue, and decrement dependency count for next SESE block
     if( fsen != mlpa.getMainSESE() ) {
+    	
     	output.println();    
         output.println("   /* check memory dependency*/");
     	output.println("  {");
@@ -3669,25 +3676,26 @@ public class BuildCode {
     	output.println("   int giveCount=0;");
     	output.println("   struct Queue* launchQueue=createQueue();");
     	output.println("   struct QueueItem* nextQueueItem;");
-    	output.println("   for(idx = 0 ; idx < ___params___->common.parent->numRelatedAllocSites ; idx++){");
+    	output.println("   for(idx = 0 ; idx < ___params___->common.parent->numRelatedWaitingQueue ; idx++){");
     	output.println("     if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
     	output.println("        struct QueueItem* qItem=getHead(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
     	output.println("        while(qItem!=NULL){");
-    	output.println("           SESEcommon* item=qItem->objectptr;");
-    	output.println("           if(item->classID==___params___->common.classID){");
+    	output.println("           WaitingElement* item=qItem->objectptr;");
+    	output.println("           SESEcommon* seseItem=(SESEcommon*)item->seseRec;");
+    	output.println("           if(seseItem->classID==___params___->common.classID && item->id==___params___->common.waitingQueueItemID){");
     	output.println("              removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,qItem);");
-    	output.println("              qItem=NULL;");
-    	output.println("           }else{");
-    	output.println("           qItem=getNextQueueItem(qItem);");
     	output.println("           }");
+    	output.println("           qItem=getNextQueueItem(qItem);");
     	output.println("        }");
     	output.println("        if( !isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue) ){");
     	
     	output.println("           struct QueueItem* nextQItem=getHead(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
     	output.println("           while(nextQItem!=NULL){");
-    	output.println("              SESEcommon* nextItem=nextQItem->objectptr;");
-    	output.println("              int isResolved=resolveWaitingQueue(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
-    	output.println("              if(nextItem->classID==___params___->common.parent->classID){");
+    	output.println("              WaitingElement* nextItem=nextQItem->objectptr;");
+    	output.println("              SESEcommon* seseNextItem=(SESEcommon*)nextItem->seseRec;");
+//    	output.println("              int isResolved=resolveWaitingQueue(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
+    	output.println("              int isResolved=isRunnable(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
+    	output.println("              if(seseNextItem->classID==___params___->common.parent->classID){"); // stall site
     	output.println("                 if(isResolved){");
     	output.println("                    struct QueueItem* stallItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextItem);");
     	output.println("                    removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,stallItem);");
@@ -3701,15 +3709,15 @@ public class BuildCode {
     	output.println("                 }");
     	output.println("              }else{");
     	output.println("                 if(isResolved){");
-    	output.println("                    pthread_mutex_lock( &(nextItem->lock) );");
-    	output.println("                    if(nextItem->unresolvedDependencies > 0){");
-    	output.println("                       --(nextItem->unresolvedDependencies);");
-    	output.println("                       if( nextItem->unresolvedDependencies == 0){");
+    	output.println("                    pthread_mutex_lock( &(seseNextItem->lock) );");
+    	output.println("                    if(seseNextItem->unresolvedDependencies > 0){");
+    	output.println("                       --(seseNextItem->unresolvedDependencies);");
+    	output.println("                       if( seseNextItem->unresolvedDependencies == 0){");
     	//output.println("                          workScheduleSubmit( (void*)nextItem);");
-    	output.println("                            addNewItem(launchQueue,(void*)nextItem);");
+    	output.println("                            addNewItem(launchQueue,(void*)seseNextItem);");
     	output.println("                       }");
     	output.println("                    }");
-    	output.println("                    pthread_mutex_unlock( &(nextItem->lock) );");
+    	output.println("                    pthread_mutex_unlock( &(seseNextItem->lock) );");
     	output.println("                 }");
     	output.println("                 nextQItem=getNextQueueItem(nextQItem);");
     	output.println("               }");
@@ -3730,6 +3738,7 @@ public class BuildCode {
      	output.println("    psem_give(&(___params___->common.parent->memoryStallSiteSem));");
      	output.println("  }");
     	output.println("  }");
+    	
     }
     
     // if parent is stalling on you, let them know you're done
diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c
index da39c41d..b3ab4120 100644
--- a/Robust/src/Runtime/mlp_runtime.c
+++ b/Robust/src/Runtime/mlp_runtime.c
@@ -45,6 +45,30 @@ ConflictNode* mlpCreateConflictNode(int id){
   return newConflictNode;
 }
 
+WaitingElement* mlpCreateWaitingElement(int status, void* seseToIssue, struct Queue* queue, int id){
+  WaitingElement* newElement=(WaitingElement*)RUNMALLOC(sizeof(WaitingElement));
+  newElement->status=status;
+  newElement->seseRec=seseToIssue;
+  newElement->list=queue;
+  newElement->id=id;
+  return newElement;
+}
+
+struct QueueItem* addWaitingQueueElement2(AllocSite* waitingQueueArray, int numWaitingQueue, int waitingID, WaitingElement* element){
+
+  int i;
+  struct QueueItem* newItem=NULL;
+  for(i=0;i<numWaitingQueue;i++){
+    if(waitingQueueArray[i].id==waitingID){
+      newItem=addNewItemBack(waitingQueueArray[i].waitingQueue,element);
+      return newItem;
+      //printf("add new item %d into waiting queue:%d\n",((SESEcommon*)seseRec)->classID,allocID);
+    }
+  }
+  return newItem;  
+  
+}
+
 struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec){
 
   int i;
@@ -70,6 +94,90 @@ int getQueueIdx(AllocSite* allocSiteArray, int numAllocSites, long  allocID){
   return -1;
 }
 
+int isRunnable(struct Queue* waitingQueue, struct QueueItem* qItem){
+
+  if(!isEmpty(waitingQueue)){
+
+    struct QueueItem* current=getHead(waitingQueue);
+    while(current!=NULL){
+         if(current!=qItem){
+	   if(isConflicted(current,qItem)){
+	     return 0;
+	   }
+	 }else{
+	   return 1;
+	 }
+	 current=getNextQueueItem(current);
+    }
+  }
+  return 1;
+}
+
+int isConflicted(struct QueueItem* prevItem, struct QueueItem* item){
+
+  WaitingElement* element=item->objectptr;
+  WaitingElement* prevElement=prevItem->objectptr;
+
+  if(prevElement->id!=element->id){
+
+    if(element->status==0){ // fine read
+    
+      if(prevElement->status==1 || prevElement->status==3){
+      
+	if(isOverlapped(prevElement->list,element->list)){
+	  return 1;
+	}
+      
+      }else{
+	return 0;
+      }
+        
+    }else if(element->status==1){ // fine write
+      if(isOverlapped(prevElement->list,element->list)){
+	return 1;
+      }
+    }else if(element->status==2){// coarse read
+      
+      if(prevElement->status==1 || prevElement->status==3){
+	if(isOverlapped(prevElement->list,element->list)){
+	  return 1;
+	}
+      }
+
+    }else if(element->status==3){// coarse write
+      return 1;
+    }
+
+  }
+
+  return 0;
+}
+
+int isOverlapped(struct Queue* prevList, struct Queue* itemList){
+
+  if(!isEmpty(prevList)){
+    struct QueueItem* queueItemA=getHead(prevList); 
+    
+    while(queueItemA!=NULL){
+      ConflictNode* nodeA=queueItemA->objectptr;
+
+      if(!isEmpty(itemList)){
+	struct QueueItem* queueItemB=getHead(itemList);
+	while(queueItemB!=NULL){
+	  ConflictNode* nodeB=queueItemB->objectptr;
+	  if(nodeA->id==nodeB->id){
+	    return 1;
+	  }
+	  queueItemB=getNextQueueItem(queueItemB);
+	}
+      }
+      queueItemA=getNextQueueItem(queueItemA);      
+    }
+  }
+  return 0;
+  
+}
+
 int resolveWaitingQueue(struct Queue* waitingQueue,struct QueueItem* qItem){
 
   if(!isEmpty(waitingQueue)){
diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h
index 7ab92c1e..61ebdd34 100644
--- a/Robust/src/Runtime/mlp_runtime.h
+++ b/Robust/src/Runtime/mlp_runtime.h
@@ -25,6 +25,7 @@ typedef struct ConflictNode_t{
   int id;
 } ConflictNode;
 
+
 // forward declaration of pointer type
 typedef struct SESEcommon_t* SESEcommon_p;
 
@@ -62,10 +63,19 @@ typedef struct SESEcommon_t {
   int numRelatedAllocSites;
   psemaphore memoryStallSiteSem;
   struct Queue* connectedList;
+  int numRelatedWaitingQueue;
+  int waitingQueueItemID;
 
 } SESEcommon;
 
 
+typedef struct WaitingElement_t{
+  void* seseRec;
+  int status;
+  int id;
+  struct Queue* list;
+} WaitingElement;
+
 // a thread-local stack of SESEs and function to
 // ensure it is initialized once per thread
 /*
@@ -84,7 +94,7 @@ void  mlpDestroySESErecord( void* seseRecord );
 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
 ConflictNode* mlpCreateConflictNode(int id);
 struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec);
-
+WaitingElement* mlpCreateWaitingElement(int status, void* seseToIssue, struct Queue* queue, int id);
 
 
 #endif /* __MLP_RUNTIME__ */
-- 
2.34.1