Exemple #1
0
    /**
     * Returns a <code>ThrowableSet</code> representing the set of exceptions included in <code>
     * include</code> minus the set of exceptions included in <code>exclude</code>. Creates a new
     * <code>ThrowableSet</code> only if there was not already one whose contents correspond to
     * <code>include</code> - <code>exclude</code>.
     *
     * @param include A set of {@link RefLikeType} objects representing exception types included in
     *     the result; may be <code>null</code> if there are no included types.
     * @param exclude A set of {@link AnySubType} objects representing exception types excluded from
     *     the result; may be <code>null</code> if there are no excluded types.
     * @return a <code>ThrowableSet</code> representing the set of exceptions corresponding to
     *     <code>include</code> - <code>exclude</code>.
     */
    private ThrowableSet registerSetIfNew(Set include, Set exclude) {
      if (INSTRUMENTING) {
        registrationCalls++;
      }
      if (include == null) {
        include = Collections.EMPTY_SET;
      }
      if (exclude == null) {
        exclude = Collections.EMPTY_SET;
      }
      int size = include.size() + exclude.size();
      Integer sizeKey = new Integer(size);

      List sizeList = (List) sizeToSets.get(sizeKey);
      if (sizeList == null) {
        sizeList = new LinkedList();
        sizeToSets.put(sizeKey, sizeList);
      }
      for (Iterator i = sizeList.iterator(); i.hasNext(); ) {
        ThrowableSet set = (ThrowableSet) i.next();
        if (set.exceptionsIncluded.equals(include) && set.exceptionsExcluded.equals(exclude)) {
          return set;
        }
      }
      if (INSTRUMENTING) {
        registeredSets++;
      }
      ThrowableSet result = new ThrowableSet(include, exclude);
      sizeList.add(result);
      return result;
    }
Exemple #2
0
  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--------");
  }
  public StronglyConnectedComponentsBV(BitVector typeVariableList, TypeResolverBV resolver)
      throws TypeException {
    this.resolver = resolver;
    variables = typeVariableList;

    black = new TreeSet();
    finished = new LinkedList();

    for (BitSetIterator i = variables.iterator(); i.hasNext(); ) {
      TypeVariableBV var = resolver.typeVariableForId(i.next());

      if (!black.contains(var)) {
        black.add(var);
        dfsg_visit(var);
      }
    }

    black = new TreeSet();

    for (Iterator i = finished.iterator(); i.hasNext(); ) {
      TypeVariableBV var = (TypeVariableBV) i.next();

      if (!black.contains(var)) {
        current_tree = new LinkedList();
        forest.add(current_tree);
        black.add(var);
        dfsgt_visit(var);
      }
    }

    for (Iterator i = forest.iterator(); i.hasNext(); ) {
      LinkedList list = (LinkedList) i.next();
      TypeVariableBV previous = null;
      StringBuffer s = null;
      if (DEBUG) {
        s = new StringBuffer("scc:\n");
      }

      for (Iterator j = list.iterator(); j.hasNext(); ) {
        TypeVariableBV current = (TypeVariableBV) j.next();

        if (DEBUG) {
          s.append(" " + current + "\n");
        }

        if (previous == null) {
          previous = current;
        } else {
          try {
            previous = previous.union(current);
          } catch (TypeException e) {
            if (DEBUG) {
              G.v().out.println(s);
            }
            throw e;
          }
        }
      }
    }
  }
Exemple #4
0
 protected void testUnitToPeg(HashMap unitToPeg) {
   System.out.println("=====test unitToPeg ");
   Set maps = unitToPeg.entrySet();
   for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iter.next();
     System.out.println("---key=  " + entry.getKey());
     JPegStmt s = (JPegStmt) entry.getValue();
     System.out.println("--value= " + s);
   }
   System.out.println("=========unitToPeg--ends--------");
 }
Exemple #5
0
  protected void testJoinStmtToThread() {
    System.out.println("=====test JoinStmtToThread");
    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);

      System.out.println("value: " + entry.getValue());
    }
    System.out.println("=========JoinStmtToThread--ends--------");
  }
Exemple #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);
      }
    }
  }
Exemple #7
0
  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--------");
  }
Exemple #8
0
 protected void buildPreds() {
   buildPredecessor(mainPegChain);
   Set maps = getStartToThread().entrySet();
   for (Iterator iter = maps.iterator(); iter.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iter.next();
     List runMethodChainList = (List) entry.getValue();
     Iterator it = runMethodChainList.iterator();
     while (it.hasNext()) {
       Chain chain = (Chain) it.next();
       //	System.out.println("chain is null: "+(chain == null));
       buildPredecessor(chain);
     }
   }
 }
  private void dfsgt_visit(TypeVariableBV var) {
    current_tree.add(var);

    BitVector children = var.children();

    for (BitSetIterator i = children.iterator(); i.hasNext(); ) {
      TypeVariableBV child = resolver.typeVariableForId(i.next());

      if (!black.contains(child)) {
        black.add(child);
        dfsgt_visit(child);
      }
    }
  }
  private void dfsg_visit(TypeVariableBV var) {
    BitVector parents = var.parents();

    for (BitSetIterator i = parents.iterator(); i.hasNext(); ) {
      TypeVariableBV parent = resolver.typeVariableForId(i.next());

      if (!black.contains(parent)) {
        black.add(parent);
        dfsg_visit(parent);
      }
    }

    finished.add(0, var);
  }
Exemple #11
0
 protected void buildMaps(PegGraph pg) {
   exceHandlers.addAll(pg.getExceHandlers());
   startToThread.putAll(pg.getStartToThread());
   startToAllocNodes.putAll(pg.getStartToAllocNodes());
   startToBeginNodes.putAll(pg.getStartToBeginNodes());
   waitingNodes.putAll(pg.getWaitingNodes());
   notifyAll.putAll(pg.getNotifyAll());
   canNotBeCompacted.addAll(pg.getCanNotBeCompacted());
   synch.addAll(pg.getSynch());
   threadNameToStart.putAll(pg.getThreadNameToStart());
   specialJoin.addAll(pg.getSpecialJoin());
   joinStmtToThread.putAll(pg.getJoinStmtToThread());
   threadAllocSites.addAll(pg.getThreadAllocSites());
   allocNodeToThread.putAll(pg.getAllocNodeToThread());
 }
Exemple #12
0
 /** Returns a string representation of this <code>ThrowableSet</code>. */
 public String toString() {
   StringBuffer buffer = new StringBuffer(this.toBriefString());
   buffer.append(":\n  ");
   for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
     buffer.append('+');
     Object o = i.next();
     buffer.append(o == null ? "null" : o.toString());
     // buffer.append(i.next().toString());
   }
   for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
     buffer.append('-');
     buffer.append(i.next().toString());
   }
   return buffer.toString();
 }
Exemple #13
0
 /**
  * Utility method for building sets of exceptional types for a {@link Pair}.
  *
  * @param e The exceptional type to add to the set.
  * @param set The <code>Set</code> to which to add the types, or <code>null</code> if no <code>Set
  *     </code> has yet been allocated.
  * @return A <code>Set</code> containing the elements in <code>set</code> plus <code>e</code>.
  */
 private Set addExceptionToSet(RefLikeType e, Set set) {
   if (set == null) {
     set = new HashSet();
   }
   set.add(e);
   return set;
 }
Exemple #14
0
 protected void testSet(Set set, String name) {
   System.out.println("$test set " + name);
   Iterator setIt = set.iterator();
   while (setIt.hasNext()) {
     Object s = setIt.next();
     // JPegStmt s = (JPegStmt)setIt.next();
     // Tag tag = (Tag)s.getTags().get(0);
     System.out.println(s);
   }
 }
Exemple #15
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--------");
  }
Exemple #16
0
 protected void testSynch() {
   Iterator<List> it = synch.iterator();
   System.out.println("========test synch======");
   while (it.hasNext()) {
     // JPegStmt s = (JPegStmt)it.next();
     // Tag tag = (Tag)s.getTags().get(0);
     // System.out.println(tag+" "+s);
     System.out.println(it.next());
   }
   System.out.println("========end test synch======");
 }
Exemple #17
0
  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--------");
  }
Exemple #18
0
  /**
   * Indicates whether this ThrowableSet includes some exception that might be caught by a handler
   * argument of the type <code>catcher</code>.
   *
   * @param catcher type of the handler parameter to be tested.
   * @return <code>true</code> if this set contains an exception type that might be caught by <code>
   *     catcher</code>, false if it does not.
   */
  public boolean catchableAs(RefType catcher) {
    if (INSTRUMENTING) {
      Manager.v().catchableAsQueries++;
    }

    FastHierarchy h = Scene.v().getOrMakeFastHierarchy();

    if (exceptionsExcluded.size() > 0) {
      if (INSTRUMENTING) {
        Manager.v().catchableAsFromSearch++;
      }
      for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
        AnySubType exclusion = (AnySubType) i.next();
        if (h.canStoreType(catcher, exclusion.getBase())) {
          return false;
        }
      }
    }

    if (exceptionsIncluded.contains(catcher)) {
      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() == 0) {
          Manager.v().catchableAsFromMap++;
        } else {
          Manager.v().catchableAsFromSearch++;
        }
      }
      return true;
    } else {
      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() == 0) {
          Manager.v().catchableAsFromSearch++;
        }
      }
      for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
        RefLikeType thrownType = (RefLikeType) i.next();
        if (thrownType instanceof RefType) {
          if (thrownType == catcher) {
            // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.catchableAs(RefType): exceptions.contains() failed to match contained RefType "
                    + catcher);
          } else if (h.canStoreType(thrownType, catcher)) {
            return true;
          }
        } else {
          RefType thrownBase = ((AnySubType) thrownType).getBase();
          // At runtime, thrownType might be instantiated by any
          // of thrownBase's subtypes, so:
          if (h.canStoreType(thrownBase, catcher) || h.canStoreType(catcher, thrownBase)) {
            return true;
          }
        }
      }
      return false;
    }
  }
Exemple #19
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--------");
  }
Exemple #20
0
  /**
   * Utility method which prints the abbreviations of the elements in a passed {@link Set} of
   * exception types.
   *
   * @param s The exceptions to print.
   * @param connector The character to insert between exceptions.
   * @return An abbreviated representation of the exceptions.
   */
  private String toAbbreviatedString(Set s, char connector) {
    final String JAVA_LANG = "java.lang.";
    final int JAVA_LANG_LENGTH = JAVA_LANG.length();
    final String EXCEPTION = "Exception";
    final int EXCEPTION_LENGTH = EXCEPTION.length();

    Collection vmErrorThrowables = ThrowableSet.Manager.v().VM_ERRORS.exceptionsIncluded;
    boolean containsAllVmErrors = s.containsAll(vmErrorThrowables);
    StringBuffer buf = new StringBuffer();

    if (containsAllVmErrors) {
      buf.append(connector);
      buf.append("vmErrors");
    }

    for (Iterator it = sortedThrowableIterator(s); it.hasNext(); ) {
      RefLikeType reflikeType = (RefLikeType) it.next();
      RefType baseType = null;
      if (reflikeType instanceof RefType) {
        baseType = (RefType) reflikeType;
        if (vmErrorThrowables.contains(baseType) && containsAllVmErrors) {
          continue; // Already accounted for vmErrors.
        } else {
          buf.append(connector);
        }
      } else if (reflikeType instanceof AnySubType) {
        buf.append(connector);
        buf.append('(');
        baseType = ((AnySubType) reflikeType).getBase();
      }
      String typeName = baseType.toString();
      if (typeName.startsWith(JAVA_LANG)) {
        typeName = typeName.substring(JAVA_LANG_LENGTH);
      }
      if (typeName.length() > EXCEPTION_LENGTH && typeName.endsWith(EXCEPTION)) {
        typeName = typeName.substring(0, typeName.length() - EXCEPTION_LENGTH);
      }
      buf.append(typeName);
      if (reflikeType instanceof AnySubType) {
        buf.append(')');
      }
    }
    return buf.toString();
  }
Exemple #21
0
 /**
  * Returns a <code>ThrowableSet</code> which contains all the exceptions in <code>s</code> in
  * addition to those in this <code>ThrowableSet</code>.
  *
  * @param s set of exceptions to add to this set.
  * @return the union of this set with <code>s</code>
  * @throws ThrowableSet.AlreadyHasExclusionsException if this <code>ThrowableSet</code> or <code>s
  *     </code> is the result of a {@link #whichCatchableAs(RefType)} operation, so that it is not
  *     possible to represent the addition of <code>s</code> to this <code>ThrowableSet</code>.
  */
 public ThrowableSet add(ThrowableSet s) throws ThrowableSet.AlreadyHasExclusionsException {
   if (INSTRUMENTING) {
     Manager.v().addsOfSet++;
   }
   if (exceptionsExcluded.size() > 0 || s.exceptionsExcluded.size() > 0) {
     throw new AlreadyHasExclusionsException(
         "ThrowableSet.Add(ThrowableSet): attempt to add to ["
             + this.toString()
             + "] after removals recorded.");
   }
   ThrowableSet result = getMemoizedAdds(s);
   if (result == null) {
     if (INSTRUMENTING) {
       Manager.v().addsInclusionFromSearch++;
       Manager.v().addsExclusionWithoutSearch++;
     }
     result = this.add(s.exceptionsIncluded);
     memoizedAdds.put(s, result);
   } else if (INSTRUMENTING) {
     Manager.v().addsInclusionFromMemo++;
     Manager.v().addsExclusionWithoutSearch++;
   }
   return result;
 }
Exemple #22
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
  }
Exemple #23
0
  /**
   * Partitions the exceptions in this <code>ThrowableSet</code> into those which would be caught by
   * a handler with the passed <code>catch</code> parameter type and those which would not.
   *
   * @param catcher type of the handler parameter to be tested.
   * @return a pair of <code>ThrowableSet</code>s, one containing the types in this <code>
   *     ThrowableSet</code> which would be be caught as <code>catcher</code> and the other
   *     containing the types in this <code>ThrowableSet</code> which would not be caught as <code>
   *     catcher</code>.
   */
  public Pair whichCatchableAs(RefType catcher) {
    if (INSTRUMENTING) {
      Manager.v().removesOfAnySubType++;
    }

    FastHierarchy h = Scene.v().getOrMakeFastHierarchy();
    Set caughtIncluded = null;
    Set caughtExcluded = null;
    Set uncaughtIncluded = null;
    Set uncaughtExcluded = null;

    if (INSTRUMENTING) {
      Manager.v().removesFromSearch++;
    }

    for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
      AnySubType exclusion = (AnySubType) i.next();
      RefType exclusionBase = exclusion.getBase();
      if (h.canStoreType(catcher, exclusionBase)) {
        // Because the add() operations ban additions to sets
        // with exclusions, we can be sure no types in this are
        // caught by catcher.
        return new Pair(ThrowableSet.Manager.v().EMPTY, this);
      } else if (h.canStoreType(exclusionBase, catcher)) {
        // exclusion wouldn't be in exceptionsExcluded if one
        // of its supertypes were not in exceptionsIncluded,
        // so we know the next loop will add either that supertype
        // or catcher to caughtIncluded.  Thus:
        caughtExcluded = addExceptionToSet(exclusion, caughtExcluded);
      } else {
        uncaughtExcluded = addExceptionToSet(exclusion, uncaughtExcluded);
      }
    }

    for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
      RefLikeType inclusion = (RefLikeType) i.next();
      if (inclusion instanceof RefType) {
        if (h.canStoreType(inclusion, catcher)) {
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      } else {
        RefType base = ((AnySubType) inclusion).getBase();
        if (h.canStoreType(base, catcher)) {
          // All subtypes of base will be caught.  Any exclusions
          // will already have been copied to caughtExcluded by
          // the preceding loop.
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else if (h.canStoreType(catcher, base)) {
          // Some subtypes of base will be caught, and
          // we know that not all of those catchable subtypes
          // are among exceptionsExcluded, since in that case we
          // would already have returned from within the
          // preceding loop.  So, remove AnySubType(catcher)
          // from the uncaught types.
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
          uncaughtExcluded = addExceptionToSet(AnySubType.v(catcher), uncaughtExcluded);
          caughtIncluded = addExceptionToSet(AnySubType.v(catcher), caughtIncluded);
          // Any already excluded subtypes of inclusion
          // which are subtypes of catcher will have been
          // added to caughtExcluded by the previous loop.
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      }
    }
    ThrowableSet caughtSet = Manager.v().registerSetIfNew(caughtIncluded, caughtExcluded);
    ThrowableSet uncaughtSet = Manager.v().registerSetIfNew(uncaughtIncluded, uncaughtExcluded);
    return new Pair(caughtSet, uncaughtSet);
  }
Exemple #24
0
  /**
   * Returns a <code>ThrowableSet</code> which contains all the exceptions in <code>addedExceptions
   * </code> in addition to those in this <code>ThrowableSet</code>.
   *
   * @param addedExceptions a set of {@link RefLikeType} and {@link AnySubType} objects to be added
   *     to the types included in this <code>ThrowableSet</code>.
   * @return a set containing all the <code>addedExceptions</code> as well as the exceptions in this
   *     set.
   */
  private ThrowableSet add(Set addedExceptions) {
    Set resultSet = new HashSet(this.exceptionsIncluded);
    int changes = 0;
    FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();

    // This algorithm is O(n m), where n and m are the sizes of the
    // two sets, so hope that the sets are small.

    for (Iterator i = addedExceptions.iterator(); i.hasNext(); ) {
      RefLikeType newType = (RefLikeType) i.next();
      if (!resultSet.contains(newType)) {
        boolean addNewType = true;
        if (newType instanceof RefType) {
          for (Iterator j = resultSet.iterator(); j.hasNext(); ) {
            RefLikeType incumbentType = (RefLikeType) j.next();
            if (incumbentType instanceof RefType) {
              if (newType == incumbentType) {
                // assertion failure.
                throw new IllegalStateException(
                    "ThrowableSet.add(Set): resultSet.contains() failed to screen duplicate RefType "
                        + newType);
              }
            } else if (incumbentType instanceof AnySubType) {
              RefType incumbentBase = ((AnySubType) incumbentType).getBase();
              if (hierarchy.canStoreType(newType, incumbentBase)) {
                // No need to add this class.
                addNewType = false;
              }
            } else { // assertion failure.
              throw new IllegalStateException(
                  "ThrowableSet.add(Set): incumbent Set element "
                      + incumbentType
                      + " is neither a RefType nor an AnySubType.");
            }
          }
        } else if (newType instanceof AnySubType) {
          RefType newBase = ((AnySubType) newType).getBase();
          for (Iterator j = resultSet.iterator(); j.hasNext(); ) {
            RefLikeType incumbentType = (RefLikeType) j.next();
            if (incumbentType instanceof RefType) {
              RefType incumbentBase = (RefType) incumbentType;
              if (hierarchy.canStoreType(incumbentBase, newBase)) {
                j.remove();
                changes++;
              }
            } else if (incumbentType instanceof AnySubType) {
              RefType incumbentBase = ((AnySubType) incumbentType).getBase();
              if (newBase == incumbentBase) {
                // assertion failure.
                throw new IllegalStateException(
                    "ThrowableSet.add(Set): resultSet.contains() failed to screen duplicate AnySubType "
                        + newBase);
              } else if (hierarchy.canStoreType(incumbentBase, newBase)) {
                j.remove();
                changes++;
              } else if (hierarchy.canStoreType(newBase, incumbentBase)) {
                // No need to add this class.
                addNewType = false;
              }
            } else { // assertion failure.
              throw new IllegalStateException(
                  "ThrowableSet.add(Set): old Set element "
                      + incumbentType
                      + " is neither a RefType nor an AnySubType.");
            }
          }
        } else { // assertion failure.
          throw new IllegalArgumentException(
              "ThrowableSet.add(Set): new Set element "
                  + newType
                  + " is neither a RefType nor an AnySubType.");
        }
        if (addNewType) {
          changes++;
          resultSet.add(newType);
        }
      }
    }

    ThrowableSet result = null;
    if (changes > 0) {
      result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
    } else {
      result = this;
    }
    return result;
  }
Exemple #25
0
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> and all of its subclasses as
   * well as the exceptions in this set.
   *
   * <p><code>e</code> should be an instance of {@link AnySubType} if you know that the compile-time
   * type of the exception you are representing is <code>e</code>, but the exception may be
   * instantiated at run-time by a subclass of <code>e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * catch (IOException e) {
   *    throw e;
   * }
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(AnySubtype.v(Scene.v().getRefType("java.lang.Exception.IOException")))</code>
   * </pre>
   *
   * since the handler might rethrow any subclass of <code>IOException</code>.
   *
   * @param e represents a subtree of the exception class hierarchy to add to this set.
   * @return a set containing <code>e</code> and all its subclasses, as well as the exceptions
   *     represented by this set.
   * @throws ThrowableSet.AlreadyHasExclusionsException if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(AnySubType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfAnySubType++;
    }

    ThrowableSet result = getMemoizedAdds(e);
    if (result != null) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMemo++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return result;
    } else {
      FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();
      RefType newBase = e.getBase();

      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() != 0) {
          Manager.v().addsExclusionWithSearch++;
        } else {
          Manager.v().addsExclusionWithoutSearch++;
        }
      }
      for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
        RefType exclusionBase = ((AnySubType) i.next()).getBase();
        if (hierarchy.canStoreType(newBase, exclusionBase)
            || hierarchy.canStoreType(exclusionBase, newBase)) {
          if (INSTRUMENTING) {
            // To ensure that the subcategories total properly:
            Manager.v().addsInclusionInterrupted++;
          }
          throw new AlreadyHasExclusionsException(
              "ThrowableSet.add("
                  + e.toString()
                  + ") to the set [ "
                  + this.toString()
                  + "] where "
                  + exclusionBase.toString()
                  + " is excluded.");
        }
      }

      if (this.exceptionsIncluded.contains(e)) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMap++;
        }
        return this;

      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
        }

        int changes = 0;
        boolean addNewException = true;
        Set resultSet = new HashSet();

        for (Iterator i = this.exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof RefType) {
            if (hierarchy.canStoreType(incumbent, newBase)) {
              // Omit incumbent from result.
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else if (incumbent instanceof AnySubType) {
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            // We have to use the base types in these hierarchy calls
            // because we want to know if _all_ possible
            // types represented by e can be represented by
            // the incumbent, or vice versa.
            if (hierarchy.canStoreType(newBase, incumbentBase)) {
              addNewException = false;
              resultSet.add(incumbent);
            } else if (hierarchy.canStoreType(incumbentBase, newBase)) {
              // Omit incumbent from result;
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else { // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(AnySubType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        if (addNewException) {
          resultSet.add(e);
          changes++;
        }
        if (changes > 0) {
          result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        } else {
          result = this;
        }
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }
Exemple #26
0
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> in addition to the exceptions
   * in this <code>ThrowableSet</code>.
   *
   * <p>Add <code>e</code> as a {@link RefType} when you know that the run-time class of the
   * exception you are representing is necessarily <code>e</code> and cannot be a subclass of <code>
   * e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * throw new IOException("Permission denied");
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(Scene.v().getRefType("java.lang.Exception.IOException"))</code>
   * </pre>
   *
   * since the class of the exception is necessarily <code>IOException</code>.
   *
   * @param e the exception class
   * @return a set containing <code>e</code> as well as the exceptions in this set.
   * @throws {@link ThrowableSet.IllegalStateException} if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(RefType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfRefType++;
    }
    if (this.exceptionsIncluded.contains(e)) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMap++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return this;
    } else {
      ThrowableSet result = getMemoizedAdds(e);
      if (result != null) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMemo++;
          Manager.v().addsExclusionWithoutSearch++;
        }
        return result;
      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
          if (exceptionsExcluded.size() != 0) {
            Manager.v().addsExclusionWithSearch++;
          } else {
            Manager.v().addsExclusionWithoutSearch++;
          }
        }
        FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();

        for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
          RefType exclusionBase = ((AnySubType) i.next()).getBase();
          if (hierarchy.canStoreType(e, exclusionBase)) {
            throw new AlreadyHasExclusionsException(
                "ThrowableSet.add(RefType): adding"
                    + e.toString()
                    + " to the set [ "
                    + this.toString()
                    + "] where "
                    + exclusionBase.toString()
                    + " is excluded.");
          }
        }

        for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof AnySubType) {
            // Need to use incumbent.getBase() because
            // hierarchy.canStoreType() assumes that parent
            // is not an AnySubType.
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            if (hierarchy.canStoreType(e, incumbentBase)) {
              memoizedAdds.put(e, this);
              return this;
            }
          } else if (!(incumbent instanceof RefType)) {
            // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(RefType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        Set resultSet = new HashSet(this.exceptionsIncluded);
        resultSet.add(e);
        result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }
Exemple #27
0
    /**
     * Constructs a <code>ThrowableSet.Manager</code> for inclusion in Soot's global variable
     * manager, {@link G}.
     *
     * @param g guarantees that the constructor may only be called from {@link Singletons}.
     */
    public Manager(Singletons.Global g) {
      // First ensure the Exception classes are represented in Soot.

      // Runtime errors:
      RUNTIME_EXCEPTION = Scene.v().getRefType("java.lang.RuntimeException");
      ARITHMETIC_EXCEPTION = Scene.v().getRefType("java.lang.ArithmeticException");
      ARRAY_STORE_EXCEPTION = Scene.v().getRefType("java.lang.ArrayStoreException");
      CLASS_CAST_EXCEPTION = Scene.v().getRefType("java.lang.ClassCastException");
      ILLEGAL_MONITOR_STATE_EXCEPTION =
          Scene.v().getRefType("java.lang.IllegalMonitorStateException");
      INDEX_OUT_OF_BOUNDS_EXCEPTION = Scene.v().getRefType("java.lang.IndexOutOfBoundsException");
      ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION =
          Scene.v().getRefType("java.lang.ArrayIndexOutOfBoundsException");
      NEGATIVE_ARRAY_SIZE_EXCEPTION = Scene.v().getRefType("java.lang.NegativeArraySizeException");
      NULL_POINTER_EXCEPTION = Scene.v().getRefType("java.lang.NullPointerException");

      INSTANTIATION_ERROR = Scene.v().getRefType("java.lang.InstantiationError");

      EMPTY = registerSetIfNew(null, null);

      Set allThrowablesSet = new HashSet();
      allThrowablesSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Throwable")));
      ALL_THROWABLES = registerSetIfNew(allThrowablesSet, null);

      Set vmErrorSet = new HashSet();
      vmErrorSet.add(Scene.v().getRefType("java.lang.InternalError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.OutOfMemoryError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.StackOverflowError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.UnknownError"));

      // The Java library's deprecated Thread.stop(Throwable) method
      // would actually allow _any_ Throwable to be delivered
      // asynchronously, not just java.lang.ThreadDeath.
      vmErrorSet.add(Scene.v().getRefType("java.lang.ThreadDeath"));

      VM_ERRORS = registerSetIfNew(vmErrorSet, null);

      Set resolveClassErrorSet = new HashSet();
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.ClassCircularityError"));
      // We add AnySubType(ClassFormatError) so that we can
      // avoid adding its subclass,
      // UnsupportedClassVersionError, explicitly.  This is a
      // hack to allow Soot to analyze older class libraries
      // (UnsupportedClassVersionError was added in JDK 1.2).

      // TODO: The class "ClassFormatError" does not exist in TakaTuka so our best guess is that
      // 			commenting the following line out won't affect the analysis in any way. But this
      //			is a "fault point" to look at if any problems arise in the future.
      // resolveClassErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.ClassFormatError")));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IllegalAccessError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IncompatibleClassChangeError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.LinkageError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.NoClassDefFoundError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.VerifyError"));
      RESOLVE_CLASS_ERRORS = registerSetIfNew(resolveClassErrorSet, null);

      Set resolveFieldErrorSet = new HashSet(resolveClassErrorSet);
      resolveFieldErrorSet.add(Scene.v().getRefType("java.lang.NoSuchFieldError"));
      RESOLVE_FIELD_ERRORS = registerSetIfNew(resolveFieldErrorSet, null);

      Set resolveMethodErrorSet = new HashSet(resolveClassErrorSet);
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.AbstractMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.NoSuchMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.UnsatisfiedLinkError"));
      RESOLVE_METHOD_ERRORS = registerSetIfNew(resolveMethodErrorSet, null);

      // The static initializers of a newly loaded class might
      // throw any Error (if they threw an Exception---even a
      // RuntimeException---it would be replaced by an
      // ExceptionInInitializerError):
      //
      Set initializationErrorSet = new HashSet();
      initializationErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Error")));
      INITIALIZATION_ERRORS = registerSetIfNew(initializationErrorSet, null);
    }
Exemple #28
0
  /** Constructs a hierarchy from the current scene. */
  public Hierarchy() {
    this.sc = Scene.v();
    state = sc.getState();

    // Well, this used to be describable by 'Duh'.
    // Construct the subclasses hierarchy and the subinterfaces hierarchy.
    {
      Chain allClasses = sc.getClasses();

      classToSubclasses = new HashMap<SootClass, List<SootClass>>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToSubinterfaces =
          new HashMap<SootClass, List<SootClass>>(allClasses.size() * 2 + 1, 0.7f);

      classToDirSubclasses = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToDirSubinterfaces = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToDirImplementers = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);

      Iterator classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.isInterface()) {
          interfaceToDirSubinterfaces.put(c, new ArrayList());
          interfaceToDirImplementers.put(c, new ArrayList());
        } else classToDirSubclasses.put(c, new ArrayList());
      }

      classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.hasSuperclass()) {
          if (c.isInterface()) {
            Iterator subIt = c.getInterfaces().iterator();

            while (subIt.hasNext()) {
              SootClass i = (SootClass) subIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              List<SootClass> l = interfaceToDirSubinterfaces.get(i);
              l.add(c);
            }
          } else {
            List<SootClass> l = classToDirSubclasses.get(c.getSuperclass());
            l.add(c);

            Iterator subIt = c.getInterfaces().iterator();

            while (subIt.hasNext()) {
              SootClass i = (SootClass) subIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              l = interfaceToDirImplementers.get(i);
              l.add(c);
            }
          }
        }
      }

      // Fill the directImplementers lists with subclasses.
      {
        classesIt = allClasses.iterator();
        while (classesIt.hasNext()) {
          SootClass c = (SootClass) classesIt.next();
          if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
          if (c.isInterface()) {
            List<SootClass> imp = interfaceToDirImplementers.get(c);
            Set<SootClass> s = new ArraySet();

            Iterator<SootClass> impIt = imp.iterator();
            while (impIt.hasNext()) {
              SootClass c0 = impIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              s.addAll(getSubclassesOfIncluding(c0));
            }

            imp.clear();
            imp.addAll(s);
          }
        }
      }

      classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.isInterface()) {
          interfaceToDirSubinterfaces.put(
              c, Collections.unmodifiableList(interfaceToDirSubinterfaces.get(c)));
          interfaceToDirImplementers.put(
              c, Collections.unmodifiableList(interfaceToDirImplementers.get(c)));
        } else
          classToDirSubclasses.put(c, Collections.unmodifiableList(classToDirSubclasses.get(c)));
      }
    }
  }
Exemple #29
0
  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
    }
  }