Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Method


     * edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public UnpackedCode analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        Method method = getMethod(analysisCache, descriptor);
        Code code = method.getCode();
        if (code == null) {
            return null;
        }

        byte[] instructionList = code.getCode();
View Full Code Here


    public CFG analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        // Construct the CFG in its raw form
        MethodGen methodGen = analysisCache.getMethodAnalysis(MethodGen.class, descriptor);
        if (methodGen == null) {
            JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, descriptor.getClassDescriptor());
            Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
            JavaClassAndMethod javaClassAndMethod = new JavaClassAndMethod(jclass, method);
            AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportSkippedAnalysis(descriptor);
            throw new MethodUnprofitableException(javaClassAndMethod);
        }
        CFGBuilder cfgBuilder = CFGBuilderFactory.create(descriptor, methodGen);
        cfgBuilder.build();
        CFG cfg = cfgBuilder.getCFG();

        // Mark as busy while we're pruning the CFG.
        cfg.setFlag(CFG.BUSY);

        // Important: eagerly put the CFG in the analysis cache.
        // Recursively performed analyses required to prune the CFG,
        // such as TypeAnalysis, will operate on the raw CFG.
        analysisCache.eagerlyPutMethodAnalysis(CFG.class, descriptor, cfg);

        // Record method name and signature for informational purposes
        cfg.setMethodName(SignatureConverter.convertMethodSignature(methodGen));
        cfg.setMethodGen(methodGen);

        // System.out.println("CC: getting refined CFG for " + methodId);
        if (CFGFactory.DEBUG_CFG) {
            String methodId = methodGen.getClassName() + "." + methodGen.getName() + ":" + methodGen.getSignature();
            System.out.println("CC: getting refined CFG for " + methodId);
        }
        if (ClassContext.DEBUG) {
            String methodId = methodGen.getClassName() + "." + methodGen.getName() + ":" + methodGen.getSignature();
            System.out.println("ClassContext: request to prune " + methodId);
        }

        // Remove CFG edges corresponding to failed assertions.
        boolean changed = false;
        boolean ASSUME_ASSERTIONS_ENABLED = true;
        if (ASSUME_ASSERTIONS_ENABLED) {
            LinkedList<Edge> edgesToRemove = new LinkedList<Edge>();
            for (Iterator<Edge> i = cfg.edgeIterator(); i.hasNext();) {
                Edge e = i.next();
                if (e.getType() == EdgeTypes.IFCMP_EDGE) {
                    try {
                        BasicBlock source = e.getSource();
                        InstructionHandle last = source.getLastInstruction();
                        Instruction lastInstruction = last.getInstruction();
                        InstructionHandle prev = last.getPrev();
                        Instruction prevInstruction = prev.getInstruction();
                        if (prevInstruction instanceof GETSTATIC && lastInstruction instanceof IFNE) {
                            GETSTATIC getStatic = (GETSTATIC) prevInstruction;

                            if (getStatic.getFieldName(methodGen.getConstantPool()).equals("$assertionsDisabled")
                                    && getStatic.getSignature(methodGen.getConstantPool()).equals("Z")) {
                                edgesToRemove.add(e);
                            }
                        }
                    } catch (RuntimeException exception) {
                        assert true; // ignore it
                    }
                }
            }
            if (edgesToRemove.size() > 0) {
                changed = true;
                for (Edge e : edgesToRemove) {
                    cfg.removeEdge(e);
                }
            }
        }
        cfg.setFlag(CFG.PRUNED_FAILED_ASSERTION_EDGES);

        final boolean PRUNE_INFEASIBLE_EXCEPTION_EDGES = AnalysisContext.currentAnalysisContext().getBoolProperty(
                AnalysisFeatures.ACCURATE_EXCEPTIONS);

        if (PRUNE_INFEASIBLE_EXCEPTION_EDGES && !cfg.isFlagSet(CFG.PRUNED_INFEASIBLE_EXCEPTIONS)) {
            try {
                TypeDataflow typeDataflow = analysisCache.getMethodAnalysis(TypeDataflow.class, descriptor);
                // Exception edge pruning based on ExceptionSets.
                // Note: this is quite slow.
                PruneInfeasibleExceptionEdges pruner = new PruneInfeasibleExceptionEdges(cfg, methodGen, typeDataflow);
                pruner.execute();
                changed = changed || pruner.wasCFGModified();
            } catch (MissingClassException e) {
                AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
                .reportMissingClass(e.getClassNotFoundException());
            } catch (DataflowAnalysisException e) {
                AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
                .logError("unable to extract type analysis", e);
            } catch (ClassNotFoundException e) {
                AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e);
            }
        }
        cfg.setFlag(CFG.PRUNED_INFEASIBLE_EXCEPTIONS);

        final boolean PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES = !AnalysisContext.currentAnalysisContext().getBoolProperty(
                AnalysisFeatures.CONSERVE_SPACE);

        if (PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES && !cfg.isFlagSet(CFG.PRUNED_UNCONDITIONAL_THROWERS)) {
            try {
                JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, descriptor.getClassDescriptor());
                Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
                ConstantPoolGen cpg = analysisCache.getClassAnalysis(ConstantPoolGen.class, descriptor.getClassDescriptor());
                TypeDataflow typeDataflow = analysisCache.getMethodAnalysis(TypeDataflow.class, descriptor);

                PruneUnconditionalExceptionThrowerEdges pruner = new PruneUnconditionalExceptionThrowerEdges(jclass, method,
                        methodGen, cfg, cpg, typeDataflow, AnalysisContext.currentAnalysisContext());
View Full Code Here

    @Override
    public Method analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, descriptor.getClassDescriptor());
        Method[] methodList = jclass.getMethods();

        Method result = null;

        // As a side-effect, cache all of the Methods for this JavaClass
        for (Method method : methodList) {
            MethodDescriptor methodDescriptor = DescriptorFactory.instance().getMethodDescriptor(
                    descriptor.getSlashedClassName(), method.getName(), method.getSignature(), method.isStatic());
View Full Code Here

    @Override
    public UsagesRequiringNonNullValues analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
            throws CheckedAnalysisException {
        // ClassContext classContext = getClassContext(jclass);
        ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, descriptor.getClassDescriptor());
        Method method = getMethod(analysisCache, descriptor);
        return DerefFinder.getAnalysis(classContext, method);
    }
View Full Code Here

     * edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public MethodGen analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        Method method = getMethod(analysisCache, descriptor);

        if (method.getCode() == null) {
            return null;
        }
        XMethod xmethod =  XFactory.createXMethod(descriptor);
        if (xmethod.usesInvokeDynamic() && false) {
            AnalysisContext.currentAnalysisContext().analysisSkippedDueToInvokeDynamic(xmethod);
            return null;
        }

        try {
            AnalysisContext analysisContext = AnalysisContext.currentAnalysisContext();
            JavaClass jclass = getJavaClass(analysisCache, descriptor.getClassDescriptor());
            ConstantPoolGen cpg = getConstantPoolGen(analysisCache, descriptor.getClassDescriptor());

            String methodName = method.getName();
            int codeLength = method.getCode().getLength();
            String superclassName = jclass.getSuperclassName();
            if (codeLength > 6000 && methodName.equals("<clinit>") && superclassName.equals("java.lang.Enum")) {
                analysisContext.getLookupFailureCallback().reportSkippedAnalysis(
                        new JavaClassAndMethod(jclass, method).toMethodDescriptor());
                return null;
View Full Code Here

     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public CompactLocationNumbering analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
            throws CheckedAnalysisException {
        Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);

        if (method.getCode() == null) {
            return null;
        }

        CFG cfg = getCFG(analysisCache, descriptor);
        return new CompactLocationNumbering(cfg);
View Full Code Here

            throw new MethodUnprofitableException(descriptor);
        }
        CFG cfg = getCFG(analysisCache, descriptor);
        DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor);
        ExceptionSetFactory exceptionSetFactory = getExceptionSetFactory(analysisCache, descriptor);
        Method method = getMethod(analysisCache, descriptor);

        TypeAnalysis typeAnalysis = new TypeAnalysis(method, methodGen, cfg, dfs, AnalysisContext.currentAnalysisContext()
                .getLookupFailureCallback(), exceptionSetFactory);

        if (AnalysisContext.currentAnalysisContext().getBoolProperty(AnalysisFeatures.MODEL_INSTANCEOF)) {
View Full Code Here

                        break;
                    }
                }
            }
        } catch (MethodUnprofitableException e) {
            Method m = getMethod();
            bugReporter.reportSkippedAnalysis(DescriptorFactory.instance().getMethodDescriptor(getClassName(), getMethodName(),
                    getMethodSig(), m.isStatic()));
        } catch (DataflowAnalysisException e) {
            bugReporter.logError("Error checking for dead exception store", e);
        } catch (CFGBuilderException e) {
            bugReporter.logError("Error checking for dead exception store", e);
        }
View Full Code Here

            return;
        }
        String sig = getMethodSig();
        if (mName.equals(baseClassName) && sig.equals("()V")) {
            Code code = obj.getCode();
            Method realVoidConstructor = findVoidConstructor(getThisClass());
            if (code != null && !markedAsNotUsable(obj)) {
                int priority = NORMAL_PRIORITY;
                if (codeDoesSomething(code)) {
                    priority--;
                } else if (!obj.isPublic() && getThisClass().isPublic()) {
View Full Code Here

        ExceptionTable et = null;
        if (throws_vec.size() > 0) {
            addAttribute(et = getExceptionTable(cp));
            // Add `Exceptions' if there are "throws" clauses
        }
        Method m = new Method(access_flags, name_index, signature_index, getAttributes(), cp
                .getConstantPool());
        // Undo effects of adding attributes
        if (lvt != null) {
            removeCodeAttribute(lvt);
        }
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Method

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.