/** * Trigger a page of all the destinations. * * @param inbound The inbound Leg (audio from here goes to all destinations) * @param inboundRtp The destination to send RTP packets so the inbound caller can hear. * @param alertInfoKey The magic key needed for Polycom Auto-Answer * @return */ public boolean page(Leg inbound, InetSocketAddress inboundRtp, String alertInfoKey) { if (busy == false) { LOG.debug("PageGroup::page starting"); busy = true; this.inbound = inbound; this.inboundRtp = inboundRtp; // Spin up the RTP forker rtpFork.start(); try { // Get the originator for the Page. InboundLeg origLeg = (InboundLeg) inbound; String pageOriginatorAddress; pageOriginatorAddress = origLeg.getAddress(); // Answer the inbound call. inbound.acceptCall(rtpPort); // Start the timers if (maximumDuration > 0) { // Start the maximumDuration timer if it is greater than 0 Timers.addTimer( "maximum_duration", maximumDuration, this); // End this page after this many mS } Timers.addTimer("beep_start", 1000, this); // Start the beep after this much time // Place a call to each destination for (String destination : destinations) { // Compare the originator with the destination. Only place an outbound call // if they aren't the same. We don't make a call to the same destination that // is initiating the page. if (destination.compareToIgnoreCase(pageOriginatorAddress) != 0) { Leg outbound = placeCall(inbound.getDisplayName(), origLeg.getCallId(), destination, alertInfoKey); if (outbound != null) { // Keep track of them! outbounds.add(outbound); } } else { LOG.info( String.format("Skipping %s as it is the page originator.", pageOriginatorAddress)); } } return true; } catch (Throwable t) { LOG.warn("PageGroup::page", t); end(); } } LOG.debug("PageGroup::page failed"); return false; }
/** * Traverse the statements in the given body, looking for aggregation possibilities; that is, * given a def d and a use u, d has no other uses, u has no other defs, collapse d and u. * * <p>option: only-stack-locals; if this is true, only aggregate variables starting with $ */ protected void internalTransform(Body b, String phaseName, Map<String, String> options) { StmtBody body = (StmtBody) b; boolean onlyStackVars = PhaseOptions.getBoolean(options, "only-stack-locals"); int aggregateCount = 1; if (Options.v().time()) Timers.v().aggregationTimer.start(); boolean changed = false; Map<ValueBox, Zone> boxToZone = new HashMap<ValueBox, Zone>(body.getUnits().size() * 2 + 1, 0.7f); // Determine the zone of every box { Zonation zonation = new Zonation(body); for (Unit u : body.getUnits()) { Zone zone = zonation.getZoneOf(u); for (ValueBox box : u.getUseBoxes()) { boxToZone.put(box, zone); } for (ValueBox box : u.getDefBoxes()) { boxToZone.put(box, zone); } } } do { if (Options.v().verbose()) G.v() .out .println( "[" + body.getMethod().getName() + "] Aggregating iteration " + aggregateCount + "..."); // body.printTo(new java.io.PrintWriter(G.v().out, true)); changed = internalAggregate(body, boxToZone, onlyStackVars); aggregateCount++; } while (changed); if (Options.v().time()) Timers.v().aggregationTimer.end(); }
/** * Constructs a BriefUnitGraph given a Body instance. * * @param body The underlying body we want to make a graph for. */ public BriefUnitGraph(Body body) { super(body); int size = unitChain.size(); if (Options.v().time()) Timers.v().graphTimer.start(); unitToSuccs = new HashMap(size * 2 + 1, 0.7f); unitToPreds = new HashMap(size * 2 + 1, 0.7f); buildUnexceptionalEdges(unitToSuccs, unitToPreds); makeMappedListsUnmodifiable(unitToSuccs); makeMappedListsUnmodifiable(unitToPreds); buildHeadsAndTails(); if (Options.v().time()) Timers.v().graphTimer.end(); }
/** * End this page, by clearing up all timers, outbound calls, the inbound call, and the RTP forker. * * <p>synchronized so multiple calls are serialized. Only the first should be needed. */ public synchronized void end() { // Remove all timers associated with me Timers.removeTimer(this); // Hangup on all outbound calls. for (Leg outbound : outbounds) { try { outbound.destroyLeg(); } catch (Exception e) { LOG.error("PageGroup::end outbound", e); } } outbounds.removeAllElements(); // Stop the RTP processing. rtpFork.stop(); rtpFork.removeAllDestinations(); // Hangup on the inbound call if (inbound != null) { try { inbound.destroyLeg(); } catch (Exception e) { LOG.error("PageGroup::end inbound", e); } inbound = null; } busy = false; }
// This method is deprecated. Use soot.util.JasminOutputStream instead. public void writeXXXDeprecated(SootClass cl, String outputDir) { String outputDirWithSep = ""; if (!outputDir.equals("")) outputDirWithSep = outputDir + fileSeparator; try { File tempFile = new File(outputDirWithSep + cl.getName() + ".jasmin"); FileOutputStream streamOut = new FileOutputStream(tempFile); PrintWriter writerOut = new PrintWriter(new EscapedWriter(new OutputStreamWriter(streamOut))); if (cl.containsBafBody()) new soot.baf.JasminClass(cl).print(writerOut); else new soot.jimple.JasminClass(cl).print(writerOut); writerOut.close(); if (Options.v().time()) Timers.v().assembleJasminTimer.start(); // Invoke jasmin { String[] args; if (outputDir.equals("")) { args = new String[1]; args[0] = cl.getName() + ".jasmin"; } else { args = new String[3]; args[0] = "-d"; args[1] = outputDir; args[2] = outputDirWithSep + cl.getName() + ".jasmin"; } jasmin.Main.main(args); } tempFile.delete(); if (Options.v().time()) Timers.v().assembleJasminTimer.end(); } catch (IOException e) { throw new RuntimeException("Could not produce new classfile! (" + e + ")"); } }
public void onEnable() { final Plugin ccapi = Bukkit.getPluginManager().getPlugin("CodCraftAPI"); if (ccapi == null) { getServer().getPluginManager().disablePlugin(this); } this.api = (CCAPI) ccapi; getServer().getPluginManager().registerEvents(new GameListener(this), this); LoadSpawns(); LoadSpawns2(); timers = new Timers(this); timers.GunTimer(); }
/** * Computes the analysis given a UnitGraph computed from a method body. It is recommended that a * ExceptionalUnitGraph (or similar) be provided for correct results in the case of exceptional * control flow. * * @param g a graph on which to compute the analysis. * @see ExceptionalUnitGraph */ public SimpleLiveLocals(UnitGraph graph) { if (Options.v().time()) Timers.v().liveTimer.start(); if (Options.v().verbose()) G.v() .out .println( "[" + graph.getBody().getMethod().getName() + "] Constructing SimpleLiveLocals..."); SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph); if (Options.v().time()) Timers.v().livePostTimer.start(); // Build unitToLocals map { unitToLocalsAfter = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f); unitToLocalsBefore = new HashMap<Unit, List>(graph.size() * 2 + 1, 0.7f); Iterator unitIt = graph.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet set = (FlowSet) analysis.getFlowBefore(s); unitToLocalsBefore.put(s, Collections.unmodifiableList(set.toList())); set = (FlowSet) analysis.getFlowAfter(s); unitToLocalsAfter.put(s, Collections.unmodifiableList(set.toList())); } } if (Options.v().time()) Timers.v().livePostTimer.end(); if (Options.v().time()) Timers.v().liveTimer.end(); }
SimpleLiveLocalsAnalysis(UnitGraph g) { super(g); if (Options.v().time()) Timers.v().liveSetupTimer.start(); emptySet = new ArraySparseSet(); // Create kill sets. { unitToKillSet = new HashMap<Unit, FlowSet>(g.size() * 2 + 1, 0.7f); Iterator unitIt = g.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet killSet = emptySet.clone(); Iterator boxIt = s.getDefBoxes().iterator(); while (boxIt.hasNext()) { ValueBox box = (ValueBox) boxIt.next(); if (box.getValue() instanceof Local) killSet.add(box.getValue(), killSet); } unitToKillSet.put(s, killSet); } } // Create generate sets { unitToGenerateSet = new HashMap<Unit, FlowSet>(g.size() * 2 + 1, 0.7f); Iterator unitIt = g.iterator(); while (unitIt.hasNext()) { Unit s = (Unit) unitIt.next(); FlowSet genSet = emptySet.clone(); Iterator boxIt = s.getUseBoxes().iterator(); while (boxIt.hasNext()) { ValueBox box = (ValueBox) boxIt.next(); if (box.getValue() instanceof Local) genSet.add(box.getValue(), genSet); } unitToGenerateSet.put(s, genSet); } } if (Options.v().time()) Timers.v().liveSetupTimer.end(); if (Options.v().time()) Timers.v().liveAnalysisTimer.start(); doAnalysis(); if (Options.v().time()) Timers.v().liveAnalysisTimer.end(); }
public static void main(String args[]) { Timers timer = new Timers(); try { // Get the data set path. String referenceFile = Utils.getOption('r', args); String queryFile = Utils.getOption('q', args); if (referenceFile.length() == 0) throw new IllegalArgumentException( "Required option: File containing" + "the reference dataset."); // Load input dataset. DataSource source = new DataSource(referenceFile); Instances referenceData = source.getDataSet(); Instances queryData = null; if (queryFile.length() != 0) { source = new DataSource(queryFile); queryData = source.getDataSet(); } timer.StartTimer("total_time"); // Get all the parameters. String leafSize = Utils.getOption('l', args); String neighbors = Utils.getOption('k', args); // Validate options. int k = 0; if (neighbors.length() == 0) { throw new IllegalArgumentException( "Required option: Number of " + "furthest neighbors to find."); } else { k = Integer.parseInt(neighbors); if (k < 1 || k > referenceData.numInstances()) throw new IllegalArgumentException("[Fatal] Invalid k"); } int l = 20; if (leafSize.length() != 0) l = Integer.parseInt(leafSize); // Create KDTree. KDTree tree = new KDTree(); tree.setMaxInstInLeaf(l); tree.setInstances(referenceData); // Perform All K-Nearest-Neighbors. if (queryFile.length() != 0) { for (int i = 0; i < queryData.numInstances(); i++) { Instances out = tree.kNearestNeighbours(queryData.instance(i), k); } } else { for (int i = 0; i < referenceData.numInstances(); i++) { Instances out = tree.kNearestNeighbours(referenceData.instance(i), k); } } timer.StopTimer("total_time"); timer.PrintTimer("total_time"); } catch (IOException e) { System.err.println(USAGE); } catch (Exception e) { e.printStackTrace(); } }
protected void doAnalysis() { LinkedList<Object> changedUnits = new LinkedList<Object>(); HashSet<Object> changedUnitsSet = new HashSet<Object>(); int numNodes = graph.size(); int numComputations = 0; // Set initial values and nodes to visit. createWorkList(changedUnits, changedUnitsSet); // testWorkList(changedUnits); // Set initial values for entry points { Iterator it = graph.getHeads().iterator(); while (it.hasNext()) { Object s = it.next(); // unitToBeforeFlow.put(s, entryInitialFlow()); nodes.add(s); valueBefore.add(entryInitialFlow()); } } // Perform fixed point flow analysis { Object previousAfterFlow = newInitialFlow(); while (!changedUnits.isEmpty()) { Object beforeFlow; Object afterFlow; Object s = changedUnits.removeFirst(); Tag tag = (Tag) ((JPegStmt) s).getTags().get(0); // System.out.println("===unit is: "+tag+" "+s); changedUnitsSet.remove(s); // copy(unitToAfterFlow.get(s), previousAfterFlow); // add for debug april 6 int pos = nodes.indexOf(s); copy(valueAfter.elementAt(pos), previousAfterFlow); // end add for debug april // Compute and store beforeFlow { List preds = graph.getPredsOf(s); // beforeFlow = unitToBeforeFlow.get(s); beforeFlow = valueBefore.elementAt(pos); if (preds.size() == 1) { // copy(unitToAfterFlow.get(preds.get(0)), beforeFlow); copy(valueAfter.elementAt(nodes.indexOf(preds.get(0))), beforeFlow); } else if (preds.size() != 0) { Iterator predIt = preds.iterator(); Object obj = predIt.next(); // copy(unitToAfterFlow.get(obj), beforeFlow); copy(valueAfter.elementAt(nodes.indexOf(obj)), beforeFlow); while (predIt.hasNext()) { JPegStmt stmt = (JPegStmt) predIt.next(); if (stmt.equals(obj)) { // System.out.println("!!!same object!!!"); continue; } Tag tag1 = (Tag) stmt.getTags().get(0); // System.out.println("pred: "+tag1+" "+stmt); // Object otherBranchFlow = unitToAfterFlow.get(stmt); if (nodes.indexOf(stmt) >= 0) // RLH { Object otherBranchFlow = valueAfter.elementAt(nodes.indexOf(stmt)); merge(beforeFlow, otherBranchFlow, beforeFlow); } } } } // Compute afterFlow and store it. { // afterFlow = unitToAfterFlow.get(s); afterFlow = valueAfter.elementAt(nodes.indexOf(s)); flowThrough(beforeFlow, s, afterFlow); // unitToAfterFlow.put(s, afterFlow); valueAfter.set(nodes.indexOf(s), afterFlow); // System.out.println("update afterFlow nodes: "+s); // System.out.println("afterFlow: "+afterFlow); // ((MonitorSet)unitToAfterFlow.get(s)).test(); numComputations++; } // Update queue appropriately if (!afterFlow.equals(previousAfterFlow)) { Iterator succIt = graph.getSuccsOf(s).iterator(); while (succIt.hasNext()) { Object succ = succIt.next(); if (!changedUnitsSet.contains(succ)) { changedUnits.addLast(succ); changedUnitsSet.add(succ); /*if (succ instanceof JPegStmt){ Tag tag1 = (Tag)((JPegStmt)succ).getTags().get(0); System.out.println("add to worklist: "+tag1+" "+succ); } else System.out.println("add to worklist: "+succ); */ } } } } } // G.v().out.println(graph.getBody().getMethod().getSignature() + " numNodes: " + numNodes + // " numComputations: " + numComputations + " avg: " + Main.truncatedOf((double) // numComputations / numNodes, 2)); Timers.v().totalFlowNodes += numNodes; Timers.v().totalFlowComputations += numComputations; }