Esempio n. 1
0
  private static Result getOrigSDG(Config cfg, IProgressMonitor progress)
      throws IllegalArgumentException, CancelException, PDGFormatException, IOException,
          WalaException, InvalidClassFileException {
    progress.beginTask(Messages.getString("Analyzer.Task_Prepare_IR"), -1); // $NON-NLS-1$

    com.ibm.wala.ipa.callgraph.impl.Util.setNativeSpec(cfg.nativesXML);

    progress.subTask(Messages.getString("Analyzer.SubTask_Analysis_Scope")); // $NON-NLS-1$

    ClassLoader loader = cfg.getClass().getClassLoader();
    AnalysisScope scope = Util.makeAnalysisScope(cfg, loader);
    // AnalysisScopeReader.makeJavaBinaryAnalysisScope(cfg.scopeFile, cfg.classpath, null);
    progress.done();

    ClassHierarchy cha = ClassHierarchy.make(scope, progress);

    Iterable<Entrypoint> entrypoints =
        com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, cfg.mainClass);
    AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
    AnalysisCache cache = new AnalysisCache();

    progress.subTask(
        Messages.getString("Analyzer.SubTask_Call_Graph_Builder") + cfg.pointsTo); // $NON-NLS-1$
    SSAPropagationCallGraphBuilder builder =
        SDGFactory.getCallGraphBuilder(cfg.pointsTo, options, cache, cha, scope);

    /**
     * Change the wala internal pointer and instancekeyfactory of the callgraph builder to our
     * adapter. So we can keep track of the created InstanceKeys and PointerKeys. This information
     * is used later on when creating subobject trees for accessed field variables.
     */
    InstanceAndPointerKeyFactoryAdapter adapter = null;
    InstanceKeyFactory ikFact = builder.getInstanceKeys();
    PointerKeyFactory pkFact = builder.getPointerKeyFactory();
    adapter = new InstanceAndPointerKeyFactoryAdapter(ikFact, pkFact);

    builder.setInstanceKeys(adapter);
    builder.setPointerKeyFactory(adapter);

    progress.done();

    progress.subTask(Messages.getString("Analyzer.SubTask_Call_Graph")); // $NON-NLS-1$
    CallGraph cg = builder.makeCallGraph(options, progress);

    if (cfg.optimizeCg >= 0) {
      CallGraphPruning opt = new CallGraphPruning(cg);
      System.out.println("Call Graph has " + cg.getNumberOfNodes() + " Nodes.");
      Set<CGNode> sopt = opt.findApplicationNodes(cfg.optimizeCg);
      cg = new PrunedCallGraph(cg, sopt);
      System.out.println("Optimized Call Graph has " + cg.getNumberOfNodes() + " Nodes.");
    }

    if (Debug.Var.DUMP_CALLGRAPH.isSet()) {
      Util.dumpCallGraph(cg, cfg.mainClass.replace('/', '.').substring(1), progress);
    }

    if (Debug.Var.DUMP_HEAP_GRAPH.isSet()) {
      PointerAnalysis pta = builder.getPointerAnalysis();
      HeapGraph hg = pta.getHeapGraph();
      Util.dumpHeapGraph(
          cfg.mainClass.replace('/', '.').substring(1) + "." + cfg.pointsTo, hg, null);
    }

    PointerAnalysis pta = builder.getPointerAnalysis();
    progress.done();

    DemandRefinementPointsTo demandPts = null;
    if (cfg.useDemandPts) {
      throw new UnsupportedOperationException();
      //		    MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, builder.getPointerAnalysis());
      //			demandPts = new DemandRefinementPointsTo(cg,
      //				new ThisFilteringHeapModel(builder,cha), mam, cha, options, getStateMachineFactory());
    }

    IPointerAnalysis pts = new PointsToWrapper(demandPts, pta);

    progress.subTask(Messages.getString("Analyzer.SubTask_Search_Main")); // $NON-NLS-1$
    IMethod main =
        edu.kit.joana.deprecated.jsdg.util.Util.searchMethod(
            entrypoints, "main([Ljava/lang/String;)V"); // $NON-NLS-1$
    progress.done();

    progress.done();

    SDG sdg = SDG.create(main, cg, cache, adapter, pts, cfg, progress);
    sdg.setAnalysisScope(scope);
    sdg.setPointerAnalysis(pta);

    progress.done();

    if (Debug.Var.PRINT_FIELD_PTS_INFO.isSet()) {
      Log.info("search for field allocs called " + PDG.searchFieldAllocs + " times.");
    }

    if (Debug.Var.PRINT_UNRESOLVED_CLASSES.isSet()) {
      for (TypeReference tRef : cg.getClassHierarchy().getUnresolvedClasses()) {
        Log.warn("Could not resolve: " + Util.typeName(tRef.getName()));
      }
    }

    return new Result(null, sdg, cg, pta, null);
  }
Esempio n. 2
0
  private static edu.kit.joana.ifc.sdg.graph.SDG createSDG(
      CallGraphResult cgResult, AnalysisOptions opt, IMethod method, boolean ignoreExceptions)
      throws CancelException, PDGFormatException, WalaException {
    DemandRefinementPointsTo demandPts = null;
    //		if (cfg.useDemandPts) {
    //		    MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, builder.getPointerAnalysis());
    //			demandPts = new DemandRefinementPointsTo(cg,
    //				new ThisFilteringHeapModel(builder,cha), mam, cha, options,
    //			        getStateMachineFactory());
    //		}

    IPointerAnalysis pts = new PointsToWrapper(demandPts, cgResult.pts);
    IProgressMonitor progress = NullProgressMonitor.INSTANCE;
    // new VerboseProgressMonitor(System.out);
    IKey2Origin k2o = null;
    edu.kit.joana.deprecated.jsdg.SDGFactory.Config cfg =
        new edu.kit.joana.deprecated.jsdg.SDGFactory.Config();
    cfg.computeSummaryEdges = true;
    cfg.useSummaryOpt = false;
    cfg.addControlFlow = true;
    cfg.computeInterference = false;
    cfg.ignoreExceptions = ignoreExceptions;
    cfg.optimizeExceptions = false; // !ignoreExceptions;
    cfg.nonTermination = false;

    cfg.immutables =
        new String[] {
          "java.lang.String",
          "java.lang.Integer",
          "java.lang.Float",
          "java.lang.Double",
          "java.lang.Boolean",
          "java.lang.Character"
        };

    edu.kit.joana.deprecated.jsdg.sdg.SDG jSDG =
        edu.kit.joana.deprecated.jsdg.sdg.SDG.create(
            method, cgResult.cg, cgResult.cache, k2o, pts, cfg, progress);

    edu.kit.joana.ifc.sdg.graph.SDG sdg =
        JoanaStyleSDG.createJoanaSDG(
            jSDG, cfg.addControlFlow, cfg.nonTermination, cfg.useSummaryOpt, progress);

    RemoveLibraryClinits.removeLibraryClinits(sdg);
    StaticFieldMerge.mergeStaticFields(sdg);

    final Logger log = Log.getLogger(Log.L_WALA_CORE_DEBUG);

    if (cfg.computeSummaryEdges) {
      progress.subTask("Compute Summary Edges");
      log.outln("Compute Summary Edges");
      SummaryEdgeComputation.compute(sdg, progress);

      log.outln("Summary Edges done.");
      progress.done();
    }

    SummarizeDependencies.transformToSummary(sdg, method);

    return sdg;
  }