⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classcontext.java

📁 A static analysis tool to find bugs in Java programs
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					// Create callback					UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);					// Scan the method.					BytecodeScanner scanner = new BytecodeScanner();					scanner.scan(instructionList, callback);					return callback.getUnpackedCode();				}			};	private AnalysisFactory<LockDataflow> lockDataflowFactory =			new DataflowAnalysisFactory<LockDataflow>("lock set analysis") {				@Override						 protected LockDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {					MethodGen methodGen = getMethodGen(method);					if (methodGen == null) throw new MethodUnprofitableException(getJavaClass(),method);					ValueNumberDataflow vnaDataflow = getValueNumberDataflow(method);					DepthFirstSearch dfs = getDepthFirstSearch(method);					CFG cfg = getCFG(method);					LockAnalysis analysis = new LockAnalysis(methodGen, vnaDataflow, dfs);					LockDataflow dataflow = new LockDataflow(cfg, analysis);					dataflow.execute();					return dataflow;				}			};	private AnalysisFactory<LockChecker> lockCheckerFactory =			new DataflowAnalysisFactory<LockChecker>("lock checker meta-analysis") {				/* (non-Javadoc)				 * @see edu.umd.cs.findbugs.ba.ClassContext.AnalysisFactory#analyze(org.apache.bcel.classfile.Method)				 */				@Override								 protected LockChecker analyze(Method method) throws CFGBuilderException,						DataflowAnalysisException {					LockChecker lockChecker = new LockChecker(ClassContext.this, method);					lockChecker.execute();					return lockChecker;				}			};	private AnalysisFactory<ReturnPathDataflow> returnPathDataflowFactory =			new DataflowAnalysisFactory<ReturnPathDataflow>("return path analysis") {				@Override						 protected ReturnPathDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {					CFG cfg = getCFG(method);					DepthFirstSearch dfs = getDepthFirstSearch(method);					ReturnPathAnalysis analysis = new ReturnPathAnalysis(dfs);					ReturnPathDataflow dataflow = new ReturnPathDataflow(cfg, analysis);					dataflow.execute();					return dataflow;				}			};	private AnalysisFactory<DominatorsAnalysis> nonExceptionDominatorsAnalysisFactory =			new DataflowAnalysisFactory<DominatorsAnalysis>("non-exception dominators analysis") {				@Override						 protected DominatorsAnalysis analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {					CFG cfg = getCFG(method);					DepthFirstSearch dfs = getDepthFirstSearch(method);					DominatorsAnalysis analysis = new DominatorsAnalysis(cfg, dfs, true);					Dataflow<java.util.BitSet, DominatorsAnalysis> dataflow =							new Dataflow<java.util.BitSet, DominatorsAnalysis>(cfg, analysis);					dataflow.execute();					return analysis;				}			};	private AnalysisFactory<PostDominatorsAnalysis> nonExceptionPostDominatorsAnalysisFactory =			new DataflowAnalysisFactory<PostDominatorsAnalysis>("non-exception postdominators analysis") {				@Override						 protected PostDominatorsAnalysis analyze(Method method) throws DataflowAnalysisException, CFGBuilderException {					CFG cfg = getCFG(method);					ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(method);					PostDominatorsAnalysis analysis = new PostDominatorsAnalysis(cfg, rdfs, getDepthFirstSearch(method), true);					Dataflow<java.util.BitSet, PostDominatorsAnalysis> dataflow =							new Dataflow<java.util.BitSet, PostDominatorsAnalysis>(cfg, analysis);					dataflow.execute();					return analysis;				}			};	private AnalysisFactory<PostDominatorsAnalysis> nonImplicitExceptionPostDominatorsAnalysisFactory =		new DataflowAnalysisFactory<PostDominatorsAnalysis>("non-implicit-exception postdominators analysis") {			@Override						 protected PostDominatorsAnalysis analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				CFG cfg = getCFG(method);				PostDominatorsAnalysis analysis = new PostDominatorsAnalysis(						cfg,						getReverseDepthFirstSearch(method),						getDepthFirstSearch(method), new EdgeChooser() {					public boolean choose(Edge edge) {						return !edge.isExceptionEdge()							||  edge.isFlagSet(EdgeTypes.EXPLICIT_EXCEPTIONS_FLAG);						}					}				);				Dataflow<BitSet, PostDominatorsAnalysis> dataflow =					new Dataflow<BitSet, PostDominatorsAnalysis>(cfg, analysis);				dataflow.execute();				return analysis;			}		};	private NoExceptionAnalysisFactory<ExceptionSetFactory> exceptionSetFactoryFactory =			new NoExceptionAnalysisFactory<ExceptionSetFactory>("exception set factory") {				@Override						 protected ExceptionSetFactory analyze(Method method) {					return new ExceptionSetFactory();				}			};	private NoExceptionAnalysisFactory<String[]> parameterSignatureListFactory =			new NoExceptionAnalysisFactory<String[]>("parameter signature list factory") {				@Override						 protected String[] analyze(Method method) {					SignatureParser parser = new SignatureParser(method.getSignature());					ArrayList<String> resultList = new ArrayList<String>();					for (Iterator<String> i = parser.parameterSignatureIterator(); i.hasNext();) {						resultList.add(i.next());					}					return resultList.toArray(new String[resultList.size()]);				}			};	private AnalysisFactory<ConstantDataflow> constantDataflowFactory =		new DataflowAnalysisFactory<ConstantDataflow>("constant propagation analysis") {			@Override @CheckForNull			protected ConstantDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				MethodGen methodGen = getMethodGen(method);				if (methodGen == null) return null;				ConstantAnalysis analysis = new ConstantAnalysis(					methodGen,					getDepthFirstSearch(method)				);				ConstantDataflow dataflow = new ConstantDataflow(getCFG(method), analysis);				dataflow.execute();				return dataflow;			}		};//	private AnalysisFactory<UnconditionalDerefDataflow> unconditionalDerefDataflowFactory =//		new DataflowAnalysisFactory<UnconditionalDerefDataflow>("unconditional deref analysis") {//			@Override @CheckForNull//			protected UnconditionalDerefDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {//				MethodGen methodGen = getMethodGen(method);//				if (methodGen == null)//					return null;//				CFG cfg = getCFG(method); //				//	//				UnconditionalDerefAnalysis analysis = new UnconditionalDerefAnalysis(//						getReverseDepthFirstSearch(method),//						getDepthFirstSearch(method),//						cfg,//						methodGen,//						getValueNumberDataflow(method),//						getTypeDataflow(method));//				UnconditionalDerefDataflow dataflow = new UnconditionalDerefDataflow(cfg, analysis);//				//				dataflow.execute();//				//				return dataflow;//			}//		};	private AnalysisFactory<LoadDataflow> loadDataflowFactory =		new DataflowAnalysisFactory<LoadDataflow>("field load analysis") {			@Override @CheckForNull			protected LoadDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				MethodGen methodGen = getMethodGen(method);				if (methodGen == null)					return null;				LoadAnalysis analysis = new LoadAnalysis(						getDepthFirstSearch(method),						getConstantPoolGen()						);				LoadDataflow dataflow = new LoadDataflow(getCFG(method), analysis);				dataflow.execute();				return dataflow;			}		};	private AnalysisFactory<StoreDataflow> storeDataflowFactory =		new DataflowAnalysisFactory<StoreDataflow>("field store analysis") {			@Override @CheckForNull			protected StoreDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				MethodGen methodGen = getMethodGen(method);				if (methodGen == null)					return null;				StoreAnalysis analysis = new StoreAnalysis(						getDepthFirstSearch(method),						getConstantPoolGen()						);				StoreDataflow dataflow = new StoreDataflow(getCFG(method), analysis);				dataflow.execute();				return dataflow;			}		};	private static final BitSet fieldInstructionOpcodeSet = new BitSet();	static {		fieldInstructionOpcodeSet.set(Constants.GETFIELD);		fieldInstructionOpcodeSet.set(Constants.PUTFIELD);		fieldInstructionOpcodeSet.set(Constants.GETSTATIC);		fieldInstructionOpcodeSet.set(Constants.PUTSTATIC);	}	/**	 * Factory to determine which fields are loaded and stored	 * by the instructions in a method, and the overall method.	 * The main purpose is to support efficient redundant load elimination	 * and forward substitution in ValueNumberAnalysis (there is no need to	 * remember stores of fields that are never read,	 * or loads of fields that are only loaded in one location).	 * However, it might be useful for other kinds of analysis.	 *	 * <p> The tricky part is that in addition to fields loaded and stored	 * with get/putfield and get/putstatic, we also try to figure	 * out field accessed through calls to inner-class access methods.	 */	private NoExceptionAnalysisFactory<LoadedFieldSet> loadedFieldSetFactory =			new NoExceptionAnalysisFactory<LoadedFieldSet>("loaded field set factory") {				@Override								 protected LoadedFieldSet analyze(Method method) {					MethodGen methodGen = getMethodGen(method);					if (methodGen == null) return null;					InstructionList il = methodGen.getInstructionList();					LoadedFieldSet loadedFieldSet = new LoadedFieldSet(methodGen);					for (InstructionHandle handle = il.getStart(); handle != null; handle = handle.getNext()) {						Instruction ins = handle.getInstruction();						short opcode = ins.getOpcode();						try {							if (opcode == Constants.INVOKESTATIC) {								INVOKESTATIC inv = (INVOKESTATIC) ins;								if (Hierarchy.isInnerClassAccess(inv, getConstantPoolGen())) {									InnerClassAccess access = Hierarchy.getInnerClassAccess(inv, getConstantPoolGen());/*									if (access == null) {										System.out.println("Missing inner class access in " +											SignatureConverter.convertMethodSignature(methodGen) + " at " +											inv);									}*/									if (access != null) {										if (access.isLoad())											loadedFieldSet.addLoad(handle, access.getField());										else											loadedFieldSet.addStore(handle, access.getField());									}								}							} else if (fieldInstructionOpcodeSet.get(opcode)) {								boolean isLoad = (opcode == Constants.GETFIELD || opcode == Constants.GETSTATIC);								XField field = Hierarchy.findXField((FieldInstruction) ins, getConstantPoolGen());								if (field != null) {									if (isLoad)										loadedFieldSet.addLoad(handle, field);									else										loadedFieldSet.addStore(handle, field);								}							}						} catch (ClassNotFoundException e) {							analysisContext.getLookupFailureCallback().reportMissingClass(e);						}					}					return loadedFieldSet;				}			};	private AnalysisFactory<LiveLocalStoreDataflow> liveLocalStoreDataflowFactory =			new DataflowAnalysisFactory<LiveLocalStoreDataflow>("live local stores analysis") {				@Override								 protected LiveLocalStoreDataflow analyze(Method method)					throws DataflowAnalysisException, CFGBuilderException {						MethodGen methodGen = getMethodGen(method);						if (methodGen == null) return null;						CFG cfg = getCFG(method);						ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(method);						LiveLocalStoreAnalysis analysis = new LiveLocalStoreAnalysis(methodGen, rdfs, getDepthFirstSearch(method));						LiveLocalStoreDataflow dataflow = new LiveLocalStoreDataflow(cfg, analysis);						dataflow.execute();						return dataflow;				}			};	private AnalysisFactory<Dataflow<BlockType, BlockTypeAnalysis>> blockTypeDataflowFactory =			new DataflowAnalysisFactory<Dataflow<BlockType, BlockTypeAnalysis>>("block type analysis") {				@Override								 protected Dataflow<BlockType, BlockTypeAnalysis> analyze(Method method)						throws DataflowAnalysisException, CFGBuilderException {					CFG cfg = getCFG(method);					DepthFirstSearch dfs = getDepthFirstSearch(method);					BlockTypeAnalysis analysis = new BlockTypeAnalysis(dfs);					Dataflow<BlockType, BlockTypeAnalysis> dataflow =						new Dataflow<BlockType, BlockTypeAnalysis>(cfg, analysis);					dataflow.execute();					return dataflow;				}			};	private AnalysisFactory<CallListDataflow> callListDataflowFactory =		new DataflowAnalysisFactory<CallListDataflow>("call list analysis") {			@Override						 protected CallListDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				CallListAnalysis analysis = new CallListAnalysis(						getCFG(method),						getDepthFirstSearch(method),						getConstantPoolGen());				CallListDataflow dataflow = new CallListDataflow(getCFG(method), analysis);				dataflow.execute();				return dataflow;			}		};	private AnalysisFactory<UnconditionalValueDerefDataflow> unconditionalValueDerefDataflowFactory =		new DataflowAnalysisFactory<UnconditionalValueDerefDataflow>("unconditional value dereference analysis") {			/* (non-Javadoc)			 * @see edu.umd.cs.findbugs.ba.ClassContext.AnalysisFactory#analyze(org.apache.bcel.classfile.Method)			 */			@Override			protected UnconditionalValueDerefDataflow analyze(Method method) throws CFGBuilderException, DataflowAnalysisException {				CFG cfg = getCFG(method);				ValueNumberDataflow vnd = getValueNumberDataflow(method);				UnconditionalValueDerefAnalysis analysis = new UnconditionalValueDerefAnalysis(						getReverseDepthFirstSearch(method),						getDepthFirstSearch(method),						cfg,						method,						getMethodGen(method), vnd, getAssertionMethods()						);				IsNullValueDataflow inv = getIsNullValueDataflow(method);				// XXX: hack to clear derefs on not-null branches				analysis.clearDerefsOnNonNullBranches(inv);				TypeDataflow typeDataflow = getTypeDataflow(method);				// XXX: type analysis is needed to resolve method calls for				// checking whether call targets unconditionally dereference parameters				analysis.setTypeDataflow(typeDataflow);				UnconditionalValueDerefDataflow dataflow =					new UnconditionalValueDerefDataflow(getCFG(method), analysis);				dataflow.execute();				 if (UnconditionalValueDerefAnalysis.DEBUG) {						dumpDataflowInformation(method, cfg, vnd, inv, dataflow, typeDataflow);					}				return dataflow;			}		};	private NoDataflowAnalysisFactory<CompactLocationNumbering> compactLocationNumberingFactory =		new NoDataflowAnalysisFactory<CompactLocationNumbering>("compact location numbering") {		/* (non-Javadoc)		 * @see edu.umd.cs.findbugs.ba.ClassContext.AnalysisFactory#analyze(org.apache.bcel.classfile.Method)		 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -