@Override public DominatorsAnalysis analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException { CFG cfg = getCFG(analysisCache, descriptor); DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor); DominatorsAnalysis analysis = new DominatorsAnalysis(cfg, dfs, true); Dataflow<java.util.BitSet, DominatorsAnalysis> dataflow = new Dataflow<>(cfg, analysis); dataflow.execute(); return analysis; } }
private static void debug(BasicBlock bb, String msg) { System.out.print("Dataflow (block " + blockId(bb) + "): " + msg); }
@Override public void inspectResult(ClassContext classContext, MethodGen methodGen, CFG cfg, Dataflow<ResourceValueFrame, ResourceValueAnalysis<Stream>> dataflow, Stream stream) { if (DEBUG) { System.out.printf("Result for %s in %s%n", stream, methodGen); dataflow.dumpDataflow(dataflow.getAnalysis()); } ResourceValueFrame exitFrame = dataflow.getResultFact(cfg.getExit()); int exitStatus = exitFrame.getStatus(); if (exitStatus == ResourceValueFrame.OPEN || exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) { // FIXME: Stream object should be queried for the // priority. String bugType = stream.getBugType(); int priority = NORMAL_PRIORITY; if (exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) { bugType += "_EXCEPTION_PATH"; priority = LOW_PRIORITY; } potentialOpenStreamList.add(new PotentialOpenStream(bugType, priority, stream)); } else if (exitStatus == ResourceValueFrame.CLOSED) { // Remember that this stream was closed on all paths. // Later, we will mark all of the streams in its equivalence class // as having been closed. stream.setClosed(); } }
@Override public String blockAnnotate(BasicBlock bb) { boolean flip = isForwards() != dataflow.getAnalysis().isForwards(); Fact fact = flip ? dataflow.getStartFact(bb) : dataflow.getResultFact(bb); return " " + dataflow.getAnalysis().factToString(fact); }
/** * Constructor. * * @param dataflow * the Dataflow object whose values should be used to annotate * the printed CFG */ public DataflowCFGPrinter(Dataflow<Fact, AnalysisType> dataflow) { super(dataflow.getCFG()); this.dataflow = dataflow; setIsForwards(dataflow.getAnalysis().isForwards()); }
boolean debug = DEBUG; if (debug) { reportAnalysis("Executing"); if (numIterations > MAX_ITERS && !debug) { debug = true; reportAnalysis("Too many iterations"); System.out.println(this.getClass().getName()); if (this.getClass() == UnconditionalValueDerefDataflow.class || this.getClass() == LiveLocalStoreDataflow.class) { + getFullyQualifiedMethodName()); System.out.println("Entry point is: " + logicalEntryBlock()); System.out.println("Basic block order: "); Iterator<BasicBlock> i = blockOrder.blockIterator(); debug(block, "rBlockOrder " + rBlockOrder.rdfs.getDiscoveryTime(block) + "\n"); debug(block, "\n"); dumpDataflow(analysis); if (block == logicalEntryBlock()) { analysis.makeFactTop(start); analysis.initEntryFact(start); if (debug) { debug(block, "Init entry fact ==> " + analysis.factToString(start) + "\n"); Iterator<Edge> predEdgeIter = logicalPredecessorEdgeIterator(block);
public void dumpDataflow(AnalysisType analysis) { System.out.println(this.getClass().getName() + " analysis for " + getCFG().getMethodName() + getCFG().getMethodSig() + " { "); try { for (Location loc : getCFG().orderedLocations()) { System.out.println("\nBefore: " + analysis.factToString(getFactAtLocation(loc))); System.out.println("Location: " + loc); System.out.println("After: " + analysis.factToString(getFactAfterLocation(loc))); } } catch (DataflowAnalysisException e) { AnalysisContext.logError("error dumping dataflow analysis", e); System.out.println(e); } System.out.println("}"); } }
@Override public String edgeAnnotate(Edge edge) { String edgeAnnotation = ""; try { edgeAnnotation = " " + dataflow.getAnalysis().factToString(dataflow.getAnalysis().getFactOnEdge(edge)); } catch (Throwable e) { // ignore } return edgeAnnotation; }
private void reportAnalysis(String msg) { String shortAnalysisName = analysis.getClass().getName(); int pkgEnd = shortAnalysisName.lastIndexOf('.'); if (pkgEnd >= 0) { shortAnalysisName = shortAnalysisName.substring(pkgEnd + 1); } System.out.println(msg + " " + shortAnalysisName + " on " + getFullyQualifiedMethodName()); }
boolean debugWas = DEBUG; if (DEBUG) { reportAnalysis("Executing"); if (numIterations > MAX_ITERS && !DEBUG) { DEBUG = true; reportAnalysis("Too many iterations"); System.out.println(this.getClass().getName()); if (this.getClass() == UnconditionalValueDerefDataflow.class || this.getClass() == LiveLocalStoreDataflow.class) { + getFullyQualifiedMethodName()); System.out.println("Entry point is: " + logicalEntryBlock()); System.out.println("Basic block order: "); Iterator<BasicBlock> i = blockOrder.blockIterator(); debug(block, "rBlockOrder " + rBlockOrder.rdfs.getDiscoveryTime(block) + "\n"); debug(block, "\n"); dumpDataflow(analysis); if (block == logicalEntryBlock()) { analysis.makeFactTop(start); analysis.initEntryFact(start); if (DEBUG) { debug(block, "Init entry fact ==> " + analysis.factToString(start) + "\n"); Iterator<Edge> predEdgeIter = logicalPredecessorEdgeIterator(block);
@Override public String blockStartAnnotate(BasicBlock bb) { boolean flip = isForwards() != dataflow.getAnalysis().isForwards(); Fact fact = flip ? dataflow.getResultFact(bb) : dataflow.getStartFact(bb); return " " + dataflow.getAnalysis().factToString(fact); }
public void dumpDataflow(AnalysisType analysis) { System.out.println(this.getClass().getName() + " analysis for " + getCFG().getMethodName() + getCFG().getMethodSig() + " { "); try { for (Location loc : getCFG().orderedLocations()) { System.out.println("\nBefore: " + analysis.factToString(getFactAtLocation(loc))); System.out.println("Location: " + loc); System.out.println("After: " + analysis.factToString(getFactAfterLocation(loc))); } } catch (DataflowAnalysisException e) { AnalysisContext.logError("error dumping dataflow analysis", e); System.out.println(e); } System.out.println("}"); } }
@Override public String instructionAnnotate(InstructionHandle handle, BasicBlock bb) { try { boolean flip = isForwards() != dataflow.getAnalysis().isForwards(); Location loc = new Location(handle, bb); Fact fact = flip ? dataflow.getAnalysis().getFactAfterLocation(loc) : dataflow.getAnalysis().getFactAtLocation(loc); return " " + dataflow.getAnalysis().factToString(fact); } catch (DataflowAnalysisException e) { throw new IllegalStateException("Caught exception: " + e.toString()); } }
/** * Constructor. * * @param dataflow * the Dataflow object whose values should be used to annotate * the printed CFG */ public DataflowCFGPrinter(Dataflow<Fact, AnalysisType> dataflow) { super(dataflow.getCFG()); this.dataflow = dataflow; setIsForwards(dataflow.getAnalysis().isForwards()); }
private void reportAnalysis(String msg) { String shortAnalysisName = analysis.getClass().getName(); int pkgEnd = shortAnalysisName.lastIndexOf('.'); if (pkgEnd >= 0) { shortAnalysisName = shortAnalysisName.substring(pkgEnd + 1); } System.out.println(msg + " " + shortAnalysisName + " on " + getFullyQualifiedMethodName()); }
@Override public String blockStartAnnotate(BasicBlock bb) { boolean flip = isForwards() != dataflow.getAnalysis().isForwards(); Fact fact = flip ? dataflow.getResultFact(bb) : dataflow.getStartFact(bb); return " " + dataflow.getAnalysis().factToString(fact); }
@Override public NonExceptionPostdominatorsAnalysis analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException { CFG cfg = getCFG(analysisCache, descriptor); ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(analysisCache, descriptor); NonExceptionPostdominatorsAnalysis analysis = new NonExceptionPostdominatorsAnalysis(cfg, rdfs, getDepthFirstSearch( analysisCache, descriptor)); Dataflow<java.util.BitSet, PostDominatorsAnalysis> dataflow = new Dataflow<>(cfg, analysis); dataflow.execute(); return analysis; } }
@Override public void inspectResult(ClassContext classContext, MethodGen methodGen, CFG cfg, Dataflow<ResourceValueFrame, ResourceValueAnalysis<Stream>> dataflow, Stream stream) { if (DEBUG) { System.out.printf("Result for %s in %s%n", stream, methodGen); dataflow.dumpDataflow(dataflow.getAnalysis()); } ResourceValueFrame exitFrame = dataflow.getResultFact(cfg.getExit()); int exitStatus = exitFrame.getStatus(); if (exitStatus == ResourceValueFrame.OPEN || exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) { // FIXME: Stream object should be queried for the // priority. String bugType = stream.getBugType(); int priority = NORMAL_PRIORITY; if (exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) { bugType += "_EXCEPTION_PATH"; priority = LOW_PRIORITY; } potentialOpenStreamList.add(new PotentialOpenStream(bugType, priority, stream)); } else if (exitStatus == ResourceValueFrame.CLOSED) { // Remember that this stream was closed on all paths. // Later, we will mark all of the streams in its equivalence class // as having been closed. stream.setClosed(); } }
LocalVariableAnnotation match = null; int lowestCost = Integer.MAX_VALUE; BitSet liveStoreSetAtEntry = llsaDataflow.getAnalysis().getResultFact(cfg.getEntry()); int localsThatAreParameters = PreorderVisitor.getNumberArguments(method.getSignature()); int startIndex = 0;