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
00037
00038 import ca.mcgill.sable.util.*;
00039 import ca.mcgill.sable.soot.*;
00040 import ca.mcgill.sable.soot.jimple.*;
00041 import edu.ksu.cis.bandera.pdgslicer.exceptions.*;
00042 import edu.ksu.cis.bandera.annotation.*;
00043 import java.util.BitSet;
00044 import java.util.Enumeration;
00045 import java.util.Vector;
00046
00047
00048
00049
00050
00051
00052
00053
00054 public class BuildPDG {
00055
00056
00057
00058 private BitSet exitNodes;
00059 MethodInfo methodInfo;
00060
00061
00062
00063
00064 private Map stmtToPostdoms;
00065
00066
00067
00068
00069 private Map stmtToImmedPostdom;
00070
00071
00072
00073 private StmtList stmtList;
00074 private StmtGraph stmtGraph;
00075 private JimpleBody jimpleBody;
00076
00077
00078
00079 private BitSet staticReachDef[];
00080
00081
00082
00083 private BitSet instanceReachDef[];
00084
00085
00086
00087 private LockAnalysis lockAnalysis = null;
00088
00089
00090
00091
00092
00093 private Map readyDependMap = null;
00094
00095
00096
00097
00098
00099 private Map interferenceMap = null;
00100
00101
00102
00103
00104 private Map callSiteMap = null;
00105
00106
00107
00108 private BitSet exitNodesNoThrow;
00109
00110
00111
00112 private Set instanceFieldDefStmtList = new ArraySet();
00113
00114
00115
00116 private Set staticFieldDefStmtList = null;
00117
00118
00119
00120
00121
00122 private Map stmtToDdOn;
00123
00124 private Integer indefiniteNode = null;
00125
00126
00127
00128
00129
00130 private Map stmtToCdOn;
00131
00132
00133
00134
00135 private Map divergenceMap;
00136 private AnnotationManager annotationManager = null;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 public BuildPDG(MethodInfo mdInfo, AnnotationManager cfanns) {
00149 annotationManager = cfanns;
00150 prepareToBuild(mdInfo);
00151 domination();
00152 dependency();
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 private void cdAnalysisForReturnOfInit() {
00180 BitSet specialInvokeSet = new BitSet(stmtList.size());
00181 for (Iterator si = methodInfo.indexMaps.getSpecialInvokeList().iterator(); si.hasNext();) {
00182 InvokeStmt invoke = (InvokeStmt) si.next();
00183 SpecialInvokeExpr specInvoke = (SpecialInvokeExpr) invoke.getInvokeExpr();
00184 if (methodInfo.indexMaps.getThisRefLocal().equals(specInvoke.getBase())) {
00185 if (specInvoke.getMethod().getName().equals("<init>")) {
00186 if (methodInfo.sootClass.getSuperClass().equals(specInvoke.getMethod().getDeclaringClass())) {
00187 int specialInvokeInt = stmtList.indexOf(invoke);
00188 specialInvokeSet.set(specialInvokeInt);
00189 } else
00190 if (methodInfo.sootClass.equals(specInvoke.getMethod().getDeclaringClass())) {
00191 int specialInvokeInt = stmtList.indexOf(invoke);
00192 specialInvokeSet.set(specialInvokeInt);
00193 }
00194 }
00195 }
00196 }
00197 if (SetUtil.emptyBitSet(specialInvokeSet))
00198 throw new SlicerException("Can not find special invoke of super class in method " + methodInfo.sootMethod);
00199 for (int i = 0; i < exitNodesNoThrow.size(); i++) {
00200 if (exitNodesNoThrow.get(i)) {
00201 Stmt exitStmt = (Stmt) stmtList.get(i);
00202 BitSet cdSet = (BitSet) stmtToCdOn.get(exitStmt);
00203 if (cdSet == null)
00204 cdSet = new BitSet(stmtList.size());
00205 cdSet.or(specialInvokeSet);
00206 stmtToCdOn.put(exitStmt, cdSet);
00207 }
00208 }
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 private void cdAnalysisForStmtsInCatch() {
00219
00220 Annotation annForSm = annotationManager.getAnnotation(methodInfo.sootClass, methodInfo.sootMethod);
00221
00222 Vector currentCFANNs = annForSm.getAllAnnotations(true);
00223
00224 for (Enumeration e = currentCFANNs.elements(); e.hasMoreElements();) {
00225 Annotation cfann = (Annotation) e.nextElement();
00226
00227 if (cfann instanceof TryStmtAnnotation) {
00228 TryStmtAnnotation tryAnnotation = (TryStmtAnnotation) cfann;
00229 Annotation blockAnn = tryAnnotation.getBlockAnnotation();
00230 Stmt stmtsInBlock[] = blockAnn.getStatements();
00231 BitSet stmtsInTryBlock = SetUtil.stmtArrayToBitSet(stmtsInBlock, stmtList);
00232 Vector catchClauses = tryAnnotation.getCatchClauses();
00233
00234 for (Enumeration en = catchClauses.elements(); en.hasMoreElements();) {
00235 CatchAnnotation catchAnn = (CatchAnnotation) en.nextElement();
00236 Stmt stmtsInCatch[] = catchAnn.getStatements();
00237 for (int i = 0; i < stmtsInCatch.length; i++) {
00238 Stmt branchStmt = stmtsInCatch[i];
00239 BitSet cdSet = (BitSet) stmtToCdOn.get(branchStmt);
00240 if (cdSet == null)
00241 cdSet = new BitSet(stmtList.size());
00242 cdSet.or(stmtsInTryBlock);
00243 stmtToCdOn.put(branchStmt, cdSet);
00244 }
00245 }
00246
00247 }
00248
00249 }
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 static Set cloneAndChangeBase(Set original, Value base) {
00267 Set newFields = new ArraySet();
00268 for (Iterator orIt = original.iterator(); orIt.hasNext();) {
00269 InstanceFieldRef insFieldRef = (InstanceFieldRef) orIt.next();
00270 InstanceFieldRef newInsFieldRef = Jimple.v().newInstanceFieldRef(base, insFieldRef.getField());
00271 newFields.add(newInsFieldRef);
00272 }
00273 return newFields;
00274 }
00275
00276
00277
00278
00279
00280 private void collectInstanceFieldDefStmt() {
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 Fields MOD = methodInfo.MOD;
00295 Set paraFields = MOD.paraFields;
00296 Set instanceFields = MOD.instanceFields;
00297 Set otherInsFields = MOD.otherInsFds;
00298 instanceFieldDefStmtList.addAll(instanceFields);
00299 instanceFieldDefStmtList.addAll(otherInsFields);
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 }
00356
00357
00358
00359
00360
00361
00362
00363 private Set collectVarsDefined(Set defStmtList) {
00364 Set varsDefined = new ArraySet();
00365 for (Iterator i = defStmtList.iterator(); i.hasNext();) {
00366 DataBox db = (DataBox) i.next();
00367 Set vars = db.getInterferVars();
00368 varsDefined.addAll(vars);
00369 }
00370 return varsDefined;
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 private Map computeImmedDom(Map stmtToBitSet) {
00386 Map stmtToImmediate = new HashMap(stmtList.size() * 2 + 1, 0.7f);
00387 Iterator keyStmtIt = stmtToBitSet.keySet().iterator();
00388 while (keyStmtIt.hasNext()) {
00389 Stmt keyStmt = (Stmt) keyStmtIt.next();
00390 int keyStmtIndex = stmtList.indexOf(keyStmt);
00391 BitSet doms = (BitSet) stmtToBitSet.get(keyStmt);
00392 BitSet workSet = (BitSet) doms.clone();
00393 workSet.clear(keyStmtIndex);
00394
00395
00396 BitSet immediate = (BitSet) workSet.clone();
00397 for (int i = 0; i < workSet.size(); i++) {
00398 if (workSet.get(i)) {
00399 BitSet domX = (BitSet) stmtToBitSet.get((Stmt) stmtList.get(i));
00400 BitSet domX2 = (BitSet) domX.clone();
00401 domX2.clear(i);
00402 domX2.and(immediate);
00403 immediate.xor(domX2);
00404 }
00405 }
00406 int immT = 0;
00407 for (int i = 0; i < immediate.size(); i++) {
00408 if (immediate.get(i)) {
00409 stmtToImmediate.put(keyStmt, new Integer(i));
00410 immT++;
00411 }
00412 }
00413 if (immT == 0)
00414 stmtToImmediate.put(keyStmt, IndexMaps.EntryNode);
00415 else
00416 if (immT > 1)
00417 throw new DomOrPostdomNotUniqueException("immediate dominator and postdominator should be unique or none for statement: " + keyStmt);
00418 }
00419 return stmtToImmediate;
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 private void controlDependAnalysis() {
00478 stmtToCdOn = new HashMap();
00479 for (Iterator stmtIt = stmtList.iterator(); stmtIt.hasNext();) {
00480 Stmt stmt = (Stmt) stmtIt.next();
00481 List succs = removeExceptionCaught(stmtGraph.getSuccsOf(stmt));
00482 if (succs.size() < 2)
00483 continue;
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 Stmt xSuccStmt = (Stmt) succs.get(0);
00494 BitSet PsUnion = (BitSet) postdominatorsOf(xSuccStmt).clone();
00495 for (int i = 1; i < succs.size(); i++) {
00496 xSuccStmt = (Stmt) succs.get(i);
00497 BitSet Ps = (BitSet) postdominatorsOf(xSuccStmt).clone();
00498 PsUnion.or(Ps);
00499 }
00500 BitSet Px = (BitSet) postdominatorsOf(stmt).clone();
00501 PsUnion.xor(Px);
00502
00503
00504 for (int i = 0; i < PsUnion.size(); i++) {
00505 if (!PsUnion.get(i))
00506 continue;
00507 int cdStmtIndex = stmtList.indexOf(stmt);
00508 Stmt branchStmt = (Stmt) stmtList.get(i);
00509 BitSet cdSet = (BitSet) stmtToCdOn.get(branchStmt);
00510 if (cdSet == null)
00511 cdSet = new BitSet(stmtList.size());
00512 cdSet.set(cdStmtIndex);
00513 stmtToCdOn.put(branchStmt, cdSet);
00514 }
00515 }
00516
00517
00518 cdAnalysisForStmtsInCatch();
00519 if (methodInfo.sootMethod.getName().equals("<init>"))
00520 cdAnalysisForReturnOfInit();
00521 }
00522
00523
00524
00525
00526
00527
00528
00529 public BitSet controlNodesOf(Stmt st)
00530 {
00531 return (BitSet) stmtToCdOn.get(st);
00532 }
00533
00534
00535
00536
00537
00538
00539
00540
00541 public Set controlSuccNodesOf(Stmt stmt) {
00542 Set succNodes = new ArraySet();
00543 int index = stmtList.indexOf(stmt);
00544 for (Iterator stmtIt = stmtToCdOn.keySet().iterator(); stmtIt.hasNext();) {
00545 Stmt controlledStmt = (Stmt) stmtIt.next();
00546 BitSet controlNodes = (BitSet) stmtToCdOn.get(controlledStmt);
00547 if (controlNodes.get(index))
00548 succNodes.add(controlledStmt);
00549 }
00550 return succNodes;
00551 }
00552
00553
00554
00555
00556
00557
00558
00559
00560 private boolean dataBoxesContains(Set dataBoxes, Stmt stmt)
00561 {
00562 for (Iterator boxIt = dataBoxes.iterator(); boxIt.hasNext();)
00563 {
00564 DataBox db = (DataBox) boxIt.next();
00565 if (stmt==db.getStmt()) return true;
00566 }
00567 return false;
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 private void dataDependAnalysis() {
00581 stmtToDdOn = new HashMap(stmtList.size() * 2 + 1, 0.7f);
00582 LocalDefs localDefs = new SimpleLocalDefs((CompleteStmtGraph) stmtGraph);
00583 for (Iterator stmtIt = stmtList.iterator(); stmtIt.hasNext();) {
00584 Stmt stmt = (Stmt) stmtIt.next();
00585 Set ddList = new ArraySet();
00586 for (Iterator useBoxIt = stmt.getUseBoxes().iterator(); useBoxIt.hasNext();) {
00587 ValueBox useBox = (ValueBox) useBoxIt.next();
00588 if (useBox.getValue() instanceof Local) {
00589 Local local = (Local) useBox.getValue();
00590 List defsOfUse = localDefs.getDefsOfAt(local, stmt);
00591
00592
00593
00594 for (Iterator defsIt = defsOfUse.iterator(); defsIt.hasNext();) {
00595 Stmt def = (Stmt) defsIt.next();
00596 Set tempSet = new ArraySet();
00597 tempSet.add(local);
00598 DataBox ddBox = new DataBox(def, tempSet);
00599 ddList.add(ddBox);
00600 }
00601
00602
00603 if (local.getType() instanceof ArrayType)
00604 ddForArray(ddList, stmt, local);
00605 } else
00606 if (useBox.getValue() instanceof InstanceFieldRef) {
00607 dataDependOfInstanceFieldRef((InstanceFieldRef) useBox.getValue(), stmt, ddList);
00608 }
00609 }
00610
00611 stmtToDdOn.put(stmt, ddList);
00612 }
00613
00614
00615 ddForStaticAndInstanceFd();
00616
00617
00618 ddForParameters();
00619 }
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 private void dataDependOfInstanceFieldRef(InstanceFieldRef insfr, Stmt stmt, Set ddList) {
00633 Set instanceVarsDefined = collectVarsDefined(instanceFieldDefStmtList);
00634 Set fieldsDefined = fieldRefToSootField(instanceVarsDefined);
00635 if (fieldsDefined.contains(insfr.getField())) {
00636
00637
00638 Object array[] = instanceFieldDefStmtList.toArray();
00639 for (int mm = 0; mm < array.length; mm++) {
00640
00641 {
00642 DataBox db2 = (DataBox) array[mm];
00643 Set vars = db2.getInterferVars();
00644 Set fields = fieldRefToSootField(vars);
00645 if (fields.contains(insfr.getField())) {
00646 Set fieldReferences = getRefsWithCommonField(vars,insfr.getField());
00647 Stmt defStmt = db2.getInterferStmt();
00648 if (defStmt.equals(stmt)) {
00649 if (SlicingMethod.isCallSite(callSiteMap, stmt) != null) {
00650 } else {
00651
00652 if (SlicingMethod.reachableStmtFrom(defStmt, stmtGraph).contains(stmt)) {
00653
00654 if (BuildPDG.mayPointToTheSameRef(insfr.getBase(), fieldReferences, methodInfo.sootMethod, methodInfo.sootMethod)) {
00655 DataBox ddBox = new DataBox(defStmt, vars);
00656 ddList.add(ddBox);
00657 }
00658 }
00659 }
00660 } else {
00661
00662 if (SlicingMethod.reachableStmtFrom(defStmt, stmtGraph).contains(stmt)) {
00663
00664 if (BuildPDG.mayPointToTheSameRef(insfr.getBase(), fieldReferences, methodInfo.sootMethod, methodInfo.sootMethod)) {
00665 DataBox ddBox = new DataBox(defStmt, vars);
00666 ddList.add(ddBox);
00667 }
00668 }
00669 }
00670 }
00671 }
00672 }
00673
00674 }
00675 }
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 private void dataDependOfStaticFieldRef(StaticFieldRef staticVariable, Stmt stmt, Set ddList) {
00689 Set staticVarsDefined = collectVarsDefined(staticFieldDefStmtList);
00690 if (staticVarsDefined.contains(staticVariable)) {
00691
00692 BitSet reachIni = staticReachDef[stmtList.indexOf(stmt)];
00693 Object array[] = staticFieldDefStmtList.toArray();
00694 for (int mm = 0; mm < array.length; mm++) {
00695 if (reachIni.get(mm)) {
00696 DataBox db2 = (DataBox) array[mm];
00697 Set vars = db2.getInterferVars();
00698 if (vars.contains(staticVariable)) {
00699 Stmt defStmt = db2.getInterferStmt();
00700 if (defStmt.equals(stmt)) {
00701 if (SlicingMethod.isCallSite(callSiteMap, stmt) != null) {
00702 } else {
00703 DataBox ddBox = new DataBox(defStmt, vars);
00704 ddList.add(ddBox);
00705 }
00706 } else {
00707 DataBox ddBox = new DataBox(defStmt, vars);
00708 ddList.add(ddBox);
00709 }
00710 }
00711 }
00712 }
00713
00714 }
00715 }
00716
00717
00718
00719
00720
00721
00722
00723 public Set dataNodesOf(Stmt st)
00724 {
00725 return (Set) stmtToDdOn.get(st);
00726 }
00727
00728
00729
00730
00731
00732
00733
00734 public Set dataSuccNodesOf(Stmt stmt)
00735 {
00736 Set succNodes = new ArraySet();
00737 for (Iterator stmtIt = stmtToDdOn.keySet().iterator(); stmtIt.hasNext();)
00738 {
00739 Stmt reachedStmt = (Stmt) stmtIt.next();
00740 Set dataBoxes = (Set) stmtToDdOn.get(reachedStmt);
00741 if (dataBoxesContains(dataBoxes, stmt))
00742 succNodes.add(reachedStmt);
00743 }
00744 return succNodes;
00745 }
00746
00747
00748
00749
00750
00751
00752 private void ddForArray(Set ddList, Stmt stmt, Local arrayLocal) {
00753
00754 Map arrayRefs = new HashMap();
00755 for (Iterator stmtIt = stmtList.iterator(); stmtIt.hasNext();) {
00756 Stmt s = (Stmt) stmtIt.next();
00757 List defList = s.getDefBoxes();
00758 for (Iterator defBoxIt = defList.iterator(); defBoxIt.hasNext();) {
00759 ValueBox defBox = (ValueBox) defBoxIt.next();
00760 Value defValue = defBox.getValue();
00761 if (defValue instanceof ArrayRef) {
00762
00763 arrayRefs.put(defValue, s);
00764 }
00765 }
00766 }
00767
00768
00769 for (Iterator keyIt = arrayRefs.keySet().iterator(); keyIt.hasNext();) {
00770 ArrayRef defValue = (ArrayRef) keyIt.next();
00771 Value baseValue = defValue.getBase();
00772
00773
00774 if (baseValue instanceof Local) {
00775
00776
00777
00778 if (mayPointToTheSameRef(arrayLocal,baseValue, methodInfo.sootMethod, methodInfo.sootMethod))
00779 {
00780 Stmt defStmt = (Stmt) arrayRefs.get(defValue);
00781
00782 if (SlicingMethod.reachableStmtFrom(defStmt, stmtGraph).contains(stmt)) {
00783 Set vars = new ArraySet();
00784 vars.add(defValue);
00785 DataBox ddBox = new DataBox(defStmt, vars);
00786 ddList.add(ddBox);
00787 }
00788 }
00789 }
00790 }
00791 }
00792
00793
00794
00795
00796
00797
00798 private void ddForParameters() {
00799 for (Iterator siteIt = callSiteMap.keySet().iterator(); siteIt.hasNext();) {
00800 CallSite site = (CallSite) siteIt.next();
00801 SootMethod calledMd = (SootMethod) callSiteMap.get(site);
00802 MethodInfo calledMdInfo = (MethodInfo) Slicer.sootMethodInfoMap.get(calledMd);
00803 if (calledMdInfo==null) continue;
00804 Fields usedFields = calledMdInfo.REF;
00805 Stmt callSiteStmt = site.callStmt;
00806 int callSiteStmtIndex = stmtList.indexOf(callSiteStmt);
00807 Set ddList = new ArraySet();
00808 Set usingParas = Fields.parametersLocalize(calledMdInfo, usedFields, site.invokeExpr);
00809 for (Iterator i = usingParas.iterator(); i.hasNext();) {
00810 InstanceFieldRef para = (InstanceFieldRef) i.next();
00811 dataDependOfInstanceFieldRef(para, callSiteStmt, ddList);
00812 }
00813 if (ddList.size() == 0)
00814 continue;
00815 if (stmtToDdOn.containsKey(callSiteStmt))
00816 ddList.addAll((Set) stmtToDdOn.get(callSiteStmt));
00817 stmtToDdOn.put(callSiteStmt, ddList);
00818 }
00819 }
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 private void ddForStaticAndInstanceFd() {
00830 Fields refFields = methodInfo.REF;
00831
00832 for (Iterator i = refFields.staticFields.iterator(); i.hasNext();) {
00833 DataBox dbx = (DataBox) i.next();
00834 Set ddList = new ArraySet();
00835 Stmt useStmt = dbx.getInterferStmt();
00836 for (Iterator j = dbx.getInterferVars().iterator(); j.hasNext();) {
00837 StaticFieldRef stcField = (StaticFieldRef) j.next();
00838 dataDependOfStaticFieldRef(stcField, useStmt, ddList);
00839 }
00840 if (ddList.size() == 0)
00841 continue;
00842 if (stmtToDdOn.containsKey(useStmt))
00843 ddList.addAll((Set) stmtToDdOn.get(useStmt));
00844 stmtToDdOn.put(useStmt, ddList);
00845 }
00846
00847 for (Iterator i = refFields.instanceFields.iterator(); i.hasNext();) {
00848 DataBox dbx = (DataBox) i.next();
00849 Set ddList = new ArraySet();
00850 Stmt useStmt = dbx.getInterferStmt();
00851 for (Iterator j = dbx.getInterferVars().iterator(); j.hasNext();) {
00852 InstanceFieldRef insField = (InstanceFieldRef) j.next();
00853 dataDependOfInstanceFieldRef(insField, useStmt, ddList);
00854 }
00855 if (ddList.size() == 0)
00856 continue;
00857 if (stmtToDdOn.containsKey(useStmt))
00858 ddList.addAll((Set) stmtToDdOn.get(useStmt));
00859 stmtToDdOn.put(useStmt, ddList);
00860 }
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874 private Set defsNotPreserves(int staticDefIndex) {
00875 Set defsNotPres = new ArraySet();
00876 Object array[] = staticFieldDefStmtList.toArray();
00877 defsNotPres.add(new Integer(staticDefIndex));
00878 DataBox staticBox = (DataBox) array[staticDefIndex];
00879 Set staticDefs = staticBox.getInterferVars();
00880 for (int i = 0; i < array.length; i++) {
00881 DataBox db = (DataBox) array[i];
00882 Set staticDefs2 = db.getInterferVars();
00883 Set intersectDefs = SetUtil.setIntersection(staticDefs, staticDefs2);
00884 if (intersectDefs.size() != 0) {
00885 boolean hasNoArrayComponent = true;
00886 for (Iterator varIt = intersectDefs.iterator(); varIt.hasNext();) {
00887 Value staticVar = (Value) varIt.next();
00888 Type varType = staticVar.getType();
00889 if (varType instanceof ArrayType) {
00890
00891
00892 Stmt defStmt = db.getStmt();
00893 List defBoxes = defStmt.getDefBoxes();
00894 for (Iterator defIt = defBoxes.iterator(); defIt.hasNext();) {
00895 ValueBox defBox = (ValueBox) defIt.next();
00896 Value defValue = defBox.getValue();
00897 if (defValue instanceof ArrayRef)
00898 hasNoArrayComponent = false;
00899 }
00900 }
00901 }
00902 if (hasNoArrayComponent)
00903 defsNotPres.add(new Integer(i));
00904 }
00905 }
00906 return defsNotPres;
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 private void dependency() {
00918 if (staticFieldDefStmtList.size() != 0)
00919 reachingDefOfStaticField();
00920
00921 if (instanceFieldDefStmtList.size() != 0)
00922 reachingDefOfInstanceField();
00923 controlDependAnalysis();
00924 dataDependAnalysis();
00925
00926
00927 specialInvokeDdAnalysis();
00928 divergenceDependenceAnalysis();
00929 }
00930
00931
00932
00933
00934 private void divergenceDependenceAnalysis() {
00935 divergenceMap = new HashMap();
00936 Stmt[] statementsInLoop;
00937 Stmt[] testStatements;
00938 Annotation annForSm = annotationManager.getAnnotation(methodInfo.sootClass, methodInfo.sootMethod);
00939 Vector currentCFANNs = annForSm.getAllAnnotations(true);
00940 for (Enumeration e = currentCFANNs.elements(); e.hasMoreElements();) {
00941 Annotation cfann = (Annotation) e.nextElement();
00942 statementsInLoop = null;
00943 testStatements = null;
00944 if (cfann instanceof DoWhileStmtAnnotation) {
00945 DoWhileStmtAnnotation doWhile = (DoWhileStmtAnnotation) cfann;
00946 statementsInLoop = doWhile.getStatements();
00947 testStatements = doWhile.getTestStatements();
00948 } else
00949 if (cfann instanceof ForStmtAnnotation) {
00950 ForStmtAnnotation forStmt = (ForStmtAnnotation) cfann;
00951 statementsInLoop = forStmt.getStatements();
00952 testStatements = forStmt.getTestStatements();
00953 } else
00954 if (cfann instanceof WhileStmtAnnotation) {
00955 WhileStmtAnnotation whileStmt = (WhileStmtAnnotation) cfann;
00956 statementsInLoop = whileStmt.getStatements();
00957 testStatements = whileStmt.getTestStatements();
00958 }
00959 if ((statementsInLoop == null) || (testStatements == null))
00960 continue;
00961 Stmt preDivergencePoint = null;
00962 if (testStatements.length == 0)
00963 preDivergencePoint = statementsInLoop[0];
00964 else
00965 preDivergencePoint = getConditionalStmtFrom(testStatements);
00966 Set reachableStmtsFromThePoint = SlicingMethod.reachableStmtSetFrom(preDivergencePoint, stmtGraph);
00967 BitSet reachableBitSet = SetUtil.stmtSetToBitSet(reachableStmtsFromThePoint, stmtList);
00968 BitSet stmtsBitSetInLoop = SetUtil.stmtArrayToBitSet(statementsInLoop, stmtList);
00969 reachableBitSet = SetUtil.bitSetAndNot(reachableBitSet, stmtsBitSetInLoop);
00970 divergenceMap.put(preDivergencePoint, reachableBitSet);
00971 }
00972 }
00973
00974
00975
00976
00977
00978
00979 private void domination()
00980 {
00981
00982 postDomAnalysis();
00983 immediateDominators();
00984 }
00985
00986
00987
00988
00989
00990
00991 public static Set fieldRefToSootField(Set refSet) {
00992 Set sootFieldSet = new ArraySet();
00993 for (Iterator refIt = refSet.iterator(); refIt.hasNext();) {
00994 FieldRef oneRef = (FieldRef) refIt.next();
00995 sootFieldSet.add(oneRef.getField());
00996 }
00997 return sootFieldSet;
00998 }
00999
01000
01001
01002
01003
01004 public Map getCdMap()
01005 {
01006 return stmtToCdOn;
01007 }
01008
01009
01010
01011
01012
01013
01014 private Stmt getConditionalStmtFrom(Stmt[] testStmts) {
01015 for (int i = 0; i < testStmts.length; i++) {
01016 if (testStmts[i] instanceof IfStmt)
01017 return testStmts[i];
01018 }
01019 return testStmts[0];
01020 }
01021
01022
01023
01024
01025
01026 public Map getDdMap()
01027 {
01028 return stmtToDdOn;
01029 }
01030
01031
01032
01033
01034
01035 Map getDivergenceMap() {
01036 return divergenceMap;
01037 }
01038
01039
01040
01041
01042
01043
01044 private Set getHandlerStmtSet() {
01045 Set stmtSet = new ArraySet();
01046 for (Iterator trapIt = jimpleBody.getTraps().iterator(); trapIt.hasNext();) {
01047 Trap trap = (Trap) trapIt.next();
01048 Stmt handlerStmt = (Stmt) trap.getHandlerUnit();
01049 stmtSet.add(handlerStmt);
01050 }
01051 return stmtSet;
01052 }
01053
01054
01055
01056
01057
01058
01059
01060 private int getInstanceDefIndexOf(Stmt s)
01061 {
01062 int index = -1;
01063 Object array[] = instanceFieldDefStmtList.toArray();
01064 for (int i = 0; i<array.length; i++)
01065 {
01066 DataBox db = (DataBox) array[i];
01067 Stmt fieldDefStmt = db.getInterferStmt();
01068 if (fieldDefStmt.equals(s))
01069 {
01070 index = i;
01071 return index;
01072 }
01073 }
01074
01075 return index;
01076 }
01077
01078
01079
01080
01081
01082 public Set getInstanceFieldDefStmtList()
01083 {
01084 return instanceFieldDefStmtList;
01085 }
01086
01087
01088
01089
01090
01091 public Map getInterferenceMap()
01092 {
01093 return interferenceMap;
01094 }
01095
01096
01097
01098
01099
01100 public LockAnalysis getLockAnalysis()
01101 {
01102 return lockAnalysis;
01103 }
01104
01105
01106
01107
01108
01109 public Map getReadyDependMap()
01110 {
01111 return readyDependMap;
01112 }
01113
01114
01115
01116
01117
01118
01119
01120 private Set getRefsWithCommonField(Set vars, SootField sootField) {
01121 Set refSet = new ArraySet();
01122 for (Iterator varIt = vars.iterator(); varIt.hasNext();) {
01123 Object var = (Object) varIt.next();
01124 if (var instanceof InstanceFieldRef) {
01125 InstanceFieldRef insVar = (InstanceFieldRef) var;
01126 if (insVar.getField().equals(sootField))
01127 refSet.add(insVar.getBase());
01128 }
01129 }
01130 return refSet;
01131 }
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164 private Stmt getSpecialInvokeStmtOf(DataBox ddBoxWithNewExpr, SootClass newClass) {
01165 for (Iterator stmtKeyIt = stmtToDdOn.keySet().iterator(); stmtKeyIt.hasNext();) {
01166 Stmt stmtK = (Stmt) stmtKeyIt.next();
01167 if (!(stmtK instanceof InvokeStmt))
01168 continue;
01169 InvokeStmt invokeStmtK = (InvokeStmt) stmtK;
01170 Value invokeExpr = invokeStmtK.getInvokeExpr();
01171 if (!(invokeExpr instanceof SpecialInvokeExpr))
01172 continue;
01173 String methodInvoked = ((InvokeExpr) invokeExpr).getMethod().getName();
01174 if (!methodInvoked.equals("<init>"))
01175 continue;
01176
01177
01178
01179
01180 SootClass typeOfInvokeBase = ((InvokeExpr) invokeExpr).getMethod().getDeclaringClass();
01181
01182
01183 if (newClass.equals(typeOfInvokeBase) || newClass.getSuperClass().equals(typeOfInvokeBase)) {
01184 Set specDdBoxes = (Set) stmtToDdOn.get(stmtK);
01185 if (specDdBoxes.contains(ddBoxWithNewExpr))
01186 return stmtK;
01187 }
01188 }
01189 throw new NoInitStmtException("Can not find the special invoke init statement dependent on " + ddBoxWithNewExpr + " in getSpecialInvokeStmtOf of BuildPDG.java");
01190 }
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 private Stmt getSpecialInvokeStmtOf(DataBox ddBoxWithNewExpr, String typeOfNewExpr) {
01224 for (Iterator stmtKeyIt = stmtToDdOn.keySet().iterator(); stmtKeyIt.hasNext();) {
01225 Stmt stmtK = (Stmt) stmtKeyIt.next();
01226 if (!(stmtK instanceof InvokeStmt))
01227 continue;
01228 InvokeStmt invokeStmtK = (InvokeStmt) stmtK;
01229 Value invokeExpr = invokeStmtK.getInvokeExpr();
01230 if (!(invokeExpr instanceof SpecialInvokeExpr))
01231 continue;
01232 String methodInvoked = ((InvokeExpr) invokeExpr).getMethod().getName();
01233 if (!methodInvoked.equals("<init>"))
01234 continue;
01235
01236 String typeOfInvokeBase =
01237 ((SpecialInvokeExpr) invokeExpr).getBase().getType().toString();
01238
01239
01240 if (typeOfInvokeBase.equals(typeOfNewExpr))
01241
01242 {
01243 Set specDdBoxes = (Set) stmtToDdOn.get(stmtK);
01244 if (specDdBoxes.contains(ddBoxWithNewExpr))
01245 return stmtK;
01246 }
01247 }
01248 throw new NoInitStmtException("Can not find the special invoke init statement dependent on " + ddBoxWithNewExpr + " in getSpecialInvokeStmtOf of BuildPDG.java");
01249 }
01250
01251
01252
01253
01254
01255
01256
01257 private int getStaticDefIndexOf(Stmt s)
01258 {
01259 int index = -1;
01260 Object array[] = staticFieldDefStmtList.toArray();
01261 for (int i = 0; i<array.length; i++)
01262 {
01263 DataBox db = (DataBox) array[i];
01264 Stmt fieldDefStmt = db.getInterferStmt();
01265 if (fieldDefStmt.equals(s))
01266 {
01267 index = i;
01268 return index;
01269 }
01270 }
01271
01272 return index;
01273 }
01274
01275
01276
01277
01278
01279 private void immediateDominators() {
01280
01281
01282 stmtToImmedPostdom = computeImmedDom(stmtToPostdoms);
01283 }
01284
01285
01286
01287
01288
01289
01290
01291 public int immediatePostdominatorOf(int stmtIndex)
01292 {
01293 Stmt stmt = (Stmt) stmtList.get(stmtIndex);
01294 return ((Integer) stmtToImmedPostdom.get(stmt)).intValue();
01295 }
01296
01297
01298
01299
01300
01301
01302
01303 public int immediatePostdominatorOf(Stmt stmt)
01304 {
01305 return ((Integer) stmtToImmedPostdom.get(stmt)).intValue();
01306 }
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325 public static Integer indefiniteFrom(AnnotationManager cfanns, MethodInfo mdInfo) {
01326 Annotation annForSm = cfanns.getAnnotation(mdInfo.sootClass, mdInfo.sootMethod);
01327
01328
01329 Vector currentCFANNs = annForSm.getAllAnnotations(true);
01330 for (Enumeration e = currentCFANNs.elements(); e.hasMoreElements();) {
01331 Annotation cfann = (Annotation) e.nextElement();
01332 if (cfann instanceof ControlFlowAnnotation) {
01333 ControlFlowAnnotation controlCfann = (ControlFlowAnnotation) cfann;
01334 if (controlCfann.isIndefinite()) {
01335 Stmt backPointStmt = controlCfann.getBackpointStmt();
01336 Integer backIndex = new Integer(mdInfo.originalStmtList.indexOf(backPointStmt));
01337 return backIndex;
01338 }
01339 }
01340 }
01341 return IndexMaps.specialExitNode;
01342 }
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 private LinkedList initializeWorkList(AnnotationManager cfanns) {
01358 LinkedList workList = new LinkedList();
01359 BitSet postDominators = new BitSet(stmtList.size());
01360 Stmt keyStmt;
01361
01362
01363
01364
01365 if (SetUtil.emptyBitSet(exitNodesNoThrow)) {
01366 indefiniteNode = indefiniteFrom(cfanns, methodInfo);
01367 if (indefiniteNode.equals(IndexMaps.specialExitNode))
01368 throw new NoExitNodeException("Can not find out the exit node or the infinite loop in method " + methodInfo.sootMethod.getName());
01369 workList.addFirst(indefiniteNode);
01370 keyStmt = (Stmt) stmtList.get(indefiniteNode.intValue());
01371 postDominators.set(indefiniteNode.intValue());
01372 stmtToPostdoms.put(keyStmt, postDominators);
01373 } else {
01374 for (int i = 0; i < stmtList.size(); i++) {
01375 if (exitNodes.get(i)) {
01376 workList.addFirst(new Integer(i));
01377 keyStmt = (Stmt) stmtList.get(i);
01378 postDominators = new BitSet(stmtList.size());
01379 postDominators.set(i);
01380 stmtToPostdoms.put(keyStmt, postDominators);
01381 }
01382 }
01383 indefiniteNode = IndexMaps.specialExitNode;
01384 }
01385 return workList;
01386 }
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399 private Set instanceDefsNotPreserves(int instanceDefIndex) {
01400 Set defsNotPres = new ArraySet();
01401 defsNotPres.add(new Integer(instanceDefIndex));
01402 Object array[] = instanceFieldDefStmtList.toArray();
01403 DataBox instanceBox = (DataBox) array[instanceDefIndex];
01404 Set instanceDefs = instanceBox.getInterferVars();
01405 for (int i = 0; i < array.length; i++) {
01406 DataBox db = (DataBox) array[i];
01407 Set instanceDefs2 = db.getInterferVars();
01408 Set intersectDefs = SetUtil.setIntersection(instanceDefs, instanceDefs2);
01409 if (intersectDefs.size() != 0)
01410 defsNotPres.add(new Integer(i));
01411 }
01412 return defsNotPres;
01413 }
01414
01415
01416
01417
01418
01419
01420
01421
01422 public static boolean mayPointToTheSameRef(Value v1, Value v2, SootMethod enclosingMethod1, SootMethod enclosingMethod2) {
01423 Collection refValues = Slicer.BOFA_Analysis.referenceValueSet(v1, enclosingMethod1);
01424 Collection refValues2 = Slicer.BOFA_Analysis.referenceValueSet(v2, enclosingMethod2);
01425
01426 for (Iterator valueIt = refValues.iterator(); valueIt.hasNext();) {
01427 if (refValues2.contains(valueIt.next()))
01428 return true;
01429 }
01430 return false;
01431 }
01432
01433
01434
01435
01436
01437
01438
01439
01440 public static boolean mayPointToTheSameRef(Value v1, Set vs, SootMethod enclosingMethod1, SootMethod enclosingMethod2) {
01441 for (Iterator varIt = vs.iterator(); varIt.hasNext();){
01442 Value v2 = (Value) varIt.next();
01443 boolean mayPointToTheSame = BuildPDG.mayPointToTheSameRef(v1, v2, enclosingMethod1, enclosingMethod2);
01444 if (mayPointToTheSame) return true;
01445 }
01446 return false;
01447 }
01448
01449
01450
01451
01452
01453
01454 private void postDomAnalysis() {
01455 LinkedList workList = initializeWorkList(annotationManager);
01456 postdomFixPoint(workList);
01457 }
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468 private void postdomFixPoint(LinkedList workList) {
01469 boolean change = true;
01470 BitSet postDominators = new BitSet(stmtList.size());
01471 BitSet tempPostdoms = new BitSet(stmtList.size());
01472 Set visitedNode = new ArraySet();
01473
01474
01475
01476
01477 Set initialWorkList = new ArraySet();
01478 for (int i = 0; i < workList.size(); i++) {
01479 initialWorkList.add((Integer) workList.get(i));
01480 }
01481
01482
01483
01484 workList.addFirst(new Integer(0));
01485 BitSet indexSetWoE = methodInfo.indexMaps.indexSetWithoutExceptionHandling();
01486 for (int i = 0; i < indexSetWoE.size(); i++) {
01487 if (indexSetWoE.get(i))
01488 postDominators.set(i);
01489 }
01490 while (workList.size() != 0) {
01491 Integer nodeIndex = (Integer) workList.removeFirst();
01492 visitedNode.add(nodeIndex);
01493 Stmt nodeStmt = (Stmt) stmtList.get(nodeIndex.intValue());
01494 if (!initialWorkList.contains(nodeIndex))
01495 stmtToPostdoms.put(nodeStmt, postDominators);
01496 List nodeStmtSuccs = stmtGraph.getSuccsOf(nodeStmt);
01497
01498 List newSuccs = nodeStmtSuccs;
01499 for (Iterator succIt = newSuccs.iterator(); succIt.hasNext();) {
01500 Stmt succStmt = (Stmt) succIt.next();
01501 Integer succIndex = new Integer(stmtList.indexOf(succStmt));
01502 if (workList.contains(succIndex) || visitedNode.contains(succIndex)) {
01503 } else
01504 workList.addLast(succIndex);
01505 }
01506 }
01507 while (change) {
01508 change = false;
01509 workList.clear();
01510 visitedNode.clear();
01511
01512
01513 for (Iterator i = initialWorkList.iterator(); i.hasNext();) {
01514 workList.addFirst((Integer) i.next());
01515 }
01516 while (workList.size() != 0) {
01517 Integer stmtIndex = (Integer) workList.removeFirst();
01518 visitedNode.add(stmtIndex);
01519 Stmt keyStmt = (Stmt) stmtList.get(stmtIndex.intValue());
01520 postDominators = (BitSet) stmtToPostdoms.get(keyStmt);
01521 if (postDominators == null)
01522 continue;
01523 tempPostdoms = (BitSet) postDominators.clone();
01524 List realSuccs = stmtGraph.getSuccsOf(keyStmt);
01525 List succs = removeExceptionCaught(realSuccs);
01526 for (int i = 0; i < succs.size(); i++) {
01527 Stmt succStmt = (Stmt) succs.get(i);
01528 BitSet succDom = (BitSet) stmtToPostdoms.get(succStmt);
01529 tempPostdoms.and(succDom);
01530 }
01531 tempPostdoms.set(stmtIndex.intValue());
01532 if (!tempPostdoms.equals(postDominators)) {
01533 change = true;
01534 stmtToPostdoms.remove(keyStmt);
01535 stmtToPostdoms.put(keyStmt, tempPostdoms);
01536 }
01537
01538
01539
01540
01541 List preds = stmtGraph.getPredsOf(keyStmt);
01542 for (int i = 0; i < preds.size(); i++) {
01543 Stmt predStmt = (Stmt) preds.get(i);
01544 Integer predIndex = new Integer(stmtList.indexOf(predStmt));
01545 if (workList.contains(predIndex) || visitedNode.contains(predIndex)) {
01546 } else
01547 workList.addLast(predIndex);
01548 }
01549 }
01550 }
01551 }
01552
01553
01554
01555
01556
01557
01558
01559
01560 BitSet postdominatorsOf(int index) {
01561 Stmt stmt = (Stmt) stmtList.get(index);
01562 return (BitSet) stmtToPostdoms.get(stmt);
01563 }
01564
01565
01566
01567
01568
01569
01570
01571 public BitSet postdominatorsOf(Stmt stmt) {
01572 return (BitSet) stmtToPostdoms.get(stmt);
01573 }
01574
01575
01576
01577
01578
01579
01580
01581
01582 public BitSet postdominatorsOf(Integer stmtIndex)
01583 {
01584 Stmt stmt = (Stmt) stmtList.get(stmtIndex.intValue());
01585 return (BitSet) stmtToPostdoms.get(stmt);
01586 }
01587
01588
01589
01590
01591
01592
01593 public BitSet preDivergencePointsOf(Stmt stmt) {
01594 int indexOfStmt = stmtList.indexOf(stmt);
01595 BitSet preDivergencePoints = new BitSet(stmtList.size());
01596 for (Iterator keyIt = divergenceMap.keySet().iterator(); keyIt.hasNext();) {
01597 Stmt divergPoint = (Stmt) keyIt.next();
01598 BitSet reachableStmts = (BitSet) divergenceMap.get(divergPoint);
01599 if (reachableStmts.get(indexOfStmt)) {
01600 int indexOfDivergPoint = stmtList.indexOf(divergPoint);
01601 preDivergencePoints.set(indexOfDivergPoint);
01602 }
01603 }
01604 return preDivergencePoints;
01605 }
01606
01607
01608
01609
01610
01611 private void prepareToBuild(MethodInfo mdInfo) {
01612 methodInfo = mdInfo;
01613 jimpleBody = (JimpleBody) mdInfo.sootMethod.getBody(Jimple.v());
01614 stmtList = mdInfo.originalStmtList;
01615 stmtToPostdoms = new HashMap(stmtList.size() * 2 + 1, 0.7f);
01616 stmtGraph = mdInfo.indexMaps.getStmtGraph();
01617 IndexMaps im = mdInfo.indexMaps;
01618 exitNodes = im.exitNodes();
01619
01620 exitNodesNoThrow = im.exitNodesWithoutThrow(exitNodes);
01621
01622 callSiteMap = im.getCallSiteMap();
01623 collectInstanceFieldDefStmt();
01624 staticFieldDefStmtList = mdInfo.MOD.staticFields;
01625 }
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638 private void reachingDefOfInstanceField() {
01639
01640
01641
01642
01643 boolean change = true;
01644 int instanceFieldDefSize = instanceFieldDefStmtList.size();
01645 int stmtListSize = stmtList.size();
01646 BitSet reachIn[] = new BitSet[stmtListSize];
01647 BitSet preserve[] = new BitSet[stmtListSize];
01648 BitSet generate[] = new BitSet[stmtListSize];
01649
01650
01651
01652
01653
01654 for (int i = 0; i < stmtListSize; i++) {
01655
01656
01657
01658 reachIn[i] = new BitSet(instanceFieldDefSize);
01659 preserve[i] = new BitSet(instanceFieldDefSize);
01660 generate[i] = new BitSet(instanceFieldDefSize);
01661
01662
01663
01664 for (int j = 0; j < instanceFieldDefSize; j++) {
01665 reachIn[i].clear(j);
01666 preserve[i].set(j);
01667 generate[i].clear(j);
01668 }
01669 }
01670
01671
01672 for (int i = 0; i < stmtListSize; i++) {
01673 Stmt stmt = (Stmt) stmtList.get(i);
01674 int stmtInInstanceDef = getInstanceDefIndexOf(stmt);
01675 if (stmtInInstanceDef >= 0) {
01676
01677 generate[i].set(stmtInInstanceDef);
01678
01679
01680
01681
01682 Set defSet = instanceDefsNotPreserves(stmtInInstanceDef);
01683
01684
01685
01686 for (Iterator k = defSet.iterator(); k.hasNext();) {
01687 int defNotPreserve = ((Integer) k.next()).intValue();
01688 preserve[i].clear(defNotPreserve);
01689 }
01690
01691 }
01692 }
01693 while (change) {
01694 change = false;
01695 for (int i = 0; i < stmtListSize; i++) {
01696 Stmt stmt = (Stmt) stmtList.get(i);
01697
01698
01699 BitSet newReachIn = null;
01700 List preds = stmtGraph.getPredsOf(stmt);
01701 for (int ppp = 0; ppp < preds.size(); ppp++) {
01702 int j=stmtList.indexOf(preds.get(ppp));
01703
01704
01705 BitSet tempReachIn = (BitSet) reachIn[j].clone();
01706 tempReachIn.and(preserve[j]);
01707 tempReachIn.or(generate[j]);
01708 if (ppp == 0)
01709 newReachIn = (BitSet) tempReachIn.clone();
01710 else
01711 newReachIn.or(tempReachIn);
01712 }
01713 if (newReachIn != null)
01714
01715
01716
01717
01718 if (!reachIn[i].equals(newReachIn)) {
01719 reachIn[i] = newReachIn;
01720 change = true;
01721 }
01722 }
01723 }
01724 instanceReachDef = reachIn;
01725 }
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741 private void reachingDefOfStaticField() {
01742 boolean change = true;
01743 int staticFieldDefSize = staticFieldDefStmtList.size();
01744 int stmtListSize = stmtList.size();
01745 BitSet reachIn[] = new BitSet[stmtListSize];
01746 BitSet preserve[] = new BitSet[stmtListSize];
01747 BitSet generate[] = new BitSet[stmtListSize];
01748
01749
01750
01751
01752
01753 for (int i = 0; i < stmtListSize; i++) {
01754
01755
01756
01757 reachIn[i] = new BitSet(staticFieldDefSize);
01758 preserve[i] = new BitSet(staticFieldDefSize);
01759 generate[i] = new BitSet(staticFieldDefSize);
01760
01761
01762
01763 for (int j = 0; j < staticFieldDefSize; j++) {
01764 reachIn[i].clear(j);
01765 preserve[i].set(j);
01766 generate[i].clear(j);
01767 }
01768 }
01769
01770
01771
01772 for (int i = 0; i < stmtListSize; i++) {
01773 Stmt stmt = (Stmt) stmtList.get(i);
01774 int stmtInStaticDef = getStaticDefIndexOf(stmt);
01775 if (stmtInStaticDef >= 0) {
01776
01777 generate[i].set(stmtInStaticDef);
01778
01779
01780
01781 Set defSet = defsNotPreserves(stmtInStaticDef);
01782
01783
01784
01785 for (Iterator k = defSet.iterator(); k.hasNext();) {
01786 int defNotPreserve = ((Integer) k.next()).intValue();
01787 preserve[i].clear(defNotPreserve);
01788 }
01789 }
01790 }
01791 while (change) {
01792 change = false;
01793 for (int i = 0; i < stmtListSize; i++) {
01794 Stmt stmt = (Stmt) stmtList.get(i);
01795
01796
01797 BitSet newReachIn = null;
01798 List preds = stmtGraph.getPredsOf(stmt);
01799 for (int ppp = 0; ppp < preds.size(); ppp++) {
01800 Stmt predStmt = (Stmt)preds.get(ppp);
01801 int j= stmtList.indexOf(predStmt);
01802
01803
01804 BitSet tempReachIn = (BitSet) reachIn[j].clone();
01805 tempReachIn.and(preserve[j]);
01806 tempReachIn.or(generate[j]);
01807 if (ppp == 0)
01808 newReachIn = (BitSet) tempReachIn.clone();
01809 else
01810 newReachIn.or(tempReachIn);
01811 }
01812 if (newReachIn != null)
01813
01814
01815 if (!reachIn[i].equals(newReachIn)) {
01816 reachIn[i] = newReachIn;
01817 change = true;
01818 }
01819 }
01820 }
01821 staticReachDef = reachIn;
01822 }
01823
01824
01825
01826
01827
01828
01829
01830 private List removeExceptionCaught(List actualSuccs) {
01831 List newSuccs = new ArrayList();
01832 Set trapHandlerStmtSet = getHandlerStmtSet();
01833 for (Iterator asuccsIt = actualSuccs.iterator(); asuccsIt.hasNext();) {
01834 Stmt succStmt = (Stmt) asuccsIt.next();
01835 if (!trapHandlerStmtSet.contains(succStmt))
01836 newSuccs.add(succStmt);
01837 }
01838 return newSuccs;
01839 }
01840
01841
01842
01843
01844
01845 public void setInterferenceMap(Map iterMap)
01846 {
01847 interferenceMap = iterMap;
01848 }
01849
01850
01851
01852
01853
01854 public void setLockAnalysis(LockAnalysis la)
01855 {
01856 lockAnalysis = la;
01857 }
01858
01859
01860
01861
01862
01863 public void setReadyDependMap(Map rm)
01864 {
01865 readyDependMap = rm;
01866 }
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891 private void specialInvokeDdAnalysis() {
01892 for (Iterator keyIt = stmtToDdOn.keySet().iterator(); keyIt.hasNext();) {
01893 Stmt keyStmt = (Stmt) keyIt.next();
01894 Set ddBoxesInMap = (Set) stmtToDdOn.get(keyStmt);
01895 Set ddBoxes = new ArraySet();
01896 ddBoxes.addAll(ddBoxesInMap);
01897 for (Iterator i = ddBoxes.iterator(); i.hasNext();) {
01898 DataBox ddBox = (DataBox) i.next();
01899 Stmt ddOnStmt = (Stmt) ddBox.getStmt();
01900 if (ddOnStmt instanceof DefinitionStmt) {
01901 DefinitionStmt defStmt = (DefinitionStmt) ddOnStmt;
01902 Value rightOp = defStmt.getRightOp();
01903 if (rightOp instanceof NewExpr) {
01904 NewExpr newExpr = (NewExpr) rightOp;
01905 String className = newExpr.getType().toString();
01906 SootClass newExprType = IndexMaps.lookupSootClassByName(className);
01907 Stmt specInvoke = null;
01908 if (newExprType == null)
01909 specInvoke = getSpecialInvokeStmtOf(ddBox, className);
01910
01911
01912
01913 else
01914 specInvoke = getSpecialInvokeStmtOf(ddBox, newExprType);
01915 if (specInvoke.equals(keyStmt)) {
01916 } else {
01917 DataBox specInvokeDataBox = new DataBox(specInvoke, ddBox.getDependVar());
01918
01919
01920
01921
01922
01923 specInvokeDataBox.setToInvokeInit();
01924 ddBoxesInMap.add(specInvokeDataBox);
01925 ddBoxesInMap.remove(ddBox);
01926 ddBox.setToNewExprStmt();
01927 ddBoxesInMap.add(ddBox);
01928 }
01929 }
01930 } else {
01931 }
01932 }
01933 }
01934 }
01935
01936
01937
01938
01939
01940
01941 public BitSet succDivergencePointsOf(Stmt stmt) {
01942 if (divergenceMap.containsKey(stmt))
01943 return (BitSet) divergenceMap.get(stmt);
01944 else
01945 return null;
01946 }
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964 public String toString()
01965 {
01966 String pdg = "Stmt to Postdomimators: " + stmtToPostdoms + "\n\n";
01967 pdg += "Stmt to Control Depend nodes: " + stmtToCdOn + "\n\n";
01968 pdg += "Stmt to Data Depend nodes: " + stmtToDdOn + "\n";
01969 return pdg;
01970 }
01971 }