Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

DomAnalysis.java

00001 package edu.ksu.cis.bandera.prog;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999   Hongjun Zheng (zheng@cis.ksu.edu)      *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import ca.mcgill.sable.util.*;
00036 import ca.mcgill.sable.soot.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 
00039 import edu.ksu.cis.bandera.prog.Index;
00040 import edu.ksu.cis.bandera.util.GenericSet;
00041 
00042 public class DomAnalysis extends AbstractDom
00043 {
00044   private Map stmtToDoms;
00045   private Map stmtToImmediateDom;
00046 
00047   public DomAnalysis(StmtList statementsList, StmtGraph sg)
00048     {
00049       super(statementsList, sg);
00050       stmtToDoms = new HashMap(stmtList.size() *2 +1, 0.7f);
00051 
00052       dominatorsMap();
00053       stmtToImmediateDom = computeImmedDom(stmtToDoms);
00054     }
00055   private void dominatorsMap()
00056     {      
00057       GenericSet dominators;
00058       GenericSet tempDoms;
00059       Stmt keyStmt;
00060       Index stmtIndex;
00061       LinkedList workList = new LinkedList();
00062       GenericSet visitedNode = new GenericSet();
00063 
00064       GenericSet startNodes = getStartNodes();
00065 
00066       //initialize the entry statement's dominator as itself
00067       for (int i = 0; i< startNodes.size(); i++)
00068     {
00069       stmtIndex = (Index) startNodes.setRef(i);
00070       workList.addFirst(stmtIndex);
00071 
00072       keyStmt = (Stmt) stmtList.get(stmtIndex.index());
00073       dominators = new GenericSet(stmtIndex);
00074       stmtToDoms.put(keyStmt, dominators);
00075     }
00076 
00077       //initialize the stmtDomin map for other statement as all stmt set
00078       //but not including exception handling statement
00079 
00080       dominators = indexSetWithoutExceptionHandling();
00081   
00082       while (workList.size() != 0)
00083     {
00084       Index nodeIndex = (Index) workList.removeFirst();
00085       visitedNode.addElemToSet(nodeIndex);
00086       Stmt nodeStmt = (Stmt) stmtList.get(nodeIndex.index());
00087 
00088       if (! startNodes.contains(nodeIndex))
00089         stmtToDoms.put(nodeStmt, dominators);
00090 
00091       List nodeStmtSuccs = stmtGraph.getSuccsOf(nodeStmt);
00092       List newSuccs = removeExceptionCaught(nodeStmtSuccs);
00093       Iterator succIt = newSuccs.iterator();
00094       while (succIt.hasNext())
00095         {
00096           Stmt succStmt = (Stmt) succIt.next();
00097           Index succIndex = new Index(stmtList.indexOf(succStmt));
00098           if (workList.contains(succIndex) || 
00099           visitedNode.contains(succIndex))
00100         {
00101         }
00102           else workList.addLast(succIndex);
00103         }
00104     }
00105 
00106       //begin fix point iteration
00107 
00108       boolean change = true;
00109 
00110       while (change)
00111     {
00112       change = false;
00113       workList = new LinkedList();
00114       visitedNode = new GenericSet();
00115 
00116       for (int i = 0; i< startNodes.size(); i++)
00117         {
00118           stmtIndex = (Index) startNodes.setRef(i);
00119           workList.addFirst(stmtIndex);
00120         }
00121 
00122       while (workList.size() != 0)
00123         {
00124           stmtIndex = (Index) workList.removeFirst();
00125           visitedNode.addElemToSet(stmtIndex);
00126 
00127           keyStmt = (Stmt) stmtList.get(stmtIndex.index());
00128           dominators = (GenericSet) stmtToDoms.get(keyStmt);
00129           tempDoms = new GenericSet();
00130           tempDoms = tempDoms.union(dominators);
00131 
00132           List preds = stmtGraph.getPredsOf(keyStmt);
00133 
00134           for (int i = 0; i < preds.size(); i++)
00135         {
00136           Stmt predStmt = (Stmt) preds.get(i);
00137           GenericSet predDom = (GenericSet) stmtToDoms.get(predStmt);
00138 
00139           if (predDom != null)
00140             tempDoms = tempDoms.intersect(predDom);
00141         }
00142 
00143           tempDoms.addElemToSet(stmtIndex);
00144           
00145           if (! tempDoms.equals(dominators))
00146         {
00147           change = true;
00148           stmtToDoms.remove(keyStmt);
00149           stmtToDoms.put(keyStmt, tempDoms);
00150         }
00151 
00152           //begin to add nodes into workList
00153           List keyStmtSuccs = stmtGraph.getSuccsOf(keyStmt);
00154           List newSuccs = removeExceptionCaught(keyStmtSuccs);
00155           Iterator succIt = newSuccs.iterator();
00156           while (succIt.hasNext())
00157         {
00158           Stmt succStmt = (Stmt) succIt.next();
00159           Index succIndex = new Index(stmtList.indexOf(succStmt));
00160           if (workList.contains(succIndex) || 
00161               visitedNode.contains(succIndex))
00162             {
00163             }
00164           else workList.addLast(succIndex);
00165         }         
00166         }
00167     }
00168     }
00169   public GenericSet domsOf(Stmt stmt)
00170     {
00171       return (GenericSet) stmtToDoms.get(stmt);
00172     }
00173   public Index immediateDomOf(Stmt s)
00174     {
00175       return (Index) stmtToImmediateDom.get(s);
00176     }
00177   public Map stmtToDominatorsMap()
00178     {
00179       return stmtToDoms;
00180     }
00181   public Map stmtToImmediateDom()
00182     {
00183       return stmtToImmediateDom;
00184     }
00185 }

Generated at Thu Feb 7 06:44:36 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001