protected void computeEdgeAndThreadNo() { Iterator it = iterator(); int numberOfEdge = 0; while (it.hasNext()) { List succList = (List) getSuccsOf(it.next()); numberOfEdge = numberOfEdge + succList.size(); } numberOfEdge = numberOfEdge + startToThread.size(); System.err.println("**number of edges: " + numberOfEdge); System.err.println("**number of threads: " + (startToThread.size() + 1)); /* Set keySet = startToThread.keySet(); Iterator keyIt = keySet.iterator(); while (keyIt.hasNext()){ List list = (List)startToThread.get(keyIt.next()); System.out.println("********start thread:"); Iterator itit = list.iterator(); while (itit.hasNext()){ System.out.println(it.next()); } } */ }
protected int processModifiers(List l) { int modifier = 0; Iterator it = l.iterator(); while (it.hasNext()) { Object t = it.next(); if (t instanceof AAbstractModifier) modifier |= Modifier.ABSTRACT; else if (t instanceof AFinalModifier) modifier |= Modifier.FINAL; else if (t instanceof ANativeModifier) modifier |= Modifier.NATIVE; else if (t instanceof APublicModifier) modifier |= Modifier.PUBLIC; else if (t instanceof AProtectedModifier) modifier |= Modifier.PROTECTED; else if (t instanceof APrivateModifier) modifier |= Modifier.PRIVATE; else if (t instanceof AStaticModifier) modifier |= Modifier.STATIC; else if (t instanceof ASynchronizedModifier) modifier |= Modifier.SYNCHRONIZED; else if (t instanceof ATransientModifier) modifier |= Modifier.TRANSIENT; else if (t instanceof AVolatileModifier) modifier |= Modifier.VOLATILE; else if (t instanceof AEnumModifier) modifier |= Modifier.ENUM; else if (t instanceof AAnnotationModifier) modifier |= Modifier.ANNOTATION; else throw new RuntimeException( "Impossible: modifier unknown - Have you added a new modifier and not updated this file?"); } return modifier; }
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"); } */ } }
private void insertAfter(JPegStmt node, JPegStmt after) { // System.out.println("node: "+node); // System.out.println("after: "+after); // System.out.println("succs of node: "+getSuccsOf(node)); // this must be done first because the succs of node will be chanaged lately List succOfAfter = new ArrayList(); succOfAfter.addAll(getSuccsOf(node)); unitToSuccs.put(after, succOfAfter); Iterator succsIt = getSuccsOf(node).iterator(); while (succsIt.hasNext()) { Object succ = succsIt.next(); List pred = getPredsOf(succ); pred.remove(node); pred.add(after); } List succOfNode = new ArrayList(); succOfNode.add(after); unitToSuccs.put(node, succOfNode); List predOfAfter = new ArrayList(); predOfAfter.add(node); unitToPreds.put(after, predOfAfter); // buildPredecessor(Chain pegChain); }
/** * Given an abstract dispatch to an object of type c and a method m, gives a list of possible * receiver methods. */ public List resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Iterator<SootClass> classesIt = null; if (c.isInterface()) { classesIt = getImplementersOf(c).iterator(); HashSet<SootClass> classes = new HashSet<SootClass>(); while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next())); classesIt = classes.iterator(); } else classesIt = getSubclassesOfIncluding(c).iterator(); ArraySet s = new ArraySet(); while (classesIt.hasNext()) { SootClass cl = classesIt.next(); if (Modifier.isAbstract(cl.getModifiers())) continue; s.add(resolveConcreteDispatch(cl, m)); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
/** * 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; }
/** * Utility method used in the construction of {@link UnitGraph}s, to be called only after the * unitToPreds and unitToSuccs maps have been built. * * <p><code>UnitGraph</code> provides an implementation of <code>buildHeadsAndTails()</code> which * defines the graph's set of heads to include the first {@link Unit} in the graph's body, * together with any other <tt>Unit</tt> which has no predecessors. It defines the graph's set of * tails to include all <tt>Unit</tt>s with no successors. Subclasses of <code>UnitGraph</code> * may override this method to change the criteria for classifying a node as a head or tail. */ protected void buildHeadsAndTails() { List tailList = new ArrayList(); List headList = new ArrayList(); for (Iterator unitIt = unitChain.iterator(); unitIt.hasNext(); ) { Unit s = (Unit) unitIt.next(); List succs = (List) unitToSuccs.get(s); if (succs.size() == 0) { tailList.add(s); } List preds = (List) unitToPreds.get(s); if (preds.size() == 0) { headList.add(s); } } // Add the first Unit, even if it is the target of // a branch. Unit entryPoint = (Unit) unitChain.getFirst(); if (!headList.contains(entryPoint)) { headList.add(entryPoint); } tails = Collections.unmodifiableList(tailList); heads = Collections.unmodifiableList(headList); }
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 void go() { Iterator methods = cg.sourceMethods(); while (methods.hasNext()) { SootMethod m = (SootMethod) methods.next(); dfsVisit(m); } }
protected void testList(List list) { // System.out.println("test list"); Iterator listIt = list.iterator(); while (listIt.hasNext()) { System.out.println(listIt.next()); } }
public void convertToBaf(JimpleToBafContext context, List<Unit> out) { Unit u = Baf.v().newLoadInst(getType(), context.getBafLocalOfJimpleLocal(this)); out.add(u); Iterator it = context.getCurrentUnit().getTags().iterator(); while (it.hasNext()) { u.addTag((Tag) it.next()); } }
public void convertToBaf(JimpleToBafContext context, List out) { Unit u = Baf.v().newStaticGetInst(fieldRef); out.add(u); Iterator it = context.getCurrentUnit().getTags().iterator(); while (it.hasNext()) { u.addTag((Tag) it.next()); } }
// helper function protected void testIterator() { System.out.println("********begin test iterator*******"); Iterator testIt = iterator(); while (testIt.hasNext()) { System.out.println(testIt.next()); } System.out.println("********end test iterator*******"); System.out.println("=======size is: " + size()); }
private void dfsVisit(SootMethod m) { if (visited.contains(m)) return; visited.add(m); Iterator targets = new Targets(cg.edgesOutOf(m)); while (targets.hasNext()) { SootMethod target = (SootMethod) targets.next(); dfsVisit(target); } order.add(m); }
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); } }
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; } } } } }
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======"); }
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--------"); }
public String toString() { Iterator it = unitChain.iterator(); StringBuffer buf = new StringBuffer(); while (it.hasNext()) { Unit u = (Unit) it.next(); buf.append("// preds: " + getPredsOf(u) + "\n"); buf.append(u.toString() + '\n'); buf.append("// succs " + getSuccsOf(u) + "\n"); } return buf.toString(); }
/** * Utility method that replaces the values of a {@link Map}, which must be instances of {@link * List}, with unmodifiable equivalents. * * @param map The map whose values are to be made unmodifiable. */ protected static void makeMappedListsUnmodifiable(Map map) { for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); List value = (List) entry.getValue(); if (value.size() == 0) { entry.setValue(Collections.EMPTY_LIST); } else { entry.setValue(Collections.unmodifiableList(value)); } } }
/** Returns a list of possible targets for the given method and set of receiver types. */ public List resolveAbstractDispatch(List classes, SootMethod m) { m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); ArraySet s = new ArraySet(); Iterator classesIt = classes.iterator(); while (classesIt.hasNext()) s.addAll(resolveAbstractDispatch((SootClass) classesIt.next(), m)); List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
private static List<Unit> searchIfStmts(Body b) { List<Unit> searchResult = new ArrayList<Unit>(); PatchingChain<Unit> statements = b.getUnits(); Iterator<Unit> unitIt = statements.iterator(); // iterate through the Units of the body while (unitIt.hasNext()) { Unit tempUnit = unitIt.next(); // if the unit is a "if statement" if (tempUnit instanceof soot.jimple.internal.JIfStmt) searchResult.add(tempUnit); } return searchResult; }
public void convertToBaf(JimpleToBafContext context, List<Unit> out) { ((ConvertToBaf) getOp()).convertToBaf(context, out); Unit u; out.add(u = Baf.v().newThrowInst()); Unit currentUnit = this; Iterator it = currentUnit.getTags().iterator(); while (it.hasNext()) { u.addTag((Tag) it.next()); } }
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); } }
public void outADeclaration(ADeclaration node) { List localNameList = (List) mProductions.removeLast(); Type type = (Type) mProductions.removeLast(); Iterator it = localNameList.iterator(); List localList = new ArrayList(); while (it.hasNext()) { Local l = Jimple.v().newLocal((String) it.next(), type); mLocals.put(l.getName(), l); localList.add(l); } mProductions.addLast(localList); }
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--------"); }
// Declared in AnonymousClasses.jrag at line 52 private AnonymousDecl rewriteRule0() { { setModifiers(new Modifiers(new List().add(new Modifier("final")))); ConstructorDecl constructor = new ConstructorDecl(); addBodyDecl(constructor); constructor.setModifiers((Modifiers) constructorDecl().getModifiers().fullCopy()); String name = "Anonymous" + nextAnonymousIndex(); setID(name); constructor.setID(name); List parameterList = new List(); for (int i = 0; i < constructorDecl().getNumParameter(); i++) { parameterList.add( new ParameterDeclaration( constructorDecl().getParameter(i).type().createBoundAccess(), constructorDecl().getParameter(i).name())); } constructor.setParameterList(parameterList); List argList = new List(); for (int i = 0; i < constructor.getNumParameter(); i++) argList.add(new VarAccess(constructor.getParameter(i).name())); constructor.setConstructorInvocation( new ExprStmt(new SuperConstructorAccess("super", argList))); constructor.setBlock(new Block()); HashSet set = new HashSet(); for (int i = 0; i < getNumBodyDecl(); i++) { if (getBodyDecl(i) instanceof InstanceInitializer) { InstanceInitializer init = (InstanceInitializer) getBodyDecl(i); set.addAll(init.exceptions()); } else if (getBodyDecl(i) instanceof FieldDeclaration) { FieldDeclaration f = (FieldDeclaration) getBodyDecl(i); if (f.isInstanceVariable()) { set.addAll(f.exceptions()); } } } List exceptionList = new List(); for (Iterator iter = set.iterator(); iter.hasNext(); ) { TypeDecl exceptionType = (TypeDecl) iter.next(); if (exceptionType.isNull()) exceptionType = typeNullPointerException(); exceptionList.add(exceptionType.createQualifiedAccess()); } constructor.setExceptionList(exceptionList); return this; } }
/** * Report the counts collected by instrumentation (for now, at least, there is no need to * provide access to the individual values as numbers). * * @return a string listing the counts. */ public String reportInstrumentation() { int setCount = 0; for (Iterator it = sizeToSets.values().iterator(); it.hasNext(); ) { List sizeList = (List) it.next(); setCount += sizeList.size(); } if (setCount != registeredSets) { throw new IllegalStateException( "ThrowableSet.reportInstrumentation() assertion failure: registeredSets != list count"); } StringBuffer buf = new StringBuffer("registeredSets: ") .append(setCount) .append("\naddsOfRefType: ") .append(addsOfRefType) .append("\naddsOfAnySubType: ") .append(addsOfAnySubType) .append("\naddsOfSet: ") .append(addsOfSet) .append("\naddsInclusionFromMap: ") .append(addsInclusionFromMap) .append("\naddsInclusionFromMemo: ") .append(addsInclusionFromMemo) .append("\naddsInclusionFromSearch: ") .append(addsInclusionFromSearch) .append("\naddsInclusionInterrupted: ") .append(addsInclusionInterrupted) .append("\naddsExclusionWithoutSearch: ") .append(addsExclusionWithoutSearch) .append("\naddsExclusionWithSearch: ") .append(addsExclusionWithSearch) .append("\nremovesOfAnySubType: ") .append(removesOfAnySubType) .append("\nremovesFromMap: ") .append(removesFromMap) .append("\nremovesFromMemo: ") .append(removesFromMemo) .append("\nremovesFromSearch: ") .append(removesFromSearch) .append("\nregistrationCalls: ") .append(registrationCalls) .append("\ncatchableAsQueries: ") .append(catchableAsQueries) .append("\ncatchableAsFromMap: ") .append(catchableAsFromMap) .append("\ncatchableAsFromSearch: ") .append(catchableAsFromSearch) .append('\n'); return buf.toString(); }
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--------"); }
/* throws_clause = throws class_name_list; */ public void outAThrowsClause(AThrowsClause node) { List l = (List) mProductions.removeLast(); Iterator it = l.iterator(); List exceptionClasses = new ArrayList(l.size()); while (it.hasNext()) { String className = (String) it.next(); exceptionClasses.add(mResolver.makeClassRef(className)); } mProductions.addLast(exceptionClasses); }