Package edu.umd.cs.findbugs.log

Examples of edu.umd.cs.findbugs.log.Profiler


        this.undeterminedBranchSet = new BitSet();
        this.assertionMethods = classContext.getAssertionMethods();
    }

    public void execute() {
        Profiler profiler = Global.getAnalysisCache().getProfiler();
        profiler.start(this.getClass());
        try {
            // Do the null-value analysis
            this.invDataflow = classContext.getIsNullValueDataflow(method);
            this.vnaDataflow = classContext.getValueNumberDataflow(method);
            if (findGuaranteedDerefs) {
                if (DEBUG_DEREFS) {
                    System.out.println("Checking for guaranteed derefs in "
                            + classContext.getClassDescriptor().getDottedClassName() + "." + method.getName()
                            + method.getSignature());
                }
                this.uvdDataflow = classContext.getUnconditionalValueDerefDataflow(method);
            }

            // Check method and report potential null derefs and
            // redundant null comparisons.
            examineBasicBlocks();
            if (findGuaranteedDerefs) {
                examineNullValues();
            }
            examineRedundantBranches();
        } catch (MissingClassException e) {
            AnalysisContext.reportMissingClass(e.getClassNotFoundException());
        } catch (CheckedAnalysisException e) {
            AnalysisContext.logError("Error while checking guaranteed derefs in "
                    + classContext.getClassDescriptor().getDottedClassName() + "." + method.getName() + method.getSignature(), e);
        } finally {
            profiler.end(this.getClass());
        }

    }
View Full Code Here


        }

    }

    public static <E> List<E> sortByCallGraph(Collection<E> elements, OutEdges<E> outEdges) {
        Profiler profile = Global.getAnalysisCache().getProfiler();
        profile.start(TopologicalSort.class);
        try {
            SortAlgorithm<E> instance = new Worker2<E>(elements, outEdges);
            return instance.compute();
        } finally {
            profile.end(TopologicalSort.class);
        }
    }
View Full Code Here

        if (FindBugs.isNoAnalysis()) {
            throw new UnsupportedOperationException("This FindBugs invocation was started without analysis capabilities");
        }

        Profiler profiler = bugReporter.getProjectStats().getProfiler();

        try {
            try {
                // Get the class factory for creating classpath/codebase/etc.
                classFactory = ClassFactory.instance();

                // The class path object
                createClassPath();

                progress.reportNumberOfArchives(project.getFileCount() + project.getNumAuxClasspathEntries());
                profiler.start(this.getClass());

                // The analysis cache object
                createAnalysisCache();

                // Create BCEL compatibility layer
                createAnalysisContext(project, appClassList, analysisOptions.sourceInfoFileName);

                // Discover all codebases in classpath and
                // enumerate all classes (application and non-application)
                buildClassPath();


                // Build set of classes referenced by application classes
                buildReferencedClassSet();

                // Create BCEL compatibility layer
                setAppClassList(appClassList);

                // Configure the BugCollection (if we are generating one)
                FindBugs.configureBugCollection(this);

                // Enable/disabled relaxed reporting mode
                FindBugsAnalysisFeatures.setRelaxedMode(analysisOptions.relaxedReportingMode);
                FindBugsDisplayFeatures.setAbridgedMessages(analysisOptions.abridgedMessages);

                // Configure training databases
                FindBugs.configureTrainingDatabases(this);

                // Configure analysis features
                configureAnalysisFeatures();

                // Create the execution plan (which passes/detectors to execute)
                createExecutionPlan();

                for (Plugin p : detectorFactoryCollection.plugins()) {
                    for (ComponentPlugin<BugReporterDecorator> brp
                            : p.getComponentPlugins(BugReporterDecorator.class)) {
                        if (brp.isEnabledByDefault() && !brp.isNamed(explicitlyDisabledBugReporterDecorators)
                                || brp.isNamed(explicitlyEnabledBugReporterDecorators)) {
                            bugReporter = BugReporterDecorator.construct(brp, bugReporter);
                        }
                    }
                }
                if (!classScreener.vacuous()) {
                    bugReporter = new DelegatingBugReporter(bugReporter) {

                        @Override
                        public void reportBug(@Nonnull BugInstance bugInstance) {
                            String className = bugInstance.getPrimaryClass().getClassName();
                            String resourceName = className.replace('.', '/') + ".class";
                            if (classScreener.matches(resourceName)) {
                                this.getDelegate().reportBug(bugInstance);
                            }
                        }
                    };
                }

                if (executionPlan.isActive(NoteSuppressedWarnings.class)) {
                    SuppressionMatcher m = AnalysisContext.currentAnalysisContext().getSuppressionMatcher();
                    bugReporter = new FilterBugReporter(bugReporter, m, false);
                }

                if (appClassList.size() == 0) {
                    Map<String, ICodeBaseEntry> codebase = classPath.getApplicationCodebaseEntries();
                    if (analysisOptions.noClassOk) {
                        System.err.println("No classfiles specified; output will have no warnings");
                    } else if  (codebase.isEmpty()) {
                        throw new IOException("No files to analyze could be opened");
                    } else {
                        throw new NoClassesFoundToAnalyzeException(classPath);
                    }
                }

                // Analyze the application
                analyzeApplication();
            } catch (CheckedAnalysisException e) {
                IOException ioe = new IOException("IOException while scanning codebases");
                ioe.initCause(e);
                throw ioe;
            } catch (OutOfMemoryError e) {
                System.err.println("Out of memory");
                System.err.println("Total memory: " + Runtime.getRuntime().maxMemory() / 1000000 + "M");
                System.err.println(" free memory: " + Runtime.getRuntime().freeMemory() / 1000000 + "M");

                for (String s : project.getFileList()) {
                    System.err.println("Analyzed: " + s);
                }
                for (String s : project.getAuxClasspathEntryList()) {
                    System.err.println("     Aux: " + s);
                }
                throw e;
            } finally {
                clearCaches();
                profiler.end(this.getClass());
                profiler.report();
            }
        } catch (IOException e) {
            bugReporter.reportQueuedErrors();
            throw e;
        }
View Full Code Here

    /**
     * Analyze the classes in the application codebase.
     */
    private void analyzeApplication() throws InterruptedException {
        int passCount = 0;
        Profiler profiler = bugReporter.getProjectStats().getProfiler();
        profiler.start(this.getClass());
        AnalysisContext.currentXFactory().canonicalizeAll();
        try {
            boolean multiplePasses = executionPlan.getNumPasses() > 1;
            if (executionPlan.getNumPasses() == 0) {
                throw new AssertionError("no analysis passes");
            }
            int[] classesPerPass = new int[executionPlan.getNumPasses()];
            classesPerPass[0] = referencedClassSet.size();
            for (int i = 0; i < classesPerPass.length; i++) {
                classesPerPass[i] = i == 0 ? referencedClassSet.size() : appClassList.size();
            }
            progress.predictPassCount(classesPerPass);
            XFactory factory = AnalysisContext.currentXFactory();
            Collection<ClassDescriptor> badClasses = new LinkedList<ClassDescriptor>();
            for (ClassDescriptor desc : referencedClassSet) {
                try {
                    XClass info = Global.getAnalysisCache().getClassAnalysis(XClass.class, desc);
                    factory.intern(info);
                } catch (CheckedAnalysisException e) {
                    AnalysisContext.logError("Couldn't get class info for " + desc, e);
                    badClasses.add(desc);
                } catch (RuntimeException e) {
                    AnalysisContext.logError("Couldn't get class info for " + desc, e);
                    badClasses.add(desc);
                }
            }
            if (!badClasses.isEmpty()) {
                referencedClassSet = new LinkedHashSet<ClassDescriptor>(referencedClassSet);
                referencedClassSet.removeAll(badClasses);
            }

            long startTime = System.currentTimeMillis();
            bugReporter.getProjectStats().setReferencedClasses(referencedClassSet.size());
            for (Iterator<AnalysisPass> passIterator = executionPlan.passIterator(); passIterator.hasNext();) {
                AnalysisPass pass = passIterator.next();
                yourkitController.advanceGeneration("Pass " + passCount);
                // The first pass is generally a non-reporting pass which
                // gathers information about referenced classes.
                boolean isNonReportingFirstPass = multiplePasses && passCount == 0;

                // Instantiate the detectors
                Detector2[] detectorList = pass.instantiateDetector2sInPass(bugReporter);

                // If there are multiple passes, then on the first pass,
                // we apply detectors to all classes referenced by the
                // application classes.
                // On subsequent passes, we apply detector only to application
                // classes.
                Collection<ClassDescriptor> classCollection = (isNonReportingFirstPass) ? referencedClassSet : appClassList;
                AnalysisContext.currentXFactory().canonicalizeAll();
                if (PROGRESS || LIST_ORDER) {
                    System.out.printf("%6d : Pass %d: %d classes%n", (System.currentTimeMillis() - startTime)/1000, passCount,  classCollection.size());
                    if (DEBUG) {
                        XFactory.profile();
                    }
                }
                if (!isNonReportingFirstPass) {
                    OutEdges<ClassDescriptor> outEdges = new OutEdges<ClassDescriptor>() {

                        @Override
                        public Collection<ClassDescriptor> getOutEdges(ClassDescriptor e) {
                            try {
                                XClass classNameAndInfo = Global.getAnalysisCache().getClassAnalysis(XClass.class, e);
                                return classNameAndInfo.getCalledClassDescriptors();
                            } catch (CheckedAnalysisException e2) {
                                AnalysisContext.logError("error while analyzing " + e.getClassName(), e2);
                                return Collections.emptyList();

                            }
                        }
                    };

                    classCollection = sortByCallGraph(classCollection, outEdges);
                }
                if (LIST_ORDER) {
                    System.out.println("Analysis order:");
                    for (ClassDescriptor c : classCollection) {
                        System.out.println("  " + c);
                    }
                }
                AnalysisContext currentAnalysisContext = AnalysisContext.currentAnalysisContext();
                currentAnalysisContext.updateDatabases(passCount);

                progress.startAnalysis(classCollection.size());
                int count = 0;
                Global.getAnalysisCache().purgeAllMethodAnalysis();
                Global.getAnalysisCache().purgeClassAnalysis(FBClassReader.class);
                for (ClassDescriptor classDescriptor : classCollection) {
                    long classStartNanoTime = 0;
                    if (PROGRESS) {
                        classStartNanoTime = System.nanoTime();
                        System.out.printf("%6d %d/%d  %d/%d %s%n", (System.currentTimeMillis() - startTime)/1000,
                                passCount, executionPlan.getNumPasses(), count,
                                classCollection.size(), classDescriptor);
                    }
                    count++;
                    if (!isNonReportingFirstPass && count % 1000 == 0) {
                        yourkitController.advanceGeneration(String.format("Pass %d.%02d", passCount, count/1000));
                    }


                    // Check to see if class is excluded by the class screener.
                    // In general, we do not want to screen classes from the
                    // first pass, even if they would otherwise be excluded.
                    if ((SCREEN_FIRST_PASS_CLASSES || !isNonReportingFirstPass)
                            && !classScreener.matches(classDescriptor.toResourceName())) {
                        if (DEBUG) {
                            System.out.println("*** Excluded by class screener");
                        }
                        continue;
                    }
                    boolean isHuge = currentAnalysisContext.isTooBig(classDescriptor);
                    if (isHuge && currentAnalysisContext.isApplicationClass(classDescriptor)) {
                        bugReporter.reportBug(new BugInstance("SKIPPED_CLASS_TOO_BIG", Priorities.NORMAL_PRIORITY)
                        .addClass(classDescriptor));
                    }
                    currentClassName = ClassName.toDottedClassName(classDescriptor.getClassName());
                    notifyClassObservers(classDescriptor);
                    profiler.startContext(currentClassName);
                    currentAnalysisContext.setClassBeingAnalyzed(classDescriptor);

                    try {
                        for (Detector2 detector : detectorList) {
                            if (Thread.interrupted()) {
                                throw new InterruptedException();
                            }
                            if (isHuge && !FirstPassDetector.class.isAssignableFrom(detector.getClass())) {
                                continue;
                            }
                            if (DEBUG) {
                                System.out.println("Applying " + detector.getDetectorClassName() + " to " + classDescriptor);
                                // System.out.println("foo: " +
                                // NonReportingDetector.class.isAssignableFrom(detector.getClass())
                                // + ", bar: " + detector.getClass().getName());
                            }
                            try {
                                profiler.start(detector.getClass());
                                detector.visitClass(classDescriptor);
                            } catch (ClassFormatException e) {
                                logRecoverableException(classDescriptor, detector, e);
                            } catch (MissingClassException e) {
                                Global.getAnalysisCache().getErrorLogger().reportMissingClass(e.getClassDescriptor());
                            } catch (CheckedAnalysisException e) {
                                logRecoverableException(classDescriptor, detector, e);
                            } catch (RuntimeException e) {
                                logRecoverableException(classDescriptor, detector, e);
                            } finally {
                                profiler.end(detector.getClass());
                            }
                        }
                    } finally {

                        progress.finishClass();
                        profiler.endContext(currentClassName);
                        currentAnalysisContext.clearClassBeingAnalyzed();
                        if (PROGRESS) {
                            long usecs = (System.nanoTime() - classStartNanoTime)/1000;
                            if (usecs > 15000) {
                                int classSize = currentAnalysisContext.getClassSize(classDescriptor);
                                long speed = usecs /classSize;
                                if (speed > 15) {
                                    System.out.printf("  %6d usecs/byte  %6d msec  %6d bytes  %d pass %s%n", speed, usecs/1000, classSize, passCount,
                                            classDescriptor);
                                }
                            }

                        }
                    }
                }

                if (!passIterator.hasNext()) {
                    yourkitController.captureMemorySnapshot();
                }
                // Call finishPass on each detector
                for (Detector2 detector : detectorList) {
                    detector.finishPass();
                }

                progress.finishPerClassAnalysis();

                passCount++;
            }


        } finally {

            bugReporter.finish();
            bugReporter.reportQueuedErrors();
            profiler.end(this.getClass());
            if (PROGRESS) {
                System.out.println("Analysis completed");
            }
        }

View Full Code Here

    @CheckForNull
    @Override
    public NullnessAnnotation getResolvedAnnotation(final Object o, boolean getMinimal) {

        Profiler profiler = Global.getAnalysisCache().getProfiler();
        profiler.start(this.getClass());
        try {
            if (o instanceof XMethodParameter) {
                XMethodParameter mp = (XMethodParameter) o;
                XMethod m = mp.getMethod();
                // TODO: Handle argument to equals specially: generate special
                // bug code for it
                int parameterNumber = mp.getParameterNumber();
                if (parameterNumber == 0) {
                    if (m.getName().equals("equals") && m.getSignature().equals("(Ljava/lang/Object;)Z") && !m.isStatic()) {
                        return NullnessAnnotation.CHECK_FOR_NULL;
                    } else if (m.getName().equals("main") && m.getSignature().equals("([Ljava/lang/String;)V") && m.isStatic()
                            && m.isPublic()) {
                        return NullnessAnnotation.NONNULL;
                    } else if (TypeQualifierNullnessAnnotationDatabase.assertsFirstParameterIsNonnull(m)) {
                        return NullnessAnnotation.NONNULL;
                    } else if (m.getName().equals("compareTo") && m.getSignature().endsWith(";)Z") && !m.isStatic()) {
                        return NullnessAnnotation.NONNULL;
                    }
                }
            } else if (o instanceof XMethod) {
                XMethod m = (XMethod) o;
                String name = m.getName();
                String signature = m.getSignature();
                if (!m.isStatic()
                        && (name.equals("clone") && signature.equals("()Ljava/lang/Object;") || name.equals("toString")
                                && signature.equals("()Ljava/lang/String;") || m.isPrivate() && name.equals("readResolve")
                                && signature.equals("()Ljava/lang/Object;"))) {
                    NullnessAnnotation result = super.getDirectAnnotation(m);
                    if (result != null) {
                        return result;
                    }
                    return NullnessAnnotation.NONNULL;
                }

            } else if (o instanceof XField) {
                XField f = (XField) o;
                if (f.getName().startsWith("this$")) {
                    return NullnessAnnotation.NONNULL;
                }
            }
            NullnessAnnotation result = super.getResolvedAnnotation(o, getMinimal);
            return result;
        } finally {
            profiler.end(this.getClass());
        }
    }
View Full Code Here

    public ProjectStats() {
        this.packageStatsMap = new TreeMap<String, PackageStats>();
        this.totalClasses = 0;
        this.analysisTimestamp = new Date();
        this.baseFootprint = new Footprint();
        this.profiler = new Profiler();
    }
View Full Code Here

    private void doReadXML(@WillClose Reader reader, @CheckForNull File base) throws IOException, DocumentException {
        timeStartedLoading = System.currentTimeMillis();

        SAXBugCollectionHandler handler = new SAXBugCollectionHandler(this, base);
        Profiler profiler = getProjectStats().getProfiler();
        profiler.start(handler.getClass());
        try {

            XMLReader xr;
            try {
                xr = XMLReaderFactory.createXMLReader();
            } catch (SAXException e) {
                AnalysisContext.logError("Couldn't create XMLReaderFactory", e);
                throw new DocumentException("Sax error ", e);
            }
            xr.setContentHandler(handler);
            xr.setErrorHandler(handler);

            xr.parse(new InputSource(reader));
        } catch (SAXParseException e) {
            if (base != null) {
                throw new DocumentException("Parse error at line " + e.getLineNumber() + " : " + e.getColumnNumber() + " of "
                        + base, e);
            }
            throw new DocumentException("Parse error at line " + e.getLineNumber() + " : " + e.getColumnNumber(), e);
        } catch (SAXException e) {
            // FIXME: throw SAXException from method?
            if (base != null) {
                throw new DocumentException("Sax error while parsing " + base, e);
            }
            throw new DocumentException("Sax error ", e);
        } finally {
            Util.closeSilently(reader);
            profiler.end(handler.getClass());
        }
        timeFinishedLoading = System.currentTimeMillis();
        bugsPopulated();
        // Presumably, project is now up-to-date
        project.setModified(false);
View Full Code Here

                ResourceValueAnalysis<Resource> analysis = new ResourceValueAnalysis<Resource>(methodGen, cfg, dfs,
                        resourceTracker, resource);
                Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>> dataflow = new Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>>(
                        cfg, analysis);

                Profiler profiler = Global.getAnalysisCache().getProfiler();
                profiler.start(resourceTracker.getClass());
                try {
                    dataflow.execute();
                } finally {
                    profiler.end(resourceTracker.getClass());
                }
                inspectResult(classContext, methodGen, cfg, dataflow, resource);
            }
        } catch (RuntimeException e) {
            AnalysisContext.logError("Exception while analyzing " + methodGen.getClassName() + "." + methodGen.getName() + ":"
View Full Code Here

        // Just get the ClassContext from the analysis cache
        // and apply the detector to it.

        IAnalysisCache analysisCache = Global.getAnalysisCache();
        ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, classDescriptor);
        Profiler profiler = analysisCache.getProfiler();
        profiler.start(detector.getClass());
        try {
            detector.visitClassContext(classContext);
        } finally {
            profiler.end(detector.getClass());
        }
    }
View Full Code Here

        RefComparisonTypeFrameModelingVisitor visitor = new RefComparisonTypeFrameModelingVisitor(methodGen.getConstantPool(),
                typeMerger, bugReporter);
        TypeAnalysis typeAnalysis = new SpecialTypeAnalysis(method, methodGen, cfg, dfs, typeMerger, visitor, bugReporter,
                exceptionSetFactory);
        TypeDataflow typeDataflow = new TypeDataflow(cfg, typeAnalysis);
        Profiler profiler = Global.getAnalysisCache().getProfiler();
        profiler.start(SpecialTypeAnalysis.class);
        try {
            typeDataflow.execute();
        } finally {
            profiler.end(SpecialTypeAnalysis.class);
        }

        // Inspect Locations in the method for suspicious ref comparisons and
        // calls to equals()
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.log.Profiler

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.