Exemplo n.º 1
0
  /** Given a new expression (Jimple NewExpr or String) return the corresponding AllocNode. */
  public IAllocNode getAllocNode(Object newExpr, Context context) {
    InsensitiveAllocNode insens = null;
    if (newExpr instanceof NewMultiArrayExpr) {
      NewMultiArrayExpr newArr = (NewMultiArrayExpr) newExpr;
      ArrayType type = (ArrayType) newArr.getType();
      Integer i = type.numDimensions;
      Pair pair = new Pair(newArr, i);
      insens = newToAllocNodeMap.get(pair);
    } else {
      if (!newToAllocNodeMap.containsKey(newExpr)) {
        System.out.println("Not in new -> alloc map: " + newExpr);
        return null;
      }
      insens = newToAllocNodeMap.get(newExpr);
    }

    // handle no context case
    if (k == 0) return insens;

    return insens.context(context);
  }
Exemplo n.º 2
0
  public Set<IAllocNode> getAllocNodeIns(Object newExpr) {
    InsensitiveAllocNode insens = null;
    if (newExpr instanceof NewMultiArrayExpr) {
      NewMultiArrayExpr newArr = (NewMultiArrayExpr) newExpr;
      ArrayType type = (ArrayType) newArr.getType();
      Integer i = type.numDimensions;
      Pair pair = new Pair(newArr, i);
      insens = newToAllocNodeMap.get(pair);
    } else {
      if (!newToAllocNodeMap.containsKey(newExpr)) {
        System.out.println("Not in new -> alloc map: " + newExpr);
        return null;
      }
      insens = newToAllocNodeMap.get(newExpr);
    }

    Set<IAllocNode> nodes = new LinkedHashSet<IAllocNode>();

    nodes.add(insens);
    nodes.addAll(insens.getContextNodeMap().values());

    return nodes;
  }
 public void caseNewMultiArrayExpr(NewMultiArrayExpr arg0) {
   OpenCLScene.v().setUsingGarbageCollector();
   OpenCLArrayType array_type = new OpenCLArrayType((ArrayType) arg0.getType());
   m_output.append(array_type.invokeNewMultiArrayExpr(arg0));
   m_newCalled = true;
 }
 private Value mutate(Value value) {
   if (value instanceof FieldRef) {
     FieldRef ref = (FieldRef) value;
     SootField field = ref.getField();
     Type type = field.getType();
     if (type instanceof RefType) {
       RefType ref_type = (RefType) type;
       SootClass soot_class = ref_type.getSootClass();
       if (shouldMap(soot_class)) {
         addField(field, ref);
       }
     } else if (type instanceof ArrayType) {
       ArrayType array_type = (ArrayType) type;
       Type base_type = array_type.baseType;
       if (base_type instanceof RefType) {
         RefType ref_type = (RefType) base_type;
         SootClass soot_class = ref_type.getSootClass();
         if (shouldMap(soot_class)) {
           addField(field, ref);
         }
       }
     }
     SootClass soot_class = field.getDeclaringClass();
     if (shouldMap(soot_class)) {
       addField(field, ref);
     }
     return value;
   } else if (value instanceof InvokeExpr) {
     InvokeExpr expr = (InvokeExpr) value;
     SootMethodRef ref = expr.getMethodRef();
     SootClass soot_class = ref.declaringClass();
     final NumberedString subSignature = ref.getSubSignature();
     if (shouldMap(soot_class)) {
       SootClass new_class = getMapping(soot_class);
       if (new_class.declaresMethod(subSignature)) {
         SootMethod new_method = RootbeerScene.v().getMethod(new_class, subSignature.getString());
         addAddedMethod(new_method);
         fixArguments(new_method);
         RootbeerScene.v().getDfsInfo().addReachableMethodSig(new_method.getSignature());
         expr.setMethodRef(new_method.makeRef());
       }
     } else {
       if (soot_class.declaresMethod(ref.getSubSignature())) {
         SootMethod method = soot_class.getMethod(ref.getSubSignature());
         fixArguments(method);
       }
     }
     ref = remapRef(ref);
     try {
       if (shouldMap(soot_class)) {
         soot_class = getMapping(soot_class);
       }
       SootMethod method = soot_class.getMethod(ref.getSubSignature());
       RootbeerScene.v().getDfsInfo().addReachableMethodSig(method.getSignature());
       expr.setMethodRef(method.makeRef());
     } catch (Exception ex) {
       // ex.printStackTrace();
     }
     return value;
   } else if (value instanceof NewExpr) {
     NewExpr expr = (NewExpr) value;
     RefType base_type = expr.getBaseType();
     SootClass soot_class = base_type.getSootClass();
     if (shouldMap(soot_class)) {
       SootClass new_class = getMapping(soot_class);
       expr.setBaseType(new_class.getType());
     }
     return value;
   } else if (value instanceof NewArrayExpr) {
     NewArrayExpr expr = (NewArrayExpr) value;
     Type base_type = expr.getBaseType();
     base_type = fixType(base_type);
     expr.setBaseType(base_type);
     return value;
   } else if (value instanceof NewMultiArrayExpr) {
     NewMultiArrayExpr expr = (NewMultiArrayExpr) value;
     ArrayType array_type = expr.getBaseType();
     Type base_type = array_type.baseType;
     if (base_type instanceof RefType) {
       RefType ref_type = (RefType) base_type;
       SootClass soot_class = ref_type.getSootClass();
       if (shouldMap(soot_class)) {
         SootClass new_class = getMapping(soot_class);
         ArrayType new_type = ArrayType.v(new_class.getType(), array_type.numDimensions);
         expr.setBaseType(new_type);
       }
     }
     return value;
   } else if (value instanceof CastExpr) {
     CastExpr expr = (CastExpr) value;
     Type cast_type = expr.getCastType();
     cast_type = fixType(cast_type);
     expr.setCastType(cast_type);
     return value;
   } else if (value instanceof ParameterRef) {
     ParameterRef ref = (ParameterRef) value;
     Type new_type = fixType(ref.getType());
     return new ParameterRef(new_type, ref.getIndex());
   } else if (value instanceof ThisRef) {
     ThisRef ref = (ThisRef) value;
     Type new_type = fixType(ref.getType());
     return new ThisRef((RefType) new_type);
   } else if (value instanceof Local) {
     Local local = (Local) value;
     Type type = local.getType();
     local.setType(fixType(type));
     return value;
   } else {
     return value;
   }
 }