Package dk.brics.xact.analysis.flowgraph

Examples of dk.brics.xact.analysis.flowgraph.FlowGraph


  public void analyze() {
      if (Debug.getLevel() >= 1 && tasks.maybeMultiThreaded()) {
          Debug.println(1, false, "Warning: Concurrency can mess up the debug output");
      }
    try {
      FlowGraph g;
            synchronized (soot.G.class) {
        try {
              initializeSoot();
              if (classpath != null)
                  soot.options.Options.v().set_soot_classpath(classpath);
          loadClasses();
          diagnostics.afterSootLoaded();
          g = buildFlowGraph().getGraph();
        } finally {
          releaseSoot();
        }
            }
      transformFlowGraph(g);
            final XMLGraph sharedXg = g.getXMLGraph();
      List<FlowGraph> graphs = splitFlowGraph(g);
      g = null;
      int index=0;
      final ThreadLocal<XMLGraph> localXg = new ThreadLocal<XMLGraph>();
      for (final FlowGraph g2 : graphs) {
View Full Code Here


   * This method is <i>not</i> thread-safe (because of Soot).
   */
  public TranslationResult buildFlowGraph() {
    startPhase("Building flow graph...");
    TranslationResult tr = new Jimple2FlowGraph(config, errors).run();
    FlowGraph g = tr.getGraph();
    Debug.println(2, true, "Flow graph nodes: " + g.getNodes().size()
        + ", edges: " + g.getNumberOfEdges()
        + ", entries: " + g.getEntries().size());
    dumpFlowGraph(g, "fg1.dot");
    endPhase();
    return tr;
  }
View Full Code Here

    for (Statement stm : graph.getNodes()) {
      Component comp = forest.getData(stm);
      if (!comp.interesting)
        continue;
      if (comp.graph == null) {
        comp.graph = new FlowGraph(graph.getSchemas(), graph.getNamespaces());
        comp.graph.setXMLGraph(graph.getXMLGraph());
        comp.graph.setTypemap(graph.getTypemap());
        graphs.add(comp.graph);
      }
      comp.graph.addNode(stm);
View Full Code Here

 
  public TranslationResult run() {
    Map<String,String> namespaces = findNamespaces();
    config.modifyNamespaces(namespaces);
    Map<String,Origin> schemas = findSchemas();
    FlowGraph graph = new FlowGraph(schemas, namespaces);
    TranslatorContext context = new TranslatorContext(graph, errors);
    Translator translator = new Translator(context, config);
    // create methods and parse field annotations
    for (SootClass c : Scene.v().getApplicationClasses()) {
      for (SootMethod m : c.getMethods()) {
        Origin origin = new Origin(c.getName() + "." + m.getName(), 0, 0);
        Statement methodentry, methodexit;
        Variable returnVar;
        Variable[] parameters = new Variable[m.getParameterCount()];
        if (m.isConcrete()) {
          // entry
          methodentry = new NopStm(origin, "method entry");
          graph.addNode(methodentry);
          // exit
          methodexit = new NopStm(origin, "method exit");
          graph.addNode(methodexit);
          // parameters
          for (int i=0; i<m.getParameterCount(); i++) {
            parameters[i] = new Variable(context.getNextVarID(), false);
          }
          // return var
          returnVar = new Variable(context.getNextVarID(), false);
          // externally callable
          if (config.isExternallyCallable(m)) {
            graph.addEntry(methodentry);
          }
        } else {
          // non-concrete method. it must still be created for annotations to
          // be visible.
          methodentry = methodexit = null;
          returnVar = null;
        }
        // parse annotations
        SchemaType returnType;
        if (context.isAnnotatableType(m.getReturnType())) {
          returnType = context.parseSchemaType(config.getMethodReturnType(m, context.getTypeAnnotation(m)), origin);
        } else {
          returnType = null;
        }
        SchemaType[] paramTypes = new SchemaType[m.getParameterCount()];
        for (int i=0; i<m.getParameterCount(); i++) {
          if (context.isAnnotatableType(m.getParameterType(i))) {
            paramTypes[i] = context.parseSchemaType(config.getMethodParameterType(m, i, context.getTypeAnnotationForParameter(m, i)), origin);
          }
        }
        // make the method
        Method method = new Method(m.getName(), methodentry, methodexit, parameters, returnVar, returnType, paramTypes);
        context.setMethod(m, method);
      }
      for (SootField f : c.getFields()) {
        // parse annotations
        if (context.isAnnotatableType(f.getType())) {
          Origin origin = new Origin(c.getName() + "." + f.getName(), 0, 0);
          context.setFieldSchemaType(f, context.parseSchemaType(config.getFieldType(f, context.getTypeAnnotation(f)), origin));
        }
      }
    }
    // translate!
    for (SootClass c : Scene.v().getApplicationClasses()) {
      context.setCurrentClass(c);
      for (SootMethod m : c.getMethods()) {
        if (!m.isConcrete())
          continue;
        context.setCurrentSootMethod(m);
        CompleteUnitGraph unitgraph = new CompleteUnitGraph(m.retrieveActiveBody());
        context.setNullness(new NullnessAnalysis(unitgraph));
        context.setStringConstants(new StringConstantAnalysis(unitgraph));
        context.setArrayConstants(new ArrayConstantAnalysis(unitgraph));
        Method method = context.getMethod(m);
        Map<Unit,StatementPair> translated = new HashMap<Unit,StatementPair>();
        for (Unit stmt : m.getActiveBody().getUnits()) {
          context.setCurrentUnit(stmt);
          context.setCurrentLine(getLineNumber(stmt));
          translated.put(stmt, translator.translateStmt((Stmt)stmt));
        }
        for (Map.Entry<Unit, StatementPair> entry : translated.entrySet()) {
          Unit stmt = entry.getKey();
          StatementPair translation = entry.getValue();
          // add successors
          for (Unit next : unitgraph.getSuccsOf(stmt)) {
            StatementPair nextt = translated.get(next);
            graph.addEdge(translation.last, nextt.first, new VariableFilter());
          }
          // add (exceptional) return edge
          graph.addEdge(translation.last, method.getExit(), new VariableFilter());
        }
        // add entry edges
        for (Unit head : unitgraph.getHeads()) {
          graph.addEdge(method.getEntry(), translated.get(head).first, new VariableFilter(true, VariableFilter.Kind.ENTRY));
        }
      }
    }
   
    // run string analysis
View Full Code Here

        // run xact
        TranslationResult result = analysis.buildFlowGraph();

        analysis.transformFlowGraph(result.getGraph());

        final FlowGraph graph = result.getGraph();
        XMLGraphBuilder xmlGraphs = analysis.buildXMLGraphs(graph);

        int counter = 0;
        for (Map.Entry<ValueBox, AnalyzeStm> en : result.getHotspots()
                .entrySet()) {
View Full Code Here

        analysis.setConfiguration(new JWIGConfiguration(stmt2box.values()));
        TranslationResult result = analysis.buildFlowGraph();

        analysis.transformFlowGraph(result.getGraph());

        final FlowGraph graph = result.getGraph();
        XMLGraphBuilder xmlGraphs = analysis.buildXMLGraphs(graph);
        log.info("xact analysis done");

        Map<ChoiceNode, Set<Plugging>> gap2plug = linkGapsToPluggings(
                pluggings, stmt2box, result, xmlGraphs);
View Full Code Here

TOP

Related Classes of dk.brics.xact.analysis.flowgraph.FlowGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.