private static DefinitelyDerefedParams getAnalysisDriver( IMethod mtd, AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha) { IR ir = cache.getIRFactory().makeIR(mtd, Everywhere.EVERYWHERE, options.getSSAOptions()); ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg = ir.getControlFlowGraph(); accountCodeBytes(mtd); return new DefinitelyDerefedParams(mtd, ir, cfg, cha); }
int numParam = ir.getSymbolTable().getNumberOfParameters(); int firstParamIndex = method.isStatic() ? 1 : 2; // 1-indexed; v1 is 'this' for non-static methods if (!node.isEntryBlock() && !node.isExitBlock()) { // entry and exit are dummy basic blocks LOG(DEBUG, "DEBUG", ">> bb: " + node.getNumber()); for (int i = node.getFirstInstructionIndex(); i <= node.getLastInstructionIndex(); i++) { SSAInstruction instr = ir.getInstructions()[i]; if (instr == null) continue; // Some instructions are null (padding NoOps) LOG(DEBUG, "DEBUG", "\tinst: " + instr.toString()); int derefValueNumber = -1; if (instr instanceof SSAGetInstruction && !((SSAGetInstruction) instr).isStatic()) { derefValueNumber = ((SSAGetInstruction) instr).getRef(); } else if (instr instanceof SSAPutInstruction && !((SSAPutInstruction) instr).isStatic()) { derefValueNumber = ((SSAPutInstruction) instr).getRef(); } else if (instr instanceof SSAAbstractInvokeInstruction) { SSAAbstractInvokeInstruction callInst = (SSAAbstractInvokeInstruction) instr; String sign = callInst.getDeclaredTarget().getSignature(); if (((SSAAbstractInvokeInstruction) instr).isStatic()) { derefValueNumber = callInst.getUse(NULL_TEST_APIS.get(sign)); !NULL_TEST_APIS.containsKey(sign), "Add support for non-static NULL_TEST_APIS : " + sign); derefValueNumber = ((SSAAbstractInvokeInstruction) instr).getReceiver();
for (int i = bb.getFirstInstructionIndex(); i <= bb.getLastInstructionIndex(); i++) { SSAInstruction instr = ir.getInstructions()[i]; if (instr instanceof SSAReturnInstruction) { SSAReturnInstruction retInstr = (SSAReturnInstruction) instr; if (ir.getSymbolTable().isNullConstant(retInstr.getResult())) { LOG(DEBUG, "DEBUG", "Nullable return in method: " + method.getSignature()); return NullnessHint.NULLABLE;
private boolean isBranchTaken(SSAPiInstruction pi, SSAConditionalBranchInstruction cnd) { final BasicBlock branchTargetBlock = this.ir.getControlFlowGraph() .getBlockForInstruction(cnd.getTarget()); return branchTargetBlock.getNumber() == pi.getSuccessor(); }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { if (isStatic()) return insts.PutInstruction(iindex, uses == null ? val : uses[0], getDeclaredField()); else return insts.PutInstruction(iindex, uses == null ? getRef() : uses[0], uses == null ? val : uses[1], getDeclaredField()); }
/** * @return the maximum value number in a particular IR */ protected int getMaxValueNumber() { return ir.getSymbolTable().getMaxValueNumber(); }
/** * If we've already created the current instruction, return the value number def'ed by the current instruction. Else, create a * new symbol. */ private int reuseOrCreateDef() { if (getCurrentInstruction() == null) { return symbolTable.newSymbol(); } else { return getCurrentInstruction().getDef(); } }
@Override public SSAInstruction next() { ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) cfg.getNode(currentBlockIndex); SSAInstruction result = bb.getCatchInstruction(); advanceBlock(); return result; }
CatchIterator() { currentBlockIndex = 0; if (!hasCatch(cfg.getNode(0))) { advanceBlock(); } }
private void advanceBlock() { for (int i = currentBlockIndex + 1; i < cfg.getMaxNumber(); i++) { if (hasCatch(cfg.getNode(i))) { currentBlockIndex = i; return; } } currentBlockIndex = -1; } }
/** * return a policy that enables all built-in pi node policies */ public static SSAPiNodePolicy getAllBuiltInPiNodes() { return CompoundPiPolicy.createCompoundPiPolicy(InstanceOfPiPolicy.createInstanceOfPiPolicy(), NullTestPiPolicy .createNullTestPiPolicy()); }
private void maybeInsertPi(SSAAbstractInvokeInstruction call) { if (piNodePolicy != null) { Pair<Integer, SSAInstruction> pi = piNodePolicy.getPi(call, symbolTable); if (pi != null) { reuseOrCreatePi(pi.snd, pi.fst); } } }
private boolean isBranchTaken(SSAPiInstruction pi, SSAConditionalBranchInstruction cnd) { final BasicBlock branchTargetBlock = this.ir.getControlFlowGraph() .getBlockForInstruction(cnd.getTarget()); return branchTargetBlock.getNumber() == pi.getSuccessor(); }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { if (isStatic()) return insts.PutInstruction(iindex, uses == null ? val : uses[0], getDeclaredField()); else return insts.PutInstruction(iindex, uses == null ? getRef() : uses[0], uses == null ? val : uses[1], getDeclaredField()); }
/** * @return the maximum value number in a particular IR */ protected int getMaxValueNumber() { return ir.getSymbolTable().getMaxValueNumber(); }
/** * If we've already created the current instruction, return the value number def'ed by the current instruction. Else, create a * new symbol. */ private int reuseOrCreateDef() { if (getCurrentInstruction() == null) { return symbolTable.newSymbol(); } else { return getCurrentInstruction().getDef(); } }
@Override public SSAInstruction next() { ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) cfg.getNode(currentBlockIndex); SSAInstruction result = bb.getCatchInstruction(); advanceBlock(); return result; }
CatchIterator() { currentBlockIndex = 0; if (!hasCatch(cfg.getNode(0))) { advanceBlock(); } }