00001 package edu.ksu.cis.bandera.pdgslicer;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00044
00045 public class DeadlockRelatedCriterion {
00046
00047
00048
00049
00050 private SootClass[] classes;
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 private List deadlockRelatedInvokes = new ArrayList();
00066
00067
00068
00069 private Vector sliceInterests = new Vector();
00070
00071
00072
00073
00074
00075
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
00096
00097
00098
00099
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
00119
00120
00121
00122
00123
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
00167
00168
00169
00170 Vector getSliceInterestForDL() {
00171 return sliceInterests;
00172 }
00173 }