Class AnalysisCache
java.lang.Object
edu.umd.cs.findbugs.classfile.impl.AnalysisCache
- All Implemented Interfaces:
IAnalysisCache
Implementation of IAnalysisCache. This object is responsible for registering
class and method analysis engines and caching analysis results.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<?, ?> private final BugReporterprivate final Map<Class<?>, IClassAnalysisEngine<?>> private final Map<Class<?>, Map<ClassDescriptor, Object>> private final IClassPathprivate final Map<Class<?>, IDatabaseFactory<?>> private static final intMaximum number of results to cache.private static final intMaximum number of class analysis results to cache.private static final intprivate static final intprivate static final intprivate final Map<Class<?>, IMethodAnalysisEngine<?>> (package private) static final AnalysisCache.AbnormalAnalysisResult -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate <E> EanalyzeMethod(ClassContext classContext, Class<E> analysisClass, MethodDescriptor methodDescriptor) Analyze a method.(package private) static <E> EcheckedCast(Class<E> analysisClass, Object o) createMap(Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, Class<?> analysisClass) voiddispose()Cleans up all cached data<E> voideagerlyPutDatabase(Class<E> databaseClass, E database) Eagerly install a database.<E> voideagerlyPutMethodAnalysis(Class<E> analysisClass, MethodDescriptor methodDescriptor, E analysisObject) Eagerly put a method analysis object in the cache.findOrCreateDescriptorMap(Map<Class<?>, Map<DescriptorType, Object>> analysisClassToDescriptorMapMap, Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, Class<?> analysisClass) Find or create a descriptor to analysis object map.private <E> Map<ClassDescriptor, E> getAllClassAnalysis(Class<E> analysisClass) final Map<?, ?> Get map of analysis-local objects.getClassAnalysis(Class<?> analysisClass) <E> EgetClassAnalysis(Class<E> analysisClass, ClassDescriptor classDescriptor) Get an analysis of the given class.Get the classpath from which classes are loaded.<E> EgetDatabase(Class<E> databaseClass) Get a database.<E> EgetDatabase(Class<E> databaseClass, boolean optional) Get the error logger.<E> EgetMethodAnalysis(Class<E> analysisClass, MethodDescriptor methodDescriptor) Get an analysis of the given method.<E> EgetOptionalDatabase(Class<E> databaseClass) Get the analysis profiler instance, never null(package private) String<E> EprobeClassAnalysis(Class<E> analysisClass, ClassDescriptor classDescriptor) See if the cache contains a cached class analysis result for given class descriptor.voidPurge all method analysis results for all methods.voidpurgeClassAnalysis(Class<?> analysisClass) Purge all class analysis results of a particular kindvoidpurgeMethodAnalyses(MethodDescriptor methodDescriptor) Purge all analysis results for given method.<E> voidregisterClassAnalysisEngine(Class<E> analysisResultType, IClassAnalysisEngine<E> classAnalysisEngine) Register the given class analysis engine as producing the analysis result type whose Class is given.<E> voidregisterDatabaseFactory(Class<E> databaseClass, IDatabaseFactory<E> databaseFactory) Register a database factory.<E> voidregisterMethodAnalysisEngine(Class<E> analysisResultType, IMethodAnalysisEngine<E> methodAnalysisEngine) Register the given method analysis engine as producing the analysis result type whose Class is given.<E> voidreuseClassAnalysis(Class<E> analysisClass, Map<ClassDescriptor, Object> map) Adds the data for given analysis type from given map to the cache
-
Field Details
-
MAX_JAVACLASS_RESULTS_TO_CACHE
private static final int MAX_JAVACLASS_RESULTS_TO_CACHE- See Also:
-
MAX_FBCLASSREADER_RESULTS_TO_CACHE
private static final int MAX_FBCLASSREADER_RESULTS_TO_CACHE- See Also:
-
MAX_CONSTANT_POOL_GEN_RESULTS_TO_CACHE
private static final int MAX_CONSTANT_POOL_GEN_RESULTS_TO_CACHE- See Also:
-
MAX_CLASS_RESULTS_TO_CACHE
private static final int MAX_CLASS_RESULTS_TO_CACHEMaximum number of class analysis results to cache.- See Also:
-
DEFAULT_RESULTS_TO_CACHE
private static final int DEFAULT_RESULTS_TO_CACHEMaximum number of results to cache. Plugins such as FindSecBugs are using the cache and using an unbounded map can lead to OOM errors on large projects- See Also:
-
classPath
-
bugReporter
-
classAnalysisEngineMap
-
methodAnalysisEngineMap
-
databaseFactoryMap
-
classAnalysisMap
-
databaseMap
-
analysisLocals
-
NULL_ANALYSIS_RESULT
-
-
Constructor Details
-
AnalysisCache
AnalysisCache(IClassPath classPath, BugReporter errorLogger) Constructor.- Parameters:
classPath- the IClassPath to load resources fromerrorLogger- the IErrorLogger
-
-
Method Details
-
getAnalysisLocals
Description copied from interface:IAnalysisCacheGet map of analysis-local objects.- Specified by:
getAnalysisLocalsin interfaceIAnalysisCache
-
checkedCast
-
getClassPath
Description copied from interface:IAnalysisCacheGet the classpath from which classes are loaded.- Specified by:
getClassPathin interfaceIAnalysisCache- Returns:
- the classpath
-
purgeAllMethodAnalysis
public void purgeAllMethodAnalysis()Description copied from interface:IAnalysisCachePurge all method analysis results for all methods.- Specified by:
purgeAllMethodAnalysisin interfaceIAnalysisCache
-
getAllClassAnalysis
-
purgeClassAnalysis
Description copied from interface:IAnalysisCachePurge all class analysis results of a particular kind- Specified by:
purgeClassAnalysisin interfaceIAnalysisCache
-
dispose
public void dispose()Cleans up all cached data -
getClassAnalysis
- Parameters:
analysisClass- non null analysis type- Returns:
- map with analysis data for given type, can be null
-
reuseClassAnalysis
Adds the data for given analysis type from given map to the cache- Parameters:
analysisClass- non null analysis typemap- non null, pre-filled map with analysis data for given type
-
getClassAnalysis
public <E> E getClassAnalysis(Class<E> analysisClass, @Nonnull ClassDescriptor classDescriptor) throws CheckedAnalysisException Description copied from interface:IAnalysisCacheGet an analysis of the given class.- Specified by:
getClassAnalysisin interfaceIAnalysisCache- Type Parameters:
E- the type of the analysis (e.g., FoobarAnalysis)- Parameters:
analysisClass- the analysis class object (e.g., FoobarAnalysis.class)classDescriptor- the descriptor of the class to analyze- Returns:
- the analysis object (e.g., instance of FoobarAnalysis for the class)
- Throws:
CheckedAnalysisException- if an error occurs performing the analysis
-
probeClassAnalysis
Description copied from interface:IAnalysisCacheSee if the cache contains a cached class analysis result for given class descriptor.- Specified by:
probeClassAnalysisin interfaceIAnalysisCache- Parameters:
analysisClass- analysis result classclassDescriptor- the class descriptor- Returns:
- a cached analysis result, or null if there is no cached analysis result
-
hex
-
getMethodAnalysis
public <E> E getMethodAnalysis(Class<E> analysisClass, @Nonnull MethodDescriptor methodDescriptor) throws CheckedAnalysisException Description copied from interface:IAnalysisCacheGet an analysis of the given method.- Specified by:
getMethodAnalysisin interfaceIAnalysisCache- Type Parameters:
E- the type of the analysis (e.g., FoobarAnalysis)- Parameters:
analysisClass- the analysis class object (e.g., FoobarAnalysis.class)methodDescriptor- the descriptor of the method to analyze- Returns:
- the analysis object (e.g., instance of FoobarAnalysis for the method)
- Throws:
CheckedAnalysisException- if an error occurs performing the analysis
-
analyzeMethod
private <E> E analyzeMethod(ClassContext classContext, Class<E> analysisClass, MethodDescriptor methodDescriptor) throws CheckedAnalysisException Analyze a method.- Parameters:
classContext- ClassContext storing method analysis objects for method's classanalysisClass- class the method analysis object should belong tomethodDescriptor- method descriptor identifying the method to analyze- Returns:
- the computed analysis object for the method
- Throws:
CheckedAnalysisException
-
eagerlyPutMethodAnalysis
public <E> void eagerlyPutMethodAnalysis(Class<E> analysisClass, @Nonnull MethodDescriptor methodDescriptor, E analysisObject) Description copied from interface:IAnalysisCacheEagerly put a method analysis object in the cache. This can be necessary if an method analysis engine invokes other analysis engines that might recursively require the analysis being produced.- Specified by:
eagerlyPutMethodAnalysisin interfaceIAnalysisCache- Type Parameters:
E- the type of the analysis (e.g., FoobarAnalysis)- Parameters:
analysisClass- the analysis class object (e.g., FoobarAnalysis.class)methodDescriptor- the descriptor of the method to analyzeanalysisObject-
-
purgeMethodAnalyses
Description copied from interface:IAnalysisCachePurge all analysis results for given method. This can be called when a CFG is pruned and we want to compute more accurate analysis results on the new CFG.- Specified by:
purgeMethodAnalysesin interfaceIAnalysisCache- Parameters:
methodDescriptor- method whose analysis results should be purged
-
findOrCreateDescriptorMap
private static <DescriptorType> Map<DescriptorType, Object> findOrCreateDescriptorMap(Map<Class<?>, Map<DescriptorType, Object>> analysisClassToDescriptorMapMap, Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, Class<?> analysisClass) Find or create a descriptor to analysis object map.- Type Parameters:
DescriptorType- type of descriptor used as the map's key type (ClassDescriptor or MethodDescriptor)- Parameters:
analysisClassToDescriptorMapMap- analysis class to descriptor map mapengineMap- analysis class to analysis engine mapanalysisClass- the analysis map- Returns:
- the descriptor to analysis object map
-
createMap
-
registerClassAnalysisEngine
public <E> void registerClassAnalysisEngine(Class<E> analysisResultType, IClassAnalysisEngine<E> classAnalysisEngine) Description copied from interface:IAnalysisCacheRegister the given class analysis engine as producing the analysis result type whose Class is given.- Specified by:
registerClassAnalysisEnginein interfaceIAnalysisCache- Type Parameters:
E- analysis result type- Parameters:
analysisResultType- analysis result type Class objectclassAnalysisEngine- the class analysis engine to register
-
registerMethodAnalysisEngine
public <E> void registerMethodAnalysisEngine(Class<E> analysisResultType, IMethodAnalysisEngine<E> methodAnalysisEngine) Description copied from interface:IAnalysisCacheRegister the given method analysis engine as producing the analysis result type whose Class is given.- Specified by:
registerMethodAnalysisEnginein interfaceIAnalysisCache- Type Parameters:
E- analysis result type- Parameters:
analysisResultType- analysis result type Class objectmethodAnalysisEngine- the method analysis engine to register
-
registerDatabaseFactory
public <E> void registerDatabaseFactory(Class<E> databaseClass, IDatabaseFactory<E> databaseFactory) Description copied from interface:IAnalysisCacheRegister a database factory.- Specified by:
registerDatabaseFactoryin interfaceIAnalysisCache- Type Parameters:
E- type of database- Parameters:
databaseClass- Class of databasedatabaseFactory- the database factory
-
getDatabase
Description copied from interface:IAnalysisCacheGet a database. Note: an unchecked analysis exception will be thrown if the database cannot be instantiated. Since instantiation of most kinds of databases simply involves creating an object (and not opening a file or other failure-prone operation), throwing a CheckedAnalysisException creates too great of an exception-handling burden on analyses and detectors which use databases.- Specified by:
getDatabasein interfaceIAnalysisCache- Type Parameters:
E- type of database- Parameters:
databaseClass- Class of database- Returns:
- the database (which is created by a database factory if required)
-
getOptionalDatabase
- Specified by:
getOptionalDatabasein interfaceIAnalysisCache
-
getDatabase
-
eagerlyPutDatabase
Description copied from interface:IAnalysisCacheEagerly install a database. This avoids the need to register a database factory.- Specified by:
eagerlyPutDatabasein interfaceIAnalysisCache- Type Parameters:
E- type of database- Parameters:
databaseClass- Class of databasedatabase- database object
-
getErrorLogger
Description copied from interface:IAnalysisCacheGet the error logger.- Specified by:
getErrorLoggerin interfaceIAnalysisCache- Returns:
- the error logger
-
getProfiler
Description copied from interface:IAnalysisCacheGet the analysis profiler instance, never null- Specified by:
getProfilerin interfaceIAnalysisCache
-