/** * Constructor. * * @param cfg * the CFG to perform the depth first search on */ public DepthFirstSearch(CFG cfg) { super(cfg); firstRoot = cfg.getEntry(); }
/** * Get the entry block for the subroutine's CFG. */ public BasicBlock getEntry() { return cfgSub.getEntry(); }
/** * 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()); }
/** * Get the "logical" entry block of the CFG. For forward analyses, this is * the entry block. For backward analyses, this is the exit block. */ private BasicBlock logicalEntryBlock() { return isForwards ? cfg.getEntry() : cfg.getExit(); }
/** * 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; }
private Set<ValueNumber> getParameterValueNumbers(ClassContext classContext, Method method, CFG cfg) throws DataflowAnalysisException, CFGBuilderException { ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); ValueNumberFrame vnaFrameAtEntry = vnaDataflow.getStartFact(cfg.getEntry()); Set<ValueNumber> paramValueNumberSet = new HashSet<>(); int firstParam = method.isStatic() ? 0 : 1; for (int i = firstParam; i < vnaFrameAtEntry.getNumLocals(); ++i) { paramValueNumberSet.add(vnaFrameAtEntry.getValue(i)); } return paramValueNumberSet; }
walkStates.push(new WalkState(new HashSet<Long>(), cfg.getEntry()));
workList.addLast(cfg.getEntry());
/** * Build map of value numbers to param indices. The first parameter has * index 0, the second has index 1, etc. * * @param methodSignature * signature of the method analyzed by the ValueNumberAnalysis * @param isStatic * true if the method is static, false if not * @return the value number to parameter index map */ public Map<ValueNumber, Integer> getValueNumberToParamMap(String methodSignature, boolean isStatic) { HashMap<ValueNumber, Integer> valueNumberToParamMap = new HashMap<>(); ValueNumberFrame frameAtEntry = getStartFact(getCFG().getEntry()); int numParams = new SignatureParser(methodSignature).getNumParameters(); int shift = isStatic ? 0 : 1; for (int i = 0; i < numParams; ++i) { valueNumberToParamMap.put(frameAtEntry.getValue(i + shift), i); } return valueNumberToParamMap; }
@Override public void visitBasicBlock(BasicBlock basicBlock) { curBlock = basicBlock; // See if the initial instance of the leaked resource // is in the entry fact due to a @WillClose annotation. if (curBlock == cfg.getEntry()) { // Get the entry fact - it should have precisely one // state StateSet entryFact = dataflow.getResultFact(curBlock); Iterator<State> i = entryFact.stateIterator(); if (i.hasNext()) { State entryState = i.next(); if (entryState.getObligationSet().getCount(obligation.getId()) > 0) { lastSourceLine = SourceLineAnnotation.forFirstLineOfMethod(methodDescriptor); lastSourceLine .setDescription(SourceLineAnnotation.ROLE_OBLIGATION_CREATED_BY_WILLCLOSE_PARAMETER); bugInstance.add(lastSourceLine); sawFirstCreation = true; if (REPORT_PATH_DEBUG) { System.out.println(" " + obligation + " created by @WillClose parameter at " + lastSourceLine); } } } } }
/** * 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; }
@Override public void build() throws CFGBuilderException { InstructionList instructionList = methodGen.getInstructionList(); optimize(instructionList); topLevelSubroutine = new Subroutine(instructionList.getStart()); subroutineWorkList.add(topLevelSubroutine); // Build top level subroutine and all JSR subroutines while (!subroutineWorkList.isEmpty()) { Subroutine subroutine = subroutineWorkList.removeFirst(); if (DEBUG) { System.out.println("Starting subroutine " + subroutine.getStartInstruction()); } build(subroutine); } // Inline everything into the top level subroutine cfg = inlineAll(); // Add a NOP instruction to the entry block. // This allows analyses to construct a Location // representing the entry to the method. BasicBlock entryBlock = cfg.getEntry(); InstructionList il = new InstructionList(); entryBlock.addInstruction(il.append(new NOP())); if (VERIFY_INTEGRITY) { cfg.checkIntegrity(); } if (true) { cfg.checkIntegrity(); } }
LocalVariableAnnotation match = null; int lowestCost = Integer.MAX_VALUE; BitSet liveStoreSetAtEntry = llsaDataflow.getAnalysis().getResultFact(cfg.getEntry()); int localsThatAreParameters = PreorderVisitor.getNumberArguments(method.getSignature()); int startIndex = 0;
private void registerParameterSources() { ValueNumberFrame vnaFrameAtEntry = vnaDataflow.getStartFact(cfg.getEntry()); SignatureParser sigParser = new SignatureParser(xmethod.getSignature()); int firstParamSlot = xmethod.isStatic() ? 0 : 1; int param = 0; int slotOffset = 0; for ( String paramSig : sigParser.parameterSignatures()) { // Get the TypeQualifierAnnotation for this parameter SourceSinkInfo info; TypeQualifierAnnotation tqa = TypeQualifierApplications.getEffectiveTypeQualifierAnnotation(xmethod, param, typeQualifierValue); When when = (tqa != null) ? tqa.when : When.UNKNOWN; ValueNumber vn = vnaFrameAtEntry.getValue(slotOffset + firstParamSlot); info = new SourceSinkInfo(SourceSinkType.PARAMETER, cfg.getLocationAtEntry(), vn, when); info.setParameterAndLocal(param, slotOffset + firstParamSlot); registerSourceSink(info); param++; slotOffset += SignatureParser.getNumSlotsForType(paramSig); } }
UnconditionalValueDerefSet entryFact = dataflow.getResultFact(cfg.getEntry()); Iterator<String> paramIterator = parser.parameterSignatureIterator(); int i = 0;
BasicBlock entry = dataflow.getCFG().getEntry(); TypeQualifierValueSet entryFact = dataflow.getAnalysis().getResultFact(entry);
ValueNumber valueNumberForThis = null; if (!method.isStatic()) { ValueNumberFrame frameAtEntry = vna.getStartFact(cfg.getEntry()); valueNumberForThis = frameAtEntry.getValue(0);
return; BitSet liveStoreSetAtEntry = llsaDataflow.getAnalysis().getResultFact(cfg.getEntry()); BitSet complainedAbout = new BitSet(); TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
/** * Get the entry block for the subroutine's CFG. */ public BasicBlock getEntry() { return cfgSub.getEntry(); }