コード例 #1
0
  public static void main(String[] args) throws Exception {
    // explicit configuration
    for (int i = 0; i < PDGs.pdgs.length; i++) {
      String file = PDGs.pdgs[i];
      /* 1 */
      g = SDG.readFrom(file);
      ThreadInstance ti = g.getThreadsInfo().iterator().next();
      LinkedList<ThreadInstance> l = new LinkedList<ThreadInstance>();
      l.add(ti);
      ThreadsInformation info = new ThreadsInformation(l);
      g.setThreadsInfo(info);
      int[] threads = new int[] {0};
      for (SDGNode n : g.vertexSet()) {
        n.setThreadNumbers(threads);
      }

      System.out.println("initializing the slicers");
      LinkedList<Slicer> array = new LinkedList<Slicer>();

      array.addLast(new SummarySlicerBackward(g));
      array.addLast(new Phase1SlicerBackward(g));

      System.out.println(file);
      System.out.println("criteria: " + g.vertexSet().size());

      String str = compare(array, g.vertexSet());

      System.out.println(str);
    }
  }
コード例 #2
0
ファイル: RunTestModular.java プロジェクト: serialcake/joana
  private static SDGNode searchEntry(SDG sdg, String bcMethodName) {
    for (SDGNode node : sdg.vertexSet()) {
      if (node.kind == Kind.ENTRY && bcMethodName.equals(node.getBytecodeName())) {
        return node;
      }
    }

    return null;
  }
コード例 #3
0
ファイル: BarrierChopper.java プロジェクト: majestyhao/joana
  /**
   * Creates a new Chopper.
   *
   * @param alg The algorithm to use.
   * @param graph The graph to slice.
   */
  public BarrierChopper(String className, Graph g) {

    // load the demanded algorithm
    Object o = AlgorithmFactory.loadClass(className, g);
    chopper = (edu.kit.joana.ifc.sdg.graph.chopper.barrier.BarrierChopper) o;

    // initialize the sourceCriteria and sinkCriteria and barrier sets
    sourceCriteria = new TreeSet<SDGNode>(SDGNode.getIDComparator());
    sinkCriteria = new TreeSet<SDGNode>(SDGNode.getIDComparator());
    barrier = new TreeSet<SDGNode>(SDGNode.getIDComparator());
  }
コード例 #4
0
  @SuppressWarnings("unchecked")
  private static String compare(List<Slicer> slicer, Collection<SDGNode> criteria) {
    int[] size = new int[slicer.size()];
    long[] time = new long[slicer.size()];
    Collection<SDGNode>[] slices = new Collection[slicer.size()];
    int s = 0;
    int diff = Integer.MAX_VALUE;

    int ctr = 0;

    for (SDGNode crit : criteria) {
      ctr++;
      if ((ctr % 1) != 0) continue;

      for (int i = 0; i < slicer.size(); i++) {
        long tmp = System.currentTimeMillis();
        slices[i] = slicer.get(i).slice(Collections.singleton(crit));
        time[i] += System.currentTimeMillis() - tmp;
        size[i] += slices[i].size();

        if (i == 1
            && slices[0].size() != slices[1].size()
            && Math.abs(slices[0].size() - slices[1].size()) < diff) {
          diff = Math.abs(slices[0].size() - slices[1].size());
          s = crit.getId();
        }
      }
      //            System.out.println("************************************** ");
      if (ctr % 10 == 0) {
        System.out.print(".");
      }
      if (ctr % 100 == 0) {
        System.out.print(ctr);
      }
      if (ctr % 1000 == 0) {
        System.out.println();
      }
    }

    String str = "\n";
    for (int i = 0; i < slicer.size(); i++) {
      str +=
          slicer.get(i).getClass().getName()
              + ": "
              + size[i]
              + "              time:"
              + time[i]
              + "\n";
    }

    str += s + ": " + diff + "\n";

    return str;
  }
コード例 #5
0
  private static SDGNode findExitNode(SDGNode node, CFG cfg) {
    SDGNode entry = cfg.getEntry(node);
    LinkedList<SDGNode> wl = new LinkedList<SDGNode>();
    Set<SDGNode> visited = new HashSet<SDGNode>();
    wl.add(entry);
    while (!wl.isEmpty()) {
      SDGNode n = wl.poll();
      visited.add(n);
      if (n.getKind() == SDGNode.Kind.EXIT) {
        return n;
      } else {

        for (SDGEdge e : cfg.outgoingEdgesOf(n)) {
          if (!visited.contains(e.getTarget()) && e.getKind() == SDGEdge.Kind.CONTROL_FLOW) {
            wl.add(e.getTarget());
          }
        }
      }
    }

    throw new IllegalStateException(
        "Visited the following nodes, which not include an exit node: " + visited);
  }
コード例 #6
0
ファイル: JoanaConverter.java プロジェクト: serialcake/joana
  private static SDGNode convertNode(SDGBuilder sdg, PDGNode node) {
    Operation op = null;
    Kind kind = null;
    int[] allocNodes = null;

    switch (node.getKind()) {
      case ACTUAL_IN:
        op = Operation.ACTUAL_IN;
        kind = Kind.ACTUAL_IN;
        break;
      case ACTUAL_OUT:
        op = Operation.ACTUAL_OUT;
        kind = Kind.ACTUAL_OUT;
        break;
      case CALL:
        op = Operation.CALL;
        kind = Kind.CALL;
        if (sdg.cfg.computeInterference) {
          TIntSet allocNodesAsSet = sdg.getAllocationNodes(node);
          if (allocNodesAsSet != null) {
            allocNodes = allocNodesAsSet.toArray();
          }
        }
        break;
      case ENTRY:
        op = Operation.ENTRY;
        kind = Kind.ENTRY;
        break;
      case EXIT:
        op = Operation.EXIT;
        kind = Kind.EXIT;
        break;
      case EXPRESSION:
        op = Operation.ASSIGN;
        kind = Kind.EXPRESSION;
        break;
      case FOLDED:
        op = Operation.COMPOUND;
        kind = Kind.FOLDED;
        break;
      case FORMAL_IN:
        op = Operation.FORMAL_IN;
        kind = Kind.FORMAL_IN;
        break;
      case FORMAL_OUT:
        op = Operation.FORMAL_OUT;
        kind = Kind.FORMAL_OUT;
        break;
      case HREAD:
        op = Operation.REFERENCE;
        kind = Kind.EXPRESSION;
        break;
      case HWRITE:
        op = Operation.MODIFY;
        kind = Kind.EXPRESSION;
        break;
      case JOIN:
        op = Operation.COMPOUND;
        kind = Kind.JOIN;
        break;
      case NEW:
        op = Operation.DECLARATION;
        kind = Kind.NORMAL;
        break;
      case NORMAL:
        op = Operation.COMPOUND;
        kind = Kind.NORMAL;
        break;
      case PHI:
        op = Operation.ASSIGN;
        kind = Kind.EXPRESSION;
        break;
      case PREDICATE:
        op = Operation.IF;
        kind = Kind.PREDICATE;
        break;
      case SYNCHRONIZATION:
        op = Operation.MONITOR;
        kind = Kind.SYNCHRONIZATION;
        break;
      default:
        throw new IllegalStateException("Unknown node kind: " + node.getKind().name());
    }
    SourceLocation sloc = node.getSourceLocation();

    SDGNode sn =
        new SecurityNode(
            node.getId(),
            op,
            node.getLabel(),
            node.getPdgId(),
            node.getType(),
            sloc.getSourceFile(),
            sloc.getStartRow(),
            sloc.getStartColumn(),
            sloc.getEndRow(),
            sloc.getEndColumn(),
            node.getBytecodeName(),
            node.getBytecodeIndex());

    if (node.getKind() == PDGNode.Kind.ENTRY) {
      PDG pdg = sdg.getPDGforId(node.getPdgId());
      IMethod im = pdg.getMethod();

      if (im != null) {
        IClass cls = im.getDeclaringClass();

        if (cls != null) {
          String clsLoader = cls.getClassLoader().toString();
          sn.setClassLoader(clsLoader);
        }
      }
    }

    if (allocNodes != null) {
      sn.setAllocationSites(allocNodes);
    }

    if (node.getAliasDataSources() != null) {
      sn.setAliasDataSources(node.getAliasDataSources());
    }

    assert sn.getKind() == kind;

    return sn;
  }
コード例 #7
0
ファイル: InterferenceMap.java プロジェクト: serialcake/joana
 public int hashCode() {
   return context.hashCode() | (node.getId() << 16);
 }
コード例 #8
-1
ファイル: RunTestModular.java プロジェクト: serialcake/joana
  private static Set<SDGNode> filterStatic(final SDG sdg, final Set<SDGNode> nodes) {
    final Set<SDGNode> filtered = new HashSet<SDGNode>();

    for (SDGNode n : nodes) {
      if (n.getBytecodeIndex() == BytecodeLocation.ROOT_PARAMETER) {
        filtered.add(n);
      }
    }

    LinkedList<SDGNode> work = new LinkedList<SDGNode>();
    work.addAll(filtered);
    while (!work.isEmpty()) {
      final SDGNode n = work.removeFirst();

      for (SDGEdge edge : sdg.getOutgoingEdgesOfKind(n, SDGEdge.Kind.PARAMETER_STRUCTURE)) {
        final SDGNode tgt = edge.getTarget();
        if (!filtered.contains(tgt)) {
          filtered.add(tgt);
          work.add(tgt);
        }
      }
    }

    return filtered;
  }