@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 void checkIntegrity() { // Ensure that basic blocks have only consecutive instructions for (Iterator<BasicBlock> i = blockIterator(); i.hasNext();) { BasicBlock basicBlock = i.next(); InstructionHandle prev = null; for (Iterator<InstructionHandle> j = basicBlock.instructionIterator(); j.hasNext();) { InstructionHandle handle = j.next(); if (prev != null && prev.getNext() != handle) { throw new IllegalStateException("Non-consecutive instructions in block " + basicBlock.getLabel() + ": prev=" + prev + ", handle=" + handle); } prev = handle; } } }
/** * Allocate a new BasicBlock. The block won't be connected to any node in * the graph. */ public BasicBlock allocate() { BasicBlock b = new BasicBlock(); addVertex(b); return b; }
/** * 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(); }
protected Iterator<InstructionHandle> instructionIterator(BasicBlock bb) { if (isForwards) { return bb.instructionIterator(); } else { return bb.instructionReverseIterator(); } }
private static Location getLocation(BasicBlock block) { InstructionHandle handle = block.getFirstInstruction(); if(handle == null) { handle = block.getExceptionThrower(); } return handle == null ? null : new Location(handle, block); }
resultBlock.setInJSRSubroutine(context.getCaller() != null); BasicBlock.InstructionIterator insIter = subBlock.instructionIterator(); while (insIter.hasNext()) { InstructionHandle handle = insIter.next(); resultBlock.addInstruction(handle); if (subBlock.isExceptionThrower()) { resultBlock.setExceptionThrower(subBlock.getExceptionThrower()); if (subBlock.isExceptionHandler()) { resultBlock.setExceptionGen(null, subBlock.getExceptionGen()); InstructionHandle jsrHandle = subBlock.getLastInstruction(); JsrInstruction jsr = (JsrInstruction) jsrHandle.getInstruction(); Subroutine jsrSub = jsrSubroutineMap.get(jsr.getTarget());
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)); } } }
if (destBlock.isExceptionHandler()) { CodeExceptionGen handler = destBlock.getExceptionGen(); ObjectType catchType = handler.getCatchType(); if (catchType != null) { System.out.println("Updating edge information for " + valueTested); final Location atIf = new Location(sourceBlock.getLastInstruction(), sourceBlock); final ValueNumberFrame prevVnaFrame = vnaDataflow.getFactAtLocation(atIf); System.out.println("Set decision information"); System.out.println(" " + valueTested + " becomes " + decisionValue); System.out.println(" at " + targetBlock.getFirstInstruction().getPosition()); System.out.println(" prev available loads: " + prevVnaFrame.availableLoadMapAsString()); System.out.println(" target available loads: " if (sourceBlock.isNullCheck() && edgeType == FALL_THROUGH_EDGE) { ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(destBlock); if (vnaFrame == null) { Instruction firstInDest = edge.getTarget().getFirstInstruction().getInstruction(); InstructionHandle kaBoomLocation = targetBlock.getFirstInstruction(); ValueNumber replaceMe = vnaFrame.getInstance(firstInDest, methodGen.getConstantPool()); IsNullValue noKaboomNonNullValue = IsNullValue.noKaboomNonNullValue(new Location(kaBoomLocation,
/** * Return whether or not the basic block contains the given instruction. * * @param handle * the instruction * @return true if the block contains the instruction, false otherwise */ public boolean containsInstruction(InstructionHandle handle) { Iterator<InstructionHandle> i = instructionIterator(); while (i.hasNext()) { if (i.next() == handle) { return true; } } return false; }
private void removeStrictlyDominatedLocations(Set<Location> locations, DominatorsAnalysis domAnalysis) { BitSet strictlyDominated = new BitSet(); for (Location loc : locations) { BitSet allDominatedBy = domAnalysis.getAllDominatedBy(loc.getBasicBlock()); allDominatedBy.clear(loc.getBasicBlock().getLabel()); strictlyDominated.or(allDominatedBy); } LinkedList<Location> locations2 = new LinkedList<>(locations); for (Iterator<Location> i = locations.iterator(); i.hasNext();) { Location loc = i.next(); if (strictlyDominated.get(loc.getBasicBlock().getLabel())) { i.remove(); continue; } for (Location loc2 : locations2) { if (loc.getBasicBlock().equals(loc2.getBasicBlock()) && loc.getHandle().getPosition() > loc2.getHandle().getPosition()) { i.remove(); break; } } } }
System.out.println("ETB block " + basicBlock.getLabel() + " for " + handle); System.out.println("BODY block " + basicBlock.getLabel() + " for " + handle); if (!basicBlock.isEmpty()) { throw new IllegalStateException("Block isn't empty!"); System.out.println("BB " + basicBlock.getLabel() + ": adding" + handle); basicBlock.addInstruction(handle); subroutine.addInstruction(handle);
if (getBlockIdAt(index) == startBlock.getLabel()) { break; Iterator<InstructionHandle> i = startBlock.instructionIterator(); if (startHandle != startBlock.getFirstInstruction()) { while (i.hasNext()) { InstructionHandle handle = i.next(); i = basicBlock.instructionIterator();
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("[basicBlock="); buf.append(getBasicBlock().getLabel()); if (next != null) { buf.append(", next=" + next); } else if (getBasicBlock().isExceptionThrower()) { buf.append(", check for" + getBasicBlock().getExceptionThrower()); } else { buf.append(", end"); } buf.append(']'); return buf.toString(); } }
InstructionHandle handle = sourceBlock.getExceptionThrower(); fact.setOnExceptionPath(true); for (ObligationPolicyDatabaseAction action : actions) { if (action.getActionType() == ObligationPolicyDatabaseActionType.DEL) { action.apply(fact, edge.getTarget().getLabel()); + edge.getSource().getLastInstruction()); fact.deleteObligation(comparedObligation, edge.getTarget().getLabel());
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(); }
/** * 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); }
@Override public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, BlockType start, BlockType result) throws DataflowAnalysisException { result.copyFrom(start); if (start.isValid()) { if (basicBlock.isExceptionHandler()) { CodeExceptionGen exceptionGen = basicBlock.getExceptionGen(); ObjectType catchType = exceptionGen.getCatchType(); if (catchType == null) { // Probably a finally block, or a synchronized block // exception-compensation catch block. result.pushFinally(); } else { // Catch type was explicitly specified: // this is probably a programmer-written catch block result.pushCatch(); } } } }
private static String blockId(BasicBlock bb) { InstructionHandle handle = bb.getFirstInstruction(); if (handle == null) { return "" + bb.getLabel(); } return bb.getLabel() + ":" + handle.getPosition() + " " + handle.getInstruction(); }