Exemple #1
0
  private static void computeAliasVariant(
      final MoJo mojo,
      final MayAliasGraph alias,
      final IMethod method,
      final boolean ignoreExceptions,
      final String outDir)
      throws IllegalArgumentException, CancelException, PDGFormatException, WalaException,
          FileNotFoundException {
    final Logger debug = Log.getLogger(Log.L_MOJO_DEBUG);
    final Logger info = Log.getLogger(Log.L_MOJO_INFO);

    info.out("Preparing points-to config and call graph...");
    final PointsTo pts = MoJo.computePointsTo(alias);
    if (debug.isEnabled()) {
      AliasGraphIO.dumpToDot(alias, outDir + ".alias.dot");
    }
    AliasGraphIO.writeOut(alias, new FileOutputStream(outDir + ".alias"));

    final AnalysisOptions optPts = mojo.createAnalysisOptionsWithPTS(pts, method);
    final CallGraphResult cg = mojo.computeContextSensitiveCallGraph(optPts);
    if (debug.isEnabled()) {
      final PrintStream ssaOut = new PrintStream(outDir + ".ssa.txt");
      Util.dumpSSA(cg.cg.getFakeRootNode().getIR(), ssaOut);
      Util.dumpPhiSSA(cg.cg.getFakeRootNode().getIR(), ssaOut);
      ssaOut.flush();
      ssaOut.close();

      Util.dumpHeapGraphToFile(
          outDir + ".heap.dot", cg.pts.getHeapGraph(), cg.cg.getFakeRootNode().getMethod());
    }
    info.out("done, sdg... ");
    // run analysis on callgraph with minimal alias configuration
    // ...
    final edu.kit.joana.ifc.sdg.graph.SDG sdg = createSDG(cg, optPts, method, ignoreExceptions);
    SDGSerializer.toPDGFormat(sdg, new BufferedOutputStream(new FileOutputStream(outDir + ".pdg")));
    info.out("(" + sdg.edgeSet().size() + " edges)");

    if (debug.isEnabled()) {
      final int summary =
          outputSummaryEdges(sdg, method.getReference().getSignature(), outDir + ".sum.dot");
      debug.out(" (" + summary + " sum)");
    }

    info.outln(" done.");
  }
  /** Computes information about the threads in a CFG. */
  public static ThreadsInformation createThreadsInformation(ThreadAllocationAnalysis ta, CFG cfg) {
    LinkedList<ThreadInstance> result = new LinkedList<ThreadInstance>();

    // create a ThreadInstance for the main thread
    ThreadInstance main =
        new ThreadInstance(0, findMainEntry(cfg), null, new LinkedList<SDGNode>());

    main.setDynamic(false);

    main.setExit(findExitNode(main.getEntry(), cfg));

    result.add(main);

    final Logger debug = Log.getLogger(Log.L_MHP_DEBUG);
    debug.outln("entry: " + main.getEntry());
    debug.outln("    fork: " + main.getFork());
    debug.outln("    context: " + main.getThreadContext());

    // a thread is identified by its calling context
    Set<DynamicContext> threads = ta.getThreads();
    int id = 1;

    // determine the thread instances
    for (DynamicContext thread : threads) {
      debug.outln("entry: " + thread.getNode());
      debug.outln("    fork: " + thread.getCallStack().peek());
      debug.outln("    context: " + thread.getCallStack());

      ThreadInstance ti =
          new ThreadInstance(
              id, thread.getNode(), thread.getCallStack().peek(), thread.getCallStack());
      ti.setExit(findExitNode(ti.getEntry(), cfg));

      // distinguish between dynamic and not dynamic threads
      if (ta.getThreadAmount().get(thread) == SpawnNumber.INDEFINITE) {
        ti.setDynamic(true);

      } else {
        ti.setDynamic(false);
      }

      result.add(ti);
      id++;
    }

    if (debug.isEnabled()) {
      for (ThreadInstance ti : result) {
        debug.outln(ti + "\n");
      }
    }
    return new ThreadsInformation(result);
  }
Exemple #3
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;
  }