public boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); return bytecodeSet != null && (bytecodeSet.get(Const.CHECKCAST) || bytecodeSet.get(Const.INSTANCEOF)); }
/** * Get a BitSet representing the bytecodes that are used in the given * method. This is useful for prescreening a method for the existence of * particular instructions. Because this step doesn't require building a * MethodGen, it is very fast and memory-efficient. It may allow a Detector * to avoid some very expensive analysis, which is a Big Win for the user. * * @param method * the method * @return the BitSet containing the opcodes which appear in the method, or * null if the method has no code */ @CheckForNull public BitSet getBytecodeSet(Method method) { return getBytecodeSet(jclass, method); }
/** * Use this to screen out methods that do not contain invocations. */ public boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); return bytecodeSet != null && (bytecodeSet.get(Const.INVOKEINTERFACE) || bytecodeSet.get(Const.INVOKEVIRTUAL) || bytecodeSet.get(Const.INVOKESPECIAL) || bytecodeSet.get(Const.INVOKESTATIC) || bytecodeSet .get(Const.INVOKENONVIRTUAL)); }
@Override public boolean prescreen(ClassContext classContext, Method method, boolean mightClose) { BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return false; } return bytecodeSet.get(Const.NEW) || bytecodeSet.get(Const.INVOKEINTERFACE) || bytecodeSet.get(Const.INVOKESPECIAL) || bytecodeSet.get(Const.INVOKESTATIC) || bytecodeSet.get(Const.INVOKEVIRTUAL); }
private boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return false; } // method must acquire a lock if (!bytecodeSet.get(Const.MONITORENTER) && !method.isSynchronized()) { return false; } // and contain a static method invocation if (!bytecodeSet.get(Const.INVOKESTATIC)) { return false; } return true; }
@Override public boolean prescreen(ClassContext classContext, Method method, boolean mightClose) { if (!mightClose) { return false; } BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return false; } MethodGen methodGen = classContext.getMethodGen(method); return methodGen != null && methodGen.getName().toLowerCase().indexOf("lock") == -1 && (bytecodeSet.get(Const.INVOKEVIRTUAL) || bytecodeSet.get(Const.INVOKEINTERFACE)); }
@Override public boolean prescreen(Method method, ClassContext classContext) { if (Const.STATIC_INITIALIZER_NAME.equals(method.getName())) { return false; } Code code = method.getCode(); if (code.getCode().length > 5000) { return false; } BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return false; } // The pattern requires a get/put pair accessing the same field. boolean hasGetStatic = bytecodeSet.get(Const.GETSTATIC); boolean hasPutStatic = bytecodeSet.get(Const.PUTSTATIC); if (!hasGetStatic || !hasPutStatic) { return false; } // If the method is synchronized, then we'll assume that // things are properly synchronized if (method.isSynchronized()) { return false; } reported.clear(); return true; }
@Override public void visitClassContext(ClassContext classContext) { JavaClass jclass = classContext.getJavaClass(); Method[] methodList = jclass.getMethods(); for (Method method : methodList) { MethodGen methodGen = classContext.getMethodGen(method); if (methodGen == null) { continue; } // Don't bother analyzing the method unless there is both locking // and a method call. BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { continue; } if (!(bytecodeSet.get(Const.MONITORENTER) && bytecodeSet.get(Const.INVOKEVIRTUAL))) { continue; } try { analyzeMethod(classContext, method); } catch (DataflowAnalysisException e) { bugReporter.logError("FindMismatchedWaitOrNotify: caught exception", e); } catch (CFGBuilderException e) { bugReporter.logError("FindMismatchedWaitOrNotify: caught exception", e); } } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass jclass = classContext.getJavaClass(); if (jclass.getClassName().startsWith("java.util.concurrent.")) { return; } Method[] methodList = jclass.getMethods(); for (Method method : methodList) { if (method.getCode() == null) { continue; } // We can ignore methods that don't contain a monitorenter BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { continue; } if (false && !bytecodeSet.get(Const.MONITORENTER)) { continue; } analyzeMethod(classContext, method); } }
/** * Execute dataflow analyses (only if required). * * @throws CheckedAnalysisException */ public void execute() throws CheckedAnalysisException { method = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor); ClassContext classContext = Global.getAnalysisCache().getClassAnalysis(ClassContext.class, methodDescriptor.getClassDescriptor()); BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return; } if (bytecodeSet.get(Const.MONITORENTER) || bytecodeSet.get(Const.MONITOREXIT)) { this.lockDataflow = classContext.getLockDataflow(method); } else if (method.isSynchronized()) { this.vnaDataflow = classContext.getValueNumberDataflow(method); // will // need // this // later } }
@Override public void visitClassContext(ClassContext classContext) { this.classContext = classContext; JavaClass jclass = classContext.getJavaClass(); Method[] methodList = jclass.getMethods(); for (Method method : methodList) { MethodGen methodGen = classContext.getMethodGen(method); if (methodGen == null) { continue; } // Prescreening - must have IF_ACMPEQ, IF_ACMPNE, // or an invocation of an instance method BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null || !bytecodeSet.intersects(prescreenSet)) { continue; } if (DEBUG) { System.out.println("FindRefComparison: analyzing " + SignatureConverter.convertMethodSignature(methodGen)); } try { analyzeMethod(classContext, method); } catch (CFGBuilderException e) { bugReporter.logError("Error analyzing " + method.toString(), e); } catch (DataflowAnalysisException e) { // bugReporter.logError("Error analyzing " + method.toString(), // e); } bugAccumulator.reportAccumulatedBugs(); } }
return; BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return;
return; BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return;
return; BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return;
@Override public boolean prescreen(ClassContext classContext, Method method, boolean mightClose) { BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return false; } return bytecodeSet.get(Constants.NEW) || bytecodeSet.get(Constants.INVOKEINTERFACE) || bytecodeSet.get(Constants.INVOKESPECIAL) || bytecodeSet.get(Constants.INVOKESTATIC) || bytecodeSet.get(Constants.INVOKEVIRTUAL); }
/** * Use this to screen out methods that do not contain invocations. */ public boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); return bytecodeSet != null && (bytecodeSet.get(Constants.INVOKEINTERFACE) || bytecodeSet.get(Constants.INVOKEVIRTUAL) || bytecodeSet.get(Constants.INVOKESPECIAL) || bytecodeSet.get(Constants.INVOKESTATIC) || bytecodeSet .get(Constants.INVOKENONVIRTUAL)); }
/** * looks for methods that contain a LDC opcode * * @param obj * the context object of the current method * @return if the class uses LDC instructions */ private boolean prescreen(Method obj) { BitSet bytecodeSet = getClassContext().getBytecodeSet(obj); return (bytecodeSet != null) && ((bytecodeSet.get(Constants.LDC) || (bytecodeSet.get(Constants.LDC_W)))); }
/** * looks for methods that contain a checkcast instruction * * @param method * the context object of the current method * @return if the class does checkcast instructions */ private boolean prescreen(Method method) { BitSet bytecodeSet = getClassContext().getBytecodeSet(method); return (bytecodeSet != null) && (bytecodeSet.get(Constants.CHECKCAST)); }
/** * looks for methods that contain a GOTO opcodes * * @param method * the context object of the current method * @return if the class uses synchronization */ private boolean prescreen(Method method) { BitSet bytecodeSet = getClassContext().getBytecodeSet(method); return (bytecodeSet != null) && bytecodeSet.get(Constants.GOTO); }
/** * looks for methods that contain a IINC and GOTO or GOTO_W opcodes * * @param method * the context object of the current method * @return if the class uses synchronization */ private boolean prescreen(Method method) { BitSet bytecodeSet = getClassContext().getBytecodeSet(method); return (bytecodeSet != null) && (bytecodeSet.get(Constants.IINC)) && (bytecodeSet.get(Constants.GOTO) || bytecodeSet.get(Constants.GOTO_W)); }