Search in sources :

Example 1 with StopOpcodeParsingException

use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.

the class PossibleMemoryBloat method removeFieldsThatGetReturned.

protected void removeFieldsThatGetReturned() {
    if (stack.getStackDepth() > 0) {
        OpcodeStack.Item returnItem = stack.getStackItem(0);
        XField field = returnItem.getXField();
        if (field != null) {
            bloatableCandidates.remove(field);
            bloatableFields.remove(field);
            if (bloatableCandidates.isEmpty()) {
                throw new StopOpcodeParsingException();
            }
        }
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) XField(edu.umd.cs.findbugs.ba.XField) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)

Example 2 with StopOpcodeParsingException

use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.

the class PossibleMemoryBloat method visitClassContext.

/**
 * collects static fields that are likely bloatable objects and if found allows the visitor to proceed, at the end report all leftover fields
 *
 * @param classContext
 *            the class context object of the currently parsed java class
 */
@Override
public void visitClassContext(ClassContext classContext) {
    try {
        bloatableCandidates = new HashMap<>();
        bloatableFields = new HashMap<>();
        threadLocalNonStaticFields = new HashSet<>();
        parseFields(classContext);
        if (!bloatableCandidates.isEmpty()) {
            stack = new OpcodeStack();
            super.visitClassContext(classContext);
            reportMemoryBloatBugs();
            reportThreadLocalBugs();
        }
    } catch (StopOpcodeParsingException e) {
    // no more bloatable candidates
    } finally {
        stack = null;
        bloatableCandidates = null;
        bloatableFields = null;
        threadLocalNonStaticFields = null;
    }
}
Also used : OpcodeStack(edu.umd.cs.findbugs.OpcodeStack) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)

Example 3 with StopOpcodeParsingException

use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.

the class SluggishGui method visitAfter.

/**
 * overrides the visitor to visit all of the collected listener methods
 *
 * @param obj
 *            the context object of the currently parsed class
 */
@Override
public void visitAfter(JavaClass obj) {
    isListenerMethod = true;
    for (Code l : listenerCode.keySet()) {
        try {
            super.visitCode(l);
        } catch (StopOpcodeParsingException e) {
        // method already reported
        }
    }
    super.visitAfter(obj);
}
Also used : StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException) Code(org.apache.bcel.classfile.Code)

Example 4 with StopOpcodeParsingException

use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.

the class SluggishGui method visitCode.

/**
 * overrides the visitor to segregate method into two, those that implement listeners, and those that don't. The ones that don't are processed first.
 *
 * @param obj
 *            the context object of the currently parsed code block
 */
@Override
public void visitCode(Code obj) {
    try {
        for (JavaClass inf : guiInterfaces) {
            Method[] methods = inf.getMethods();
            for (Method m : methods) {
                if (m.getName().equals(methodName) && m.getSignature().equals(methodSig)) {
                    listenerCode.put(obj, this.getMethod());
                    return;
                }
            }
        }
        isListenerMethod = false;
        super.visitCode(obj);
    } catch (StopOpcodeParsingException e) {
    // method already reported
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException) Method(org.apache.bcel.classfile.Method)

Example 5 with StopOpcodeParsingException

use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.

the class TristateBooleanPattern method visitCode.

/**
 * implements the visitor to filter out methods that don't return Boolean,
 *
 * @param obj
 *            the context object for the currently parsed code block
 */
@Override
public void visitCode(Code obj) {
    try {
        Method m = getMethod();
        Type retType = m.getReturnType();
        if ("Ljava/lang/Boolean;".equals(retType.getSignature())) {
            stack.resetForMethodEntry(this);
            super.visitCode(obj);
        }
    } catch (StopOpcodeParsingException e) {
    // if the method was already reported
    }
}
Also used : Type(org.apache.bcel.generic.Type) BugType(com.mebigfatguy.fbcontrib.utils.BugType) StopOpcodeParsingException(com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException) Method(org.apache.bcel.classfile.Method)

Aggregations

StopOpcodeParsingException (com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException)24 BugInstance (edu.umd.cs.findbugs.BugInstance)11 Method (org.apache.bcel.classfile.Method)11 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)8 JavaClass (org.apache.bcel.classfile.JavaClass)5 XField (edu.umd.cs.findbugs.ba.XField)4 ToString (com.mebigfatguy.fbcontrib.utils.ToString)3 SourceLineAnnotation (edu.umd.cs.findbugs.SourceLineAnnotation)2 CodeException (org.apache.bcel.classfile.CodeException)2 ImmutabilityType (com.mebigfatguy.fbcontrib.collect.ImmutabilityType)1 MethodInfo (com.mebigfatguy.fbcontrib.collect.MethodInfo)1 BugType (com.mebigfatguy.fbcontrib.utils.BugType)1 QMethod (com.mebigfatguy.fbcontrib.utils.QMethod)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Code (org.apache.bcel.classfile.Code)1 ExceptionTable (org.apache.bcel.classfile.ExceptionTable)1