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; }
// 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 }