@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); }
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()); } }
/** * 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); }
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 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); } }
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; }
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); } } } }
/** * 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); }
// 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 }
public void add(Object obj, FlowSet dest) { if (dest != this) copy(dest); dest.add(obj); }
public void copy(FlowSet dest) { List elements = toList(); Iterator it = elements.iterator(); dest.clear(); while (it.hasNext()) dest.add(it.next()); }