1 20 21 package soot.dava.toolkits.base.finders; 22 23 import soot.*; 24 import soot.dava.*; 25 import soot.util.*; 26 import java.util.*; 27 import soot.jimple.*; 28 import soot.toolkits.graph.*; 29 import soot.dava.internal.asg.*; 30 import soot.dava.internal.SET.*; 31 import soot.dava.internal.AST.*; 32 33 public class SynchronizedBlockFinder implements FactFinder 34 { 35 public SynchronizedBlockFinder( Singletons.Global g ) {} 36 public static SynchronizedBlockFinder v() { return G.v().soot_dava_toolkits_base_finders_SynchronizedBlockFinder(); } 37 38 private HashMap as2ml; 39 private DavaBody davaBody; 40 41 46 private IterableSet monitorLocalSet, monitorEnterSet; 47 48 private Integer WHITE = new Integer (0); private Integer GRAY = new Integer (1); private Integer BLACK = new Integer (2); 52 private int UNKNOWN = -100000; private Integer VARIABLE_INCR = new Integer (UNKNOWN); 54 55 private String THROWABLE = "java.lang.Throwable"; 56 57 58 public void find( DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException 59 { 60 davaBody=body; 61 Dava.v().log( "SynchronizedBlockFinder::find()"); 62 63 as2ml = new HashMap(); 64 65 IterableSet synchronizedBlockFacts = body.get_SynchronizedBlockFacts(); 66 synchronizedBlockFacts.clear(); 67 68 set_MonitorLevels( asg); 69 70 Map as2synchSet = build_SynchSets(); 71 72 IterableSet usedMonitors = new IterableSet(); 73 74 AugmentedStmt previousStmt = null; 75 76 Iterator asgit = asg.iterator(); 77 while (asgit.hasNext()) { 78 80 AugmentedStmt as = (AugmentedStmt) asgit.next(); 81 if (as.get_Stmt() instanceof EnterMonitorStmt) { 82 84 IterableSet synchSet = (IterableSet) as2synchSet.get( as); 85 if (synchSet != null) { 86 IterableSet synchBody = get_BodyApproximation( as, synchSet); 87 Value local = ((EnterMonitorStmt) as.get_Stmt()).getOp(); 88 Value copiedLocal=null; 89 90 99 if(previousStmt != null){ 100 Stmt previousS = previousStmt.get_Stmt(); 101 if(previousS instanceof DefinitionStmt){ 102 DefinitionStmt previousDef = (DefinitionStmt)previousS; 103 Value rightPrevious = previousDef.getRightOp(); 104 if(rightPrevious.toString().compareTo(local.toString())==0){ 105 copiedLocal = previousDef.getLeftOp(); 106 } 107 } 108 } 109 110 111 Integer level = (Integer ) ((HashMap) as2ml.get( as)).get( local); 112 Iterator enit = body.get_ExceptionFacts().iterator(); 113 114 boolean done=false; 116 IterableSet origSynchBody=synchBody; 117 while (enit.hasNext()) { 118 ExceptionNode en = (ExceptionNode) enit.next(); 119 synchBody=(IterableSet)origSynchBody.clone(); 120 122 if (verify_CatchBody( en, synchBody, local,copiedLocal)) { 123 if (SET.nest( new SETSynchronizedBlockNode( en, local))) { 124 done=true; 125 Iterator ssit = synchSet.iterator(); 127 while (ssit.hasNext()) { 128 AugmentedStmt ssas = (AugmentedStmt) ssit.next(); 129 Stmt sss = ssas.get_Stmt(); 130 131 138 if (sss instanceof MonitorStmt){ 139 if( (((MonitorStmt) sss).getOp() == local) && 140 (((Integer ) ((HashMap) as2ml.get( ssas)).get( local)).equals( level)) && 141 (usedMonitors.contains( ssas) == false) ){ 142 143 usedMonitors.add( ssas); 144 } 145 else{ 146 if( (((MonitorStmt) sss).getOp() == copiedLocal) && 147 (usedMonitors.contains( ssas) == false) ){ 148 usedMonitors.add( ssas); 150 } 151 } 152 } 153 } 154 synchronizedBlockFacts.add( en); 155 } 156 break; 157 } 158 else{ 159 } 161 } 162 if(!done) 163 throw new RuntimeException ("Could not verify approximated Synchronized body"); 164 } } previousStmt=as; 167 } 169 IterableSet monitorFacts = body.get_MonitorFacts(); 170 monitorFacts.clear(); 171 172 asgit = asg.iterator(); 173 while (asgit.hasNext()) { 174 AugmentedStmt as = (AugmentedStmt) asgit.next(); 175 176 if ((as.get_Stmt() instanceof MonitorStmt) && (usedMonitors.contains( as) == false)){ 177 monitorFacts.add( as); 178 } 179 } 180 } 181 182 183 184 185 186 187 191 192 private void find_VariableIncreasing( AugmentedStmtGraph asg, HashMap local2level_template, 193 LinkedList viAugStmts, HashMap as2locals) { 194 StronglyConnectedComponents scc = new StronglyConnectedComponents(asg); 195 IterableSet viSeeds = new IterableSet(); 196 HashMap 197 as2color = new HashMap(), 198 as2rml = new HashMap(); 199 200 Iterator asgit = asg.iterator(); 202 while (asgit.hasNext()){ 203 as2rml.put( asgit.next(), local2level_template.clone()); 204 } 205 206 207 Iterator sccit = scc.getComponents().iterator(); 209 while (sccit.hasNext()) { 210 List componentList = (List) sccit.next(); 212 213 if (componentList.size() < 2) 215 continue; 216 217 IterableSet component = new IterableSet(); 219 component.addAll( componentList); 220 221 Iterator cit = component.iterator(); 223 while (cit.hasNext()){ 224 as2color.put( cit.next(), WHITE); 225 } 226 227 AugmentedStmt seedStmt = (AugmentedStmt) component.getFirst(); 229 231 232 DFS_Scc( seedStmt, component, as2rml, as2color, seedStmt, viSeeds); 233 } 236 237 238 239 IterableSet worklist = new IterableSet(); 241 worklist.addAll( viSeeds); 242 243 while (worklist.isEmpty() == false) { 245 AugmentedStmt as = (AugmentedStmt) worklist.getFirst(); 246 worklist.removeFirst(); 247 HashMap local2level = (HashMap) as2rml.get( as); 248 249 Iterator sit = as.csuccs.iterator(); 251 while (sit.hasNext()) { 252 AugmentedStmt sas = (AugmentedStmt) sit.next(); 253 HashMap slocal2level = (HashMap) as2rml.get( sas); 254 255 Iterator mlsit = monitorLocalSet.iterator(); 256 while (mlsit.hasNext()) { 257 Value local = (Value) mlsit.next(); 258 259 if ((local2level.get( local) == VARIABLE_INCR) && (slocal2level.get( local) != VARIABLE_INCR)) { 262 slocal2level.put( local, VARIABLE_INCR); 263 264 if (worklist.contains( sas) == false) 265 worklist.addLast( sas); 266 } 267 } 268 } 269 } 270 275 276 asgit = asg.iterator(); 278 while (asgit.hasNext()) { 279 AugmentedStmt as = (AugmentedStmt) asgit.next(); 280 HashMap local2level = (HashMap) as2rml.get( as); 281 282 Iterator mlsit = monitorLocalSet.iterator(); 283 while (mlsit.hasNext()) { 284 Value local = (Value) mlsit.next(); 286 287 if (local2level.get( local) == VARIABLE_INCR) { 288 289 294 if (!viAugStmts.isEmpty()){ 295 if (viAugStmts.getLast() != as) 296 viAugStmts.addLast( as); 297 } 298 else{ 299 viAugStmts.addLast(as); 301 } 302 303 LinkedList locals = null; 304 305 if ((locals = (LinkedList) as2locals.get( as)) == null) { 306 locals = new LinkedList(); 307 as2locals.put( as, locals); 308 } 309 310 locals.addLast( local); 311 } 312 } 313 } 314 } 315 316 317 318 319 320 336 private void DFS_Scc( AugmentedStmt as, IterableSet component, HashMap as2rml, 337 HashMap as2color, AugmentedStmt seedStmt, IterableSet viSeeds){ 338 as2color.put( as, GRAY); 339 340 Stmt s = as.get_Stmt(); 341 HashMap local2level = (HashMap) as2rml.get( as); 343 344 if (s instanceof MonitorStmt ) { 345 Value local = ((MonitorStmt) s).getOp(); 346 347 if (s instanceof EnterMonitorStmt){ local2level.put( local, new Integer ( ((Integer ) local2level.get( local)).intValue() + 1)); 349 } 350 else{ local2level.put( local, new Integer ( ((Integer ) local2level.get( local)).intValue() - 1)); 352 } 353 } 354 355 Iterator sit = as.csuccs.iterator(); 357 while (sit.hasNext()) { 359 AugmentedStmt sas = (AugmentedStmt) sit.next(); 360 361 if (component.contains( sas) == false) 362 continue; 363 364 HashMap slocal2level = (HashMap) as2rml.get( sas); 366 Integer scolor = (Integer ) as2color.get( sas); 368 369 if (scolor.equals( WHITE)) { 370 Iterator mlsit = monitorLocalSet.iterator(); 372 while (mlsit.hasNext()) { 373 Value local = (Value) mlsit.next(); 375 380 slocal2level.put( local, local2level.get( local)); 381 } 382 383 DFS_Scc( sas, component, as2rml, as2color, seedStmt, viSeeds); 385 } 386 387 else { 388 Iterator mlsit = monitorLocalSet.iterator(); 390 while (mlsit.hasNext()) { 391 Value local = (Value) mlsit.next(); 392 393 if (((Integer ) slocal2level.get( local)).intValue() < ((Integer ) local2level.get( local)).intValue()) { 394 slocal2level.put( local, VARIABLE_INCR); 397 398 if (viSeeds.contains( sas) == false) 400 viSeeds.add( sas); 401 } 402 } 403 } 404 } 405 406 as2color.put( as, BLACK); 408 } 409 410 411 412 413 418 private Map build_SynchSets(){ 419 HashMap as2synchSet = new HashMap(); 420 421 Iterator mesit = monitorEnterSet.iterator(); 422 monitorEnterLoop: 423 while (mesit.hasNext()) { 424 AugmentedStmt headAs = (AugmentedStmt) mesit.next(); 426 Value local = ((EnterMonitorStmt) headAs.get_Stmt()).getOp(); 427 IterableSet synchSet = new IterableSet(); 428 429 int monitorLevel = ((Integer ) ((HashMap) as2ml.get( headAs)).get( local)).intValue(); 431 IterableSet worklist = new IterableSet(); 432 worklist.add( headAs); 433 434 while (worklist.isEmpty() == false) { 435 AugmentedStmt as = (AugmentedStmt) worklist.getFirst(); 436 worklist.removeFirst(); 437 438 Stmt s = as.get_Stmt(); 439 if ((s instanceof DefinitionStmt) && (((DefinitionStmt) s).getLeftOp() == local)) 440 continue monitorEnterLoop; 441 442 synchSet.add( as); 443 444 Iterator sit = as.csuccs.iterator(); 445 while (sit.hasNext()) { 446 AugmentedStmt sas = (AugmentedStmt) sit.next(); 447 int sml = ((Integer ) ((HashMap) as2ml.get( sas)).get( local)).intValue(); 449 450 453 if (sas.get_Dominators().contains( headAs) && (sml >= monitorLevel) && 454 (worklist.contains( sas) == false) && (synchSet.contains( sas) == false)) 455 456 worklist.addLast( sas); 457 } 458 } 459 460 as2synchSet.put( headAs, synchSet); 461 } 462 return as2synchSet; 463 } 464 465 466 467 468 469 470 471 477 private void set_MonitorLevels( AugmentedStmtGraph asg){ 478 monitorLocalSet = new IterableSet(); 479 monitorEnterSet = new IterableSet(); 480 481 Iterator asgit = asg.iterator(); 483 while (asgit.hasNext()) { 484 AugmentedStmt as = (AugmentedStmt) asgit.next(); 485 Stmt s = as.get_Stmt(); 486 487 if (s instanceof MonitorStmt) { 488 Value local = ((MonitorStmt) s).getOp(); 489 490 if (monitorLocalSet.contains( local) == false) 492 monitorLocalSet.add( local); 493 494 if (s instanceof EnterMonitorStmt) 496 monitorEnterSet.add( as); 497 } 498 } 499 500 HashMap local2level_template = new HashMap(); 502 Iterator mlsit = monitorLocalSet.iterator(); 503 while (mlsit.hasNext()) { 504 local2level_template.put( mlsit.next(), new Integer ( 0)); 506 } 507 508 asgit = asg.iterator(); 510 while (asgit.hasNext()){ 511 as2ml.put( asgit.next(), local2level_template.clone()); 513 } 514 515 516 LinkedList viAugStmts = new LinkedList(); 517 HashMap incrAs2locals = new HashMap(); 518 519 find_VariableIncreasing( asg, local2level_template, viAugStmts, incrAs2locals); 521 525 526 527 528 Iterator viasit = viAugStmts.iterator(); 530 while (viasit.hasNext()) { 531 AugmentedStmt vias = (AugmentedStmt) viasit.next(); 532 HashMap local2level = (HashMap) as2ml.get( vias); 533 534 Iterator lit = ((LinkedList) incrAs2locals.get( vias)).iterator(); 536 while (lit.hasNext()){ 537 local2level.put( lit.next(), VARIABLE_INCR); 539 } 540 } 541 542 IterableSet worklist = new IterableSet(); 543 worklist.addAll( monitorEnterSet); 544 545 while (worklist.isEmpty() == false) { 547 AugmentedStmt as = (AugmentedStmt) worklist.getFirst(); 549 worklist.removeFirst(); 550 551 HashMap cur_local2level = (HashMap) as2ml.get( as); 552 553 Iterator pit = as.cpreds.iterator(); 554 while (pit.hasNext()) { 555 AugmentedStmt pas = (AugmentedStmt) pit.next(); 557 Stmt s = as.get_Stmt(); 558 559 HashMap pred_local2level = (HashMap) as2ml.get( pas); 560 561 mlsit = monitorLocalSet.iterator(); 562 while (mlsit.hasNext()) { 563 Value local = (Value) mlsit.next(); 564 565 int predLevel = ((Integer ) pred_local2level.get( local)).intValue(); 566 Stmt ps = pas.get_Stmt(); 567 568 if (predLevel == UNKNOWN) continue; 570 571 if (ps instanceof ExitMonitorStmt) { 572 573 ExitMonitorStmt ems = (ExitMonitorStmt) ps; 574 578 if ((ems.getOp() == local) && (predLevel > 0)) 579 predLevel--; 580 } 581 582 if (s instanceof EnterMonitorStmt) { 583 EnterMonitorStmt ems = (EnterMonitorStmt) s; 584 589 if ((ems.getOp() == local) && (predLevel >= 0)) 590 predLevel++; 591 } 592 593 int curLevel = ((Integer ) cur_local2level.get( local)).intValue(); 594 595 599 if (predLevel > curLevel) { 600 cur_local2level.put( local, new Integer ( predLevel)); 601 602 Iterator sit = as.csuccs.iterator(); 603 while (sit.hasNext()) { 604 Object so = sit.next(); 605 606 if (worklist.contains( so) == false) 607 worklist.add( so); 608 } 609 } 610 } 611 } 612 } 613 } 614 615 616 617 621 private void removeOtherDominatedStmts(IterableSet synchBody, AugmentedStmt sas){ 622 ArrayList toRemove = new ArrayList(); 623 624 Iterator it = synchBody.iterator(); 625 while(it.hasNext()){ 626 AugmentedStmt as = (AugmentedStmt)it.next(); 627 IterableSet doms = as.get_Dominators(); 628 if(doms.contains(sas)){ 629 toRemove.add(as); 631 } 632 } 633 634 it = toRemove.iterator(); 635 while(it.hasNext()){ 636 AugmentedStmt as = (AugmentedStmt)it.next(); 637 synchBody.remove(as); 639 } 640 } 641 642 643 644 645 private boolean verify_CatchBody( ExceptionNode en, IterableSet synchBody, Value monitorVariable,Value copiedLocal) 646 { 647 { 649 654 655 IterableSet tryBodySet = en.get_TryBody(); 656 Iterator tempIt = tryBodySet.iterator(); 657 AugmentedStmt tempas=null; 658 659 outer: 661 while(tempIt.hasNext()){ 662 tempas = (AugmentedStmt)tempIt.next(); 663 664 665 Iterator succIt = tempas.bsuccs.iterator(); 667 while(succIt.hasNext()){ 668 AugmentedStmt succAS = (AugmentedStmt)succIt.next(); 669 if(!tryBodySet.contains(succAS)){ 670 break outer; 672 } 673 } 674 } 676 677 678 if(tempas!=null){ 680 Stmt temps = tempas.get_Stmt(); 681 683 Iterator sit = tempas.bsuccs.iterator(); 685 while (sit.hasNext()) { 686 AugmentedStmt sas = (AugmentedStmt) sit.next(); 687 689 692 synchBody.remove(sas); 693 removeOtherDominatedStmts(synchBody,sas); 696 } 697 } 698 } 699 700 701 708 { 709 Iterator tempIt = en.get_TryBody().iterator(); 710 while(tempIt.hasNext()){ 711 AugmentedStmt as = (AugmentedStmt)tempIt.next(); 712 if(as.get_Stmt() instanceof ExitMonitorStmt){ 713 List csuccs = as.csuccs; 715 716 csuccs.remove(as.bsuccs); 718 721 Iterator succIt = csuccs.iterator(); 722 while(succIt.hasNext()){ 723 AugmentedStmt as1 = (AugmentedStmt)succIt.next(); 724 if(as1.get_Stmt() instanceof GotoStmt){ 725 Unit target=((soot.jimple.internal.JGotoStmt)as1.get_Stmt()).getTarget(); 726 if(target instanceof DefinitionStmt){ 727 DefinitionStmt defStmt = (DefinitionStmt)target; 728 729 733 734 Value asnFrom = defStmt.getRightOp(); 735 736 if (! (asnFrom instanceof CaughtExceptionRef)){ 738 synchBody.remove(as1); 740 removeOtherDominatedStmts(synchBody,as1); 742 } 743 else{ 744 Value leftOp = defStmt.getLeftOp(); 745 747 750 HashSet params = new HashSet(); 751 params.addAll(davaBody.get_CaughtRefs()); 752 753 Iterator localIt = davaBody.getLocals().iterator(); 754 String typeName=""; 755 while (localIt.hasNext()) { 756 Local local = (Local) localIt.next(); 757 if(local.toString().compareTo(leftOp.toString())==0){ 758 Type t = local.getType(); 759 760 typeName = t.toString(); 761 break; 762 } 763 } 764 765 if(!( typeName.compareTo(THROWABLE)==0) ){ 766 synchBody.remove(as1); 768 removeOtherDominatedStmts(synchBody,as1); 770 } 771 else{ 772 } 775 } 776 } 777 else{ 778 synchBody.remove(as1); 781 synchBody.remove(as1.bsuccs.get(0)); 783 removeOtherDominatedStmts(synchBody,as1); 785 } 786 } 787 } 788 } 789 } 790 } 791 792 799 800 805 AugmentedStmt synchEnter=null; 806 Iterator synchIt = synchBody.iterator(); 807 808 outerLoop: 809 while (synchIt.hasNext()) { 810 AugmentedStmt as = (AugmentedStmt) synchIt.next(); 811 812 Iterator pit = as.cpreds.iterator(); 813 while (pit.hasNext()) { 814 AugmentedStmt pas = (AugmentedStmt) pit.next(); 815 816 if (synchBody.contains( pas) == false) { 817 Stmt pasStmt = pas.get_Stmt(); 819 if(pasStmt instanceof EnterMonitorStmt){ 820 synchEnter = as; 822 break outerLoop; 823 } 824 } 825 } 826 } 827 828 if(synchEnter==null){ 829 throw new RuntimeException ("Could not find enter stmt of the synchBody"); 830 } 831 832 834 835 836 840 841 boolean unChanged=false; 842 while(!unChanged){ 843 unChanged=true; 844 List toRemove = new ArrayList(); 845 synchIt = synchBody.iterator(); 846 while(synchIt.hasNext()){ 847 AugmentedStmt synchAs = (AugmentedStmt)synchIt.next(); 848 if(synchAs == synchEnter){ 849 continue; 851 } 852 Iterator pit = synchAs.cpreds.iterator(); 853 boolean remove = true; 854 while (pit.hasNext()) { 855 AugmentedStmt pAs = (AugmentedStmt)pit.next(); 856 if(synchBody.contains(pAs)){ 857 remove=false; 859 } 860 } if(remove){ 862 toRemove.add(synchAs); 864 } 865 } if(toRemove.size() >0){ 867 synchBody.removeAll(toRemove); 869 unChanged=false; 871 } 872 } 873 874 875 876 877 878 879 if ((en.get_Body().equals( synchBody) == false)){ 881 return false; 885 } 886 887 888 894 if ((en.get_Exception().getName().equals( THROWABLE) == false) || (en.get_CatchList().size() > 1)){ 895 return false; 897 } 898 899 900 902 907 IterableSet catchBody = en.get_CatchBody(); 908 AugmentedStmt entryPoint = null; 909 910 Iterator it = catchBody.iterator(); 911 catchBodyLoop: 912 while (it.hasNext()) { 913 AugmentedStmt as = (AugmentedStmt) it.next(); 914 915 Iterator pit = as.cpreds.iterator(); 916 while (pit.hasNext()) { 917 AugmentedStmt pas = (AugmentedStmt) pit.next(); 918 919 if (catchBody.contains( pas) == false) { 920 entryPoint = as; 921 break catchBodyLoop; 922 } 923 } 924 } 925 926 927 928 929 931 938 939 940 Unit entryPointTarget = null; 941 if(entryPoint.get_Stmt() instanceof GotoStmt){ 942 entryPointTarget=((soot.jimple.internal.JGotoStmt)entryPoint.get_Stmt()).getTarget(); 944 } 945 946 947 948 AugmentedStmt as = entryPoint; 949 if (as.bsuccs.size() != 1){ 950 return false; 952 } 953 954 while (as.get_Stmt() instanceof GotoStmt) { 955 as = (AugmentedStmt) as.bsuccs.get(0); 956 if (as.bsuccs.size() != 1){ 960 return false; 962 } 963 if(entryPointTarget != null){ 964 if ((as.get_Stmt() != entryPointTarget) && (as.cpreds.size() != 1)){ 965 if(as.cpreds.size() != 1) { 966 return false; 968 } 969 } 970 } 971 else{ 972 if ((as != entryPoint) && (as.cpreds.size() != 1)) { 973 return false; 975 } 976 } 977 } 978 979 980 984 Stmt s = as.get_Stmt(); 985 986 if (!(s instanceof DefinitionStmt)){ 987 return false; 989 } 990 991 992 DefinitionStmt ds = (DefinitionStmt) s; 993 Value asnFrom = ds.getRightOp(); 994 995 if (! ( (asnFrom instanceof CaughtExceptionRef) && 997 (((RefType) ((CaughtExceptionRef) asnFrom).getType()).getSootClass().getName().equals( THROWABLE)) ) ){ 998 return false; 1000 } 1001 1002 1003 1004 1005 1006 Value throwlocal = ds.getLeftOp(); 1007 1009 1012 IterableSet esuccs = new IterableSet(); 1013 esuccs.addAll( as.csuccs); 1014 esuccs.removeAll( as.bsuccs); 1015 1016 1017 1018 1019 as = (AugmentedStmt) as.bsuccs.get(0); 1021 s = as.get_Stmt(); 1022 1023 1024 if(s instanceof DefinitionStmt && 1026 ( ((DefinitionStmt)s).getRightOp().toString().compareTo(throwlocal.toString()) ==0)) { 1027 1028 throwlocal = ((DefinitionStmt)s).getLeftOp(); 1032 1033 as = (AugmentedStmt) as.bsuccs.get(0); 1035 } 1036 1037 1038 1039 if (as.bsuccs.size() != 1){ 1040 return false; 1043 } 1044 1045 1046 if (as.cpreds.size() != 1){ 1047 return false; 1050 } 1051 1052 checkProtectionArea(as,ds); 1054 1055 1056 1057 s = as.get_Stmt(); 1058 if (!(s instanceof ExitMonitorStmt)){ 1059 return false; 1061 } 1062 1063 1064 if ( (((ExitMonitorStmt) s).getOp() != monitorVariable)){ 1065 1066 if( ( ((ExitMonitorStmt) s).getOp() != copiedLocal)){ 1067 return false; 1069 } 1070 } 1071 1072 1073 1074 as = (AugmentedStmt) as.bsuccs.get(0); 1076 if ((as.bsuccs.size() != 0) || (as.cpreds.size() != 1) || (verify_ESuccs( as, esuccs) == false)){ 1077 return false; 1079 } 1080 1081 1082 1083 s = as.get_Stmt(); 1084 1085 if ( ! ( (s instanceof ThrowStmt) && (((ThrowStmt) s).getOp() == throwlocal) ) ){ 1086 return false; 1088 } 1089 1090 return true; 1091 } 1092 1093 1094 1095 1096 1097 1098 1099 1100 1104 private boolean checkProtectionArea( AugmentedStmt as, DefinitionStmt s) 1105 { 1106 IterableSet esuccs = new IterableSet(); 1107 esuccs.addAll( as.csuccs); 1108 esuccs.removeAll( as.bsuccs); 1109 1110 1113 Iterator it = esuccs.iterator(); 1114 while(it.hasNext()){ 1115 AugmentedStmt tempas = (AugmentedStmt)it.next(); 1117 Stmt temps = tempas.get_Stmt(); 1118 if(temps instanceof GotoStmt){ 1119 Unit target = ((GotoStmt)temps).getTarget(); 1120 if(target != s){ 1121 return false; 1123 } 1124 else{ 1125 } 1127 } 1128 else{ 1129 if(temps != s){ 1130 return false; 1132 } 1133 else{ 1134 } 1136 } 1137 1138 } 1139 return true; 1140 } 1141 1142 1143 1144 private boolean verify_ESuccs( AugmentedStmt as, IterableSet ref) 1145 { 1146 IterableSet esuccs = new IterableSet(); 1147 1148 1149 esuccs.addAll( as.csuccs); 1150 esuccs.removeAll( as.bsuccs); 1151 1152 return esuccs.equals( ref); 1155 } 1156 1157 1158 1159 1164 private IterableSet get_BodyApproximation( AugmentedStmt head, IterableSet synchSet) { 1165 IterableSet body = (IterableSet) synchSet.clone(); 1166 Value local = ((EnterMonitorStmt) head.get_Stmt()).getOp(); 1167 Integer level = (Integer ) ((HashMap) as2ml.get( head)).get( local); 1168 1169 1170 body.remove( head); 1172 1173 Iterator bit = body.snapshotIterator(); 1174 while (bit.hasNext()) { 1175 AugmentedStmt as = (AugmentedStmt) bit.next(); 1176 Stmt s = as.get_Stmt(); 1177 1178 if ((s instanceof ExitMonitorStmt) && (((ExitMonitorStmt) s).getOp() == local) && 1179 (((Integer ) ((HashMap) as2ml.get( as)).get( local)).equals( level))) { 1180 1181 Iterator sit = as.csuccs.iterator(); 1182 while (sit.hasNext()) { 1183 AugmentedStmt sas = (AugmentedStmt) sit.next(); 1184 1185 if (sas.get_Dominators().contains( head) == false) 1187 continue; 1188 1189 Stmt ss = sas.get_Stmt(); 1190 1191 if (((ss instanceof GotoStmt) || (ss instanceof ThrowStmt)) && (body.contains( sas) == false)){ 1192 body.add( sas); 1195 } 1196 } 1197 } 1198 } 1199 1200 return body; 1201 } 1202} 1203 | Popular Tags |