/** * Return whether or not the Location is positioned at the first instruction * in the basic block. */ public boolean isFirstInstructionInBasicBlock() { return !basicBlock.isEmpty() && handle == basicBlock.getFirstInstruction(); }
public static Location getFirstLocation(@Nonnull BasicBlock basicBlock) { InstructionHandle location = basicBlock.getFirstInstruction(); if (location == null) { return null; } return new Location(location, basicBlock); }
private static Location getLocation(BasicBlock block) { InstructionHandle handle = block.getFirstInstruction(); if(handle == null) { handle = block.getExceptionThrower(); } return handle == null ? null : new Location(handle, block); }
/** * Return whether or not this block is a null check. */ public boolean isNullCheck() { // Null check blocks must be exception throwers, // and are always empty. (The only kind of non-empty // exception throwing block is one terminated by an ATHROW). if (!isExceptionThrower() || getFirstInstruction() != null) { return false; } short opcode = exceptionThrower.getInstruction().getOpcode(); return nullCheckInstructionSet.get(opcode); }
public static boolean isThrower(BasicBlock target) { InstructionHandle ins = target.getFirstInstruction(); int maxCount = 7; while (ins != null) { if (maxCount-- <= 0) { break; } Instruction i = ins.getInstruction(); if (i instanceof ATHROW) { return true; } if (i instanceof InstructionTargeter || i instanceof ReturnInstruction) { return false; } ins = ins.getNext(); } return false; }
public static boolean isThrower(BasicBlock target) { InstructionHandle ins = target.getFirstInstruction(); int maxCount = 7; while (ins != null) { if (maxCount-- <= 0) { break; } Instruction i = ins.getInstruction(); if (i instanceof ATHROW) { return true; } if (i instanceof InstructionTargeter || i instanceof ReturnInstruction) { return false; } ins = ins.getNext(); } return false; }
private InstructionHandle findThenFinish(CFG cfg, BasicBlock thenBB, int elsePos) { InstructionHandle inst = thenBB.getFirstInstruction(); while (inst == null) { Iterator<Edge> ie = cfg.outgoingEdgeIterator(thenBB); while (ie.hasNext()) { Edge e = ie.next(); if (e.getType() == EdgeTypes.FALL_THROUGH_EDGE) { thenBB = e.getTarget(); break; } } inst = thenBB.getFirstInstruction(); } InstructionHandle lastIns = inst; while (inst.getPosition() < elsePos) { lastIns = inst; inst = inst.getNext(); } return lastIns; }
/** * Get the Location representing the entry to the CFG. Note that this is a * "fake" Location, and shouldn't be relied on to yield source line * information. * * @return Location at entry to CFG */ public Location getLocationAtEntry() { InstructionHandle handle = getEntry().getFirstInstruction(); assert handle != null; return new Location(handle, getEntry()); }
private Location getEdgeTargetLocation(CFG cfg, Edge edge) { BasicBlock targetBlock = edge.getTarget(); // Target block is nonempty? if (targetBlock.getFirstInstruction() != null) { return new Location(targetBlock.getFirstInstruction(), targetBlock); } // Target block is an ETB? if (targetBlock.isExceptionThrower()) { BasicBlock fallThroughSuccessor = cfg.getSuccessorWithEdgeType(targetBlock, EdgeTypes.FALL_THROUGH_EDGE); if (fallThroughSuccessor == null) { // Fall through edge might have been pruned for (Iterator<Edge> i = cfg.removedEdgeIterator(); i.hasNext();) { Edge removedEdge = i.next(); if (removedEdge.getSource() == targetBlock && removedEdge.getType() == EdgeTypes.FALL_THROUGH_EDGE) { fallThroughSuccessor = removedEdge.getTarget(); break; } } } if (fallThroughSuccessor != null && fallThroughSuccessor.getFirstInstruction() != null) { return new Location(fallThroughSuccessor.getFirstInstruction(), fallThroughSuccessor); } } return null; }
/** * Like bb.getFirstInstruction() except that if null is returned it will * follow the FALL_THROUGH_EDGE (if any) */ private static InstructionHandle getDeepFirstInstruction(CFG cfg, BasicBlock bb) { InstructionHandle ih = bb.getFirstInstruction(); if (ih != null) { return ih; } Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next(); if (EdgeTypes.FALL_THROUGH_EDGE == e.getType()) { return getDeepFirstInstruction(cfg, e.getTarget()); } } return null; }
@Override public InstructionHandle next() { if (!hasNext()) { throw new NoSuchElementException(); } InstructionHandle result = next; if(result == block.getFirstInstruction()) { do { Iterator<Edge> edgeIterator = cfg.incomingEdgeIterator(block); if(!edgeIterator.hasNext()) { break; } Edge edge = edgeIterator.next(); if(!edgeIterator.hasNext() && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE) { block = edge.getSource(); } else { break; } } while(block.isExceptionThrower()); } next = (block.isExceptionThrower() || result == block.getFirstInstruction()) ? null : next.getPrev(); return result; }
private static String blockId(BasicBlock bb) { InstructionHandle handle = bb.getFirstInstruction(); if (handle == null) { return "" + bb.getLabel(); } return bb.getLabel() + ":" + handle.getPosition() + " " + handle.getInstruction(); }
/** * Add an edge to the subroutine's CFG. * * @param sourceBlock * the source basic block * @param destBlock * the destination basic block * @param edgeType * the type of edge */ public void addEdge(BasicBlock sourceBlock, BasicBlock destBlock, @Edge.Type int edgeType) { if (VERIFY_INTEGRITY) { if (destBlock.isExceptionHandler() && edgeType != HANDLED_EXCEPTION_EDGE) { throw new IllegalStateException("In method " + SignatureConverter.convertMethodSignature(methodGen) + ": exception handler " + destBlock.getFirstInstruction() + " reachable by non exception edge type " + edgeType); } } cfgSub.createEdge(sourceBlock, destBlock, edgeType); }
@Override public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, TypeFrame start, TypeFrame result) throws DataflowAnalysisException { visitor.startBasicBlock(); super.transfer(basicBlock, end, start, result); // Compute thrown exception types computeThrownExceptionTypes(basicBlock, end, result); if (DEBUG) { System.out.println("After " + basicBlock.getFirstInstruction() + " -> " + basicBlock.getLastInstruction()); System.out.println(" frame: " + result); } // If this block ends with an instanceof check, // update the cached information about it. instanceOfCheckMap.remove(basicBlock); if (visitor.isInstanceOfFollowedByBranch()) { InstanceOfCheck check = new InstanceOfCheck(visitor.getInstanceOfValueNumber(), visitor.getInstanceOfType()); instanceOfCheckMap.put(basicBlock, check); } }
/** * Accept a PathVisitor. * * @param cfg * the control flow graph * @param visitor * a PathVisitor */ public void acceptVisitor(CFG cfg, PathVisitor visitor) { if (getLength() > 0) { BasicBlock startBlock = cfg.lookupBlockByLabel(getBlockIdAt(0)); acceptVisitorStartingFromLocation(cfg, visitor, startBlock, startBlock.getFirstInstruction()); } }
@Override public void visitEdge(Edge edge) { if (REPORT_PATH_DEBUG) { System.out.println("Edge of type " + Edge.edgeTypeToString(edge.getType()) + " to " + edge.getTarget().getLabel()); if (edge.getTarget().getFirstInstruction() != null) { System.out.println(" First instruction in target: " + edge.getTarget().getFirstInstruction()); } if (edge.getTarget().isExceptionThrower()) { System.out.println(" exception thrower for " + edge.getTarget().getExceptionThrower()); } if (edge.isExceptionEdge()) { System.out.println(" exceptions thrown: " + typeDataflow.getEdgeExceptionSet(edge)); } } } };
public boolean isBackwardInBytecode() { BasicBlock source = getSource(); BasicBlock target = getTarget(); InstructionHandle sourceInstruction = source.getLastInstruction(); InstructionHandle targetInstruction = target.getFirstInstruction(); if (targetInstruction == null || sourceInstruction == null) { return false; } return targetInstruction.getPosition() < sourceInstruction.getPosition(); }
public Location getPreviousLocation(Location loc) { InstructionHandle handle = loc.getHandle(); BasicBlock basicBlock = loc.getBasicBlock(); if (basicBlock.getFirstInstruction().equals(handle)) { BasicBlock prevBlock = basicBlock; while (true) { prevBlock = getPredecessorWithEdgeType(prevBlock, EdgeTypes.FALL_THROUGH_EDGE); if (prevBlock == null) { return loc; } handle = prevBlock.getLastInstruction(); if (handle != null) { return new Location(handle, prevBlock); } } } else { handle = handle.getPrev(); return new Location(handle, basicBlock); } }
BasicBlock b = loc.getBasicBlock(); BasicBlock b2 = null; if (b.getFirstInstruction() != null && b.getFirstInstruction().getPosition() == pc) { b2 = cfg.getPredecessorWithEdgeType(b, EdgeTypes.FALL_THROUGH_EDGE);
/** * Get the dataflow fact representing the point just after given Location. * Note "after" is meant in the logical sense, so for backward analyses, * after means before the location in the control flow sense. * * @param location * the location * @return the fact at the point just after the location */ @Override public Fact getFactAfterLocation(Location location) throws DataflowAnalysisException { BasicBlock basicBlock = location.getBasicBlock(); InstructionHandle handle = location.getHandle(); if (handle == (isForwards() ? basicBlock.getLastInstruction() : basicBlock.getFirstInstruction())) { return getResultFact(basicBlock); } else { return getFactAtLocation(new Location(isForwards() ? handle.getNext() : handle.getPrev(), basicBlock)); } }