Beispiel #1
0
  @Override
  protected void merge(Object in1, Object in2, Object out) {

    FlowSet inSet1 = (FlowSet) in1, inSet2 = (FlowSet) in2, outSet = (FlowSet) out;
    inSet1.union(inSet2, outSet);

    //		 System.out.println("inset1: " + inSet1 + "\ninset2: " + inSet2 + "\noutset: " + outSet);
  }
 public boolean equals(Object o) {
   if (!(o instanceof FlowSet)) return false;
   FlowSet other = (FlowSet) o;
   if (size() != other.size()) return false;
   Iterator it = toList().iterator();
   while (it.hasNext()) if (!other.contains(it.next())) return false;
   return true;
 }
Beispiel #3
0
 public FlowSet getFlowBeforeEnd() {
   FlowSet inEnd = new ArraySparseSet();
   List<Unit> tails = g.getTails();
   for (Unit u : tails) {
     if (!(u instanceof ThrowStmt)) { // TODO verify this
       inEnd.union((FlowSet) getFlowBefore(u));
     }
   }
   return inEnd;
 }
  public void computeSynchNodes() {
    int num = 0;
    Set maps = monitor.entrySet();

    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();
      FlowSet fs = (FlowSet) entry.getValue();
      num += fs.size();
    }
    System.err.println("synch objects: " + num);
  }
 /**
  * Creates a KILL set for a given Unit and it to the FlowSet dest. In this case, our KILL set are
  * the Assignments made to the same Value that this Unit assigns to.
  *
  * @param src the src
  * @param unit the unit
  * @param dest the dest
  */
 private void kill(FlowSet source, AssignStmt assignment, FlowSet dest) {
   FlowSet kills = new ArraySparseSet();
   for (Object earlierAssignment : source.toList()) {
     if (earlierAssignment instanceof AssignStmt) {
       AssignStmt stmt = (AssignStmt) earlierAssignment;
       if (stmt.getLeftOp().equivTo(assignment.getLeftOp())) {
         kills.add(earlierAssignment);
       }
     }
   }
   source.difference(kills, dest);
 }
Beispiel #6
0
  public void computeMonitorObjs() {
    Set maps = monitor.entrySet();
    for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Map.Entry) iter.next();

      FlowSet fs = (FlowSet) entry.getValue();
      Iterator it = fs.iterator();
      while (it.hasNext()) {
        Object obj = it.next();
        if (!monitorObjs.contains(obj)) monitorObjs.add(obj);
      }
    }
  }
  public void union(FlowSet other, FlowSet dest) {
    if (dest != this && dest != other) dest.clear();

    if (dest != this) {
      Iterator thisIt = toList().iterator();
      while (thisIt.hasNext()) dest.add(thisIt.next());
    }

    if (dest != other) {
      Iterator otherIt = other.toList().iterator();
      while (otherIt.hasNext()) dest.add(otherIt.next());
    }
  }
Beispiel #8
0
  private int numMatchArgs(int numFormals, UnchangedParamsAnalysis mrpa, Stmt s) {
    FlowSet before = (FlowSet) mrpa.getFlowBefore(s);

    List args = ((InvokeExpr) s.getInvokeExpr()).getArgs();
    int matchArg = 0;
    for (int i = 0; i < numFormals; i++) {
      Value arg = (Value) args.get(i);
      for (Iterator rppIt = before.iterator(); rppIt.hasNext(); ) {
        IDValuePair rpp = (IDValuePair) rppIt.next();
        if (rpp.groupID == i && arg.equivTo(rpp.value)) {
          matchArg++;
          break;
        }
      }
    }
    return matchArg;
  }
Beispiel #9
0
  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;
  }
  /*
   * (non-Javadoc)
   *
   * @see soot.toolkits.scalar.FlowAnalysis#flowThrough(java.lang.Object, java.lang.Object, java.lang.Object)
   */
  @Override
  protected void flowThrough(FlowSet source, Unit unit, FlowSet dest) {

    if (unit instanceof AssignStmt) {
      AssignStmt assignment = (AssignStmt) unit;

      FeatureTag tag = (FeatureTag) assignment.getTag(FeatureTag.FEAT_TAG_NAME);
      IFeatureRep featureRep = tag.getFeatureRep();

      if (featureRep.belongsToConfiguration(configuration)) {
        kill(source, assignment, dest);
        gen(dest, assignment);
      } else {
        source.copy(dest);
      }
    } else {
      source.copy(dest);
    }
  }
 public void intersection(FlowSet other, FlowSet dest) {
   if (dest == this && dest == other) return;
   List elements = null;
   FlowSet flowSet = null;
   if (dest == this) {
     /* makes automaticly a copy of <code>this</code>, as it will be cleared */
     elements = toList();
     flowSet = other;
   } else {
     /* makes a copy o <code>other</code>, as it might be cleared */
     elements = other.toList();
     flowSet = this;
   }
   dest.clear();
   Iterator it = elements.iterator();
   while (it.hasNext()) {
     Object o = it.next();
     if (flowSet.contains(o)) dest.add(o);
   }
 }
Beispiel #12
0
  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--------");
  }
Beispiel #13
0
  public boolean addPeg(PegGraph pg, Chain chain) {
    if (!pg.removeBeginNode()) return false;
    //		System.out.println("adding one peg into another");

    //		System.out.println("after removeBeginNode===");
    //	pg.testPegChain();
    // System.out.println(pg);

    // put every node of peg into this
    Iterator mainIt = pg.mainIterator();

    while (mainIt.hasNext()) {
      JPegStmt s = (JPegStmt) mainIt.next();
      //			System.out.println("add to mainPegChain: "+s);
      mainPegChain.addLast(s);
      //			if (chain.contains(s)){
      //				System.err.println("error! chain contains: "+s);
      //				System.exit(1);
      //			}
      //			else
      //				chain.addLast(s);

    }
    Iterator it = pg.iterator();
    while (it.hasNext()) {
      JPegStmt s = (JPegStmt) it.next();
      // System.out.println("add to allNodes: "+s);
      if (allNodes.contains(s)) {
        System.err.println("error! allNodes contains: " + s);
        System.exit(1);
      } else allNodes.add(s);
    }
    //	testPegChain();
    //	testIterator();
    unitToSuccs.putAll(pg.getUnitToSuccs());
    unitToPreds.putAll(pg.getUnitToPreds());
    //	testUnitToSucc();
    // testUnitToPred();
    //		buildMaps(pg); // RLH
    return true;
  }
Beispiel #14
0
  /**
   * given a DelayabilityAnalysis and the computations of each unit, calculates the latest
   * computation-point for each expression.<br>
   * the <code>equivRhsMap</code> could be calculated on the fly, but it is <b>very</b> likely that
   * it already exists (as similar maps are used for calculating Earliestness, Delayed,...<br>
   * the shared set allows more efficient set-operations, when they the computation is merged with
   * other analyses/computations.
   *
   * @param dg a ExceptionalUnitGraph
   * @param delayed the delayability-analysis of the same graph.
   * @param equivRhsMap all computations of the graph
   * @param set the shared flowSet
   */
  public LatestComputation(
      UnitGraph unitGraph, DelayabilityAnalysis delayed, Map equivRhsMap, BoundedFlowSet set) {
    unitToLatest = new HashMap<Unit, FlowSet>(unitGraph.size() + 1, 0.7f);

    Iterator unitIt = unitGraph.iterator();
    while (unitIt.hasNext()) {
      /* create a new Earliest-list for each unit */
      Unit currentUnit = (Unit) unitIt.next();

      /* basically the latest-set is:
       * (delayed) INTERSECT (comp UNION (UNION_successors ~Delayed)) =
       * (delayed) MINUS ((INTERSECTION_successors Delayed) MINUS comp).
       */

      FlowSet delaySet = (FlowSet) delayed.getFlowBefore(currentUnit);

      /* Calculate (INTERSECTION_successors Delayed) */
      FlowSet succCompSet = (FlowSet) set.topSet();
      List succList = unitGraph.getSuccsOf(currentUnit);
      Iterator succIt = succList.iterator();
      while (succIt.hasNext()) {
        Unit successor = (Unit) succIt.next();
        succCompSet.intersection((FlowSet) delayed.getFlowBefore(successor), succCompSet);
      }
      /* remove the computation of this set: succCompSet is then:
       * ((INTERSECTION_successors Delayed) MINUS comp) */
      if (equivRhsMap.get(currentUnit) != null) succCompSet.remove(equivRhsMap.get(currentUnit));

      /* make the difference: */
      FlowSet latest = (FlowSet) delaySet.emptySet();
      delaySet.difference(succCompSet, latest);

      unitToLatest.put(currentUnit, latest);
    }
  }
  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--------");
  }
 private void updateMonitor(MonitorSet ms, Object unit) {
   // System.out.println("===inside updateMonitor===");
   // ml.test();
   Iterator it = ms.iterator();
   while (it.hasNext()) {
     Object obj = it.next();
     if (obj instanceof MonitorDepth) {
       MonitorDepth md = (MonitorDepth) obj;
       String objName = md.getObjName();
       if (monitor.containsKey(objName)) {
         if (md.getDepth() > 0) {
           monitor.get(objName).add(unit);
           // System.out.println("add to monitorset "+unit);
         }
       } else {
         FlowSet monitorObjs = new ArraySparseSet();
         monitorObjs.add(unit);
         monitor.put(objName, monitorObjs);
         // System.out.println("put into monitor: "+objName);
       }
     }
   }
 }
Beispiel #17
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()) {
          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--------");
  }
  public void difference(FlowSet other, FlowSet dest) {
    if (dest == this && dest == other) {
      dest.clear();
      return;
    }

    Iterator it = this.toList().iterator();
    FlowSet flowSet = (other == dest) ? (FlowSet) other.clone() : other;
    dest.clear(); // now safe, since we have copies of this & other

    while (it.hasNext()) {
      Object o = it.next();
      if (!flowSet.contains(o)) dest.add(o);
    }
  }
 public void remove(Object obj, FlowSet dest) {
   if (dest != this) copy(dest);
   dest.remove(obj);
 }
 /*
  * (non-Javadoc)
  *
  * @see soot.toolkits.scalar.AbstractFlowAnalysis#merge(java.lang.Object, java.lang.Object, java.lang.Object)
  */
 @Override
 protected void merge(FlowSet source1, FlowSet source2, FlowSet dest) {
   source1.union(source2, dest);
 }
 /*
  * (non-Javadoc)
  *
  * @see soot.toolkits.scalar.AbstractFlowAnalysis#copy(java.lang.Object, java.lang.Object)
  */
 @Override
 protected void copy(FlowSet source, FlowSet dest) {
   source.copy(dest);
 }
 /**
  * Creates a GEN set for a given Unit and it to the FlowSet dest. In this case, our GEN set are
  * all the definitions present in the unit.
  *
  * @param dest the dest
  * @param unit the unit
  */
 private void gen(FlowSet dest, AssignStmt unit) {
   dest.add(unit);
 }
Beispiel #23
0
  private Map<Pair<Unit, Set<String>>, Set<Unit>> createProvidesConfigMap(
      Collection<Unit> unitsInSelection, LiftedReachingDefinitions reachingDefinitions, Body body) {
    Map<Pair<Unit, Set<String>>, Set<Unit>> unitConfigurationMap =
        new HashMap<Pair<Unit, Set<String>>, Set<Unit>>();

    for (Unit unitFromSelection : unitsInSelection) {
      if (unitFromSelection instanceof DefinitionStmt) {
        /*
         * exclude definitions when it's $temp on the leftOp.
         */
        DefinitionStmt definition = (DefinitionStmt) unitFromSelection;
        Local leftOp = (Local) definition.getLeftOp();
        if (leftOp.getName().charAt(0) == '$') {
          continue;
        }

        System.out.println("Definition:" + definition);

        // for every unit in the body...
        Iterator<Unit> iterator = body.getUnits().snapshotIterator();
        while (iterator.hasNext()) {
          Unit nextUnit = iterator.next();
          LiftedFlowSet<Collection<Set<Object>>> liftedFlowAfter =
              reachingDefinitions.getFlowAfter(nextUnit);
          Set<String>[] configurations = liftedFlowAfter.getConfigurations();
          FlowSet[] lattices = liftedFlowAfter.getLattices();
          // and for every configuration...
          for (int configurationIndex = 0;
              configurationIndex < configurations.length;
              configurationIndex++) {
            FlowSet flowSet = lattices[configurationIndex];
            Set<String> currConfiguration = configurations[configurationIndex];
            FeatureTag nextUnitTag = (FeatureTag) nextUnit.getTag("FeatureTag");

            // if the unit belongs to the current configuration...
            if (nextUnitTag.belongsToConfiguration(currConfiguration)) {

              // if the definition reaches this unit...
              if (flowSet.contains(definition)) {
                List<ValueBox> useBoxes = nextUnit.getUseBoxes();
                for (ValueBox vbox : useBoxes) {
                  /*
                   * and the definition is used, add to the
                   * map...
                   */
                  if (vbox.getValue().equivTo(leftOp)) {
                    Pair<Unit, Set<String>> currentPair =
                        new Pair<Unit, Set<String>>(definition, currConfiguration);
                    Set<Unit> unitConfigurationReachesSet = unitConfigurationMap.get(currentPair);

                    if (unitConfigurationReachesSet == null) {
                      unitConfigurationReachesSet = new HashSet<Unit>();
                      unitConfigurationReachesSet.add(nextUnit);
                      unitConfigurationMap.put(currentPair, unitConfigurationReachesSet);
                    } else {
                      unitConfigurationReachesSet.add(nextUnit);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    return unitConfigurationMap;
  }
 public void add(Object obj, FlowSet dest) {
   if (dest != this) copy(dest);
   dest.add(obj);
 }
Beispiel #25
0
  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);
    }
  }
Beispiel #26
0
  public Iterator iterator() {

    return allNodes.iterator();
  }
Beispiel #27
0
  // This method adds the monitorenter/exit statements into whichever pegChain contains the
  // corresponding node statement
  protected void addMonitorStmt() {
    // System.out.println("====entering addMonitorStmt");
    if (synch.size() > 0) {
      // System.out.println("synch: "+synch);
      Iterator<List> it = synch.iterator();
      while (it.hasNext()) {
        List list = it.next();

        JPegStmt node = (JPegStmt) list.get(0);
        JPegStmt enter = (JPegStmt) list.get(1);
        JPegStmt exit = (JPegStmt) list.get(2);
        //		System.out.println("monitor node: "+node);
        // System.out.println("monitor enter: "+enter);
        // System.out.println("monitor exit: "+exit);
        // add for test
        // System.out.println("allNodes contains node: "+allNodes.contains(node));
        // end add for test

        {
          if (!mainPegChain.contains(node)) {

            boolean find = false;
            // System.out.println("main chain does not contain node");
            Set maps = startToThread.entrySet();
            // System.out.println("size of startToThread: "+startToThread.size());
            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();
                //	testPegChain(chain);
                if (chain.contains(node)) {
                  find = true;
                  // System.out.println("---find it---");
                  chain.add(enter);
                  chain.add(exit);
                  break;
                }
              }
            }
            if (find == false) {
              System.err.println("fail to find stmt: " + node + " in chains!");
              System.exit(1);
            }

            // this.toString();
          } else {
            mainPegChain.add(enter);
            mainPegChain.add(exit);
          }
        }

        allNodes.add(enter);
        allNodes.add(exit);

        insertBefore(node, enter);
        insertAfter(node, exit);
      }
    }
    // add for test
    /*
    {
    // System.out.println("===main peg chain===");
     //testPegChain(mainPegChain);
      //System.out.println("===end main peg chain===");
       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();
       testPegChain(chain);
       }
       }
       }
       */
    //	System.out.println(this.toString());
    // end add for test
  }
Beispiel #28
0
  @Override
  protected void flowThrough(Object in, Object node, Object out) {
    // perform flow from in to out, through node
    FlowSet inSet = (FlowSet) in, outSet = (FlowSet) out;
    Unit unit = (Unit) node;

    //		 System.out.println(inSet);
    //		 System.out.println("=== " + unit);
    // copy inSet to outSet
    inSet.copy(outSet);

    if (unit instanceof Stmt) {
      Stmt s = (Stmt) unit;
      if (exactProceedSet.contains(s)) {
        // exact proceed
        outSet.add(EXACT);
        outSet.remove(NONE);
        outSet.remove(NON_EXACT);
      } else if (nonExactProceedSet.contains(s)) {
        // non-exact proceed
        if (!inSet.contains(EXACT)) {
          outSet.add(NON_EXACT);
          outSet.remove(NONE);
        }
      } else {
        // no proceed
        if (!inSet.contains(NON_EXACT) && !inSet.contains(EXACT)) outSet.add(NONE);
      }
    }
    //		 System.out.println(outSet);
  }
Beispiel #29
0
 @Override
 protected void copy(Object source, Object dest) {
   // copy from source to dest
   FlowSet srcSet = (FlowSet) source, destSet = (FlowSet) dest;
   srcSet.copy(destSet);
 }
Beispiel #30
0
  public int size() {
    return allNodes.size();
    //		return pegSize;

  }