📄 classcontext.java
字号:
try { new PruneUnconditionalExceptionThrowerEdges(methodGen, cfg, getConstantPoolGen(), analysisContext).execute(); } catch (DataflowAnalysisException e) { // FIXME: should report the error } } cfg.setFlags(cfg.getFlags() | PRUNED_UNCONDITIONAL_THROWERS); busyCFGSet.remove(methodId); return cfg; } protected CFG analyze(Method method) throws CFGBuilderException { MethodGen methodGen = getMethodGen(method); CFGBuilder cfgBuilder = CFGBuilderFactory.create(methodGen); cfgBuilder.build(); return cfgBuilder.getCFG(); } } /* ---------------------------------------------------------------------- * Fields * ---------------------------------------------------------------------- */ private JavaClass jclass; private AnalysisContext analysisContext; private NoExceptionAnalysisFactory<MethodGen> methodGenFactory = new NoExceptionAnalysisFactory<MethodGen>("MethodGen construction") { protected MethodGen analyze(Method method) { if (method.getCode() == null) return null; return new MethodGen(method, jclass.getClassName(), getConstantPoolGen()); } }; private CFGFactory cfgFactory = new CFGFactory(); private AnalysisFactory<ValueNumberDataflow> vnaDataflowFactory = new AnalysisFactory<ValueNumberDataflow>("value number analysis") { protected ValueNumberDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { MethodGen methodGen = getMethodGen(method); DepthFirstSearch dfs = getDepthFirstSearch(method); LoadedFieldSet loadedFieldSet = getLoadedFieldSet(method); ValueNumberAnalysis analysis = new ValueNumberAnalysis(methodGen, dfs, loadedFieldSet, getLookupFailureCallback()); CFG cfg = getCFG(method); ValueNumberDataflow vnaDataflow = new ValueNumberDataflow(cfg, analysis); vnaDataflow.execute(); return vnaDataflow; } }; private AnalysisFactory<IsNullValueDataflow> invDataflowFactory = new AnalysisFactory<IsNullValueDataflow>("null value analysis") { protected IsNullValueDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { MethodGen methodGen = getMethodGen(method); CFG cfg = getCFG(method); ValueNumberDataflow vnaDataflow = getValueNumberDataflow(method); DepthFirstSearch dfs = getDepthFirstSearch(method); AssertionMethods assertionMethods = getAssertionMethods(); IsNullValueAnalysis invAnalysis = new IsNullValueAnalysis(methodGen, cfg, vnaDataflow, dfs, assertionMethods); IsNullValueDataflow invDataflow = new IsNullValueDataflow(cfg, invAnalysis); invDataflow.execute(); return invDataflow; } }; private AnalysisFactory<TypeDataflow> typeDataflowFactory = new AnalysisFactory<TypeDataflow>("type analysis") { protected TypeDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { MethodGen methodGen = getMethodGen(method); CFG cfg = getRawCFG(method); DepthFirstSearch dfs = getDepthFirstSearch(method); ExceptionSetFactory exceptionSetFactory = getExceptionSetFactory(method); TypeAnalysis typeAnalysis = new TypeAnalysis(methodGen, cfg, dfs, getLookupFailureCallback(), exceptionSetFactory); TypeDataflow typeDataflow = new TypeDataflow(cfg, typeAnalysis); typeDataflow.execute(); return typeDataflow; } }; private NoDataflowAnalysisFactory<DepthFirstSearch> dfsFactory = new NoDataflowAnalysisFactory<DepthFirstSearch>("depth first search") { protected DepthFirstSearch analyze(Method method) throws CFGBuilderException { CFG cfg = getRawCFG(method); DepthFirstSearch dfs = new DepthFirstSearch(cfg); dfs.search(); return dfs; } }; private NoDataflowAnalysisFactory<ReverseDepthFirstSearch> rdfsFactory = new NoDataflowAnalysisFactory<ReverseDepthFirstSearch>("reverse depth first search") { protected ReverseDepthFirstSearch analyze(Method method) throws CFGBuilderException { CFG cfg = getRawCFG(method); ReverseDepthFirstSearch rdfs = new ReverseDepthFirstSearch(cfg); rdfs.search(); return rdfs; } }; private NoExceptionAnalysisFactory<BitSet> bytecodeSetFactory = new NoExceptionAnalysisFactory<BitSet>("bytecode set construction") { protected BitSet analyze(Method method) { final BitSet result = new BitSet(); Code code = method.getCode(); if (code != null) { byte[] instructionList = code.getCode(); // Create a callback to put the opcodes of the method's // bytecode instructions into the BitSet. BytecodeScanner.Callback callback = new BytecodeScanner.Callback() { public void handleInstruction(int opcode, int index) { result.set(opcode, true); } }; // Scan the method. BytecodeScanner scanner = new BytecodeScanner(); scanner.scan(instructionList, callback); } return result; } };/* private AnalysisFactory<LockCountDataflow> anyLockCountDataflowFactory = new AnalysisFactory<LockCountDataflow>("lock count analysis (any lock)") { protected LockCountDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { MethodGen methodGen = getMethodGen(method); ValueNumberDataflow vnaDataflow = getValueNumberDataflow(method); DepthFirstSearch dfs = getDepthFirstSearch(method); CFG cfg = getCFG(method); AnyLockCountAnalysis analysis = new AnyLockCountAnalysis(methodGen, vnaDataflow, dfs); LockCountDataflow dataflow = new LockCountDataflow(cfg, analysis); dataflow.execute(); return dataflow; } };*/ private AnalysisFactory<LockDataflow> lockDataflowFactory = new AnalysisFactory<LockDataflow>("lock set analysis") { protected LockDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { MethodGen methodGen = getMethodGen(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<ReturnPathDataflow> returnPathDataflowFactory = new AnalysisFactory<ReturnPathDataflow>("return path analysis") { 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 AnalysisFactory<DominatorsAnalysis>("non-exception dominators analysis") { 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 AnalysisFactory<PostDominatorsAnalysis>("non-exception postdominators analysis") { protected PostDominatorsAnalysis analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { CFG cfg = getCFG(method); ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(method); PostDominatorsAnalysis analysis = new PostDominatorsAnalysis(cfg, rdfs, true); Dataflow<java.util.BitSet, PostDominatorsAnalysis> dataflow = new Dataflow<java.util.BitSet, PostDominatorsAnalysis>(cfg, analysis); dataflow.execute(); return analysis; } }; private NoExceptionAnalysisFactory<ExceptionSetFactory> exceptionSetFactoryFactory = new NoExceptionAnalysisFactory<ExceptionSetFactory>("exception set factory") { protected ExceptionSetFactory analyze(Method method) { return new ExceptionSetFactory(); } }; private NoExceptionAnalysisFactory<String[]> parameterSignatureListFactory = new NoExceptionAnalysisFactory<String[]>("parameter signature list factory") { 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 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") { protected LoadedFieldSet analyze(Method method) { MethodGen methodGen = getMethodGen(method); 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 AnalysisFactory<LiveLocalStoreDataflow>("live local stores analysis") { protected LiveLocalStoreDataflow analyze(Method method) throws DataflowAnalysisException, CFGBuilderException { CFG cfg = getCFG(method); MethodGen methodGen = getMethodGen(method); ReverseDepthFirstSearch rdfs = getReverseDepthFirstSearch(method); LiveLocalStoreAnalysis analysis = new LiveLocalStoreAnalysis(methodGen, rdfs); LiveLocalStoreDataflow dataflow = new LiveLocalStoreDataflow(cfg, analysis); dataflow.execute(); return dataflow; } }; private AnalysisFactory<Dataflow<BlockType, BlockTypeAnalysis>> blockTypeDataflowFactory = new AnalysisFactory<Dataflow<BlockType, BlockTypeAnalysis>>("block type analysis") { protected Dataflow<BlockType, BlockTypeAnalysis> analyze(Method method)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -