예제 #1
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private Set<SootField> collectBlockField(JavaCriticalSection cs) {
    Set result = new HashSet();
    int startLine = cs.getStartLine();
    int endLine = cs.getEndline();
    Body body = cs.getSootMethod().getActiveBody();
    PatchingChain<Unit> units = body.getUnits();
    for (Unit u : units) {
      Stmt s = (Stmt) u;
      LineNumberTag linetag = (LineNumberTag) s.getTag("LineNumberTag");
      if (linetag == null) continue;
      int line = linetag.getLineNumber();
      if (line < startLine || line > endLine) {
        continue;
      }

      List<ValueBox> Fieldslist = u.getUseBoxes();
      Fieldslist.addAll(u.getDefBoxes());
      for (ValueBox box : Fieldslist) {
        Value v = box.getValue();
        if (v instanceof JInstanceFieldRef) {
          result.add(((JInstanceFieldRef) v).getField());
        }
      }
      if (s.containsInvokeExpr()) {
        // 用调用图获得调用目标
        Callees callees = new Callees(getCallGragh(), u);
        for (SootMethod invokeMethod : callees.explicits()) {
          if (invokeMethod == null) continue;
          Collection use = scaner.getUseInstanceFields(invokeMethod);
          Collection mod = new HashSet();
          if (needMod) {
            mod.addAll(scaner.getModInstanceFields(invokeMethod));
          }
          if (use != null) result.addAll(use);
          result.addAll(mod);
        }
      }
    }
    return result;
  }
예제 #2
0
  public void buildVarConn(Collection<JavaCriticalSection> validSyncs) {
    scaner = new FieldScaner(allInvolvedMethod);
    for (JavaCriticalSection cs : validSyncs) {
      SootMethod m = cs.getSootMethod();
      if (m == null) continue;
      Set<SootField> fields = null;
      if (cs.getSynType() == SyncType.SyncMethod) {
        fields = scaner.getUseInstanceFields(m);
        if (fields != null && needMod) fields.addAll(scaner.getModInstanceFields(m));
        fields = filter(cs, fields);
        everyMethodFields.put(cs.getMethodName(), fields);
      } // synchronization is a block
      else {
        fields = collectBlockField(cs);
        fields = filter(cs, fields);
        everyBlockFields.put(cs.getMethodName(), fields);
      }

      // -------------------------------------addEdges-----------------------------------

      String clsName = cs.getClassNameOfSourceFile();
      if (!protectedFieldsInAllClass.containsKey(clsName)) {
        protectedFieldsInAllClass.put(clsName, new HashSet());
      }
      protectedFieldsInAllClass.get(clsName).addAll(fields);

      SootField[] fs = fields.toArray(new SootField[0]);
      for (int i = 0; i < fs.length; i++) {
        Set<SootField> neighbors = new HashSet();
        for (int j = 0; j < fs.length; j++) {
          if (i == j) continue;
          neighbors.add(fs[j]);
        }
        varConn.add(fs[i], neighbors);
      }
    }
  }