private LocationIterator() { this.blockIter = blockIterator(); findNext(); }
/** * Inline all JSR subroutines into the top-level subroutine. This produces a * complete CFG for the entire method, in which all JSR subroutines are * inlined. * * @return the CFG for the method */ private CFG inlineAll() throws CFGBuilderException { CFG result = new CFG(); Context rootContext = new Context(null, topLevelSubroutine, result); rootContext.mapBlock(topLevelSubroutine.getEntry(), result.getEntry()); rootContext.mapBlock(topLevelSubroutine.getExit(), result.getExit()); BasicBlock resultStartBlock = rootContext.getBlock(topLevelSubroutine.getStartBlock()); result.createEdge(result.getEntry(), resultStartBlock, START_EDGE); inline(rootContext); return result; }
public static void dumpTypeDataflow(Method method, CFG cfg, TypeDataflow typeDataflow) throws DataflowAnalysisException { System.out.println("\n\n{ Type analysis for " + cfg.getMethodGen().getClassName() + "." + method.getName() + method.getSignature()); TreeSet<Location> tree = new TreeSet<>(); for (Iterator<Location> locs = cfg.locationIterator(); locs.hasNext();) { Location loc = locs.next(); tree.add(loc); } for (Location loc : tree) { System.out.println("\n Pre: " + typeDataflow.getFactAtLocation(loc)); System.out.println("Location: " + loc); System.out.println("Post: " + typeDataflow.getFactAfterLocation(loc)); } System.out.println("}\n\n"); }
/** * Return an Iterator over edges that connect given block to its logical * predecessors. For forward analyses, this is the incoming edges. For * backward analyses, this is the outgoing edges. */ private Iterator<Edge> logicalPredecessorEdgeIterator(BasicBlock block) { return isForwards ? cfg.incomingEdgeIterator(block) : cfg.outgoingEdgeIterator(block); }
/** * Get the first outgoing edge in basic block with given type. * * @param basicBlock * the basic block * @param edgeType * the edge type * @return the Edge, or null if there is no edge with that edge type */ public Edge getOutgoingEdgeWithType(BasicBlock basicBlock, @Type int edgeType) { return getEdgeWithType(outgoingEdgeIterator(basicBlock), edgeType); }
cfg.setFlag(CFG.BUSY); cfg.setMethodName(SignatureConverter.convertMethodSignature(methodGen)); cfg.setMethodGen(methodGen); if (ASSUME_ASSERTIONS_ENABLED) { LinkedList<Edge> edgesToRemove = new LinkedList<>(); for (Iterator<Edge> i = cfg.edgeIterator(); i.hasNext();) { Edge e = i.next(); if (e.getType() == EdgeTypes.IFCMP_EDGE) { changed = true; for (Edge e : edgesToRemove) { cfg.removeEdge(e); cfg.setFlag(CFG.PRUNED_FAILED_ASSERTION_EDGES); if (PRUNE_INFEASIBLE_EXCEPTION_EDGES && !cfg.isFlagSet(CFG.PRUNED_INFEASIBLE_EXCEPTIONS)) { try { TypeDataflow typeDataflow = analysisCache.getMethodAnalysis(TypeDataflow.class, descriptor); cfg.setFlag(CFG.PRUNED_INFEASIBLE_EXCEPTIONS); if (PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES && !cfg.isFlagSet(CFG.PRUNED_UNCONDITIONAL_THROWERS)) { try { JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, descriptor.getClassDescriptor()); cfg.setFlag(CFG.PRUNED_UNCONDITIONAL_THROWERS);
for (Iterator<Edge> i = cfg.edgeIterator(); i.hasNext();) { Edge edge = i.next(); if (!edge.isExceptionEdge()) { if (exceptionSet.isSingleton("java.lang.CloneNotSupportedException") && cfg.getMethodName().endsWith(".clone()")) { String className = cfg.getMethodGen().getClassName(); if (Subtypes2.instanceOf(className, "java.lang.Cloneable")) { deletedEdgeSet.add(edge); cfg.removeEdge(edge); if (STATS) { ++numEdgesPruned;
/** * Enumerate the simple paths. * * @return this object */ public SimplePathEnumerator enumerate() { Iterator<Edge> entryOut = cfg.outgoingEdgeIterator(cfg.getEntry()); if (!entryOut.hasNext()) { throw new IllegalStateException(); } Edge entryEdge = entryOut.next(); LinkedList<Edge> init = new LinkedList<>(); init.add(entryEdge); work(init); if (DEBUG && work == maxWork) { System.out.println("**** Reached max work! ****"); } return this; }
/** * Constructor. * * @param cfg * the CFG to perform the depth first search on */ public DepthFirstSearch(CFG cfg) { super(cfg); firstRoot = cfg.getEntry(); }
/** * Get an Iterator over the Locations in the control flow graph. */ public Iterable<Location> locations() { return () -> locationIterator(); }
Context context = new Context(cfg.getMethodGen().getConstantPool().getConstantPool(), method.getCode().getLocalVariableTable(), getParameterTypes(descriptor), classContext.getValueNumberDataflow(method)); Map<ValueNumber, VariableData> analyzedArguments = new HashMap<>(); Map<Edge, Branch> allEdges = new IdentityHashMap<>(); for (Iterator<Edge> edgeIterator = cfg.edgeIterator(); edgeIterator.hasNext();) { Edge edge = edgeIterator.next(); if (edge.getType() == EdgeTypes.IFCMP_EDGE) { for (LongRangeSet subRange : data.splitSet) { BitSet reachedBlocks = new BitSet(); walkCFG(cfg, cfg.getEntry(), subRange, data.edges, reachedBlocks, new HashSet<Long>()); data.reachableBlocks.or(reachedBlocks); BasicBlock falseTarget = cfg.getSuccessorWithEdgeType(edge.getSource(), EdgeTypes.FALL_THROUGH_EDGE); String condition; BasicBlock deadTarget, aliveTarget; MethodGen methodGen = cfg.getMethodGen(); Iterator<InstructionHandle> iterator = methodGen.getInstructionList().iterator(); while(iterator.hasNext()) {
/** * overrides the visitor to navigate basic blocks looking for all first usages of fields, removing those that are read from first. * * @param obj * the context object of the currently parsed method */ @Override public void visitMethod(Method obj) { if (localizableFields.isEmpty()) { return; } try { cfg = clsContext.getCFG(obj); cpg = cfg.getMethodGen().getConstantPool(); BasicBlock bb = cfg.getEntry(); Set<String> uncheckedFields = new HashSet<>(localizableFields.keySet()); visitedBlocks.clear(); checkBlock(bb, uncheckedFields); } catch (CFGBuilderException cbe) { localizableFields.clear(); } finally { cfg = null; cpg = null; } }
Iterator<BasicBlock> bbIter = cfg.blockIterator(); ConstantPoolGen cpg = classContext.getConstantPoolGen(); ValueNumber valueNumberForThis = null; if (!method.isStatic()) { ValueNumberFrame frameAtEntry = vna.getStartFact(cfg.getEntry()); valueNumberForThis = frameAtEntry.getValue(0); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); InstructionHandle handle = location.getHandle();
MethodGen methodGen = classContext.getMethodGen(method); CFG cfg = classContext.getCFG(method); if (cfg.isFlagSet(CFG.FOUND_INEXACT_UNCONDITIONAL_THROWERS)) { return; BitSet liveStoreSetAtEntry = llsaDataflow.getAnalysis().getResultFact(cfg.getEntry()); BitSet complainedAbout = new BitSet(); TypeDataflow typeDataflow = classContext.getTypeDataflow(method); for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); foundDeadClassInitialization = getStatic.getFieldName(cpg).startsWith("class$") && "Ljava/lang/Class;".equals(getStatic.getSignature(cpg)); for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) { Location location2 = j.next(); if (location2.getHandle().getPosition() + 15 == location.getHandle().getPosition()) { propertySet.addProperty(DeadLocalStoreProperty.MANY_STORES); int occurrences = cfg.getLocationsContainingInstructionWithOffset(pc).size(); if (occurrences > 2 || sourceLineAnnotation.getStartLine() > 0 && linesMentionedMultipleTimes.get(sourceLineAnnotation.getStartLine())) {
public void print(PrintStream out) { Iterator<BasicBlock> i = cfg.blockIterator(); while (i.hasNext()) { BasicBlock bb = i.next(); out.println(); out.println("BASIC BLOCK: " + bb.getLabel() + (bb.isExceptionThrower() ? " [EXCEPTION THROWER]" : "") + blockStartAnnotate(bb)); if (bb.isExceptionThrower()) { out.println(" Exception thrower: " + bb.getExceptionThrower()); } CodeExceptionGen exceptionGen = bb.getExceptionGen(); if (exceptionGen != null) { out.println("\tCATCHES " + exceptionGen.getCatchType()); } Iterator<InstructionHandle> j = instructionIterator(bb); while (j.hasNext()) { InstructionHandle handle = j.next(); out.println(handle + instructionAnnotate(handle, bb)); } out.println("END" + blockAnnotate(bb)); Iterator<Edge> edgeIter = isForwards ? cfg.outgoingEdgeIterator(bb) : cfg.incomingEdgeIterator(bb); while (edgeIter.hasNext()) { Edge edge = edgeIter.next(); out.println(" " + edge.formatAsString(!isForwards) + " " + edgeAnnotate(edge)); } } }
UselessValuesContext(ClassContext classContext, Method method) throws CheckedAnalysisException { this.classContext = classContext; this.method = method; cfg = classContext.getCFG(method); cpg = cfg.getMethodGen().getConstantPool(); ta = classContext.getTypeDataflow(method).getAnalysis(); vna = classContext.getValueNumberDataflow(method).getAnalysis(); }
/** * Get number of non-exception control successors of given basic block. * * @param block * a BasicBlock * @return number of non-exception control successors of the basic block */ public int getNumNonExceptionSucessors(BasicBlock block) { int numNonExceptionSuccessors = block.getNumNonExceptionSuccessors(); if (numNonExceptionSuccessors < 0) { numNonExceptionSuccessors = 0; for (Iterator<Edge> i = outgoingEdgeIterator(block); i.hasNext();) { Edge edge = i.next(); if (!edge.isExceptionEdge()) { numNonExceptionSuccessors++; } } block.setNumNonExceptionSuccessors(numNonExceptionSuccessors); } return numNonExceptionSuccessors; }
Iterator<BasicBlock> bbi = cfg.blockIterator(); while (bbi.hasNext()) { BasicBlock bb = bbi.next(); Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next();
private String getFullyQualifiedMethodName() { String methodName; MethodGen methodGen = cfg.getMethodGen(); if (methodGen == null) { methodName = cfg.getMethodName(); } else { methodName = SignatureConverter.convertMethodSignature(methodGen); } return methodName; }