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

DeadlockRelatedCriterion.java

00001 package edu.ksu.cis.bandera.pdgslicer;
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 
00036 import ca.mcgill.sable.util.*;
00037 import ca.mcgill.sable.soot.*;
00038 import ca.mcgill.sable.soot.jimple.*;
00039 import java.util.Vector;
00040 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00041 import edu.ksu.cis.bandera.pdgslicer.exceptions.*;
00042 /**
00043  * This class is for extracting and storing slice criterion for deadlock checking.
00044  */
00045 public class DeadlockRelatedCriterion {
00046   /**
00047    * All classes need to be checked for deadlock. These classes will be sliced for
00048    * deadlock checking.
00049    */
00050     private SootClass[] classes;
00051   /**
00052    * A list of {@link String String} which is a signature of all method invokes
00053    * related to deadlock checking. 
00054    * <br>
00055    * It's currently including:
00056    * <br>(1) <code>java.lang.Object.notifyAll():void</code>
00057    * <br>(2) <code>java.lang.Object.notify():void</code>
00058    * <br>(3) <code>java.lang.Object.wait():void</code>
00059    * <br>(4) <code>java.lang.Thread.stop():void</code>
00060    * <br>(5) <code>java.lang.Thread.destroy():void</code>
00061    * <br>(6) <code>java.lang.Thread.suspend():void</code>
00062    * <br>(7) <code>java.lang.Thread.resume():void</code>
00063    * <br>(8) <code>java.lang.Thread.join():void</code>
00064    */
00065     private List deadlockRelatedInvokes = new ArrayList();
00066   /**
00067    * A list of extracted {@link SliceInterest SliceInterest}.
00068    */
00069     private Vector sliceInterests = new Vector();
00070   /**
00071    * Constructor of this class:
00072    * <br> (1) Initializing {@link #deadlockRelatedInvokes deadlockRelatedInvokes}.
00073    * <br> (2) {@link #extractSliceInterestForDL() extractSliceInterestForDL()}.
00074    * <p>
00075    * @param classArr an array of sootclasses.
00076    */
00077   public DeadlockRelatedCriterion(SootClass[] classArr)
00078     {
00079       classes = classArr;
00080       String[] invokes =
00081       {"java.lang.Object.notifyAll():void",
00082        "java.lang.Object.notify():void",
00083        "java.lang.Object.wait():void",
00084        "java.lang.Thread.stop():void",
00085        "java.lang.Thread.destroy():void",
00086        "java.lang.Thread.suspend():void",
00087        "java.lang.Thread.resume():void",
00088        "java.lang.Thread.join():void"
00089       };
00090 
00091       deadlockRelatedInvokes.addAll(new ArraySet(invokes));
00092       extractSliceInterestForDL();
00093     }
00094   /**
00095    * Extract slicing interests for deadlock checking.
00096    * <br> Algorithm: scanning every class in {@link #classes classes}, 
00097    * then {@link #extractSliceInterestFromMethod(SootClass, SootMethod) 
00098    * extractSliceInterestFromMethod(sootClass, sootMethod)} 
00099    * except for <code>interface</code> and <code>native</code> methods.
00100    */
00101 private void extractSliceInterestForDL() {
00102     for (int i = 0; i < classes.length; i++) {
00103         SootClass sootClass = classes[i];
00104         int modifiers = sootClass.getModifiers();
00105         if (Modifier.isInterface(modifiers)) {
00106             System.out.println("Class " + sootClass.getName() + " is an interface");
00107             continue;
00108         }
00109         for (Iterator sootMdIt = sootClass.getMethods().iterator(); sootMdIt.hasNext();) {
00110             SootMethod sootMethod = (SootMethod) sootMdIt.next();
00111             if (InfoAnalysis.nativeMdSig.contains(sootMethod) || !Slicer.reachableMethods.contains(sootMethod))
00112                 continue;
00113             extractSliceInterestFromMethod(sootClass, sootMethod);
00114         }
00115     }
00116 }
00117   /**
00118    * Extrace slice interests from a method.
00119    * Put all <code>synchronization</code> statements and deadlock related 
00120    * method invokes into {@link #sliceInterests sliceInterests}.
00121    * <p>
00122    * @param sootClass class where the method is declared.
00123    * @param sootMethod method which will be processed.
00124    */
00125 private void extractSliceInterestFromMethod(SootClass sootClass, SootMethod sootMethod) {
00126     StmtList stmtList = ((MethodInfo) Slicer.sootMethodInfoMap.get(sootMethod)).originalStmtList;
00127     for (Iterator stmtIt = stmtList.iterator(); stmtIt.hasNext();) {
00128         Stmt stmt = (Stmt) stmtIt.next();
00129         if (stmt instanceof EnterMonitorStmt) {
00130             Value op = ((EnterMonitorStmt) stmt).getOp();
00131             if (op instanceof Local) {
00132                 sliceInterests.addElement(new SliceLocal(sootClass, sootMethod, (Local) op));
00133                 sliceInterests.addElement(new SlicePoint(sootClass, sootMethod, stmt, stmtList.indexOf(stmt)));
00134             } else
00135                 throw new ValueTypeException("The operator " + op + " should be local.");
00136         } else
00137             if (stmt instanceof ExitMonitorStmt) {
00138                 Value op = ((ExitMonitorStmt) stmt).getOp();
00139                 if (op instanceof Local) {
00140                     sliceInterests.addElement(new SliceLocal(sootClass, sootMethod, (Local) op));
00141                     sliceInterests.addElement(new SlicePoint(sootClass, sootMethod, stmt, stmtList.indexOf(stmt)));
00142                 } else
00143                     throw new ValueTypeException("The operator " + op + " should be local.");
00144             } else
00145                 if (stmt instanceof InvokeStmt) {
00146                     Value invokeExpr = ((InvokeStmt) stmt).getInvokeExpr();
00147                     if (invokeExpr instanceof VirtualInvokeExpr) {
00148                         VirtualInvokeExpr virtualInvokeExpr = (VirtualInvokeExpr) invokeExpr;
00149                         SootMethod invokeMethod = virtualInvokeExpr.getMethod();
00150                         if (deadlockRelatedInvokes.contains(invokeMethod.getSignature())) {
00151                             sliceInterests.addElement(new SlicePoint(sootClass, sootMethod, stmt,stmtList.indexOf(stmt)));
00152                             Iterator useBoxesIt = stmt.getUseBoxes().iterator();
00153                             while (useBoxesIt.hasNext()) {
00154                                 ValueBox valueBox = (ValueBox) useBoxesIt.next();
00155                                 Value usedValue = valueBox.getValue();
00156                                 if (usedValue instanceof Local) {
00157                                     sliceInterests.addElement(new SliceLocal(sootClass, sootMethod, (Local)usedValue));
00158                                 }
00159                             }
00160                         }
00161                     }
00162                 }
00163     }
00164 }
00165 /**
00166  * Get slice interests for deadlock checking.
00167  * <p>
00168  * @return {@link #sliceInterests sliceInterests}.
00169  */
00170 Vector getSliceInterestForDL() {
00171     return sliceInterests;
00172 }
00173 }

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