コード例 #1
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testPegChain(Chain chain) {
    System.out.println("******** chain********");
    Iterator it = chain.iterator();
    while (it.hasNext()) {
      /*Object o = it.next();
      System.out.println(o);
      if (!(o instanceof JPegStmt))  System.out.println("not instanceof JPegStmt: "+o);
      JPegStmt s = (JPegStmt)o;
      */
      JPegStmt stmt = (JPegStmt) it.next();
      System.out.println(stmt.toString());
      /*if (stmt.getName().equals("start")){

      System.out.println("find start method in : " + stmt.toString() );
      List list =(List)startToThread.get(stmt);
      Iterator chainIt = list.iterator();
      while (chainIt.hasNext()){
      Chain chain = (Chain)chainIt.next();
      Iterator subit = chain.iterator();
      while (subit.hasNext()){
      System.out.println("**" + ((JPegStmt)subit.next()).toString());
      }
      }
      System.out.println("$$$$$$returing to main chain");
      }
      */
    }
  }
コード例 #2
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testStartToThread() {
    System.out.println("=====test startToThread ");
    Set maps = startToThread.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      JPegStmt key = (JPegStmt) entry.getKey();
      Tag tag = (Tag) key.getTags().get(0);
      System.out.println("---key=  " + tag + " " + key);
      /*	    List list = (List)entry.getValue();
      if (list.size()>0){

      System.out.println("**thread set:");
      Iterator it = list.iterator();
      while (it.hasNext()){
      Chain chain =(Chain)it.next();
      Iterator chainIt = chain.iterator();

      System.out.println("the size of chain is: "+chain.size());
      while (chainIt.hasNext()){
      JPegStmt stmt = (JPegStmt)chainIt.next();
      System.out.println(stmt);
      }
      }
      }
      */
    }
    System.out.println("=========startToThread--ends--------");
  }
コード例 #3
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void addTag() {
    // add tag for each stmt
    Iterator it = iterator();
    //		int count = 0;

    while (it.hasNext()) {
      JPegStmt stmt = (JPegStmt) it.next();
      int count = Counter.getTagNo();
      //			count++;
      StringTag t = new StringTag(Integer.toString(count));
      stmt.addTag(t);
    }
  }
コード例 #4
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testThreadNameToStart() {
    System.out.println("=====test ThreadNameToStart");
    Set maps = threadNameToStart.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      Object key = entry.getKey();

      System.out.println("---key=  " + key);
      JPegStmt stmt = (JPegStmt) entry.getValue();
      Tag tag1 = (Tag) stmt.getTags().get(0);
      System.out.println("value: " + tag1 + " " + stmt);
    }
    System.out.println("=========ThreadNameToStart--ends--------");
  }
コード例 #5
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  private boolean removeBeginNode() {
    List heads = getHeads();
    if (heads.size() != 1) {
      // System.out.println("heads: "+heads);
      // System.out.println("Error: the size of heads is not equal to 1!");
      return false;
      //	    System.exit(1);
    } else {
      JPegStmt head = (JPegStmt) heads.get(0);
      // System.out.println("test head: "+head);
      if (!head.getName().equals("begin")) {
        System.err.println("Error: the head is not begin node!");
        System.exit(1);
      }
      // remove begin node from heads list
      heads.remove(0);
      // set the preds list of the succs of head to a new list and put succs of head into heads
      Iterator succOfHeadIt = getSuccsOf(head).iterator();
      while (succOfHeadIt.hasNext()) {

        JPegStmt succOfHead = (JPegStmt) succOfHeadIt.next();

        unitToPreds.put(succOfHead, new ArrayList());
        // put succs of head into heads
        heads.add(succOfHead);
      }
      // remove begin node from inlinee Peg
      if (!mainPegChain.remove(head)) {
        System.err.println("fail to remove begin node in from mainPegChain!");
        System.exit(1);
      }
      if (!allNodes.contains(head)) {
        System.err.println("fail to find begin node in FlowSet allNodes!");
        System.exit(1);
      } else {
        allNodes.remove(head);
      }

      // remove begin node from unitToSuccs
      if (unitToSuccs.containsKey(head)) {
        unitToSuccs.remove(head);
      }
    }

    return true;
  }
コード例 #6
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  public void testWaitingNodes() {
    System.out.println("------waiting---begin");
    Set maps = waitingNodes.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      System.out.println("---key=  " + entry.getKey());
      FlowSet fs = (FlowSet) entry.getValue();
      if (fs.size() > 0) {

        System.out.println("**waiting nodes set:");
        Iterator it = fs.iterator();
        while (it.hasNext()) {
          JPegStmt unit = (JPegStmt) it.next();

          System.out.println(unit.toString());
        }
      }
    }
    System.out.println("------------waitingnodes---ends--------");
  }
コード例 #7
0
  public void testMonitor() {
    System.out.println("=====test monitor size: " + monitor.size());
    Set maps = monitor.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      String key = (String) entry.getKey();

      System.out.println("---key=  " + key);
      FlowSet list = (FlowSet) entry.getValue();
      if (list.size() > 0) {

        System.out.println("**set:  " + list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
          JPegStmt stmt = (JPegStmt) it.next();
          Tag tag1 = (Tag) stmt.getTags().get(0);
          System.out.println(tag1 + " " + stmt);
        }
      }
    }
    System.out.println("=========monitor--ends--------");
  }
コード例 #8
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void testUnitToSucc() {
    System.out.println("=====test unitToSucc ");
    Set maps = unitToSuccs.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      JPegStmt key = (JPegStmt) entry.getKey();
      Tag tag = (Tag) key.getTags().get(0);
      System.out.println("---key=  " + tag + " " + key);
      List list = (List) entry.getValue();
      if (list.size() > 0) {

        System.out.println("**succ set: size: " + list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
          JPegStmt stmt = (JPegStmt) it.next();
          Tag tag1 = (Tag) stmt.getTags().get(0);
          System.out.println(tag1 + " " + stmt);
        }
      }
    }
    System.out.println("=========unitToSucc--ends--------");
  }
コード例 #9
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  public void testMonitor() {
    System.out.println("=====test monitor size: " + monitor.size());
    Set maps = monitor.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      String key = (String) entry.getKey();

      System.out.println("---key=  " + key);
      FlowSet list = (FlowSet) entry.getValue();
      if (list.size() > 0) {

        System.out.println("**set:  " + list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
          Object obj = it.next();
          if (obj instanceof JPegStmt) {
            JPegStmt stmt = (JPegStmt) obj;
            Tag tag1 = (Tag) stmt.getTags().get(0);
            System.out.println(tag1 + " " + stmt);
          } else {
            System.out.println("---list---");
            Iterator listIt = ((List) obj).iterator();
            while (listIt.hasNext()) {
              Object oo = listIt.next();
              if (oo instanceof JPegStmt) {
                JPegStmt unit = (JPegStmt) oo;
                Tag tag = (Tag) unit.getTags().get(0);
                System.out.println(tag + " " + unit);
              } else System.out.println(oo);
            }
            System.out.println("---list--end-");
          }
        }
      }
    }
    System.out.println("=========monitor--ends--------");
  }
コード例 #10
0
  protected void doAnalysis() {
    LinkedList<Object> changedUnits = new LinkedList<Object>();
    HashSet<Object> changedUnitsSet = new HashSet<Object>();

    int numNodes = graph.size();
    int numComputations = 0;

    // Set initial values and nodes to visit.

    createWorkList(changedUnits, changedUnitsSet);

    // testWorkList(changedUnits);

    // Set initial values for entry points
    {
      Iterator it = graph.getHeads().iterator();

      while (it.hasNext()) {
        Object s = it.next();

        // unitToBeforeFlow.put(s, entryInitialFlow());
        nodes.add(s);
        valueBefore.add(entryInitialFlow());
      }
    }

    // Perform fixed point flow analysis
    {
      Object previousAfterFlow = newInitialFlow();

      while (!changedUnits.isEmpty()) {
        Object beforeFlow;
        Object afterFlow;

        Object s = changedUnits.removeFirst();
        Tag tag = (Tag) ((JPegStmt) s).getTags().get(0);
        // System.out.println("===unit is: "+tag+" "+s);
        changedUnitsSet.remove(s);

        // copy(unitToAfterFlow.get(s), previousAfterFlow);
        // add for debug april 6
        int pos = nodes.indexOf(s);
        copy(valueAfter.elementAt(pos), previousAfterFlow);
        // end add for debug april
        // Compute and store beforeFlow
        {
          List preds = graph.getPredsOf(s);

          // beforeFlow = unitToBeforeFlow.get(s);

          beforeFlow = valueBefore.elementAt(pos);

          if (preds.size() == 1) {
            // copy(unitToAfterFlow.get(preds.get(0)), beforeFlow);
            copy(valueAfter.elementAt(nodes.indexOf(preds.get(0))), beforeFlow);
          } else if (preds.size() != 0) {
            Iterator predIt = preds.iterator();
            Object obj = predIt.next();

            // copy(unitToAfterFlow.get(obj), beforeFlow);
            copy(valueAfter.elementAt(nodes.indexOf(obj)), beforeFlow);

            while (predIt.hasNext()) {
              JPegStmt stmt = (JPegStmt) predIt.next();
              if (stmt.equals(obj)) {
                // System.out.println("!!!same object!!!");
                continue;
              }
              Tag tag1 = (Tag) stmt.getTags().get(0);
              // System.out.println("pred: "+tag1+" "+stmt);

              // Object otherBranchFlow = unitToAfterFlow.get(stmt);
              if (nodes.indexOf(stmt) >= 0) // RLH
              {
                Object otherBranchFlow = valueAfter.elementAt(nodes.indexOf(stmt));

                merge(beforeFlow, otherBranchFlow, beforeFlow);
              }
            }
          }
        }

        // Compute afterFlow and store it.
        {
          // afterFlow = unitToAfterFlow.get(s);
          afterFlow = valueAfter.elementAt(nodes.indexOf(s));
          flowThrough(beforeFlow, s, afterFlow);

          // unitToAfterFlow.put(s, afterFlow);
          valueAfter.set(nodes.indexOf(s), afterFlow);
          // System.out.println("update afterFlow nodes: "+s);
          // System.out.println("afterFlow: "+afterFlow);
          // ((MonitorSet)unitToAfterFlow.get(s)).test();

          numComputations++;
        }

        // Update queue appropriately

        if (!afterFlow.equals(previousAfterFlow)) {

          Iterator succIt = graph.getSuccsOf(s).iterator();

          while (succIt.hasNext()) {
            Object succ = succIt.next();

            if (!changedUnitsSet.contains(succ)) {
              changedUnits.addLast(succ);
              changedUnitsSet.add(succ);
              /*if (succ instanceof JPegStmt){
              Tag tag1 = (Tag)((JPegStmt)succ).getTags().get(0);

              System.out.println("add to worklist: "+tag1+" "+succ);
              }
              else
              System.out.println("add to worklist: "+succ);
              */
            }
          }
        }
      }
    }

    // G.v().out.println(graph.getBody().getMethod().getSignature() + " numNodes: " + numNodes +
    //    " numComputations: " + numComputations + " avg: " + Main.truncatedOf((double)
    // numComputations / numNodes, 2));

    Timers.v().totalFlowNodes += numNodes;
    Timers.v().totalFlowComputations += numComputations;
  }
コード例 #11
0
  //	STEP 5: Define flow equations.
  //	in(s) = ( out(s) minus defs(s) ) union uses(s)
  //
  protected void flowThrough(Object inValue, Object unit, Object outValue) {
    MonitorSet in = (MonitorSet) inValue;
    MonitorSet out = (MonitorSet) outValue;
    JPegStmt s = (JPegStmt) unit;
    Tag tag = (Tag) s.getTags().get(0);
    // System.out.println("s: "+tag+" "+s);
    // Copy in to out
    // if (in.contains("&")) in.remove("&");

    in.copy(out);
    //	System.out.println("-----in: ");
    // in.test();

    if (in.size() > 0) {

      if (!s.getName().equals("waiting") && !s.getName().equals("notified-entry"))
        updateMonitor(in, unit);
    }
    String objName = s.getObject();
    // if (objName == null) throw new RuntimeException("null object: "+s.getUnit());
    if (s.getName().equals("entry") || s.getName().equals("exit")) {
      if (out.contains("&")) out.remove("&");

      Object obj = out.getMonitorDepth(objName);

      if (obj == null) {

        if (s.getName().equals("entry")) {
          MonitorDepth md = new MonitorDepth(objName, 1);
          out.add(md);
          // System.out.println("add to out: "+md.getObjName()+" "+md.getDepth());
        }
        /*
        else{
        throw new RuntimeException("The monitor depth can not be decreased at  "+
        (Tag)((JPegStmt)s).getTags().get(0)+" "+unit);
        }
        */

      } else {
        // System.out.println("obj: "+obj);
        if (obj instanceof MonitorDepth) {
          MonitorDepth md = (MonitorDepth) obj;

          if (s.getName().equals("entry")) {
            md.increaseDepth();
            // System.out.println("===increase depth===");
          } else {

            if (md.getDepth() > 1) {
              // System.out.println("===decrease depth==");
              md.decreaseDepth();
            } else if (md.getDepth() == 1) {
              //  System.out.println("===remove monitordepth: "+md);

              out.remove(md);
            } else throw new RuntimeException("The monitor depth can not be decreased at  " + unit);
          }
        } else throw new RuntimeException("MonitorSet contains non MonitorDepth element!");
      }
    }

    // System.out.println("-----out: "+out);
    // out.test();
    // testForDebug();
  }
コード例 #12
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  protected void buildSuccsForInlining(JPegStmt stmt, Chain chain, PegGraph inlinee) {
    // System.out.println("entering buildSuccsForInlining...");
    Tag tag = (Tag) stmt.getTags().get(0);
    // System.out.println("stmt is: "+tag+" "+stmt);
    /*connect heads of inlinee with the preds of invokeStmt and
     * delete stmt from the succs list from the preds
     */

    Iterator predIt = getPredsOf(stmt).iterator();
    // System.out.println("preds list: "+getPredsOf(stmt));
    // System.out.println("preds size: "+getPredsOf(stmt).size());
    Iterator headsIt = inlinee.getHeads().iterator();
    {
      // System.out.println("heads: "+inlinee.getHeads());
      while (predIt.hasNext()) {
        JPegStmt pred = (JPegStmt) predIt.next();
        // System.out.println("pred: "+pred);
        List succList = (List) getSuccsOf(pred);
        // System.out.println("succList of pred: "+succList);
        int pos = succList.indexOf(stmt);
        // System.out.println("remove : "+stmt + " from succList: \n"+succList+ "\n of pred" );
        // remove invokeStmt
        succList.remove(pos);

        while (headsIt.hasNext()) {
          succList.add(headsIt.next());
        }
        unitToSuccs.put(pred, succList);
      }

      {
        while (headsIt.hasNext()) {
          Object head = headsIt.next();
          List predsOfHeads = new ArrayList();
          predsOfHeads.addAll(getPredsOf(head));
          unitToPreds.put(head, predsOfHeads);
        }
      }
      /*
      {
      predIt = getPredsOf(stmt).iterator();
      while (predIt.hasNext()){
      JPegStmt s = (JPegStmt)predIt.next();
      if (unitToSuccs.containsKey(s)){
      Iterator succIt = ((List) unitToSuccs.get(s)).iterator();
      while(succIt.hasNext()){

      //Object successor =  succIt.next();
       JPegStmt successor = (JPegStmt)succIt.next();
       List predList = (List) unitToPreds.get(successor);
       if (predList != null) {
       try {
       predList.add(s);

       } catch(NullPointerException e) {
       System.out.println(s + "successor: " + successor);
       throw e;
       }
       }
       }
       }
       }




       }*/

    }

    /*connect tails of inlinee with the succ of invokeStmt and
     * delete stmt from the
     */

    Iterator tailsIt = inlinee.getTails().iterator();
    {
      // System.out.println("tails: "+inlinee.getTails());
      while (tailsIt.hasNext()) {
        Iterator succIt = getSuccsOf(stmt).iterator();
        JPegStmt tail = (JPegStmt) tailsIt.next();
        List succList = null;
        if (unitToSuccs.containsKey(tail)) {
          // System.out.println("error: unitToSucc containsKey: "+tail);
          succList = (List) getSuccsOf(tail);
          // System.out.println("succList: "+succList);
        } else {

          succList = new ArrayList();
        }
        while (succIt.hasNext()) {
          JPegStmt succ = (JPegStmt) succIt.next();
          succList.add(succ);
          // System.out.println("succ: "+succ);
          // remove stmt from the preds list of the succs of itself.
          List predListOfSucc = getPredsOf(succ);
          if (predListOfSucc == null) {
            System.err.println("Error: predListOfSucc is null!");
            System.exit(1);
          } else {
            if (predListOfSucc.size() != 0) {

              int pos = predListOfSucc.indexOf(stmt);
              if (pos > 0 || pos == 0) {

                //	System.out.println("remove stmt: "+stmt+" from the preds list"+predListOfSucc+"
                // of the succ");
                predListOfSucc.remove(pos);
              }

              //		System.out.println("remove(from PRED): ");
            }
          }
          unitToPreds.put(succ, predListOfSucc);
        }
        unitToSuccs.put(tail, succList);
        // System.out.println("put: "+tail);
        // System.out.println("succList: "+succList+ "into unitToSucc");

      }
    }

    // add Nov 1
    {
      tailsIt = inlinee.getTails().iterator();
      while (tailsIt.hasNext()) {
        JPegStmt s = (JPegStmt) tailsIt.next();
        if (unitToSuccs.containsKey(s)) {
          Iterator succIt = unitToSuccs.get(s).iterator();
          while (succIt.hasNext()) {

            // Object successor =  succIt.next();
            JPegStmt successor = (JPegStmt) succIt.next();
            List<JPegStmt> predList = unitToPreds.get(successor);
            if (predList != null && !predList.contains(s)) {
              try {
                predList.add(s);
                /*
                Tag tag = (Tag)successor.getTags().get(0);
                System.out.println("add "+s+" to predlist of "+tag+" "+successor);
                */
              } catch (NullPointerException e) {
                System.out.println(s + "successor: " + successor);
                throw e;
              }
            }
          }
        }
      }
    }
    // end add Nov 1

    // System.out.println("stmt: "+stmt);
    // remove stmt from allNodes and mainPegChain
    // System.out.println("mainPegChain contains stmt: "+mainPegChain.contains(stmt));
    //		testPegChain();

    if (!allNodes.contains(stmt)) {
      System.err.println("fail to find begin node in  allNodes!");
      System.exit(1);
    } else {
      allNodes.remove(stmt);
      // System.out.println("remove from allNode: "+stmt);
    }

    if (!chain.contains(stmt)) {
      System.err.println("Error! Chain does not contains stmt (extending point)!");
      System.exit(1);

    } else {
      if (!chain.remove(stmt)) {
        System.err.println("fail to remove invoke stmt in from Chain!");
        System.exit(1);
      }
    }
    /*
    if (!mainPegChain.contains(stmt)){
    boolean find = false;
    //System.out.println("main chain does not contain AFTER");
     Set maps = startToThread.entrySet();
     for(Iterator iter=maps.iterator(); iter.hasNext();){
     Map.Entry entry = (Map.Entry)iter.next();
     Object startNode = entry.getKey();
     Iterator runIt  = ((List)entry.getValue()).iterator();
     while (runIt.hasNext()){
     Chain chain=(Chain)runIt.next();
     if (chain.contains(stmt)) {
     find = true;
     if (!chain.remove(stmt)){
     System.err.println("fail to remove begin node in from mainPegChain!");
     System.exit(1);
     }
     break;
     }
     }
     if (find == false){
     System.err.println("fail to find stmt: "+stmt+" in chains!");
     System.exit(1);
     }
     }
     //this.toString();
      }
      else{
      if (!mainPegChain.remove(stmt)) {
      System.err.println("fail to remove begin node in from mainPegChain!");
      System.exit(1);
      }
      else{
      // System.out.println("remove(from mainchain): "+stmt);
       }
       }
       */
    // remove stmt from unitToSuccs and unitToPreds
    if (unitToSuccs.containsKey(stmt)) {
      unitToSuccs.remove(stmt);
    }
    if (unitToPreds.containsKey(stmt)) {
      unitToPreds.remove(stmt);
    }
  }
コード例 #13
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  /*
  private void deleteExitToException(){
  Iterator it = iterator();
  while (it.hasNext()){
  JPegStmt stmt = (JPegStmt)it.next();
  Unit unit = stmt.getUnit();
  UnitGraph unitGraph = stmt.getUnitGraph();
  if (unit instanceof ExitMonitorStmt){
  Iterator succIt = unitGraph.getSuccsOf(unit).iterator();
  while(succIt.next
  && exceHandlers.contains(un) ){
  System.out.println("====find it! unit: "+unit+"\n un: "+un);
  continue;
  }
  }
  }
  */
  private void buildPredecessor(Chain pegChain) {
    // System.out.println("==building predcessor===");

    // initialize the pred sets to empty
    {
      JPegStmt s = null;
      Iterator unitIt = pegChain.iterator();
      while (unitIt.hasNext()) {

        s = (JPegStmt) unitIt.next();

        unitToPreds.put(s, new ArrayList());
      }
    }
    //	System.out.println("==finish init of unitToPred===");
    {
      Iterator unitIt = pegChain.iterator();

      while (unitIt.hasNext()) {

        Object s = unitIt.next();
        //		System.out.println("s is: "+s);

        // Modify preds set for each successor for this statement
        if (unitToSuccs.containsKey(s)) {
          List succList = unitToSuccs.get(s);
          Iterator succIt = succList.iterator();
          //		    System.out.println("unitToSuccs contains "+s);
          //		    System.out.println("succList is: "+succList);
          while (succIt.hasNext()) {

            // Object successor =  succIt.next();
            JPegStmt successor = (JPegStmt) succIt.next();
            //			System.out.println("successor is: "+successor);
            List<Object> predList = unitToPreds.get(successor);
            //			System.out.println("predList is: "+predList);
            if (predList != null && !predList.contains(s)) {
              try {
                predList.add(s);
                /*
                Tag tag1 = (Tag)((JPegStmt)s).getTags().get(0);
                System.out.println("add "+tag1+" "+s+" to predListof");
                Tag tag2 = (Tag)((JPegStmt)successor).getTags().get(0);
                System.out.println(tag2+" "+successor);
                */
              } catch (NullPointerException e) {
                System.out.println(s + "successor: " + successor);
                throw e;
              }
              // if (((JPegStmt)successor).getName().equals("start")){
              if (successor instanceof StartStmt) {
                List runMethodChainList = startToThread.get(successor);
                if (runMethodChainList == null) {
                  throw new RuntimeException("null runmehtodchain: \n" + successor.getUnit());
                }
                Iterator possibleMethodIt = runMethodChainList.iterator();
                while (possibleMethodIt.hasNext()) {

                  Chain subChain = (Chain) possibleMethodIt.next();

                  buildPredecessor(subChain);
                }
              }
            } else {
              System.err.println("predlist of " + s + " is null");
              //							System.exit(1);
            }
            //			unitToPreds.put(successor, predList);

          }

        } else {
          System.err.println("unitToSuccs does not contains key" + s);
          System.exit(1);
        }
      }
    }
  }
コード例 #14
0
ファイル: PegGraph.java プロジェクト: Hounge/apkinspector
  private void buildSuccessor(Chain pegChain) {

    // Add regular successors
    {
      HashMap unitToPeg = (HashMap) unitToPegMap.get(pegChain);
      Iterator pegIt = pegChain.iterator();
      JPegStmt currentNode, nextNode;
      currentNode = pegIt.hasNext() ? (JPegStmt) pegIt.next() : null;
      // June 19 add for begin node
      if (currentNode != null) {
        // System.out.println("currentNode: "+currentNode);
        // if the unit is "begin" node
        nextNode = pegIt.hasNext() ? (JPegStmt) pegIt.next() : null;

        if (currentNode.getName().equals("begin")) {
          List<JPegStmt> successors = new ArrayList<JPegStmt>();
          successors.add(nextNode);
          unitToSuccs.put(currentNode, successors);

          currentNode = nextNode;
        }
        // end June 19 add for begin node

        while (currentNode != null) {
          //		    System.out.println("currentNode: "+currentNode);
          /* If unitToSuccs contains currentNode, it is the point to inline methods,
           * we need not compute its successors again
           */

          if (unitToSuccs.containsKey(currentNode) && !currentNode.getName().equals("wait")) {
            currentNode = pegIt.hasNext() ? (JPegStmt) pegIt.next() : null;
            continue;
          }
          List<JPegStmt> successors = new ArrayList<JPegStmt>();
          Unit unit = currentNode.getUnit();

          UnitGraph unitGraph = currentNode.getUnitGraph();
          List unitSucc = unitGraph.getSuccsOf(unit);
          Iterator succIt = unitSucc.iterator();
          while (succIt.hasNext()) {
            Unit un = (Unit) succIt.next();

            // Don't build the edge from "monitor exit" to exception handler

            if (unit instanceof ExitMonitorStmt && exceHandlers.contains(un)) {
              // System.out.println("====find it! unit: "+unit+"\n un: "+un);
              continue;
            } else if (unitToPeg.containsKey(un)) {
              JPegStmt pp = (JPegStmt) (unitToPeg.get(un));
              if (pp != null && !successors.contains(pp)) successors.add(pp);
            }
          } // end while

          if (currentNode.getName().equals("wait")) {
            while (!(currentNode.getName().equals("notified-entry"))) {
              currentNode = pegIt.hasNext() ? (JPegStmt) pegIt.next() : null;
            }
            unitToSuccs.put(currentNode, successors);
            // System.out.println("put key: "+currentNode+" into unitToSucc");
          } else {
            unitToSuccs.put(currentNode, successors);
          }
          if (currentNode.getName().equals("start")) {

            //						System.out.println("-----build succ for start----");

            if (startToThread.containsKey(currentNode)) {
              List runMethodChainList = startToThread.get(currentNode);
              Iterator possibleMethodIt = runMethodChainList.iterator();
              while (possibleMethodIt.hasNext()) {

                Chain subChain = (Chain) possibleMethodIt.next();
                if (subChain != null) {
                  // System.out.println("build succ for subChain");
                  // buildSuccessor(subGraph, subChain, addExceptionEdges);
                  buildSuccessor(subChain);
                } else System.out.println("*********subgraph is null!!!");
              }
            }
          }

          currentNode = pegIt.hasNext() ? (JPegStmt) pegIt.next() : null;
        } // while

        // June 19 add for begin node
      }
      // end June 19 add for begin node
    }
  }