/** * Constructor. * * @param method * the method containing the call site * @param basicBlock * the basic block where the call site is located * @param handle * the instruction which performs the call */ public CallSite(Method method, BasicBlock basicBlock, InstructionHandle handle) { this.method = method; this.location = new Location(handle, basicBlock); }
public static Location getLastLocation(@Nonnull BasicBlock basicBlock) { InstructionHandle lastInstruction = basicBlock.getLastInstruction(); /* * if (lastInstruction == null) lastInstruction = * basicBlock.getExceptionThrower(); if (lastInstruction == null) * lastInstruction = basicBlock.getFirstInstruction(); */ if (lastInstruction == null) { return null; } return new Location(lastInstruction, basicBlock); }
public static Location getFirstLocation(@Nonnull BasicBlock basicBlock) { InstructionHandle location = basicBlock.getFirstInstruction(); if (location == null) { return null; } return new Location(location, basicBlock); }
private void findNext() { while (next == null) { // Make sure we have an instruction iterator if (instructionIter == null) { if (!blockIter.hasNext()) { return; // At end } curBlock = blockIter.next(); instructionIter = curBlock.instructionIterator(); } if (instructionIter.hasNext()) { next = new Location(instructionIter.next(), curBlock); } else { instructionIter = null; // Go to next block } } } }
private static Location getLocation(BasicBlock block) { InstructionHandle handle = block.getFirstInstruction(); if(handle == null) { handle = block.getExceptionThrower(); } return handle == null ? null : new Location(handle, block); }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, ResourceValueFrame fact) throws DataflowAnalysisException { visitor.setFrameAndLocation(fact, new Location(handle, basicBlock)); visitor.transferInstruction(handle, basicBlock); }
/** * Match current pattern element with next instruction in basic block. * Returns MatchResult if match succeeds, null otherwise. */ public MatchResult matchNextInBasicBlock() throws DataflowAnalysisException { if (!moreInstructionsInBasicBlock()) { throw new IllegalStateException("At end of BB!"); } // Move to location of next instruction to be matched Location location = new Location(instructionIterator.next(), basicBlock); return matchLocation(location); }
private State getTransferState(InstructionHandle handle) { StateSet stateSet; try { stateSet = dataflow.getFactAtLocation(new Location(handle, curBlock)); } catch (DataflowAnalysisException e) { bugReporter.logError("Error checking obligation state at " + handle, e); return null; } List<State> prefixes = stateSet.getPrefixStates(state.getPath()); if (prefixes.size() != 1) { // Could this happen? if (DEBUG_FP) { System.out.println("at " + handle + " in " + xmethod + " found " + prefixes.size() + " states which are prefixes of error state"); } return null; } return prefixes.get(0); } }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, TypeFrame fact) throws DataflowAnalysisException { visitor.setFrameAndLocation(fact, new Location(handle, basicBlock)); visitor.analyzeInstruction(handle.getInstruction()); }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, ConstantFrame frame) throws DataflowAnalysisException { visitor.setFrameAndLocation(frame, new Location(handle, basicBlock)); visitor.analyzeInstruction(handle.getInstruction()); }
/** * 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 getEdgeSourceLocation(CFG cfg, Edge edge) { BasicBlock sourceBlock = edge.getSource(); return (sourceBlock.getLastInstruction() != null) ? new Location(sourceBlock.getLastInstruction(), sourceBlock) : null; }
private @CheckForNull Location getPreviousLocation(CFG cfg, Location startLocation, boolean skipNops) { Location loc = startLocation; InstructionHandle prev = getPreviousInstruction(loc.getHandle(), skipNops); if (prev != null) { return new Location(prev, loc.getBasicBlock()); } BasicBlock block = loc.getBasicBlock(); while (true) { block = cfg.getPredecessorWithEdgeType(block, EdgeTypes.FALL_THROUGH_EDGE); if (block == null) { return null; } InstructionHandle lastInstruction = block.getLastInstruction(); if (lastInstruction != null) { return new Location(lastInstruction, block); } } }
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); } }
private Type nullCheck(short opcode, Edge edge, InstructionHandle last, BasicBlock sourceBlock) throws DataflowAnalysisException { if (DEBUG_NULL_CHECK) { System.out.println("checking for nullcheck on edge " + edge); } Type type = null; if ((opcode == Const.IFNULL && edge.getType() == EdgeTypes.IFCMP_EDGE) || (opcode == Const.IFNONNULL && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) { Location location = new Location(last, sourceBlock); TypeFrame typeFrame = typeDataflow.getFactAtLocation(location); if (typeFrame.isValid()) { type = typeFrame.getTopValue(); if (DEBUG_NULL_CHECK) { System.out.println("ifnull comparison of " + type + " to null at " + last); } } } return type; }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, TypeQualifierValueSet fact) throws DataflowAnalysisException { if (!fact.isValid()) { return; } if (PRUNE_CONFLICTING_VALUES && forwardTypeQualifierDataflow != null) { Location location = new Location(handle, basicBlock); pruneConflictingValues(fact, forwardTypeQualifierDataflow.getFactAfterLocation(location)); } super.transferInstruction(handle, basicBlock, fact); }
@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()); } }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, ValueNumberFrame fact) throws DataflowAnalysisException { Location location = new Location(handle, basicBlock); ValueNumberFrame atLocation = getFactAtLocation(location); copy(fact, atLocation); visitor.setFrameAndLocation(fact, location); visitor.setHandle(handle); visitor.analyzeInstruction(handle.getInstruction()); ValueNumberFrame afterLocation = getFactAfterLocation(location); copy(fact, afterLocation); }
@Override public void transfer(BasicBlock basicBlock, InstructionHandle end, ValueNumberFrame start, ValueNumberFrame result) throws DataflowAnalysisException { if(basicBlock.isExceptionThrower() && isFactValid(start)) { /* If exceptionThrower is invoke instruction then it's possible that * it was partially executed before an exception occurred * So we have to kill available loads when control is transferred to the catch block */ InstructionHandle handle = basicBlock.getExceptionThrower(); Instruction inst = handle.getInstruction(); if(inst instanceof InvokeInstruction || inst instanceof INVOKEDYNAMIC) { copy(start, result); visitor.setFrameAndLocation(result, new Location(handle, basicBlock)); visitor.setHandle(handle); visitor.visitInvokeOnException(inst); return; } } super.transfer(basicBlock, end, start, result); }
/** * 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)); } }