private InvokeInstruction toInvokeInstruction(Instruction ins) { short opcode = ins.getOpcode(); if (opcode != Const.INVOKEVIRTUAL && opcode != Const.INVOKEINTERFACE) { return null; } return (InvokeInstruction) ins; } }
/** * Determine whether or not given instruction is a goto. * * @param instruction * the instruction * @return true if the instruction is a goto, false otherwise */ private boolean isGoto(Instruction instruction) { return instruction.getOpcode() == Const.GOTO || instruction.getOpcode() == Const.GOTO_W; }
@Override public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException { if (handle.getInstruction().getOpcode() == opcode) { return new MatchResult(this, bindingSet); } else { return null; } }
/** * 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); }
/** * @param handle instruction handle which loads the object for further GETFIELD/PUTFIELD operation * @return true if this object is known to be non-null */ private boolean isSafeFieldSource(InstructionHandle handle) { while(handle != null && handle.getInstruction().getOpcode() == Const.DUP) { // Some compilers generate DUP for field increment code like // ALOAD_0 / DUP / GETFIELD x / ICONST_1 / IADD / PUTFIELD x handle = handle.getPrev(); } if(handle == null) { return false; } Instruction inst = handle.getInstruction(); if(inst.getOpcode() == Const.ALOAD_0) { return true; } if(inst instanceof GETFIELD && ((GETFIELD)inst).getFieldName(cpg).startsWith("this$")) { return true; } return false; }
private static boolean check(InstructionHandle h, int[] opcodes) { for (int opcode : opcodes) { if (h == null) { return false; } short opcode2 = h.getInstruction().getOpcode(); if (opcode == Const.LDC) { switch (opcode2) { case Const.LDC: case Const.ALOAD: case Const.ALOAD_0: case Const.ALOAD_1: case Const.ALOAD_2: case Const.ALOAD_3: break; default: return false; } } else if (opcode2 != opcode) { return false; } h = h.getNext(); } return true; }
/** * Determine if given Instruction is a monitor wait. * * @param ins * the Instruction * @param cpg * the ConstantPoolGen for the Instruction * * @return true if the instruction is a monitor wait, false if not */ public static boolean isMonitorWait(Instruction ins, ConstantPoolGen cpg) { if (!(ins instanceof InvokeInstruction)) { return false; } if (ins.getOpcode() == Const.INVOKESTATIC) { return false; } InvokeInstruction inv = (InvokeInstruction) ins; String methodName = inv.getMethodName(cpg); String methodSig = inv.getSignature(cpg); return isMonitorWait(methodName, methodSig); }
/** * Determine if given Instruction is a monitor wait. * * @param ins * the Instruction * @param cpg * the ConstantPoolGen for the Instruction * * @return true if the instruction is a monitor wait, false if not */ public static boolean isMonitorNotify(Instruction ins, ConstantPoolGen cpg) { if (!(ins instanceof InvokeInstruction)) { return false; } if (ins.getOpcode() == Const.INVOKESTATIC) { return false; } InvokeInstruction inv = (InvokeInstruction) ins; String methodName = inv.getMethodName(cpg); String methodSig = inv.getSignature(cpg); return isMonitorNotify(methodName, methodSig); }
throws DataflowAnalysisException { Instruction ins = location.getHandle().getInstruction(); short opcode = ins.getOpcode(); if (opcode == Const.IF_ACMPEQ || opcode == Const.IF_ACMPNE) { checkRefComparison(location, jclass, method, methodGen, visitor, typeDataflow, stringComparisonList,
@Override public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Const.GETSTATIC) { return null; } GETSTATIC getstatic = (GETSTATIC) ins; if (!className.equals(getstatic.getClassName(cpg)) || !fieldName.equals(getstatic.getName(cpg)) || !fieldSig.equals(getstatic.getSignature(cpg))) { return null; } return new Stream(location, type.getClassName(), streamBaseClass).setIgnoreImplicitExceptions(true).setIsOpenOnCreation( true); } }
private void registerInstructionSinks() throws DataflowAnalysisException { TypeQualifierAnnotation returnValueAnnotation = null; if (!xmethod.getSignature().endsWith(")V")) { returnValueAnnotation = TypeQualifierApplications.getEffectiveTypeQualifierAnnotation(xmethod, typeQualifierValue); } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction ins = location.getHandle().getInstruction(); if (ins instanceof ReturnInstruction && !(ins instanceof RETURN)) { // Return instruction which returns a value modelReturn(returnValueAnnotation, location); } else { short opcode = ins.getOpcode(); if (opcode == Const.PUTFIELD || opcode == Const.PUTSTATIC) { modelFieldStore(location); } else if (location.getHandle().getInstruction() instanceof InvokeInstruction) { modelArguments(location); } } } }
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, LockSet fact) throws DataflowAnalysisException { Instruction ins = handle.getInstruction(); short opcode = ins.getOpcode(); if (opcode == Const.MONITORENTER || opcode == Const.MONITOREXIT) { ValueNumberFrame frame = vnaDataflow.getFactAtLocation(new Location(handle, basicBlock)); modifyLock(frame, fact, opcode == Const.MONITORENTER ? 1 : -1); } else if (opcode == Const.INVOKEVIRTUAL || opcode == Const.INVOKEINTERFACE) { InvokeInstruction inv = (InvokeInstruction) ins; String name = inv.getMethodName(methodGen.getConstantPool()); String sig = inv.getSignature(methodGen.getConstantPool()); ValueNumberFrame frame = vnaDataflow.getFactAtLocation(new Location(handle, basicBlock)); if ("()V".equals(sig) && ("lock".equals(name) || "lockInterruptibly".equals(name))) { modifyLock(frame, fact, 1); } else if ("()V".equals(sig) && ("unlock".equals(name))) { modifyLock(frame, fact, -1); } } else if ((ins instanceof ReturnInstruction) && isSynchronized && !isStatic) { lockOp(fact, vna.getThisValue().getNumber(), -1); } }
public Condition extractCondition(BackIterator iterator) throws DataflowAnalysisException { Instruction comparisonInstruction = iterator.next().getInstruction(); if (!(comparisonInstruction instanceof IfInstruction)) { return null; } short cmpOpcode = comparisonInstruction.getOpcode(); int nargs = ((IfInstruction) comparisonInstruction).consumeStack(null); if (nargs == 2) { return extractTwoArgCondition(iterator, cmpOpcode, "I"); } else if (nargs == 1) { Object val = extractValue(iterator, "I"); if(val instanceof Value) { return new Condition(cmpOpcode, (Value) val, 0); } else if(val instanceof LCMP) { return extractTwoArgCondition(iterator, cmpOpcode, "J"); } } return null; }
private void registerInstructionSources() throws DataflowAnalysisException { for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction instruction = location.getHandle().getInstruction(); short opcode = instruction.getOpcode(); int produces = instruction.produceStack(cpg); if (instruction instanceof InvokeInstruction) { // Model return value registerReturnValueSource(location); } else if (opcode == Const.GETFIELD || opcode == Const.GETSTATIC) { // Model field loads registerFieldLoadSource(location); } else if (instruction instanceof LDC) { // Model constant values registerLDCValueSource(location); } else if (instruction instanceof LDC2_W) { // Model constant values registerLDC2ValueSource(location); } else if (instruction instanceof ConstantPushInstruction) { // Model constant values registerConstantPushSource(location); } else if (instruction instanceof ACONST_NULL) { // Model constant values registerPushNullSource(location); } else if ((produces == 1 || produces == 2) && !(instruction instanceof LocalVariableInstruction) && !(instruction instanceof CHECKCAST)){ // Model other sources registerOtherSource(location); } } }
private void handleInstruction(InstructionHandle handle, BasicBlock basicBlock, FieldSet fact) short opcode = ins.getOpcode(); XField field;
if (ins.getOpcode() != Const.GETFIELD) { return null;
Instruction ins = location.getHandle().getInstruction(); if (!receiverObjectInstructionSet.get(ins.getOpcode())) { return;
short opcode = last.getInstruction().getOpcode(); switch (opcode) { case Const.IFNULL:
Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Const.NEW) { return null;
} else if (methodAnnotation == NullnessAnnotation.NONNULL && ins.getOpcode() == Const.ARETURN) { examineReturnInstruction(location); } else if (ins instanceof PUTFIELD) {