import Analysis.Liveness;
import Analysis.ArrayReferencees;
import Analysis.OoOJava.RBlockRelationAnalysis;
-import Analysis.OoOJava.RBlockStatusAnalysis;
import IR.*;
import IR.Flat.*;
import IR.Tree.Modifiers;
public Liveness liveness;
public ArrayReferencees arrayReferencees;
public RBlockRelationAnalysis rblockRel;
- public RBlockStatusAnalysis rblockStatus;
public TypeUtil typeUtil;
public int allocationDepth;
Liveness l,
ArrayReferencees ar,
Set<FlatNew> sitesToFlag,
- RBlockRelationAnalysis rra,
- RBlockStatusAnalysis rsa
+ RBlockRelationAnalysis rra
) {
- init( s, tu, cg, l, ar, sitesToFlag, rra, rsa, false );
+ init( s, tu, cg, l, ar, sitesToFlag, rra, false );
}
public DisjointAnalysis( State s,
ArrayReferencees ar,
Set<FlatNew> sitesToFlag,
RBlockRelationAnalysis rra,
- RBlockStatusAnalysis rsa,
boolean suppressOutput
) {
- init( s, tu, cg, l, ar, sitesToFlag, rra, rsa, suppressOutput );
+ init( s, tu, cg, l, ar, sitesToFlag, rra, suppressOutput );
}
protected void init( State state,
ArrayReferencees arrayReferencees,
Set<FlatNew> sitesToFlag,
RBlockRelationAnalysis rra,
- RBlockStatusAnalysis rsa,
boolean suppressOutput
) {
this.arrayReferencees = arrayReferencees;
this.sitesToFlag = sitesToFlag;
this.rblockRel = rra;
- this.rblockStatus = rsa;
if( rblockRel != null ) {
doEffectsAnalysis = true;
case FKind.FlatGenReachNode: {
FlatGenReachNode fgrn = (FlatGenReachNode) fn;
- System.out.println( "Generating a reach graph!" );
+ System.out.println( " Generating reach graph for program point: "+fgrn.getGraphName() );
+
rg.writeGraph( "genReach"+fgrn.getGraphName(),
true, // write labels (variables)
- true, // selectively hide intermediate temp vars
+ false, // selectively hide intermediate temp vars
true, // prune unreachable heap regions
false, // hide reachability altogether
- true, // hide subset reachability states
+ false, // hide subset reachability states
true, // hide predicates
true ); // hide edge taints
} break;
// before transfer, do effects analysis support
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x gets status of y
if(!rg.isAccessible(rhs)){
rg.makeInaccessible(lhs);
// before transfer, do effects analysis support
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x gets status of y
if(!rg.isAccessible(rhs)){
rg.makeInaccessible(lhs);
// a stall-site taint
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x=y.f, stall y if not accessible
// contributes read effects on stall site of y
if(!rg.isAccessible(rhs)) {
// stall-site taints
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x.y=f , stall x and y if they are not accessible
// also contribute write effects on stall site of x
if(!rg.isAccessible(lhs)) {
// before transfer func, possibly inject
// stall-site taint
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x=y.f, stall y if not accessible
// contributes read effects on stall site of y
// after this, x and y are accessbile.
// stall-site taints
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
- if(rblockStatus.isInCriticalRegion(fmContaining, fn)){
+ if(rblockRel.isPotentialStallSite(fn)){
// x.y=f , stall x and y if they are not accessible
// also contribute write effects on stall site of x
if(!rg.isAccessible(lhs)) {
// before transform, support effects analysis
if (doEffectsAnalysis && fmContaining != fmAnalysisEntry) {
- if (rblockStatus.isInCriticalRegion(fmContaining, fn)) {
+ if (rblockRel.isPotentialStallSite(fn)) {
// after creating new object, lhs is accessible
rg.makeAccessible(lhs);
}
case FKind.FlatSESEEnterNode:
sese = (FlatSESEEnterNode) fn;
- if( sese.getIsCallerSESEplaceholder() ) {
- // ignore these dummy rblocks!
- break;
- }
-
if( doEffectsAnalysis && fmContaining != fmAnalysisEntry ) {
// always remove ALL stall site taints at enter
System.out.println( " callee hasn't been analyzed, scheduling: "+mdPossible );
}
-
} else {
// calculate the method call transform
rgPossibleCaller.resolveMethodCall( fc,
}
protected void add(Taint t, Effect e) {
- if( t.getSESE() != null &&
- t.getSESE().getIsCallerSESEplaceholder() ) {
- return;
- }
Taint tNoPreds = Canonical.changePredsTo( t,
ReachGraph.predsEmpty
// so we capture the full change from the old alpha:
ReachSet localDelta = Canonical.applyChangeSet( n.getAlpha(),
C,
- true
+ true
);
// but this propagation may be only one of many concurrent
// possible changes, so keep a running union with the node's
public void taintInSetVars( FlatSESEEnterNode sese ) {
- if( sese.getIsCallerSESEplaceholder() ) {
- return;
- }
Iterator<TempDescriptor> isvItr = sese.getInVarSet().iterator();
while( isvItr.hasNext() ) {
}
public void removeInContextTaints( FlatSESEEnterNode sese ) {
- if( sese.getIsCallerSESEplaceholder() ) {
- return;
- }
Iterator meItr = id2hrn.entrySet().iterator();
while( meItr.hasNext() ) {
private static boolean resolveMethodDebugDOTwriteLabels = true;
private static boolean resolveMethodDebugDOTselectTemps = true;
private static boolean resolveMethodDebugDOTpruneGarbage = true;
- private static boolean resolveMethodDebugDOThideReach = true;
- private static boolean resolveMethodDebugDOThideSubsetReach = true;
+ private static boolean resolveMethodDebugDOThideReach = false;
+ private static boolean resolveMethodDebugDOThideSubsetReach = false;
private static boolean resolveMethodDebugDOThidePreds = true;
- private static boolean resolveMethodDebugDOThideEdgeTaints = false;
+ private static boolean resolveMethodDebugDOThideEdgeTaints = true;
static String debugGraphPrefix;
static int debugCallSiteVisitCounter;
) {
if( writeDebugDOTs ) {
+
System.out.println( " Writing out visit "+
debugCallSiteVisitCounter+
" to debug call site" );
boolean hideEdgeTaints,
Set<Integer> callerNodeIDsCopiedToCallee
) {
-
try {
// remove all non-word characters from the graph name so
// the filename and identifier in dot don't cause errors
String s;
if( isRBlockTaint() ) {
- if( sese.getIsCallerSESEplaceholder() ) {
- s = "placeh";
- } else {
- s = sese.getPrettyIdentifier();
- }
-
+ s = sese.getPrettyIdentifier();
} else {
s = stallSite.toString();
}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-
-// a code plan contains information based on analysis results
-// for injecting code before and/or after a flat node
-public class CodePlan {
-
- private Hashtable< VariableSourceToken, Set<TempDescriptor> > stall2copySet;
- private Set<TempDescriptor> dynamicStallSet;
- private Hashtable<TempDescriptor, TempDescriptor> dynAssign_lhs2rhs;
- private Set<TempDescriptor> dynAssign_lhs2curr;
- private FlatSESEEnterNode currentSESE;
-
- public CodePlan( FlatSESEEnterNode fsen ) {
- stall2copySet = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
- dynamicStallSet = new HashSet<TempDescriptor>();
- dynAssign_lhs2rhs = new Hashtable<TempDescriptor, TempDescriptor>();
- dynAssign_lhs2curr = new HashSet<TempDescriptor>();
- currentSESE = fsen;
- }
-
- public FlatSESEEnterNode getCurrentSESE() {
- return currentSESE;
- }
-
- public void addStall2CopySet( VariableSourceToken stallToken,
- Set<TempDescriptor> copySet ) {
-
- if( stall2copySet.containsKey( stallToken ) ) {
- Set<TempDescriptor> priorCopySet = stall2copySet.get( stallToken );
- priorCopySet.addAll( copySet );
- } else {
- stall2copySet.put( stallToken, copySet );
- }
- }
-
- public Set<VariableSourceToken> getStallTokens() {
- return stall2copySet.keySet();
- }
-
- public Set<TempDescriptor> getCopySet( VariableSourceToken stallToken ) {
- return stall2copySet.get( stallToken );
- }
-
-
- public void addDynamicStall( TempDescriptor var ) {
- dynamicStallSet.add( var );
- }
-
- public Set<TempDescriptor> getDynamicStallSet() {
- return dynamicStallSet;
- }
-
- public void addDynAssign( TempDescriptor lhs,
- TempDescriptor rhs ) {
- dynAssign_lhs2rhs.put( lhs, rhs );
- }
-
- public Hashtable<TempDescriptor, TempDescriptor> getDynAssigns() {
- return dynAssign_lhs2rhs;
- }
-
- public void addDynAssign( TempDescriptor lhs ) {
- dynAssign_lhs2curr.add( lhs );
- }
-
- public Set<TempDescriptor> getDynAssignCurr() {
- return dynAssign_lhs2curr;
- }
-
- public String toString() {
- String s = " PLAN: ";
-
- if( !stall2copySet.entrySet().isEmpty() ) {
- s += "[STATIC STALLS:";
- }
- Iterator cpsItr = stall2copySet.entrySet().iterator();
- while( cpsItr.hasNext() ) {
- Map.Entry me = (Map.Entry) cpsItr.next();
- VariableSourceToken stallToken = (VariableSourceToken) me.getKey();
- Set<TempDescriptor> copySet = (Set<TempDescriptor>) me.getValue();
-
- s += "("+stallToken+"->"+copySet+")";
- }
- if( !stall2copySet.entrySet().isEmpty() ) {
- s += "]";
- }
-
- if( !dynamicStallSet.isEmpty() ) {
- s += "[DYN STALLS:"+dynamicStallSet+"]";
- }
-
- if( !dynAssign_lhs2rhs.isEmpty() ) {
- s += "[DYN ASSIGNS:"+dynAssign_lhs2rhs+"]";
- }
-
- if( !dynAssign_lhs2curr.isEmpty() ) {
- s += "[DYN ASS2CURR:"+dynAssign_lhs2curr+"]";
- }
-
- return s;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import Analysis.OwnershipAnalysis.OwnershipGraph;
-import Analysis.OwnershipAnalysis.ReachabilitySet;
-import Analysis.OwnershipAnalysis.TokenTuple;
-import IR.Flat.FlatMethod;
-import IR.Flat.FlatSESEEnterNode;
-import IR.Flat.TempDescriptor;
-
-public class ConflictGraph {
-
- static private int uniqueCliqueIDcount = 100;
-
- public Hashtable<String, ConflictNode> id2cn;
- private OwnershipGraph og;
-
- public ConflictGraph(OwnershipGraph og) {
- id2cn = new Hashtable<String, ConflictNode>();
- this.og = og;
- }
-
- public boolean hasConflictEdge() {
-
- Set<String> keySet = id2cn.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- String key = (String) iterator.next();
- ConflictNode node = id2cn.get(key);
- if (node.getEdgeSet().size() > 0) {
- return true;
- }
- }
- return false;
- }
-
- public void analyzeConflicts() {
-
- Set<String> keySet = id2cn.keySet();
- Set<String> analyzedIDSet = new HashSet<String>();
-
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- String nodeID = (String) iterator.next();
- ConflictNode node = id2cn.get(nodeID);
- analyzePossibleConflicts(analyzedIDSet, node);
- }
- }
-
- private boolean compareHRNSet(Set<HeapRegionNode> setA,
- Set<HeapRegionNode> setB) {
- boolean found = false;
- for (Iterator iterator = setA.iterator(); iterator.hasNext();) {
- HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
- String gID = heapRegionNode.getGloballyUniqueIdentifier();
- for (Iterator iterator2 = setB.iterator(); iterator2.hasNext();) {
- HeapRegionNode heapRegionNode2 = (HeapRegionNode) iterator2
- .next();
- if (heapRegionNode2.getGloballyUniqueIdentifier().equals(gID)) {
- found = true;
- }
- }
- }
- if (!found) {
- return false;
- }
- return true;
- }
-
- public String addStallNode(TempDescriptor td, FlatMethod fm,
- StallSite stallSite, Set<Set> reachabilitySet) {
-
- String stallNodeID = td + "_" + fm.getMethod().getSymbol();
-
- if (!id2cn.containsKey(stallNodeID)) {
- StallSiteNode newNode = new StallSiteNode(stallNodeID, td,
- stallSite, reachabilitySet);
- id2cn.put(stallNodeID, newNode);
- // it add new new stall node to conflict graph
- return stallNodeID;
- }
- // it doesn't add new stall node because stall node has already been
- // added.
- return null;
- }
-
- public StallSiteNode getStallNode(String stallNodeID) {
- ConflictNode node = id2cn.get(stallNodeID);
- if (node instanceof StallSiteNode) {
- return (StallSiteNode) node;
- } else {
- return null;
- }
- }
-
- public void addLiveInNode(TempDescriptor td, Set<HeapRegionNode> hrnSet,
- FlatSESEEnterNode fsen, Set<SESEEffectsKey> readEffectsSet,
- Set<SESEEffectsKey> writeEffectsSet,
- Set<SESEEffectsKey> strongUpdateSet, Set<Set> reachabilitySet) {
-
- String liveinNodeID = td + "_" + fsen.getIdentifier();
-
- LiveInNode newNode = new LiveInNode(liveinNodeID, td, hrnSet,
- readEffectsSet, writeEffectsSet, strongUpdateSet,
- reachabilitySet, fsen.getIdentifier());
- id2cn.put(liveinNodeID, newNode);
-
- }
-
- public void addConflictEdge(int type, ConflictNode nodeU, ConflictNode nodeV) {
-
- // if there are two edges between the same node pair, coarse has a
- // priority
- HashSet<ConflictEdge> set = nodeU.getEdgeSet();
- ConflictEdge toBeRemoved = null;
- for (Iterator iterator = set.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
-
- if ((conflictEdge.getVertexU().equals(nodeU) && conflictEdge
- .getVertexV().equals(nodeV))
- || (conflictEdge.getVertexU().equals(nodeV) && conflictEdge
- .getVertexV().equals(nodeU))) {
- if (conflictEdge.getType() == ConflictEdge.FINE_GRAIN_EDGE
- && type == ConflictEdge.COARSE_GRAIN_EDGE) {
- toBeRemoved = conflictEdge;
- break;
- } else if (conflictEdge.getType() == ConflictEdge.COARSE_GRAIN_EDGE
- && type == ConflictEdge.FINE_GRAIN_EDGE) {
- // ignore
- return;
- }
- }
- }
-
- if (toBeRemoved != null) {
- nodeU.getEdgeSet().remove(toBeRemoved);
- nodeV.getEdgeSet().remove(toBeRemoved);
- }
-
- ConflictEdge newEdge = new ConflictEdge(nodeU, nodeV, type);
- nodeU.addEdge(newEdge);
- nodeV.addEdge(newEdge);
-
- }
-
- public 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();
-
- 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();
-
- for (Iterator<SESELock> seseLockIter = seseLockSet
- .iterator(); seseLockIter.hasNext();) {
- SESELock seseLock = seseLockIter.next();
- if (seseLock
- .containsConflictNode(stallSiteNode)
- && seseLock
- .containsConflictEdge(conflictEdge)) {
- WaitingElement newElement = new WaitingElement();
- newElement.setQueueID(seseLock.getID());
- if (isFineElement(newElement.getStatus())) {
- newElement
- .setDynID(node
- .getTempDescriptor()
- .toString());
- }
- newElement.setStatus(seseLock
- .getNodeType(stallSiteNode));
- waitingElementSet.add(newElement);
- }
- }
- }
- }
- }
- }
-
- }
-
- return waitingElementSet;
- }
-
- private Set<Integer> getConnectedConflictNode(ConflictEdge conflictEdge,
- int seseID) {
-
- HashSet<Integer> nodeIDSet = new HashSet<Integer>();
-
- if (conflictEdge.getVertexU() instanceof LiveInNode) {
- LiveInNode lin = (LiveInNode) conflictEdge.getVertexU();
- if (lin.getSESEIdentifier() != seseID) {
- nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
- }
- } else {
- // it is stall site
- nodeIDSet.add(new Integer(-1));
- }
- if (conflictEdge.getVertexV() instanceof LiveInNode) {
- LiveInNode lin = (LiveInNode) conflictEdge.getVertexV();
- if (lin.getSESEIdentifier() != seseID) {
- nodeIDSet.add(new Integer(lin.getSESEIdentifier()));
- }
- } else {
- // it is stall site
- nodeIDSet.add(new Integer(-1));
- }
-
- // self-edge case
- if (conflictEdge.getVertexU() instanceof LiveInNode
- && conflictEdge.getVertexV() instanceof LiveInNode) {
- if (((LiveInNode) conflictEdge.getVertexU()).getSESEIdentifier() == seseID
- && ((LiveInNode) conflictEdge.getVertexV())
- .getSESEIdentifier() == seseID) {
- nodeIDSet.add(seseID);
- }
- }
-
- return nodeIDSet;
- }
-
- 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();
-
- 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();
- //
- nodeIDSet.addAll(getConnectedConflictNode(conflictEdge,
- seseID));
- //
- }
- }
- }
- }
-
- return nodeIDSet;
-
- }
-
- public SESEWaitingQueue 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();
-
- for (Iterator<SESELock> seseLockIter = seseLockSet
- .iterator(); seseLockIter.hasNext();) {
- SESELock seseLock = seseLockIter.next();
- if (seseLock.containsConflictNode(liveInNode)
- && seseLock
- .containsConflictEdge(conflictEdge)) {
- WaitingElement newElement = new WaitingElement();
- newElement.setQueueID(seseLock.getID());
- newElement.setStatus(seseLock
- .getNodeType(liveInNode));
- if (isFineElement(newElement.getStatus())) {
- newElement.setDynID(node
- .getTempDescriptor().toString());
- newElement.setTempDesc(node.getTempDescriptor());
- }
- if (!waitingElementSet.contains(newElement)) {
- waitingElementSet.add(newElement);
- }
-
- }
- }
- }
-
- }
- }
-
- }
-
- //handle the case that multiple enqueues by an SESE for different live-in into the same queue
- return refineQueue(waitingElementSet);
-// return waitingElementSet;
-
- }
-
- public SESEWaitingQueue refineQueue(Set<WaitingElement> waitingElementSet) {
-
- Set<WaitingElement> refinedSet=new HashSet<WaitingElement>();
- HashMap<Integer, Set<WaitingElement>> map = new HashMap<Integer, Set<WaitingElement>>();
- SESEWaitingQueue seseDS=new SESEWaitingQueue();
-
- for (Iterator iterator = waitingElementSet.iterator(); iterator
- .hasNext();) {
- WaitingElement waitingElement = (WaitingElement) iterator.next();
- Set<WaitingElement> set=map.get(new Integer(waitingElement.getQueueID()));
- if(set==null){
- set=new HashSet<WaitingElement>();
- }
- set.add(waitingElement);
- map.put(new Integer(waitingElement.getQueueID()), set);
- }
-
- Set<Integer> keySet=map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- Integer queueID = (Integer) iterator.next();
- Set<WaitingElement> queueWEset=map.get(queueID);
- refineQueue(queueID.intValue(),queueWEset,seseDS);
- }
-
- return seseDS;
- }
-
- private void refineQueue(int queueID,
- Set<WaitingElement> waitingElementSet, SESEWaitingQueue seseDS) {
-
- if (waitingElementSet.size() > 1) {
- //only consider there is more than one element submitted by same SESE
- Set<WaitingElement> refinedSet = new HashSet<WaitingElement>();
-
- int numCoarse = 0;
- int numRead = 0;
- int numWrite = 0;
- int total=waitingElementSet.size();
- WaitingElement SCCelement = null;
- WaitingElement coarseElement = null;
-
- for (Iterator iterator = waitingElementSet.iterator(); iterator
- .hasNext();) {
- WaitingElement waitingElement = (WaitingElement) iterator
- .next();
- if (waitingElement.getStatus() == ConflictNode.FINE_READ) {
- numRead++;
- } else if (waitingElement.getStatus() == ConflictNode.FINE_WRITE) {
- numWrite++;
- } else if (waitingElement.getStatus() == ConflictNode.COARSE) {
- numCoarse++;
- coarseElement = waitingElement;
- } else if (waitingElement.getStatus() == ConflictNode.SCC) {
- SCCelement = waitingElement;
- }
- }
-
- if (SCCelement != null) {
- // if there is at lease one SCC element, just enqueue SCC and
- // ignore others.
- refinedSet.add(SCCelement);
- } else if (numCoarse == 1 && (numRead + numWrite == total)) {
- // if one is a coarse, the othere are reads/write, enqueue SCC.
- WaitingElement we = new WaitingElement();
- we.setQueueID(queueID);
- we.setStatus(ConflictNode.SCC);
- refinedSet.add(we);
- } else if (numCoarse == total) {
- // if there are multiple coarses, enqueue just one coarse.
- refinedSet.add(coarseElement);
- } else if(numWrite==total || (numRead+numWrite)==total){
- // code generator is going to handle the case for multiple writes & read/writes.
- seseDS.setType(queueID, SESEWaitingQueue.EXCEPTION);
- refinedSet.addAll(waitingElementSet);
- } else{
- // otherwise, enqueue everything.
- refinedSet.addAll(waitingElementSet);
- }
- seseDS.setWaitingElementSet(queueID, refinedSet);
- } else {
- seseDS.setWaitingElementSet(queueID, waitingElementSet);
- }
-
- }
-
- public boolean isFineElement(int type) {
- if (type == ConflictNode.FINE_READ || type == ConflictNode.FINE_WRITE
- || type == ConflictNode.PARENT_READ
- || type == ConflictNode.PARENT_WRITE) {
- return true;
- } else {
- return false;
- }
- }
-
- 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;
- }
-
- public void writeGraph(String graphName, boolean filter)
- throws java.io.IOException {
-
- graphName = graphName.replaceAll("[\\W]", "");
-
- BufferedWriter bw = new BufferedWriter(new FileWriter(graphName
- + ".dot"));
- bw.write("graph " + graphName + " {\n");
-
- HashSet<HeapRegionNode> visited = new HashSet<HeapRegionNode>();
- // then visit every heap region node
- Set<Entry<String, ConflictNode>> s = id2cn.entrySet();
- Iterator<Entry<String, ConflictNode>> i = s.iterator();
-
- HashSet<ConflictEdge> addedSet = new HashSet<ConflictEdge>();
-
- while (i.hasNext()) {
- Entry<String, ConflictNode> entry = i.next();
- ConflictNode node = entry.getValue();
-
- if (filter) {
- if (node.getID().startsWith("___dst")
- || node.getID().startsWith("___srctmp")
- || node.getID().startsWith("___neverused")
- || node.getID().startsWith("___temp")) {
-
- continue;
- }
- }
-
- String attributes = "[";
-
- attributes += "label=\"ID" + node.getID() + "\\n";
-
- if (node instanceof StallSiteNode) {
- attributes += "STALL SITE" + "\\n" + "\"]";
- } else {
- attributes += "LIVE-IN" + "\\n" + "\"]";
- }
- bw.write(entry.getKey() + attributes + ";\n");
-
- HashSet<ConflictEdge> edgeSet = node.getEdgeSet();
- for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
-
- ConflictNode u = conflictEdge.getVertexU();
- ConflictNode v = conflictEdge.getVertexV();
-
- if (filter) {
- String uID = u.getID();
- String vID = v.getID();
- if (uID.startsWith("___dst") || uID.startsWith("___srctmp")
- || uID.startsWith("___neverused")
- || uID.startsWith("___temp")
- || vID.startsWith("___dst")
- || vID.startsWith("___srctmp")
- || vID.startsWith("___neverused")
- || vID.startsWith("___temp")) {
- continue;
- }
- }
-
- if (!addedSet.contains(conflictEdge)) {
- bw.write(" " + u.getID() + "--" + v.getID() + "[label="
- + conflictEdge.toGraphEdgeString()
- + ",decorate];\n");
- addedSet.add(conflictEdge);
- }
-
- }
- }
-
- bw.write(" graphTitle[label=\"" + graphName + "\",shape=box];\n");
-
- bw.write("}\n");
- bw.close();
-
- }
-
- private int calculateConflictType(StallSiteNode nodeA, LiveInNode nodeB) {
-
- StallSite stallSite = nodeA.getStallSite();
- Set<SESEEffectsKey> writeEffectsSet = nodeB.getWriteEffectsSet();
- Set<SESEEffectsKey> readEffectsSet = nodeB.getReadEffectsSet();
-
- int conflictType = 0;
-
- if (writeEffectsSet != null) {
- Iterator<SESEEffectsKey> writeIter = writeEffectsSet.iterator();
- while (writeIter.hasNext()) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIter
- .next();
- String writeHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String writeFieldName = seseEffectsKey.getFieldDescriptor();
-
- HashSet<HeapRegionNode> stallSiteHRNSet = nodeA.getHRNSet();
- for (Iterator iterator = stallSiteHRNSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode stallHRN = (HeapRegionNode) iterator.next();
- if (stallHRN.getGloballyUniqueIdentifier().equals(
- writeHeapRegionID)) {
- // check whether there are read or write effects of
- // stall sites
- HashSet<Effect> effectSet = stallSite.getEffectSet();
- for (Iterator iterator2 = effectSet.iterator(); iterator2
- .hasNext();) {
- Effect effect = (Effect) iterator2.next();
- String stallEffectfieldName = effect.getField();
-
- if (stallEffectfieldName.equals(writeFieldName)) {
- int newType = determineConflictType(nodeA,
- effect, nodeB, seseEffectsKey);
- if (newType > conflictType) {
- // coarse-grain conflict overrides
- // fine-grain conflict
- conflictType = newType;
- }
- }
- }
- }
- }
-
- }
- }
-
- if (readEffectsSet != null) {
- Iterator<SESEEffectsKey> readIter = readEffectsSet.iterator();
- while (readIter.hasNext()) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) readIter
- .next();
- String readHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String readFieldName = seseEffectsKey.getFieldDescriptor();
-
- HashSet<HeapRegionNode> stallSiteHRNSet = nodeA.getHRNSet();
- for (Iterator iterator = stallSiteHRNSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode stallHRN = (HeapRegionNode) iterator.next();
- if (stallHRN.getGloballyUniqueIdentifier().equals(
- readHeapRegionID)) {
-
- HashSet<Effect> effectSet = stallSite.getEffectSet();
- for (Iterator iterator2 = effectSet.iterator(); iterator2
- .hasNext();) {
- Effect effect = (Effect) iterator2.next();
- String stallEffectfieldName = effect.getField();
-
- if (effect.getEffectType().equals(
- StallSite.WRITE_EFFECT)) {
- if (stallEffectfieldName.equals(readFieldName)) {
- int newType = determineConflictType(nodeA,
- effect, nodeB, seseEffectsKey);
- if (newType > conflictType) {
- // coarse-grain conflict overrides
- // fine-grain conflict
- conflictType = newType;
- }
- }
- }
- }
- }
- }
- }
- }
-//System.out.println("%%%%%%%%%%%%%% RETURN conflictType="+conflictType);
- return conflictType;
- }
-
- private int calculateConflictType(LiveInNode nodeA, LiveInNode nodeB) {
-
- Set<SESEEffectsKey> readEffectsSetA = nodeA.getReadEffectsSet();
- Set<SESEEffectsKey> writeEffectsSetA = nodeA.getWriteEffectsSet();
- Set<SESEEffectsKey> strongUpdateSetA = nodeA.getStrongUpdateSet();
-
- Set<SESEEffectsKey> readEffectsSetB = nodeB.getReadEffectsSet();
- Set<SESEEffectsKey> writeEffectsSetB = nodeB.getWriteEffectsSet();
- Set<SESEEffectsKey> strongUpdateSetB = nodeB.getStrongUpdateSet();
-
- int conflictType = 0;
-
- // if node A has write effects on reading/writing regions of node B
- if (writeEffectsSetA != null) {
- Iterator<SESEEffectsKey> writeIterA = writeEffectsSetA.iterator();
- while (writeIterA.hasNext()) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterA
- .next();
- String writeHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String writeFieldName = seseEffectsKey.getFieldDescriptor();
-
- if (readEffectsSetB != null) {
-
- Iterator<SESEEffectsKey> readIterB = readEffectsSetB
- .iterator();
- while (readIterB.hasNext()) {
- SESEEffectsKey readingEffect = (SESEEffectsKey) readIterB
- .next();
-
- if (readingEffect.getHRNUniqueId().equals(
- writeHeapRegionID)
- && readingEffect.getFieldDescriptor().equals(
- writeFieldName)) {
- int newType = determineConflictType(nodeA,
- seseEffectsKey, nodeB, readingEffect);
- if (newType > conflictType) {
- // coarse-grain conflict overrides fine-grain
- // conflict
- conflictType = newType;
- }
- }
- }
-
- }
-
- if (writeEffectsSetB != null) {
- Iterator<SESEEffectsKey> writeIterB = writeEffectsSetB
- .iterator();
- while (writeIterB.hasNext()) {
- SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterB
- .next();
-
- if (writingEffect.getHRNUniqueId().equals(
- writeHeapRegionID)
- && writingEffect.getFieldDescriptor().equals(
- writeFieldName)) {
- int newType = determineConflictType(nodeA,
- seseEffectsKey, nodeB, writingEffect);
- if (newType > conflictType) {
- // coarse-grain conflict overrides fine-grain
- // conflict
- conflictType = newType;
- }
- }
-
- }
- }
-
- }
- }
-
- // if node B has write effects on reading regions of node A
- if (writeEffectsSetB != null) {
- Iterator<SESEEffectsKey> writeIterB = writeEffectsSetB.iterator();
- while (writeIterB.hasNext()) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIterB
- .next();
-
- // if (!hasStrongUpdate(seseEffectsKey, strongUpdateSetB)) {
-
- String writeHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String writeFieldName = seseEffectsKey.getFieldDescriptor();
-
- if (readEffectsSetA != null) {
- Iterator<SESEEffectsKey> readIterA = readEffectsSetA
- .iterator();
- while (readIterA.hasNext()) {
- SESEEffectsKey readingEffect = (SESEEffectsKey) readIterA
- .next();
-
- if (readingEffect.getHRNUniqueId().equals(
- writeHeapRegionID)
- && readingEffect.getFieldDescriptor().equals(
- writeFieldName)) {
- int newType = determineConflictType(nodeA,
- readingEffect, nodeB, seseEffectsKey);
- if (newType > conflictType) {
- // coarse-grain conflict overrides fine-grain
- // conflict
- conflictType = newType;
- }
- }
-
- }
- }
-
- if (writeEffectsSetA != null) {
- Iterator<SESEEffectsKey> writeIterA = writeEffectsSetA
- .iterator();
- while (writeIterA.hasNext()) {
- SESEEffectsKey writingEffect = (SESEEffectsKey) writeIterA
- .next();
-
- if (writingEffect.getHRNUniqueId().equals(
- writeHeapRegionID)
- && writingEffect.getFieldDescriptor().equals(
- writeFieldName)) {
- int newType = determineConflictType(nodeA,
- writingEffect, nodeB, seseEffectsKey);
- if (newType > conflictType) {
- // coarse-grain conflict overrides fine-grain
- // conflict
- conflictType = newType;
- }
- }
-
- }
- }
-
- }
- }
- return conflictType;
- }
-
- private Set<HeapRegionNode> getSameHeapRoot(Set<HeapRegionNode> setA,
- Set<HeapRegionNode> setB) {
-
- Set<HeapRegionNode> retSet = new HashSet<HeapRegionNode>();
-
- if (compareHRNSet(setA, setB)) {
- for (Iterator iterator = setA.iterator(); iterator.hasNext();) {
- HeapRegionNode heapRegionNode = (HeapRegionNode) iterator
- .next();
- String gID = heapRegionNode.getGloballyUniqueIdentifier();
- for (Iterator iterator2 = setB.iterator(); iterator2.hasNext();) {
- HeapRegionNode heapRegionNode2 = (HeapRegionNode) iterator2
- .next();
- if (heapRegionNode2.getGloballyUniqueIdentifier().equals(
- gID)) {
- retSet.add(heapRegionNode2);
- }
- }
- }
- }
-
- return retSet;
-
- }
-
- private boolean isReachableFrom(HeapRegionNode root1, HeapRegionNode root2,
- ReachabilitySet rset) {
-
- boolean reachable=false;
-
- TokenTuple h1 = new TokenTuple(root1.getID(), !root1.isSingleObject(),
- TokenTuple.ARITY_ONE).makeCanonical();
-
- TokenTuple h1plus = new TokenTuple(root1.getID(), !root1
- .isSingleObject(), TokenTuple.ARITY_ONEORMORE).makeCanonical();
-
- TokenTuple h1star = new TokenTuple(root1.getID(), !root1
- .isSingleObject(), TokenTuple.ARITY_ZEROORMORE).makeCanonical();
-
- TokenTuple h2 = new TokenTuple(root2.getID(), !root2.isSingleObject(),
- TokenTuple.ARITY_ONE).makeCanonical();
-
- TokenTuple h2plus = new TokenTuple(root2.getID(), !root2
- .isSingleObject(), TokenTuple.ARITY_ONEORMORE).makeCanonical();
-
- TokenTuple h2star = new TokenTuple(root2.getID(), !root2
- .isSingleObject(), TokenTuple.ARITY_ZEROORMORE).makeCanonical();
-
- // only do this one if they are different tokens
- if( h1 != h2 &&
- rset.containsTupleSetWithBoth(h1, h2) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1plus, h2) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1star, h2) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1, h2plus) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1plus, h2plus) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1star, h2plus) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1, h2star) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1plus, h2star) ) {
- reachable = true;
- }
- if( rset.containsTupleSetWithBoth(h1star, h2star) ) {
- reachable = true;
- }
-
- return reachable;
-
- }
-
- private int determineConflictType(StallSiteNode stallSiteNodeA,
- Effect effect, LiveInNode liveInNodeB,
- SESEEffectsKey effectB) {
-
- Set<HeapRegionNode> liveInHrnSetA = stallSiteNodeA.getStallSite().getHRNSet();
- Set<HeapRegionNode> liveInHrnSetB = liveInNodeB.getHRNSet();
-
- // check whether alloc site is reached from both heap roots
- boolean isDisjoint=true;
- HeapRegionNode effectHrn=og.gid2hrn.get(effectB.getHRNUniqueId());
- if(effectHrn.isSingleObject()){
- for (Iterator iterator = liveInHrnSetA.iterator(); iterator.hasNext();) {
- HeapRegionNode r1 = (HeapRegionNode) iterator.next();
- for (Iterator iterator2 = liveInHrnSetB.iterator(); iterator2.hasNext();) {
- HeapRegionNode r2 = (HeapRegionNode) iterator2.next();
- r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier());
- r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier());
- if(isReachableFrom(r1,r2,effectB.getRSet())){
- isDisjoint=false;
- }
- }
- }
- if(isDisjoint){
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
- }
-
- /*
- HeapRegionNode r1=liveInHrnSetA.iterator().next();
- HeapRegionNode r2=liveInHrnSetB.iterator().next();
-
- r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier());
- r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier());
-
- System.out.println("r1="+r1);
- System.out.println("r2="+r2);
- System.out.println("effectB="+effectB.getRSet());
- System.out.println("###STALL calculateConflictType2");
- if(!isReachableFrom(r1,r2,effectB.getRSet())){
- System.out.println("###STALL calculateConflictType3");
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
- */
- Set<HeapRegionNode> entryHRNSet = getSameHeapRoot(liveInHrnSetA,
- liveInHrnSetB);
- if (entryHRNSet.size() == 0) {
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }
-
- for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
-
- String entryIdentifier = hrn.getGloballyUniqueIdentifier();
- HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier);
-
- TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN
- .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical();
-
- TokenTuple h1star = new TokenTuple(entryHRN.getID(), true,
- TokenTuple.ARITY_ONEORMORE).makeCanonical();
-
- if (effectB.getRSet().containsTuple(h1star)) {
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }else if (effectB.getRSet().containsTuple(h1)) {
- // rechability states contain heap root with arity 1
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
- }
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
-
- private int determineConflictType(LiveInNode liveInNodeA,
- SESEEffectsKey effectA, LiveInNode liveInNodeB,
- SESEEffectsKey effectB) {
-
- if (liveInNodeA.getSESEIdentifier() == liveInNodeB.getSESEIdentifier()) {
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
-
- Set<HeapRegionNode> liveInHrnSetA = liveInNodeA.getHRNSet();
- Set<HeapRegionNode> liveInHrnSetB = liveInNodeB.getHRNSet();
-
- // check whether alloc site is reached from both heap roots
- boolean isDisjoint=true;
- HeapRegionNode effectHrn=og.gid2hrn.get(effectB.getHRNUniqueId());
- if(effectHrn.isSingleObject()){
- for (Iterator iterator = liveInHrnSetA.iterator(); iterator.hasNext();) {
- HeapRegionNode r1 = (HeapRegionNode) iterator.next();
- for (Iterator iterator2 = liveInHrnSetB.iterator(); iterator2.hasNext();) {
- HeapRegionNode r2 = (HeapRegionNode) iterator2.next();
- r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier());
- r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier());
-
- if(isReachableFrom(r1,r2,effectB.getRSet())){
- isDisjoint=false;
- }else{
- }
- }
- }
- if(isDisjoint){
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
- }
-
- /*
- HeapRegionNode r1=liveInHrnSetA.iterator().next();
- HeapRegionNode r2=liveInHrnSetB.iterator().next();
-
-// r1=og.gid2hrn.get(r1.getGloballyUniqueIdentifier());
-// r2=og.gid2hrn.get(r2.getGloballyUniqueIdentifier());
- System.out.println("@@r1="+r1);
- System.out.println("@@r2="+r2);
- System.out.println("@@effectB="+effectA.getRSet());
-
- if(!isReachableFrom(r1,r2,effectA.getRSet())){
- // two heap root are disjoint
- return ConflictEdge.NON_WRITE_CONFLICT;
- }
- */
-
- Set<HeapRegionNode> entryHRNSet = getSameHeapRoot(liveInHrnSetA,
- liveInHrnSetB);
- if (entryHRNSet.size() == 0 ) {
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }
- if(entryHRNSet.size()!=liveInHrnSetA.size() || entryHRNSet.size()!=liveInHrnSetB.size()){
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }
-
- int count=0;
- for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
- if(hrn.getType()!=null && hrn.getType().isImmutable()){
- count++;
- }
- }
- if(count==entryHRNSet.size()){
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
-
- for (Iterator iterator = entryHRNSet.iterator(); iterator.hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
-
- String entryIdentifier = hrn.getGloballyUniqueIdentifier();
- HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier);
-
- TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN
- .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical();
-
- TokenTuple h1star = new TokenTuple(entryHRN.getID(), true,
- TokenTuple.ARITY_ONEORMORE).makeCanonical();
-
- if (effectA.getRSet().containsTuple(h1star)) {
- return ConflictEdge.COARSE_GRAIN_EDGE;
- } else if (effectA.getRSet().containsTuple(h1)) {
- // rechability states contain heap root with arity 1
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
-
- }
-
- return ConflictEdge.NON_WRITE_CONFLICT;
-
- }
-
- private int calculateSelfConflictType(LiveInNode liveInNode) {
-
- // if strong update effect exists, it conflicts every effects of objects that are reachable from same heap root
- Set<SESEEffectsKey> strongUpdateSet = liveInNode.getStrongUpdateSet();
- if(strongUpdateSet!=null && strongUpdateSet.size()>0){
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
-
- if (liveInNode.getWriteEffectsSet() != null
- && liveInNode.getWriteEffectsSet().size() > 0) {
-
- Set<SESEEffectsKey> writeEffectsSet=liveInNode.getWriteEffectsSet();
-
- int immuntableCount = 0;
- for (Iterator<HeapRegionNode> iterator = liveInNode.getHRNSet()
- .iterator(); iterator.hasNext();) {
- HeapRegionNode root = iterator.next();
- if(root.getType()!=null && root.getType().isImmutable()){
- immuntableCount++;
- }
- }
- if (immuntableCount == liveInNode.getHRNSet().size()) {
- // in this case, heap root is a parameter heap region
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
-
-
- int paramCount = 0;
- for (Iterator<HeapRegionNode> iterator = liveInNode.getHRNSet()
- .iterator(); iterator.hasNext();) {
- HeapRegionNode root = iterator.next();
- if (root.isParameter()) {
- paramCount++;
- }
- }
-
- if (paramCount == liveInNode.getHRNSet().size()) {
- // in this case, heap root is a parameter heap region
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
-
- if (liveInNode.getHRNSet().size()==1) {
- HeapRegionNode hrn = liveInNode.getHRNSet().iterator().next();
- String entryIdentifier = hrn.getGloballyUniqueIdentifier();
- HeapRegionNode entryHRN = og.gid2hrn.get(entryIdentifier);
-
- boolean containsStar=false;
- for (Iterator iterator = writeEffectsSet.iterator(); iterator
- .hasNext();) {
- SESEEffectsKey effect = (SESEEffectsKey) iterator.next();
- TokenTuple h1 = new TokenTuple(entryHRN.getID(), !entryHRN
- .isSingleObject(), TokenTuple.ARITY_ONE).makeCanonical();
- TokenTuple h1star = new TokenTuple(entryHRN.getID(), true, TokenTuple.ARITY_ZEROORMORE).makeCanonical();
- if (effect.getRSet().containsTuple(h1star)) {
- // rechability states contain heap root with arity star
- containsStar=true;
- }
- }
- if(containsStar){
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }else{
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
- }else{
- return ConflictEdge.COARSE_GRAIN_EDGE;
- }
-
-
- /*
- boolean containsAllTuple=true;
- for (Iterator iterator2 = writeEffectsSet.iterator(); iterator2
- .hasNext();) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2
- .next();
- ReachabilitySet rset = seseEffectsKey.getRSet();
- Iterator<TokenTupleSet> tsetIter=rset.iterator();
- int countNotContained=0;
- while (tsetIter.hasNext()) {
- TokenTupleSet tokenTupleSet = (TokenTupleSet) tsetIter
- .next();
- boolean found=true;
- for (Iterator iterator = rootIDSet.iterator(); iterator
- .hasNext();) {
- Integer rootID = (Integer) iterator.next();
- if(tokenTupleSet.containsToken(rootID)==null){
- found=false;
- }
- }
- if(!found){
- countNotContained++;
- }
- }
- if(countNotContained==rset.size()){
- containsAllTuple=false;
- }
- }
-
- if (containsAllTuple && liveInNode.getHRNSet().size() > 1) {
- return ConflictEdge.COARSE_GRAIN_EDGE;
- } else {
- return ConflictEdge.FINE_GRAIN_EDGE;
- }
- */
-
-
-
- }
-
- return ConflictEdge.NON_WRITE_CONFLICT;
-
- }
-
- public void analyzePossibleConflicts(Set<String> analyzedIDSet,
- ConflictNode currentNode) {
-
- // compare with all nodes
- // examine the case where self-edge exists
- if (currentNode instanceof LiveInNode) {
- LiveInNode liveInNode = (LiveInNode) currentNode;
- int conflictType=calculateSelfConflictType(liveInNode);
- if(conflictType>0){
- addConflictEdge(conflictType, currentNode,
- currentNode);
- }
- }
-
- Set<Entry<String, ConflictNode>> set = id2cn.entrySet();
- for (Iterator iterator = set.iterator(); iterator.hasNext();) {
- Entry<String, ConflictNode> entry = (Entry<String, ConflictNode>) iterator
- .next();
-
- String entryNodeID = entry.getKey();
- ConflictNode entryNode = entry.getValue();
-
- if ((!currentNode.getID().equals(entryNodeID))
- && !(analyzedIDSet.contains(currentNode.getID()
- + entryNodeID) || analyzedIDSet
- .contains(entryNodeID + currentNode.getID()))) {
-
- if (currentNode instanceof StallSiteNode
- && entryNode instanceof LiveInNode) {
-
- int conflictType = calculateConflictType((StallSiteNode) currentNode, (LiveInNode) entryNode);
- if (conflictType > 0) {
- addConflictEdge(conflictType, currentNode, entryNode);
- }
-
- analyzedIDSet.add(currentNode.getID() + entryNodeID);
-
- } else if (currentNode instanceof LiveInNode
- && entryNode instanceof LiveInNode) {
-
- int conflictType = calculateConflictType(
- (LiveInNode) currentNode, (LiveInNode) entryNode);
- if (conflictType > 0) {
- addConflictEdge(conflictType, currentNode, entryNode);
- }
- analyzedIDSet.add(currentNode.getID() + entryNodeID);
- }
-
- }
-
- }
-
- }
-
-}
-
-class ConflictEdge {
-
- private ConflictNode u;
- private ConflictNode v;
- private int type;
-
- 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 ConflictEdge(ConflictNode u, ConflictNode v, int type) {
- this.u = u;
- this.v = v;
- this.type = type;
- }
-
- public String toGraphEdgeString() {
- if (type == FINE_GRAIN_EDGE) {
- return "\"F_CONFLICT\"";
- } else if (type == COARSE_GRAIN_EDGE) {
- return "\"C_CONFLICT\"";
- } else {
- return "CONFLICT\"";
- }
- }
-
- public ConflictNode getVertexU() {
- return u;
- }
-
- public ConflictNode getVertexV() {
- return v;
- }
-
- public int getType() {
- return type;
- }
-
- public String toString() {
- return getVertexU() + "-" + getVertexV();
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import IR.Flat.TempDescriptor;
-
-public abstract class ConflictNode {
-
- protected TempDescriptor td;
- protected String id;
- protected HashSet<ConflictEdge> edgeSet;
- protected Set<Set> reachabilitySet;
- protected TempDescriptor alias;
- protected int type;
-
- public static final int FINE_READ = 0;
- public static final int FINE_WRITE = 1;
- public static final int PARENT_READ = 2;
- public static final int PARENT_WRITE = 3;
- public static final int COARSE = 4;
- public static final int PARENT_COARSE = 5;
- public static final int SCC = 6;
-
-
-
- public ConflictNode() {
- edgeSet = new HashSet<ConflictEdge>();
- }
-
- public TempDescriptor getTempDescriptor() {
- return td;
- }
-
- public String getID() {
- return id;
- }
-
- public int getType(){
- return type;
- }
-
- public void setType(int type){
- this.type=type;
- }
- public void addEdge(ConflictEdge edge) {
- edgeSet.add(edge);
- }
-
- public HashSet<ConflictEdge> getEdgeSet() {
- return edgeSet;
- }
-
- public Set<Set> getReachabilitySet() {
- return reachabilitySet;
- }
-
- public TempDescriptor getAlias(){
- return alias;
- }
-
- public void setAlias(TempDescriptor alias){
- this.alias=alias;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import Analysis.OwnershipAnalysis.Canonical;
-import Analysis.OwnershipAnalysis.TokenTuple;
-
-public class GloballyUniqueTokenTuple extends Canonical{
-
- private Integer token;
- private boolean isMultiObject;
- private int arity;
- private String id;
-
- public GloballyUniqueTokenTuple(String uniqueID, TokenTuple tt) {
- this.id = uniqueID;
- this.arity = tt.getArity();
- this.token = tt.getToken();
- this.isMultiObject = tt.isMultiObject();
- }
-
- public boolean isMultiObject() {
- return isMultiObject;
- }
-
- public int getArity() {
- return arity;
- }
-
- public int hashCode() {
- return id.hashCode() + arity;
- }
-
- public String getID() {
- return id;
- }
-
- public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof GloballyUniqueTokenTuple)) {
- return false;
- }
-
- GloballyUniqueTokenTuple tt = (GloballyUniqueTokenTuple) o;
-
- return id.equals(tt.getID()) && arity == tt.getArity();
- }
-
- public String toString() {
- String s = id;
-
- if (isMultiObject) {
- s += "M";
- }
-
- if (arity == TokenTuple.ARITY_ZEROORMORE) {
- s += "*";
- } else if (arity == TokenTuple.ARITY_ONEORMORE) {
- s += "+";
- }
-
- return s;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import IR.Flat.TempDescriptor;
-
-public class LiveInNode extends ConflictNode {
-
- Set<SESEEffectsKey> readEffectsSet;
- Set<SESEEffectsKey> writeEffectsSet;
- Set<SESEEffectsKey> strongUpdateSet;
- Set<HeapRegionNode> hrnSet;
- int seseID;
-
- public LiveInNode(String id, TempDescriptor td, Set<HeapRegionNode> hrnSet,
- Set<SESEEffectsKey> readEffectsSet,
- Set<SESEEffectsKey> writeEffectsSet, Set<SESEEffectsKey> strongUpdateSet, Set<Set> reachabilitySet, int seseID) {
- this.hrnSet = hrnSet;
- this.id = id;
- this.td = td;
- this.readEffectsSet = readEffectsSet;
- this.writeEffectsSet = writeEffectsSet;
- this.strongUpdateSet=strongUpdateSet;
- this.reachabilitySet = reachabilitySet;
- this.seseID=seseID;
- }
-
- public Set<HeapRegionNode> getHRNSet() {
- return hrnSet;
- }
-
- public Set<SESEEffectsKey> getReadEffectsSet() {
- return readEffectsSet;
- }
-
- public Set<SESEEffectsKey> getWriteEffectsSet() {
- return writeEffectsSet;
- }
-
- public Set<SESEEffectsKey> getStrongUpdateSet(){
- return strongUpdateSet;
- }
-
- public void addReadEffectsSet(Set<SESEEffectsKey> newReadEffectsSet) {
- if (newReadEffectsSet != null) {
- readEffectsSet.addAll(newReadEffectsSet);
- }
- }
-
- public void addWriteEffectsSet(Set<SESEEffectsKey> newWriteEffectsSet) {
- if (newWriteEffectsSet != null) {
- writeEffectsSet.addAll(newWriteEffectsSet);
- }
- }
-
- public void addReachabilitySet(Set<Set> newReachabilitySet) {
- if (newReachabilitySet != null) {
- reachabilitySet.addAll(newReachabilitySet);
- }
- }
-
- public boolean isWriteConflictWith(StallSiteNode stallNode) {
-
- // if live-in var has write-effects on heap region node of stall site,
- // it is write conflict
-
- boolean result = false;
- StallSite stallSite = stallNode.getStallSite();
-
- if (writeEffectsSet != null) {
- Iterator<SESEEffectsKey> writeIter = writeEffectsSet.iterator();
- while (writeIter.hasNext()) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) writeIter
- .next();
- String writeHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String writeFieldName = seseEffectsKey.getFieldDescriptor();
-
- HashSet<HeapRegionNode> stallSiteHRNSet = stallNode.getHRNSet();
- for (Iterator iterator = stallSiteHRNSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode stallHRN = (HeapRegionNode) iterator.next();
- if (stallHRN.getGloballyUniqueIdentifier().equals(
- writeHeapRegionID)) {
-
- // check whether there are read or write effects of
- // stall sites
-
- HashSet<Effect> effectSet = stallSite.getEffectSet();
- for (Iterator iterator2 = effectSet.iterator(); iterator2
- .hasNext();) {
- Effect effect = (Effect) iterator2.next();
- String stallEffectfieldName = effect.getField();
-
- if (stallEffectfieldName.equals(writeFieldName)) {
- result = result | true;
- }
- }
-
- }
- }
-
- }
- }
-
- if (readEffectsSet != null) {
- Iterator<SESEEffectsKey> readIter = readEffectsSet.iterator();
- while (readIter.hasNext()) {
-
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) readIter
- .next();
- String readHeapRegionID = seseEffectsKey.getHRNUniqueId();
- String readFieldName = seseEffectsKey.getFieldDescriptor();
-
- HashSet<HeapRegionNode> stallSiteHRNSet = stallNode.getHRNSet();
- for (Iterator iterator = stallSiteHRNSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode stallHRN = (HeapRegionNode) iterator.next();
- if (stallHRN.getGloballyUniqueIdentifier().equals(
- readHeapRegionID)) {
-
- HashSet<Effect> effectSet = stallSite.getEffectSet();
- for (Iterator iterator2 = effectSet.iterator(); iterator2
- .hasNext();) {
- Effect effect = (Effect) iterator2.next();
- String stallEffectfieldName = effect.getField();
-
- if (effect.getEffectType().equals(
- StallSite.WRITE_EFFECT)) {
- if (stallEffectfieldName.equals(readFieldName)) {
- result = result | true;
- }
- }
-
- }
-
- }
-
- }
-
- }
- }
-
- return result;
- }
-
- public int getSESEIdentifier(){
- return seseID;
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof LiveInNode)) {
- return false;
- }
-
- LiveInNode in = (LiveInNode) o;
-
- if (id.equals(in.id)) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public String toString() {
- String str = "LiveInNode " + id +" type="+type;
- return str;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-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;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Collection;
-import java.util.Set;
-import java.util.Stack;
-import java.util.Map.Entry;
-import Analysis.CallGraph.CallGraph;
-import Analysis.CallGraph.JavaCallGraph;
-import Analysis.OwnershipAnalysis.AllocationSite;
-import Analysis.OwnershipAnalysis.EffectsKey;
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import Analysis.OwnershipAnalysis.LabelNode;
-import Analysis.OwnershipAnalysis.MethodContext;
-import Analysis.OwnershipAnalysis.MethodEffects;
-import Analysis.OwnershipAnalysis.OwnershipAnalysis;
-import Analysis.OwnershipAnalysis.OwnershipGraph;
-import Analysis.OwnershipAnalysis.OwnershipNode;
-import Analysis.OwnershipAnalysis.ParameterDecomposition;
-import Analysis.OwnershipAnalysis.ReachabilitySet;
-import Analysis.OwnershipAnalysis.ReferenceEdge;
-import Analysis.OwnershipAnalysis.TokenTuple;
-import Analysis.OwnershipAnalysis.TokenTupleSet;
-import IR.Descriptor;
-import IR.FieldDescriptor;
-import IR.MethodDescriptor;
-import IR.Operation;
-import IR.State;
-import IR.TypeDescriptor;
-import IR.TypeUtil;
-import IR.Flat.FKind;
-import IR.Flat.FlatCall;
-import IR.Flat.FlatCondBranch;
-import IR.Flat.FlatEdge;
-import IR.Flat.FlatElementNode;
-import IR.Flat.FlatFieldNode;
-import IR.Flat.FlatMethod;
-import IR.Flat.FlatNew;
-import IR.Flat.FlatNode;
-import IR.Flat.FlatOpNode;
-import IR.Flat.FlatReturnNode;
-import IR.Flat.FlatSESEEnterNode;
-import IR.Flat.FlatSESEExitNode;
-import IR.Flat.FlatSetElementNode;
-import IR.Flat.FlatSetFieldNode;
-import IR.Flat.FlatWriteDynamicVarNode;
-import IR.Flat.TempDescriptor;
-
-
-public class MLPAnalysis {
-
- // data from the compiler
- private State state;
- private TypeUtil typeUtil;
- private CallGraph callGraph;
- private OwnershipAnalysis ownAnalysis;
-
-
- // an implicit SESE is automatically spliced into
- // the IR graph around the C main before this analysis--it
- // is nothing special except that we can make assumptions
- // about it, such as the whole program ends when it ends
- private FlatSESEEnterNode mainSESE;
-
- // SESEs that are the root of an SESE tree belong to this
- // set--the main SESE is always a root, statically SESEs
- // inside methods are a root because we don't know how they
- // will fit into the runtime tree of SESEs
- private Set<FlatSESEEnterNode> rootSESEs;
-
- // simply a set of every reachable SESE in the program, not
- // including caller placeholder SESEs
- private Set<FlatSESEEnterNode> allSESEs;
-
-
- // A mapping of flat nodes to the stack of SESEs for that node, where
- // an SESE is the child of the SESE directly below it on the stack.
- // These stacks do not reflect the heirarchy over methods calls--whenever
- // there is an empty stack it means all variables are available.
- private Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks;
-
- private Hashtable< FlatNode, Set<TempDescriptor> > livenessRootView;
- private Hashtable< FlatNode, Set<TempDescriptor> > livenessVirtualReads;
- private Hashtable< FlatNode, VarSrcTokTable > variableResults;
- private Hashtable< FlatNode, Set<TempDescriptor> > notAvailableResults;
- private Hashtable< FlatNode, CodePlan > codePlans;
-
- private Hashtable< FlatSESEEnterNode, Set<TempDescriptor> > notAvailableIntoSESE;
-
- private Hashtable< FlatEdge, FlatWriteDynamicVarNode > wdvNodesToSpliceIn;
-
- private Hashtable< MethodContext, HashSet<AllocationSite>> mapMethodContextToLiveInAllocationSiteSet;
-
- private Hashtable < FlatNode, ParentChildConflictsMap > conflictsResults;
- private Hashtable< FlatMethod, MethodSummary > methodSummaryResults;
- private OwnershipAnalysis ownAnalysisForSESEConflicts;
- private Hashtable <FlatNode, ConflictGraph> conflictGraphResults;
-
- // temporal data structures to track analysis progress.
- private MethodSummary currentMethodSummary;
- private HashSet<PreEffectsKey> preeffectsSet;
- private Hashtable<FlatNode, Boolean> isAfterChildSESEIndicatorMap;
- private Hashtable<FlatNode, SESESummary> seseSummaryMap;
- private Hashtable<ConflictGraph, HashSet<SESELock>> conflictGraphLockMap;
- static private int uniqueLockSetId = 0;
-
- public static int maxSESEage = -1;
-
-
- // use these methods in BuildCode to have access to analysis results
- public FlatSESEEnterNode getMainSESE() {
- return mainSESE;
- }
-
- public Set<FlatSESEEnterNode> getRootSESEs() {
- return rootSESEs;
- }
-
- public Set<FlatSESEEnterNode> getAllSESEs() {
- return allSESEs;
- }
-
- public int getMaxSESEage() {
- return maxSESEage;
- }
-
- // may be null
- public CodePlan getCodePlan( FlatNode fn ) {
- CodePlan cp = codePlans.get( fn );
- return cp;
- }
-
-
- public MLPAnalysis( State state,
- TypeUtil tu,
- CallGraph callGraph,
- OwnershipAnalysis ownAnalysis
- ) {
-
- double timeStartAnalysis = (double) System.nanoTime();
-
- this.state = state;
- this.typeUtil = tu;
- this.callGraph = callGraph;
- this.ownAnalysis = ownAnalysis;
- this.maxSESEage = state.MLP_MAXSESEAGE;
-
- rootSESEs = new HashSet<FlatSESEEnterNode>();
- allSESEs = new HashSet<FlatSESEEnterNode>();
-
- seseStacks = new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
- livenessRootView = new Hashtable< FlatNode, Set<TempDescriptor> >();
- livenessVirtualReads = new Hashtable< FlatNode, Set<TempDescriptor> >();
- variableResults = new Hashtable< FlatNode, VarSrcTokTable >();
- notAvailableResults = new Hashtable< FlatNode, Set<TempDescriptor> >();
- codePlans = new Hashtable< FlatNode, CodePlan >();
- wdvNodesToSpliceIn = new Hashtable< FlatEdge, FlatWriteDynamicVarNode >();
-
- notAvailableIntoSESE = new Hashtable< FlatSESEEnterNode, Set<TempDescriptor> >();
-
- mapMethodContextToLiveInAllocationSiteSet = new Hashtable< MethodContext, HashSet<AllocationSite>>();
-
- conflictsResults = new Hashtable < FlatNode, ParentChildConflictsMap >();
- methodSummaryResults=new Hashtable<FlatMethod, MethodSummary>();
- conflictGraphResults=new Hashtable<FlatNode, ConflictGraph>();
-
- seseSummaryMap= new Hashtable<FlatNode, SESESummary>();
- isAfterChildSESEIndicatorMap= new Hashtable<FlatNode, Boolean>();
- conflictGraphLockMap=new Hashtable<ConflictGraph, HashSet<SESELock>>();
-
- FlatMethod fmMain = state.getMethodFlat( typeUtil.getMain() );
-
- mainSESE = (FlatSESEEnterNode) fmMain.getNext(0);
- mainSESE.setfmEnclosing( fmMain );
- mainSESE.setmdEnclosing( fmMain.getMethod() );
- mainSESE.setcdEnclosing( fmMain.getMethod().getClassDesc() );
-
-
- // 1st pass
- // run analysis on each method that is actually called
- // reachability analysis already computed this so reuse
- Iterator<Descriptor> methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
-
- // find every SESE from methods that may be called
- // and organize them into roots and children
- buildForestForward( fm );
- }
-
-
- // 2nd pass, results are saved in FlatSESEEnterNode, so
- // intermediate results, for safety, are discarded
- Iterator<FlatSESEEnterNode> rootItr = rootSESEs.iterator();
- while( rootItr.hasNext() ) {
- FlatSESEEnterNode root = rootItr.next();
- livenessAnalysisBackward( root,
- true,
- null );
- }
-
-
- // 3rd pass
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
-
- // starting from roots do a forward, fixed-point
- // variable analysis for refinement and stalls
- variableAnalysisForward( fm );
- }
-
- // 4th pass, compute liveness contribution from
- // virtual reads discovered in variable pass
- rootItr = rootSESEs.iterator();
- while( rootItr.hasNext() ) {
- FlatSESEEnterNode root = rootItr.next();
- livenessAnalysisBackward( root,
- true,
- null );
- }
-
-
- /*
- SOMETHING IS WRONG WITH THIS, DON'T USE IT UNTIL IT CAN BE FIXED
-
- // 5th pass
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
-
- // prune variable results in one traversal
- // by removing reference variables that are not live
- pruneVariableResultsWithLiveness( fm );
- }
- */
-
-
- // 6th pass
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
-
- // compute what is not available at every program
- // point, in a forward fixed-point pass
- notAvailableForward( fm );
- }
-
- if(state.METHODEFFECTS){
- // new pass, sese effects analysis
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- JavaCallGraph javaCallGraph = new JavaCallGraph(state,tu);
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
- methodEffects(fm,javaCallGraph);
- }
-
- // Parent/child memory conflicts analysis
- seseConflictsForward(javaCallGraph);
-
- Set<MethodContext> keySet=mapMethodContextToLiveInAllocationSiteSet.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- MethodContext methodContext = (MethodContext) iterator.next();
- HashSet<AllocationSite> asSet=mapMethodContextToLiveInAllocationSiteSet.get(methodContext);
- for (Iterator iterator2 = asSet.iterator(); iterator2.hasNext();) {
- AllocationSite allocationSite = (AllocationSite) iterator2.next();
- }
- }
-
- // disjoint analysis with a set of flagged allocation sites of live-in variables & stall sites
- try {
- ownAnalysisForSESEConflicts = new OwnershipAnalysis(state,
- tu,
- callGraph,
- ownAnalysis.liveness,
- ownAnalysis.arrayReferencees,
- state.OWNERSHIPALLOCDEPTH, false,
- false, state.OWNERSHIPALIASFILE,
- state.METHODEFFECTS,
- mapMethodContextToLiveInAllocationSiteSet);
- // debug
- methItr = ownAnalysisForSESEConflicts.descriptorsToAnalyze.iterator();
- while (methItr.hasNext()) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat(d);
- debugFunction(ownAnalysisForSESEConflicts, fm);
- }
- //
- } catch (IOException e) {
- System.err.println(e);
- }
-
- // postSESEConflictsForward(javaCallGraph);
- // another pass for making graph
- makeConflictGraph();
-
- // lock synthesis
- synthesizeLocks();
- /*
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while (methItr.hasNext()) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat(d);
- 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 {
- if(cg.hasConflictEdge()){
- cg.writeGraph("ConflictGraphFor"+key, false);
- }
- } catch (IOException e) {
- System.out.println("Error writing");
- System.exit(0);
- }
- }
- }
-
-
- // 7th pass
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat( d );
-
- // compute a plan for code injections
- codePlansForward( fm );
- }
-
-
- // splice new IR nodes into graph after all
- // analysis passes are complete
- Iterator spliceItr = wdvNodesToSpliceIn.entrySet().iterator();
- while( spliceItr.hasNext() ) {
- Map.Entry me = (Map.Entry) spliceItr.next();
- FlatWriteDynamicVarNode fwdvn = (FlatWriteDynamicVarNode) me.getValue();
- fwdvn.spliceIntoIR();
- }
-
-
- double timeEndAnalysis = (double) System.nanoTime();
- double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) );
- String treport = String.format( "The mlp analysis took %.3f sec.", dt );
- System.out.println( treport );
-
- if( state.MLPDEBUG ) {
- try {
- writeReports( treport );
- } catch( IOException e ) {}
- }
- }
-
-
- private void buildForestForward( FlatMethod fm ) {
-
- // start from flat method top, visit every node in
- // method exactly once, find SESEs and remember
- // roots and child relationships
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
-
- Set<FlatNode> visited = new HashSet<FlatNode>();
-
- Stack<FlatSESEEnterNode> seseStackFirst = new Stack<FlatSESEEnterNode>();
- seseStacks.put( fm, seseStackFirst );
-
- while( !flatNodesToVisit.isEmpty() ) {
- Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
- FlatNode fn = fnItr.next();
-
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
- assert seseStack != null;
-
- flatNodesToVisit.remove( fn );
- visited.add( fn );
-
- buildForest_nodeActions( fn, seseStack, fm );
-
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
-
- if( !visited.contains( nn ) ) {
- flatNodesToVisit.add( nn );
-
- // clone stack and send along each analysis path
- seseStacks.put( nn, (Stack<FlatSESEEnterNode>)seseStack.clone() );
- }
- }
- }
- }
-
- private void buildForest_nodeActions( FlatNode fn,
- Stack<FlatSESEEnterNode> seseStack,
- FlatMethod fm ) {
- switch( fn.kind() ) {
-
- case FKind.FlatSESEEnterNode: {
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
-
- if( !fsen.getIsCallerSESEplaceholder() ) {
- allSESEs.add( fsen );
- }
-
- fsen.setfmEnclosing( fm );
- fsen.setmdEnclosing( fm.getMethod() );
- fsen.setcdEnclosing( fm.getMethod().getClassDesc() );
-
- if( seseStack.empty() ) {
- rootSESEs.add( fsen );
- fsen.setParent( null );
- } else {
- seseStack.peek().addChild( fsen );
- fsen.setParent( seseStack.peek() );
- }
-
- seseStack.push( fsen );
- } break;
-
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- assert !seseStack.empty();
- FlatSESEEnterNode fsen = seseStack.pop();
- } break;
-
- case FKind.FlatReturnNode: {
- FlatReturnNode frn = (FlatReturnNode) fn;
- if( !seseStack.empty() &&
- !seseStack.peek().getIsCallerSESEplaceholder()
- ) {
- throw new Error( "Error: return statement enclosed within SESE "+
- seseStack.peek().getPrettyIdentifier() );
- }
- } break;
-
- }
- }
-
-
- private void livenessAnalysisBackward( FlatSESEEnterNode fsen,
- boolean toplevel,
- Hashtable< FlatSESEExitNode, Set<TempDescriptor> > liveout ) {
-
- // start from an SESE exit, visit nodes in reverse up to
- // SESE enter in a fixed-point scheme, where children SESEs
- // should already be analyzed and therefore can be skipped
- // because child SESE enter node has all necessary info
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-
- if( toplevel ) {
- flatNodesToVisit.add( fsen.getfmEnclosing().getFlatExit() );
- } else {
- flatNodesToVisit.add( fsen.getFlatExit() );
- }
-
- Hashtable<FlatNode, Set<TempDescriptor>> livenessResults =
- new Hashtable< FlatNode, Set<TempDescriptor> >();
-
- if( toplevel ) {
- liveout = new Hashtable< FlatSESEExitNode, Set<TempDescriptor> >();
- }
-
- while( !flatNodesToVisit.isEmpty() ) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove( fn );
-
- Set<TempDescriptor> prev = livenessResults.get( fn );
-
- // merge sets from control flow joins
- Set<TempDescriptor> u = new HashSet<TempDescriptor>();
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- Set<TempDescriptor> s = livenessResults.get( nn );
- if( s != null ) {
- u.addAll( s );
- }
- }
-
- Set<TempDescriptor> curr = liveness_nodeActions( fn, u, fsen, toplevel, liveout);
-
- // if a new result, schedule backward nodes for analysis
- if( !curr.equals( prev ) ) {
- livenessResults.put( fn, curr );
-
- // don't flow backwards past current SESE enter
- if( !fn.equals( fsen ) ) {
- for( int i = 0; i < fn.numPrev(); i++ ) {
- FlatNode nn = fn.getPrev( i );
- flatNodesToVisit.add( nn );
- }
- }
- }
- }
-
- Set<TempDescriptor> s = livenessResults.get( fsen );
- if( s != null ) {
- fsen.addInVarSet( s );
- }
-
- // remember liveness per node from the root view as the
- // global liveness of variables for later passes to use
- if( toplevel ) {
- livenessRootView.putAll( livenessResults );
- }
-
- // post-order traversal, so do children first
- Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
- while( childItr.hasNext() ) {
- FlatSESEEnterNode fsenChild = childItr.next();
- livenessAnalysisBackward( fsenChild, false, liveout );
- }
- }
-
- private Set<TempDescriptor> liveness_nodeActions( FlatNode fn,
- Set<TempDescriptor> liveIn,
- FlatSESEEnterNode currentSESE,
- boolean toplevel,
- Hashtable< FlatSESEExitNode, Set<TempDescriptor> > liveout
- ) {
- switch( fn.kind() ) {
-
- case FKind.FlatSESEExitNode:
- if( toplevel ) {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- if( !liveout.containsKey( fsexn ) ) {
- liveout.put( fsexn, new HashSet<TempDescriptor>() );
- }
- liveout.get( fsexn ).addAll( liveIn );
- }
- // no break, sese exits should also execute default actions
-
- default: {
- // handle effects of statement in reverse, writes then reads
- TempDescriptor [] writeTemps = fn.writesTemps();
- for( int i = 0; i < writeTemps.length; ++i ) {
- liveIn.remove( writeTemps[i] );
-
- if( !toplevel ) {
- FlatSESEExitNode fsexn = currentSESE.getFlatExit();
- Set<TempDescriptor> livetemps = liveout.get( fsexn );
- if( livetemps != null &&
- livetemps.contains( writeTemps[i] ) ) {
- // write to a live out temp...
- // need to put in SESE liveout set
- currentSESE.addOutVar( writeTemps[i] );
- }
- }
- }
-
- TempDescriptor [] readTemps = fn.readsTemps();
- for( int i = 0; i < readTemps.length; ++i ) {
- liveIn.add( readTemps[i] );
- }
-
- Set<TempDescriptor> virtualReadTemps = livenessVirtualReads.get( fn );
- if( virtualReadTemps != null ) {
- liveIn.addAll( virtualReadTemps );
- }
-
- } break;
-
- } // end switch
-
- return liveIn;
- }
-
-
- private void variableAnalysisForward( FlatMethod fm ) {
-
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
-
- while( !flatNodesToVisit.isEmpty() ) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove( fn );
-
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
- assert seseStack != null;
-
- VarSrcTokTable prev = variableResults.get( fn );
-
- // merge sets from control flow joins
- VarSrcTokTable curr = new VarSrcTokTable();
- for( int i = 0; i < fn.numPrev(); i++ ) {
- FlatNode nn = fn.getPrev( i );
- VarSrcTokTable incoming = variableResults.get( nn );
- curr.merge( incoming );
- }
-
- if( !seseStack.empty() ) {
- variable_nodeActions( fn, curr, seseStack.peek() );
- }
-
- // if a new result, schedule forward nodes for analysis
- if( !curr.equals( prev ) ) {
- variableResults.put( fn, curr );
-
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- flatNodesToVisit.add( nn );
- }
- }
- }
- }
-
- private void variable_nodeActions( FlatNode fn,
- VarSrcTokTable vstTable,
- FlatSESEEnterNode currentSESE ) {
- switch( fn.kind() ) {
-
- case FKind.FlatSESEEnterNode: {
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- assert fsen.equals( currentSESE );
-
- vstTable.age( currentSESE );
- vstTable.assertConsistency();
- } break;
-
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- FlatSESEEnterNode fsen = fsexn.getFlatEnter();
- assert currentSESE.getChildren().contains( fsen );
-
- // remap all of this child's children tokens to be
- // from this child as the child exits
- vstTable.remapChildTokens( fsen );
-
- // liveness virtual reads are things that might be
- // written by an SESE and should be added to the in-set
- // anything virtually read by this SESE should be pruned
- // of parent or sibling sources
- Set<TempDescriptor> liveVars = livenessRootView.get( fn );
- Set<TempDescriptor> fsenVirtReads = vstTable.calcVirtReadsAndPruneParentAndSiblingTokens( fsen, liveVars );
- Set<TempDescriptor> fsenVirtReadsOld = livenessVirtualReads.get( fn );
- if( fsenVirtReadsOld != null ) {
- fsenVirtReads.addAll( fsenVirtReadsOld );
- }
- livenessVirtualReads.put( fn, fsenVirtReads );
-
-
- // then all child out-set tokens are guaranteed
- // to be filled in, so clobber those entries with
- // the latest, clean sources
- Iterator<TempDescriptor> outVarItr = fsen.getOutVarSet().iterator();
- while( outVarItr.hasNext() ) {
- TempDescriptor outVar = outVarItr.next();
- HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
- ts.add( outVar );
- VariableSourceToken vst =
- new VariableSourceToken( ts,
- fsen,
- new Integer( 0 ),
- outVar
- );
- vstTable.remove( outVar );
- vstTable.add( vst );
- }
- vstTable.assertConsistency();
-
- } break;
-
- case FKind.FlatOpNode: {
- FlatOpNode fon = (FlatOpNode) fn;
-
- if( fon.getOp().getOp() == Operation.ASSIGN ) {
- TempDescriptor lhs = fon.getDest();
- TempDescriptor rhs = fon.getLeft();
-
- vstTable.remove( lhs );
-
- Set<VariableSourceToken> forAddition = new HashSet<VariableSourceToken>();
-
- Iterator<VariableSourceToken> itr = vstTable.get( rhs ).iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
-
- HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
- ts.add( lhs );
-
- if( currentSESE.getChildren().contains( vst.getSESE() ) ) {
- // if the source comes from a child, copy it over
- forAddition.add( new VariableSourceToken( ts,
- vst.getSESE(),
- vst.getAge(),
- vst.getAddrVar()
- )
- );
- } else {
- // otherwise, stamp it as us as the source
- forAddition.add( new VariableSourceToken( ts,
- currentSESE,
- new Integer( 0 ),
- lhs
- )
- );
- }
- }
-
- vstTable.addAll( forAddition );
-
- // only break if this is an ASSIGN op node,
- // otherwise fall through to default case
- vstTable.assertConsistency();
- break;
- }
- }
-
- // note that FlatOpNode's that aren't ASSIGN
- // fall through to this default case
- default: {
- TempDescriptor [] writeTemps = fn.writesTemps();
- if( writeTemps.length > 0 ) {
-
-
- // for now, when writeTemps > 1, make sure
- // its a call node, programmer enforce only
- // doing stuff like calling a print routine
- //assert writeTemps.length == 1;
- if( writeTemps.length > 1 ) {
- assert fn.kind() == FKind.FlatCall ||
- fn.kind() == FKind.FlatMethod;
- break;
- }
-
- vstTable.remove( writeTemps[0] );
-
- HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
- ts.add( writeTemps[0] );
-
- vstTable.add( new VariableSourceToken( ts,
- currentSESE,
- new Integer( 0 ),
- writeTemps[0]
- )
- );
- }
-
- vstTable.assertConsistency();
- } break;
-
- } // end switch
- }
-
-
- private void pruneVariableResultsWithLiveness( FlatMethod fm ) {
-
- // start from flat method top, visit every node in
- // method exactly once
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
-
- Set<FlatNode> visited = new HashSet<FlatNode>();
-
- while( !flatNodesToVisit.isEmpty() ) {
- Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
- FlatNode fn = fnItr.next();
-
- flatNodesToVisit.remove( fn );
- visited.add( fn );
-
- Set<TempDescriptor> rootLiveSet = livenessRootView.get( fn );
- VarSrcTokTable vstTable = variableResults.get( fn );
-
- vstTable.pruneByLiveness( rootLiveSet );
-
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
-
- if( !visited.contains( nn ) ) {
- flatNodesToVisit.add( nn );
- }
- }
- }
- }
-
-
- private void notAvailableForward( FlatMethod fm ) {
-
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
-
- while( !flatNodesToVisit.isEmpty() ) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove( fn );
-
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
- assert seseStack != null;
-
- Set<TempDescriptor> prev = notAvailableResults.get( fn );
-
- Set<TempDescriptor> curr = new HashSet<TempDescriptor>();
- for( int i = 0; i < fn.numPrev(); i++ ) {
- FlatNode nn = fn.getPrev( i );
- Set<TempDescriptor> notAvailIn = notAvailableResults.get( nn );
- if( notAvailIn != null ) {
- curr.addAll( notAvailIn );
- }
- }
-
- if( !seseStack.empty() ) {
- notAvailable_nodeActions( fn, curr, seseStack.peek() );
- }
-
- // if a new result, schedule forward nodes for analysis
- if( !curr.equals( prev ) ) {
- notAvailableResults.put( fn, curr );
-
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- flatNodesToVisit.add( nn );
- }
- }
- }
- }
-
- private void notAvailable_nodeActions( FlatNode fn,
- Set<TempDescriptor> notAvailSet,
- FlatSESEEnterNode currentSESE ) {
-
- // any temps that are removed from the not available set
- // at this node should be marked in this node's code plan
- // as temps to be grabbed at runtime!
-
- switch( fn.kind() ) {
-
- case FKind.FlatSESEEnterNode: {
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- assert fsen.equals( currentSESE );
-
- // keep a copy of what's not available into the SESE
- // and restore it at the matching exit node
- Set<TempDescriptor> notAvailCopy = new HashSet<TempDescriptor>();
- Iterator<TempDescriptor> tdItr = notAvailSet.iterator();
- while( tdItr.hasNext() ) {
- notAvailCopy.add( tdItr.next() );
- }
- notAvailableIntoSESE.put( fsen, notAvailCopy );
-
- notAvailSet.clear();
- } break;
-
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- FlatSESEEnterNode fsen = fsexn.getFlatEnter();
- assert currentSESE.getChildren().contains( fsen );
-
- notAvailSet.addAll( fsen.getOutVarSet() );
-
- Set<TempDescriptor> notAvailIn = notAvailableIntoSESE.get( fsen );
- assert notAvailIn != null;
- notAvailSet.addAll( notAvailIn );
-
- } break;
-
- case FKind.FlatMethod: {
- notAvailSet.clear();
- }
-
- case FKind.FlatOpNode: {
- FlatOpNode fon = (FlatOpNode) fn;
-
- if( fon.getOp().getOp() == Operation.ASSIGN ) {
- TempDescriptor lhs = fon.getDest();
- TempDescriptor rhs = fon.getLeft();
-
- // copy makes lhs same availability as rhs
- if( notAvailSet.contains( rhs ) ) {
- notAvailSet.add( lhs );
- } else {
- notAvailSet.remove( lhs );
- }
-
- // only break if this is an ASSIGN op node,
- // otherwise fall through to default case
- break;
- }
- }
-
- // note that FlatOpNode's that aren't ASSIGN
- // fall through to this default case
- default: {
- TempDescriptor [] writeTemps = fn.writesTemps();
- for( int i = 0; i < writeTemps.length; i++ ) {
- TempDescriptor wTemp = writeTemps[i];
- notAvailSet.remove( wTemp );
- }
- TempDescriptor [] readTemps = fn.readsTemps();
- for( int i = 0; i < readTemps.length; i++ ) {
- TempDescriptor rTemp = readTemps[i];
- notAvailSet.remove( rTemp );
-
- // if this variable has exactly one source, potentially
- // get other things from this source as well
- VarSrcTokTable vstTable = variableResults.get( fn );
-
- VSTWrapper vstIfStatic = new VSTWrapper();
- Integer srcType =
- vstTable.getRefVarSrcType( rTemp,
- currentSESE,
- vstIfStatic
- );
-
- if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
-
- VariableSourceToken vst = vstIfStatic.vst;
-
- Iterator<VariableSourceToken> availItr = vstTable.get( vst.getSESE(),
- vst.getAge()
- ).iterator();
-
- // look through things that are also available from same source
- while( availItr.hasNext() ) {
- VariableSourceToken vstAlsoAvail = availItr.next();
-
- Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
- while( refVarItr.hasNext() ) {
- TempDescriptor refVarAlso = refVarItr.next();
-
- // if a variable is available from the same source, AND it ALSO
- // only comes from one statically known source, mark it available
- VSTWrapper vstIfStaticNotUsed = new VSTWrapper();
- Integer srcTypeAlso =
- vstTable.getRefVarSrcType( refVarAlso,
- currentSESE,
- vstIfStaticNotUsed
- );
- if( srcTypeAlso.equals( VarSrcTokTable.SrcType_STATIC ) ) {
- notAvailSet.remove( refVarAlso );
- }
- }
- }
- }
- }
- } break;
-
- } // end switch
- }
-
- private void debugFunction(OwnershipAnalysis oa2, FlatMethod fm) {
-
- String methodName="SomeWork";
-
- MethodDescriptor md=fm.getMethod();
- HashSet<MethodContext> mcSet=oa2.getAllMethodContextSetByDescriptor(md);
- Iterator<MethodContext> mcIter=mcSet.iterator();
-
- while(mcIter.hasNext()){
- MethodContext mc=mcIter.next();
-
- OwnershipGraph og=oa2.getOwnvershipGraphByMethodContext(mc);
-
- if(fm.toString().indexOf(methodName)>0){
- try {
- og.writeGraph("SECONDGRAPH"+fm.toString(),
- true, // write labels (variables)
- true, // selectively hide intermediate temp vars
- true, // prune unreachable heap regions
- false, // show back edges to confirm graph validity
- false, // show parameter indices (unmaintained!)
- true, // hide subset reachability states
- false);// hide edge taints
- } catch (IOException e) {
- System.out.println("Error writing debug capture.");
- System.exit(0);
- }
- }
- }
-
- }
-
- private void methodEffects(FlatMethod fm, CallGraph callGraph) {
-
- MethodDescriptor md=fm.getMethod();
- HashSet<MethodContext> mcSet=ownAnalysis.getAllMethodContextSetByDescriptor(md);
- Iterator<MethodContext> mcIter=mcSet.iterator();
-
- while(mcIter.hasNext()){
- MethodContext mc=mcIter.next();
-
- Set<FlatNode> visited = new HashSet<FlatNode>();
-
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add(fm);
-
- Hashtable<TempDescriptor, TempDescriptor> invarMap=new Hashtable<TempDescriptor,TempDescriptor>();
-
- while (!flatNodesToVisit.isEmpty()) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove(fn);
-
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get(fn);
- assert seseStack != null;
-
- if (!seseStack.empty()) {
- effects_nodeActions(mc, fn, seseStack.peek(), callGraph,invarMap);
- }
-
- flatNodesToVisit.remove(fn);
- visited.add(fn);
-
- for (int i = 0; i < fn.numNext(); i++) {
- FlatNode nn = fn.getNext(i);
- if (!visited.contains(nn)) {
- flatNodesToVisit.add(nn);
- }
- }
-
- }
-
-
- }
-
- }
-
- private void analyzeRelatedAllocationSite(MethodDescriptor callerMD,
- MethodContext calleeMC, HashSet<Integer> paramIndexSet,
- HashSet<HeapRegionNode> visitedHRN) {
-
- HashSet<MethodContext> mcSet = ownAnalysis
- .getAllMethodContextSetByDescriptor(callerMD);
-
- if (mcSet != null) {
-
- Iterator<MethodContext> mcIter = mcSet.iterator();
-
- FlatMethod callerFM = state.getMethodFlat(callerMD);
-
- while (mcIter.hasNext()) {
- MethodContext mc = mcIter.next();
-
- Set<FlatNode> visited = new HashSet<FlatNode>();
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add(callerFM);
-
- while (!flatNodesToVisit.isEmpty()) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove(fn);
-
- analyzeRelatedAllocationSite_NodeAction(fn, mc, calleeMC,
- paramIndexSet,visitedHRN);
-
- flatNodesToVisit.remove(fn);
- visited.add(fn);
-
- for (int i = 0; i < fn.numNext(); i++) {
- FlatNode nn = fn.getNext(i);
- if (!visited.contains(nn)) {
- flatNodesToVisit.add(nn);
- }
- }
- }
- }
- }
-
- }
-
- private void analyzeRelatedAllocationSite_NodeAction(FlatNode fn, MethodContext callerMC,
- MethodContext calleeMC,
- HashSet<Integer> paramIndexSet, HashSet<HeapRegionNode> visitedHRN) {
-
- OwnershipGraph og = ownAnalysis
- .getOwnvershipGraphByMethodContext(callerMC);
-
- switch (fn.kind()) {
-
- case FKind.FlatCall: {
-
- FlatCall fc = (FlatCall) fn;
-
-
- if(fc.numArgs()>0 && fc.getMethod().equals(calleeMC.getDescriptor())){
- MethodContext calleeMCfromOG = ownAnalysis.getCalleeMethodContext(
- callerMC, fc);
-
- // disable below condition. currently collect all possible
- // allocation sites without regarding method context
-
- // if (calleeMC.equals(calleeMCfromOG)) { // in this case, this
- // method context calls corresponding callee.
-
- int base;
- if (((MethodDescriptor) calleeMC.getDescriptor()).isStatic()) {
- base = 0;
- } else {
- base = 1;
- }
-
- for (Iterator iterator = paramIndexSet.iterator(); iterator
- .hasNext();) {
- Integer integer = (Integer) iterator.next();
-
- int paramIdx = integer - base;
- if (paramIdx >= 0) {
- // if paramIdx is less than 0, assumes that it is
- // related with wrong method contexts.
- TempDescriptor arg = fc.getArg(paramIdx);
- LabelNode argLN = og.td2ln.get(arg);
- if (argLN != null) {
- Iterator<ReferenceEdge> iterEdge = argLN
- .iteratorToReferencees();
- while (iterEdge.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) iterEdge
- .next();
-
- HeapRegionNode dstHRN = referenceEdge.getDst();
- if (dstHRN.isParameter()) {
- if (!visitedHRN.contains(dstHRN)) {
- setupRelatedAllocSiteAnalysis(og, callerMC,
- dstHRN, visitedHRN);
- }
- } else {
-// System.out.println("FLAGGED "+callerMC+":fc="+fc+":arg="+arg+" , paramIdx="+paramIdx);
- flagAllocationSite(callerMC, dstHRN
- .getAllocationSite());
- }
- }
- }
- }
- }
- }
-
-
- // }
-
- }
- break;
-
- }
- }
-
- private void setupRelatedAllocSiteAnalysis(OwnershipGraph og,
- MethodContext mc, HeapRegionNode dstHRN,
- HashSet<HeapRegionNode> visitedHRN) {
-
- HashSet<Integer> paramIndexSet = new HashSet<Integer>();
-
- // collect corresponding param index
- Set<Integer> pIndexSet = og.idPrimary2paramIndexSet.get(dstHRN.getID());
- if (pIndexSet != null) {
- for (Iterator iterator = pIndexSet.iterator(); iterator.hasNext();) {
- Integer integer = (Integer) iterator.next();
- paramIndexSet.add(integer);
- }
- }
-
- Set<Integer> sIndexSet = og.idSecondary2paramIndexSet.get(dstHRN
- .getID());
- if (sIndexSet != null) {
- for (Iterator iterator = sIndexSet.iterator(); iterator.hasNext();) {
- Integer integer = (Integer) iterator.next();
- paramIndexSet.add(integer);
- }
- }
-
- if (mc.getDescriptor() instanceof MethodDescriptor) {
- Set callerSet = callGraph.getCallerSet((MethodDescriptor) mc
- .getDescriptor());
- for (Iterator iterator = callerSet.iterator(); iterator.hasNext();) {
- Object obj = (Object) iterator.next();
- if (obj instanceof MethodDescriptor) {
- MethodDescriptor callerMD = (MethodDescriptor) obj;
-
- if(callerMD.equals(mc.getDescriptor())){
- continue;
- }
- analyzeRelatedAllocationSite(callerMD, mc, paramIndexSet,visitedHRN);
-
- }
- }
- }
- }
-
- private void effects_nodeActions(MethodContext mc, FlatNode fn,
- FlatSESEEnterNode currentSESE, CallGraph callGraph,Hashtable<TempDescriptor, TempDescriptor> invarMap) {
-
- OwnershipGraph og = ownAnalysis.getOwnvershipGraphByMethodContext(mc);
-
- switch (fn.kind()) {
-
- case FKind.FlatSESEEnterNode: {
-
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- assert fsen.equals(currentSESE);
-
- if (!fsen.getIsCallerSESEplaceholder()) {
- // uniquely taint each live-in variable
- Collection<TempDescriptor> set = fsen.getInVarSet();
- Iterator<TempDescriptor> iter = set.iterator();
- int idx = 0;
- while (iter.hasNext()) {
- TempDescriptor td = iter.next();
- LabelNode ln = og.td2ln.get(td);
-
- if(currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx().containsKey(td)){
- idx=currentSESE.getSeseEffectsSet().getInVarIdx(td);
- }
-
- if (ln != null) {
- int taint = (int) Math.pow(2, idx);
- taintLabelNode(ln, taint,currentSESE.getSeseEffectsSet());
- currentSESE.getSeseEffectsSet().setInVarIdx(idx, td);
-
- // collects related allocation sites
- Iterator<ReferenceEdge> referenceeIter = ln
- .iteratorToReferencees();
- while (referenceeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) referenceeIter
- .next();
- HeapRegionNode dstHRN = referenceEdge.getDst();
- if (dstHRN.isParameter()) {
-
- HashSet<HeapRegionNode> visitedHRN = new HashSet<HeapRegionNode>();
- visitedHRN.add(dstHRN);
- setupRelatedAllocSiteAnalysis(og, mc, dstHRN,
- visitedHRN);
-
- } else {
-// System.out.println("FLAGGED "+fsen+":"+td);
- flagAllocationSite(mc, dstHRN
- .getAllocationSite());
- }
- }
-
- }
-
- idx++;
- }
- }
-
- }
- break;
-
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode fsexit = (FlatSESEExitNode) fn;
-
- if (!fsexit.getFlatEnter().getIsCallerSESEplaceholder()) {
-
- // clear taint information of live-in variables
- Set<Integer> keySet=og.id2hrn.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- Integer hrnID = (Integer) iterator.next();
- HeapRegionNode hrn=og.id2hrn.get(hrnID);
- Iterator<ReferenceEdge> edgeIter=hrn.iteratorToReferencers();
- while (edgeIter.hasNext()) {
- ReferenceEdge refEdge = (ReferenceEdge) edgeIter
- .next();
- refEdge.setSESETaintIdentifier(0);
- }
- }
-
- FlatSESEEnterNode enterNode = fsexit.getFlatEnter();
- FlatSESEEnterNode parent = enterNode.getParent();
- if (parent != null) {
-
- SESEEffectsSet set = enterNode.getSeseEffectsSet();
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> readTable = set
- .getReadTable();
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> parentReadTable = parent
- .getSeseEffectsSet().getReadTable();
- Set<TempDescriptor> keys = readTable.keySet();
- Iterator<TempDescriptor> keyIter = keys.iterator();
- while (keyIter.hasNext()) {
- TempDescriptor td = (TempDescriptor) keyIter.next();
- HashSet<SESEEffectsKey> effectsSet = readTable.get(td);
- HashSet<SESEEffectsKey> parentEffectsSet = parentReadTable
- .get(td);
- if (parentEffectsSet == null) {
- parentEffectsSet = new HashSet<SESEEffectsKey>();
- }
-
- for (Iterator iterator = effectsSet.iterator(); iterator
- .hasNext();) {
- SESEEffectsKey seseKey = (SESEEffectsKey) iterator
- .next();
- parentEffectsSet.add(new SESEEffectsKey(seseKey
- .getFieldDescriptor(), seseKey
- .getTypeDescriptor(), seseKey.getHRNId(),
- seseKey.getHRNUniqueId()));
- }
-
- parentReadTable.put(td, parentEffectsSet);
- }
-
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> writeTable = set
- .getWriteTable();
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> parentWriteTable = parent
- .getSeseEffectsSet().getWriteTable();
- keys = writeTable.keySet();
- keyIter = keys.iterator();
- while (keyIter.hasNext()) {
- TempDescriptor td = (TempDescriptor) keyIter.next();
- HashSet<SESEEffectsKey> effectsSet = writeTable.get(td);
- HashSet<SESEEffectsKey> parentEffectsSet = parentWriteTable
- .get(td);
- if (parentEffectsSet == null) {
- parentEffectsSet = new HashSet<SESEEffectsKey>();
- }
-
- for (Iterator iterator = effectsSet.iterator(); iterator
- .hasNext();) {
- SESEEffectsKey seseKey = (SESEEffectsKey) iterator
- .next();
- parentEffectsSet.add(new SESEEffectsKey(seseKey
- .getFieldDescriptor(), seseKey
- .getTypeDescriptor(), seseKey.getHRNId(),
- seseKey.getHRNUniqueId()));
- }
-
- parentWriteTable.put(td, parentEffectsSet);
- }
-
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> strongUpdateTable = set
- .getStrongUpdateTable();
- Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> parentstrongUpdateTable = parent
- .getSeseEffectsSet().getStrongUpdateTable();
- keys = strongUpdateTable.keySet();
- keyIter = keys.iterator();
- while (keyIter.hasNext()) {
- TempDescriptor td = (TempDescriptor) keyIter.next();
- HashSet<SESEEffectsKey> effectsSet = strongUpdateTable
- .get(td);
- HashSet<SESEEffectsKey> parentEffectsSet = parentstrongUpdateTable
- .get(td);
- if (parentEffectsSet == null) {
- parentEffectsSet = new HashSet<SESEEffectsKey>();
- }
-
- for (Iterator iterator = effectsSet.iterator(); iterator
- .hasNext();) {
- SESEEffectsKey seseKey = (SESEEffectsKey) iterator
- .next();
- parentEffectsSet.add(new SESEEffectsKey(seseKey
- .getFieldDescriptor(), seseKey
- .getTypeDescriptor(), seseKey.getHRNId(),
- seseKey.getHRNUniqueId()));
- }
-
- parentstrongUpdateTable.put(td, parentEffectsSet);
- }
-
- }
-
- }
-
- }
- break;
-
- case FKind.FlatFieldNode: {
-
- FlatFieldNode ffn = (FlatFieldNode) fn;
- TempDescriptor dst = ffn.getDst();
- TempDescriptor src = ffn.getSrc();
- FieldDescriptor field = ffn.getField();
-
- LabelNode srcLN = og.td2ln.get(src);
- if(srcLN!=null){
- Iterator<ReferenceEdge> edgeIter=srcLN.iteratorToReferencees();
- int taintIdentifier=0;
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- HeapRegionNode refHRN=referenceEdge.getDst();
- taintIdentifier=currentSESE.getSeseEffectsSet().getTaint(referenceEdge);
-// taintIdentifier=referenceEdge.getSESETaintIdentifier();
-
- // figure out which invar has related effects
- Hashtable<TempDescriptor, Integer> map=currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx();
- Set<TempDescriptor> keySet=map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor inVarTD = (TempDescriptor) iterator
- .next();
- int inVarMask=(int) Math.pow(2, map.get(inVarTD).intValue());
- if((inVarMask&taintIdentifier)>0){
- // found related invar, contribute effects
- currentSESE.readEffects(inVarTD, field.getSymbol(),src.getType(), refHRN);
- }
- }
- }
-
- // taint
- if(!field.getType().isImmutable()){
- LabelNode dstLN = og.td2ln.get(dst);
- edgeIter=dstLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- currentSESE.getSeseEffectsSet().mapEdgeToTaint(referenceEdge, taintIdentifier);
-// referenceEdge.unionSESETaintIdentifier(taintIdentifier);
- }
- }
- }
-
-
- }
- break;
-
- case FKind.FlatOpNode:{
-
- FlatOpNode fon=(FlatOpNode)fn;
- TempDescriptor dest=fon.getDest();
- TempDescriptor src=fon.getLeft();
-
- if(currentSESE.getInVarSet().contains(src)){
- int idx=currentSESE.getSeseEffectsSet().getInVarIdx(src);
- if(idx==-1){
- break;
- }
-
- //mark dest's edges for corresponding sese live in-var.
- LabelNode srcLN = og.td2ln.get(dest);
- if (srcLN != null) {
- Iterator<ReferenceEdge> refEdgeIter=srcLN.iteratorToReferencees();
- while (refEdgeIter.hasNext()) {
- ReferenceEdge edge = refEdgeIter.next();
- int newTaint = (int) Math.pow(2, idx);
-// System.out.println("fon="+fon);
-// System.out.println(currentSESE+" src:"+src+"->"+"dest:"+dest+" with taint="+newTaint);
-// System.out.println("referenceEdge="+edge);
- currentSESE.getSeseEffectsSet().mapEdgeToTaint(edge, newTaint);
-// System.out.println("after tainting="+edge.getSESETaintIdentifier());
- }
- }
- }
- }break;
-
- case FKind.FlatElementNode:{
-
- FlatElementNode fsen=(FlatElementNode)fn;
- TempDescriptor src = fsen.getSrc();
- TempDescriptor dst = fsen.getDst();
- String field="___element_";
-
- LabelNode srcLN = og.td2ln.get(src);
- int taintIdentifier=0;
- if(srcLN!=null){
- Iterator<ReferenceEdge> edgeIter=srcLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- HeapRegionNode dstHRN=referenceEdge.getDst();
- taintIdentifier=currentSESE.getSeseEffectsSet().getTaint(referenceEdge);
-// taintIdentifier=referenceEdge.getSESETaintIdentifier();
-
- // figure out which invar has related effects
- Hashtable<TempDescriptor, Integer> map=currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx();
- Set<TempDescriptor> keySet=map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor inVarTD = (TempDescriptor) iterator
- .next();
- int inVarMask=(int) Math.pow(2, map.get(inVarTD).intValue());
- if((inVarMask&taintIdentifier)>0){
- // found related invar, contribute effects
- currentSESE.readEffects(inVarTD, field,src.getType(), dstHRN);
- }
- }
-
- }
- }
-
- // taint
- LabelNode dstLN = og.td2ln.get(dst);
- if(dstLN!=null){
- Iterator<ReferenceEdge> edgeIter=dstLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- currentSESE.getSeseEffectsSet().mapEdgeToTaint(referenceEdge, taintIdentifier);
-// referenceEdge.unionSESETaintIdentifier(taintIdentifier);
- }
- }
-
- }break;
-
- case FKind.FlatSetElementNode: {
-
- FlatSetElementNode fsen = (FlatSetElementNode) fn;
- TempDescriptor dst = fsen.getDst();
- TypeDescriptor tdElement = dst.getType().dereference();
-
- String field = "___element_";
-
- LabelNode dstLN=og.td2ln.get(dst);
- if(dst!=null){
-
- Iterator<ReferenceEdge> edgeIter=dstLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- HeapRegionNode dstHRN=referenceEdge.getDst();
- int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge);
-// int edgeTaint=referenceEdge.getSESETaintIdentifier();
-
- // we can do a strong update here if one of two cases
- // holds
- boolean strongUpdate=false;
- if (field != null && !dst.getType().isImmutable()
- && ((dstHRN.getNumReferencers() == 1) || // case 1
- (dstHRN.isSingleObject() && dstLN
- .getNumReferencees() == 1) // case 2
- )) {
- strongUpdate = true;
- }
-
-
- // figure out which invar has related effects
- Hashtable<TempDescriptor, Integer> map=currentSESE.getSeseEffectsSet().getMapTempDescToInVarIdx();
- Set<TempDescriptor> keySet=map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor inVarTD = (TempDescriptor) iterator
- .next();
- int inVarMask=(int) Math.pow(2, map.get(inVarTD).intValue());
- if((inVarMask&edgeTaint)>0){
- // found related invar, contribute effects
- currentSESE.writeEffects(inVarTD, field, dst.getType(),dstHRN, strongUpdate);
- }
- }
-
-
- }
-
- }
-
- }break;
-
- case FKind.FlatSetFieldNode: {
-
- FlatSetFieldNode fsen = (FlatSetFieldNode) fn;
- TempDescriptor dst = fsen.getDst();
- FieldDescriptor field = fsen.getField();
-
- LabelNode dstLN = og.td2ln.get(dst);
- if(dstLN!=null){
-
- Iterator<ReferenceEdge> edgeIter=dstLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- HeapRegionNode dstHRN=referenceEdge.getDst();
- int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge);
-// int edgeTaint=referenceEdge.getSESETaintIdentifier();
-
- // we can do a strong update here if one of two cases
- // holds
- boolean strongUpdate=false;
- if (field != null && !field.getType().isImmutable()
- && field != OwnershipAnalysis
- .getArrayField(field.getType())
- && ((dstHRN.getNumReferencers() == 1) || // case 1
- (dstHRN.isSingleObject() && dstLN
- .getNumReferencees() == 1) // case 2
- )) {
- strongUpdate = true;
- }
-
-
- // figure out which invar has related effects
- Hashtable<TempDescriptor, Integer> map = currentSESE
- .getSeseEffectsSet().getMapTempDescToInVarIdx();
- Set<TempDescriptor> keySet = map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor inVarTD = (TempDescriptor) iterator
- .next();
- int inVarMask = (int) Math.pow(2, map.get(inVarTD)
- .intValue());
- if ((inVarMask & edgeTaint) > 0) {
- // found related invar, contribute effects
- currentSESE.writeEffects(inVarTD,
- field.getSymbol(), dst.getType(), dstHRN,
- strongUpdate);
- }
- }
-
-
- }
- }
- }
- break;
-
- case FKind.FlatCall: {
- FlatCall fc = (FlatCall) fn;
-
- MethodContext calleeMC = ownAnalysis.getCalleeMethodContext(mc, fc);
-
- MethodEffects me = ownAnalysis.getMethodEffectsAnalysis()
- .getMethodEffectsByMethodContext(calleeMC);
-
- OwnershipGraph calleeOG = ownAnalysis
- .getOwnvershipGraphByMethodContext(calleeMC);
-
-
- FlatMethod fm = state.getMethodFlat(fc.getMethod());
- ParameterDecomposition decomp = new ParameterDecomposition(
- ownAnalysis, fc, fm, calleeMC, calleeOG, og);
-
- int base=0;
- if (((MethodDescriptor) calleeMC.getDescriptor()).isStatic()) {
- base = 0;
- } else {
- base = 1;
- }
-
- for (int i = 0; i < fc.numArgs()+base; i++) {
-
- TempDescriptor arg ;
- Set<EffectsKey> readSet;
- Set<EffectsKey> writeSet;
- Set<EffectsKey> strongUpdateSet;
-
- int paramIdx=0;
-
- boolean isThis=false;
- if(i==fc.numArgs()){
- paramIdx=0;
- arg = fc.getThis();
- Integer hrnPrimaryID = calleeOG.paramIndex2idPrimary.get(paramIdx);
- Integer hrnSecondaryID = calleeOG.paramIndex2idSecondary.get(paramIdx);
- readSet = me.getEffects().getReadingSet(
- 0);
- writeSet = me.getEffects().getWritingSet(
- 0);
- strongUpdateSet = me.getEffects()
- .getStrongUpdateSet(0);
- isThis=true;
- }else{
- paramIdx=i + base;
- arg = fc.getArg(i);
- readSet = me.getEffects().getReadingSet(
- i + base);
- writeSet = me.getEffects().getWritingSet(
- i + base);
- strongUpdateSet = me.getEffects()
- .getStrongUpdateSet(i + base);
- }
-
- LabelNode argLN = og.td2ln.get(arg);
- if( argLN!=null){
- Iterator<ReferenceEdge> edgeIter=argLN.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) edgeIter
- .next();
- HeapRegionNode dstHRN=referenceEdge.getDst();
- int edgeTaint=currentSESE.getSeseEffectsSet().getTaint(referenceEdge);
-// int edgeTaint=referenceEdge.getSESETaintIdentifier();
-
- // figure out which invar has related effects
- Hashtable<TempDescriptor, Integer> map = currentSESE
- .getSeseEffectsSet().getMapTempDescToInVarIdx();
- Set<TempDescriptor> keySet = map.keySet();
- for (Iterator iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor inVarTD = (TempDescriptor) iterator
- .next();
- int inVarMask = (int) Math.pow(2, map.get(inVarTD)
- .intValue());
-
- if ((inVarMask & edgeTaint) > 0) {
- // found related invar, contribute effects
-
- if (readSet != null) {
- Iterator<EffectsKey> readIter = readSet
- .iterator();
- while (readIter.hasNext()) {
- EffectsKey key = readIter.next();
- Set<Integer> hrnSet = getCallerHRNId(
- new Integer(paramIdx), calleeOG,
- key.getHRNId(), decomp);
- Iterator<Integer> hrnIter = hrnSet
- .iterator();
- while (hrnIter.hasNext()) {
- Integer hrnID = (Integer) hrnIter
- .next();
-
- HeapRegionNode refHRN = og.id2hrn
- .get(hrnID);
-
- currentSESE.readEffects(inVarTD, key
- .getFieldDescriptor(), key
- .getTypeDescriptor(), refHRN);
-
- }
- }
- }
-
- if (writeSet != null) {
- Iterator<EffectsKey> writeIter = writeSet
- .iterator();
- while (writeIter.hasNext()) {
- EffectsKey key = writeIter.next();
-
- Set<Integer> hrnSet = getCallerHRNId(
- new Integer(paramIdx), calleeOG,
- key.getHRNId(), decomp);
- Iterator<Integer> hrnIter = hrnSet
- .iterator();
- while (hrnIter.hasNext()) {
- Integer hrnID = (Integer) hrnIter
- .next();
-
- HeapRegionNode refHRN = og.id2hrn
- .get(hrnID);
-
- currentSESE.writeEffects(inVarTD,
- key.getFieldDescriptor(), key
- .getTypeDescriptor(),
- refHRN, false);
- }
-
- }
- }
-
- if (strongUpdateSet != null) {
- Iterator<EffectsKey> strongUpdateIter = strongUpdateSet
- .iterator();
- while (strongUpdateIter.hasNext()) {
- EffectsKey key = strongUpdateIter
- .next();
-
- Set<Integer> hrnSet = getCallerHRNId(
- new Integer(paramIdx),
- calleeOG, key.getHRNId(),
- decomp);
- Iterator<Integer> hrnIter = hrnSet
- .iterator();
- while (hrnIter.hasNext()) {
- Integer hrnID = (Integer) hrnIter
- .next();
-
- HeapRegionNode refHRN = og.id2hrn
- .get(hrnID);
-
- currentSESE.writeEffects(inVarTD,
- key.getFieldDescriptor(),
- key.getTypeDescriptor(),
- refHRN, true);
- }
- }
- } // end of if (strongUpdateSet != null)
-
- } // end of if ((inVarMask & edgeTaint) > 0)
- }
-
- }
- }
-
- }
-
- }
- break;
-
- }
- }
-
- private void flagAllocationSite(MethodContext mc, AllocationSite ac){
- HashSet<AllocationSite> set=mapMethodContextToLiveInAllocationSiteSet.get(mc);
- if(set==null){
- set=new HashSet<AllocationSite>();
- }
- set.add(ac);
- mapMethodContextToLiveInAllocationSiteSet.put(mc, set);
- }
-
- private void followReference(HeapRegionNode hrn,HashSet<TempDescriptor> tdSet, HashSet<HeapRegionNode> visited, FlatSESEEnterNode currentSESE){
-
- Iterator<ReferenceEdge> referIter=hrn.iteratorToReferencers();
- // check whether hrn is referenced by TD
- while (referIter.hasNext()) {
- ReferenceEdge referEdge = (ReferenceEdge) referIter.next();
- if(referEdge.getSrc() instanceof LabelNode){
- LabelNode ln=(LabelNode)referEdge.getSrc();
- if(currentSESE.getInVarSet().contains(ln.getTempDescriptor())){
- tdSet.add(ln.getTempDescriptor());
- }
- }else if(referEdge.getSrc() instanceof HeapRegionNode){
- HeapRegionNode nextHRN=(HeapRegionNode)referEdge.getSrc();
- if(!visited.contains(nextHRN)){
- visited.add(nextHRN);
- followReference(nextHRN,tdSet,visited,currentSESE);
- }
-
- }
- }
-
- }
-
- private Set<Integer> getCallerHRNId(Integer paramIdx,
- OwnershipGraph calleeOG, Integer calleeHRNId,
- ParameterDecomposition paramDecom) {
-
- Integer hrnPrimaryID = calleeOG.paramIndex2idPrimary.get(paramIdx);
- Integer hrnSecondaryID = calleeOG.paramIndex2idSecondary.get(paramIdx);
-
- if (calleeHRNId.equals(hrnPrimaryID)) {
- // it references to primary param heap region
- return paramDecom.getParamObject_hrnIDs(paramIdx);
- } else if (calleeHRNId.equals(hrnSecondaryID)) {
- // it references to secondary param heap region
- return paramDecom.getParamReachable_hrnIDs(paramIdx);
- }
-
- return new HashSet<Integer>();
- }
-
- private void taintLabelNode(LabelNode ln, int identifier, SESEEffectsSet effectSet) {
-
- Iterator<ReferenceEdge> edgeIter = ln.iteratorToReferencees();
- while (edgeIter.hasNext()) {
- ReferenceEdge edge = edgeIter.next();
- effectSet.mapEdgeToTaint(edge, identifier);
- }
-
- }
-
- private HashSet<HeapRegionNode> getReferenceHeapIDSet(OwnershipGraph og, TempDescriptor td){
-
- HashSet<HeapRegionNode> returnSet=new HashSet<HeapRegionNode>();
-
- LabelNode ln=og.td2ln.get(td);
- if(ln!=null){
- Iterator<ReferenceEdge> edgeIter=ln.iteratorToReferencees();
- while(edgeIter.hasNext()){
- ReferenceEdge edge=edgeIter.next();
- HeapRegionNode hrn=edge.getDst();
- returnSet.add(hrn);
- }
- }
- return returnSet;
- }
-
-
- private HashSet<ReferenceEdge> getRefEdgeSetReferenceToSameHRN(
- OwnershipGraph og, TempDescriptor td) {
-
- HashSet<ReferenceEdge> returnSet = new HashSet<ReferenceEdge>();
-
- HashSet<HeapRegionNode> heapIDs = getReferenceHeapIDSet(og, td);
- for (Iterator<HeapRegionNode> iterator = heapIDs.iterator(); iterator
- .hasNext();) {
- HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
- Iterator<ReferenceEdge> referenceeIter = heapRegionNode
- .iteratorToReferencees();
- while (referenceeIter.hasNext()) {
- ReferenceEdge edge = (ReferenceEdge) referenceeIter.next();
- if (edge.getSrc() instanceof HeapRegionNode) {
- returnSet.add(edge);
- }
- }
- }
- return returnSet;
- }
-
- private HashSet<TempDescriptor> getTempDescSetReferenceToSameHRN(
- OwnershipGraph og, TempDescriptor td) {
-
- HashSet<TempDescriptor> returnSet = new HashSet<TempDescriptor>();
-
- HashSet<HeapRegionNode> heapIDs = getReferenceHeapIDSet(og, td);
- for (Iterator<HeapRegionNode> iterator = heapIDs.iterator(); iterator
- .hasNext();) {
- HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
- Iterator<ReferenceEdge> referencerIter = heapRegionNode
- .iteratorToReferencers();
- while (referencerIter.hasNext()) {
- ReferenceEdge edge = (ReferenceEdge) referencerIter.next();
- if (edge.getSrc() instanceof LabelNode) {
- LabelNode ln = (LabelNode) edge.getSrc();
- returnSet.add(ln.getTempDescriptor());
- }
- }
- }
- return returnSet;
- }
-
- private void DFSVisit( MethodDescriptor md,
- LinkedList<MethodDescriptor> sorted,
- HashSet<MethodDescriptor> discovered, JavaCallGraph javaCallGraph) {
-
- discovered.add(md);
-
- Iterator itr = javaCallGraph.getCallerSet(md).iterator();
- while (itr.hasNext()) {
- MethodDescriptor mdCaller = (MethodDescriptor) itr.next();
-
- if (!discovered.contains(mdCaller)) {
- DFSVisit(mdCaller, sorted, discovered, javaCallGraph);
- }
- }
-
- sorted.addFirst(md);
- }
-
-
- private LinkedList<MethodDescriptor> topologicalSort(Set set,
- JavaCallGraph javaCallGraph) {
- HashSet<MethodDescriptor> discovered = new HashSet<MethodDescriptor>();
- LinkedList<MethodDescriptor> sorted = new LinkedList<MethodDescriptor>();
-
- Iterator<MethodDescriptor> itr = set.iterator();
- while (itr.hasNext()) {
- MethodDescriptor md = itr.next();
-
- if (!discovered.contains(md)) {
- DFSVisit(md, sorted, discovered, javaCallGraph);
- }
- }
-
- return sorted;
- }
-
- private void calculateCovering(ConflictGraph conflictGraph){
- uniqueLockSetId=0; // reset lock counter for every new conflict graph
- HashSet<ConflictEdge> fineToCover = new HashSet<ConflictEdge>();
- HashSet<ConflictEdge> coarseToCover = new HashSet<ConflictEdge>();
- HashSet<SESELock> lockSet=new HashSet<SESELock>();
-
- HashSet<ConflictEdge> tempCover = conflictGraph.getEdgeSet();
- for (Iterator iterator = tempCover.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
- if(conflictEdge.getType()==ConflictEdge.FINE_GRAIN_EDGE){
- fineToCover.add(conflictEdge);
- }else if(conflictEdge.getType()==ConflictEdge.COARSE_GRAIN_EDGE){
- coarseToCover.add(conflictEdge);
- }
- }
-
- HashSet<ConflictEdge> toCover=new HashSet<ConflictEdge>();
- toCover.addAll(fineToCover);
- toCover.addAll(coarseToCover);
-
- while (!toCover.isEmpty()) {
-
- SESELock seseLock = new SESELock();
- seseLock.setID(uniqueLockSetId++);
-
- boolean changed;
-
- do{ // fine-grained edge
-
- changed=false;
-
- for (Iterator iterator = fineToCover.iterator(); iterator
- .hasNext();) {
-
- int type;
- ConflictEdge edge = (ConflictEdge) iterator.next();
- if(seseLock.getConflictNodeSet().size()==0){
- //initial setup
- if(seseLock.isWriteNode(edge.getVertexU())){
- // mark as fine_write
- if(edge.getVertexU() instanceof StallSiteNode){
- type=ConflictNode.PARENT_WRITE;
- }else{
- type=ConflictNode.FINE_WRITE;
- }
- seseLock.addConflictNode(edge.getVertexU(), type);
- }else{
- // mark as fine_read
- if(edge.getVertexU() instanceof StallSiteNode){
- type=ConflictNode.PARENT_READ;
- }else{
- type=ConflictNode.FINE_READ;
- }
- seseLock.addConflictNode(edge.getVertexU(), type);
- }
- if(edge.getVertexV()!=edge.getVertexU()){
- if(seseLock.isWriteNode(edge.getVertexV())){
- // mark as fine_write
- if(edge.getVertexV() instanceof StallSiteNode){
- type=ConflictNode.PARENT_WRITE;
- }else{
- type=ConflictNode.FINE_WRITE;
- }
- seseLock.addConflictNode(edge.getVertexV(), type);
- }else{
- // mark as fine_read
- if(edge.getVertexV() instanceof StallSiteNode){
- type=ConflictNode.PARENT_READ;
- }else{
- type=ConflictNode.FINE_READ;
- }
- seseLock.addConflictNode(edge.getVertexV(), type);
- }
- }
- changed=true;
- seseLock.addConflictEdge(edge);
- fineToCover.remove(edge);
- break;// exit iterator loop
- }// end of initial setup
-
- ConflictNode newNode;
- if((newNode=seseLock.getNewNodeConnectedWithGroup(edge))!=null){
- // new node has a fine-grained edge to all current node
- // If there is a coarse grained edge where need a fine edge, it's okay to add the node
- // but the edge must remain uncovered.
-
- changed=true;
-
- if(seseLock.isWriteNode(newNode)){
- if(newNode instanceof StallSiteNode){
- type=ConflictNode.PARENT_WRITE;
- }else{
- type=ConflictNode.FINE_WRITE;
- }
- seseLock.setNodeType(newNode,type);
- }else{
- if(newNode instanceof StallSiteNode){
- type=ConflictNode.PARENT_READ;
- }else{
- type=ConflictNode.FINE_READ;
- }
- seseLock.setNodeType(newNode,type);
- }
-
- seseLock.addEdge(edge);
- HashSet<ConflictEdge> edgeSet=newNode.getEdgeSet();
- for (Iterator iterator2 = edgeSet.iterator(); iterator2
- .hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator2
- .next();
-
-
- // mark all fine edges between new node and nodes in the group as covered
- if(!conflictEdge.getVertexU().equals(newNode)){
- if(seseLock.containsConflictNode(conflictEdge.getVertexU())){
- changed=true;
- seseLock.addConflictEdge(conflictEdge);
- fineToCover.remove(conflictEdge);
- }
- }else if(!conflictEdge.getVertexV().equals(newNode)){
- if(seseLock.containsConflictNode(conflictEdge.getVertexV())){
- changed=true;
- seseLock.addConflictEdge(conflictEdge);
- fineToCover.remove(conflictEdge);
- }
- }
-
- }
-
- break;// exit iterator loop
- }
- }
-
- }while(changed);
- do{ // coarse
- changed=false;
- int type;
- for (Iterator iterator = coarseToCover.iterator(); iterator
- .hasNext();) {
-
- ConflictEdge edge = (ConflictEdge) iterator.next();
-
- if(seseLock.getConflictNodeSet().size()==0){
- //initial setup
- if(seseLock.hasSelfCoarseEdge(edge.getVertexU())){
- // node has a coarse-grained edge with itself
- if(!(edge.getVertexU() instanceof StallSiteNode)){
- // and it is not parent
- type=ConflictNode.SCC;
- }else{
- type=ConflictNode.PARENT_COARSE;
- }
- seseLock.addConflictNode(edge.getVertexU(), type);
- }else{
- if(edge.getVertexU() instanceof StallSiteNode){
- type=ConflictNode.PARENT_COARSE;
- }else{
- type=ConflictNode.COARSE;
- }
- seseLock.addConflictNode(edge.getVertexU(), type);
- }
- if(seseLock.hasSelfCoarseEdge(edge.getVertexV())){
- // node has a coarse-grained edge with itself
- if(!(edge.getVertexV() instanceof StallSiteNode)){
- // and it is not parent
- type=ConflictNode.SCC;
- }else{
- type=ConflictNode.PARENT_COARSE;
- }
- seseLock.addConflictNode(edge.getVertexV(), type);
- }else{
- if(edge.getVertexV() instanceof StallSiteNode){
- type=ConflictNode.PARENT_COARSE;
- }else{
- type=ConflictNode.COARSE;
- }
- seseLock.addConflictNode(edge.getVertexV(), type);
- }
- changed=true;
- coarseToCover.remove(edge);
- seseLock.addConflictEdge(edge);
- break;// exit iterator loop
- }// end of initial setup
-
-
- ConflictNode newNode;
- if((newNode=seseLock.getNewNodeConnectedWithGroup(edge))!=null){
- // new node has a coarse-grained edge to all fine-read, fine-write, parent
- changed=true;
-
- if(seseLock.hasSelfCoarseEdge(newNode)){
- //SCC
- if(newNode instanceof StallSiteNode){
- type=ConflictNode.PARENT_COARSE;
- }else{
- type=ConflictNode.SCC;
- }
- seseLock.setNodeType(newNode, type);
- }else{
- if(newNode instanceof StallSiteNode){
- type=ConflictNode.PARENT_COARSE;
- }else{
- type=ConflictNode.COARSE;
- }
- seseLock.setNodeType(newNode, type);
- }
-
- seseLock.addEdge(edge);
- HashSet<ConflictEdge> edgeSet=newNode.getEdgeSet();
- for (Iterator iterator2 = edgeSet.iterator(); iterator2
- .hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator2
- .next();
- // mark all coarse edges between new node and nodes in the group as covered
- if(!conflictEdge.getVertexU().equals(newNode)){
- if(seseLock.containsConflictNode(conflictEdge.getVertexU())){
- changed=true;
- seseLock.addConflictEdge(conflictEdge);
- coarseToCover.remove(conflictEdge);
- }
- }else if(!conflictEdge.getVertexV().equals(newNode)){
- if(seseLock.containsConflictNode(conflictEdge.getVertexV())){
- changed=true;
- seseLock.addConflictEdge(conflictEdge);
- coarseToCover.remove(conflictEdge);
- }
- }
-
- }
- break;// exit iterator loop
- }
-
- }
-
- }while(changed);
- lockSet.add(seseLock);
-
- toCover.clear();
- toCover.addAll(fineToCover);
- toCover.addAll(coarseToCover);
-
- }
-
- conflictGraphLockMap.put(conflictGraph, lockSet);
- }
-
- private void synthesizeLocks(){
- 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();
- calculateCovering(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();
- OwnershipGraph og=ownAnalysisForSESEConflicts.getOwnvershipGraphByMethodContext(mc);
-
- 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);
-
- Hashtable<TempDescriptor, TempDescriptor> invarMap=new Hashtable<TempDescriptor,TempDescriptor>();
-
- 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(og);
- }
- 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
- 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,invarMap);
-
- 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,
- TempDescriptor tempDescriptor) {
- // reachability set
- Set<Set> reachabilitySet = new HashSet();
- LabelNode ln = og.td2ln.get(tempDescriptor);
- if(ln!=null){
- Iterator<ReferenceEdge> refEdgeIter = ln.iteratorToReferencees();
- while (refEdgeIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) refEdgeIter.next();
-
- ReachabilitySet set = referenceEdge.getBeta();
- Iterator<TokenTupleSet> ttsIter = set.iterator();
- while (ttsIter.hasNext()) {
- TokenTupleSet tokenTupleSet = (TokenTupleSet) ttsIter.next();
-
- HashSet<GloballyUniqueTokenTuple> newTokenTupleSet = new HashSet<GloballyUniqueTokenTuple>();
- // reachabilitySet.add(tokenTupleSet);
-
- Iterator iter = tokenTupleSet.iterator();
- while (iter.hasNext()) {
- TokenTuple tt = (TokenTuple) iter.next();
- int token = tt.getToken();
- String uniqueID = og.id2hrn.get(new Integer(token))
- .getGloballyUniqueIdentifier();
- GloballyUniqueTokenTuple gtt = new GloballyUniqueTokenTuple(
- uniqueID, tt);
- newTokenTupleSet.add(gtt);
- }
-
- reachabilitySet.add(newTokenTupleSet);
- }
- }
- }
-
- return reachabilitySet;
- }
-
- private ReachabilitySet packupStates(OwnershipGraph og, HeapRegionNode hrn) {
-
- ReachabilitySet betaSet = new ReachabilitySet().makeCanonical();
-
- Iterator<ReferenceEdge> itrEdge = hrn.iteratorToReferencers();
- while (itrEdge.hasNext()) {
- ReferenceEdge edge = itrEdge.next();
- betaSet = betaSet.union(edge.getBeta());
- }
-
- return betaSet;
-
- }
-
- private ReachabilitySet packupStates(OwnershipGraph og, AllocationSite as) {
-
- ReachabilitySet betaSet = new ReachabilitySet().makeCanonical();
- assert as!=null;
- HeapRegionNode hrnSummary = og.id2hrn.get(as.getSummary());
- if(hrnSummary!=null){
- Iterator<ReferenceEdge> itrEdge = hrnSummary.iteratorToReferencers();
- while (itrEdge.hasNext()) {
- ReferenceEdge edge = itrEdge.next();
- betaSet = betaSet.union(edge.getBeta());
- }
- }
-
- // check for other nodes
- for (int i = 0; i < as.getAllocationDepth(); ++i) {
-
- HeapRegionNode hrnIthOldest = og.id2hrn.get(as.getIthOldest(i));
-// betaSet = new ReachabilitySet().makeCanonical();
-// itrEdge = hrnIthOldest.iteratorToReferencees();
- Iterator<ReferenceEdge> itrEdge = hrnIthOldest.iteratorToReferencers();
- while (itrEdge.hasNext()) {
- ReferenceEdge edge = itrEdge.next();
- betaSet = betaSet.union(edge.getBeta());
- }
- }
-
- Iterator<TokenTupleSet> ttSetIter = betaSet.iterator();
- while (ttSetIter.hasNext()) {
- TokenTupleSet tokenTupleSet = (TokenTupleSet) ttSetIter.next();
- Iterator iter = tokenTupleSet.iterator();
- while (iter.hasNext()) {
- TokenTuple tt = (TokenTuple) iter.next();
- int token = tt.getToken();
- String uniqueID = og.id2hrn.get(new Integer(token))
- .getGloballyUniqueIdentifier();
- GloballyUniqueTokenTuple gtt = new GloballyUniqueTokenTuple(
- uniqueID, tt);
- }
- }
- return betaSet;
- }
-
- private void conflictGraph_nodeAction(MethodContext mc, FlatMethod fm,
- FlatNode fn,Hashtable<TempDescriptor, TempDescriptor> invarMap) {
-
- switch (fn.kind()) {
-
- case FKind.FlatSESEEnterNode: {
-
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- OwnershipGraph og = ownAnalysisForSESEConflicts
- .getOwnvershipGraphByMethodContext(mc);
-
- if (!fsen.getIsCallerSESEplaceholder()) {
- Collection<TempDescriptor> invar_set = fsen.getInVarSet();
-
- SESESummary seseSummary=seseSummaryMap.get(fsen);
- ConflictGraph conflictGraph=null;
- conflictGraph=conflictGraphResults.get(seseSummary.getCurrentParent());
-
- if(conflictGraph==null){
- conflictGraph = new ConflictGraph(og);
- }
-
-
- for (Iterator iterator = invar_set.iterator(); iterator
- .hasNext();) {
- TempDescriptor tempDescriptor = (TempDescriptor) iterator
- .next();
-
- if(!tempDescriptor.getType().isArray() && tempDescriptor.getType().isImmutable()){
- continue;
- }
-
- // effects set
- SESEEffectsSet seseEffectsSet = fsen.getSeseEffectsSet();
- Set<SESEEffectsKey> readEffectsSet = seseEffectsSet
- .getReadingSet(tempDescriptor);
-
- if (readEffectsSet != null) {
- for (Iterator iterator2 = readEffectsSet.iterator(); iterator2
- .hasNext();) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2
- .next();
- String uniqueID = seseEffectsKey.getHRNUniqueId();
- HeapRegionNode node = og.gid2hrn.get(uniqueID);
- if(node.isParameter()){
- seseEffectsKey.setRSet(packupStates(og,node));
- }else{
- AllocationSite as = node.getAllocationSite();
- seseEffectsKey.setRSet(packupStates(og,as));
- }
- }
- }
-
- if (readEffectsSet != null) {
- for (Iterator iterator2 = readEffectsSet.iterator(); iterator2
- .hasNext();) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2
- .next();
- }
- }
- Set<SESEEffectsKey> writeEffectsSet = seseEffectsSet
- .getWritingSet(tempDescriptor);
-
- if (writeEffectsSet != null) {
- for (Iterator iterator2 = writeEffectsSet.iterator(); iterator2
- .hasNext();) {
- SESEEffectsKey seseEffectsKey = (SESEEffectsKey) iterator2
- .next();
- String uniqueID = seseEffectsKey.getHRNUniqueId();
- HeapRegionNode node = og.gid2hrn.get(uniqueID);
-
- if(node.isParameter()){
- seseEffectsKey.setRSet(packupStates(og,node));
- }else{
- AllocationSite as = node.getAllocationSite();
- seseEffectsKey.setRSet(packupStates(og,as));
- }
- }
- }
-
- Set<SESEEffectsKey> strongUpdateSet = seseEffectsSet.getStrongUpdateSet(tempDescriptor);
-
- Set<Set> reachabilitySet = calculateReachabilitySet(og,
- tempDescriptor);
-
- // add new live-in node
-
- OwnershipGraph lastOG = ownAnalysis
- .getOwnvershipGraphByMethodContext(mc);
- LabelNode ln = lastOG.td2ln.get(tempDescriptor);
-
-
- Set<HeapRegionNode> hrnSet = new HashSet<HeapRegionNode>();
- Iterator<ReferenceEdge> refIter = ln
- .iteratorToReferencees();
- while (refIter.hasNext()) {
- ReferenceEdge referenceEdge = (ReferenceEdge) refIter
- .next();
- //
- SESEEffectsSet seseEffects=fsen.getSeseEffectsSet();
- int taintIdentifier=fsen.getSeseEffectsSet().getTaint(referenceEdge);
- int invarIdx=fsen.getSeseEffectsSet().getInVarIdx(tempDescriptor);
- int inVarMask=(int) Math.pow(2,invarIdx);
- if((inVarMask&taintIdentifier)>0){
- // find tainted edge, add heap root to live-in node
- hrnSet.add(referenceEdge.getDst());
- }
- //
- }
-
- conflictGraph.addLiveInNode(tempDescriptor, hrnSet, fsen,
- readEffectsSet, writeEffectsSet, strongUpdateSet, reachabilitySet);
- }
-
-
- if(conflictGraph.id2cn.size()>0){
- conflictGraphResults.put(seseSummary.getCurrentParent(),conflictGraph);
- }
-
- }
-
- }
-
- break;
-
- }
-
- }
-
- private void seseConflictsForward(JavaCallGraph javaCallGraph) {
-
- Set methodCallSet = javaCallGraph.getAllMethods(typeUtil.getMain());
-
- // topologically sort java call chain so that leaf calls are ordered
- // first
- LinkedList<MethodDescriptor> sortedMethodCalls = topologicalSort(
- methodCallSet, javaCallGraph);
-
- for (Iterator iterator = sortedMethodCalls.iterator(); iterator
- .hasNext();) {
-
- MethodDescriptor md = (MethodDescriptor) iterator.next();
-
- FlatMethod fm = state.getMethodFlat(md);
-
- HashSet<MethodContext> mcSet = ownAnalysis
- .getAllMethodContextSetByDescriptor(md);
- Iterator<MethodContext> mcIter = mcSet.iterator();
-
- currentMethodSummary = new MethodSummary();
- preeffectsSet = new HashSet<PreEffectsKey>();
-
- // iterates over all possible method context
- while (mcIter.hasNext()) {
- MethodContext mc = mcIter.next();
-
- LinkedList<FlatNode> flatNodesToVisit=new LinkedList<FlatNode>();
- flatNodesToVisit.add(fm);
-
- SESESummary summary = new SESESummary(null, fm);
- seseSummaryMap.put(fm, summary);
-
- Hashtable<TempDescriptor, TempDescriptor> invarMap=new Hashtable<TempDescriptor,TempDescriptor>();
-
- while (!flatNodesToVisit.isEmpty()) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove(fn);
- ParentChildConflictsMap prevResult = conflictsResults
- .get(fn);
-
- // merge sets from control flow
- Boolean prevSESE=null;
- ParentChildConflictsMap currentConflictsMap = new ParentChildConflictsMap();
- for (int i = 0; i < fn.numPrev(); i++) {
- FlatNode prevFlatNode = fn.getPrev(i);
- ParentChildConflictsMap incoming = conflictsResults
- .get(prevFlatNode);
- if (incoming != null) {
- currentConflictsMap.merge(incoming);
- }
-
- if(prevFlatNode instanceof FlatCondBranch){
- prevSESE=isAfterChildSESEIndicatorMap.get(prevFlatNode);
- }
- }
- SESESummary currentSummary = seseSummaryMap.get(fn);
- //if (currentSummary == null) {
- if(!(fn instanceof FlatMethod)){
- FlatNode current = null;
- FlatNode currentParent = null;
- // calculate sese summary info from previous flat nodes
-
- for (int i = 0; i < fn.numPrev(); i++) {
- FlatNode prevFlatNode = fn.getPrev(i);
- SESESummary prevSummary = seseSummaryMap
- .get(prevFlatNode);
- if (prevSummary != null) {
- if (prevFlatNode instanceof FlatSESEExitNode
- && !((FlatSESEExitNode) prevFlatNode)
- .getFlatEnter()
- .getIsCallerSESEplaceholder()) {
- current = prevSummary.getCurrentParent();
- SESESummary temp = seseSummaryMap
- .get(current);
- currentParent = temp.getCurrentParent();
- } else {
- current = prevSummary.getCurrentSESE();
- currentParent = prevSummary
- .getCurrentParent();
- }
-
- break;
- }
- }
-
- currentSummary = new SESESummary(currentParent, current);
- seseSummaryMap.put(fn, currentSummary);
- }
-
- if(prevSESE!=null){
- if(fn instanceof FlatSESEEnterNode){
- isAfterChildSESEIndicatorMap.put(currentSummary.getCurrentSESE(), currentConflictsMap.isAfterSESE());
- }else{
- isAfterChildSESEIndicatorMap.put(currentSummary.getCurrentSESE(), prevSESE);
- }
- }
-
- Boolean b=isAfterChildSESEIndicatorMap.get(currentSummary.getCurrentSESE());;
- if(b==null){
- currentConflictsMap.setIsAfterSESE(false);
- }else{
- currentConflictsMap.setIsAfterSESE(b.booleanValue());
- }
-
- FlatNode tempP=currentSummary.getCurrentParent();
- FlatNode tempS=currentSummary.getCurrentSESE();
-
- conflicts_nodeAction(mc, fn, callGraph, preeffectsSet,
- currentConflictsMap, currentSummary,invarMap);
-
-
- // if we have a new result, schedule forward nodes for
- // analysis
- if (!currentConflictsMap.equals(prevResult)) {
- seseSummaryMap.put(fn, currentSummary);
- conflictsResults.put(fn, currentConflictsMap);
- for (int i = 0; i < fn.numNext(); i++) {
- FlatNode nn = fn.getNext(i);
- flatNodesToVisit.addFirst(nn);
- }
- }
-
- }
-
- }
-
- }
-
- }
-
-
- private void conflicts_nodeAction(MethodContext mc, FlatNode fn,
- CallGraph callGraph, HashSet<PreEffectsKey> preeffectsSet,
- ParentChildConflictsMap currentConflictsMap,
- SESESummary currentSummary,
- Hashtable<TempDescriptor, TempDescriptor> invarMap) {
-
- OwnershipGraph og = ownAnalysis.getOwnvershipGraphByMethodContext(mc);
-
- currentConflictsMap.clearStallMap();
-
- switch (fn.kind()) {
-
- case FKind.FlatSESEEnterNode: {
-
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
-
- if (!fsen.getIsCallerSESEplaceholder()) {
- FlatNode parentNode = currentSummary.getCurrentSESE();
- currentSummary.setCurrentParent(parentNode);
- currentSummary.setCurrentSESE(fsen);
-// seseSummaryMap.put(fsen, currentSummary);
- }
-
- if (!fsen.getIsCallerSESEplaceholder()) {
- currentMethodSummary.increaseChildSESECount();
- }
- if (currentMethodSummary.getChildSESECount() == 1) {
- // need to store pre-effects
- currentMethodSummary.getEffectsSet().addAll(preeffectsSet);
- for (Iterator iterator = currentMethodSummary.getEffectsSet()
- .iterator(); iterator.hasNext();) {
- PreEffectsKey preEffectsKey = (PreEffectsKey) iterator
- .next();
- }
- preeffectsSet.clear();
- }
- }
- break;
-
- case FKind.FlatSESEExitNode: {
-
- FlatSESEExitNode fsen = (FlatSESEExitNode) fn;
-
- if (!fsen.getFlatEnter().getIsCallerSESEplaceholder()) {
- // all object variables are inaccessible.
- isAfterChildSESEIndicatorMap.put(currentSummary
- .getCurrentParent(), new Boolean(true));
- }
-// currentConflictsMap = new ParentChildConflictsMap();
- currentConflictsMap.clear();
-
- }
- break;
-
- case FKind.FlatCondBranch: {
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
- isAfterChildSESEIndicatorMap.put(fn, new Boolean(isAfterChildSESE));
- }
- break;
-
- case FKind.FlatNew: {
-
- FlatNew fnew = (FlatNew) fn;
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (isAfterChildSESE) {
- TempDescriptor dst = fnew.getDst();
- currentConflictsMap.addAccessibleVar(dst);
- }
-
- }
- break;
-
- case FKind.FlatElementNode:{
-
-
- FlatElementNode fen = (FlatElementNode) fn;
- TempDescriptor src=fen.getSrc();
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if(isAfterChildSESE){
-
- if (!currentConflictsMap.isAccessible(src)) {
- if(invarMap.containsKey(src)){
- currentConflictsMap.addStallSite(src, new HashSet<HeapRegionNode>(),
- new StallTag(fn),invarMap.get(src));
- }else{
- currentConflictsMap.addStallSite(src, new HashSet<HeapRegionNode>(),
- new StallTag(fn),null);
- }
- }
- currentConflictsMap.addAccessibleVar(src);
-
- // contribute read effect on source's stall site
- currentConflictsMap.contributeEffect(src, "", "",
- StallSite.READ_EFFECT);
-
- }
-
- if (currentMethodSummary.getChildSESECount() == 0) {
- // analyze preeffects
- preEffectAnalysis(og, src, null, PreEffectsKey.READ_EFFECT);
- }
-
-
- } break;
-
- case FKind.FlatFieldNode: {
-
- FlatFieldNode ffn = (FlatFieldNode) fn;
- TempDescriptor dst = ffn.getDst();
- TempDescriptor src = ffn.getSrc();
- FieldDescriptor field = ffn.getField();
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (isAfterChildSESE) {
-
- if (!currentConflictsMap.isAccessible(src)) {
- HashSet<HeapRegionNode> refHRN = getReferenceHeapIDSet(
- og, src);
- currentConflictsMap.addStallSite(src, refHRN,
- new StallTag(fn),null);
-
- // flag stall site for disjoint analysis
- for (Iterator iterator2 = refHRN.iterator(); iterator2
- .hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator2
- .next();
- if (hrn.isParameter()) {
- // if stall site is paramter heap region, need
- // to decompose into caller's
- HashSet<HeapRegionNode> visitedHRN = new HashSet<HeapRegionNode>();
- visitedHRN.add(hrn);
- setupRelatedAllocSiteAnalysis(og, mc, hrn,
- visitedHRN);
- } else {
-// System.out.println("FLAGGED "+mc+":"+ffn);
- flagAllocationSite(mc, hrn.getAllocationSite());
- }
- }
-
- }
- currentConflictsMap.addAccessibleVar(src);
-
- // contribute read effect on source's stall site
- currentConflictsMap.contributeEffect(src, field
- .getType().getSafeSymbol(), field.getSymbol(),
- StallSite.READ_EFFECT);
-
- if(field.getType().isImmutable()){
- currentConflictsMap.addAccessibleVar(dst);
- }
-
- }
-
- if (currentMethodSummary.getChildSESECount() == 0) {
- // analyze preeffects
- preEffectAnalysis(og, src, field, PreEffectsKey.READ_EFFECT);
- }
-
- }
- break;
-
- case FKind.FlatSetElementNode:{
-
- FlatSetElementNode fsen=(FlatSetElementNode)fn;
- TempDescriptor dst = fsen.getDst();
- TempDescriptor src = fsen.getSrc();
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (isAfterChildSESE) {
-
- if (!currentConflictsMap.isAccessible(src)) {
- HashSet<HeapRegionNode> refHRN = getReferenceHeapIDSet(og,
- src);
- currentConflictsMap.addStallSite(src, refHRN , new StallTag(
- fn),null);
- }
- currentConflictsMap.addAccessibleVar(src);
-
- if (!currentConflictsMap.isAccessible(dst)) {
- if(invarMap.containsKey(dst)){
- currentConflictsMap.addStallSite(dst, new HashSet<HeapRegionNode>(),
- new StallTag(fn),invarMap.get(dst));
- }else{
- currentConflictsMap.addStallSite(dst, new HashSet<HeapRegionNode>(),
- new StallTag(fn),null);
- }
- }
- currentConflictsMap.addAccessibleVar(dst);
- // contribute write effect on destination's stall site
- currentConflictsMap.contributeEffect(dst, "","",
- StallSite.WRITE_EFFECT);
-
- }
-
- if (currentMethodSummary.getChildSESECount() == 0) {
- // analyze preeffects
- preEffectAnalysis(og, dst, null, PreEffectsKey.WRITE_EFFECT);
- }
-
- } break;
-
- case FKind.FlatSetFieldNode: {
-
- FlatSetFieldNode fsen = (FlatSetFieldNode) fn;
- TempDescriptor dst = fsen.getDst();
- FieldDescriptor field = fsen.getField();
- TempDescriptor src = fsen.getSrc();
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (isAfterChildSESE) {
-
- if (!currentConflictsMap.isAccessible(src)) {
- HashSet<HeapRegionNode> refHRN = getReferenceHeapIDSet(og,
- src);
- currentConflictsMap.addStallSite(src, refHRN, new StallTag(
- fn),null);
-
- // flag stall site for disjoint analysis
- for (Iterator iterator2 = refHRN.iterator(); iterator2
- .hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator2.next();
-
- if (hrn.isParameter()) {
- // if stall site is paramter heap region, need
- // to decompose into caller's
- HashSet<HeapRegionNode> visitedHRN = new HashSet<HeapRegionNode>();
- visitedHRN.add(hrn);
- setupRelatedAllocSiteAnalysis(og, mc, hrn,
- visitedHRN);
- } else {
- flagAllocationSite(mc, hrn.getAllocationSite());
- }
-
- }
-
- }
- currentConflictsMap.addAccessibleVar(src);
-
-
- if (!currentConflictsMap.isAccessible(dst)) {
- HashSet<HeapRegionNode> refHRN = getReferenceHeapIDSet(
- og, dst);
- currentConflictsMap.addStallSite(dst, refHRN,
- new StallTag(fn),null);
-
- // flag stall site for disjoint analysis
- for (Iterator iterator2 = refHRN.iterator(); iterator2
- .hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator2
- .next();
- if (hrn.isParameter()) {
- // if stall site is paramter heap region, need
- // to decompose into caller's
- HashSet<HeapRegionNode> visitedHRN = new HashSet<HeapRegionNode>();
- visitedHRN.add(hrn);
- setupRelatedAllocSiteAnalysis(og, mc, hrn,
- visitedHRN);
- } else {
- flagAllocationSite(mc, hrn.getAllocationSite());
- }
- }
- }
-
- currentConflictsMap.addAccessibleVar(dst);
- // contribute write effect on destination's stall site
- currentConflictsMap.contributeEffect(dst, field
- .getType().getSafeSymbol(), field.getSymbol(),
- StallSite.WRITE_EFFECT);
-
-
- // TODO need to create edge mapping for newly created edge
- HashSet<ReferenceEdge> edges = getRefEdgeSetReferenceToSameHRN(
- og, dst);
-
- StallSite ss = currentConflictsMap.getStallMap().get(dst);
- if (ss != null) {
- for (Iterator iterator = edges.iterator(); iterator
- .hasNext();) {
- ReferenceEdge referenceEdge = (ReferenceEdge) iterator
- .next();
- if (!(referenceEdge.getSrc() instanceof LabelNode)) {
- currentConflictsMap.addStallEdge(referenceEdge,
- new StallTag(fn));
- }
- }
- }
- }
-
- if (currentMethodSummary.getChildSESECount() == 0) {
- // analyze preeffects
- preEffectAnalysis(og, dst, field, PreEffectsKey.WRITE_EFFECT);
- }
-
- }
- break;
-
- case FKind.FlatOpNode: {
-
- FlatOpNode fon = (FlatOpNode) fn;
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
-
-
- if( fon.getOp().getOp() ==Operation.ASSIGN){
- invarMap.put(fon.getDest(), fon.getLeft());
- }
-
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (isAfterChildSESE) {
-
- // destination variable gets the status of source.
-
- if (fon.getOp().getOp() == Operation.ASSIGN) {
-
- TempDescriptor dst = fon.getDest();
- TempDescriptor src = fon.getLeft();
-
- Integer sourceStatus = currentConflictsMap
- .getAccessibleMap().get(src);
- if (sourceStatus == null) {
- sourceStatus = ParentChildConflictsMap.INACCESSIBLE;
- }
-
- HashSet<TempDescriptor> dstTempSet = getTempDescSetReferenceToSameHRN(
- og, dst);
-
- for (Iterator<TempDescriptor> iterator = dstTempSet
- .iterator(); iterator.hasNext();) {
- TempDescriptor possibleDst = iterator.next();
-
- if (sourceStatus
- .equals(ParentChildConflictsMap.ACCESSIBLE)) {
- currentConflictsMap.addAccessibleVar(possibleDst);
- } else {
- currentConflictsMap.addInaccessibleVar(possibleDst);
-
- }
-
- }
- }
-
- }
- }
- break;
-
- case FKind.FlatCall: {
-
- FlatCall fc = (FlatCall) fn;
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- int base = 0;
- if (!fc.getMethod().isStatic()) {
- base = 1;
- }
-
- FlatMethod calleeFM = state.getMethodFlat(fc.getMethod());
-
- // retrieve callee's method summary
- MethodSummary calleeMethodSummary = methodSummaryResults
- .get(calleeFM);
-
- if (calleeMethodSummary != null
- && calleeMethodSummary.getChildSESECount() > 0) {
-
- // when parameter variable is accessible,
- // use callee's preeffects to figure out about how it affects
- // caller's stall site
-
- for (int i = 0; i < fc.numArgs(); i++) {
- TempDescriptor paramTemp = fc.getArg(i);
-
- if (isAfterChildSESE) {
- if (currentConflictsMap.isAccessible(paramTemp)
- && currentConflictsMap.hasStallSite(paramTemp)) {
- // preeffect contribute its effect to caller's stall
- // site
-
- int offset = 0;
- if (!fc.getMethod().isStatic()) {
- offset = 1;
- }
-
- HashSet<PreEffectsKey> preeffectSet = calleeMethodSummary
- .getEffectsSetByParamIdx(i + offset);
-
- for (Iterator iterator = preeffectSet.iterator(); iterator
- .hasNext();) {
- PreEffectsKey preEffectsKey = (PreEffectsKey) iterator
- .next();
- currentConflictsMap.contributeEffect(paramTemp,
- preEffectsKey.getType(), preEffectsKey
- .getField(), preEffectsKey
- .getEffectType());
- }
- }
- }
- // in other cases, child SESE has not been discovered,
- // assumes that all variables are accessible
-
- }
-
- // If callee has at least one child sese, all parent object
- // is going to be inaccessible.
- // currentConflictsMap = new ParentChildConflictsMap();
- currentConflictsMap.makeAllInaccessible();
- isAfterChildSESEIndicatorMap.put(currentSummary
- .getCurrentSESE(), new Boolean(true));
-
- TempDescriptor returnTemp = fc.getReturnTemp();
-
- if (calleeMethodSummary.getReturnValueAccessibility().equals(
- MethodSummary.ACCESSIBLE)) {
- // when return value is accessible, associate with its
- // stall site
- currentConflictsMap.addAccessibleVar(returnTemp);
-
- StallSite returnStallSite = calleeMethodSummary
- .getReturnStallSite().copy();
- // handling parameter regions
- HashSet<Integer> stallParamIdx = returnStallSite
- .getCallerParamIdxSet();
- for (Iterator iterator = stallParamIdx.iterator(); iterator
- .hasNext();) {
- Integer idx = (Integer) iterator.next();
-
- int paramIdx = idx.intValue() - base;
- TempDescriptor paramTD = fc.getArg(paramIdx);
-
- // TODO: resolve callee's parameter heap regions by
- // following call chain
-
- }
-
- // flag stall site's allocation sites for disjointness
- // analysis
- HashSet<HeapRegionNode> hrnSet = returnStallSite
- .getHRNSet();
- for (Iterator iterator = hrnSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
- if (hrn.isParameter()) {
- // if stall site is paramter heap region, need to
- // decompose into caller's
- HashSet<HeapRegionNode> visitedHRN = new HashSet<HeapRegionNode>();
- visitedHRN.add(hrn);
- setupRelatedAllocSiteAnalysis(og, mc, hrn,
- visitedHRN);
- } else {
- flagAllocationSite(mc, hrn.getAllocationSite());
- }
- }
-
- currentConflictsMap.addStallSite(returnTemp,
- returnStallSite);
-
- } else if (calleeMethodSummary.getReturnValueAccessibility()
- .equals(MethodSummary.INACCESSIBLE)) {
- // when return value is inaccessible
- currentConflictsMap.addInaccessibleVar(returnTemp);
- }
-
- // TODO: need to handle edge mappings from callee
- Set<Integer> stallParamIdx = calleeMethodSummary
- .getStallParamIdxSet();
- for (Iterator iterator = stallParamIdx.iterator(); iterator
- .hasNext();) {
- Integer paramIdx = (Integer) iterator.next();
- HashSet<StallTag> stallTagSet = calleeMethodSummary
- .getStallTagByParamIdx(paramIdx);
-
- int argIdx = paramIdx.intValue() - base;
- TempDescriptor argTD = fc.getArg(argIdx);
-
- putStallTagOnReferenceEdges(og, argTD, stallTagSet,
- currentConflictsMap);
- }
- }
-
- }
- break;
-
- /*
- * do we need this case? case FKind.FlatLiteralNode: {
- *
- * if (currentConflictsMap.isAfterChildSESE()) { FlatLiteralNode fln =
- * (FlatLiteralNode) fn; TempDescriptor dst = fln.getDst();
- * currentConflictsMap.addAccessibleVar(dst); }
- *
- * } break;
- */
-
- case FKind.FlatReturnNode: {
-
- FlatReturnNode frn = (FlatReturnNode) fn;
- TempDescriptor returnTD = frn.getReturnTemp();
-
- boolean isAfterChildSESE = false;
- FlatNode current = currentSummary.getCurrentSESE();
- Boolean isAfter = isAfterChildSESEIndicatorMap.get(current);
- if (isAfter != null && isAfter.booleanValue()) {
- isAfterChildSESE = true;
- }
-
- if (returnTD != null) {
- if (!isAfterChildSESE) {
- // in this case, all variables are accessible. There are no
- // child SESEs.
- } else {
- if (currentConflictsMap.isAccessible(returnTD)) {
-
- currentMethodSummary
- .setReturnValueAccessibility(MethodSummary.ACCESSIBLE);
- StallSite returnStallSite = currentConflictsMap
- .getStallMap().get(returnTD);
-
- HashSet<HeapRegionNode> stallSiteHRNSet = returnStallSite
- .getHRNSet();
- for (Iterator iterator = stallSiteHRNSet.iterator(); iterator
- .hasNext();) {
- HeapRegionNode stallSiteHRN = (HeapRegionNode) iterator
- .next();
- Set<Integer> paramSet = og.idPrimary2paramIndexSet
- .get(stallSiteHRN.getID());
- returnStallSite.addCallerParamIdxSet(paramSet);
- paramSet = og.idSecondary2paramIndexSet
- .get(stallSiteHRN.getID());
- returnStallSite.addCallerParamIdxSet(paramSet);
- }
-
- currentMethodSummary
- .setReturnStallSite(returnStallSite);
-
- } else {
- currentMethodSummary
- .setReturnValueAccessibility(MethodSummary.INACCESSIBLE);
- }
- }
- }
- }
- break;
-
- case FKind.FlatExit: {
-
- // store method summary when it has at least one child SESE
- if (currentMethodSummary.getChildSESECount() > 0) {
- // current flat method
- FlatMethod fm = state.getMethodFlat(mc.getDescriptor());
- Set<TempDescriptor> stallTempSet = currentConflictsMap
- .getStallMap().keySet();
- for (Iterator iterator = stallTempSet.iterator(); iterator
- .hasNext();) {
- TempDescriptor stallTD = (TempDescriptor) iterator.next();
- StallSite stallSite = currentConflictsMap.getStallMap()
- .get(stallTD);
-
- HashSet<HeapRegionNode> stallSiteHRNSet = stallSite
- .getHRNSet();
- for (Iterator iterator2 = stallSiteHRNSet.iterator(); iterator2
- .hasNext();) {
- HeapRegionNode stallSiteHRN = (HeapRegionNode) iterator2
- .next();
-
- if (stallSiteHRN.isParameter()) {
-
- Set<Integer> paramSet = og.idPrimary2paramIndexSet
- .get(stallSiteHRN.getID());
- currentMethodSummary.addStallParamIdxSet(paramSet,
- stallSite.getStallTagSet());
-
- paramSet = og.idSecondary2paramIndexSet
- .get(stallSiteHRN.getID());
- currentMethodSummary.addStallParamIdxSet(paramSet,
- stallSite.getStallTagSet());
- }
-
- }
-
- }
- methodSummaryResults.put(fm, currentMethodSummary);
- }
- }
- break;
-
- }
-
-// seseSummaryMap.put(fn, currentSummary);
-
- }
-
- private void putStallTagOnReferenceEdges(OwnershipGraph og,
- TempDescriptor argTD, HashSet stallTagSet,
- ParentChildConflictsMap currentConflictsMap) {
-
- LabelNode ln=og.td2ln.get(argTD);
- if(ln!=null){
-
- Iterator<ReferenceEdge> refrenceeIter=ln.iteratorToReferencees();
- while (refrenceeIter.hasNext()) {
- ReferenceEdge refEdge = (ReferenceEdge) refrenceeIter.next();
- HeapRegionNode stallHRN=refEdge.getDst();
-
- Iterator<ReferenceEdge> referencerIter=stallHRN.iteratorToReferencers();
- while (referencerIter.hasNext()) {
- ReferenceEdge referencer = (ReferenceEdge) referencerIter
- .next();
- for (Iterator iterator = stallTagSet.iterator(); iterator
- .hasNext();) {
- StallTag stallTag = (StallTag) iterator.next();
- currentConflictsMap.addStallEdge(referencer, stallTag);
- }
- }
- }
- }
- }
-
- private void preEffectAnalysis(OwnershipGraph og, TempDescriptor td,
- FieldDescriptor field, Integer effectType) {
-
- // analyze preeffects
- HashSet<HeapRegionNode> hrnSet = getReferenceHeapIDSet(og, td);
- for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
- if (hrn.isParameter()) {
- // effects on param heap region
-
- Set<Integer> paramSet = og.idPrimary2paramIndexSet.get(hrn
- .getID());
-
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
- while (paramIter.hasNext()) {
- Integer paramID = paramIter.next();
- PreEffectsKey effectKey=null;
- if(field!=null){
- effectKey = new PreEffectsKey(paramID,
- field.getSymbol(), field.getType()
- .getSafeSymbol(), effectType);
- }else{
- effectKey = new PreEffectsKey(paramID,
- "", "", effectType);
- }
- preeffectsSet.add(effectKey);
- }
- }
-
- // check weather this heap region is parameter
- // reachable...
-
- paramSet = og.idSecondary2paramIndexSet.get(hrn.getID());
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
-
- while (paramIter.hasNext()) {
- Integer paramID = paramIter.next();
- PreEffectsKey effectKey=null;
- if(field!=null){
- effectKey = new PreEffectsKey(paramID,
- field.getSymbol(), field.getType()
- .getSafeSymbol(), effectType);
- }else{
- effectKey = new PreEffectsKey(paramID,
- "", "", effectType);
- }
- preeffectsSet.add(effectKey);
- }
- }
-
- }
- }
- }
-
- private void codePlansForward( FlatMethod fm ) {
-
- // start from flat method top, visit every node in
- // method exactly once
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
-
- Set<FlatNode> visited = new HashSet<FlatNode>();
-
- while( !flatNodesToVisit.isEmpty() ) {
- Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
- FlatNode fn = fnItr.next();
-
- flatNodesToVisit.remove( fn );
- visited.add( fn );
-
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
- assert seseStack != null;
-
- // use incoming results as "dot statement" or just
- // before the current statement
- VarSrcTokTable dotSTtable = new VarSrcTokTable();
- for( int i = 0; i < fn.numPrev(); i++ ) {
- FlatNode nn = fn.getPrev( i );
- dotSTtable.merge( variableResults.get( nn ) );
- }
-
- // find dt-st notAvailableSet also
- Set<TempDescriptor> dotSTnotAvailSet = new HashSet<TempDescriptor>();
- for( int i = 0; i < fn.numPrev(); i++ ) {
- FlatNode nn = fn.getPrev( i );
- Set<TempDescriptor> notAvailIn = notAvailableResults.get( nn );
- if( notAvailIn != null ) {
- dotSTnotAvailSet.addAll( notAvailIn );
- }
- }
-
- Set<TempDescriptor> dotSTlive = livenessRootView.get( fn );
-
- if( !seseStack.empty() ) {
- codePlans_nodeActions( fn,
- dotSTlive,
- dotSTtable,
- dotSTnotAvailSet,
- seseStack.peek()
- );
- }
-
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
-
- if( !visited.contains( nn ) ) {
- flatNodesToVisit.add( nn );
- }
- }
- }
- }
-
- private void codePlans_nodeActions( FlatNode fn,
- Set<TempDescriptor> liveSetIn,
- VarSrcTokTable vstTableIn,
- Set<TempDescriptor> notAvailSetIn,
- FlatSESEEnterNode currentSESE ) {
-
- CodePlan plan = new CodePlan( currentSESE);
-
- switch( fn.kind() ) {
-
- case FKind.FlatSESEEnterNode: {
- FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- assert fsen.equals( currentSESE );
-
- // track the source types of the in-var set so generated
- // code at this SESE issue can compute the number of
- // dependencies properly
- Iterator<TempDescriptor> inVarItr = fsen.getInVarSet().iterator();
- while( inVarItr.hasNext() ) {
- TempDescriptor inVar = inVarItr.next();
-
- // when we get to an SESE enter node we change the
- // currentSESE variable of this analysis to the
- // child that is declared by the enter node, so
- // in order to classify in-vars correctly, pass
- // the parent SESE in--at other FlatNode types just
- // use the currentSESE
- VSTWrapper vstIfStatic = new VSTWrapper();
- Integer srcType =
- vstTableIn.getRefVarSrcType( inVar,
- fsen.getParent(),
- vstIfStatic
- );
-
- // the current SESE needs a local space to track the dynamic
- // variable and the child needs space in its SESE record
- if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
- fsen.addDynamicInVar( inVar );
- fsen.getParent().addDynamicVar( inVar );
-
- } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
- fsen.addStaticInVar( inVar );
- VariableSourceToken vst = vstIfStatic.vst;
- fsen.putStaticInVar2src( inVar, vst );
- fsen.addStaticInVarSrc( new SESEandAgePair( vst.getSESE(),
- vst.getAge()
- )
- );
- } else {
- assert srcType.equals( VarSrcTokTable.SrcType_READY );
- fsen.addReadyInVar( inVar );
- }
- }
-
- } break;
-
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- } break;
-
- case FKind.FlatOpNode: {
- FlatOpNode fon = (FlatOpNode) fn;
-
- if( fon.getOp().getOp() == Operation.ASSIGN ) {
- TempDescriptor lhs = fon.getDest();
- TempDescriptor rhs = fon.getLeft();
-
- // if this is an op node, don't stall, copy
- // source and delay until we need to use value
-
- // ask whether lhs and rhs sources are dynamic, static, etc.
- VSTWrapper vstIfStatic = new VSTWrapper();
- Integer lhsSrcType
- = vstTableIn.getRefVarSrcType( lhs,
- currentSESE,
- vstIfStatic
- );
- Integer rhsSrcType
- = vstTableIn.getRefVarSrcType( rhs,
- currentSESE,
- vstIfStatic
- );
-
- if( rhsSrcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
- // if rhs is dynamic going in, lhs will definitely be dynamic
- // going out of this node, so track that here
- plan.addDynAssign( lhs, rhs );
- currentSESE.addDynamicVar( lhs );
- currentSESE.addDynamicVar( rhs );
-
- } else if( lhsSrcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
- // otherwise, if the lhs is dynamic, but the rhs is not, we
- // need to update the variable's dynamic source as "current SESE"
- plan.addDynAssign( lhs );
- }
-
- // only break if this is an ASSIGN op node,
- // otherwise fall through to default case
- break;
- }
- }
-
- // note that FlatOpNode's that aren't ASSIGN
- // fall through to this default case
- default: {
-
- // a node with no live set has nothing to stall for
- if( liveSetIn == null ) {
- break;
- }
-
- TempDescriptor[] readarray = fn.readsTemps();
- for( int i = 0; i < readarray.length; i++ ) {
- TempDescriptor readtmp = readarray[i];
-
- // ignore temps that are definitely available
- // when considering to stall on it
- if( !notAvailSetIn.contains( readtmp ) ) {
- continue;
- }
-
- // check the source type of this variable
- VSTWrapper vstIfStatic = new VSTWrapper();
- Integer srcType
- = vstTableIn.getRefVarSrcType( readtmp,
- currentSESE,
- vstIfStatic
- );
-
- if( srcType.equals( VarSrcTokTable.SrcType_DYNAMIC ) ) {
- // 1) It is not clear statically where this variable will
- // come from, so dynamically we must keep track
- // along various control paths, and therefore when we stall,
- // just stall for the exact thing we need and move on
- plan.addDynamicStall( readtmp );
- currentSESE.addDynamicVar( readtmp );
-
- } else if( srcType.equals( VarSrcTokTable.SrcType_STATIC ) ) {
- // 2) Single token/age pair: Stall for token/age pair, and copy
- // all live variables with same token/age pair at the same
- // time. This is the same stuff that the notavaialable analysis
- // marks as now available.
- VariableSourceToken vst = vstIfStatic.vst;
-
- Iterator<VariableSourceToken> availItr =
- vstTableIn.get( vst.getSESE(), vst.getAge() ).iterator();
-
- while( availItr.hasNext() ) {
- VariableSourceToken vstAlsoAvail = availItr.next();
-
- // only grab additional stuff that is live
- Set<TempDescriptor> copySet = new HashSet<TempDescriptor>();
-
- Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
- while( refVarItr.hasNext() ) {
- TempDescriptor refVar = refVarItr.next();
- if( liveSetIn.contains( refVar ) ) {
- copySet.add( refVar );
- }
- }
-
- if( !copySet.isEmpty() ) {
- plan.addStall2CopySet( vstAlsoAvail, copySet );
- }
- }
-
- } else {
- // the other case for srcs is READY, so do nothing
- }
-
- // assert that everything being stalled for is in the
- // "not available" set coming into this flat node and
- // that every VST identified is in the possible "stall set"
- // that represents VST's from children SESE's
-
- }
- } break;
-
- } // end switch
-
-
- // identify sese-age pairs that are statically useful
- // and should have an associated SESE variable in code
- // JUST GET ALL SESE/AGE NAMES FOR NOW, PRUNE LATER,
- // AND ALWAYS GIVE NAMES TO PARENTS
- Set<VariableSourceToken> staticSet = vstTableIn.get();
- Iterator<VariableSourceToken> vstItr = staticSet.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
-
- // placeholder source tokens are useful results, but
- // the placeholder static name is never needed
- if( vst.getSESE().getIsCallerSESEplaceholder() ) {
- continue;
- }
-
- FlatSESEEnterNode sese = currentSESE;
- while( sese != null ) {
- sese.addNeededStaticName(
- new SESEandAgePair( vst.getSESE(), vst.getAge() )
- );
- sese.mustTrackAtLeastAge( vst.getAge() );
-
- sese = sese.getParent();
- }
- }
-
-
- codePlans.put( fn, plan );
-
-
- // if any variables at this-node-*dot* have a static source (exactly one vst)
- // but go to a dynamic source at next-node-*dot*, create a new IR graph
- // node on that edge to track the sources dynamically
- VarSrcTokTable thisVstTable = variableResults.get( fn );
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
- VarSrcTokTable nextVstTable = variableResults.get( nn );
- Set<TempDescriptor> nextLiveIn = livenessRootView.get( nn );
-
- // the table can be null if it is one of the few IR nodes
- // completely outside of the root SESE scope
- if( nextVstTable != null && nextLiveIn != null ) {
-
- Hashtable<TempDescriptor, VSTWrapper> readyOrStatic2dynamicSet =
- thisVstTable.getReadyOrStatic2DynamicSet( nextVstTable,
- nextLiveIn,
- currentSESE
- );
-
- if( !readyOrStatic2dynamicSet.isEmpty() ) {
-
- // either add these results to partial fixed-point result
- // or make a new one if we haven't made any here yet
- FlatEdge fe = new FlatEdge( fn, nn );
- FlatWriteDynamicVarNode fwdvn = wdvNodesToSpliceIn.get( fe );
-
- if( fwdvn == null ) {
- fwdvn = new FlatWriteDynamicVarNode( fn,
- nn,
- readyOrStatic2dynamicSet,
- currentSESE
- );
- wdvNodesToSpliceIn.put( fe, fwdvn );
- } else {
- fwdvn.addMoreVar2Src( readyOrStatic2dynamicSet );
- }
- }
- }
- }
- }
-
-
- public void writeReports( String timeReport ) throws java.io.IOException {
-
- BufferedWriter bw = new BufferedWriter( new FileWriter( "mlpReport_summary.txt" ) );
- bw.write( "MLP Analysis Results\n\n" );
- bw.write( timeReport+"\n\n" );
- printSESEHierarchy( bw );
- bw.write( "\n" );
- printSESEInfo( bw );
- bw.close();
-
- Iterator<Descriptor> methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while( methItr.hasNext() ) {
- MethodDescriptor md = (MethodDescriptor) methItr.next();
- FlatMethod fm = state.getMethodFlat( md );
- bw = new BufferedWriter( new FileWriter( "mlpReport_"+
- md.getClassMethodName()+
- md.getSafeMethodDescriptor()+
- ".txt" ) );
- bw.write( "MLP Results for "+md+"\n-------------------\n");
-
- FlatSESEEnterNode implicitSESE = (FlatSESEEnterNode) fm.getNext(0);
- if( !implicitSESE.getIsCallerSESEplaceholder() &&
- implicitSESE != mainSESE
- ) {
- System.out.println( implicitSESE+" is not implicit?!" );
- System.exit( -1 );
- }
- bw.write( "Dynamic vars to manage:\n "+implicitSESE.getDynamicVarSet());
-
- bw.write( "\n\nLive-In, Root View\n------------------\n" +fm.printMethod( livenessRootView ) );
- bw.write( "\n\nVariable Results-Out\n----------------\n" +fm.printMethod( variableResults ) );
- bw.write( "\n\nNot Available Results-Out\n---------------------\n"+fm.printMethod( notAvailableResults ) );
- bw.write( "\n\nCode Plans\n----------\n" +fm.printMethod( codePlans ) );
- bw.write("\n\nSESE Effects\n----------------------\n"+printSESEEffects());
- bw.close();
- }
- }
-
- private String printSESEEffects() {
-
- StringWriter writer = new StringWriter();
-
- Iterator<FlatSESEEnterNode> keyIter = allSESEs.iterator();
-
- while (keyIter.hasNext()) {
- FlatSESEEnterNode seseEnter = keyIter.next();
- String result = seseEnter.getSeseEffectsSet().printSet();
- if (result.length() > 0) {
- writer.write("\nSESE " + seseEnter + "\n");
- writer.write(result);
- }
- }
- keyIter = rootSESEs.iterator();
- while (keyIter.hasNext()) {
- FlatSESEEnterNode seseEnter = keyIter.next();
- if (seseEnter.getIsCallerSESEplaceholder()) {
- if (!seseEnter.getChildren().isEmpty()) {
- String result = seseEnter.getSeseEffectsSet().printSet();
- if (result.length() > 0) {
- writer.write("\nSESE " + seseEnter + "\n");
- writer.write(result);
- }
- }
- }
- }
-
- return writer.toString();
-
- }
-
- private void printSESEHierarchy( BufferedWriter bw ) throws java.io.IOException {
- bw.write( "SESE Hierarchy\n--------------\n" );
- Iterator<FlatSESEEnterNode> rootItr = rootSESEs.iterator();
- while( rootItr.hasNext() ) {
- FlatSESEEnterNode root = rootItr.next();
- if( root.getIsCallerSESEplaceholder() ) {
- if( !root.getChildren().isEmpty() ) {
- printSESEHierarchyTree( bw, root, 0 );
- }
- } else {
- printSESEHierarchyTree( bw, root, 0 );
- }
- }
- }
-
- private void printSESEHierarchyTree( BufferedWriter bw,
- FlatSESEEnterNode fsen,
- int depth
- ) throws java.io.IOException {
- for( int i = 0; i < depth; ++i ) {
- bw.write( " " );
- }
- bw.write( "- "+fsen.getPrettyIdentifier()+"\n" );
-
- Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
- while( childItr.hasNext() ) {
- FlatSESEEnterNode fsenChild = childItr.next();
- printSESEHierarchyTree( bw, fsenChild, depth + 1 );
- }
- }
-
-
- private void printSESEInfo( BufferedWriter bw ) throws java.io.IOException {
- bw.write("\nSESE info\n-------------\n" );
- Iterator<FlatSESEEnterNode> rootItr = rootSESEs.iterator();
- while( rootItr.hasNext() ) {
- FlatSESEEnterNode root = rootItr.next();
- if( root.getIsCallerSESEplaceholder() ) {
- if( !root.getChildren().isEmpty() ) {
- printSESEInfoTree( bw, root );
- }
- } else {
- printSESEInfoTree( bw, root );
- }
- }
- }
-
- private void printSESEInfoTree( BufferedWriter bw,
- FlatSESEEnterNode fsen
- ) throws java.io.IOException {
-
- if( !fsen.getIsCallerSESEplaceholder() ) {
- bw.write( "SESE "+fsen.getPrettyIdentifier()+" {\n" );
-
- bw.write( " in-set: "+fsen.getInVarSet()+"\n" );
- Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
- while( tItr.hasNext() ) {
- TempDescriptor inVar = tItr.next();
- if( fsen.getReadyInVarSet().contains( inVar ) ) {
- bw.write( " (ready) "+inVar+"\n" );
- }
- if( fsen.getStaticInVarSet().contains( inVar ) ) {
- bw.write( " (static) "+inVar+" from "+
- fsen.getStaticInVarSrc( inVar )+"\n" );
- }
- if( fsen.getDynamicInVarSet().contains( inVar ) ) {
- bw.write( " (dynamic)"+inVar+"\n" );
- }
- }
-
- bw.write( " Dynamic vars to manage: "+fsen.getDynamicVarSet()+"\n");
-
- bw.write( " out-set: "+fsen.getOutVarSet()+"\n" );
- bw.write( "}\n" );
- }
-
- Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
- while( childItr.hasNext() ) {
- FlatSESEEnterNode fsenChild = childItr.next();
- printSESEInfoTree( bw, fsenChild );
- }
- }
-
- public Hashtable <FlatNode, ConflictGraph> getConflictGraphResults(){
- return conflictGraphResults;
- }
-
- public Hashtable < FlatNode, ParentChildConflictsMap > getConflictsResults(){
- return conflictsResults;
- }
-
- public Hashtable<FlatNode, SESESummary> getSeseSummaryMap(){
- return seseSummaryMap;
- }
-
- public Hashtable<ConflictGraph, HashSet<SESELock>> getConflictGraphLockMap(){
- return conflictGraphLockMap;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-public class MemoryStall {
- JavaCallGraph callgraph;
- State state;
- TypeUtil typeutil;
- SESETree sesetree;
-
- public MemoryStall(State state, TypeUtil typeutil, JavaCallGraph callgraph, SESETree sesetree) {
- this.state=state;
- this.typeutil=typeutil;
- this.callgraph=callgraph;
- this.sesetree=sesetree;
- }
-
- private boolean isOnlyLeaf(MethodDescriptor md) {
- Set<SESENode> seseset=sesetree.getSESE(md);
- for(Iterator<SESENode> seseit=seseset.iterator();seseit.hasNext();) {
- SESENode sese=seseit.next();
- if (!sese.isLeaf())
- return false;
- }
- return true;
- }
-
- HashSet toanalyze=new HashSet();
-
- public void doAnalysis() {
- MethodDescriptor main=typeutil.getMain();
- toanalyze.addAll(callGraph.getAllMethods(main));
-
- while(!toanalyze.isEmpty()) {
- MethodDescriptor md=(MethodDescriptor)toanalyze.iterator().next();
- toanalyze.remove(md);
- if (isOnlyLeaf(md))
- continue;
- analyzeMethod(md);
- }
- }
-
- private void analyzeMethod(MethodDescriptor md) {
- FlatMethod fm=state.getMethodFlat(md);
- Hashtable<FlatNode, Stack<SESENode>> nodetosese=sesetree.analyzeMethod(md);
- HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
- tovisit.add(fm);
- Hashtable<FlatNode, Set<TempDescriptor>> dirtytemps=new Hashtable<FlatNode, Set<TempDescriptor>>();
-
- while(!tovisit.isEmpty()) {
- FlatNode fn=tovisit.iterator().next();
- tovisit.remove(fn);
- HashSet<TempDescriptor> newset=new HashSet<TempDescriptor>();
- for(int i=0;i<fn.numPrev();i++) {
- if (dirtytemps.containsKey(fn.getPrev(i)))
- newset.addAll(dirtytemps.get(fn.getPrev(i)));
- }
-
- switch(fn.kind()) {
- case FKind.FlatSESEExitNode: {
- newset=new HashSet<TempDescriptor>();
- break;
- }
- case FKind.FlatElementNode: {
- FlatElementNode fen=(FlatElementNode) fn;
- newset.remove(fen.getSrc());
- newset.remove(fen.getDst());
- break;
- }
- case FKind.FlatFieldNode: {
- FlatFieldNode ffn=(FlatFieldNode) fn;
- newset.remove(ffn.getSrc());
- newset.remove(ffn.getDst());
- break;
- }
- case FKind.FlatSetFieldNode: {
- FlatSetFieldNode fsfn=(FlatSetFieldNode) fn;
- newset.remove(fsfn.getSrc());
- newset.remove(fsfn.getDst());
- break;
- }
- case FKind.FlatSetElementNode: {
- FlatSetElementNode fsen=(FlatSetElementNode) fn;
- newset.remove(fsen.getSrc());
- newset.remove(fsen.getDst());
- break;
- }
- case FKind.FlatLiteralNode: {
- FlatLiteralNode fln=(FlatLiteralNode) fn;
- newset.remove(fln.getDst());
- break;
- }
- case FKind.FlatMethodNode: {
-
- break;
- }
- case FKind.FlatOpNode: {
- FlatOpNode fon=(FlatOpNode)fn;
- if (fon.getOp().getOp()==Operation.ASSIGN) {
- if (newset.contains(getLeft()))
- newset.add(getDest());
- else if (!newset.contains(getLeft()))
- newset.remove(getDest());
- break;
- }
- }
- case FKind.FlatCastNode: {
- FlatCastNode fcn=(FlatOpNode)fn;
- if (newset.contains(getSrc()))
- newset.add(getDst());
- else if (!newset.contains(getSrc()))
- newset.remove(getDst());
- break;
- }
- case FKind.FlatNew: {
- FlatNew fnew=(FlatNew) fn;
- newset.remove(fnew.getDst());
- break;
- }
- case FKind.FlatReturnNode: {
- FlatReturnNode frn=(FlatReturnNode) fn;
-
- break;
- }
- case FKind.FlatCall: {
- FlatCall fc=(FlatCall)fn;
-
- break;
- }
- }
-
- }
-
-
-
- }
-
- private MethodDescriptor getBase(MethodDescriptor md) {
- ClassDescriptor cd=md.getClassDesc();
- while (cd.getSuperDesc()!=null) {
- cd=cd.getSuperDesc();
- Set methodset=cd.getMethodTable().getSet(md.getSymbol());
- MethodDescriptor mdtemp=null;
- for(Iterator mdit=methodset.iterator();mdit.hasNext();) {
- MethodDescriptor mdsuper=(MethodDescriptor) mdit.next();
- if (mdsuper.matches(md)) {
- mdtemp=mdsuper;
- break;
- }
- }
- if (mdtemp!=null)
- md=mdtemp;
- else
- return md;
- }
- return md;
- }
-
- class MethodContext {
- boolean[] parameters;
- boolean dirtytemp;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-public class MethodSummary {
-
- public static final Integer VOID=new Integer(0);
- public static final Integer ACCESSIBLE = new Integer(1);
- public static final Integer INACCESSIBLE=new Integer(2);
-
- private int childSESECount;
- private HashSet<PreEffectsKey> effectsSet;
- private Integer accessibility;
- private StallSite returnStallSite;
-
- private Hashtable<Integer, HashSet<StallTag>> mapParamIndexToRelatedStallTag;
-
- public MethodSummary() {
- effectsSet = new HashSet<PreEffectsKey>();
- accessibility = MethodSummary.VOID;
- childSESECount = 0;
- returnStallSite=null;
- mapParamIndexToRelatedStallTag=new Hashtable<Integer, HashSet<StallTag>>();
- }
-
- public void addStallParamIdxSet(Set<Integer> paramIdxSet, HashSet<StallTag> stallTagSet){
-
- if(paramIdxSet!=null){
- for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
- Integer paramIdx = (Integer) iterator.next();
- mapParamIndexToRelatedStallTag.put(paramIdx, stallTagSet);
- }
- }
- }
-
- public HashSet<StallTag> getStallTagByParamIdx(Integer paramIdx){
- return mapParamIndexToRelatedStallTag.get(paramIdx);
- }
-
-
- public Set<Integer> getStallParamIdxSet(){
- return mapParamIndexToRelatedStallTag.keySet();
- }
-
- public void setReturnStallSite(StallSite ss){
- returnStallSite=ss;
- }
-
- public StallSite getReturnStallSite(){
- return returnStallSite;
- }
-
- public void increaseChildSESECount() {
- childSESECount++;
- }
-
- public int getChildSESECount() {
- return childSESECount;
- }
-
- public Integer getReturnValueAccessibility() {
- return accessibility;
- }
-
- public void setReturnValueAccessibility(Integer accessibility) {
- this.accessibility = accessibility;
- }
-
- public HashSet<PreEffectsKey> getEffectsSet() {
- return effectsSet;
- }
-
- @Override
- public String toString() {
- return "MethodSummary [accessibility=" + accessibility
- + ", childSESECount=" + childSESECount + ", effectsSet="
- + effectsSet + "]";
- }
-
- public HashSet<PreEffectsKey> getEffectsSetByParamIdx(int paramIdx){
-
- HashSet<PreEffectsKey> returnSet=new HashSet<PreEffectsKey>();
-
- for (Iterator iterator = effectsSet.iterator(); iterator.hasNext();) {
- PreEffectsKey preEffectsKey = (PreEffectsKey) iterator.next();
- if(preEffectsKey.getParamIndex().equals(new Integer(paramIdx))){
- returnSet.add(preEffectsKey);
- }
- }
-
- return returnSet;
- }
-
-}
-
-class PreEffectsKey {
-
- public static final Integer READ_EFFECT = new Integer(1);
- public static final Integer WRITE_EFFECT = new Integer(2);
-
- private String type;
- private String field;
- private Integer effectType;
- private Integer paramIndex;
-
- public PreEffectsKey(Integer paramIndex, String field, String type,
- Integer effectType) {
- this.paramIndex = paramIndex;
- this.field = field;
- this.type = type;
- this.effectType = effectType;
- }
-
- public String getType() {
- return type;
- }
-
- public String getField() {
- return field;
- }
-
- public Integer getEffectType() {
- return effectType;
- }
-
- public Integer getParamIndex() {
- return paramIndex;
- }
-
- public String toString() {
- return "PreEffectsKey [effectType=" + effectType + ", field=" + field
- + ", paramIndex=" + paramIndex + ", type=" + type + "]";
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof PreEffectsKey)) {
- return false;
- }
-
- PreEffectsKey in = (PreEffectsKey) o;
-
- if (paramIndex.equals(in.getParamIndex())
- && field.equals(in.getField()) && type.equals(in.getType())
- && effectType.equals(in.getEffectType())) {
- return true;
- } else {
- return false;
- }
-
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-import Analysis.OwnershipAnalysis.AllocationSite;
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import Analysis.OwnershipAnalysis.ReferenceEdge;
-import Analysis.OwnershipAnalysis.TokenTupleSet;
-import IR.Flat.TempDescriptor;
-
-public class ParentChildConflictsMap {
-
- public static final Integer ACCESSIBLE = new Integer(1);
- public static final Integer INACCESSIBLE = new Integer(2);
-
- private Hashtable<TempDescriptor, Integer> accessibleMap;
- private Hashtable<TempDescriptor, StallSite> stallMap;
- private Hashtable < ReferenceEdge, HashSet<StallTag> > stallEdgeMap;
- private boolean isAfterSESE;
-
- public ParentChildConflictsMap() {
-
- accessibleMap = new Hashtable<TempDescriptor, Integer>();
- stallMap = new Hashtable<TempDescriptor, StallSite>();
- stallEdgeMap= new Hashtable < ReferenceEdge, HashSet<StallTag> >();
- isAfterSESE=false;
- }
-
- public void setIsAfterSESE(boolean after){
- this.isAfterSESE=after;
- }
-
- public boolean isAfterSESE(){
- return isAfterSESE;
- }
-
- public void clear(){
- accessibleMap.clear();
- stallMap.clear();
- stallEdgeMap.clear();
- }
-
- public void clearStallMap(){
- stallMap.clear();
- }
-
- public void makeAllInaccessible(){
-
- Set<TempDescriptor> keySet=accessibleMap.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- TempDescriptor key = (TempDescriptor) iterator.next();
- accessibleMap.put(key, INACCESSIBLE);
- }
-
- }
-
- public Hashtable < ReferenceEdge, HashSet<StallTag> > getStallEdgeMap(){
- return stallEdgeMap;
- }
-
- public void addStallEdge(ReferenceEdge edge, StallTag sTag){
-
- HashSet<StallTag> tagSet=stallEdgeMap.get(edge);
- if(tagSet==null){
- tagSet=new HashSet<StallTag>();
- }
- tagSet.add(sTag);
- stallEdgeMap.put(edge, tagSet);
- }
-
- public HashSet<StallTag> getStallTagByEdge(ReferenceEdge edge){
- return stallEdgeMap.get(edge);
- }
-
- public Hashtable<TempDescriptor, Integer> getAccessibleMap() {
- return accessibleMap;
- }
-
- public Hashtable<TempDescriptor, StallSite> getStallMap() {
- return stallMap;
- }
-
- public void addAccessibleVar(TempDescriptor td) {
- accessibleMap.put(td, ACCESSIBLE);
- }
-
- public void addInaccessibleVar(TempDescriptor td) {
- accessibleMap.put(td, INACCESSIBLE);
- }
-
- public void addStallSite(TempDescriptor td, HashSet<HeapRegionNode> heapSet, StallTag sTag, TempDescriptor tdA) {
- StallSite stallSite=new StallSite(heapSet,sTag);
- if(tdA!=null){
- stallSite.setTdA(tdA);
- }
- stallMap.put(td, stallSite);
- }
-
- public void addStallSite(TempDescriptor td, StallSite stallSite) {
- stallMap.put(td, stallSite);
- }
-
- public boolean hasStallSite(TempDescriptor td){
- return stallMap.containsKey(td);
- }
-
- public boolean isAccessible(TempDescriptor td) {
- if (accessibleMap.containsKey(td)
- && accessibleMap.get(td).equals(ACCESSIBLE)) {
- return true;
- }
- return false;
- }
-
- public void contributeEffect(TempDescriptor td, String type, String field,
- int effect) {
-
- StallSite stallSite = stallMap.get(td);
- if (stallSite != null) {
- stallSite.addEffect(type, field, effect);
- }
-
- }
-
- public void merge(ParentChildConflictsMap newConflictsMap) {
-
- Hashtable<TempDescriptor, Integer> newAccessibleMap = newConflictsMap
- .getAccessibleMap();
- Hashtable<TempDescriptor, StallSite> newStallMap = newConflictsMap
- .getStallMap();
-
- Set<TempDescriptor> keySet = newAccessibleMap.keySet();
- for (Iterator<TempDescriptor> iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor key = iterator.next();
-
- Integer newStatus = newAccessibleMap.get(key);
-
- // inaccessible is prior to accessible
- Integer currentStatus = getAccessibleMap().get(key);
- if (currentStatus != null && currentStatus == ACCESSIBLE
- && newStatus == INACCESSIBLE) {
- getAccessibleMap().put(key, INACCESSIBLE);
- }else if(currentStatus == null && newStatus == ACCESSIBLE){
- getAccessibleMap().put(key, ACCESSIBLE);
- }
- }
-
- keySet = newStallMap.keySet();
- for (Iterator<TempDescriptor> iterator = keySet.iterator(); iterator
- .hasNext();) {
- TempDescriptor key = iterator.next();
-
- StallSite newStallSite = newStallMap.get(key);
- StallSite currentStallSite = getStallMap().get(key);
-
- if(currentStallSite==null){
- currentStallSite=new StallSite();
- }
-
- // handle effects
- HashSet<Effect> currentEffectSet = currentStallSite.getEffectSet();
- HashSet<Effect> newEffectSet = newStallSite.getEffectSet();
- for (Iterator iterator2 = newEffectSet.iterator(); iterator2
- .hasNext();) {
- Effect effect = (Effect) iterator2.next();
- if (!currentEffectSet.contains(effect)) {
- currentEffectSet.add(effect);
- }
- }
-
- // handle heap region
- HashSet<HeapRegionNode> currentHRNSet = currentStallSite.getHRNSet();
- HashSet<HeapRegionNode> newHRNSet = newStallSite.getHRNSet();
- for (Iterator iterator2 = newHRNSet.iterator(); iterator2.hasNext();) {
- HeapRegionNode hrnID = (HeapRegionNode) iterator2.next();
- if (!currentHRNSet.contains(hrnID)) {
- currentHRNSet.add(hrnID);
- }
- }
-
- // handle reachabilitySet
- HashSet<TokenTupleSet> currentRSet=currentStallSite.getReachabilitySet();
- HashSet<TokenTupleSet> newRSet=newStallSite.getReachabilitySet();
- Iterator<TokenTupleSet> ttsIter=newRSet.iterator();
- while(ttsIter.hasNext()){
- TokenTupleSet tokenTupleSet=(TokenTupleSet) ttsIter.next();
- currentRSet.add(tokenTupleSet);
- }
-// ReachabilitySet currentRSet = currentStallSite.getReachabilitySet();
-// ReachabilitySet newRSet = newStallSite.getReachabilitySet();
-// Iterator<TokenTupleSet> ttsIter = newRSet.iterator();
-// while (ttsIter.hasNext()) {
-// TokenTupleSet tokenTupleSet = (TokenTupleSet) ttsIter.next();
-// currentRSet.add(tokenTupleSet);
-// }
-
- //handle allocationsite
- HashSet<AllocationSite> currentAloc=currentStallSite.getAllocationSiteSet();
- HashSet<AllocationSite> newAloc=newStallSite.getAllocationSiteSet();
- currentAloc.addAll(newAloc);
-
- // handle related stall tags
- HashSet<StallTag> currentStallTagSet=currentStallSite.getStallTagSet();
- HashSet<StallTag> newStallTagSet=newStallSite.getStallTagSet();
- currentStallTagSet.addAll(newStallTagSet);
-
- // reaching param idxs
- HashSet<Integer> currentParamIdx=currentStallSite.getCallerParamIdxSet();
- HashSet<Integer> newParamIdx=newStallSite.getCallerParamIdxSet();
- currentParamIdx.addAll(newParamIdx);
-
- StallSite merged=new StallSite(currentEffectSet, currentHRNSet,
- currentRSet, currentAloc, currentStallTagSet,currentParamIdx);
-
-
- getStallMap()
- .put(
- key,
- merged);
-
- }
-
- // merge edge mapping
-
- Hashtable<ReferenceEdge, HashSet<StallTag>> newStallEdgeMapping=newConflictsMap.getStallEdgeMap();
- Set<ReferenceEdge> edgeSet=newStallEdgeMapping.keySet();
-
- for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
- ReferenceEdge stallEdge = (ReferenceEdge) iterator.next();
- HashSet<StallTag> newStallTagSet=newStallEdgeMapping.get(stallEdge);
- HashSet<StallTag>currentStallTagSet=getStallEdgeMap().get(stallEdge);
-
- if(currentStallTagSet==null){
- currentStallTagSet=new HashSet<StallTag>();
- }
- currentStallTagSet.addAll(newStallTagSet);
- getStallEdgeMap().put(stallEdge,currentStallTagSet);
- }
-
- }
-
- public Set<Long> getAllocationSiteIDSetofStallSite() {
-
- HashSet<Long> returnSet=new HashSet<Long>();
-
- Enumeration<StallSite> stallSiteEnum=stallMap.elements();
- while (stallSiteEnum.hasMoreElements()) {
- StallSite stallSite = (StallSite) stallSiteEnum.nextElement();
- HashSet<HeapRegionNode> hrnSet=stallSite.getHRNSet();
- for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
- HeapRegionNode hrn = (HeapRegionNode) iterator.next();
- // allocSiteIDSet.add(hrn.getGloballyUniqueIdentifier());
- returnSet.add(new Long(hrn
- .getGloballyUniqueIntegerIdentifier()));
- }
- }
- return returnSet;
-
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof ParentChildConflictsMap)) {
- return false;
- }
-
- ParentChildConflictsMap in = (ParentChildConflictsMap) o;
-
- if ( accessibleMap.equals(in.getAccessibleMap())
- && stallMap.equals(in.getStallMap()) && isAfterSESE()==in.isAfterSESE()) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public String toString() {
- return "ParentChildConflictsMap [accessibleMap=" + accessibleMap
- + ", stallMap="
- + stallMap + "]";
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import Analysis.OwnershipAnalysis.ReachabilitySet;
-import IR.TypeDescriptor;
-
-public class SESEEffectsKey {
-
- private String fd;
- private TypeDescriptor td;
- private Integer hrnId;
- private String hrnUniqueId;
- private ReachabilitySet rset;
- private boolean wStrong=false;
-
- public SESEEffectsKey(String fd, TypeDescriptor td, Integer hrnId, String hrnUniqueId) {
- this.fd = fd;
- this.td = td;
- this.hrnId = hrnId;
- this.hrnUniqueId=hrnUniqueId;
- }
-
- public void setRSet(ReachabilitySet rset){
- this.rset=rset;
- }
-
- public ReachabilitySet getRSet(){
- return rset;
- }
-
- public void setStrong(boolean wStrong){
- this.wStrong=wStrong;
- }
-
- public boolean isStrong(){
- return wStrong;
- }
-
- public String getFieldDescriptor() {
- return fd;
- }
-
- public TypeDescriptor getTypeDescriptor() {
- return td;
- }
-
- public Integer getHRNId() {
- return hrnId;
- }
-
- public String getHRNUniqueId(){
- return hrnUniqueId;
- }
-
- public String toString() {
- return "(" + td + ")" + fd + "#" + hrnId+":"+hrnUniqueId;
- }
-
- public int hashCode() {
-
- int hash = 1;
-
- if (fd != null) {
- hash = hash * 31 + fd.hashCode();
- }
-
- if (td != null) {
- hash += td.getSymbol().hashCode();
- }
-
- if (hrnId != null) {
- hash += hrnId.hashCode();
- }
-
- return hash;
-
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof SESEEffectsKey)) {
- return false;
- }
-
- SESEEffectsKey in = (SESEEffectsKey) o;
-
- if (fd.equals(in.getFieldDescriptor())
- && td.getSymbol().equals(in.getTypeDescriptor().getSymbol())
- && hrnId.equals(in.getHRNId())) {
- return true;
- } else {
- return false;
- }
-
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.io.StringWriter;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-import Analysis.OwnershipAnalysis.ReferenceEdge;
-import IR.Flat.TempDescriptor;
-
-public class SESEEffectsSet {
- private Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> readTable;
- private Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> writeTable;
- private Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> strongUpdateTable;
- private Hashtable<TempDescriptor, Integer> mapTempDescToInVarIdx;
- private Hashtable<ReferenceEdge, Integer> mapEdgeToTaint;
-
- public SESEEffectsSet() {
- readTable = new Hashtable<TempDescriptor, HashSet<SESEEffectsKey>>();
- writeTable = new Hashtable<TempDescriptor, HashSet<SESEEffectsKey>>();
- strongUpdateTable = new Hashtable<TempDescriptor, HashSet<SESEEffectsKey>>();
- mapTempDescToInVarIdx = new Hashtable<TempDescriptor, Integer>();
- mapEdgeToTaint = new Hashtable<ReferenceEdge, Integer>();
- }
-
- public int getTaint(ReferenceEdge edge){
- int taint=0;
- if(mapEdgeToTaint.containsKey(edge)){
- taint=mapEdgeToTaint.get(edge).intValue();
- }
- return taint;
- }
-
- public void mapEdgeToTaint(ReferenceEdge edge, int newTaint){
- int taint=0;
- if(mapEdgeToTaint.containsKey(edge)){
- taint=mapEdgeToTaint.get(edge).intValue();
- }
- taint=taint | newTaint;
- mapEdgeToTaint.put(edge, new Integer(taint));
- }
-
- public void setInVarIdx(int idx, TempDescriptor td){
- mapTempDescToInVarIdx.put(td,new Integer(idx));
- }
-
- public int getInVarIdx(TempDescriptor td){
- Integer idx=mapTempDescToInVarIdx.get(td);
- if(idx==null){
- // if invar is from SESE placeholder, it is going to be ignored.
- return -1;
- }
- return idx.intValue();
- }
-
- public Hashtable<TempDescriptor, Integer> getMapTempDescToInVarIdx(){
- return mapTempDescToInVarIdx;
- }
-
- public void addReadingVar(TempDescriptor td, SESEEffectsKey access) {
- HashSet<SESEEffectsKey> aSet = readTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<SESEEffectsKey>();
- }
-
- aSet.add(access);
- readTable.put(td, aSet);
- }
-
- public void addReadingEffectsSet(TempDescriptor td,
- HashSet<SESEEffectsKey> newSet) {
-
- if (newSet != null) {
- HashSet<SESEEffectsKey> aSet = readTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<SESEEffectsKey>();
- }
- aSet.addAll(newSet);
- readTable.put(td, aSet);
- }
-
- }
-
- public void addWritingEffectsSet(TempDescriptor td,
- HashSet<SESEEffectsKey> newSet) {
-
- if (newSet != null) {
- HashSet<SESEEffectsKey> aSet = writeTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<SESEEffectsKey>();
- }
- aSet.addAll(newSet);
- writeTable.put(td, aSet);
- }
-
- }
-
- public Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> getReadTable() {
- return readTable;
- }
-
- public Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> getWriteTable() {
- return writeTable;
- }
-
- public Hashtable<TempDescriptor, HashSet<SESEEffectsKey>> getStrongUpdateTable() {
- return strongUpdateTable;
- }
-
- public void addWritingVar(TempDescriptor td, SESEEffectsKey access) {
- HashSet<SESEEffectsKey> aSet = writeTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<SESEEffectsKey>();
- }
- aSet.add(access);
- writeTable.put(td, aSet);
- }
-
- public void addStrongUpdateVar(TempDescriptor td, SESEEffectsKey access) {
- HashSet<SESEEffectsKey> aSet = strongUpdateTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<SESEEffectsKey>();
- }
- aSet.add(access);
- strongUpdateTable.put(td, aSet);
- }
-
- public Set<SESEEffectsKey> getReadingSet(TempDescriptor td) {
- return readTable.get(td);
- }
-
- public Set<SESEEffectsKey> getWritingSet(TempDescriptor td) {
- return writeTable.get(td);
- }
-
- public Set<SESEEffectsKey> getStrongUpdateSet(TempDescriptor td){
- return strongUpdateTable.get(td);
- }
-
- public String printSet() {
-
- StringWriter writer=new StringWriter();
-
- Set<TempDescriptor> keySet = readTable.keySet();
- Iterator<TempDescriptor> iter = keySet.iterator();
- while (iter.hasNext()) {
- TempDescriptor td = iter.next();
- Set<SESEEffectsKey> effectSet = readTable.get(td);
- String keyStr = "{";
- if (effectSet != null) {
- Iterator<SESEEffectsKey> effectIter = effectSet.iterator();
- while (effectIter.hasNext()) {
- SESEEffectsKey key = effectIter.next();
- keyStr += " " + key;
- }
- }
- keyStr+=" }";
- writer.write("Live-in Var " + td + " Read=" + keyStr+"\n");
- }
-
- keySet = writeTable.keySet();
- iter = keySet.iterator();
- while (iter.hasNext()) {
- TempDescriptor td = iter.next();
- Set<SESEEffectsKey> effectSet = writeTable.get(td);
- String keyStr = "{";
- if (effectSet != null) {
- Iterator<SESEEffectsKey> effectIter = effectSet.iterator();
- while (effectIter.hasNext()) {
- SESEEffectsKey key = effectIter.next();
- keyStr += " " + key;
- }
- }
- keyStr+=" }";
- writer.write("Live-in Var " + td + " Write=" + keyStr+"\n");
- }
-
- keySet = strongUpdateTable.keySet();
- iter = keySet.iterator();
- while (iter.hasNext()) {
- TempDescriptor td = iter.next();
- Set<SESEEffectsKey> effectSet = strongUpdateTable.get(td);
- String keyStr = "{";
- if (effectSet != null) {
- Iterator<SESEEffectsKey> effectIter = effectSet.iterator();
- while (effectIter.hasNext()) {
- SESEEffectsKey key = effectIter.next();
- keyStr += " " + key;
- }
- }
- keyStr+=" }";
- writer.write("Live-in Var " + td + " StrongUpdate=" + keyStr+"\n");
- }
-
- return writer.toString();
-
- }
-
- public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof SESEEffectsSet)) {
- return false;
- }
-
- SESEEffectsSet in = (SESEEffectsSet) o;
-
- if (getReadTable().equals(in.getReadTable())
- && getWriteTable().equals(in.getWriteTable())
- && getStrongUpdateTable().equals(in.getStrongUpdateTable())) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public int hashCode() {
- int hash = 1;
-
- hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31 +getStrongUpdateTable().hashCode();
-
- return hash;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class SESELock {
-
- private HashSet<ConflictNode> conflictNodeSet;
- private HashSet<ConflictEdge> conflictEdgeSet;
- private HashMap<ConflictNode, Integer> nodeTypeMap;
- private int id;
-
- public SESELock(){
- conflictNodeSet=new HashSet<ConflictNode>();
- conflictEdgeSet=new HashSet<ConflictEdge>();
- nodeTypeMap=new HashMap<ConflictNode, Integer>();
- }
-
- public void addConflictNode(ConflictNode node, int type){
- conflictNodeSet.add(node);
- setNodeType(node, type);
- }
-
- public void setNodeType(ConflictNode node, int type){
- nodeTypeMap.put(node, new Integer(type));
- }
-
- public int getNodeType(ConflictNode node){
- return nodeTypeMap.get(node).intValue();
- }
-
- public void addConflictEdge(ConflictEdge e){
- conflictEdgeSet.add(e);
- }
-
- public boolean containsConflictEdge(ConflictEdge e){
- return conflictEdgeSet.contains(e);
- }
-
- public HashSet<ConflictNode> getConflictNodeSet(){
- return conflictNodeSet;
- }
-
- public boolean isWriteNode(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 true;
- }
- }
- } else {
- LiveInNode liveInNode = (LiveInNode) node;
- Set<SESEEffectsKey> writeEffectSet = liveInNode
- .getWriteEffectsSet();
- if (writeEffectSet != null && writeEffectSet.size() > 0) {
- return true;
- }
- }
-
- return false;
-
- }
-
-
- public boolean hasSelfCoarseEdge(ConflictNode node){
-
- HashSet<ConflictEdge> set=node.getEdgeSet();
- for (Iterator iterator = set.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
- if(conflictEdge.getType()!=ConflictEdge.FINE_GRAIN_EDGE&&conflictEdge.getVertexU()==conflictEdge.getVertexV()){
- return true;
- }
- }
- return false;
- }
-
- private boolean isFineNode(ConflictNode node){
-
- if(node.getType()<4){
- return true;
- }
-
- return false;
-
- }
-
- public ConflictNode getNewNodeCoarseConnectedWithGroup(ConflictEdge newEdge) {
-
- // check whether or not the new node has a fine-grained edges to all
- // current nodes.
-
- ConflictNode newNode;
- if (conflictNodeSet.contains(newEdge.getVertexU())) {
- newNode = newEdge.getVertexV();
- } else if(conflictNodeSet.contains(newEdge.getVertexV())) {
- newNode = newEdge.getVertexU();
- }else{
- return null;
- }
-
- int count = 0;
- HashSet<ConflictEdge> edgeSet = newNode.getEdgeSet();
- for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
- if (!conflictEdge.getVertexU().equals(newNode)
- && conflictNodeSet.contains(conflictEdge.getVertexU()) && isFineNode(conflictEdge.getVertexU()) ) {
- count++;
- } else if (!conflictEdge.getVertexV().equals(newNode)
- && conflictNodeSet.contains(conflictEdge.getVertexV()) && isFineNode(conflictEdge.getVertexU()) ) {
- count++;
- }
- }
-
- if (count == conflictNodeSet.size()) {
- // connected to all current nodes in group
- return newNode;
- }
-
- return null;
-
- }
-
-
- public ConflictNode getNewNodeConnectedWithGroup(ConflictEdge newEdge) {
-
- // check whether or not the new node has a fine-grained edges to all
- // current nodes.
-
- ConflictNode newNode;
- if (conflictNodeSet.contains(newEdge.getVertexU())) {
- newNode = newEdge.getVertexV();
- } else if(conflictNodeSet.contains(newEdge.getVertexV())){
- newNode = newEdge.getVertexU();
- }else{
- return null;
- }
-
- int count = 0;
- HashSet<ConflictEdge> edgeSet = newNode.getEdgeSet();
- for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
- ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
- if (!conflictEdge.getVertexU().equals(newNode)
- && conflictNodeSet.contains(conflictEdge.getVertexU())) {
- count++;
- } else if (!conflictEdge.getVertexV().equals(newNode)
- && conflictNodeSet.contains(conflictEdge.getVertexV())) {
- count++;
- }
- }
-
- if (count == conflictNodeSet.size()) {
- // connected to all current nodes in group
- return newNode;
- }
-
- return null;
-
- }
-
- 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+"::"+getNodeType(node);
- }
-
- return rtr;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.Flat.FlatNode;
-import IR.Flat.FlatSESEEnterNode;
-
-public class SESESummary {
-
- private FlatNode currentParent;
- private FlatNode currentSESE;
-
- public SESESummary(FlatNode currentParent, FlatNode currentChild) {
- this.currentParent = currentParent;
- this.currentSESE = currentChild;
- }
-
- public FlatNode getCurrentParent() {
- return currentParent;
- }
-
- public FlatNode getCurrentSESE() {
- return currentSESE;
- }
-
- public void setCurrentParent(FlatNode parent) {
- currentParent = parent;
- }
-
- public void setCurrentSESE(FlatNode current) {
- currentSESE = current;
- }
-
- public String toString() {
- String rtn;
-
- rtn = "parent=" + currentParent;
- if (currentSESE instanceof FlatSESEEnterNode) {
- rtn += " current="
- + ((FlatSESEEnterNode) currentSESE).getPrettyIdentifier();
- } else {
- rtn += " current=" + currentSESE;
- }
-
- return rtn;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import Analysis.CallGraph.*;
-
-public class SESETree {
- State state;
- TypeUtil typeutil;
- CallGraph callgraph;
- SESENode root;
- Hashtable<MethodDescriptor, Set<SESENode>> toanalyze=new Hashtable<MethodDescriptor,Set<SESENode>>();
- Hashtable<MethodDescriptor, Set<SESENode>> discovered=new Hashtable<MethodDescriptor,Set<SESENode>>();
- Hashtable<FlatSESEEnterNode, SESENode> sesemap=new Hashtable<FlatSESEEnterNode, SESENode>();
-
- public SESETree(State state, TypeUtil typeutil, CallGraph callgraph) {
- this.state=state;
- this.typeutil=typeutil;
- this.callgraph=callgraph;
- root=new SESENode(null, true);
- doAnalysis();
- }
-
- public SESENode getRoot() {
- return root;
- }
-
- public void doAnalysis() {
- MethodDescriptor main=typeutil.getMain();
- add(toanalyze, main, root);
- add(discovered, main, root);
-
- while(!toanalyze.isEmpty()) {
- MethodDescriptor md=toanalyze.keySet().iterator().next();
- Set<SESENode> context=toanalyze.get(md);
- toanalyze.remove(md);
- FlatMethod fm=state.getMethodFlat(md);
- analyzeMethod(fm, context);
- }
- }
-
- public SESENode getSESE(FlatSESEEnterNode enter) {
- if (!sesemap.containsKey(enter)) {
- sesemap.put(enter, new SESENode(enter, false));
- }
- return sesemap.get(enter);
- }
-
- public Set<SESENode> getSESE(MethodDescriptor md) {
- return discovered.get(md);
- }
-
- public Hashtable<FlatNode, Stack<SESENode>> analyzeMethod(FlatMethod fm) {
- return analyzeMethod(fm, null);
- }
-
- private Hashtable<FlatNode, Stack<SESENode>> analyzeMethod(FlatMethod fm, Set<SESENode> context) {
- Hashtable<FlatNode, Stack<SESENode>> stacks=new Hashtable<FlatNode, Stack<SESENode>> ();
- stacks.put(fm, new Stack<SESENode>());
- HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
- HashSet<FlatNode> fndiscovered=new HashSet<FlatNode>();
- tovisit.add(fm);
- fndiscovered.add(fm);
- while(!tovisit.isEmpty()) {
- FlatNode fn=tovisit.iterator().next();
- tovisit.remove(fn);
- Stack<SESENode> instack=stacks.get(fm);
- switch(fn.kind()) {
- case FKind.FlatCall: {
- if (context==null)
- break;
- FlatCall fc=(FlatCall)fn;
- //handle method call
- Set<SESENode> parents;
- if (instack.isEmpty()) {
- parents=context;
- } else {
- parents=new HashSet<SESENode>();
- parents.add(instack.peek());
- }
- for(Iterator<SESENode> parentit=parents.iterator();parentit.hasNext();) {
- SESENode parentsese=parentit.next();
- for(Iterator<MethodDescriptor> calleeit=(fc.getThis()==null?callgraph.getMethods(fc.getMethod()):callgraph.getMethods(fc.getMethod(), fc.getThis().getType())).iterator(); calleeit.hasNext();) {
- MethodDescriptor md=calleeit.next();
- if (add(discovered,md, parentsese)) {
- add(toanalyze, md, parentsese);
- }
- }
- }
- break;
- }
- case FKind.FlatSESEEnterNode: {
- FlatSESEEnterNode enter=(FlatSESEEnterNode)fn;
-
- if (context!=null) {
- Set<SESENode> parents;
- if (instack.isEmpty()) {
- parents=context;
- } else {
- parents=new HashSet<SESENode>();
- parents.add(instack.peek());
- }
- SESENode sese=getSESE(enter);
- for(Iterator<SESENode> parentit=parents.iterator();parentit.hasNext();) {
- SESENode parentsese=parentit.next();
- parentsese.addChild(sese);
- }
- }
- Stack<SESENode> copy=(Stack<SESENode>)instack.clone();
- copy.push(sese);
- instack=copy;
- break;
- }
- case FKind.FlatSESEExitNode: {
- FlatSESEExitNode exit=(FlatSESEExitNode)fn;
- Stack<SESENode> copy=(Stack<SESENode>)instack.clone();
- copy.pop();
- instack=copy;
- break;
- }
- }
- for(int i=0;i<fn.numNext();i++) {
- FlatNode fnext=fn.getNext(i);
- if (!fndiscovered.contains(fnext)) {
- fndiscovered.add(fnext);
- tovisit.add(fnext);
- stacks.put(fnext, instack);
- }
- }
- }
- return stacks;
- }
-
- public static boolean add(Hashtable<MethodDescriptor, Set<SESENode>> discovered, MethodDescriptor md, SESENode sese) {
- if (!discovered.containsKey(md))
- discovered.put(md, new HashSet<SESENode>());
- if (discovered.get(md).contains(sese))
- return false;
- discovered.get(md).add(sese);
- return true;
- }
-
-
- class SESENode {
- boolean isRoot;
- HashSet<SESENode> children;
- HashSet<SESENode> parents;
-
- FlatSESEEnterNode node;
- SESENode(FlatSESEEnterNode node, boolean isRoot) {
- children=new HashSet<SESENode>();
- this.isRoot=isRoot;
- this.node=node;
- }
-
- public boolean isLeaf() {
- return children.isEmpty();
- }
-
- protected void addChild(SESENode child) {
- children.add(child);
- child.parents.add(this);
- }
-
- public Set<SESENode> getParents() {
- return parents;
- }
-
- public Set<SESENode> getChildren() {
- return children;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-public class SESEWaitingQueue {
- public static final int NORMAL= 0; // enqueue all stuff.
- public static final int EXCEPTION= 1; // dynamically decide whether a waiting element is enqueued or not.
-
- private HashMap<Integer, Set<WaitingElement>>mapWaitingElement;
- private HashMap<Integer, Integer>mapType;
-
- public SESEWaitingQueue(){
- mapWaitingElement=new HashMap<Integer, Set<WaitingElement>>();
- mapType=new HashMap<Integer, Integer>();
- }
-
- public void setType(int queueID, int type){
- mapType.put(new Integer(queueID), new Integer(type));
- }
-
- public int getType(int queueID){
- Integer type=mapType.get(new Integer(queueID));
- if(type==null){
- return SESEWaitingQueue.NORMAL;
- }else{
- return type.intValue();
- }
- }
-
- public void setWaitingElementSet(int queueID, Set<WaitingElement> set){
- mapWaitingElement.put(new Integer(queueID), set);
- }
-
- public Set<WaitingElement> getWaitingElementSet(int queueID){
- return mapWaitingElement.get(new Integer(queueID));
- }
-
- public Set<Integer> getQueueIDSet(){
- return mapWaitingElement.keySet();
- }
-
- public int getWaitingElementSize(){
- int size=0;
- Set<Integer> keySet=mapWaitingElement.keySet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- Integer key = (Integer) iterator.next();
- size+=mapWaitingElement.get(key).size();
- }
- return size;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-public class SESEandAgePair {
-
- private FlatSESEEnterNode sese;
- private Integer age;
-
- public SESEandAgePair( FlatSESEEnterNode sese,
- Integer age ) {
- this.sese = sese;
- this.age = age;
- }
-
- public FlatSESEEnterNode getSESE() {
- return sese;
- }
-
- public Integer getAge() {
- return age;
- }
-
- public boolean equals( Object o ) {
- if( o == null ) {
- return false;
- }
-
- if( !(o instanceof SESEandAgePair) ) {
- return false;
- }
-
- SESEandAgePair p = (SESEandAgePair) o;
-
- return age.equals( p.age ) &&
- sese.equals( p.sese );
- }
-
- public int hashCode() {
- return (sese.hashCode() << 2)*(age.hashCode() << 5);
- }
-
-
- public String toString() {
- return "SESE_"+
- sese.getPrettyIdentifier()+
- sese.getIdentifier()+
- "_"+
- age;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-public class SVKey {
-
- private FlatSESEEnterNode sese;
- private TempDescriptor var;
-
- public SVKey( FlatSESEEnterNode sese,
- TempDescriptor var ) {
- this.sese = sese;
- this.var = var;
- }
-
- public FlatSESEEnterNode getSESE() {
- return sese;
- }
-
- public TempDescriptor getVar() {
- return var;
- }
-
- public boolean equals( Object o ) {
- if( o == null ) {
- return false;
- }
-
- if( !(o instanceof SVKey) ) {
- return false;
- }
-
- SVKey k = (SVKey) o;
-
- return var.equals( k.var ) &&
- sese.equals( k.sese );
- }
-
- public int hashCode() {
- return (sese.hashCode() << 2)*(var.hashCode() << 5);
- }
-
-
- public String toString() {
- return "key["+sese.getPrettyIdentifier()+", "+var+"]";
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import Analysis.OwnershipAnalysis.AllocationSite;
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import Analysis.OwnershipAnalysis.TokenTupleSet;
-import IR.Flat.FlatNode;
-import IR.Flat.TempDescriptor;
-
-public class StallSite {
-
- public static final Integer READ_EFFECT = new Integer(1);
- public static final Integer WRITE_EFFECT = new Integer(2);
-
- private HashSet<Effect> effectSet;
- private HashSet<HeapRegionNode> hrnSet;
- private HashSet<AllocationSite> allocationSiteSet;
-// private ReachabilitySet reachabilitySet;
- HashSet<TokenTupleSet> reachabilitySet;
- private HashSet<StallTag> stallTagSet;
- private TempDescriptor tdA;
-
- // if stall site is caller's parameter heap regtion, store its parameter idx
- // for further analysis
- private HashSet<Integer> callerParamIdxSet;
-
- public StallSite() {
- effectSet = new HashSet<Effect>();
- hrnSet = new HashSet<HeapRegionNode>();
- reachabilitySet = new HashSet<TokenTupleSet>();
- allocationSiteSet = new HashSet<AllocationSite>();
- stallTagSet = new HashSet<StallTag>();
- callerParamIdxSet = new HashSet<Integer>();
- }
-
- public StallSite(HashSet<HeapRegionNode> hrnSet, StallTag tag) {
-
- this();
-
- setHeapRegionNodeSet(hrnSet);
- stallTagSet.add(tag);
-
- for (Iterator iterator = hrnSet.iterator(); iterator.hasNext();) {
- HeapRegionNode heapRegionNode = (HeapRegionNode) iterator.next();
- setAllocationSite(heapRegionNode.getAllocationSite());
- }
- }
-
- public StallSite(HashSet<Effect> effectSet, HashSet<HeapRegionNode> hrnSet,
- HashSet<TokenTupleSet> rechabilitySet, HashSet<AllocationSite> alocSet,
- HashSet<StallTag> tagSet, HashSet<Integer> paramIdx) {
- this();
- this.effectSet.addAll(effectSet);
- this.hrnSet.addAll(hrnSet);
- this.reachabilitySet = rechabilitySet;
- this.allocationSiteSet.addAll(alocSet);
- this.stallTagSet.addAll(tagSet);
- this.callerParamIdxSet.addAll(paramIdx);
- }
-
- public void addTokenTupleSet(TokenTupleSet newSet){
- reachabilitySet.add(newSet);
- }
-
- public HashSet<Integer> getCallerParamIdxSet() {
- return callerParamIdxSet;
- }
-
- public void addCallerParamIdxSet(Set<Integer> newParamSet) {
- if (newParamSet != null) {
- callerParamIdxSet.addAll(newParamSet);
- }
- }
-
- public void setStallTagSet(HashSet<StallTag> tags) {
- stallTagSet = tags;
- }
-
- public void addRelatedStallTag(StallTag stallTag) {
- stallTagSet.add(stallTag);
- }
-
- public void setAllocationSite(AllocationSite allocationSite) {
- if (allocationSite != null) {
- allocationSiteSet.add(allocationSite);
- }
- }
-
- public void setHeapRegionNodeSet(HashSet<HeapRegionNode> newSet) {
- hrnSet.addAll(newSet);
- }
-
- public HashSet<AllocationSite> getAllocationSiteSet() {
- return allocationSiteSet;
- }
-
- public void addEffect(String type, String field, Integer effect) {
-
- Effect e = new Effect(type, field, effect, stallTagSet);
- effectSet.add(e);
- }
-
- public HashSet<Effect> getEffectSet() {
- return effectSet;
- }
-
- public HashSet<HeapRegionNode> getHRNSet() {
- return hrnSet;
- }
-
- public HashSet<TokenTupleSet> getReachabilitySet() {
- return reachabilitySet;
- }
-
- public HashSet<StallTag> getStallTagSet() {
- return stallTagSet;
- }
-
- public StallSite copy() {
-
- StallSite copy = new StallSite(effectSet, hrnSet, reachabilitySet,
- allocationSiteSet, stallTagSet, callerParamIdxSet);
- return copy;
-
- }
-
- public void setTdA(TempDescriptor tdA){
- this.tdA=tdA;
- }
-
- public TempDescriptor getTdA(){
- return tdA;
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof StallSite)) {
- return false;
- }
-
- StallSite in = (StallSite) o;
-
- if (allocationSiteSet.equals(in.getAllocationSiteSet())
- && stallTagSet.equals(in.getStallTagSet())
- && effectSet.equals(in.getEffectSet())
- && hrnSet.equals(in.getHRNSet())
- && reachabilitySet.equals(in.getReachabilitySet())) {
- return true;
- } else {
- return false;
- }
-
- }
-
- @Override
- public String toString() {
- return "StallSite [allocationSiteSet=" + allocationSiteSet
- + ", callerParamIdxSet=" + callerParamIdxSet + ", effectSet="
- + effectSet + ", hrnSet=" + hrnSet + ", rechabilitySet="
- + reachabilitySet + ", stallTagSet=" + stallTagSet + "]";
- }
-
-}
-
-class StallTag {
-
- private FlatNode fn;
-
- public StallTag(FlatNode fn) {
- this.fn = fn;
- }
-
- public FlatNode getKey() {
- return fn;
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof StallTag)) {
- return false;
- }
-
- StallTag in = (StallTag) o;
-
- if (getKey().equals(in.getKey())) {
- return true;
- } else {
- return false;
- }
-
- }
-
-}
-
-class Effect {
-
- private String field;
- private String type;
- private Integer effect;
- private HashSet<StallTag> stallTagSet;
-
- public Effect() {
- stallTagSet = new HashSet<StallTag>();
- }
-
- public Effect(String type, String field, Integer effect,
- HashSet<StallTag> tagSet) {
- this();
- this.type = type;
- this.field = field;
- this.effect = effect;
- stallTagSet.addAll(tagSet);
- }
-
- public String getField() {
- return field;
- }
-
- public String getType() {
- return type;
- }
-
- public Integer getEffectType() {
- return effect;
- }
-
- public HashSet<StallTag> getStallTagSet() {
- return stallTagSet;
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof Effect)) {
- return false;
- }
-
- Effect in = (Effect) o;
-
- if (stallTagSet.equals(in.getStallTagSet())
- && type.equals(in.getType()) && field.equals(in.getField())
- && effect.equals(in.getEffectType())) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public String toString() {
- return "Effect [effect=" + effect + ", field=" + field
- + ", stallTagSet=" + stallTagSet + ", type=" + type + "]";
- }
-
-}
\ No newline at end of file
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import Analysis.OwnershipAnalysis.HeapRegionNode;
-import IR.Flat.TempDescriptor;
-
-public class StallSiteNode extends ConflictNode {
-
- protected StallSite stallSite;
-
- public StallSiteNode(String id, TempDescriptor td, StallSite stallSite,
- Set<Set> reachabilitySet) {
- this.id = id;
- this.td = td;
- this.stallSite = stallSite;
- this.reachabilitySet = reachabilitySet;
- }
-
- public HashSet<HeapRegionNode> getHRNSet() {
- return stallSite.getHRNSet();
- }
-
- public StallSite getStallSite() {
- return stallSite;
- }
-
- public String toString(){
- String str="StallSiteNode "+id +" type="+type;
- return str;
- }
-
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-// the reason for this class is to allow a VariableSourceToken
-// to be null in some circumstances
-
-public class VSTWrapper {
- public VariableSourceToken vst;
-
- public VSTWrapper() {
- vst = null;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-// This class formerly had lazy consistency properties, but
-// it is being changed so that the full set and the extra
-// hash tables to access the full set efficiently by different
-// elements will be consistent after EVERY operation. Also,
-// a consistent assert method allows a debugger to ask whether
-// an operation has produced an inconsistent VarSrcTokTable.
-
-// in an effort to make sure operations keep the table consistent,
-// all public methods that are also used by other methods for
-// intermediate results (add and remove are used in other methods)
-// there should be a public version that calls the private version
-// so consistency is checked after public ops, but not private ops
-public class VarSrcTokTable {
-
- // a set of every token in the table
- private HashSet<VariableSourceToken> trueSet;
-
- // these hashtables provide an efficient retreival from the true set
- private Hashtable< TempDescriptor, Set<VariableSourceToken> > var2vst;
- private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;
- private Hashtable< SVKey, Set<VariableSourceToken> > sv2vst;
-
- // maximum age from aging operation
- private static final Integer MAX_AGE = new Integer( 2 );
-
- public static final Integer SrcType_READY = new Integer( 34 );
- public static final Integer SrcType_STATIC = new Integer( 35 );
- public static final Integer SrcType_DYNAMIC = new Integer( 36 );
-
-
- public VarSrcTokTable() {
- trueSet = new HashSet<VariableSourceToken>();
-
- sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();
- var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();
- sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();
-
- assertConsistency();
- }
-
-
- // make a deep copy of the in table
- public VarSrcTokTable( VarSrcTokTable in ) {
- this();
- merge( in );
- assertConsistency();
- }
-
-
- public void add( VariableSourceToken vst ) {
- addPrivate( vst );
- assertConsistency();
- }
-
- private void addPrivate( VariableSourceToken vst ) {
-
- // make sure we aren't clobbering anything!
- if( trueSet.contains( vst ) ) {
- // if something with the same hashcode is in the true set, they might
- // have different reference variable sets because that set is not considered
- // in a token's equality, so make sure we smooth that out right here
- Iterator<VariableSourceToken> vstItr = trueSet.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vstAlready = vstItr.next();
-
- if( vstAlready.equals( vst ) ) {
-
- // take out the one that is in (we dont' want collisions in
- // any of the other hash map sets either)
- removePrivate( vstAlready );
-
- // combine reference variable sets
- vst.getRefVars().addAll( vstAlready.getRefVars() );
-
- // now jump back as we are adding in a brand new token
- break;
- }
- }
- }
-
- trueSet.add( vst );
-
- Set<VariableSourceToken> s;
-
- s = sese2vst.get( vst.getSESE() );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- sese2vst.put( vst.getSESE(), s );
-
- Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();
- while( refVarItr.hasNext() ) {
- TempDescriptor refVar = refVarItr.next();
- s = var2vst.get( refVar );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- var2vst.put( refVar, s );
-
- SVKey key = new SVKey( vst.getSESE(), refVar );
- s = sv2vst.get( key );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- }
- s.add( vst );
- sv2vst.put( key, s );
- }
- }
-
- public void addAll( Set<VariableSourceToken> s ) {
- Iterator<VariableSourceToken> itr = s.iterator();
- while( itr.hasNext() ) {
- addPrivate( itr.next() );
- }
- assertConsistency();
- }
-
-
- public Set<VariableSourceToken> get() {
- return trueSet;
- }
-
- public Set<VariableSourceToken> get( FlatSESEEnterNode sese ) {
- Set<VariableSourceToken> s = sese2vst.get( sese );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- sese2vst.put( sese, s );
- }
- return s;
- }
-
- public Set<VariableSourceToken> get( TempDescriptor refVar ) {
- Set<VariableSourceToken> s = var2vst.get( refVar );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- var2vst.put( refVar, s );
- }
- return s;
- }
-
- public Set<VariableSourceToken> get( FlatSESEEnterNode sese,
- TempDescriptor refVar ) {
- SVKey key = new SVKey( sese, refVar );
- Set<VariableSourceToken> s = sv2vst.get( key );
- if( s == null ) {
- s = new HashSet<VariableSourceToken>();
- sv2vst.put( key, s );
- }
- return s;
- }
-
- public Set<VariableSourceToken> get( FlatSESEEnterNode sese,
- Integer age ) {
-
- HashSet<VariableSourceToken> s0 = (HashSet<VariableSourceToken>) sese2vst.get( sese );
- if( s0 == null ) {
- s0 = new HashSet<VariableSourceToken>();
- sese2vst.put( sese, s0 );
- }
-
- Set<VariableSourceToken> s = (Set<VariableSourceToken>) s0.clone();
- Iterator<VariableSourceToken> sItr = s.iterator();
- while( sItr.hasNext() ) {
- VariableSourceToken vst = sItr.next();
- if( !vst.getAge().equals( age ) ) {
- s.remove( vst );
- }
- }
-
- return s;
- }
-
-
- // merge now makes a deep copy of incoming stuff because tokens may
- // be modified (reference var sets) by later ops that change more
- // than one table, causing inconsistency
- public void merge( VarSrcTokTable in ) {
-
- if( in == null ) {
- return;
- }
-
- Iterator<VariableSourceToken> vstItr = in.trueSet.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- this.addPrivate( vst.copy() );
- }
-
- assertConsistency();
- }
-
-
- // remove operations must leave the trueSet
- // and the hash maps consistent
- public void remove( VariableSourceToken vst ) {
- removePrivate( vst );
- assertConsistency();
- }
-
- private void removePrivate( VariableSourceToken vst ) {
- trueSet.remove( vst );
-
- Set<VariableSourceToken> s;
-
- s = get( vst.getSESE() );
- if( s != null ) { s.remove( vst ); }
-
- Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();
- while( refVarItr.hasNext() ) {
- TempDescriptor refVar = refVarItr.next();
-
- s = get( refVar );
- if( s != null ) {
- s.remove( vst );
- if( s.isEmpty() ) {
- var2vst.remove( refVar );
- }
- }
-
- s = get( vst.getSESE(), refVar );
- if( s != null ) {
- s.remove( vst );
- if( s.isEmpty() ) {
- sv2vst.remove( new SVKey( vst.getSESE(), refVar ) );
- }
- }
- }
- }
-
-
- public void remove( FlatSESEEnterNode sese ) {
- removePrivate( sese );
- assertConsistency();
- }
-
- public void removePrivate( FlatSESEEnterNode sese ) {
- Set<VariableSourceToken> s = sese2vst.get( sese );
- if( s == null ) {
- return;
- }
-
- Iterator<VariableSourceToken> itr = s.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
- removePrivate( vst );
- }
-
- sese2vst.remove( sese );
- }
-
-
- public void remove( TempDescriptor refVar ) {
- removePrivate( refVar );
- assertConsistency();
- }
-
- private void removePrivate( TempDescriptor refVar ) {
- Set<VariableSourceToken> s = var2vst.get( refVar );
- if( s == null ) {
- return;
- }
-
- Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();
-
- // iterate over tokens that this temp can reference, make a set
- // of tokens that need this temp stripped out of them
- Iterator<VariableSourceToken> itr = s.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
- Set<TempDescriptor> refVars = vst.getRefVars();
- assert refVars.contains( refVar );
- forRemoval.add( vst );
- }
-
- itr = forRemoval.iterator();
- while( itr.hasNext() ) {
-
- // here's a token marked for removal
- VariableSourceToken vst = itr.next();
- Set<TempDescriptor> refVars = vst.getRefVars();
-
- // if there was only one one variable
- // referencing this token, just take it
- // out of the table all together
- if( refVars.size() == 1 ) {
- removePrivate( vst );
- }
-
- sv2vst.remove( new SVKey( vst.getSESE(), refVar ) );
-
- refVars.remove( refVar );
- }
-
- var2vst.remove( refVar );
- }
-
-
- public void remove( FlatSESEEnterNode sese,
- TempDescriptor var ) {
-
- // don't seem to need this, don't bother maintaining
- // until its clear we need it
- assert false;
- }
-
-
- // age tokens with respect to SESE curr, where
- // any curr tokens increase age by 1
- public void age( FlatSESEEnterNode curr ) {
-
- Set<VariableSourceToken> forRemoval =
- new HashSet<VariableSourceToken>();
-
- Set<VariableSourceToken> forAddition =
- new HashSet<VariableSourceToken>();
-
- Iterator<VariableSourceToken> itr = trueSet.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
-
- if( vst.getSESE().equals( curr ) ) {
-
- // only age if the token isn't already the maximum age
- if( vst.getAge() < MAX_AGE ) {
-
- forRemoval.add( vst );
-
- forAddition.add( new VariableSourceToken( vst.getRefVars(),
- curr,
- vst.getAge() + 1,
- vst.getAddrVar()
- )
- );
- }
- }
- }
-
- itr = forRemoval.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
- remove( vst );
- }
-
- itr = forRemoval.iterator();
- while( itr.hasNext() ) {
- VariableSourceToken vst = itr.next();
- add( vst );
- }
-
- assertConsistency();
- }
-
-
- // at an SESE enter node, all ref vars in the SESE's in-set will
- // be copied into the SESE's local scope, change source to itself
- public void ownInSet( FlatSESEEnterNode curr ) {
- Iterator<TempDescriptor> inVarItr = curr.getInVarSet().iterator();
- while( inVarItr.hasNext() ) {
- TempDescriptor inVar = inVarItr.next();
-
- remove( inVar );
- assertConsistency();
-
- Set<TempDescriptor> refVars = new HashSet<TempDescriptor>();
- refVars.add( inVar );
- add( new VariableSourceToken( refVars,
- curr,
- new Integer( 0 ),
- inVar
- )
- );
- assertConsistency();
- }
- }
-
-
- // for the given SESE, change child tokens into this parent
- public void remapChildTokens( FlatSESEEnterNode curr ) {
-
- Iterator<FlatSESEEnterNode> childItr = curr.getChildren().iterator();
- if( childItr.hasNext() ) {
- FlatSESEEnterNode child = childItr.next();
-
- // set of VSTs for removal
- HashSet<VariableSourceToken> removalSet=new HashSet<VariableSourceToken>();
- // set of VSTs for additon
- HashSet<VariableSourceToken> additionSet=new HashSet<VariableSourceToken>();
-
- Iterator<VariableSourceToken> vstItr = get( child ).iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- removalSet.add(vst);
- additionSet.add(new VariableSourceToken( vst.getRefVars(),
- curr,
- new Integer( 0 ),
- vst.getAddrVar()
- ));
- }
-
- // remove( eah item in forremoval )
- vstItr = removalSet.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- remove( vst );
- }
- // add( each ite inm for additon _
- vstItr = additionSet.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- add( vst );
- }
- }
-
- assertConsistency();
- }
-
-
- // this method is called at the SESE exit of SESE 'curr'
- // if the sources for a variable written by curr can also
- // come from curr's parent or curr's siblings then we're not
- // sure that curr will actually modify the variable. There are
- // many ways to handle this, but for now, mark the variable as
- // virtually read so curr insists on having ownership of it
- // whether it ends up writing to it or not. It will always, then,
- // appear in curr's out-set.
- public Set<TempDescriptor>
- calcVirtReadsAndPruneParentAndSiblingTokens( FlatSESEEnterNode exiter,
- Set<TempDescriptor> liveVars ) {
-
- Set<TempDescriptor> virtReadSet = new HashSet<TempDescriptor>();
-
- FlatSESEEnterNode parent = exiter.getParent();
- if( parent == null ) {
- // having no parent means no siblings, too
- return virtReadSet;
- }
-
- Set<FlatSESEEnterNode> alternateSESEs = new HashSet<FlatSESEEnterNode>();
- alternateSESEs.add( parent );
- Iterator<FlatSESEEnterNode> childItr = parent.getChildren().iterator();
- while( childItr.hasNext() ) {
- FlatSESEEnterNode sibling = childItr.next();
- if( !sibling.equals( exiter ) ) {
- alternateSESEs.add( sibling );
- }
- }
-
- // VSTs to remove if they are alternate sources for exiter VSTs
- // whose variables will become virtual reads
- Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();
-
- // look at all of this SESE's VSTs at exit...
- Iterator<VariableSourceToken> vstItr = get( exiter ).iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vstExiterSrc = vstItr.next();
-
- // only interested in tokens that come from our current instance
- if( vstExiterSrc.getAge() != 0 ) {
- continue;
- }
-
- // for each variable that might come from those sources...
- Iterator<TempDescriptor> refVarItr = vstExiterSrc.getRefVars().iterator();
- while( refVarItr.hasNext() ) {
- TempDescriptor refVar = refVarItr.next();
-
- // only matters for live variables at SESE exit program point
- if( !liveVars.contains( refVar ) ) {
- continue;
- }
-
- // examine other sources for a variable...
- Iterator<VariableSourceToken> srcItr = get( refVar ).iterator();
- while( srcItr.hasNext() ) {
- VariableSourceToken vstPossibleOtherSrc = srcItr.next();
-
- if( vstPossibleOtherSrc.getSESE().equals( exiter ) &&
- vstPossibleOtherSrc.getAge() > 0
- ) {
- // this is an alternate source if its
- // an older instance of this SESE
- virtReadSet.add( refVar );
- forRemoval.add( vstPossibleOtherSrc );
-
- } else if( alternateSESEs.contains( vstPossibleOtherSrc.getSESE() ) ) {
- // this is an alternate source from parent or sibling
- virtReadSet.add( refVar );
- forRemoval.add( vstPossibleOtherSrc );
-
- } else {
- if( !vstPossibleOtherSrc.getSESE().equals( exiter ) ||
- !vstPossibleOtherSrc.getAge().equals( 0 )
- ) {
- System.out.println( "For refVar="+refVar+" at exit of "+exiter+
- ", unexpected possible variable source "+vstPossibleOtherSrc );
- assert false;
- }
- }
- }
- }
- }
-
- vstItr = forRemoval.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- remove( vst );
- }
- assertConsistency();
-
- return virtReadSet;
- }
-
-
- // get the set of VST's that come from a child
- public Set<VariableSourceToken> getChildrenVSTs( FlatSESEEnterNode curr ) {
-
- Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();
-
- Iterator<FlatSESEEnterNode> cItr = curr.getChildren().iterator();
- while( cItr.hasNext() ) {
- FlatSESEEnterNode child = cItr.next();
- out.addAll( get( child ) );
- }
-
- return out;
- }
-
-
- // given a table from a subsequent program point, decide
- // which variables are going from a non-dynamic to a
- // dynamic source and return them
- public Hashtable<TempDescriptor, VSTWrapper>
- getReadyOrStatic2DynamicSet( VarSrcTokTable nextTable,
- Set<TempDescriptor> nextLiveIn,
- FlatSESEEnterNode current
- ) {
-
- Hashtable<TempDescriptor, VSTWrapper> out =
- new Hashtable<TempDescriptor, VSTWrapper>();
-
- Iterator itr = var2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- TempDescriptor var = (TempDescriptor) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
-
- // only worth tracking if live
- if( nextLiveIn.contains( var ) ) {
-
- VSTWrapper vstIfStaticBefore = new VSTWrapper();
- VSTWrapper vstIfStaticAfter = new VSTWrapper();
-
- Integer srcTypeBefore = this.getRefVarSrcType( var, current, vstIfStaticBefore );
- Integer srcTypeAfter = nextTable.getRefVarSrcType( var, current, vstIfStaticAfter );
-
- if( !srcTypeBefore.equals( SrcType_DYNAMIC ) &&
- srcTypeAfter.equals( SrcType_DYNAMIC )
- ) {
- // remember the variable and a source
- // it had before crossing the transition
- // 1) if it was ready, vstIfStatic.vst is null
- // 2) if is was static, use vstIfStatic.vst
- out.put( var, vstIfStaticBefore );
- }
- }
- }
-
- return out;
- }
-
-
- // for some reference variable, return the type of source
- // it might have in this table, which might be:
- // 1. Ready -- this variable is
- // definitely available when you are issued.
- // 2. Static -- there is definitely one child SESE with
- // a known age that will produce the value
- // 3. Dynamic -- we don't know where the value will come
- // from statically, so we'll track it dynamically
- public Integer getRefVarSrcType( TempDescriptor refVar,
- FlatSESEEnterNode current,
- VSTWrapper vstIfStatic ) {
- assert refVar != null;
- assert vstIfStatic != null;
-
- vstIfStatic.vst = null;
-
- // when the current SESE is null, that simply means it is
- // an unknown placeholder, in which case the system will
- // ensure that any variables are READY
- if( current == null ) {
- return SrcType_READY;
- }
-
- // if there appear to be no sources, it means this variable
- // comes from outside of any statically-known SESE scope,
- // which means the system guarantees its READY, so jump over
- // while loop
- Set<VariableSourceToken> srcs = get( refVar );
- Iterator<VariableSourceToken> itrSrcs = srcs.iterator();
- while( itrSrcs.hasNext() ) {
- VariableSourceToken vst = itrSrcs.next();
-
- // to make the refVar non-READY we have to find at least
- // one child token
- if( current.getChildren().contains( vst.getSESE() ) ) {
-
- // if we ever have at least one child source with an
- // unknown age, have to treat var as dynamic
- if( vst.getAge().equals( MLPAnalysis.maxSESEage ) ) {
- return SrcType_DYNAMIC;
- }
-
- // if we have a known-age child source, this var is
- // either static or dynamic now: it's static if this
- // source is the only source, otherwise dynamic
- if( srcs.size() > 1 ) {
- return SrcType_DYNAMIC;
- }
-
- vstIfStatic.vst = vst;
- return SrcType_STATIC;
- }
- }
-
- // if we never found a child source, all other
- // sources must be READY before we could even
- // begin executing!
- return SrcType_READY;
- }
-
-
- // any reference variables that are not live can be pruned
- // from the table, and if any VSTs are then no longer
- // referenced, they can be dropped as well
- // THIS CAUSES INCONSISTENCY, FIX LATER, NOT REQUIRED
- public void pruneByLiveness( Set<TempDescriptor> rootLiveSet ) {
-
- // the set of reference variables in the table minus the
- // live set gives the set of reference variables to remove
- Set<TempDescriptor> deadRefVars = new HashSet<TempDescriptor>();
- deadRefVars.addAll( var2vst.keySet() );
-
- if( rootLiveSet != null ) {
- deadRefVars.removeAll( rootLiveSet );
- }
-
- // just use the remove operation to prune the table now
- Iterator<TempDescriptor> deadItr = deadRefVars.iterator();
- while( deadItr.hasNext() ) {
- TempDescriptor dead = deadItr.next();
- removePrivate( dead );
- }
-
- assertConsistency();
- }
-
-
-
- // use as an aid for debugging, where true-set is checked
- // against the alternate mappings: assert that nothing is
- // missing or extra in the alternates
- public void assertConsistency() {
-
- Iterator itr;
- Set s;
-
- Set<VariableSourceToken> trueSetByAlts = new HashSet<VariableSourceToken>();
- itr = sese2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- // the trueSet should have all entries in s1
- assert trueSet.containsAll( s1 );
-
- // s1 should not have anything that doesn't appear in trueset
- Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
- sInt.removeAll( trueSet );
-
- assert sInt.isEmpty();
-
- // add s1 to a running union--at the end check if trueSet has extra
- trueSetByAlts.addAll( s1 );
- }
- // make sure trueSet isn't too big
- assert trueSetByAlts.containsAll( trueSet );
-
-
- trueSetByAlts = new HashSet<VariableSourceToken>();
- itr = var2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- TempDescriptor var = (TempDescriptor) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- // the trueSet should have all entries in s1
- assert trueSet.containsAll( s1 );
-
- // s1 should not have anything that doesn't appear in trueset
- Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
- sInt.removeAll( trueSet );
-
- assert sInt.isEmpty();
-
- // add s1 to a running union--at the end check if trueSet has extra
- trueSetByAlts.addAll( s1 );
- }
- // make sure trueSet isn't too big
- assert trueSetByAlts.containsAll( trueSet );
-
-
- trueSetByAlts = new HashSet<VariableSourceToken>();
- itr = sv2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- SVKey key = (SVKey) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- // the trueSet should have all entries in s1
- assert trueSet.containsAll( s1 );
-
- // s1 should not have anything that doesn't appear in trueset
- Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
- sInt.removeAll( trueSet );
-
- assert sInt.isEmpty();
-
- // add s1 to a running union--at the end check if trueSet has extra
- trueSetByAlts.addAll( s1 );
- }
- // make sure trueSet isn't too big
- assert trueSetByAlts.containsAll( trueSet );
-
-
- // also check that the reference var sets are consistent
- Hashtable<VariableSourceToken, Set<TempDescriptor> > vst2refVars =
- new Hashtable<VariableSourceToken, Set<TempDescriptor> >();
- itr = var2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- TempDescriptor refVar = (TempDescriptor) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- Iterator<VariableSourceToken> vstItr = s1.iterator();
- while( vstItr.hasNext() ) {
- VariableSourceToken vst = vstItr.next();
- assert vst.getRefVars().contains( refVar );
-
- Set<TempDescriptor> refVarsPart = vst2refVars.get( vst );
- if( refVarsPart == null ) {
- refVarsPart = new HashSet<TempDescriptor>();
- }
- refVarsPart.add( refVar );
- vst2refVars.put( vst, refVarsPart );
- }
- }
- itr = vst2refVars.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- VariableSourceToken vst = (VariableSourceToken) me.getKey();
- Set<TempDescriptor> s1 = (Set<TempDescriptor>) me.getValue();
-
- assert vst.getRefVars().equals( s1 );
- }
- }
-
-
- public boolean equals( Object o ) {
- if( o == null ) {
- return false;
- }
-
- if( !(o instanceof VarSrcTokTable) ) {
- return false;
- }
-
- VarSrcTokTable table = (VarSrcTokTable) o;
- return trueSet.equals( table.trueSet );
- }
-
- public int hashCode() {
- return trueSet.hashCode();
- }
-
- public Iterator<VariableSourceToken> iterator() {
- return trueSet.iterator();
- }
-
- public String toString() {
- return toStringPretty();
- }
-
- public String toStringVerbose() {
- return "trueSet ="+trueSet.toString()+"\n"+
- "sese2vst="+sese2vst.toString()+"\n"+
- "var2vst ="+var2vst.toString()+"\n"+
- "sv2vst ="+sv2vst.toString();
- }
-
- public String toStringPretty() {
- String tokHighlighter = "o";
-
- String str = "VarSrcTokTable\n";
- Iterator<VariableSourceToken> vstItr = trueSet.iterator();
- while( vstItr.hasNext() ) {
- str += " "+tokHighlighter+" "+vstItr.next()+"\n";
- }
- return str;
- }
-
- public String toStringPrettyVerbose() {
- String tokHighlighter = "o";
-
- String str = "VarSrcTokTable\n";
-
- Set s;
- Iterator itr;
- Iterator<VariableSourceToken> vstItr;
-
- str += " trueSet\n";
- vstItr = trueSet.iterator();
- while( vstItr.hasNext() ) {
- str += " "+tokHighlighter+" "+vstItr.next()+"\n";
- }
-
- str += " sese2vst\n";
- itr = sese2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
- HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- str += " "+sese.getPrettyIdentifier()+" -> \n";
-
- vstItr = s1.iterator();
- while( vstItr.hasNext() ) {
- str += " "+tokHighlighter+" "+vstItr.next()+"\n";
- }
- }
-
- str += " var2vst\n";
- itr = var2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- TempDescriptor var = (TempDescriptor) me.getKey();
- Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- str += " "+var+" -> \n";
-
- vstItr = s1.iterator();
- while( vstItr.hasNext() ) {
- str += " "+tokHighlighter+" "+vstItr.next()+"\n";
- }
- }
-
- str += " sv2vst\n";
- itr = sv2vst.entrySet().iterator();
- while( itr.hasNext() ) {
- Map.Entry me = (Map.Entry) itr.next();
- SVKey key = (SVKey) me.getKey();
- Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
- assert s1 != null;
-
- str += " "+key+" -> \n";
-
- vstItr = s1.iterator();
- while( vstItr.hasNext() ) {
- str += " "+tokHighlighter+" "+vstItr.next()+"\n";
- }
- }
-
- return str;
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import IR.*;
-import IR.Flat.*;
-import java.util.*;
-import java.io.*;
-
-public class VariableSourceToken {
-
- private Set<TempDescriptor> refVars;
- private FlatSESEEnterNode sese;
- private Integer seseAge;
- private TempDescriptor addrVar;
-
- public VariableSourceToken( Set<TempDescriptor> refVars,
- FlatSESEEnterNode sese,
- Integer seseAge,
- TempDescriptor addrVar
- ) {
- this.refVars = refVars;
- this.sese = sese;
- this.seseAge = seseAge;
- this.addrVar = addrVar;
- }
-
- public Set<TempDescriptor> getRefVars() {
- return refVars;
- }
-
- public FlatSESEEnterNode getSESE() {
- return sese;
- }
-
- public Integer getAge() {
- return seseAge;
- }
-
- public TempDescriptor getAddrVar() {
- return addrVar;
- }
-
- public VariableSourceToken copy() {
- Set<TempDescriptor> refVarsCopy = new HashSet<TempDescriptor>();
-
- Iterator<TempDescriptor> rvItr = refVars.iterator();
- while( rvItr.hasNext() ) {
- refVarsCopy.add( rvItr.next() );
- }
-
- return new VariableSourceToken( refVarsCopy,
- sese,
- new Integer( seseAge ),
- addrVar );
- }
-
- public boolean equals( Object o ) {
- if( o == null ) {
- return false;
- }
-
- if( !(o instanceof VariableSourceToken) ) {
- return false;
- }
-
- VariableSourceToken vst = (VariableSourceToken) o;
-
- // the reference vars have no bearing on equality
- return sese.equals( vst.sese ) &&
- addrVar.equals( vst.addrVar ) &&
- seseAge.equals( vst.seseAge );
- }
-
- public int hashCode() {
- // the reference vars have no bearing on hashCode
- return (sese.hashCode() << 3) * (addrVar.hashCode() << 4) ^ seseAge.intValue();
- }
-
-
- public String toString() {
- return refVars+"\tref "+addrVar+"\t@"+sese.toPrettyString()+"("+seseAge+")";
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Iterator;
-
-import IR.Flat.TempDescriptor;
-
-public class WaitingElement {
-
- private int queueID;
- private int status;
- private String dynID="";
- private TempDescriptor tempDesc;
-
- public void setTempDesc(TempDescriptor tempDesc){
- this.tempDesc=tempDesc;
- }
-
- public TempDescriptor getTempDesc(){
- return tempDesc;
- }
-
- public void setQueueID(int queueID) {
- this.queueID = queueID;
- }
-
- public String getDynID(){
- return dynID;
- }
-
- public void setDynID(String dynID){
- this.dynID=dynID;
- }
-
- public int getQueueID() {
- return queueID;
- }
-
- public void setStatus(int status) {
- this.status = status;
- }
-
- public int getStatus() {
- return status;
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof WaitingElement)) {
- return false;
- }
-
- WaitingElement in = (WaitingElement) o;
-
- if (queueID == in.getQueueID() && status == in.getStatus() && dynID.equals(in.getDynID()) ) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public String toString() {
- return "[waitingID=" + queueID + " status=" + status + " dynID="
- + dynID + "]";
- }
-
- public int hashCode() {
-
- int hash = 1;
-
- hash = hash * 31 + queueID;
-
- hash += status;
-
- hash += dynID.hashCode();
-
- return hash;
-
- }
-
-}
\ No newline at end of file
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+
+// a code plan contains information based on analysis results
+// for injecting code before and/or after a flat node
+public class CodePlan {
+
+ private Hashtable< VariableSourceToken, Set<TempDescriptor> > stall2copySet;
+ private Set<TempDescriptor> dynamicStallSet;
+ private Hashtable<TempDescriptor, TempDescriptor> dynAssign_lhs2rhs;
+ private Set<TempDescriptor> dynAssign_lhs2curr;
+ private FlatSESEEnterNode currentSESE;
+
+ public CodePlan( FlatSESEEnterNode fsen ) {
+ stall2copySet = new Hashtable< VariableSourceToken, Set<TempDescriptor> >();
+ dynamicStallSet = new HashSet<TempDescriptor>();
+ dynAssign_lhs2rhs = new Hashtable<TempDescriptor, TempDescriptor>();
+ dynAssign_lhs2curr = new HashSet<TempDescriptor>();
+ currentSESE = fsen;
+ }
+
+ public FlatSESEEnterNode getCurrentSESE() {
+ return currentSESE;
+ }
+
+ public void addStall2CopySet( VariableSourceToken stallToken,
+ Set<TempDescriptor> copySet ) {
+
+ if( stall2copySet.containsKey( stallToken ) ) {
+ Set<TempDescriptor> priorCopySet = stall2copySet.get( stallToken );
+ priorCopySet.addAll( copySet );
+ } else {
+ stall2copySet.put( stallToken, copySet );
+ }
+ }
+
+ public Set<VariableSourceToken> getStallTokens() {
+ return stall2copySet.keySet();
+ }
+
+ public Set<TempDescriptor> getCopySet( VariableSourceToken stallToken ) {
+ return stall2copySet.get( stallToken );
+ }
+
+
+ public void addDynamicStall( TempDescriptor var ) {
+ dynamicStallSet.add( var );
+ }
+
+ public Set<TempDescriptor> getDynamicStallSet() {
+ return dynamicStallSet;
+ }
+
+ public void addDynAssign( TempDescriptor lhs,
+ TempDescriptor rhs ) {
+ dynAssign_lhs2rhs.put( lhs, rhs );
+ }
+
+ public Hashtable<TempDescriptor, TempDescriptor> getDynAssigns() {
+ return dynAssign_lhs2rhs;
+ }
+
+ public void addDynAssign( TempDescriptor lhs ) {
+ dynAssign_lhs2curr.add( lhs );
+ }
+
+ public Set<TempDescriptor> getDynAssignCurr() {
+ return dynAssign_lhs2curr;
+ }
+
+ public String toString() {
+ String s = " PLAN: ";
+
+ if( !stall2copySet.entrySet().isEmpty() ) {
+ s += "[STATIC STALLS:";
+ }
+ Iterator cpsItr = stall2copySet.entrySet().iterator();
+ while( cpsItr.hasNext() ) {
+ Map.Entry me = (Map.Entry) cpsItr.next();
+ VariableSourceToken stallToken = (VariableSourceToken) me.getKey();
+ Set<TempDescriptor> copySet = (Set<TempDescriptor>) me.getValue();
+
+ s += "("+stallToken+"->"+copySet+")";
+ }
+ if( !stall2copySet.entrySet().isEmpty() ) {
+ s += "]";
+ }
+
+ if( !dynamicStallSet.isEmpty() ) {
+ s += "[DYN STALLS:"+dynamicStallSet+"]";
+ }
+
+ if( !dynAssign_lhs2rhs.isEmpty() ) {
+ s += "[DYN ASSIGNS:"+dynAssign_lhs2rhs+"]";
+ }
+
+ if( !dynAssign_lhs2curr.isEmpty() ) {
+ s += "[DYN ASS2CURR:"+dynAssign_lhs2curr+"]";
+ }
+
+ return s;
+ }
+}
import Analysis.Disjoint.Effect;
import Analysis.Disjoint.EffectsAnalysis;
import Analysis.Disjoint.Taint;
-import Analysis.MLP.CodePlan;
-import Analysis.MLP.SESEandAgePair;
-import Analysis.MLP.VSTWrapper;
-import Analysis.MLP.VarSrcTokTable;
-import Analysis.MLP.VariableSourceToken;
import IR.Descriptor;
import IR.MethodDescriptor;
import IR.Operation;
private TypeUtil typeUtil;
private CallGraph callGraph;
private RBlockRelationAnalysis rblockRel;
- private RBlockStatusAnalysis rblockStatus;
private DisjointAnalysis disjointAnalysisTaints;
private DisjointAnalysis disjointAnalysisReach;
- private Hashtable<FlatNode, Set<TempDescriptor>> livenessRootView;
+ private Set<MethodDescriptor> descriptorsToAnalyze;
+
+ private Hashtable<FlatNode, Set<TempDescriptor>> livenessGlobalView;
private Hashtable<FlatNode, Set<TempDescriptor>> livenessVirtualReads;
private Hashtable<FlatNode, VarSrcTokTable> variableResults;
private Hashtable<FlatNode, Set<TempDescriptor>> notAvailableResults;
return codePlans.keySet();
}
- public OoOJavaAnalysis(State state, TypeUtil typeUtil, CallGraph callGraph, Liveness liveness,
- ArrayReferencees arrayReferencees) {
+ public OoOJavaAnalysis(State state,
+ TypeUtil typeUtil,
+ CallGraph callGraph,
+ Liveness liveness,
+ ArrayReferencees arrayReferencees) {
double timeStartAnalysis = (double) System.nanoTime();
this.state = state;
this.typeUtil = typeUtil;
this.callGraph = callGraph;
- this.maxSESEage = state.MLP_MAXSESEAGE;
-
- livenessRootView = new Hashtable<FlatNode, Set<TempDescriptor>>();
- livenessVirtualReads = new Hashtable<FlatNode, Set<TempDescriptor>>();
- variableResults = new Hashtable<FlatNode, VarSrcTokTable>();
- notAvailableResults = new Hashtable<FlatNode, Set<TempDescriptor>>();
- codePlans = new Hashtable<FlatNode, CodePlan>();
- wdvNodesToSpliceIn = new Hashtable<FlatEdge, FlatWriteDynamicVarNode>();
-
- notAvailableIntoSESE = new Hashtable<FlatSESEEnterNode, Set<TempDescriptor>>();
-
- sese2conflictGraph = new Hashtable<FlatNode, ConflictGraph>();
+ this.maxSESEage = state.OOO_MAXSESEAGE;
+
+ livenessGlobalView = new Hashtable<FlatNode, Set<TempDescriptor>>();
+ livenessVirtualReads = new Hashtable<FlatNode, Set<TempDescriptor>>();
+ variableResults = new Hashtable<FlatNode, VarSrcTokTable>();
+ notAvailableResults = new Hashtable<FlatNode, Set<TempDescriptor>>();
+ codePlans = new Hashtable<FlatNode, CodePlan>();
+ wdvNodesToSpliceIn = new Hashtable<FlatEdge, FlatWriteDynamicVarNode>();
+ notAvailableIntoSESE = new Hashtable<FlatSESEEnterNode, Set<TempDescriptor>>();
+ sese2conflictGraph = new Hashtable<FlatNode, ConflictGraph>();
conflictGraph2SESELock = new Hashtable<ConflictGraph, HashSet<SESELock>>();
// add all methods transitively reachable from the
MethodDescriptor mdSourceEntry = typeUtil.getMain();
FlatMethod fmMain = state.getMethodFlat(mdSourceEntry);
- Set<MethodDescriptor> descriptorsToAnalyze = callGraph.getAllMethods(mdSourceEntry);
+ descriptorsToAnalyze = callGraph.getAllMethods(mdSourceEntry);
descriptorsToAnalyze.add(mdSourceEntry);
- // 1st pass, find basic rblock relations & status
+ // 1st pass, find basic rblock relations & potential stall sites
rblockRel = new RBlockRelationAnalysis(state, typeUtil, callGraph);
- rblockStatus = new RBlockStatusAnalysis(state, typeUtil, callGraph, rblockRel);
// 2nd pass, liveness, in-set out-set (no virtual reads yet!)
- Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
- while (rootItr.hasNext()) {
- FlatSESEEnterNode root = rootItr.next();
- livenessAnalysisBackward(root, true, null);
+ Iterator<MethodDescriptor> methItr = descriptorsToAnalyze.iterator();
+ while (methItr.hasNext()) {
+ Descriptor d = methItr.next();
+ FlatMethod fm = state.getMethodFlat(d);
+
+ // note we can't use the general liveness analysis already in
+ // the compiler because this analysis is task-aware
+ livenessAnalysisBackward(fm);
}
+ /*
// 3rd pass, variable analysis
- Iterator<MethodDescriptor> methItr = descriptorsToAnalyze.iterator();
+ methItr = descriptorsToAnalyze.iterator();
while (methItr.hasNext()) {
Descriptor d = methItr.next();
FlatMethod fm = state.getMethodFlat(d);
// 4th pass, compute liveness contribution from
// virtual reads discovered in variable pass
- rootItr = rblockRel.getRootSESEs().iterator();
- while (rootItr.hasNext()) {
- FlatSESEEnterNode root = rootItr.next();
- livenessAnalysisBackward(root, true, null);
+ methItr = descriptorsToAnalyze.iterator();
+ while (methItr.hasNext()) {
+ Descriptor d = methItr.next();
+ FlatMethod fm = state.getMethodFlat(d);
+ livenessAnalysisBackward(fm);
}
// 5th pass, use disjointness with NO FLAGGED REGIONS
// to compute taints and effects
disjointAnalysisTaints =
new DisjointAnalysis(state, typeUtil, callGraph, liveness, arrayReferencees, null,
- rblockRel, rblockStatus,
+ rblockRel,
true ); // suppress output--this is an intermediate pass
// 6th pass, not available analysis FOR VARIABLES!
FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
if (!parent.getIsLeafSESE()) {
-
+
EffectsAnalysis effectsAnalysis = disjointAnalysisTaints.getEffectsAnalysis();
ConflictGraph conflictGraph = sese2conflictGraph.get(parent);
if (conflictGraph == null) {
conflictGraph = new ConflictGraph(state);
}
- Set<FlatSESEEnterNode> children = parent.getSESEChildren();
+ Set<FlatSESEEnterNode> children = parent.getChildren();
for (Iterator iterator2 = children.iterator(); iterator2.hasNext();) {
FlatSESEEnterNode child = (FlatSESEEnterNode) iterator2.next();
Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(child);
}
}
- Iterator descItr = disjointAnalysisTaints.getDescriptorsToAnalyze().iterator();
+ Iterator descItr = descriptorsToAnalyze.iterator();
while (descItr.hasNext()) {
Descriptor d = (Descriptor) descItr.next();
FlatMethod fm = state.getMethodFlat(d);
if (fm != null)
makeConflictGraph(fm);
- }
-
-
+ }
- // debug routine
- /*
- * Iterator iter = sese2conflictGraph.entrySet().iterator(); while
- * (iter.hasNext()) { Entry e = (Entry) iter.next(); FlatNode fn =
- * (FlatNode) e.getKey(); ConflictGraph conflictGraph = (ConflictGraph)
- * e.getValue();
- * System.out.println("---------------------------------------");
- * System.out.println("CONFLICT GRAPH for " + fn); Set<String> keySet =
- * conflictGraph.id2cn.keySet(); for (Iterator iterator = keySet.iterator();
- * iterator.hasNext();) { String key = (String) iterator.next();
- * ConflictNode node = conflictGraph.id2cn.get(key);
- * System.out.println("key=" + key + " \n" + node.toStringAllEffects()); } }
- */
// 8th pass, calculate all possible conflicts without using reachability
// info
// later
disjointAnalysisReach =
new DisjointAnalysis(state, typeUtil, callGraph, liveness, arrayReferencees, sitesToFlag,
- null, // don't do effects analysis again!
null // don't do effects analysis again!
);
// 10th pass, calculate conflicts with reachability info
FlatWriteDynamicVarNode fwdvn = (FlatWriteDynamicVarNode) me.getValue();
fwdvn.spliceIntoIR();
}
+ */
+ /*
if (state.OOODEBUG) {
try {
writeReports("");
disjointAnalysisTaints.getEffectsAnalysis().writeEffects("effects.txt");
writeConflictGraph();
- } catch (IOException e) {
- }
+ } catch (IOException e) {}
}
-
+ */
+
+ System.out.println("\n\n\n##########################################################\n"+
+ "Warning, lots of code changes going on, OoOJava and RCR/DFJ\n"+
+ "systems are being cleaned up. Until the analyses and code gen\n"+
+ "are fully altered and coordinated, these systems will not run\n"+
+ "to completion. Partial stable check-ins are necessary to manage\n"+
+ "the number of files getting touched.\n"+
+ "##########################################################" );
+ System.exit( 0 );
}
+
+
+
+ // debug routine
+ /*
+ * Iterator iter = sese2conflictGraph.entrySet().iterator(); while
+ * (iter.hasNext()) { Entry e = (Entry) iter.next(); FlatNode fn =
+ * (FlatNode) e.getKey(); ConflictGraph conflictGraph = (ConflictGraph)
+ * e.getValue();
+ * System.out.println("---------------------------------------");
+ * System.out.println("CONFLICT GRAPH for " + fn); Set<String> keySet =
+ * conflictGraph.id2cn.keySet(); for (Iterator iterator = keySet.iterator();
+ * iterator.hasNext();) { String key = (String) iterator.next();
+ * ConflictNode node = conflictGraph.id2cn.get(key);
+ * System.out.println("key=" + key + " \n" + node.toStringAllEffects()); } }
+ */
+
+
private void writeFile(Set<FlatNew> sitesToFlag) {
}
- private void livenessAnalysisBackward(FlatSESEEnterNode fsen, boolean toplevel,
- Hashtable<FlatSESEExitNode, Set<TempDescriptor>> liveout) {
-
- // start from an SESE exit, visit nodes in reverse up to
- // SESE enter in a fixed-point scheme, where children SESEs
- // should already be analyzed and therefore can be skipped
- // because child SESE enter node has all necessary info
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
-
- if (toplevel) {
- flatNodesToVisit.add(fsen.getfmEnclosing().getFlatExit());
- } else {
- flatNodesToVisit.add(fsen.getFlatExit());
- }
- Hashtable<FlatNode, Set<TempDescriptor>> livenessResults =
- new Hashtable<FlatNode, Set<TempDescriptor>>();
+ private void livenessAnalysisBackward(FlatMethod fm) {
- if (toplevel) {
- liveout = new Hashtable<FlatSESEExitNode, Set<TempDescriptor>>();
- }
+ // flow backward across nodes to compute liveness, and
+ // take special care with sese enter/exit nodes that
+ // alter this from normal liveness analysis
+ Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
+ flatNodesToVisit.add( fm.getFlatExit() );
- while (!flatNodesToVisit.isEmpty()) {
+ while( !flatNodesToVisit.isEmpty() ) {
FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove(fn);
+ flatNodesToVisit.remove( fn );
- Set<TempDescriptor> prev = livenessResults.get(fn);
+ Set<TempDescriptor> prev = livenessGlobalView.get( fn );
// merge sets from control flow joins
- Set<TempDescriptor> u = new HashSet<TempDescriptor>();
+ Set<TempDescriptor> livein = new HashSet<TempDescriptor>();
for (int i = 0; i < fn.numNext(); i++) {
- FlatNode nn = fn.getNext(i);
- Set<TempDescriptor> s = livenessResults.get(nn);
- if (s != null) {
- u.addAll(s);
+ FlatNode nn = fn.getNext( i );
+ Set<TempDescriptor> s = livenessGlobalView.get( nn );
+ if( s != null ) {
+ livein.addAll( s );
}
}
-
- Set<TempDescriptor> curr = liveness_nodeActions(fn, u, fsen, toplevel, liveout);
+
+ Set<TempDescriptor> curr = liveness_nodeActions( fn, livein );
// if a new result, schedule backward nodes for analysis
- if (!curr.equals(prev)) {
- livenessResults.put(fn, curr);
+ if( !curr.equals( prev ) ) {
+ livenessGlobalView.put( fn, curr );
- // don't flow backwards past current SESE enter
- if (!fn.equals(fsen)) {
- for (int i = 0; i < fn.numPrev(); i++) {
- FlatNode nn = fn.getPrev(i);
- flatNodesToVisit.add(nn);
- }
+ for( int i = 0; i < fn.numPrev(); i++ ) {
+ FlatNode nn = fn.getPrev( i );
+ flatNodesToVisit.add( nn );
}
}
}
-
- Set<TempDescriptor> s = livenessResults.get(fsen);
- if (s != null) {
- fsen.addInVarSet(s);
- }
-
- // remember liveness per node from the root view as the
- // global liveness of variables for later passes to use
- if (toplevel) {
- livenessRootView.putAll(livenessResults);
- }
-
- // post-order traversal, so do children first
- Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
- while (childItr.hasNext()) {
- FlatSESEEnterNode fsenChild = childItr.next();
- livenessAnalysisBackward(fsenChild, false, liveout);
- }
}
- private Set<TempDescriptor> liveness_nodeActions(FlatNode fn, Set<TempDescriptor> liveIn,
- FlatSESEEnterNode currentSESE, boolean toplevel,
- Hashtable<FlatSESEExitNode, Set<TempDescriptor>> liveout) {
- switch (fn.kind()) {
+ private Set<TempDescriptor> liveness_nodeActions( FlatNode fn,
+ Set<TempDescriptor> liveIn
+ ) {
+ switch( fn.kind() ) {
- case FKind.FlatSESEExitNode:
- if (toplevel) {
- FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
- if (!liveout.containsKey(fsexn)) {
- liveout.put(fsexn, new HashSet<TempDescriptor>());
- }
- liveout.get(fsexn).addAll(liveIn);
+ case FKind.FlatSESEEnterNode: {
+ // add whatever is live-in at a task enter to that
+ // task's in-var set
+ FlatSESEEnterNode fsen = (FlatSESEEnterNode)fn;
+ if( liveIn != null ) {
+ fsen.addInVarSet( liveIn );
}
- // no break, sese exits should also execute default actions
+ // no break, should also execute default actions
+ }
default: {
// handle effects of statement in reverse, writes then reads
TempDescriptor[] writeTemps = fn.writesTemps();
- for (int i = 0; i < writeTemps.length; ++i) {
- liveIn.remove(writeTemps[i]);
-
- if (!toplevel) {
- FlatSESEExitNode fsexn = currentSESE.getFlatExit();
- Set<TempDescriptor> livetemps = liveout.get(fsexn);
- if (livetemps != null && livetemps.contains(writeTemps[i])) {
- // write to a live out temp...
- // need to put in SESE liveout set
- currentSESE.addOutVar(writeTemps[i]);
- }
+ for( int i = 0; i < writeTemps.length; ++i ) {
+ liveIn.remove( writeTemps[i] );
+
+ // if we are analyzing code declared directly in a task,
+ FlatSESEEnterNode fsen = rblockRel.getLocalInnerRBlock( fn );
+ if( fsen != null ) {
+ // check to see if we are writing to variables that will
+ // be live-out at the task's exit (and therefore should
+ // go in the task's out-var set)
+ FlatSESEExitNode fsexn = fsen.getFlatExit();
+ Set<TempDescriptor> livetemps = livenessGlobalView.get( fsexn );
+ if( livetemps != null && livetemps.contains( writeTemps[i] ) ) {
+ fsen.addOutVar( writeTemps[i] );
+ }
}
}
TempDescriptor[] readTemps = fn.readsTemps();
- for (int i = 0; i < readTemps.length; ++i) {
- liveIn.add(readTemps[i]);
- }
-
- Set<TempDescriptor> virtualReadTemps = livenessVirtualReads.get(fn);
- if (virtualReadTemps != null) {
- liveIn.addAll(virtualReadTemps);
+ for( int i = 0; i < readTemps.length; ++i ) {
+ liveIn.add( readTemps[i] );
}
- }
- break;
+ Set<TempDescriptor> virtualReadTemps = livenessVirtualReads.get( fn );
+ if( virtualReadTemps != null ) {
+ liveIn.addAll( virtualReadTemps );
+ }
+ } break;
} // end switch
return liveIn;
}
+
private void variableAnalysisForward(FlatMethod fm) {
Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
flatNodesToVisit.remove(fn);
- Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
- assert seseStack != null;
-
VarSrcTokTable prev = variableResults.get(fn);
// merge sets from control flow joins
curr.merge(incoming);
}
- if (!seseStack.empty()) {
- variable_nodeActions(fn, curr, seseStack.peek());
+ Set<FlatSESEEnterNode> possiblyExecuting =
+ rblockRel.getPossibleExecutingRBlocks( fn );
+
+ if (!possiblyExecuting.isEmpty()) {
+ variable_nodeActions(fn, curr, possiblyExecuting);
}
// if a new result, schedule forward nodes for analysis
}
}
- private void variable_nodeActions(FlatNode fn, VarSrcTokTable vstTable,
- FlatSESEEnterNode currentSESE) {
+ private void variable_nodeActions(FlatNode fn,
+ VarSrcTokTable vstTable,
+ Set<FlatSESEEnterNode> currentSESEs) {
switch (fn.kind()) {
case FKind.FlatSESEEnterNode: {
FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- assert fsen.equals(currentSESE);
-
- vstTable.age(currentSESE);
+ // ignore currently executing SESEs, at this point
+ // the analysis considers a new instance is becoming
+ // the current SESE
+ vstTable.age(fsen);
vstTable.assertConsistency();
- }
- break;
+ } break;
case FKind.FlatSESEExitNode: {
FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
+
+ // fsen is the child of currently executing tasks
FlatSESEEnterNode fsen = fsexn.getFlatEnter();
- assert currentSESE.getChildren().contains(fsen);
// remap all of this child's children tokens to be
// from this child as the child exits
// written by an SESE and should be added to the in-set
// anything virtually read by this SESE should be pruned
// of parent or sibling sources
- Set<TempDescriptor> liveVars = livenessRootView.get(fn);
+ Set<TempDescriptor> liveVars = livenessGlobalView.get(fn);
Set<TempDescriptor> fsenVirtReads =
- vstTable.calcVirtReadsAndPruneParentAndSiblingTokens(fsen, liveVars);
+ vstTable.calcVirtReadsAndPruneParentAndSiblingTokens(fsen, liveVars);
+
Set<TempDescriptor> fsenVirtReadsOld = livenessVirtualReads.get(fn);
if (fsenVirtReadsOld != null) {
fsenVirtReads.addAll(fsenVirtReadsOld);
vstTable.add(vst);
}
vstTable.assertConsistency();
-
- }
- break;
+ } break;
case FKind.FlatOpNode: {
FlatOpNode fon = (FlatOpNode) fn;
HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
ts.add(lhs);
+ ///////////////// TODO !!!!!!!!!!!!!!!!!////////////////
+ // @$@$@$@$#%@%$^@%^@$&@#$^&%&*$&*(%^*(%^*()%^*()
+ /*
if (currentSESE.getChildren().contains(vst.getSESE())) {
// if the source comes from a child, copy it over
- forAddition.add(new VariableSourceToken(ts, vst.getSESE(), vst.getAge(), vst
- .getAddrVar()));
+ forAddition.add(new VariableSourceToken(ts, vst.getSESE(), vst.getAge(), vst.getAddrVar()));
} else {
// otherwise, stamp it as us as the source
forAddition.add(new VariableSourceToken(ts, currentSESE, new Integer(0), lhs));
}
+ */
}
vstTable.addAll(forAddition);
HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
ts.add(writeTemps[0]);
- vstTable.add(new VariableSourceToken(ts, currentSESE, new Integer(0), writeTemps[0]));
+ ///////////////// TODO !!!!!!!!!!!!!!!!!////////////////
+ // @$@$@$@$#%@%$^@%^@$&@#$^&%&*$&*(%^*(%^*()%^*()
+ //vstTable.add(new VariableSourceToken(ts, currentSESE, new Integer(0), writeTemps[0]));
}
vstTable.assertConsistency();
FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
flatNodesToVisit.remove(fn);
- Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
+ Stack<FlatSESEEnterNode> seseStack = null; //rblockRel.getRBlockStacks(fm, fn);
assert seseStack != null;
Set<TempDescriptor> prev = notAvailableResults.get(fn);
flatNodesToVisit.remove(fn);
visited.add(fn);
- Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
+ Stack<FlatSESEEnterNode> seseStack = null; //rblockRel.getRBlockStacks(fm, fn);
assert seseStack != null;
// use incoming results as "dot statement" or just
}
}
- Set<TempDescriptor> dotSTlive = livenessRootView.get(fn);
+ Set<TempDescriptor> dotSTlive = livenessGlobalView.get(fn);
if (!seseStack.empty()) {
codePlans_nodeActions(fn, dotSTlive, dotSTtable, dotSTnotAvailSet, seseStack.peek());
// the parent SESE in--at other FlatNode types just
// use the currentSESE
VSTWrapper vstIfStatic = new VSTWrapper();
- Integer srcType = vstTableIn.getRefVarSrcType(inVar, fsen.getParent(), vstIfStatic);
+ Integer srcType = null; //vstTableIn.getRefVarSrcType(inVar, fsen.getParent(), vstIfStatic);
// the current SESE needs a local space to track the dynamic
// variable and the child needs space in its SESE record
if (srcType.equals(VarSrcTokTable.SrcType_DYNAMIC)) {
fsen.addDynamicInVar(inVar);
- fsen.getParent().addDynamicVar(inVar);
+ // %@%@%@%@%@%@%@% TODO!!!! @%@%@%@%@% fsen.getParent().addDynamicVar(inVar);
} else if (srcType.equals(VarSrcTokTable.SrcType_STATIC)) {
fsen.addStaticInVar(inVar);
// placeholder source tokens are useful results, but
// the placeholder static name is never needed
- if (vst.getSESE().getIsCallerSESEplaceholder()) {
- continue;
- }
+ //if (vst.getSESE().getIsCallerSESEplaceholder()) {
+ // continue;
+ //}
FlatSESEEnterNode sese = currentSESE;
while (sese != null) {
sese.addNeededStaticName(new SESEandAgePair(vst.getSESE(), vst.getAge()));
sese.mustTrackAtLeastAge(vst.getAge());
- sese = sese.getParent();
+ //@%@%@%@%@%@% TODO!!!!! @%@%@%@%@%@% sese = sese.getParent();
}
}
for (int i = 0; i < fn.numNext(); i++) {
FlatNode nn = fn.getNext(i);
VarSrcTokTable nextVstTable = variableResults.get(nn);
- Set<TempDescriptor> nextLiveIn = livenessRootView.get(nn);
+ Set<TempDescriptor> nextLiveIn = livenessGlobalView.get(nn);
// the table can be null if it is one of the few IR nodes
// completely outside of the root SESE scope
private void makeConflictGraph(FlatMethod fm) {
+ System.out.println( "Creating conflict graph for "+fm );
+
Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
flatNodesToVisit.add(fm);
flatNodesToVisit.remove(fn);
visited.add(fn);
- Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
+ Stack<FlatSESEEnterNode> seseStack = null; //rblockRel.getRBlockStacks(fm, fn);
assert seseStack != null;
if (!seseStack.isEmpty()) {
EffectsAnalysis effectsAnalysis = disjointAnalysisTaints.getEffectsAnalysis();
+
switch (fn.kind()) {
+
case FKind.FlatFieldNode:
case FKind.FlatElementNode: {
rhs = fen.getSrc();
}
- // jjenista - I think the following code is WRONG!!!
- // We are looking at some non-task FlatNode fn that is a stall site and
- // considering what conflicts it might have with CHILDREN of the CURRENT TASK
- // that contains fn. WE SHOULD NOT BE GETTING THE PARENT OF currentSESE
- // because in this scenario currentSESE IS the parent in relation to other
- // tasks that might conflict with this fn.
- // OK, why not fix it? Because code all over the place is built on
- // being able to retrieve the correct conflict graph, which is associated
- // with the wrong task, but at least consistently, SO LEAVE IT BUT REALIZE
- // WHAT IS HAPPENING
-
- Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
- for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
- FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
-// System.out.println("##current="+currentSESE.getmdEnclosing()+" PARENT=" + parent);
- conflictGraph = sese2conflictGraph.get(parent);
- if (conflictGraph == null) {
- conflictGraph = new ConflictGraph(state);
- }
+ conflictGraph = sese2conflictGraph.get(currentSESE);
+ if (conflictGraph == null) {
+ conflictGraph = new ConflictGraph(state);
+ }
- // add stall site
- Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
- conflictGraph.addStallSite(taint2Effects, rhs);
- if (taint2Effects != null)
-// System.out.println("add =" + taint2Effects + "currentSESE=" + parent
-// + " into conflictGraph=" + conflictGraph);
+ // add stall site
+ Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
+ conflictGraph.addStallSite(taint2Effects, rhs);
- if (conflictGraph.id2cn.size() > 0) {
- sese2conflictGraph.put(parent, conflictGraph);
- }
+ if (conflictGraph.id2cn.size() > 0) {
+ sese2conflictGraph.put(currentSESE, conflictGraph);
}
+ } break;
- }
- break;
case FKind.FlatSetFieldNode:
case FKind.FlatSetElementNode: {
rhs = fsen.getSrc();
}
- // jjenista - I think the following code is WRONG!!!
- // We are looking at some non-task FlatNode fn that is a stall site and
- // considering what conflicts it might have with CHILDREN of the CURRENT TASK
- // that contains fn. WE SHOULD NOT BE GETTING THE PARENT OF currentSESE
- // because in this scenario currentSESE IS the parent in relation to other
- // tasks that might conflict with this fn.
- // OK, why not fix it? Because code all over the place is built on
- // being able to retrieve the correct conflict graph, which is associated
- // with the wrong task, but at least consistently, SO LEAVE IT BUT REALIZE
- // WHAT IS HAPPENING
-
- // collects effects of stall site and generates stall site node
- Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
- for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
- FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
- conflictGraph = sese2conflictGraph.get(parent);
- if (conflictGraph == null) {
- conflictGraph = new ConflictGraph(state);
- }
+ conflictGraph = sese2conflictGraph.get(currentSESE);
+ if (conflictGraph == null) {
+ conflictGraph = new ConflictGraph(state);
+ }
- Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
- conflictGraph.addStallSite(taint2Effects, rhs);
- conflictGraph.addStallSite(taint2Effects, lhs);
+ Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
+ conflictGraph.addStallSite(taint2Effects, rhs);
+ conflictGraph.addStallSite(taint2Effects, lhs);
- if (conflictGraph.id2cn.size() > 0) {
- sese2conflictGraph.put(parent, conflictGraph);
- }
+ if (conflictGraph.id2cn.size() > 0) {
+ sese2conflictGraph.put(currentSESE, conflictGraph);
}
-
- }
- break;
+ } break;
case FKind.FlatCall: {
conflictGraph = sese2conflictGraph.get(currentSESE);
// collects effects of stall site and generates stall site node
Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
- // jjenista - I think the following code is WRONG!!!
- // We are looking at some non-task FlatNode fn that is a stall site and
- // considering what conflicts it might have with CHILDREN of the CURRENT TASK
- // that contains fn. WE SHOULD NOT BE GETTING THE PARENT OF currentSESE
- // because in this scenario currentSESE IS the parent in relation to other
- // tasks that might conflict with this fn.
- // OK, why not fix it? Because code all over the place is built on
- // being able to retrieve the correct conflict graph, which is associated
- // with the wrong task, but at least consistently, SO LEAVE IT BUT REALIZE
- // WHAT IS HAPPENING
-
- Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
- for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
- FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
- conflictGraph = sese2conflictGraph.get(parent);
- if (conflictGraph == null) {
- conflictGraph = new ConflictGraph(state);
- }
-
- conflictGraph.addStallSite(taint2Effects, lhs);
- if (conflictGraph.id2cn.size() > 0) {
- sese2conflictGraph.put(parent, conflictGraph);
- }
-
- }
-
- }
+ conflictGraph.addStallSite(taint2Effects, lhs);
+ if (conflictGraph.id2cn.size() > 0) {
+ sese2conflictGraph.put(currentSESE, conflictGraph);
+ }
+ } break;
- break;
}
-
}
+
private void calculateConflicts(Set<FlatNew> sitesToFlag, boolean useReachInfo) {
// decide fine-grain edge or coarse-grain edge among all vertexes by
// pair-wise comparison
return rblockRel.getMainSESE();
}
+
public void writeReports(String timeReport) throws java.io.IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter("mlpReport_summary.txt"));
printSESEInfo(bw);
bw.close();
- Iterator<Descriptor> methItr = disjointAnalysisTaints.getDescriptorsToAnalyze().iterator();
+ Iterator<MethodDescriptor> methItr = descriptorsToAnalyze.iterator();
while (methItr.hasNext()) {
- MethodDescriptor md = (MethodDescriptor) methItr.next();
+ MethodDescriptor md = methItr.next();
FlatMethod fm = state.getMethodFlat(md);
if (fm != null) {
- bw =
- new BufferedWriter(new FileWriter("mlpReport_" + md.getClassMethodName()
- + md.getSafeMethodDescriptor() + ".txt"));
- bw.write("MLP Results for " + md + "\n-------------------\n");
+ bw = new BufferedWriter(new FileWriter("ooojReport_" +
+ md.getClassMethodName() +
+ md.getSafeMethodDescriptor() +
+ ".txt"));
+ bw.write("OoOJava Results for " + md + "\n-------------------\n");
FlatSESEEnterNode implicitSESE = (FlatSESEEnterNode) fm.getNext(0);
- if (!implicitSESE.getIsCallerSESEplaceholder() && implicitSESE != rblockRel.getMainSESE()) {
- System.out.println(implicitSESE + " is not implicit?!");
- System.exit(-1);
- }
+ //if (!implicitSESE.getIsCallerSESEplaceholder() && implicitSESE != rblockRel.getMainSESE()) {
+ // System.out.println(implicitSESE + " is not implicit?!");
+ // System.exit(-1);
+ //}
bw.write("Dynamic vars to manage:\n " + implicitSESE.getDynamicVarSet());
- bw.write("\n\nLive-In, Root View\n------------------\n" + fm.printMethod(livenessRootView));
+ bw.write("\n\nLive-In, Root View\n------------------\n" + fm.printMethod(livenessGlobalView));
bw.write("\n\nVariable Results-Out\n----------------\n" + fm.printMethod(variableResults));
bw.write("\n\nNot Available Results-Out\n---------------------\n"
+ fm.printMethod(notAvailableResults));
private void printSESEHierarchy(BufferedWriter bw) throws java.io.IOException {
bw.write("SESE Hierarchy\n--------------\n");
- Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
+ Iterator<FlatSESEEnterNode> rootItr = rblockRel.getAllSESEs().iterator();
while (rootItr.hasNext()) {
FlatSESEEnterNode root = rootItr.next();
- if (root.getIsCallerSESEplaceholder()) {
- if (!root.getChildren().isEmpty()) {
- printSESEHierarchyTree(bw, root, 0);
- }
- } else {
+ //if (root.getIsCallerSESEplaceholder()) {
+ // if (!root.getChildren().isEmpty()) {
+ // printSESEHierarchyTree(bw, root, 0);
+ // }
+ //} else {
printSESEHierarchyTree(bw, root, 0);
- }
+ //}
}
}
private void printSESEInfo(BufferedWriter bw) throws java.io.IOException {
bw.write("\nSESE info\n-------------\n");
- Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
+ Iterator<FlatSESEEnterNode> rootItr = null; //rblockRel.getRootSESEs().iterator();
while (rootItr.hasNext()) {
FlatSESEEnterNode root = rootItr.next();
- if (root.getIsCallerSESEplaceholder()) {
- if (!root.getChildren().isEmpty()) {
- printSESEInfoTree(bw, root);
- }
- } else {
+ //if (root.getIsCallerSESEplaceholder()) {
+ // if (!root.getChildren().isEmpty()) {
+ // printSESEInfoTree(bw, root);
+ // }
+ //} else {
printSESEInfoTree(bw, root);
- }
+ //}
}
}
private void printSESEInfoTree(BufferedWriter bw, FlatSESEEnterNode fsen)
throws java.io.IOException {
- if (!fsen.getIsCallerSESEplaceholder()) {
- bw.write("SESE " + fsen.getPrettyIdentifier());
- if( fsen.getIsLeafSESE() ) {
- bw.write(" (leaf)");
+ bw.write("SESE " + fsen.getPrettyIdentifier());
+ if( fsen.getIsLeafSESE() ) {
+ bw.write(" (leaf)");
+ }
+ bw.write(" {\n");
+
+ bw.write(" in-set: " + fsen.getInVarSet() + "\n");
+ Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
+ while (tItr.hasNext()) {
+ TempDescriptor inVar = tItr.next();
+ if (fsen.getReadyInVarSet().contains(inVar)) {
+ bw.write(" (ready) " + inVar + "\n");
}
- bw.write(" {\n");
-
- bw.write(" in-set: " + fsen.getInVarSet() + "\n");
- Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
- while (tItr.hasNext()) {
- TempDescriptor inVar = tItr.next();
- if (fsen.getReadyInVarSet().contains(inVar)) {
- bw.write(" (ready) " + inVar + "\n");
- }
- if (fsen.getStaticInVarSet().contains(inVar)) {
- bw.write(" (static) " + inVar + " from " + fsen.getStaticInVarSrc(inVar) + "\n");
- }
- if (fsen.getDynamicInVarSet().contains(inVar)) {
- bw.write(" (dynamic)" + inVar + "\n");
- }
+ if (fsen.getStaticInVarSet().contains(inVar)) {
+ bw.write(" (static) " + inVar + " from " + fsen.getStaticInVarSrc(inVar) + "\n");
+ }
+ if (fsen.getDynamicInVarSet().contains(inVar)) {
+ bw.write(" (dynamic)" + inVar + "\n");
}
+ }
- bw.write(" Dynamic vars to manage: " + fsen.getDynamicVarSet() + "\n");
+ bw.write(" Dynamic vars to manage: " + fsen.getDynamicVarSet() + "\n");
- bw.write(" out-set: " + fsen.getOutVarSet() + "\n");
- bw.write("}\n");
- }
+ bw.write(" out-set: " + fsen.getOutVarSet() + "\n");
+ bw.write("}\n");
Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
while (childItr.hasNext()) {
import IR.State;
import IR.TypeUtil;
-import Analysis.CallGraph.CallGraph;
import IR.MethodDescriptor;
+import IR.TypeDescriptor;
import IR.Flat.*;
+import Analysis.CallGraph.CallGraph;
import java.util.*;
-// This analysis computes relations between rblocks
-// and identifies important rblocks.
+
+// This analysis finds all reachable rblocks in the
+// program and computes parent/child relations
+// between those rblocks
+
+// SPECIAL NOTE!
+// There is a distict between parent/child and
+// local parent/local child! "Local" means defined
+// and nested within a single method context.
+// Otherwise, SESE/rblocks/tasks may have many
+// parents and many non-method-context-local
+// children considering the call graph
+
+// Also this analysis should identify "critical regions"
+// in the context of interprocedural sese/rblock/task relations
+// where a statement may conflict with some previously executing
+// child task, even if it is in another method context.
+//
+// Ex:
+//
+// void main() {
+// task a {
+// Foo f = new Foo();
+// task achild1 {
+// f.z = 1;
+// }
+// doSomething( f );
+// }
+// }
+//
+// void doSomething( Foo f ) {
+// f.z++; <-------- These two statements are in the critical
+// f.z--; <-------- region of 'a' after 'c1' and before 'c2'
+// task achild2 {
+// f.z--;
+// }
+// }
+
public class RBlockRelationAnalysis {
// about it, such as the whole program ends when it ends
protected FlatSESEEnterNode mainSESE;
- // SESEs that are the root of an SESE tree belong to this
- // set--the main SESE is always a root, statically SESEs
- // inside methods are a root because we don't know how they
- // will fit into the runtime tree of SESEs
- protected Set<FlatSESEEnterNode> rootSESEs;
+ // this is a special task object, it is not in any IR graph
+ // and it does not appear to have any children or parents.
+ // It is a stand-in for whichever task is running when a
+ // method context starts such that intraprocedural task
+ // analyses have one static name for "the task who invoked
+ // this method" to attach facts to. It GREATLY simplifies
+ // the OoOJava variable analysis, for instance
+ protected FlatSESEEnterNode callerProxySESE;
- // simply a set of every reachable SESE in the program, not
- // including caller placeholder SESEs
+ // simply the set of every reachable SESE in the program
protected Set<FlatSESEEnterNode> allSESEs;
- // a set of every bogus palceholder SESEs
- protected Set<FlatSESEEnterNode> allBogusSESEs;
-
- // per method-per node-rblock stacks
- protected Hashtable< FlatMethod,
- Hashtable< FlatNode,
- Stack<FlatSESEEnterNode>
- >
- > fm2relmap;
-
// to support calculation of leaf SESEs (no children even
// through method calls) for optimization during code gen
protected Set<MethodDescriptor> methodsContainingSESEs;
// maps method descriptor to SESE defined inside of it
- // only contains top-level SESE definition in corresponding method
- protected Hashtable<MethodDescriptor, Set<FlatSESEEnterNode>> md2seseSet;
+ // only contains local root SESE definitions in corresponding method
+ // (has no parent in the local method context)
+ protected Hashtable< MethodDescriptor, Set<FlatSESEEnterNode> > md2localRootSESEs;
+
+ // the set of every local root SESE in the program (SESE that
+ // has no parent in the local method context)
+ protected Set<FlatSESEEnterNode> allLocalRootSESEs;
+
+ // if you want to know which rblocks might be executing a given flat
+ // node it will be in this set
+ protected Hashtable< FlatNode, Set<FlatSESEEnterNode> > fn2currentSESEs;
+
+ // if you want to know the method-local, inner-most nested task that
+ // is executing a flat node, it is either here or null.
+ //
+ // ex:
+ // void foo() {
+ // task a {
+ // bar(); <-- here 'a' is the localInnerSESE
+ // }
+ // void bar() {
+ // baz(); <-- here there is no locally-defined SESE, would be null
+ // }
+ protected Hashtable<FlatNode, FlatSESEEnterNode> fn2localInnerSESE;
+
+ // indicates whether this statement might occur in a task and
+ // after some child task definition such that, without looking at
+ // the flat node itself, the parent might have to stall for child
+ protected Hashtable<FlatNode, Boolean> fn2isPotentialStallSite;
+
+
+ ////////////////////////
+ // public interface
+ ////////////////////////
+ public FlatSESEEnterNode getMainSESE() {
+ return mainSESE;
+ }
+
+ public FlatSESEEnterNode getCallerProxySESE() {
+ return callerProxySESE;
+ }
+
+ public Set<FlatSESEEnterNode> getAllSESEs() {
+ return allSESEs;
+ }
+
+ public Set<FlatSESEEnterNode> getLocalRootSESEs() {
+ return allLocalRootSESEs;
+ }
+ public Set<FlatSESEEnterNode> getPossibleExecutingRBlocks( FlatNode fn ) {
+ return fn2currentSESEs.get( fn );
+ }
+
+ public FlatSESEEnterNode getLocalInnerRBlock( FlatNode fn ) {
+ return fn2localInnerSESE.get( fn );
+ }
+
+ public boolean isPotentialStallSite( FlatNode fn ) {
+ Boolean ipss = fn2isPotentialStallSite.get( fn );
+ if( ipss == null ) {
+ return false;
+ }
+ return ipss;
+ }
+
+
public RBlockRelationAnalysis( State state,
TypeUtil typeUtil,
CallGraph callGraph ) {
this.typeUtil = typeUtil;
this.callGraph = callGraph;
- rootSESEs = new HashSet<FlatSESEEnterNode>();
- allSESEs = new HashSet<FlatSESEEnterNode>();
- allBogusSESEs = new HashSet<FlatSESEEnterNode>();
+ callerProxySESE = new FlatSESEEnterNode( null );
- methodsContainingSESEs = new HashSet<MethodDescriptor>();
-
- fm2relmap =
- new Hashtable< FlatMethod, Hashtable< FlatNode, Stack<FlatSESEEnterNode> > >();
-
- md2seseSet = new Hashtable<MethodDescriptor, Set<FlatSESEEnterNode>>();
+ allSESEs = new HashSet<FlatSESEEnterNode>();
+ allLocalRootSESEs = new HashSet<FlatSESEEnterNode>();
+ methodsContainingSESEs = new HashSet<MethodDescriptor>();
+ md2localRootSESEs = new Hashtable<MethodDescriptor, Set<FlatSESEEnterNode>>();
+ fn2currentSESEs = new Hashtable<FlatNode, Set<FlatSESEEnterNode>>();
+ fn2localInnerSESE = new Hashtable<FlatNode, FlatSESEEnterNode>();
+ fn2isPotentialStallSite = new Hashtable<FlatNode, Boolean>();
MethodDescriptor mdSourceEntry = typeUtil.getMain();
mainSESE.setmdEnclosing( fmMain.getMethod() );
mainSESE.setcdEnclosing( fmMain.getMethod().getClassDesc() );
+
// add all methods transitively reachable from the
- // source's main to set for analysis
+ // source's main to set to find rblocks
Set<MethodDescriptor> descriptorsToAnalyze =
callGraph.getAllMethods( mdSourceEntry );
descriptorsToAnalyze.add( mdSourceEntry );
- analyzeMethods( descriptorsToAnalyze );
+ findRblocksAndLocalParentChildRelations( descriptorsToAnalyze );
- computeLeafSESEs();
- }
+ findTransitiveParentChildRelations();
+ findPossibleExecutingRBlocksAndStallSites();
- public FlatSESEEnterNode getMainSESE() {
- return mainSESE;
- }
- public Set<FlatSESEEnterNode> getRootSESEs() {
- return rootSESEs;
+ // Uncomment this phase to debug the marking of potential
+ // stall sites for parents between/after children tasks.
+ // After this debug thing runs in calls System.exit()
+ //debugPrintPotentialStallSites( descriptorsToAnalyze );
}
- public Set<FlatSESEEnterNode> getAllSESEs() {
- return allSESEs;
- }
-
- public Stack<FlatSESEEnterNode> getRBlockStacks( FlatMethod fm,
- FlatNode fn ) {
- if( !fm2relmap.containsKey( fm ) ) {
- fm2relmap.put( fm, computeRBlockRelations( fm ) );
- }
- return fm2relmap.get( fm ).get( fn );
- }
- protected void analyzeMethods( Set<MethodDescriptor> descriptorsToAnalyze ) {
+
+ protected void findRblocksAndLocalParentChildRelations( Set<MethodDescriptor> descriptorsToAnalyze ) {
Iterator<MethodDescriptor> mdItr = descriptorsToAnalyze.iterator();
while( mdItr.hasNext() ) {
FlatMethod fm = state.getMethodFlat( mdItr.next() );
-
- Hashtable< FlatNode, Stack<FlatSESEEnterNode> > relmap =
- computeRBlockRelations( fm );
-
- fm2relmap.put( fm, relmap );
- }
- }
-
- public Hashtable< FlatNode, Stack<FlatSESEEnterNode> >
- computeRBlockRelations( FlatMethod fm ) {
-
- Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks =
- new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
-
- // start from flat method top, visit every node in
- // method exactly once, find SESE stack on every
- // control path
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add( fm );
+
+ // start from flat method top, visit every node in
+ // method exactly once, find SESE stack on every
+ // control path: this will discover every reachable
+ // SESE in the program, and define the local parent
+ // and local children relations
+ Hashtable< FlatNode, Stack<FlatSESEEnterNode> > seseStacks =
+ new Hashtable< FlatNode, Stack<FlatSESEEnterNode> >();
+
+ Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
+ flatNodesToVisit.add( fm );
- Set<FlatNode> visited = new HashSet<FlatNode>();
+ Set<FlatNode> visited = new HashSet<FlatNode>();
- Stack<FlatSESEEnterNode> seseStackFirst = new Stack<FlatSESEEnterNode>();
- seseStacks.put( fm, seseStackFirst );
+ Stack<FlatSESEEnterNode> seseStackFirst = new Stack<FlatSESEEnterNode>();
+ seseStacks.put( fm, seseStackFirst );
- while( !flatNodesToVisit.isEmpty() ) {
- Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
- FlatNode fn = fnItr.next();
+ while( !flatNodesToVisit.isEmpty() ) {
+ Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
+ FlatNode fn = fnItr.next();
- Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
- assert seseStack != null;
+ Stack<FlatSESEEnterNode> seseStack = seseStacks.get( fn );
+ assert seseStack != null;
- flatNodesToVisit.remove( fn );
- visited.add( fn );
-
- nodeActions( fn, seseStack, fm );
+ flatNodesToVisit.remove( fn );
+ visited.add( fn );
- for( int i = 0; i < fn.numNext(); i++ ) {
- FlatNode nn = fn.getNext( i );
-
- if( !visited.contains( nn ) ) {
- flatNodesToVisit.add( nn );
+ if( !seseStack.isEmpty() ) {
+ fn2localInnerSESE.put( fn, seseStack.peek() );
+ }
- // clone stack and send along each control path
- seseStacks.put( nn, (Stack<FlatSESEEnterNode>)seseStack.clone() );
- }
- }
- }
+ nodeActions( fn, seseStack, fm );
+
+ for( int i = 0; i < fn.numNext(); i++ ) {
+ FlatNode nn = fn.getNext( i );
+
+ if( !visited.contains( nn ) ) {
+ flatNodesToVisit.add( nn );
- return seseStacks;
+ // clone stack and send along each control path
+ seseStacks.put( nn, (Stack<FlatSESEEnterNode>)seseStack.clone() );
+ }
+ }
+ }
+ }
}
-
+
protected void nodeActions( FlatNode fn,
Stack<FlatSESEEnterNode> seseStack,
FlatMethod fm ) {
switch( fn.kind() ) {
-
+
case FKind.FlatSESEEnterNode: {
FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
- if( !fsen.getIsCallerSESEplaceholder() ) {
- allSESEs.add( fsen );
- methodsContainingSESEs.add( fm.getMethod() );
- }else{
- allBogusSESEs.add(fsen);
- }
+ allSESEs.add( fsen );
+ methodsContainingSESEs.add( fm.getMethod() );
fsen.setfmEnclosing( fm );
fsen.setmdEnclosing( fm.getMethod() );
fsen.setcdEnclosing( fm.getMethod().getClassDesc() );
- if(!fsen.getIsCallerSESEplaceholder() && fsen.getParent()==null ){
- Set<FlatSESEEnterNode> seseSet=md2seseSet.get(fm.getMethod());
- if(seseSet==null){
- seseSet=new HashSet<FlatSESEEnterNode>();
- }
- seseSet.add(fsen);
- md2seseSet.put(fm.getMethod(), seseSet);
- }
-
if( seseStack.empty() ) {
- rootSESEs.add( fsen );
- fsen.setParent( null );
+ // no local parent
+ fsen.setLocalParent( null );
+
+ allLocalRootSESEs.add( fsen );
+
+ Set<FlatSESEEnterNode> seseSet = md2localRootSESEs.get( fm.getMethod() );
+ if( seseSet == null ) {
+ seseSet = new HashSet<FlatSESEEnterNode>();
+ }
+ seseSet.add( fsen );
+ md2localRootSESEs.put( fm.getMethod(), seseSet );
+
} else {
- seseStack.peek().addChild( fsen );
- fsen.setParent( seseStack.peek() );
- // if the top of stack is not bogus one, it should be a non-bogus parent to the current sese
- if(!seseStack.peek().getIsCallerSESEplaceholder()){
- fsen.addSESEParent(seseStack.peek());
- }
+ // otherwise a local parent/child relation
+ // which is also the broader parent/child
+ // relation as well
+ seseStack.peek().addLocalChild( fsen );
+ fsen.setLocalParent( seseStack.peek() );
+
+ seseStack.peek().addChild( fsen );
+ fsen.addParent( seseStack.peek() );
}
seseStack.push( fsen );
case FKind.FlatReturnNode: {
FlatReturnNode frn = (FlatReturnNode) fn;
- if( !seseStack.empty() &&
- !seseStack.peek().getIsCallerSESEplaceholder()
- ) {
+ if( !seseStack.empty() ) {
throw new Error( "Error: return statement enclosed within SESE "+
seseStack.peek().getPrettyIdentifier() );
}
}
- protected void computeLeafSESEs() {
-
- Set<FlatSESEEnterNode> all=new HashSet<FlatSESEEnterNode>();
- all.addAll(allSESEs);
- all.addAll(allBogusSESEs);
-
- for (Iterator<FlatSESEEnterNode> itr = all.iterator(); itr.hasNext();) {
+
+ protected void findTransitiveParentChildRelations() {
+
+ for (Iterator<FlatSESEEnterNode> itr = allSESEs.iterator(); itr.hasNext();) {
FlatSESEEnterNode fsen = itr.next();
- boolean hasNoNestedChildren = fsen.getChildren().isEmpty();
- boolean hasNoChildrenByCall = !hasChildrenByCall(fsen);
+ boolean hasNoNestedChildren = fsen.getLocalChildren().isEmpty();
+ boolean hasNoChildrenByCall = !hasChildrenByCall( fsen );
- fsen.setIsLeafSESE(hasNoNestedChildren && hasNoChildrenByCall);
+ fsen.setIsLeafSESE( hasNoNestedChildren && hasNoChildrenByCall );
}
-
- // for( Iterator<FlatSESEEnterNode> itr = allSESEs.iterator();
- // itr.hasNext();
- // ) {
- // FlatSESEEnterNode fsen = itr.next();
- //
- // boolean hasNoNestedChildren = fsen.getChildren().isEmpty();
- // boolean hasNoChildrenByCall = !hasChildrenByCall( fsen );
- //
- // fsen.setIsLeafSESE( hasNoNestedChildren &&
- // hasNoChildrenByCall );
- // }
}
+ protected boolean hasChildrenByCall( FlatSESEEnterNode fsen ) {
- protected boolean hasChildrenByCall(FlatSESEEnterNode fsen) {
- boolean hasChildrenByCall=false;
+ boolean hasChildrenByCall = false;
// visit every flat node in SESE body, find method calls that
// may transitively call methods with SESEs enclosed
Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add(fsen);
+ flatNodesToVisit.add( fsen );
Set<FlatNode> visited = new HashSet<FlatNode>();
-
- while (!flatNodesToVisit.isEmpty()) {
+
+ while( !flatNodesToVisit.isEmpty() ) {
Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
FlatNode fn = fnItr.next();
- flatNodesToVisit.remove(fn);
- visited.add(fn);
+ flatNodesToVisit.remove( fn );
+ visited.add( fn );
- if (fn.kind() == FKind.FlatCall) {
- FlatCall fc = (FlatCall) fn;
- MethodDescriptor mdCallee = fc.getMethod();
- Set reachable = new HashSet();
-
- reachable.add(mdCallee);
- reachable.addAll(callGraph.getAllMethods(mdCallee));
+ if( fn.kind() == FKind.FlatCall ) {
+ FlatCall fc = (FlatCall) fn;
+ MethodDescriptor mdCallee = fc.getMethod();
+ Set reachable = new HashSet();
- reachable.retainAll(methodsContainingSESEs);
+ reachable.add( mdCallee );
+ reachable.addAll( callGraph.getAllMethods( mdCallee ) );
+ reachable.retainAll( methodsContainingSESEs );
- if (!reachable.isEmpty()) {
+ if( !reachable.isEmpty() ) {
hasChildrenByCall = true;
- if (!fsen.getIsCallerSESEplaceholder()) {
- Set reachableSESEMethodSet =
- callGraph.getFirstReachableMethodContainingSESE(mdCallee, methodsContainingSESEs);
-
- reachableSESEMethodSet.add(mdCallee);
-
- for (Iterator iterator = reachableSESEMethodSet.iterator(); iterator.hasNext();) {
- MethodDescriptor md = (MethodDescriptor) iterator.next();
- FlatMethod fm = state.getMethodFlat(md);
- FlatSESEEnterNode fsenBogus = (FlatSESEEnterNode) fm.getNext(0);
- fsenBogus.addSESEParent(fsen);
+ Set reachableSESEMethodSet =
+ callGraph.getFirstReachableMethodContainingSESE( mdCallee, methodsContainingSESEs );
+
+ reachableSESEMethodSet.add( mdCallee );
+ reachableSESEMethodSet.retainAll( methodsContainingSESEs );
+
+ for( Iterator iterator = reachableSESEMethodSet.iterator(); iterator.hasNext(); ) {
+ MethodDescriptor md = (MethodDescriptor) iterator.next();
+ Set<FlatSESEEnterNode> seseSet = md2localRootSESEs.get( md );
+ if( seseSet != null ) {
+ fsen.addChildren( seseSet );
+ for( Iterator iterator2 = seseSet.iterator(); iterator2.hasNext(); ) {
+ FlatSESEEnterNode child = (FlatSESEEnterNode) iterator2.next();
+ child.addParent( fsen );
+ }
}
-
- reachableSESEMethodSet.retainAll(methodsContainingSESEs);
-
- for (Iterator iterator = reachableSESEMethodSet.iterator(); iterator.hasNext();) {
- MethodDescriptor md = (MethodDescriptor) iterator.next();
- Set<FlatSESEEnterNode> seseSet = md2seseSet.get(md);
- if (seseSet != null) {
- fsen.addSESEChildren(seseSet);
- for (Iterator iterator2 = seseSet.iterator(); iterator2.hasNext();) {
- FlatSESEEnterNode child = (FlatSESEEnterNode) iterator2.next();
- child.addSESEParent(fsen);
- }
- }
- }
-
}
}
-
}
- if (fn == fsen.getFlatExit()) {
+ if( fn == fsen.getFlatExit() ) {
// don't enqueue any futher nodes
continue;
}
+ for( int i = 0; i < fn.numNext(); i++ ) {
+ FlatNode nn = fn.getNext( i );
+
+ if( !visited.contains( nn ) ) {
+ flatNodesToVisit.add( nn );
+ }
+ }
+ }
+
+ return hasChildrenByCall;
+ }
+
+
+
+ protected void findPossibleExecutingRBlocksAndStallSites() {
+ for( Iterator<FlatSESEEnterNode> fsenItr = allSESEs.iterator(); fsenItr.hasNext(); ) {
+ FlatSESEEnterNode fsen = fsenItr.next();
+
+ // walk the program points, including across method calls, reachable within
+ // this sese/rblock/task and mark that this rblock might be executing.
+ // Important: skip the body of child rblocks, BUT DO mark the child ENTER
+ // and EXIT flat nodes as the parent being the current executing rblock!
+ Hashtable<FlatNode, FlatMethod> flatNodesToVisit =
+ new Hashtable<FlatNode, FlatMethod>();
+
+ for( int i = 0; i < fsen.numNext(); i++ ) {
+ FlatNode nn = fsen.getNext( i );
+ flatNodesToVisit.put( nn, fsen.getfmEnclosing() );
+ mergeIsPotentialStallSite( nn, false );
+ }
+
+ Set<FlatNode> visited = new HashSet<FlatNode>();
+
+ while( !flatNodesToVisit.isEmpty() ) {
+ Map.Entry me = (Map.Entry) flatNodesToVisit.entrySet().iterator().next();
+ FlatNode fn = (FlatNode) me.getKey();
+ FlatMethod fm = (FlatMethod) me.getValue();
+
+ flatNodesToVisit.remove( fn );
+ visited.add( fn );
+
+
+ // the "is potential stall site" strategy is to propagate
+ // "false" from the beginning of a task until you hit a
+ // child, then from the child's exit propagate "true" for
+ // the parent statements after children. When you pull a node
+ // out of the bag for traversal and it happens to be an
+ // enter or an exit node, fix the dumb propagation that
+ // your IR predecessor pushed on you
+ Boolean isPotentialStallSite = isPotentialStallSite( fn );
+
+ if( fn instanceof FlatSESEEnterNode ||
+ fn instanceof FlatSESEExitNode ) {
+ // fix it so this is never a potential stall site, but from
+ // a child definition onward propagate 'true'
+ setIsPotentialStallSite( fn, false );
+ isPotentialStallSite = true;
+ }
+
+
+ if( fn == fsen.getFlatExit() ) {
+ // don't enqueue any futher nodes when you find your exit,
+ // NOR mark your own flat as a statement you are currently
+ // executing, your parent(s) will mark it
+ continue;
+ }
+
+
+ // the purpose of this traversal is to find program
+ // points where rblock 'fsen' might be executing
+ addPossibleExecutingRBlock( fn, fsen );
+
+
+ if( fn instanceof FlatSESEEnterNode ) {
+ // don't visit internal nodes of child,
+ // just enqueue the exit node
+ FlatSESEEnterNode child = (FlatSESEEnterNode) fn;
+ assert fsen.getChildren().contains( child );
+ assert child.getParents().contains( fsen );
+ flatNodesToVisit.put( child.getFlatExit(), fm );
+
+ // explicitly do this to handle the case that you
+ // should mark yourself as possibly executing at
+ // your own exit, because one instance can
+ // recursively invoke another
+ addPossibleExecutingRBlock( child.getFlatExit(), fsen );
+
+ continue;
+ }
+
+ if( fn instanceof FlatCall ) {
+ // start visiting nodes in other contexts
+ FlatCall fc = (FlatCall) fn;
+ MethodDescriptor mdCallee = fc.getMethod();
+
+ Set<MethodDescriptor> implementations = new HashSet<MethodDescriptor>();
+
+ if( mdCallee.isStatic() ) {
+ implementations.add( mdCallee );
+ } else {
+ TypeDescriptor typeDesc = fc.getThis().getType();
+ implementations.addAll( callGraph.getMethods( mdCallee, typeDesc ) );
+ }
+
+ for( Iterator imps = implementations.iterator(); imps.hasNext(); ) {
+ MethodDescriptor mdImp = (MethodDescriptor) imps.next();
+ FlatMethod fmImp = state.getMethodFlat( mdImp );
+ flatNodesToVisit.put( fmImp, fmImp );
+
+ // propagate your IR graph predecessor's stall site potential
+ mergeIsPotentialStallSite( fmImp, isPotentialStallSite );
+ }
+ // don't 'continue' out of this loop, also enqueue
+ // flat nodes that flow in the current method context
+ }
+
+ // otherwise keep visiting nodes in same context
+ for( int i = 0; i < fn.numNext(); i++ ) {
+ FlatNode nn = fn.getNext( i );
+
+ if( !visited.contains( nn ) ) {
+ flatNodesToVisit.put( nn, fm );
+
+ // propagate your IR graph predecessor's stall site potential
+ mergeIsPotentialStallSite( nn, isPotentialStallSite );
+ }
+ }
+ }
+ }
+ }
+
+
+
+ protected void addPossibleExecutingRBlock( FlatNode fn,
+ FlatSESEEnterNode fsen ) {
+
+ Set<FlatSESEEnterNode> currentSESEs = fn2currentSESEs.get( fn );
+ if( currentSESEs == null ) {
+ currentSESEs = new HashSet<FlatSESEEnterNode>();
+ }
+
+ currentSESEs.add( fsen );
+ fn2currentSESEs.put( fn, currentSESEs );
+ }
+
+
+ // definitively set whether a statement is a potential stall site
+ // such as a task exit is FALSE and the statement following an exit
+ // is TRUE
+ protected void setIsPotentialStallSite( FlatNode fn,
+ Boolean ipss ) {
+ fn2isPotentialStallSite.put( fn, ipss );
+ }
+
+
+ // Use this to OR the previous result with a new result
+ protected void mergeIsPotentialStallSite( FlatNode fn,
+ Boolean ipss ) {
+ Boolean ipssPrev = isPotentialStallSite( fn );
+ setIsPotentialStallSite( fn, ipssPrev || ipss );
+ }
+
+
+
+
+
+ /////////////////////////////////////////////////
+ // for DEBUG
+ /////////////////////////////////////////////////
+ protected void debugPrintPotentialStallSites(Set<MethodDescriptor> descriptorsToAnalyze) {
+ Iterator<MethodDescriptor> mdItr = descriptorsToAnalyze.iterator();
+ while (mdItr.hasNext()) {
+ FlatMethod fm = state.getMethodFlat(mdItr.next());
+ printStatusMap(fm);
+ }
+ System.exit( 0 );
+ }
+
+ protected void printStatusMap(FlatMethod fm) {
+
+ System.out.println("\n\n=== "+fm+" ===");
+
+ Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
+ flatNodesToVisit.add(fm);
+
+ Set<FlatNode> visited = new HashSet<FlatNode>();
+
+ while (!flatNodesToVisit.isEmpty()) {
+ Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
+ FlatNode fn = fnItr.next();
+
+ flatNodesToVisit.remove(fn);
+ visited.add(fn);
+
+ System.out.println(fn+"[["+isPotentialStallSite(fn)+"]]");
+
for (int i = 0; i < fn.numNext(); i++) {
FlatNode nn = fn.getNext(i);
}
}
}
-
- return hasChildrenByCall;
}
-
-}
+}
\ No newline at end of file
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+public class SESEandAgePair {
+
+ private FlatSESEEnterNode sese;
+ private Integer age;
+
+ public SESEandAgePair( FlatSESEEnterNode sese,
+ Integer age ) {
+ this.sese = sese;
+ this.age = age;
+ }
+
+ public FlatSESEEnterNode getSESE() {
+ return sese;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public boolean equals( Object o ) {
+ if( o == null ) {
+ return false;
+ }
+
+ if( !(o instanceof SESEandAgePair) ) {
+ return false;
+ }
+
+ SESEandAgePair p = (SESEandAgePair) o;
+
+ return age.equals( p.age ) &&
+ sese.equals( p.sese );
+ }
+
+ public int hashCode() {
+ return (sese.hashCode() << 2)*(age.hashCode() << 5);
+ }
+
+
+ public String toString() {
+ return "SESE_"+
+ sese.getPrettyIdentifier()+
+ sese.getIdentifier()+
+ "_"+
+ age;
+ }
+}
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+public class SVKey {
+
+ private FlatSESEEnterNode sese;
+ private TempDescriptor var;
+
+ public SVKey( FlatSESEEnterNode sese,
+ TempDescriptor var ) {
+ this.sese = sese;
+ this.var = var;
+ }
+
+ public FlatSESEEnterNode getSESE() {
+ return sese;
+ }
+
+ public TempDescriptor getVar() {
+ return var;
+ }
+
+ public boolean equals( Object o ) {
+ if( o == null ) {
+ return false;
+ }
+
+ if( !(o instanceof SVKey) ) {
+ return false;
+ }
+
+ SVKey k = (SVKey) o;
+
+ return var.equals( k.var ) &&
+ sese.equals( k.sese );
+ }
+
+ public int hashCode() {
+ return (sese.hashCode() << 2)*(var.hashCode() << 5);
+ }
+
+
+ public String toString() {
+ return "key["+sese.getPrettyIdentifier()+", "+var+"]";
+ }
+}
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+// the reason for this class is to allow a VariableSourceToken
+// to be null in some circumstances
+
+public class VSTWrapper {
+ public VariableSourceToken vst;
+
+ public VSTWrapper() {
+ vst = null;
+ }
+}
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+// This class formerly had lazy consistency properties, but
+// it is being changed so that the full set and the extra
+// hash tables to access the full set efficiently by different
+// elements will be consistent after EVERY operation. Also,
+// a consistent assert method allows a debugger to ask whether
+// an operation has produced an inconsistent VarSrcTokTable.
+
+// in an effort to make sure operations keep the table consistent,
+// all public methods that are also used by other methods for
+// intermediate results (add and remove are used in other methods)
+// there should be a public version that calls the private version
+// so consistency is checked after public ops, but not private ops
+public class VarSrcTokTable {
+
+ // a set of every token in the table
+ private HashSet<VariableSourceToken> trueSet;
+
+ // these hashtables provide an efficient retreival from the true set
+ private Hashtable< TempDescriptor, Set<VariableSourceToken> > var2vst;
+ private Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> > sese2vst;
+ private Hashtable< SVKey, Set<VariableSourceToken> > sv2vst;
+
+ // maximum age from aging operation
+ private static final Integer MAX_AGE = new Integer( 2 );
+
+ public static final Integer SrcType_READY = new Integer( 34 );
+ public static final Integer SrcType_STATIC = new Integer( 35 );
+ public static final Integer SrcType_DYNAMIC = new Integer( 36 );
+
+
+ public VarSrcTokTable() {
+ trueSet = new HashSet<VariableSourceToken>();
+
+ sese2vst = new Hashtable< FlatSESEEnterNode, Set<VariableSourceToken> >();
+ var2vst = new Hashtable< TempDescriptor, Set<VariableSourceToken> >();
+ sv2vst = new Hashtable< SVKey, Set<VariableSourceToken> >();
+
+ assertConsistency();
+ }
+
+
+ // make a deep copy of the in table
+ public VarSrcTokTable( VarSrcTokTable in ) {
+ this();
+ merge( in );
+ assertConsistency();
+ }
+
+
+ public void add( VariableSourceToken vst ) {
+ addPrivate( vst );
+ assertConsistency();
+ }
+
+ private void addPrivate( VariableSourceToken vst ) {
+
+ // make sure we aren't clobbering anything!
+ if( trueSet.contains( vst ) ) {
+ // if something with the same hashcode is in the true set, they might
+ // have different reference variable sets because that set is not considered
+ // in a token's equality, so make sure we smooth that out right here
+ Iterator<VariableSourceToken> vstItr = trueSet.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vstAlready = vstItr.next();
+
+ if( vstAlready.equals( vst ) ) {
+
+ // take out the one that is in (we dont' want collisions in
+ // any of the other hash map sets either)
+ removePrivate( vstAlready );
+
+ // combine reference variable sets
+ vst.getRefVars().addAll( vstAlready.getRefVars() );
+
+ // now jump back as we are adding in a brand new token
+ break;
+ }
+ }
+ }
+
+ trueSet.add( vst );
+
+ Set<VariableSourceToken> s;
+
+ s = sese2vst.get( vst.getSESE() );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ }
+ s.add( vst );
+ sese2vst.put( vst.getSESE(), s );
+
+ Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();
+ while( refVarItr.hasNext() ) {
+ TempDescriptor refVar = refVarItr.next();
+ s = var2vst.get( refVar );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ }
+ s.add( vst );
+ var2vst.put( refVar, s );
+
+ SVKey key = new SVKey( vst.getSESE(), refVar );
+ s = sv2vst.get( key );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ }
+ s.add( vst );
+ sv2vst.put( key, s );
+ }
+ }
+
+ public void addAll( Set<VariableSourceToken> s ) {
+ Iterator<VariableSourceToken> itr = s.iterator();
+ while( itr.hasNext() ) {
+ addPrivate( itr.next() );
+ }
+ assertConsistency();
+ }
+
+
+ public Set<VariableSourceToken> get() {
+ return trueSet;
+ }
+
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese ) {
+ Set<VariableSourceToken> s = sese2vst.get( sese );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ sese2vst.put( sese, s );
+ }
+ return s;
+ }
+
+ public Set<VariableSourceToken> get( TempDescriptor refVar ) {
+ Set<VariableSourceToken> s = var2vst.get( refVar );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ var2vst.put( refVar, s );
+ }
+ return s;
+ }
+
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese,
+ TempDescriptor refVar ) {
+ SVKey key = new SVKey( sese, refVar );
+ Set<VariableSourceToken> s = sv2vst.get( key );
+ if( s == null ) {
+ s = new HashSet<VariableSourceToken>();
+ sv2vst.put( key, s );
+ }
+ return s;
+ }
+
+ public Set<VariableSourceToken> get( FlatSESEEnterNode sese,
+ Integer age ) {
+
+ HashSet<VariableSourceToken> s0 = (HashSet<VariableSourceToken>) sese2vst.get( sese );
+ if( s0 == null ) {
+ s0 = new HashSet<VariableSourceToken>();
+ sese2vst.put( sese, s0 );
+ }
+
+ Set<VariableSourceToken> s = (Set<VariableSourceToken>) s0.clone();
+ Iterator<VariableSourceToken> sItr = s.iterator();
+ while( sItr.hasNext() ) {
+ VariableSourceToken vst = sItr.next();
+ if( !vst.getAge().equals( age ) ) {
+ s.remove( vst );
+ }
+ }
+
+ return s;
+ }
+
+
+ // merge now makes a deep copy of incoming stuff because tokens may
+ // be modified (reference var sets) by later ops that change more
+ // than one table, causing inconsistency
+ public void merge( VarSrcTokTable in ) {
+
+ if( in == null ) {
+ return;
+ }
+
+ Iterator<VariableSourceToken> vstItr = in.trueSet.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ this.addPrivate( vst.copy() );
+ }
+
+ assertConsistency();
+ }
+
+
+ // remove operations must leave the trueSet
+ // and the hash maps consistent
+ public void remove( VariableSourceToken vst ) {
+ removePrivate( vst );
+ assertConsistency();
+ }
+
+ private void removePrivate( VariableSourceToken vst ) {
+ trueSet.remove( vst );
+
+ Set<VariableSourceToken> s;
+
+ s = get( vst.getSESE() );
+ if( s != null ) { s.remove( vst ); }
+
+ Iterator<TempDescriptor> refVarItr = vst.getRefVars().iterator();
+ while( refVarItr.hasNext() ) {
+ TempDescriptor refVar = refVarItr.next();
+
+ s = get( refVar );
+ if( s != null ) {
+ s.remove( vst );
+ if( s.isEmpty() ) {
+ var2vst.remove( refVar );
+ }
+ }
+
+ s = get( vst.getSESE(), refVar );
+ if( s != null ) {
+ s.remove( vst );
+ if( s.isEmpty() ) {
+ sv2vst.remove( new SVKey( vst.getSESE(), refVar ) );
+ }
+ }
+ }
+ }
+
+
+ public void remove( FlatSESEEnterNode sese ) {
+ removePrivate( sese );
+ assertConsistency();
+ }
+
+ public void removePrivate( FlatSESEEnterNode sese ) {
+ Set<VariableSourceToken> s = sese2vst.get( sese );
+ if( s == null ) {
+ return;
+ }
+
+ Iterator<VariableSourceToken> itr = s.iterator();
+ while( itr.hasNext() ) {
+ VariableSourceToken vst = itr.next();
+ removePrivate( vst );
+ }
+
+ sese2vst.remove( sese );
+ }
+
+
+ public void remove( TempDescriptor refVar ) {
+ removePrivate( refVar );
+ assertConsistency();
+ }
+
+ private void removePrivate( TempDescriptor refVar ) {
+ Set<VariableSourceToken> s = var2vst.get( refVar );
+ if( s == null ) {
+ return;
+ }
+
+ Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();
+
+ // iterate over tokens that this temp can reference, make a set
+ // of tokens that need this temp stripped out of them
+ Iterator<VariableSourceToken> itr = s.iterator();
+ while( itr.hasNext() ) {
+ VariableSourceToken vst = itr.next();
+ Set<TempDescriptor> refVars = vst.getRefVars();
+ assert refVars.contains( refVar );
+ forRemoval.add( vst );
+ }
+
+ itr = forRemoval.iterator();
+ while( itr.hasNext() ) {
+
+ // here's a token marked for removal
+ VariableSourceToken vst = itr.next();
+ Set<TempDescriptor> refVars = vst.getRefVars();
+
+ // if there was only one one variable
+ // referencing this token, just take it
+ // out of the table all together
+ if( refVars.size() == 1 ) {
+ removePrivate( vst );
+ }
+
+ sv2vst.remove( new SVKey( vst.getSESE(), refVar ) );
+
+ refVars.remove( refVar );
+ }
+
+ var2vst.remove( refVar );
+ }
+
+
+ public void remove( FlatSESEEnterNode sese,
+ TempDescriptor var ) {
+
+ // don't seem to need this, don't bother maintaining
+ // until its clear we need it
+ assert false;
+ }
+
+
+ // age tokens with respect to SESE curr, where
+ // any curr tokens increase age by 1
+ public void age( FlatSESEEnterNode curr ) {
+
+ Set<VariableSourceToken> forRemoval =
+ new HashSet<VariableSourceToken>();
+
+ Set<VariableSourceToken> forAddition =
+ new HashSet<VariableSourceToken>();
+
+ Iterator<VariableSourceToken> itr = trueSet.iterator();
+ while( itr.hasNext() ) {
+ VariableSourceToken vst = itr.next();
+
+ if( vst.getSESE().equals( curr ) ) {
+
+ // only age if the token isn't already the maximum age
+ if( vst.getAge() < MAX_AGE ) {
+
+ forRemoval.add( vst );
+
+ forAddition.add( new VariableSourceToken( vst.getRefVars(),
+ curr,
+ vst.getAge() + 1,
+ vst.getAddrVar()
+ )
+ );
+ }
+ }
+ }
+
+ itr = forRemoval.iterator();
+ while( itr.hasNext() ) {
+ VariableSourceToken vst = itr.next();
+ remove( vst );
+ }
+
+ itr = forRemoval.iterator();
+ while( itr.hasNext() ) {
+ VariableSourceToken vst = itr.next();
+ add( vst );
+ }
+
+ assertConsistency();
+ }
+
+
+ // at an SESE enter node, all ref vars in the SESE's in-set will
+ // be copied into the SESE's local scope, change source to itself
+ public void ownInSet( FlatSESEEnterNode curr ) {
+ Iterator<TempDescriptor> inVarItr = curr.getInVarSet().iterator();
+ while( inVarItr.hasNext() ) {
+ TempDescriptor inVar = inVarItr.next();
+
+ remove( inVar );
+ assertConsistency();
+
+ Set<TempDescriptor> refVars = new HashSet<TempDescriptor>();
+ refVars.add( inVar );
+ add( new VariableSourceToken( refVars,
+ curr,
+ new Integer( 0 ),
+ inVar
+ )
+ );
+ assertConsistency();
+ }
+ }
+
+
+ // for the given SESE, change child tokens into this parent
+ public void remapChildTokens( FlatSESEEnterNode curr ) {
+
+ Iterator<FlatSESEEnterNode> childItr = curr.getChildren().iterator();
+ if( childItr.hasNext() ) {
+ FlatSESEEnterNode child = childItr.next();
+
+ // set of VSTs for removal
+ HashSet<VariableSourceToken> removalSet=new HashSet<VariableSourceToken>();
+ // set of VSTs for additon
+ HashSet<VariableSourceToken> additionSet=new HashSet<VariableSourceToken>();
+
+ Iterator<VariableSourceToken> vstItr = get( child ).iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ removalSet.add(vst);
+ additionSet.add(new VariableSourceToken( vst.getRefVars(),
+ curr,
+ new Integer( 0 ),
+ vst.getAddrVar()
+ ));
+ }
+
+ // remove( eah item in forremoval )
+ vstItr = removalSet.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ remove( vst );
+ }
+ // add( each ite inm for additon _
+ vstItr = additionSet.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ add( vst );
+ }
+ }
+
+ assertConsistency();
+ }
+
+
+ // this method is called at the SESE exit of SESE 'curr'
+ // if the sources for a variable written by curr can also
+ // come from curr's parent or curr's siblings then we're not
+ // sure that curr will actually modify the variable. There are
+ // many ways to handle this, but for now, mark the variable as
+ // virtually read so curr insists on having ownership of it
+ // whether it ends up writing to it or not. It will always, then,
+ // appear in curr's out-set.
+ public Set<TempDescriptor>
+ calcVirtReadsAndPruneParentAndSiblingTokens( FlatSESEEnterNode exiter,
+ Set<TempDescriptor> liveVars ) {
+
+ Set<TempDescriptor> virtReadSet = new HashSet<TempDescriptor>();
+
+ Set<FlatSESEEnterNode> parents = null; //exiter.getParents();
+ if( parents.isEmpty() ) {
+ // having no parent means no siblings, too
+ return virtReadSet;
+ }
+
+ Set<FlatSESEEnterNode> alternateSESEs = new HashSet<FlatSESEEnterNode>();
+ alternateSESEs.addAll( parents );
+ Iterator<FlatSESEEnterNode> childItr = null; //parents.getChildren().iterator();
+ while( childItr.hasNext() ) {
+ FlatSESEEnterNode sibling = childItr.next();
+ if( !sibling.equals( exiter ) ) {
+ alternateSESEs.add( sibling );
+ }
+ }
+
+ // VSTs to remove if they are alternate sources for exiter VSTs
+ // whose variables will become virtual reads
+ Set<VariableSourceToken> forRemoval = new HashSet<VariableSourceToken>();
+
+ // look at all of this SESE's VSTs at exit...
+ Iterator<VariableSourceToken> vstItr = get( exiter ).iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vstExiterSrc = vstItr.next();
+
+ // only interested in tokens that come from our current instance
+ if( vstExiterSrc.getAge() != 0 ) {
+ continue;
+ }
+
+ // for each variable that might come from those sources...
+ Iterator<TempDescriptor> refVarItr = vstExiterSrc.getRefVars().iterator();
+ while( refVarItr.hasNext() ) {
+ TempDescriptor refVar = refVarItr.next();
+
+ // only matters for live variables at SESE exit program point
+ if( !liveVars.contains( refVar ) ) {
+ continue;
+ }
+
+ // examine other sources for a variable...
+ Iterator<VariableSourceToken> srcItr = get( refVar ).iterator();
+ while( srcItr.hasNext() ) {
+ VariableSourceToken vstPossibleOtherSrc = srcItr.next();
+
+ if( vstPossibleOtherSrc.getSESE().equals( exiter ) &&
+ vstPossibleOtherSrc.getAge() > 0
+ ) {
+ // this is an alternate source if its
+ // an older instance of this SESE
+ virtReadSet.add( refVar );
+ forRemoval.add( vstPossibleOtherSrc );
+
+ } else if( alternateSESEs.contains( vstPossibleOtherSrc.getSESE() ) ) {
+ // this is an alternate source from parent or sibling
+ virtReadSet.add( refVar );
+ forRemoval.add( vstPossibleOtherSrc );
+
+ } else {
+ if( !vstPossibleOtherSrc.getSESE().equals( exiter ) ||
+ !vstPossibleOtherSrc.getAge().equals( 0 )
+ ) {
+ System.out.println( "For refVar="+refVar+" at exit of "+exiter+
+ ", unexpected possible variable source "+vstPossibleOtherSrc );
+ assert false;
+ }
+ }
+ }
+ }
+ }
+
+ vstItr = forRemoval.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ remove( vst );
+ }
+ assertConsistency();
+
+ return virtReadSet;
+ }
+
+
+ // get the set of VST's that come from a child
+ public Set<VariableSourceToken> getChildrenVSTs( FlatSESEEnterNode curr ) {
+
+ Set<VariableSourceToken> out = new HashSet<VariableSourceToken>();
+
+ Iterator<FlatSESEEnterNode> cItr = curr.getChildren().iterator();
+ while( cItr.hasNext() ) {
+ FlatSESEEnterNode child = cItr.next();
+ out.addAll( get( child ) );
+ }
+
+ return out;
+ }
+
+
+ // given a table from a subsequent program point, decide
+ // which variables are going from a non-dynamic to a
+ // dynamic source and return them
+ public Hashtable<TempDescriptor, VSTWrapper>
+ getReadyOrStatic2DynamicSet( VarSrcTokTable nextTable,
+ Set<TempDescriptor> nextLiveIn,
+ FlatSESEEnterNode current
+ ) {
+
+ Hashtable<TempDescriptor, VSTWrapper> out =
+ new Hashtable<TempDescriptor, VSTWrapper>();
+
+ Iterator itr = var2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ TempDescriptor var = (TempDescriptor) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+
+ // only worth tracking if live
+ if( nextLiveIn.contains( var ) ) {
+
+ VSTWrapper vstIfStaticBefore = new VSTWrapper();
+ VSTWrapper vstIfStaticAfter = new VSTWrapper();
+
+ Integer srcTypeBefore = this.getRefVarSrcType( var, current, vstIfStaticBefore );
+ Integer srcTypeAfter = nextTable.getRefVarSrcType( var, current, vstIfStaticAfter );
+
+ if( !srcTypeBefore.equals( SrcType_DYNAMIC ) &&
+ srcTypeAfter.equals( SrcType_DYNAMIC )
+ ) {
+ // remember the variable and a source
+ // it had before crossing the transition
+ // 1) if it was ready, vstIfStatic.vst is null
+ // 2) if is was static, use vstIfStatic.vst
+ out.put( var, vstIfStaticBefore );
+ }
+ }
+ }
+
+ return out;
+ }
+
+
+ // for some reference variable, return the type of source
+ // it might have in this table, which might be:
+ // 1. Ready -- this variable is
+ // definitely available when you are issued.
+ // 2. Static -- there is definitely one child SESE with
+ // a known age that will produce the value
+ // 3. Dynamic -- we don't know where the value will come
+ // from statically, so we'll track it dynamically
+ public Integer getRefVarSrcType( TempDescriptor refVar,
+ FlatSESEEnterNode current,
+ VSTWrapper vstIfStatic ) {
+ assert refVar != null;
+ assert vstIfStatic != null;
+
+ vstIfStatic.vst = null;
+
+ // when the current SESE is null, that simply means it is
+ // an unknown placeholder, in which case the system will
+ // ensure that any variables are READY
+ if( current == null ) {
+ return SrcType_READY;
+ }
+
+ // if there appear to be no sources, it means this variable
+ // comes from outside of any statically-known SESE scope,
+ // which means the system guarantees its READY, so jump over
+ // while loop
+ Set<VariableSourceToken> srcs = get( refVar );
+ Iterator<VariableSourceToken> itrSrcs = srcs.iterator();
+ while( itrSrcs.hasNext() ) {
+ VariableSourceToken vst = itrSrcs.next();
+
+ // to make the refVar non-READY we have to find at least
+ // one child token
+ if( current.getChildren().contains( vst.getSESE() ) ) {
+
+ // if we ever have at least one child source with an
+ // unknown age, have to treat var as dynamic
+ if( vst.getAge().equals( OoOJavaAnalysis.maxSESEage ) ) {
+ return SrcType_DYNAMIC;
+ }
+
+ // if we have a known-age child source, this var is
+ // either static or dynamic now: it's static if this
+ // source is the only source, otherwise dynamic
+ if( srcs.size() > 1 ) {
+ return SrcType_DYNAMIC;
+ }
+
+ vstIfStatic.vst = vst;
+ return SrcType_STATIC;
+ }
+ }
+
+ // if we never found a child source, all other
+ // sources must be READY before we could even
+ // begin executing!
+ return SrcType_READY;
+ }
+
+
+ // any reference variables that are not live can be pruned
+ // from the table, and if any VSTs are then no longer
+ // referenced, they can be dropped as well
+ // THIS CAUSES INCONSISTENCY, FIX LATER, NOT REQUIRED
+ public void pruneByLiveness( Set<TempDescriptor> rootLiveSet ) {
+
+ // the set of reference variables in the table minus the
+ // live set gives the set of reference variables to remove
+ Set<TempDescriptor> deadRefVars = new HashSet<TempDescriptor>();
+ deadRefVars.addAll( var2vst.keySet() );
+
+ if( rootLiveSet != null ) {
+ deadRefVars.removeAll( rootLiveSet );
+ }
+
+ // just use the remove operation to prune the table now
+ Iterator<TempDescriptor> deadItr = deadRefVars.iterator();
+ while( deadItr.hasNext() ) {
+ TempDescriptor dead = deadItr.next();
+ removePrivate( dead );
+ }
+
+ assertConsistency();
+ }
+
+
+
+ // use as an aid for debugging, where true-set is checked
+ // against the alternate mappings: assert that nothing is
+ // missing or extra in the alternates
+ public void assertConsistency() {
+
+ Iterator itr;
+ Set s;
+
+ Set<VariableSourceToken> trueSetByAlts = new HashSet<VariableSourceToken>();
+ itr = sese2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ // the trueSet should have all entries in s1
+ assert trueSet.containsAll( s1 );
+
+ // s1 should not have anything that doesn't appear in trueset
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
+ sInt.removeAll( trueSet );
+
+ assert sInt.isEmpty();
+
+ // add s1 to a running union--at the end check if trueSet has extra
+ trueSetByAlts.addAll( s1 );
+ }
+ // make sure trueSet isn't too big
+ assert trueSetByAlts.containsAll( trueSet );
+
+
+ trueSetByAlts = new HashSet<VariableSourceToken>();
+ itr = var2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ TempDescriptor var = (TempDescriptor) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ // the trueSet should have all entries in s1
+ assert trueSet.containsAll( s1 );
+
+ // s1 should not have anything that doesn't appear in trueset
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
+ sInt.removeAll( trueSet );
+
+ assert sInt.isEmpty();
+
+ // add s1 to a running union--at the end check if trueSet has extra
+ trueSetByAlts.addAll( s1 );
+ }
+ // make sure trueSet isn't too big
+ assert trueSetByAlts.containsAll( trueSet );
+
+
+ trueSetByAlts = new HashSet<VariableSourceToken>();
+ itr = sv2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ SVKey key = (SVKey) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ // the trueSet should have all entries in s1
+ assert trueSet.containsAll( s1 );
+
+ // s1 should not have anything that doesn't appear in trueset
+ Set<VariableSourceToken> sInt = (Set<VariableSourceToken>) s1.clone();
+ sInt.removeAll( trueSet );
+
+ assert sInt.isEmpty();
+
+ // add s1 to a running union--at the end check if trueSet has extra
+ trueSetByAlts.addAll( s1 );
+ }
+ // make sure trueSet isn't too big
+ assert trueSetByAlts.containsAll( trueSet );
+
+
+ // also check that the reference var sets are consistent
+ Hashtable<VariableSourceToken, Set<TempDescriptor> > vst2refVars =
+ new Hashtable<VariableSourceToken, Set<TempDescriptor> >();
+ itr = var2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ TempDescriptor refVar = (TempDescriptor) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+ Iterator<VariableSourceToken> vstItr = s1.iterator();
+ while( vstItr.hasNext() ) {
+ VariableSourceToken vst = vstItr.next();
+ assert vst.getRefVars().contains( refVar );
+
+ Set<TempDescriptor> refVarsPart = vst2refVars.get( vst );
+ if( refVarsPart == null ) {
+ refVarsPart = new HashSet<TempDescriptor>();
+ }
+ refVarsPart.add( refVar );
+ vst2refVars.put( vst, refVarsPart );
+ }
+ }
+ itr = vst2refVars.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ VariableSourceToken vst = (VariableSourceToken) me.getKey();
+ Set<TempDescriptor> s1 = (Set<TempDescriptor>) me.getValue();
+
+ assert vst.getRefVars().equals( s1 );
+ }
+ }
+
+
+ public boolean equals( Object o ) {
+ if( o == null ) {
+ return false;
+ }
+
+ if( !(o instanceof VarSrcTokTable) ) {
+ return false;
+ }
+
+ VarSrcTokTable table = (VarSrcTokTable) o;
+ return trueSet.equals( table.trueSet );
+ }
+
+ public int hashCode() {
+ return trueSet.hashCode();
+ }
+
+ public Iterator<VariableSourceToken> iterator() {
+ return trueSet.iterator();
+ }
+
+ public String toString() {
+ return toStringPretty();
+ }
+
+ public String toStringVerbose() {
+ return "trueSet ="+trueSet.toString()+"\n"+
+ "sese2vst="+sese2vst.toString()+"\n"+
+ "var2vst ="+var2vst.toString()+"\n"+
+ "sv2vst ="+sv2vst.toString();
+ }
+
+ public String toStringPretty() {
+ String tokHighlighter = "o";
+
+ String str = "VarSrcTokTable\n";
+ Iterator<VariableSourceToken> vstItr = trueSet.iterator();
+ while( vstItr.hasNext() ) {
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";
+ }
+ return str;
+ }
+
+ public String toStringPrettyVerbose() {
+ String tokHighlighter = "o";
+
+ String str = "VarSrcTokTable\n";
+
+ Set s;
+ Iterator itr;
+ Iterator<VariableSourceToken> vstItr;
+
+ str += " trueSet\n";
+ vstItr = trueSet.iterator();
+ while( vstItr.hasNext() ) {
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";
+ }
+
+ str += " sese2vst\n";
+ itr = sese2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey();
+ HashSet<VariableSourceToken> s1 = (HashSet<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ str += " "+sese.getPrettyIdentifier()+" -> \n";
+
+ vstItr = s1.iterator();
+ while( vstItr.hasNext() ) {
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";
+ }
+ }
+
+ str += " var2vst\n";
+ itr = var2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ TempDescriptor var = (TempDescriptor) me.getKey();
+ Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ str += " "+var+" -> \n";
+
+ vstItr = s1.iterator();
+ while( vstItr.hasNext() ) {
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";
+ }
+ }
+
+ str += " sv2vst\n";
+ itr = sv2vst.entrySet().iterator();
+ while( itr.hasNext() ) {
+ Map.Entry me = (Map.Entry) itr.next();
+ SVKey key = (SVKey) me.getKey();
+ Set<VariableSourceToken> s1 = (Set<VariableSourceToken>) me.getValue();
+ assert s1 != null;
+
+ str += " "+key+" -> \n";
+
+ vstItr = s1.iterator();
+ while( vstItr.hasNext() ) {
+ str += " "+tokHighlighter+" "+vstItr.next()+"\n";
+ }
+ }
+
+ return str;
+ }
+}
--- /dev/null
+package Analysis.OoOJava;
+
+import IR.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+
+public class VariableSourceToken {
+
+ private Set<TempDescriptor> refVars;
+ private FlatSESEEnterNode sese;
+ private Integer seseAge;
+ private TempDescriptor addrVar;
+
+ public VariableSourceToken( Set<TempDescriptor> refVars,
+ FlatSESEEnterNode sese,
+ Integer seseAge,
+ TempDescriptor addrVar
+ ) {
+ this.refVars = refVars;
+ this.sese = sese;
+ this.seseAge = seseAge;
+ this.addrVar = addrVar;
+ }
+
+ public Set<TempDescriptor> getRefVars() {
+ return refVars;
+ }
+
+ public FlatSESEEnterNode getSESE() {
+ return sese;
+ }
+
+ public Integer getAge() {
+ return seseAge;
+ }
+
+ public TempDescriptor getAddrVar() {
+ return addrVar;
+ }
+
+ public VariableSourceToken copy() {
+ Set<TempDescriptor> refVarsCopy = new HashSet<TempDescriptor>();
+
+ Iterator<TempDescriptor> rvItr = refVars.iterator();
+ while( rvItr.hasNext() ) {
+ refVarsCopy.add( rvItr.next() );
+ }
+
+ return new VariableSourceToken( refVarsCopy,
+ sese,
+ new Integer( seseAge ),
+ addrVar );
+ }
+
+ public boolean equals( Object o ) {
+ if( o == null ) {
+ return false;
+ }
+
+ if( !(o instanceof VariableSourceToken) ) {
+ return false;
+ }
+
+ VariableSourceToken vst = (VariableSourceToken) o;
+
+ // the reference vars have no bearing on equality
+ return sese.equals( vst.sese ) &&
+ addrVar.equals( vst.addrVar ) &&
+ seseAge.equals( vst.seseAge );
+ }
+
+ public int hashCode() {
+ // the reference vars have no bearing on hashCode
+ return (sese.hashCode() << 3) * (addrVar.hashCode() << 4) ^ seseAge.intValue();
+ }
+
+
+ public String toString() {
+ return refVars+"\tref "+addrVar+"\t@"+sese.toPrettyString()+"("+seseAge+")";
+ }
+}
for (int step = 0; step < local_ntimesteps; step++) { // time-step the system
ComputeCenterAndDiameter();
ArrayIndexedGraph octree = new ArrayIndexedGraph(8);
+ genreach q1;
ArrayIndexedNode root = octree.createNode(new OctTreeNodeData(centerx, centery, centerz)); // create the tree's root
+ genreach q2;
octree.addNode(root);
+ genreach q3;
double radius = diameter * 0.5;
for (int i = 0; i < local_nbodies; i++) {
+ genreach r0;
Insert(octree, root, body[i], radius); // grow the tree by inserting each body
+ genreach r1;
body[i].root=root;
+ genreach r2;
}
curr = 0;
// summarize subtree info in each internal node (plus restructure tree and sort bodies for performance reasons)
double dt=dthf;
double ep=epssq;
sese parallel{
- eachbody.ComputeForce(octree, di, it, step, dt, ep);
+ eachbody.ComputeForce(octree, di, it, step, dt, ep);
}
}
# -disjoint-debug-snap-method Remove 10 3 true
DISJOINTDEBUG= -justanalyze -disjoint -disjoint-k 1 -enable-assertions \
- -flatirusermethods \
- -disjoint-desire-determinism
-# -disjoint-debug-scheduling
+ -disjoint-debug-callsite createNode run 100 50 false
+# -disjoint-desire-determinism
# -disjoint-debug-snap-method ComputeCenterOfMass 6 2 true
+# -disjoint-debug-scheduling
+# -flatirusermethods
+
+
default:
import Analysis.Disjoint.ReachGraph;
import Analysis.Disjoint.Taint;
import Analysis.OoOJava.OoOJavaAnalysis;
+import Analysis.OoOJava.SESEandAgePair;
+import Analysis.OoOJava.VariableSourceToken;
+import Analysis.OoOJava.CodePlan;
+import Analysis.OoOJava.ConflictNode;
+import Analysis.OoOJava.SESEWaitingQueue;
+import Analysis.OoOJava.VSTWrapper;
import Analysis.Prefetch.*;
import Analysis.Loops.WriteBarrier;
import Analysis.Loops.GlobalFieldType;
import Analysis.Locality.TypeAnalysis;
-import Analysis.MLP.ConflictGraph;
-import Analysis.MLP.ConflictNode;
-import Analysis.MLP.MLPAnalysis;
-import Analysis.MLP.ParentChildConflictsMap;
-import Analysis.MLP.SESELock;
-import Analysis.MLP.SESEWaitingQueue;
-import Analysis.MLP.VariableSourceToken;
-import Analysis.MLP.VSTWrapper;
-import Analysis.MLP.CodePlan;
-import Analysis.MLP.SESEandAgePair;
-import Analysis.MLP.WaitingElement;
import Util.CodePrinter;
public class BuildCode {
Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>> backuptable;
SafetyAnalysis sa;
PrefetchAnalysis pa;
- MLPAnalysis mlpa;
OoOJavaAnalysis oooa;
String maxTaskRecSizeStr="__maxTaskRecSize___";
String mlperrstr = "if(status != 0) { "+
public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
- this(st, temptovar, typeutil, null, sa, pa, null, null);
+ this(st, temptovar, typeutil, null, sa, pa, null);
}
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
- this(st, temptovar, typeutil, null, sa, pa, mlpa, oooa);
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, OoOJavaAnalysis oooa) {
+ this(st, temptovar, typeutil, null, sa, pa, oooa);
}
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
- this(st, temptovar, typeutil, locality, null, pa, mlpa, oooa);
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, OoOJavaAnalysis oooa) {
+ this(st, temptovar, typeutil, locality, null, pa, oooa);
}
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, OoOJavaAnalysis oooa) {
this.sa=sa;
this.pa=pa;
- this.mlpa=mlpa;
this.oooa=oooa;
state=st;
callgraph=new CallGraph(state);
outmethodheader.println("#include \"abortreaders.h\"");
outmethodheader.println("#include <setjmp.h>");
}
- if (state.MLP || state.OOOJAVA) {
+ if (state.OOOJAVA) {
outmethodheader.println("#include <stdlib.h>");
outmethodheader.println("#include <stdio.h>");
outmethodheader.println("#include <string.h>");
outputTaskTypes(outtask);
}
- if( state.MLP || state.OOOJAVA) {
+ if(state.OOOJAVA) {
// have to initialize some SESE compiler data before
// analyzing normal methods, which must happen before
// generating SESE internal code
- Iterator<FlatSESEEnterNode> seseit;
- if(state.MLP){
- seseit=mlpa.getAllSESEs().iterator();
- }else{
- seseit=oooa.getAllSESEs().iterator();
- }
+ Iterator<FlatSESEEnterNode> seseit=oooa.getAllSESEs().iterator();
//TODO signal the object that will report errors
if(state.RCR) {
outputMethods(outmethod);
// Output function prototypes and structures for SESE's and code
- if( state.MLP || state.OOOJAVA ) {
+ if( state.OOOJAVA ) {
// spit out a global to inform all worker threads with
// the maximum size is for any task record
// first generate code for each sese's internals
Iterator<FlatSESEEnterNode> seseit;
- if(state.MLP){
- seseit=mlpa.getAllSESEs().iterator();
- }else{
- seseit=oooa.getAllSESEs().iterator();
- }
+ seseit=oooa.getAllSESEs().iterator();
while(seseit.hasNext()) {
FlatSESEEnterNode fsen = seseit.next();
outputStaticBlocks(outmethod);
outputClassObjects(outmethod);
- if (state.MLP || state.OOOJAVA) {
+ if (state.OOOJAVA) {
// do a calculation to determine which task record
// is the largest, store that as a global value for
// allocating records
Iterator<FlatSESEEnterNode> seseit;
- if(state.MLP){
- seseit=mlpa.getAllSESEs().iterator();
- }else{
- seseit=oooa.getAllSESEs().iterator();
- }
+ seseit=oooa.getAllSESEs().iterator();
while(seseit.hasNext()){
FlatSESEEnterNode fsen = seseit.next();
outmethod.println("if( sizeof( "+fsen.getSESErecordName()+
outmethod.println(" runningSESE = NULL;");
- outmethod.println(" workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
+ outmethod.println(" workScheduleInit( "+state.OOO_NUMCORES+", invokeSESEmethod );");
//initializes data structures needed for the RCR traverser
if(state.RCR && rcr != null) {
if (state.THREAD||state.SINGLETM)
outmethod.println("pthread_exit(NULL);");
- if (state.MLP || state.OOOJAVA ) {
+ if (state.OOOJAVA) {
outmethod.println(" workScheduleBegin();");
}
if (state.CONSCHECK) {
outmethod.println("#include \"checkers.h\"");
}
- if (state.MLP || state.OOOJAVA ) {
+ if ( state.OOOJAVA ) {
outmethod.println("#include <stdlib.h>");
outmethod.println("#include <stdio.h>");
outmethod.println("#include \"mlp_runtime.h\"");
outstructs.println("#define INTPTR int");
outstructs.println("#endif");
outstructs.println("#endif");
- if( state.MLP || state.OOOJAVA ) {
+ if( state.OOOJAVA ) {
outstructs.println("#include \"mlp_runtime.h\"");
outstructs.println("#include \"psemaphore.h\"");
}
//Print out definition for array type
outclassdefs.println("struct "+arraytype+" {");
outclassdefs.println(" int type;");
- if(state.MLP || state.OOOJAVA ){
+ if( state.OOOJAVA ){
outclassdefs.println(" int oid;");
outclassdefs.println(" int allocsite;");
}
//Print out definition for Class type
outclassdefs.println("struct Class {");
outclassdefs.println(" int type;");
- if(state.MLP || state.OOOJAVA ){
+ if( state.OOOJAVA ){
outclassdefs.println(" int oid;");
outclassdefs.println(" int allocsite;");
}
outclassdefs.print("#endif\n");
outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
- if(this.state.MLP || state.OOOJAVA ){
+ if( state.OOOJAVA ){
outclassdefs.print("extern __thread int oid;\n");
outclassdefs.print("extern int oidIncrement;\n");
}
/* Output class structure */
classdefout.println("struct "+cn.getSafeSymbol()+" {");
classdefout.println(" int type;");
- if(state.MLP || state.OOOJAVA){
+ if( state.OOOJAVA){
classdefout.println(" int oid;");
classdefout.println(" int allocsite;");
}
}
- if( state.MLP || state.OOOJAVA ) {
+ if( state.OOOJAVA ) {
if( fm.getNext(0) instanceof FlatSESEEnterNode ) {
FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
- if( (state.MLP && callerSESEplaceholder != mlpa.getMainSESE()) ||
- (state.OOOJAVA && callerSESEplaceholder != oooa.getMainSESE())
- ) {
+ if( callerSESEplaceholder != oooa.getMainSESE() ) {
// declare variables for naming static SESE's
output.println(" /* static SESE names */");
Iterator<SESEandAgePair> pItr = callerSESEplaceholder.getNeededStaticNames().iterator();
// set up related allocation sites's waiting queues
// eom
- if(state.MLP){
- ConflictGraph graph = null;
- graph = mlpa.getConflictGraphResults().get(fm);
- if (graph != null && graph.hasConflictEdge()) {
- output.println(" /* set up waiting queues */");
+
+ FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
+ if(callerSESEplaceholder!= oooa.getMainSESE()){
+ Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(callerSESEplaceholder);
+ if (graph != null && graph.hasConflictEdge()) {
+ output.println(" // set up waiting queues ");
output.println(" int numMemoryQueue=0;");
output.println(" int memoryQueueItemID=0;");
- HashSet<SESELock> lockSet = mlpa.getConflictGraphLockMap().get(
- graph);
+ Set<Analysis.OoOJava.SESELock> lockSet = oooa.getLockMappings(graph);
System.out.println("#lockSet="+lockSet.hashCode());
System.out.println("lockset="+lockSet);
for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
- SESELock seseLock = (SESELock) iterator.next();
+ Analysis.OoOJava.SESELock seseLock = (Analysis.OoOJava.SESELock) iterator.next();
System.out.println("id="+seseLock.getID());
System.out.println("#="+seseLock);
}
output.println();
}
}
- }else{
- FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
- if(callerSESEplaceholder!= oooa.getMainSESE()){
- Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(callerSESEplaceholder);
- if (graph != null && graph.hasConflictEdge()) {
- output.println(" // set up waiting queues ");
- output.println(" int numMemoryQueue=0;");
- output.println(" int memoryQueueItemID=0;");
- Set<Analysis.OoOJava.SESELock> lockSet = oooa.getLockMappings(graph);
- System.out.println("#lockSet="+lockSet.hashCode());
- System.out.println("lockset="+lockSet);
- for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
- Analysis.OoOJava.SESELock seseLock = (Analysis.OoOJava.SESELock) iterator.next();
- System.out.println("id="+seseLock.getID());
- System.out.println("#="+seseLock);
- }
- System.out.println("size="+lockSet.size());
- if (lockSet.size() > 0) {
- output.println(" numMemoryQueue=" + lockSet.size() + ";");
- output.println(" runningSESE->numMemoryQueue=numMemoryQueue;");
- output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
- output.println();
- }
- }
- }
}
+
}
/* Check to see if we need to do a GC if this is a
* multi-threaded program...*/
- if (((state.MLP||state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
+ if (((state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
|| this.state.MULTICOREGC) {
//Don't bother if we aren't in recursive methods...The loops case will catch it
if (callgraph.getAllMethods(md).contains(md)) {
}
output.println(" }");
}
- } else {
- output.println(" // set up memory queues ");
- output.println(" int numMemoryQueue=0;");
- output.println(" int memoryQueueItemID=0;");
- ConflictGraph graph = null;
- graph = mlpa.getConflictGraphResults().get(fsen);
- if (graph != null && graph.hasConflictEdge()) {
- output.println(" {");
- HashSet<SESELock> lockSet = mlpa.getConflictGraphLockMap().get(
- graph);
- System.out.println("#lockSet="+lockSet);
-
- if (lockSet.size() > 0) {
- output.println(" numMemoryQueue=" + lockSet.size() + "; ");
- output.println(" runningSESE->numMemoryQueue=numMemoryQueue;");
- output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
- output.println();
- }
- output.println(" }");
- }
}
outmethod.println( " switch( ((SESEcommon*)seseRecord)->classID ) {");
outmethod.println( " ");
Iterator<FlatSESEEnterNode> seseit;
- if(state.MLP){
- seseit=mlpa.getAllSESEs().iterator();
- }else{
- seseit=oooa.getAllSESEs().iterator();
- }
+ seseit=oooa.getAllSESEs().iterator();
+
while(seseit.hasNext()){
FlatSESEEnterNode fsen = seseit.next();
outmethod.println( " case "+fsen.getIdentifier()+":");
outmethod.println( " "+fsen.getSESEmethodName()+"( seseRecord );");
- if( (state.MLP && fsen.equals( mlpa.getMainSESE() )) ||
- (state.OOOJAVA && fsen.equals( oooa.getMainSESE() ))
- ) {
+ if( fsen.equals( oooa.getMainSESE() ) ) {
outmethod.println( " workScheduleExit();");
}
output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
}
}
- if ((state.MLP || state.OOOJAVA) && stopset!=null) {
+ if (state.OOOJAVA && stopset!=null) {
assert first.getPrev( 0 ) instanceof FlatSESEEnterNode;
assert current_node instanceof FlatSESEExitNode;
FlatSESEEnterNode fsen = (FlatSESEEnterNode) first.getPrev( 0 );
current_node=null;
} else if(current_node.numNext()==1) {
FlatNode nextnode;
- if ((state.MLP|| state.OOOJAVA) &&
- current_node.kind()==FKind.FlatSESEEnterNode &&
- !((FlatSESEEnterNode)current_node).getIsCallerSESEplaceholder()
+ if (state.OOOJAVA &&
+ current_node.kind()==FKind.FlatSESEEnterNode //&&
+ //!((FlatSESEEnterNode)current_node).getIsCallerSESEplaceholder()
) {
FlatSESEEnterNode fsen = (FlatSESEEnterNode)current_node;
generateFlatNode(fm, lb, current_node, output);
protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
// insert pre-node actions from the code plan
- if( state.MLP|| state.OOOJAVA ) {
+ if( state.OOOJAVA ) {
- CodePlan cp;
- if(state.MLP){
- cp = mlpa.getCodePlan( fn );
- }else{
- cp = oooa.getCodePlan(fn);
- }
+ CodePlan cp = oooa.getCodePlan(fn);
if( cp != null ) {
while( tdItr.hasNext() ) {
TempDescriptor td = tdItr.next();
FlatMethod fmContext;
- if( currentSESE.getIsCallerSESEplaceholder() ) {
- fmContext = currentSESE.getfmEnclosing();
- } else {
+ //if( currentSESE.getIsCallerSESEplaceholder() ) {
+ // fmContext = currentSESE.getfmEnclosing();
+ //} else {
fmContext = currentSESE.getfmBogus();
- }
+ //}
output.println(" "+generateTemp( fmContext, td, null )+
" = child->"+vst.getAddrVar().getSafeSymbol()+";");
}
output.println(" }");
FlatMethod fmContext;
- if( currentSESE.getIsCallerSESEplaceholder() ) {
- fmContext = currentSESE.getfmEnclosing();
- } else {
+ //if( currentSESE.getIsCallerSESEplaceholder() ) {
+ // fmContext = currentSESE.getfmEnclosing();
+ //} else {
fmContext = currentSESE.getfmBogus();
- }
+ //}
TypeDescriptor type = dynVar.getType();
String typeStr;
// eom
// handling stall site
if (state.OOOJAVA) {
- // NEED TO FIX IT
- // assumes that there is only one parent, but it is possible that
- // currentSESE has more than one so we need to generate
- // conditional case for each parent case
- Analysis.OoOJava.ConflictGraph graph = null;
- if(currentSESE.getSESEParent().size()>0){
- graph = oooa.getConflictGraph(currentSESE.getSESEParent().iterator().next());
- }
-// Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(currentSESE);
+ Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(currentSESE);
if(graph!=null){
Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
Set<Analysis.OoOJava.WaitingElement> waitingElementSet = graph.getStallSiteWaitingElementSet(fn, seseLockSet);
}
}
}
- } else{
- ParentChildConflictsMap conflictsMap = mlpa.getConflictsResults().get(fn);
- if (conflictsMap != null) {
- Set<Long> allocSet = conflictsMap.getAllocationSiteIDSetofStallSite();
- 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);
- 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(" REntry* rentry;");
-
- for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
- WaitingElement waitingElement = (WaitingElement) iterator.next();
-
- if( waitingElement.getStatus() >= ConflictNode.COARSE ){
- // HERE! a parent might conflict with a child
- output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+ waitingElement.getStatus()+ ", runningSESE);");
- } else {
- output.println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],"+ waitingElement.getStatus()+ ", runningSESE, (void*)&___locals___."+ waitingElement.getDynID() + ");");
- }
- output.println(" rentry->parentStallSem=&runningSESEstallSem;");
- output.println(" psem_reset( &runningSESEstallSem);");
- output.println(" rentry->tag=runningSESEstallSem.tag;");
- output.println(" rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
- output.println(" if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+"],rentry)==NOTREADY) {");
- if( state.COREPROF ) {
- output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
- output.println(" CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
- output.println("#endif");
- }
- output.println(" psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
- if( state.COREPROF ) {
- output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
- output.println(" CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
- output.println("#endif");
- }
- output.println(" } ");
- }
- output.println(" }");
- }
- }
- }
- }
+ }
}
}
if(state.DSM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) {
output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();");
}
- if (((state.MLP|| state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
+ if (((state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
|| (this.state.MULTICOREGC)) {
if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) {
output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
throw new Error();
}
- // insert post-node actions from the code-plan
- /*
- if( state.MLP) {
- CodePlan cp = mlpa.getCodePlan( fn );
-
- if( cp != null ) {
- }
- }
- */
+ // insert post-node actions from the code-plan (none right now...)
}
public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) {
LocalityBinding lb,
FlatSESEEnterNode fsen,
PrintWriter output) {
- // if MLP flag is off, okay that SESE nodes are in IR graph,
+ // if OOOJAVA flag is off, okay that SESE nodes are in IR graph,
// just skip over them and code generates exactly the same
- if( !(state.MLP || state.OOOJAVA) ) {
+ if( !state.OOOJAVA ) {
return;
}
// there may be an SESE in an unreachable method, skip over
- if( (state.MLP && !mlpa.getAllSESEs().contains( fsen )) ||
- (state.OOOJAVA && !oooa.getAllSESEs().contains(fsen))
- ) {
+ if( !oooa.getAllSESEs().contains(fsen) ) {
return;
}
// also, if we have encountered a placeholder, just skip it
- if( fsen.getIsCallerSESEplaceholder() ) {
- return;
- }
+ //if( fsen.getIsCallerSESEplaceholder() ) {
+ // return;
+ //}
output.println(" {");
// before doing anything, lock your own record and increment the running children
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
+ if( fsen != oooa.getMainSESE() ) {
output.println(" childSESE++;");
}
output.println( "#ifdef CP_EVENTID_POOLALLOC");
output.println( " CP_LOGEVENT( CP_EVENTID_POOLALLOC, CP_EVENTTYPE_BEGIN );");
output.println( "#endif");
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
+ if( fsen != oooa.getMainSESE() ) {
output.println(" "+
fsen.getSESErecordName()+"* seseToIssue = ("+
fsen.getSESErecordName()+"*) poolalloc( runningSESE->taskRecordMemPool );");
// otherwise use the parent's enclosing method as the context
boolean useParentContext = false;
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
- assert fsen.getParent() != null;
- if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+ if( fsen != oooa.getMainSESE() ) {
+ assert fsen.getParents() != null;
+ //if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
useParentContext = true;
- }
+ //}
}
+ /*
if( useParentContext ) {
output.println(" seseToIssue->"+temp+" = "+
generateTemp( fsen.getParent().getfmBogus(), temp, null )+";");
output.println(" seseToIssue->"+temp+" = "+
generateTemp( fsen.getfmEnclosing(), temp, null )+";");
}
+ */
}
// before potentially adding this SESE to other forwarding lists,
output.println(" pthread_mutex_init( &(seseToIssue->common.lock), NULL );");
output.println("#endif");
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
+ if( fsen != oooa.getMainSESE() ) {
// count up outstanding dependencies, static first, then dynamic
Iterator<SESEandAgePair> staticSrcsItr = fsen.getStaticInVarSrcs().iterator();
while( staticSrcsItr.hasNext() ) {
output.println(" } else {");
boolean useParentContext = false;
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
- assert fsen.getParent() != null;
- if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+ if( fsen != oooa.getMainSESE() ) {
+ //assert fsen.getParent() != null;
+ //if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
useParentContext = true;
- }
- }
- if( useParentContext ) {
- output.println(" seseToIssue->"+dynInVar+" = "+
- generateTemp( fsen.getParent().getfmBogus(), dynInVar, null )+";");
- } else {
- output.println(" seseToIssue->"+dynInVar+" = "+
- generateTemp( fsen.getfmEnclosing(), dynInVar, null )+";");
- }
+ //}
+ }
+ //if( useParentContext ) {
+ // output.println(" seseToIssue->"+dynInVar+" = "+
+ // generateTemp( fsen.getParent().getfmBogus(), dynInVar, null )+";");
+ //} else {
+ // output.println(" seseToIssue->"+dynInVar+" = "+
+ // generateTemp( fsen.getfmEnclosing(), dynInVar, null )+";");
+ //}
output.println(" }");
output.println(" }");
// instances from static names
SESEandAgePair pairNewest = new SESEandAgePair( fsen, 0 );
SESEandAgePair pairOldest = new SESEandAgePair( fsen, fsen.getOldestAgeToTrack() );
- if( fsen.getParent() != null &&
- fsen.getParent().getNeededStaticNames().contains( pairNewest )
+ if( true//fsen.getParent() != null &&
+ //fsen.getParent().getNeededStaticNames().contains( pairNewest )
) {
output.println(" {");
output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
// assumes that there is only one parent, but it is possible that
// currentSESE has more than one so we need to generate
// conditional case for each parent case
- assert fsen.getSESEParent().size()>0;
- FlatSESEEnterNode parent = fsen.getSESEParent().iterator().next();
- Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
+ assert fsen.getParents().size()>0;
+ FlatSESEEnterNode parent = fsen.getParents().iterator().next();
+ Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
if (graph != null && graph.hasConflictEdge()) {
Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
output.println();
}
output.println();
}
- } else {
- ConflictGraph graph = null;
- FlatSESEEnterNode parent = fsen.getParent();
- if (parent != null) {
- if (parent.isCallerSESEplaceholder) {
- graph = mlpa.getConflictGraphResults().get(parent.getfmEnclosing());
- } else {
- graph = mlpa.getConflictGraphResults().get(parent);
- }
- }
- if (graph != null && graph.hasConflictEdge()) {
- HashSet<SESELock> seseLockSet = mlpa.getConflictGraphLockMap()
- .get(graph);
- output.println();
- output.println(" //add memory queue element");
- SESEWaitingQueue seseWaitingQueue=graph.getWaitingElementSetBySESEID(fsen.getIdentifier(),
- seseLockSet);
- if(seseWaitingQueue.getWaitingElementSize()>0){
- output.println(" {");
- output.println(" REntry* rentry=NULL;");
- output.println(" INTPTR* pointer=NULL;");
- output.println(" seseToIssue->common.rentryIdx=0;");
-
- Set<Integer> queueIDSet=seseWaitingQueue.getQueueIDSet();
- for (Iterator iterator = queueIDSet.iterator(); iterator
- .hasNext();) {
- Integer key = (Integer) iterator.next();
- int queueID=key.intValue();
- Set<WaitingElement> waitingQueueSet = seseWaitingQueue.getWaitingElementSet(queueID);
- int enqueueType=seseWaitingQueue.getType(queueID);
- if(enqueueType==SESEWaitingQueue.EXCEPTION){
- output.println(" INITIALIZEBUF(runningSESE->memoryQueueArray["
- + queueID+ "]);");
- }
- for (Iterator iterator2 = waitingQueueSet.iterator(); iterator2
- .hasNext();) {
- WaitingElement waitingElement = (WaitingElement) iterator2
- .next();
- if (waitingElement.getStatus() >= ConflictNode.COARSE) {
- output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
- + waitingElement.getStatus()
- + ", &(seseToIssue->common));");
- } else {
- TempDescriptor td = waitingElement
- .getTempDesc();
- // decide whether waiting element is dynamic or
- // static
- if (fsen.getDynamicInVarSet().contains(td)) {
- // dynamic in-var case
- output.println(" pointer=seseToIssue->"
- + waitingElement.getDynID()
- + "_srcSESE+seseToIssue->"
- + waitingElement.getDynID()
- + "_srcOffset;");
- output
- .println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
- + waitingElement
- .getStatus()
- + ", &(seseToIssue->common), pointer );");
- } else if (fsen.getStaticInVarSet()
- .contains(td)) {
- // static in-var case
- VariableSourceToken vst = fsen
- .getStaticInVarSrc(td);
- if (vst != null) {
-
- String srcId = "SESE_"
- + vst.getSESE()
- .getPrettyIdentifier()
- + vst.getSESE().getIdentifier()
- + "_" + vst.getAge();
- output
- .println(" pointer=(void*)&seseToIssue->"
- + srcId
- + "->"
- + waitingElement
- .getDynID()
- + ";");
- output
- .println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
- + waitingElement
- .getStatus()
- + ", &(seseToIssue->common), pointer );");
-
- }
- } else {
- output
- .println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["+ queueID+ "],"
- + waitingElement
- .getStatus()
- + ", &(seseToIssue->common), (void*)&seseToIssue->"
- + waitingElement.getDynID()
- + ");");
- }
- }
- output
- .println(" rentry->queue=runningSESE->memoryQueueArray["
- + waitingElement.getQueueID()
- + "];");
-
- if(enqueueType==SESEWaitingQueue.NORMAL){
- output
- .println(" seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
- output
- .println(" if(ADDRENTRY(runningSESE->memoryQueueArray["
- + waitingElement.getQueueID()
- + "],rentry)==NOTREADY){");
- output.println(" ++(localCount);");
- output.println(" } ");
- }else{
- output
- .println(" ADDRENTRYTOBUF(runningSESE->memoryQueueArray["
- + waitingElement.getQueueID()
- + "],rentry);");
- }
- }
- if(enqueueType!=SESEWaitingQueue.NORMAL){
- output.println(" localCount+=RESOLVEBUF(runningSESE->memoryQueueArray["
- + queueID+ "],&seseToIssue->common);");
- }
- }
- output.println(" }");
- }
- output.println();
- }
}
}
// assumes that there is only one parent, but it is possible that
// currentSESE has more than one so we need to generate
// conditional case for each parent case
- assert fsen.getSESEParent().size()>0;
- FlatSESEEnterNode parent = fsen.getSESEParent().iterator().next();
+ assert fsen.getParents().size()>0;
+ FlatSESEEnterNode parent = fsen.getParents().iterator().next();
Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
if (graph != null && graph.hasConflictEdge()) {
Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
FlatSESEExitNode fsexn,
PrintWriter output) {
- // if MLP flag is off, okay that SESE nodes are in IR graph,
+ // if OOOJAVA flag is off, okay that SESE nodes are in IR graph,
// just skip over them and code generates exactly the same
- if( ! (state.MLP || state.OOOJAVA) ) {
+ if( !state.OOOJAVA ) {
return;
}
FlatSESEEnterNode fsen = fsexn.getFlatEnter();
// there may be an SESE in an unreachable method, skip over
- if( (state.MLP && !mlpa.getAllSESEs().contains( fsen )) ||
- (state.OOOJAVA && !oooa.getAllSESEs().contains( fsen ))
- ) {
+ if( !oooa.getAllSESEs().contains( fsen ) ) {
return;
}
// also, if we have encountered a placeholder, just jump it
- if( fsen.getIsCallerSESEplaceholder() ) {
- return;
- }
+ //if( fsen.getIsCallerSESEplaceholder() ) {
+ // return;
+ //}
if( state.COREPROF ) {
output.println("#ifdef CP_EVENTID_TASKEXECUTE");
// have to determine the context enclosing this sese
boolean useParentContext = false;
- if( (state.MLP &&fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA &&fsen != oooa.getMainSESE())
- ) {
- assert fsen.getParent() != null;
- if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+ if( fsen != oooa.getMainSESE() ) {
+ assert fsen.getParents() != null;
+ //if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
useParentContext = true;
- }
+ //}
}
String from;
- if( useParentContext ) {
- from = generateTemp( fsen.getParent().getfmBogus(), temp, null );
- } else {
+ //if( useParentContext ) {
+ //from = generateTemp( fsen.getParent().getfmBogus(), temp, null );
+ //} else {
from = generateTemp( fsen.getfmEnclosing(), temp, null );
- }
+ //}
output.println(" "+paramsprefix+
"->"+temp.getSafeSymbol()+
output.println(" runningSESE->doneExecuting = TRUE;");
// if parent is stalling on you, let them know you're done
- if( (state.MLP && fsexn.getFlatEnter() != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsexn.getFlatEnter() != oooa.getMainSESE())
- ) {
+ if( fsexn.getFlatEnter() != oooa.getMainSESE() ) {
output.println(" if( runningSESE->parentsStallSem != NULL ) {");
output.println(" psem_give( runningSESE->parentsStallSem );");
output.println(" }");
// clean up its lock element from waiting queue, and decrement dependency count for next SESE block
- if((state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())) {
+ if( fsen != oooa.getMainSESE() ) {
output.println();
output.println(" /* check memory dependency*/");
output.println(" {");
// if this is not the Main sese (which has no parent) then return
// THIS task's record to the PARENT'S task record pool, and only if
// the reference count is now zero
- if( (state.MLP && fsen != mlpa.getMainSESE()) ||
- (state.OOOJAVA && fsen != oooa.getMainSESE())
- ) {
+ if( fsen != oooa.getMainSESE() ) {
output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
output.println(" RELEASE_REFERENCE_TO( runningSESE );");
output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
FlatWriteDynamicVarNode fwdvn,
PrintWriter output
) {
- if( !(state.MLP || state.OOOJAVA) ) {
+ if( !state.OOOJAVA ) {
// should node should not be in an IR graph if the
- // MLP flag is not set
+ // OOOJAVA flag is not set
throw new Error("Unexpected presence of FlatWriteDynamicVarNode");
}
if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
} else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
- if(this.state.MLP || state.OOOJAVA){
+ if(state.OOOJAVA){
output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray_mlp("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+", oid, "+oooa.getDisjointAnalysis().getAllocationSiteFromFlatNew(fn).getUniqueAllocSiteID()+");");
output.println(" oid += oidIncrement;");
}else{
if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");");
} else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
- if (this.state.MLP || state.OOOJAVA){
+ if (state.OOOJAVA){
output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new_mlp("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+", oid, "+oooa.getDisjointAnalysis().getAllocationSiteFromFlatNew(fn).getUniqueAllocSiteID()+");");
output.println(" oid += oidIncrement;");
} else {
while(methodit.hasNext()) {
currmd=(MethodDescriptor)methodit.next();
- // if MLP is on, splice a special SESE in to
- // enclose the main method, and a special SESE
- // in around every other method that statically
- // represents the SESE instance that will call
- // that method at runtime
+ // if OOOJava is on, splice a special SESE in to
+ // enclose the main method
+ boolean spliceInImplicitMain =
+ state.OOOJAVA &&
+ currmd.equals( typeutil.getMain() );
+
FlatSESEEnterNode spliceSESE = null;
FlatSESEExitNode spliceExit = null;
- if( state.MLP || state.OOOJAVA ) {
- if( currmd.equals( typeutil.getMain() ) ) {
- SESENode mainTree = new SESENode( "main" );
- spliceSESE = new FlatSESEEnterNode( mainTree );
- spliceExit = new FlatSESEExitNode ( mainTree );
- spliceSESE.setFlatExit ( spliceExit );
- spliceExit.setFlatEnter( spliceSESE );
- } else {
- SESENode callerSESETree = new SESENode( "caller SESE placeholder" );
- spliceSESE = new FlatSESEEnterNode( callerSESETree );
- spliceSESE.setCallerSESEplaceholder();
- spliceExit = new FlatSESEExitNode ( callerSESETree );
- spliceSESE.setFlatExit ( spliceExit );
- spliceExit.setFlatEnter( spliceSESE );
- }
- }
+
+ if( spliceInImplicitMain ) {
+ SESENode mainTree = new SESENode( "main" );
+ spliceSESE = new FlatSESEEnterNode( mainTree );
+ spliceExit = new FlatSESEExitNode ( mainTree );
+ spliceSESE.setFlatExit ( spliceExit );
+ spliceExit.setFlatEnter( spliceSESE );
+ spliceSESE.setIsMainSESE();
+ }
+
fe=new FlatExit();
} else if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
FlatNode rnflat=null;
- // splice implicit SESE exit after method body
- if( state.MLP || state.OOOJAVA ) {
+ if( spliceInImplicitMain ) {
np.getEnd().addNext(spliceExit);
rnflat=spliceReturn(spliceExit);
} else {
}
rnflat.addNext(fe);
} else if (np.getEnd()!=null) {
- // splice implicit SESE exit after method body
- if( state.MLP || state.OOOJAVA ) {
+ if( spliceInImplicitMain ) {
FlatReturnNode rnflat=(FlatReturnNode)np.getEnd();
np.getEnd().addNext(spliceExit);
spliceExit.addNext(fe);
}
}
- // splice an implicit SESE enter before method body
- if( state.MLP || state.OOOJAVA ) {
+ if( spliceInImplicitMain ) {
spliceSESE.addNext(fn);
fn=spliceSESE;
}
import java.util.Vector;
import java.util.Iterator;
import java.util.Collection;
-
-import Analysis.MLP.SESEEffectsKey;
-import Analysis.MLP.SESEEffectsSet;
-import Analysis.MLP.SESEandAgePair;
-import Analysis.MLP.VariableSourceToken;
+import Analysis.OoOJava.VariableSourceToken;
+import Analysis.OoOJava.SESEandAgePair;
import Analysis.OwnershipAnalysis.HeapRegionNode;
import IR.ClassDescriptor;
import IR.FieldDescriptor;
private int id;
protected FlatSESEExitNode exit;
protected SESENode treeNode;
- protected FlatSESEEnterNode parent;
protected Integer oldestAgeToTrack;
- protected boolean isCallerSESEplaceholder;
+ // a leaf tasks simply has no children, ever
protected static final int ISLEAF_UNINIT = 1;
protected static final int ISLEAF_FALSE = 2;
protected static final int ISLEAF_TRUE = 3;
protected int isLeafSESE;
+ // there is only one main sese that is implicit
+ // (spliced in by the compiler around whole program)
+ protected boolean isMainSESE;
+
+ // all children tasks, INCLUDING those that are reachable
+ // by calling methods
protected Set<FlatSESEEnterNode> children;
+
+ // all possible parents
+ protected Set<FlatSESEEnterNode> parents;
+
+ // sometimes it is useful to know the locally defined
+ // parent or children of an SESE for various analysis,
+ // and by local it is one SESE nested within another
+ // in a single method context
+ protected Set<FlatSESEEnterNode> localChildren;
+ protected FlatSESEEnterNode localParent;
+
protected Set<TempDescriptor> inVars;
protected Set<TempDescriptor> outVars;
protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
- private SESEEffectsSet seseEffectsSet;
// a subset of the in-set variables that shouuld be traversed during
// the dynamic coarse grained conflict strategy, remember them here so
protected String firstDepRecField;
protected int numDepRecs;
- // a set of sese located at the first in transitive call chain
- // starting from the current sese
- protected Set<FlatSESEEnterNode> seseChildren;
-
- // a set of complete parent sese, not bogus one
- protected Set<FlatSESEEnterNode> seseParent;
-
public FlatSESEEnterNode( SESENode sn ) {
this.id = identifier++;
treeNode = sn;
- parent = null;
oldestAgeToTrack = new Integer( 0 );
-
children = new HashSet<FlatSESEEnterNode>();
+ parents = new HashSet<FlatSESEEnterNode>();
+ localChildren = new HashSet<FlatSESEEnterNode>();
+ localParent = null;
inVars = new HashSet<TempDescriptor>();
outVars = new HashSet<TempDescriptor>();
needStaticNameInCode = new HashSet<SESEandAgePair>();
staticInVars = new HashSet<TempDescriptor>();
dynamicInVars = new HashSet<TempDescriptor>();
dynamicVars = new HashSet<TempDescriptor>();
- seseChildren = new HashSet<FlatSESEEnterNode>();
- seseParent = new HashSet<FlatSESEEnterNode>();
inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
- seseEffectsSet = new SESEEffectsSet();
-
fmEnclosing = null;
mdEnclosing = null;
cdEnclosing = null;
- isCallerSESEplaceholder = false;
-
isLeafSESE = ISLEAF_UNINIT;
+ isMainSESE = false;
+
firstDepRecField = null;
numDepRecs = 0;
}
return exit;
}
+ public void setIsMainSESE() {
+ isMainSESE = true;
+ }
+
+ public boolean getIsMainSESE() {
+ return isMainSESE;
+ }
+
public int kind() {
return FKind.FlatSESEEnterNode;
}
return "sese "+getPrettyIdentifier()+getIdentifier();
}
- public void setParent( FlatSESEEnterNode parent ) {
- this.parent = parent;
+
+
+ public void addParent( FlatSESEEnterNode parent ) {
+ parents.add( parent );
+ }
+
+ public Set<FlatSESEEnterNode> getParents() {
+ return parents;
}
- public FlatSESEEnterNode getParent() {
- return parent;
+ public void setLocalParent( FlatSESEEnterNode parent ) {
+ localParent = parent;
+ }
+
+ public FlatSESEEnterNode getLocalParent() {
+ return localParent;
}
public void addChild( FlatSESEEnterNode child ) {
children.add( child );
}
+ public void addChildren( Set<FlatSESEEnterNode> batch ) {
+ children.addAll( batch );
+ }
+
public Set<FlatSESEEnterNode> getChildren() {
return children;
}
+ public void addLocalChild( FlatSESEEnterNode child ) {
+ localChildren.add( child );
+ }
+
+ public Set<FlatSESEEnterNode> getLocalChildren() {
+ return localChildren;
+ }
+
+
+
public void addInVar( TempDescriptor td ) {
if (!inVars.contains(td))
inVars.add( td );
"_SESErec";
}
- public void setCallerSESEplaceholder() {
- isCallerSESEplaceholder = true;
- }
-
- public boolean getIsCallerSESEplaceholder() {
- return isCallerSESEplaceholder;
- }
-
- public void addSESEChildren(FlatSESEEnterNode child){
- seseChildren.add(child);
- }
-
- public void addSESEChildren(Set<FlatSESEEnterNode> children){
-
- seseChildren.addAll(children);
- }
-
- public Set<FlatSESEEnterNode> getSESEChildren(){
- return seseChildren;
- }
-
public boolean equals( Object o ) {
if( o == null ) {
return false;
return 31*id;
}
- public void writeEffects(TempDescriptor td, String fd, TypeDescriptor type, HeapRegionNode hrn, boolean strongUpdate){
- seseEffectsSet.addWritingVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
- if(strongUpdate){
- seseEffectsSet.addStrongUpdateVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
- }
- }
-
- public void readEffects(TempDescriptor td, String fd, TypeDescriptor type, HeapRegionNode hrn ){
- seseEffectsSet.addReadingVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
- }
-
- public SESEEffectsSet getSeseEffectsSet(){
- return seseEffectsSet;
- }
public void setFirstDepRecField( String field ) {
return isLeafSESE == ISLEAF_TRUE;
}
-
- public Set<FlatSESEEnterNode> getSESEParent() {
- return seseParent;
- }
-
- public void addSESEParent(FlatSESEEnterNode seseParent) {
- this.seseParent.add(seseParent);
- }
}
package IR.Flat;
-import Analysis.MLP.VSTWrapper;
+import Analysis.OoOJava.VSTWrapper;
import java.util.Hashtable;
-// This node is inserted by the MLP analysis
+// This node is inserted by the OOOJava analysis
// in between a (tail -> head) IR graph edge.
// It is for tracking SESE variables with
// dynamic sources
import java.util.Vector;
import Util.Pair;
import Analysis.Disjoint.*;
-import Analysis.MLP.CodePlan;
import IR.State;
import IR.TypeDescriptor;
import Analysis.OoOJava.ConflictGraph;
import Analysis.OoOJava.OoOJavaAnalysis;
import Analysis.OoOJava.SESELock;
import Analysis.OoOJava.WaitingElement;
+import Analysis.OoOJava.CodePlan;
import Util.CodePrinter;
/* An instance of this class manages all OoOJava coarse-grained runtime conflicts
for(Iterator<FlatSESEEnterNode> seseit = oooa.getAllSESEs().iterator();seseit.hasNext();) {
fsen = seseit.next();
- if ( fsen.getSESEParent().size() > 0 &&
- !fsen.getIsCallerSESEplaceholder() &&
- (parentSESE = (FlatSESEEnterNode) fsen.getSESEParent().iterator().next()) != null &&
+ if ( fsen.getParents().size() > 0 &&
+ (parentSESE = (FlatSESEEnterNode) fsen.getParents().iterator().next()) != null &&
(conflictGraph = oooa.getConflictGraph(parentSESE)) != null &&
(conflicts = conflictGraph.getConflictEffectSet(fsen)) != null &&
(rg = disjointAnaylsis.getEnterReachGraph(fsen)) != null ){
FlatNode fn = codeit.next();
CodePlan cp = oooa.getCodePlan(fn);
fsen = cp.getCurrentSESE();
-
- // jjenista - I think the following code is WRONG!!! (but right... :( )
- // see note in OoOJavaAnalysis.java explaining that conflict graphs are
- // correct but stored in a parent's parent by mistake, and then in places
- // like this we look to the parent's parent for the correct conflict graph.
- // It should be oooa.getConflictGraph(fsen) which is the task enclosing the
- // stall site, and who's children might conflict with the stall site.
- // DON'T CHANGE IT unless you are willing to find the many, many dependent
- // code sections based on this behavior, but understand what is happening.
-
- if( fsen.getSESEParent().size() != 0 &&
- (parentSESE = (FlatSESEEnterNode)fsen.getSESEParent().iterator().next()) != null &&
- (conflictGraph = oooa.getConflictGraph(parentSESE)) != null &&
+
+ if( fsen.getParents().size() != 0 &&
+ (conflictGraph = oooa.getConflictGraph(fsen)) != null &&
(conflicts = conflictGraph.getConflictEffectSet(fn)) != null &&
(rg = disjointAnaylsis.getEnterReachGraph(fn)) != null ){
if(generalDebug) {
System.out.println(rblock);
- System.out.println(rblock.getIsCallerSESEplaceholder());
- System.out.println(rblock.getParent());
+ System.out.println(rblock.getParents());
System.out.println("CG=" + conflictGraph);
if(verboseDebug)
rg.writeGraph("RCR_RG_SESE_DEBUG"+removeInvalidChars(rblock.getPrettyIdentifier()));
// FIX IT LATER! Right now, we assume that there is only one parent
// JCJ ask yong hun what we should do in the multi-parent future!
- FlatSESEEnterNode parentSESE = (FlatSESEEnterNode) fsen.getSESEParent().iterator().next();
+ FlatSESEEnterNode parentSESE = (FlatSESEEnterNode) fsen.getParents().iterator().next();
ConflictGraph graph = oooa.getConflictGraph(parentSESE);
String id = tmp + "_sese" + fsen.getPrettyIdentifier();
ConflictNode node = graph.getId2cn().get(id);
public boolean hasEmptyTraversers(FlatSESEEnterNode fsen) {
boolean hasEmpty = true;
- Set<FlatSESEEnterNode> children = fsen.getSESEChildren();
+ Set<FlatSESEEnterNode> children = fsen.getChildren();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
FlatSESEEnterNode child = (FlatSESEEnterNode) iterator.next();
hasEmpty &= child.getInVarsForDynamicCoarseConflictResolution().size() == 0;
public boolean THREAD=false;
public boolean CONSCHECK=false;
public boolean INSTRUCTIONFAILURE=false;
- public boolean MLP=false;
- public boolean MLPDEBUG=false;
- public int MLP_NUMCORES=0;
- public int MLP_MAXSESEAGE=0;
+ public int OOO_NUMCORES=0;
+ public int OOO_MAXSESEAGE=0;
public boolean METHODEFFECTS=false;
public static double TRUEPROB=0.8;
public static boolean PRINTFLAT=false;
import Analysis.Prefetch.PrefetchAnalysis;
import Analysis.FlatIRGraph.FlatIRGraph;
import Analysis.OwnershipAnalysis.OwnershipAnalysis;
-import Analysis.MLP.MLPAnalysis;
import Analysis.Disjoint.DisjointAnalysis;
import Analysis.OoOJava.OoOJavaAnalysis;
import Analysis.Loops.*;
else if (option.equals("-abcclose"))
state.ARRAYBOUNDARYCHECK=false;
- else if (option.equals("-mlp")) {
- state.MLP = true;
- state.OWNERSHIP = true;
- state.MLP_NUMCORES = Integer.parseInt( args[++i] );
- state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] );
-
- } else if (option.equals("-mlpdebug")) {
- state.MLPDEBUG=true;
-
- } else if (option.equals("-methodeffects")) {
+ else if (option.equals("-methodeffects")) {
state.METHODEFFECTS=true;
} else if (option.equals("-coreprof")) {
} else if (option.equals("-ooojava")) {
state.OOOJAVA = true;
state.DISJOINT = true;
- state.MLP_NUMCORES = Integer.parseInt( args[++i] );
- state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] );
+ state.OOO_NUMCORES = Integer.parseInt( args[++i] );
+ state.OOO_MAXSESEAGE = Integer.parseInt( args[++i] );
} else if (option.equals("-ooodebug") ){
state.OOODEBUG = true;
bf.buildFlat();
SafetyAnalysis sa=null;
PrefetchAnalysis pa=null;
- MLPAnalysis mlpa=null;
OoOJavaAnalysis oooa=null;
if (state.INLINEATOMIC) {
Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
state.FLATIRGRAPHLIBMETHODS);
}
- if (state.OWNERSHIP && !state.MLP) {
+ if (state.OWNERSHIP) {
CallGraph callGraph = new CallGraph(state);
Liveness liveness = new Liveness();
ArrayReferencees ar = new ArrayReferencees(state);
state.METHODEFFECTS);
}
- if (state.MLP) {
- CallGraph callGraph = new CallGraph(state);
- Liveness liveness = new Liveness();
- ArrayReferencees ar = new ArrayReferencees(state);
- OwnershipAnalysis oa = new OwnershipAnalysis(state,
- tu,
- callGraph,
- liveness,
- ar,
- state.OWNERSHIPALLOCDEPTH,
- state.OWNERSHIPWRITEDOTS,
- state.OWNERSHIPWRITEALL,
- state.OWNERSHIPALIASFILE,
- state.METHODEFFECTS);
- mlpa = new MLPAnalysis(state,
- tu,
- callGraph,
- oa);
- }
-
if (state.DISJOINT && !state.OOOJAVA) {
CallGraph cg = new CallGraph(state);
Liveness l = new Liveness();
ArrayReferencees ar = new ArrayReferencees(state);
- DisjointAnalysis da = new DisjointAnalysis(state, tu, cg, l, ar, null, null, null);
+ DisjointAnalysis da = new DisjointAnalysis(state, tu, cg, l, ar, null, null);
}
if (state.OOOJAVA) {
}
LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
GenerateConversions gc=new GenerateConversions(la, state);
- BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa, mlpa,oooa);
+ BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa, oooa);
bc.buildCode();
} else {
- BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa, mlpa,oooa);
+ BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa, oooa);
bc.buildCode();
}
}
Analysis/OwnershipAnalysis/AccessPath.class \
Analysis/Disjoint/DisjointAnalysis.class \
Analysis/Disjoint/ReachGraph.class \
-Analysis/MLP/MLPAnalysis.class \
-Analysis/MLP/VariableSourceToken.class \
-Analysis/MLP/VSTWrapper.class \
-Analysis/MLP/SVKey.class \
-Analysis/MLP/VarSrcTokTable.class \
-Analysis/MLP/CodePlan.class \
Analysis/OoOJava/OoOJavaAnalysis.class \
Analysis/OoOJava/CodePlan.class \
Analysis/OoOJava/SVKey.class \
Analysis/Locality/*.java \
Analysis/OwnershipAnalysis/*.java \
Analysis/Disjoint/*.java \
- Analysis/MLP/*.java \
Analysis/OoOJava/*.java \
Analysis/Prefetch/*.java \
Analysis/Scheduling/*.java \
javadoc:
mkdir javadoc
- javadoc -classpath ../cup:.:$(CLASSPATH) -sourcepath . -private -d javadoc Lex Util IR IR.Tree IR.Flat Analysis Analysis.CallGraph Analysis.Flag Analysis.TaskStateAnalysis Analysis.Locality Analysis.Prefetch Main Analysis.OwnershipAnalysis Analysis.Disjoint Analysis.MLP Analysis.Scheduling
+ javadoc -classpath ../cup:.:$(CLASSPATH) -sourcepath . -private -d javadoc Lex Util IR IR.Tree IR.Flat Analysis Analysis.CallGraph Analysis.Flag Analysis.TaskStateAnalysis Analysis.Locality Analysis.Prefetch Main Analysis.OwnershipAnalysis Analysis.Disjoint Analysis.Scheduling
clean:
- rm -f IR/*.class IR/Tree/*.class Main/*.class Lex/*.class Parse/*.class Parse/Sym.java Parse/Parser.java IR/Flat/*.class classdefs.h methodheaders.h methods.c structdefs.h virtualtable.h task.h taskdefs.c taskdefs.h Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class Analysis/Prefetch/*.class Analysis/FlatIRGraph/*.class Analysis/OwnershipAnalysis/*.class Analysis/Disjoint/*.class Analysis/OoOJava/*.class Analysis/MLP/*.class Analysis/Scheduling/*.class Analysis/Loops/*.class
+ rm -f IR/*.class IR/Tree/*.class Main/*.class Lex/*.class Parse/*.class Parse/Sym.java Parse/Parser.java IR/Flat/*.class classdefs.h methodheaders.h methods.c structdefs.h virtualtable.h task.h taskdefs.c taskdefs.h Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class Analysis/Prefetch/*.class Analysis/FlatIRGraph/*.class Analysis/OwnershipAnalysis/*.class Analysis/Disjoint/*.class Analysis/OoOJava/*.class Analysis/Scheduling/*.class Analysis/Loops/*.class
cleanclass:
- rm -f IR/*.class IR/Tree/*.class Main/*.class IR/Flat/*.class Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class Analysis/Prefetch/*.class Analysis/FlatIRGraph/*.class Analysis/OwnershipAnalysis/*.class Analysis/Disjoint/*.class Analysis/OoOJava/*.class Analysis/MLP/*.class Analysis/Scheduling/*.class Analysis/Loops/*.class
+ rm -f IR/*.class IR/Tree/*.class Main/*.class IR/Flat/*.class Analysis/*.class Analysis/Flag/*.class Analysis/CallGraph/*.class Analysis/TaskStateAnalysis/*.class Interface/*.class Util/*.class Analysis/Locality/*.class Analysis/Prefetch/*.class Analysis/FlatIRGraph/*.class Analysis/OwnershipAnalysis/*.class Analysis/Disjoint/*.class Analysis/OoOJava/*.class Analysis/Scheduling/*.class Analysis/Loops/*.class
cleandoc:
rm -rf javadoc
--- /dev/null
+PROGRAM=test
+
+SOURCE_FILES=$(PROGRAM).java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+BSFLAGS= -mainclass Test -disjoint -disjoint-k 1 -enable-assertions
+# -disjoint-write-dots final -disjoint-alias-file aliases.txt normal -justanalyze -joptimize -flatirusermethods
+
+all: $(PROGRAM).bin
+
+view: PNGs
+ eog *.png &
+
+PNGs: DOTs
+ d2p *COMPLETE*.dot
+
+DOTs: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+ $(BUILDSCRIPT) $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+clean:
+ rm -f $(PROGRAM).bin
+ rm -fr tmpbuilddirectory
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f aliases.txt
--- /dev/null
+public class Foo {
+ public Foo() {
+ f = null;
+ }
+ public Foo f;
+}
+
+public class Test {
+ static public void main( String[] args ) {
+ Foo a = new Foo();
+ //Foo b = f0( a );
+ //b.f = new Foo();
+
+ /*
+ Foo ptr = a;
+ int cnt = 0;
+ while( ptr != null ) {
+ cnt++;
+ ptr = ptr.f;
+ }
+
+ System.out.println( "expecting 7, "+cnt );
+ */
+ }
+
+ static public Foo f0( Foo a ) {
+ a.f = new Foo();
+ Foo b = f1( a.f );
+ b.f = new Foo();
+ return b.f;
+ }
+
+ static public Foo f1( Foo a ) {
+ a.f = new Foo();
+ Foo b = f2( a.f );
+ b.f = new Foo();
+ return b.f;
+ }
+
+ static public Foo f2( Foo a ) {
+ a.f = new Foo();
+ return a.f;
+ }
+}
--- /dev/null
+PROGRAM=test
+
+SOURCE_FILES=$(PROGRAM).java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+BSFLAGS= -joptimize -flatirusermethods -mainclass Test -justanalyze -disjoint -disjoint-k 1 -disjoint-write-dots final -disjoint-alias-file aliases.txt normal -enable-assertions
+
+all: $(PROGRAM).bin
+
+view: PNGs
+ eog *.png &
+
+PNGs: DOTs
+ d2p *COMPLETE*.dot
+
+DOTs: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+ $(BUILDSCRIPT) $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+clean:
+ rm -f $(PROGRAM).bin
+ rm -fr tmpbuilddirectory
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f aliases.txt
--- /dev/null
+public class Foo {
+ public Foo() {}
+ public Foo f;
+}
+
+public class Test {
+ static public void main( String[] args ) {
+ Foo a = disjoint A new Foo();
+ genreach r2;
+ Foo b = createFoo();
+ genreach r3;
+ }
+
+ static public Foo createFoo() {
+ return disjoint B new Foo();
+ }
+}
--- /dev/null
+PROGRAM=Test
+
+SOURCE_FILES=test.java
+
+BUILDSCRIPT=../../../buildscript
+
+COREPROFOVERFLOW= #-coreprof-checkoverflow
+USECOREPROF= #-coreprof $(COREPROFOVERFLOW) \
+ -coreprof-eventwords 1024*1024*128 \
+ -coreprof-enable cpe_main \
+ -coreprof-enable cpe_runmalloc \
+ -coreprof-enable cpe_runfree \
+ -coreprof-enable cpe_count_poolalloc \
+ -coreprof-enable cpe_count_poolreuse \
+ -coreprof-enable cpe_workschedgrab \
+ -coreprof-enable cpe_taskdispatch \
+ -coreprof-enable cpe_taskexecute \
+ -coreprof-enable cpe_taskretire
+# -coreprof-enable cpe_taskstallvar \
+# -coreprof-enable cpe_taskstallmem
+
+
+DISJOINT= -disjoint -disjoint-k 1 -enable-assertions #-disjoint-desire-determinism
+
+USEOOO= -ooojava 24 2 -ooodebug -squeue
+USERCR= -ooojava 23 2 -rcr -ooodebug -squeue
+
+BSFLAGS= -justanalyze -64bit -mainclass $(PROGRAM) -heapsize-mb 1024 -garbagestats -noloop -joptimize -debug #-ooodebug-disable-task-mem-pool
+
+
+all: ooo
+
+
+single:
+ $(BUILDSCRIPT) $(BSFLAGS) -thread -o $(PROGRAM)s -builddir sing $(SOURCE_FILES)
+
+
+ooo: $(PROGRAM)p.bin
+
+$(PROGRAM)p.bin: $(SOURCE_FILES) makefile
+ $(BUILDSCRIPT) $(BSFLAGS) $(USECOREPROF) $(USEOOO) $(DISJOINT) -o $(PROGRAM)p -builddir par $(SOURCE_FILES)
+
+rcr: $(PROGRAM)r.bin
+
+$(PROGRAM)r.bin: $(SOURCE_FILES) makefile
+ $(BUILDSCRIPT) $(BSFLAGS) $(USECOREPROF) $(USERCR) $(DISJOINT) -o $(PROGRAM)r -builddir rcr $(SOURCE_FILES)
+
+
+clean:
+ rm -f $(PROGRAM)p.bin $(PROGRAM)r.bin $(PROGRAM)s.bin
+ rm -fr par rcr sing
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f *.txt
+ rm -f aliases.txt
+ rm -f mlpReport*txt
+ rm -f results*txt
+ rm -f coreprof.dat
--- /dev/null
+public class Foo {
+ public int z;
+ public Foo() {}
+}
+
+public class Test {
+
+ /*
+ static public void main( String args[] ) {
+ FOOO();
+ }
+
+ static public void FOOO() {
+
+ int x = 1000000;
+
+ for( int i = 0; i < 200000; ++i ) {
+ rblock a {
+ Foo f = new Foo();
+ f.z = 0;
+ ++f.z;
+ }
+ rblock b {
+ --f.z;
+ }
+ int y = -1000;
+ if( i % 2 == 0 ) {
+ y = 1000;
+ }
+
+ if( f.z > 0 ) {
+ System.out.println( "WHOA WHOA WHOA" );
+ }
+ x += f.z + y;
+ }
+
+ System.out.println( x );
+ }
+ */
+
+ /*
+ static public void main( String args[] ) {
+
+ int x = 1000000;
+
+ for( int i = 0; i < 200000; ++i ) {
+
+ Foo f = new Foo();
+ f.z = 0;
+
+ int y = -1000;
+ if( i % 2 == 0 ) {
+ y = 1000;
+ }
+
+ rblock g {
+ f.z--;
+ }
+
+ aCall( f );
+
+ x += f.z + y;
+ }
+
+ System.out.println( x );
+ }
+
+ static public void aCall( Foo f ) {
+ f.z++;
+
+ if( f.z > 0 ) {
+ System.out.println( "WHOA WHOA WHOA" );
+ }
+ }
+
+ static public void yo() {
+ rblock h {
+ int x = 2;
+ }
+ }
+ */
+
+
+ static public void main( String args[] ) {
+
+ int x = 1;
+
+ rblock a {
+ x++;
+ }
+
+ x--;
+
+ int y = yo();
+
+ x = x - y;
+
+ rblock c {
+ x++;
+ }
+
+ x--;
+
+ System.out.println( x );
+ }
+
+ static public int yo() {
+ int j = 0;
+
+ rblock b {
+ j++;
+ }
+
+ j--;
+ return j;
+ }
+}