protected void buildSuccsForInlining(JPegStmt stmt, Chain chain, PegGraph inlinee) { // System.out.println("entering buildSuccsForInlining..."); Tag tag = (Tag) stmt.getTags().get(0); // System.out.println("stmt is: "+tag+" "+stmt); /*connect heads of inlinee with the preds of invokeStmt and * delete stmt from the succs list from the preds */ Iterator predIt = getPredsOf(stmt).iterator(); // System.out.println("preds list: "+getPredsOf(stmt)); // System.out.println("preds size: "+getPredsOf(stmt).size()); Iterator headsIt = inlinee.getHeads().iterator(); { // System.out.println("heads: "+inlinee.getHeads()); while (predIt.hasNext()) { JPegStmt pred = (JPegStmt) predIt.next(); // System.out.println("pred: "+pred); List succList = (List) getSuccsOf(pred); // System.out.println("succList of pred: "+succList); int pos = succList.indexOf(stmt); // System.out.println("remove : "+stmt + " from succList: \n"+succList+ "\n of pred" ); // remove invokeStmt succList.remove(pos); while (headsIt.hasNext()) { succList.add(headsIt.next()); } unitToSuccs.put(pred, succList); } { while (headsIt.hasNext()) { Object head = headsIt.next(); List predsOfHeads = new ArrayList(); predsOfHeads.addAll(getPredsOf(head)); unitToPreds.put(head, predsOfHeads); } } /* { predIt = getPredsOf(stmt).iterator(); while (predIt.hasNext()){ JPegStmt s = (JPegStmt)predIt.next(); if (unitToSuccs.containsKey(s)){ Iterator succIt = ((List) unitToSuccs.get(s)).iterator(); while(succIt.hasNext()){ //Object successor = succIt.next(); JPegStmt successor = (JPegStmt)succIt.next(); List predList = (List) unitToPreds.get(successor); if (predList != null) { try { predList.add(s); } catch(NullPointerException e) { System.out.println(s + "successor: " + successor); throw e; } } } } } }*/ } /*connect tails of inlinee with the succ of invokeStmt and * delete stmt from the */ Iterator tailsIt = inlinee.getTails().iterator(); { // System.out.println("tails: "+inlinee.getTails()); while (tailsIt.hasNext()) { Iterator succIt = getSuccsOf(stmt).iterator(); JPegStmt tail = (JPegStmt) tailsIt.next(); List succList = null; if (unitToSuccs.containsKey(tail)) { // System.out.println("error: unitToSucc containsKey: "+tail); succList = (List) getSuccsOf(tail); // System.out.println("succList: "+succList); } else { succList = new ArrayList(); } while (succIt.hasNext()) { JPegStmt succ = (JPegStmt) succIt.next(); succList.add(succ); // System.out.println("succ: "+succ); // remove stmt from the preds list of the succs of itself. List predListOfSucc = getPredsOf(succ); if (predListOfSucc == null) { System.err.println("Error: predListOfSucc is null!"); System.exit(1); } else { if (predListOfSucc.size() != 0) { int pos = predListOfSucc.indexOf(stmt); if (pos > 0 || pos == 0) { // System.out.println("remove stmt: "+stmt+" from the preds list"+predListOfSucc+" // of the succ"); predListOfSucc.remove(pos); } // System.out.println("remove(from PRED): "); } } unitToPreds.put(succ, predListOfSucc); } unitToSuccs.put(tail, succList); // System.out.println("put: "+tail); // System.out.println("succList: "+succList+ "into unitToSucc"); } } // add Nov 1 { tailsIt = inlinee.getTails().iterator(); while (tailsIt.hasNext()) { JPegStmt s = (JPegStmt) tailsIt.next(); if (unitToSuccs.containsKey(s)) { Iterator succIt = unitToSuccs.get(s).iterator(); while (succIt.hasNext()) { // Object successor = succIt.next(); JPegStmt successor = (JPegStmt) succIt.next(); List<JPegStmt> predList = unitToPreds.get(successor); if (predList != null && !predList.contains(s)) { try { predList.add(s); /* Tag tag = (Tag)successor.getTags().get(0); System.out.println("add "+s+" to predlist of "+tag+" "+successor); */ } catch (NullPointerException e) { System.out.println(s + "successor: " + successor); throw e; } } } } } } // end add Nov 1 // System.out.println("stmt: "+stmt); // remove stmt from allNodes and mainPegChain // System.out.println("mainPegChain contains stmt: "+mainPegChain.contains(stmt)); // testPegChain(); if (!allNodes.contains(stmt)) { System.err.println("fail to find begin node in allNodes!"); System.exit(1); } else { allNodes.remove(stmt); // System.out.println("remove from allNode: "+stmt); } if (!chain.contains(stmt)) { System.err.println("Error! Chain does not contains stmt (extending point)!"); System.exit(1); } else { if (!chain.remove(stmt)) { System.err.println("fail to remove invoke stmt in from Chain!"); System.exit(1); } } /* if (!mainPegChain.contains(stmt)){ boolean find = false; //System.out.println("main chain does not contain AFTER"); 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(); if (chain.contains(stmt)) { find = true; if (!chain.remove(stmt)){ System.err.println("fail to remove begin node in from mainPegChain!"); System.exit(1); } break; } } if (find == false){ System.err.println("fail to find stmt: "+stmt+" in chains!"); System.exit(1); } } //this.toString(); } else{ if (!mainPegChain.remove(stmt)) { System.err.println("fail to remove begin node in from mainPegChain!"); System.exit(1); } else{ // System.out.println("remove(from mainchain): "+stmt); } } */ // remove stmt from unitToSuccs and unitToPreds if (unitToSuccs.containsKey(stmt)) { unitToSuccs.remove(stmt); } if (unitToPreds.containsKey(stmt)) { unitToPreds.remove(stmt); } }
// 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 }