initial commit for adding memory conflicts feature to the SESE runtime.
authoryeom <yeom>
Wed, 23 Dec 2009 19:49:47 +0000 (19:49 +0000)
committeryeom <yeom>
Wed, 23 Dec 2009 19:49:47 +0000 (19:49 +0000)
seems to work fine with a very simple test case.

Robust/src/Analysis/MLP/ConflictGraph.java
Robust/src/Analysis/MLP/LiveInNode.java
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/Analysis/MLP/ParentChildConflictsMap.java
Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h

index 6cf4cbc049897e062ad9efb643d5f64710893bbe..bdc4d1fc0dcfdf4399d93710c73cbb5d317f665b 100644 (file)
@@ -431,7 +431,8 @@ public class ConflictGraph {
                String liveinNodeID = td + "_" + fsen.getIdentifier();
 
                LiveInNode newNode = new LiveInNode(liveinNodeID, td, hrnSet,
-                               readEffectsSet, writeEffectsSet, reachabilitySet);
+                               readEffectsSet, writeEffectsSet, reachabilitySet, fsen
+                                               .getIdentifier());
                id2cn.put(liveinNodeID, newNode);
 
        }
@@ -460,6 +461,141 @@ public class ConflictGraph {
                return resultSet;
        }
 
+       /*
+       public Set<Integer> getAllocationSiteIDSetBySESEID(int seseID) {
+
+               HashSet<Integer> allocSiteIDSet = 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();
+
+                       if (node instanceof LiveInNode) {
+                               LiveInNode liveInNode = (LiveInNode) node;
+                               if (liveInNode.getSESEIdentifier() == seseID) {
+                                       Set<HeapRegionNode> hrnSet = liveInNode.getHRNSet();
+                                       for (Iterator iterator = hrnSet.iterator(); iterator
+                                                       .hasNext();) {
+                                               HeapRegionNode hrn = (HeapRegionNode) iterator.next();
+                                               // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
+                                               allocSiteIDSet.add(new    pthread_mutex_lock( &(parentCommon->lock) );
+     addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,196130920,seseToIssue->common.classID);
+     ++(seseToIssue->common.unresolvedDependencies);
+     addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,1289650030,seseToIssue->common.classID); Integer(hrn
+                                                               .getGloballyUniqueIntegerIdentifier()));
+                                       }
+                               }
+                       }
+               }
+
+               return allocSiteIDSet;
+
+       }
+*/
+       
+       public Set<Integer> getAllocationSiteIDSetBySESEID(int seseID) {
+
+               HashSet<Integer> allocSiteIDSet = 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();
+
+                       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();
+                                               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<HeapRegionNode> hrnSet = liveInNode.getHRNSet();
+//                                     for (Iterator iterator = hrnSet.iterator(); iterator
+//                                                     .hasNext();) {
+//                                             HeapRegionNode hrn = (HeapRegionNode) iterator.next();
+//                                             // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
+//                                             allocSiteIDSet.add(new Integer(hrn
+//                                                             .getGloballyUniqueIntegerIdentifier()));
+//                                     }
+                                       
+                               }
+                       }
+               }
+
+               return allocSiteIDSet;
+
+       }
+       
+       public Set<Integer> getAllocationSiteIDSet() {
+
+               HashSet<Integer> allocSiteIDSet = 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();
+                       
+                       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(node));
+                               }
+                       }
+
+               }
+
+               return allocSiteIDSet;
+
+       }
+
+       private HashSet<Integer> getHRNIdentifierSet(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
+                                               .getGloballyUniqueIntegerIdentifier()));
+                       }
+               } 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
+                                               .getGloballyUniqueIntegerIdentifier()));
+                       }
+               }
+
+               return returnSet;
+
+       }
+
        public void writeGraph(String graphName, boolean filter)
                        throws java.io.IOException {
 
index c8584fe16d0f16e2d59459c20901236889216f3a..1923ce651bb886afffff1aada6a9ee4fe1e14cde 100644 (file)
@@ -12,16 +12,18 @@ public class LiveInNode extends ConflictNode {
        Set<SESEEffectsKey> readEffectsSet;
        Set<SESEEffectsKey> writeEffectsSet;
        Set<HeapRegionNode> hrnSet;
+       int seseID;
 
        public LiveInNode(String id, TempDescriptor td, Set<HeapRegionNode> hrnSet,
                        Set<SESEEffectsKey> readEffectsSet,
-                       Set<SESEEffectsKey> writeEffectsSet, Set<Set> reachabilitySet) {
+                       Set<SESEEffectsKey> writeEffectsSet, Set<Set> reachabilitySet, int seseID) {
                this.hrnSet = hrnSet;
                this.id = id;
                this.td = td;
                this.readEffectsSet = readEffectsSet;
                this.writeEffectsSet = writeEffectsSet;
                this.reachabilitySet = reachabilitySet;
+               this.seseID=seseID;
        }
 
        public Set<HeapRegionNode> getHRNSet() {
@@ -137,6 +139,10 @@ public class LiveInNode extends ConflictNode {
 
                return result;
        }
+       
+       public int getSESEIdentifier(){
+               return seseID;
+       }
 
        public boolean equals(Object o) {
 
index 00c01c0f51220030ebc406f4d801b7f017c4c3cc..2cc97ad085959aa36ae811da580f61fb06cbf4f4 100644 (file)
@@ -4,6 +4,7 @@ import java.io.BufferedWriter;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -97,7 +98,7 @@ public class MLPAnalysis {
   private Hashtable < FlatNode, ParentChildConflictsMap > conflictsResults;
   private Hashtable< FlatMethod, MethodSummary > methodSummaryResults;
   private OwnershipAnalysis ownAnalysisForSESEConflicts;
-  private Hashtable <FlatMethod, ConflictGraph> conflictGraphResults;
+  private Hashtable <FlatNode, ConflictGraph> conflictGraphResults;
   
   // temporal data structures to track analysis progress.
   private MethodSummary currentMethodSummary;
@@ -161,7 +162,7 @@ public class MLPAnalysis {
     
     conflictsResults = new Hashtable < FlatNode, ParentChildConflictsMap >();
     methodSummaryResults=new Hashtable<FlatMethod, MethodSummary>();
-    conflictGraphResults=new Hashtable<FlatMethod, ConflictGraph>();
+    conflictGraphResults=new Hashtable<FlatNode, ConflictGraph>();
     
     seseSummaryMap= new Hashtable<FlatNode, SESESummary>();
     isAfterChildSESEIndicatorMap= new Hashtable<FlatNode, Boolean>();
@@ -295,12 +296,37 @@ public class MLPAnalysis {
        
         //     postSESEConflictsForward(javaCallGraph);
        // another pass for making graph
+       makeConflictGraph();
+       /*
        methItr = ownAnalysis.descriptorsToAnalyze.iterator();
        while (methItr.hasNext()) {
                Descriptor d = methItr.next();
                FlatMethod fm = state.getMethodFlat(d);
-               makeConflictGraph(fm);
-       }           
+               makeConflictGraph2(fm);
+       }
+       
+       Enumeration<FlatNode> keyEnum1=conflictGraphResults.keys();
+               while (keyEnum1.hasMoreElements()) {
+                       FlatNode flatNode = (FlatNode) keyEnum1.nextElement();
+                       ConflictGraph conflictGraph=conflictGraphResults.get(flatNode);
+                       conflictGraph.analyzeConflicts();
+                       conflictGraphResults.put(flatNode, conflictGraph);
+               }
+               */
+       
+       Enumeration<FlatNode> keyEnum=conflictGraphResults.keys();
+       while (keyEnum.hasMoreElements()) {
+                       FlatNode key = (FlatNode) keyEnum.nextElement();
+                       ConflictGraph cg=conflictGraphResults.get(key);
+                       try {
+                               cg.writeGraph("ConflictGraphFor"+key, false);
+                       } catch (IOException e) {
+                               System.out.println("Error writing");
+                               System.exit(0);
+                       }
+               }
+       
+       /*
        methItr = ownAnalysis.descriptorsToAnalyze.iterator();
        while(methItr.hasNext()){
                Descriptor d = methItr.next();
@@ -315,6 +341,7 @@ public class MLPAnalysis {
                        }
                }
        }
+       */
        ////////////////
     }
 
@@ -1893,10 +1920,7 @@ public class MLPAnalysis {
                return sorted;
        }
        
-       private void makeConflictGraph(FlatMethod fm) {
-
-               // create conflict graph for each flat method
-               ConflictGraph conflictGraph = new ConflictGraph();
+       private void makeConflictGraph2(FlatMethod fm) {
 
                HashSet<MethodContext> mcSet = ownAnalysisForSESEConflicts
                                .getAllMethodContextSetByDescriptor(fm.getMethod());
@@ -1909,6 +1933,9 @@ public class MLPAnalysis {
                        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();
@@ -1916,7 +1943,7 @@ public class MLPAnalysis {
 
                                flatNodesToVisit.remove(fn);
                                visited.add(fn);
-
+                       
                                // ///////////////////////////////////////////////////////////////////////
                                // Adding Stall Node of current program statement
                                ParentChildConflictsMap currentConflictsMap = conflictsResults
@@ -1926,45 +1953,143 @@ public class MLPAnalysis {
                                                .getStallMap();
                                Set<Entry<TempDescriptor, StallSite>> entrySet = stallMap
                                                .entrySet();
-
-//                             HashSet<String> newStallNodeSet = new HashSet<String>();
-
+                               
+                               
+                               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();
-                                       String stallNodeID;
 
                                        // 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, conflictGraph,
-                                               currentConflictsMap);
-
+                               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);
                                        }
                                }
-
                        } // end of while(flatNodesToVisit)
 
                } // end of while(mcIter)
 
                // decide fine-grain edge or coarse-grain edge among all vertexes by pair-wise comparison
-               conflictGraph.analyzeConflicts();
 
-               conflictGraphResults.put(fm, conflictGraph);
+       }
+       
+       private void makeConflictGraph() {
+               Iterator<Descriptor> methItr = ownAnalysis.descriptorsToAnalyze
+                               .iterator();
+               while (methItr.hasNext()) {
+                       Descriptor d = methItr.next();
+                       FlatMethod fm = state.getMethodFlat(d);
+
+                       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);
+                                               }
+                                       }
+                               } // end of while(flatNodesToVisit)
+
+                       } // end of while(mcIter)
+
+               }
+               
+               // decide fine-grain edge or coarse-grain edge among all vertexes by pair-wise comparison
+       Enumeration<FlatNode> keyEnum1=conflictGraphResults.keys();
+               while (keyEnum1.hasMoreElements()) {
+                       FlatNode flatNode = (FlatNode) keyEnum1.nextElement();
+                       ConflictGraph conflictGraph=conflictGraphResults.get(flatNode);
+                       conflictGraph.analyzeConflicts();
+                       conflictGraphResults.put(flatNode, conflictGraph);
+               }
+               
        }
        
        private Set<Set> calculateReachabilitySet(OwnershipGraph og,
@@ -2001,9 +2126,25 @@ public class MLPAnalysis {
                return reachabilitySet;
        }
        
-       private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm,
+       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) {
 
                switch (fn.kind()) {
 
@@ -2015,6 +2156,15 @@ public class MLPAnalysis {
 
                        if (!fsen.getIsCallerSESEplaceholder()) {
                                Set<TempDescriptor> invar_set = fsen.getInVarSet();
+                               
+                               SESESummary seseSummary=seseSummaryMap.get(fsen);
+                               ConflictGraph conflictGraph=null;
+                               conflictGraph=conflictGraphResults.get(seseSummary.getCurrentParent());
+                               
+                               if(conflictGraph==null){
+                                       conflictGraph = new ConflictGraph();
+                               }
+                               
 
                                for (Iterator iterator = invar_set.iterator(); iterator
                                                .hasNext();) {
@@ -2041,11 +2191,15 @@ public class MLPAnalysis {
                                                                .next();
                                                hrnSet.add(referenceEdge.getDst());
                                        }
-                                       graph.addLiveInNode(tempDescriptor, hrnSet, fsen,
+                                       
+                                       conflictGraph.addLiveInNode(tempDescriptor, hrnSet, fsen,
                                                        readEffectsSet, writeEffectsSet, reachabilitySet);
-
                                }
-
+                               
+                               if(conflictGraph.id2cn.size()>0){
+                                       conflictGraphResults.put(seseSummary.getCurrentParent(),conflictGraph);
+                               }
+                               
                        }
 
                }
@@ -2206,6 +2360,8 @@ public class MLPAnalysis {
                                isAfterChildSESEIndicatorMap.put(currentSummary
                                                .getCurrentParent(), new Boolean(true));
                        }
+//                     currentConflictsMap = new ParentChildConflictsMap();
+                       currentConflictsMap.clear();
 
                }
                        break;
@@ -3225,4 +3381,13 @@ public class MLPAnalysis {
       printSESEInfoTree( bw, fsenChild );
     }
   }
+  
+  public Hashtable <FlatNode, ConflictGraph> getConflictGraphResults(){
+         return conflictGraphResults;
+  }
+  
+  public Hashtable < FlatNode, ParentChildConflictsMap > getConflictsResults(){
+         return conflictsResults;
+  }
+  
 }
index 5a6cd89d02f21977ff08786b39ebd34a33880a02..773b5eaa6f3faf5e1fc9f35c0aa0da803972d603 100644 (file)
@@ -27,6 +27,12 @@ public class ParentChildConflictsMap {
                stallEdgeMap= new Hashtable < ReferenceEdge, HashSet<StallTag> >();
        }
        
+       public void clear(){
+               accessibleMap.clear();
+               stallMap.clear();
+               stallEdgeMap.clear();
+       }
+       
        public void makeAllInaccessible(){
                
                Set<TempDescriptor> keySet=accessibleMap.keySet();
index 36b6c8a58729b04c54ad4ef1e51eb639bacce9dc..16cc332b711b6f2e4186ab0d0a817e56865f4fde 100644 (file)
@@ -231,4 +231,17 @@ public class HeapRegionNode extends OwnershipNode {
   public String getGloballyUniqueIdentifier(){
          return globalIdentifier;
   }
+  
+       public int getGloballyUniqueIntegerIdentifier() {
+               String fristpart = globalIdentifier;
+               fristpart = fristpart.replaceAll("FN", "1");
+               fristpart = fristpart.replaceAll("FM", "2");
+               int idx = fristpart.indexOf(".");
+               String endpart = fristpart.substring(idx + 1);
+               endpart = endpart.replaceAll("S", "1");
+               endpart = endpart.replaceAll("P", "2");
+               endpart = endpart.replaceAll("A", "3");
+               String modified = fristpart.substring(0, idx) + endpart;
+               return Integer.parseInt(modified);
+       }
 }
index 13d49da98f2c3c6b3b536999ad0838a2adbc1152..f36063252b311e4142d09a417e8283b0e520e753 100644 (file)
@@ -1540,7 +1540,6 @@ public class OwnershipAnalysis {
   }
   
   public MethodContext getCalleeMethodContext(MethodContext callerMC, FlatCall fc){
-          assert methodEffects;
 
          Hashtable<FlatNode, OwnershipGraph> table=mapMethodContextToFlatNodeOwnershipGraph.get(callerMC);
          
index ed4b95a0b39265a55e1c9f482a7691c8e4dc5fd1..a51e86deffbbce0e484e800fafe9982e821f823c 100644 (file)
@@ -27,6 +27,7 @@ import Analysis.Prefetch.*;
 import Analysis.Loops.WriteBarrier;
 import Analysis.Loops.GlobalFieldType;
 import Analysis.Locality.TypeAnalysis;
+import Analysis.MLP.ConflictGraph;
 import Analysis.MLP.MLPAnalysis;
 import Analysis.MLP.VariableSourceToken;
 import Analysis.MLP.CodePlan;
@@ -1744,6 +1745,28 @@ public class BuildCode {
          }    
        }
       }
+      
+      // set up related allocation sites's waiting queues
+      // eom
+      output.println("   /* set up waiting queues */");
+      ConflictGraph graph=null;
+      graph=mlpa.getConflictGraphResults().get(fm);
+      if(graph!=null){
+         Set<Integer> allocSet=graph.getAllocationSiteIDSet();
+         
+         if(allocSet.size()>0){
+                 output.println("   int numRelatedAllocSites="+allocSet.size()+";");                     
+                 output.println("   seseCaller->numRelatedAllocSites=numRelatedAllocSites;");            
+                 output.println("   seseCaller->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);");
+                 int idx=0;
+                 for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) {
+                       Integer allocID = (Integer) iterator.next();
+                       output.println("   seseCaller->allocSiteArray["+idx+"].id="+allocID+";");
+                       idx++;
+                 }
+                 output.println();
+         }
+      }
     }
 
 
@@ -3171,7 +3194,7 @@ public class BuildCode {
        output.println("     SESEcommon* parentCommon = seseCaller;");
       }
     }
-
+    
     // before doing anything, lock your own record and increment the running children
     if( fsen != mlpa.getMainSESE() ) {      
       output.println("     pthread_mutex_lock( &(parentCommon->lock) );");
@@ -3224,6 +3247,56 @@ public class BuildCode {
                       generateTemp( fsen.getfmEnclosing(), temp, null )+";");
       }
     }
+    
+    // count up memory conflict dependencies,
+    // eom
+    ConflictGraph graph=null;
+    FlatSESEEnterNode parent=fsen.getParent();
+    if(parent!=null){
+        if(parent.isCallerSESEplaceholder){
+               graph=mlpa.getConflictGraphResults().get(parent.getfmEnclosing());
+        }else{
+               graph=mlpa.getConflictGraphResults().get(fsen);
+        }
+    }
+               if (graph != null) {
+                       output.println();
+                       output.println("     /*add waiting queue element*/");
+
+                       Set<Integer> allocSet = graph.getAllocationSiteIDSetBySESEID(fsen
+                                       .getIdentifier());
+                       if (allocSet.size() > 0) {
+                               output.println("     {");
+                               output
+                                               .println("     pthread_mutex_lock( &(parentCommon->lock) );");
+
+                               for (Iterator iterator = allocSet.iterator(); iterator
+                                               .hasNext();) {
+                                       Integer allocID = (Integer) iterator.next();
+                                       output
+                                                       .println("     addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,"
+                                                                       + allocID
+                                                                       + ",seseToIssue);");
+                                       output
+                                                       .println("     ++(seseToIssue->common.unresolvedDependencies);");
+                               }
+                               output
+                                               .println("     pthread_mutex_unlock( &(parentCommon->lock) );");
+                               output.println("     }");
+                       }
+                       
+                       output.println("     /*decide whether it is runnable or not in regarding to memory conflicts*/");
+                       output.println("     {");
+                       output.println("     int idx;");
+                       output.println("     for(idx = 0 ; idx < numRelatedAllocSites ; idx++){");
+                       output.println("        SESEcommon* item=peekItem(seseCaller->allocSiteArray[idx].waitingQueue);");
+                       output.println("        if(item->classID==seseToIssue->common.classID){");
+                       output.println("           --(seseToIssue->common.unresolvedDependencies);");
+                       output.println("        }");
+                       output.println("     }");
+                       output.println("     }");
+                       output.println();
+               }
 
     // before potentially adding this SESE to other forwarding lists,
     //  create it's lock and take it immediately
@@ -3317,6 +3390,7 @@ public class BuildCode {
        }      
        output.println("     "+p+" = seseToIssue;");
       }
     }
 
     // if there were no outstanding dependencies, issue here
@@ -3328,7 +3402,7 @@ public class BuildCode {
     // eventually, for it to mark itself finished
     output.println("     pthread_mutex_unlock( &(seseToIssue->common.lock) );");
     output.println("   }");
-
+    
   }
 
   public void generateFlatSESEExitNode( FlatMethod fm,  
@@ -3416,6 +3490,33 @@ public class BuildCode {
     output.println("     pthread_mutex_unlock( &(consumer->lock) );");
     output.println("   }");
     
+    // 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("  {");
+       output.println("   int idx;");
+       output.println("   for(idx = 0 ; idx < ___params___->common.parent->numRelatedAllocSites ; idx++){");
+       output.println("     SESEcommon* item=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
+       output.println("     if( item->classID == ___params___->common.classID ){");
+       output.println("        struct QueueItem* qItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,item);");
+       output.println("        removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,qItem);");
+       output.println("        if( !isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue) ){");
+       output.println("           SESEcommon* nextItem=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
+       output.println("           pthread_mutex_lock( &(nextItem->lock) );");
+       output.println("           --(nextItem->unresolvedDependencies);");
+       output.println("           if( nextItem->unresolvedDependencies == 0){");
+       output.println("              workScheduleSubmit( (void*)nextItem);");
+       output.println("           }");
+       output.println("           pthread_mutex_unlock( &(nextItem->lock) );");
+       output.println("        }");
+       output.println("     }");
+       output.println("  }");
+       output.println("  }");
+    }
+    
+    
     // if parent is stalling on you, let them know you're done
     if( fsexn.getFlatEnter() != mlpa.getMainSESE() ) {
       output.println("   psem_give( &("+paramsprefix+"->common.stallSem) );");
index 637558d119482190f8017ae03ac2a39e62481ae6..2101ce235a9c55a0b5de9a3d96fdc661d4159b6a 100644 (file)
@@ -29,3 +29,25 @@ void* mlpAllocSESErecord( int size ) {
 void mlpFreeSESErecord( void* seseRecord ) {
   RUNFREE( seseRecord );
 }
+
+AllocSite* mlpCreateAllocSiteArray(int numAllocSites){
+  int i;
+  AllocSite* newAllocSite=(AllocSite*)RUNMALLOC( sizeof( AllocSite ) * numAllocSites );
+  for(i=0; i<numAllocSites; i++){
+    newAllocSite[i].waitingQueue=createQueue();
+  }
+  return newAllocSite;
+}
+
+void addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, int allocID, void *seseRec){
+  
+  int i;
+  for(i=0;i<numAllocSites;i++){
+    if(allocSiteArray[i].id==allocID){
+      addNewItemBack(allocSiteArray[i].waitingQueue,seseRec);
+      //printf("add new item %d into waiting queue:%d\n",((SESEcommon*)seseRec)->classID,allocID);
+      break;
+    }
+  }
+
+}
index 3f7ca184470b7b783f414b63d973ae8302a54d3f..05d4ca57f993d68a3a1f24b320f9f76a079abc51 100644 (file)
 #define TRUE 1
 #endif
 
+// each allocation site nees the following
+typedef struct AllocSite_t{
+  int id;
+  struct Queue* waitingQueue;
+} AllocSite;
+
 // forward declaration of pointer type
 typedef struct SESEcommon_t* SESEcommon_p;
 
@@ -48,6 +54,10 @@ typedef struct SESEcommon_t {
 
   SESEcommon_p    parent;
 
+  AllocSite* allocSiteArray;
+  int numRelatedAllocSites;
+  psemaphore stallSiteSem;
+
 } SESEcommon;
 
 
@@ -66,5 +76,7 @@ extern __thread SESEcommon_p seseCaller;
 void* mlpCreateSESErecord( int size );
 void  mlpDestroySESErecord( void* seseRecord );
 
+AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
+
 
 #endif /* __MLP_RUNTIME__ */