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 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"); } */ } }
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--------"); }
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); }
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()); } }
// 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()); }
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()); } }
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); } }
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 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); }
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--------"); }
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 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()); } }
private void createWorkList( LinkedList<Object> changedUnits, HashSet<Object> changedUnitsSet, PegChain chain) { // Depth first scan Iterator it = chain.getHeads().iterator(); Set<Object> gray = new HashSet<Object>(); while (it.hasNext()) { Object head = it.next(); if (!gray.contains(head)) { visitNode(gray, head, changedUnits, changedUnitsSet); } } }
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--------"); }
public void convertToBaf(JimpleToBafContext context, List out) { for (int i = 0; i < argBoxes.size(); i++) { ((ConvertToBaf) (getArg(i))).convertToBaf(context, out); } Unit u; out.add(u = Baf.v().newStaticInvokeInst(methodRef)); Unit currentUnit = context.getCurrentUnit(); Iterator it = currentUnit.getTags().iterator(); while (it.hasNext()) { u.addTag((Tag) it.next()); } }
public String toString() { Iterator it = iterator(); StringBuffer buf = new StringBuffer(); while (it.hasNext()) { JPegStmt u = (JPegStmt) it.next(); buf.append("u is: " + u + "\n"); List l = new ArrayList(); l.addAll(getPredsOf(u)); buf.append("preds: " + l + "\n"); // buf.append(u.toString() + '\n'); l = new ArrayList(); l.addAll(getSuccsOf(u)); buf.append("succs: " + l + "\n"); } return buf.toString(); }
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; }
public void internalTransform(String phaseName, Map opts) { Iterator it = Scene.v().getApplicationClasses().iterator(); while (it.hasNext()) { SootClass sc = (SootClass) it.next(); // make map of first line to each method HashMap<Integer, SootMethod> lineToMeth = new HashMap<Integer, SootMethod>(); Iterator methIt = sc.getMethods().iterator(); while (methIt.hasNext()) { SootMethod meth = (SootMethod) methIt.next(); if (!meth.isConcrete()) continue; Body body = meth.retrieveActiveBody(); Stmt s = (Stmt) body.getUnits().getFirst(); while (s instanceof IdentityStmt) { s = (Stmt) body.getUnits().getSuccOf(s); } if (s.hasTag("LineNumberTag")) { LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag"); lineToMeth.put(new Integer(tag.getLineNumber()), meth); } } Iterator methIt2 = sc.getMethods().iterator(); while (methIt2.hasNext()) { SootMethod meth = (SootMethod) methIt2.next(); if (!meth.isConcrete()) continue; Body body = meth.retrieveActiveBody(); Stmt s = (Stmt) body.getUnits().getFirst(); while (s instanceof IdentityStmt) { s = (Stmt) body.getUnits().getSuccOf(s); } if (s.hasTag("LineNumberTag")) { LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag"); int line_num = tag.getLineNumber() - 1; // already taken if (lineToMeth.containsKey(new Integer(line_num))) { meth.addTag(new LineNumberTag(line_num + 1)); } // still available - so use it for this meth else { meth.addTag(new LineNumberTag(line_num)); } } } } }
private void visitNode( Set<Object> gray, Object obj, LinkedList<Object> changedUnits, HashSet<Object> changedUnitsSet) { gray.add(obj); changedUnits.addLast(obj); changedUnitsSet.add(obj); nodes.add(obj); valueBefore.add(newInitialFlow()); valueAfter.add(newInitialFlow()); Iterator succsIt = graph.getSuccsOf(obj).iterator(); if (g.getSuccsOf(obj).size() > 0) { while (succsIt.hasNext()) { Object succ = succsIt.next(); if (!gray.contains(succ)) { visitNode(gray, succ, changedUnits, changedUnitsSet); } } } }
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); } } } }
private void insertBefore(JPegStmt node, JPegStmt enter) { // build preds of before List predOfBefore = new ArrayList(); predOfBefore.addAll(getPredsOf(node)); unitToPreds.put(enter, predOfBefore); // System.out.println("put into unitToPreds enter: "+enter); // System.out.println("put into unitToPreds value: "+predOfBefore); Iterator predsIt = getPredsOf(node).iterator(); // build succs of former preds of node while (predsIt.hasNext()) { Object pred = predsIt.next(); List succ = getSuccsOf(pred); succ.remove(node); succ.add(enter); // System.out.println("in unitToPred pred: "+pred); // System.out.println("in unitToPred value is: "+succ); } List succOfBefore = new ArrayList(); succOfBefore.add(node); unitToSuccs.put(enter, succOfBefore); // System.out.println("put into unitToSuccs enter: "+enter); // System.out.println("put into unitToSuccs value: "+succOfBefore); List predOfNode = new ArrayList(); predOfNode.add(enter); unitToPreds.put(node, predOfNode); // System.out.println("put into unitToPreds enter: "+node); // System.out.println("put into unitToPreds value: "+predOfNode); // buildPreds(); }
/** Prints the given <code>JimpleBody</code> to the specified <code>PrintWriter</code>. */ private void printLocalsInBody(Body body, UnitPrinter up) { // Print out local variables { Map typeToLocals = new DeterministicHashMap(body.getLocalCount() * 2 + 1, 0.7f); // Collect locals { Iterator localIt = body.getLocals().iterator(); while (localIt.hasNext()) { Local local = (Local) localIt.next(); List localList; Type t = local.getType(); if (typeToLocals.containsKey(t)) localList = (List) typeToLocals.get(t); else { localList = new ArrayList(); typeToLocals.put(t, localList); } localList.add(local); } } // Print locals { Iterator typeIt = typeToLocals.keySet().iterator(); while (typeIt.hasNext()) { Type type = (Type) typeIt.next(); List localList = (List) typeToLocals.get(type); Object[] locals = localList.toArray(); up.type(type); up.literal(" "); for (int k = 0; k < locals.length; k++) { if (k != 0) up.literal(", "); up.local((Local) locals[k]); } up.literal(";"); up.newline(); } } if (!typeToLocals.isEmpty()) { up.newline(); } } }
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 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); } } }
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 createWorkList(LinkedList<Object> changedUnits, HashSet<Object> changedUnitsSet) { createWorkList(changedUnits, changedUnitsSet, g.getMainPegChain()); Set maps = g.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()) { PegChain chain = (PegChain) it.next(); createWorkList(changedUnits, changedUnitsSet, chain); } } }
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--------"); }