Search in sources :

Example 31 with CallString

use of com.jopdesign.common.code.CallString in project jop by jop-devel.

the class LoopBounds method handleNative.

@SuppressWarnings({ "LiteralAsArgToStringEquals" })
private Map<CallString, Map<Location, ValueMapping>> handleNative(MethodInfo method, Context context, Map<CallString, Map<Location, ValueMapping>> input, Map<CallString, Map<Location, ValueMapping>> result) {
    String methodId = method.getMemberID().toString();
    Map<Location, ValueMapping> in = input.get(context.callString);
    Map<Location, ValueMapping> out = new LinkedHashMap<Location, ValueMapping>();
    if (methodId.equals("com.jopdesign.sys.Native#rd(I)I") || methodId.equals("com.jopdesign.sys.Native#rdMem(I)I") || methodId.equals("com.jopdesign.sys.Native#rdIntMem(I)I") || methodId.equals("com.jopdesign.sys.Native#getStatic(I)I")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 1) {
                out.put(l, in.get(l));
            }
        }
        out.put(new Location(context.stackPtr - 1), new ValueMapping());
    } else if (methodId.equals("com.jopdesign.sys.Native#wr(II)V") || methodId.equals("com.jopdesign.sys.Native#wrMem(II)V") || methodId.equals("com.jopdesign.sys.Native#wrIntMem(II)V") || methodId.equals("com.jopdesign.sys.Native#putStatic(II)V") || methodId.equals("com.jopdesign.sys.Native#toLong(D)J") || methodId.equals("com.jopdesign.sys.Native#toDouble(J)D")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 2) {
                out.put(l, in.get(l));
            }
        }
    } else if (methodId.equals("com.jopdesign.sys.Native#toInt(Ljava/lang/Object;)I") || methodId.equals("com.jopdesign.sys.Native#toInt(F)I")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 1) {
                out.put(l, in.get(l));
            }
        }
        out.put(new Location(context.stackPtr - 1), new ValueMapping());
    } else if (methodId.equals("com.jopdesign.sys.Native#toObject(I)Ljava/lang/Object;") || methodId.equals("com.jopdesign.sys.Native#toIntArray(I)[I") || methodId.equals("com.jopdesign.sys.Native#toFloat(I)F")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 1) {
                out.put(l, in.get(l));
            }
        }
    } else if (methodId.equals("com.jopdesign.sys.Native#getSP()I")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr) {
                out.put(l, in.get(l));
            }
        }
        out.put(new Location(context.stackPtr), new ValueMapping());
    } else if (methodId.equals("com.jopdesign.sys.Native#toInt(Ljava/lang/Object;)I")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 1) {
                out.put(l, in.get(l));
            }
        }
        out.put(new Location(context.stackPtr - 1), new ValueMapping());
    } else if (methodId.equals("com.jopdesign.sys.Native#condMove(IIZ)I") || methodId.equals("com.jopdesign.sys.Native#condMoveRef(Ljava/lang/Object;Ljava/lang/Object;Z)Ljava/lang/Object;") || methodId.equals("com.jopdesign.sys.Native#memCopy(III)V")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 3) {
                out.put(l, in.get(l));
            }
        }
    } else if (methodId.equals("com.jopdesign.sys.Native#invalidate()V")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr) {
                out.put(l, in.get(l));
            }
        }
    } else if (methodId.equals("com.jopdesign.sys.Native#arrayLength(I)I") || methodId.equals("com.jopdesign.sys.Native#invoke(I)V")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 1) {
                out.put(l, in.get(l));
            }
        }
    } else if (methodId.equals("com.jopdesign.sys.Native#invoke(II)V")) {
        for (Location l : in.keySet()) {
            if (l.stackLoc < context.stackPtr - 2) {
                out.put(l, in.get(l));
            }
        }
    } else {
        AppInfoError ex = new AppInfoError("Unknown native method: " + methodId);
        logger.error(ex);
        throw ex;
    }
    result.put(context.callString, out);
    return result;
}
Also used : CallString(com.jopdesign.common.code.CallString) AppInfoError(com.jopdesign.common.misc.AppInfoError) LinkedHashMap(java.util.LinkedHashMap)

Example 32 with CallString

use of com.jopdesign.common.code.CallString in project jop by jop-devel.

the class LoopBounds method copyResults.

@Override
public void copyResults(MethodInfo newContainer, Map<InstructionHandle, InstructionHandle> newHandles) {
    for (Map.Entry<InstructionHandle, InstructionHandle> entry : newHandles.entrySet()) {
        InstructionHandle oldHandle = entry.getKey();
        InstructionHandle newHandle = entry.getValue();
        if (newHandle == null)
            continue;
        // TODO support updating the callstrings too
        // TODO this does NOT update stackPtr,.. in the new context!
        ContextMap<CallString, Pair<ValueMapping, ValueMapping>> value = bounds.get(oldHandle);
        if (value != null)
            bounds.put(newHandle, value.copy(newContainer));
        ContextMap<CallString, Interval> value1 = arrayIndices.get(oldHandle);
        if (value1 != null)
            arrayIndices.put(newHandle, value1.copy(newContainer));
        ContextMap<CallString, Integer> value2 = scopes.get(oldHandle);
        if (value2 != null)
            scopes.put(newHandle, value2.copy(newContainer));
        ContextMap<CallString, Interval[]> value3 = sizes.get(oldHandle);
        if (value3 != null)
            sizes.put(newHandle, value3.copy(newContainer));
        ContextMap<CallString, Set<FlowEdge>> old = infeasibles.get(oldHandle);
        if (old != null) {
            Map<CallString, Set<FlowEdge>> map = new LinkedHashMap<CallString, Set<FlowEdge>>(old.size());
            for (CallString cs : old.keySet()) {
                Set<FlowEdge> newSet = new LinkedHashSet<FlowEdge>();
                for (FlowEdge edge : old.get(cs)) {
                    InstructionHandle newHead = newHandles.get(edge.getHead());
                    InstructionHandle newTail = newHandles.get(edge.getTail());
                    if (newHead != null && newTail != null) {
                        Context ctx = new Context(edge.getContext());
                        ctx.setMethodInfo(newContainer);
                        newSet.add(new FlowEdge(newTail, newHead, edge.getType(), ctx));
                    }
                }
                map.put(cs, newSet);
            }
            Context c = old.getContext();
            c.setMethodInfo(newContainer);
            ContextMap<CallString, Set<FlowEdge>> edges = new ContextMap<CallString, Set<FlowEdge>>(c, map);
            infeasibles.put(newHandle, edges);
        }
    }
}
Also used : FlowEdge(com.jopdesign.dfa.framework.FlowEdge) SerializedFlowEdge(com.jopdesign.dfa.framework.FlowEdge.SerializedFlowEdge) LinkedHashSet(java.util.LinkedHashSet) Context(com.jopdesign.dfa.framework.Context) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) Pair(com.jopdesign.common.graphutils.Pair)

Example 33 with CallString

use of com.jopdesign.common.code.CallString in project jop by jop-devel.

the class LoopBounds method getArraySizes.

public Interval[] getArraySizes(InstructionHandle stmt, CallString cs) {
    ContextMap<CallString, Interval[]> map = sizes.get(stmt);
    Interval[] retval = null;
    if (map == null) {
        return retval;
    }
    for (CallString c : map.keySet()) {
        if (c.hasSuffix(cs)) {
            if (retval == null) {
                Interval[] v = map.get(c);
                // JDK1.5 compat
                retval = new Interval[v.length];
                System.arraycopy(v, 0, retval, 0, v.length);
            // JDK1.6 only
            //retval = Arrays.copyOf(v, v.length);
            } else {
                Interval[] v = map.get(c);
                for (int k = 0; k < v.length; k++) {
                    retval[k].join(v[k]);
                }
            }
        }
    }
    return retval;
}
Also used : CallString(com.jopdesign.common.code.CallString)

Example 34 with CallString

use of com.jopdesign.common.code.CallString in project jop by jop-devel.

the class SymbolicPointsTo method initial.

public ContextMap<CallString, SymbolicAddressMap> initial(InstructionHandle stmt) {
    ContextMap<CallString, SymbolicAddressMap> retval = new ContextMap<CallString, SymbolicAddressMap>(new Context(), new HashMap<CallString, SymbolicAddressMap>());
    SymbolicAddressMap init = new SymbolicAddressMap(bsFactory);
    // Add symbolic stack names
    int stackPtr = 0;
    if (!entryMethod.isStatic()) {
        init.putStack(stackPtr++, bsFactory.singleton(SymbolicAddress.rootAddress("$this")));
    }
    String[] args = entryMethod.getArgumentNames();
    for (int i = 0; i < args.length; i++) {
        Type ty = entryMethod.getArgumentType(i);
        if (ty instanceof ReferenceType) {
            init.putStack(stackPtr, bsFactory.singleton(SymbolicAddress.rootAddress("$" + args[i])));
        }
        stackPtr += ty.getSize();
    }
    retval.put(initialCallString, init);
    return retval;
}
Also used : Context(com.jopdesign.dfa.framework.Context) ReferenceType(org.apache.bcel.generic.ReferenceType) Type(org.apache.bcel.generic.Type) CallString(com.jopdesign.common.code.CallString) ContextMap(com.jopdesign.dfa.framework.ContextMap) ReferenceType(org.apache.bcel.generic.ReferenceType) CallString(com.jopdesign.common.code.CallString)

Example 35 with CallString

use of com.jopdesign.common.code.CallString in project jop by jop-devel.

the class SymbolicPointsTo method join.

public ContextMap<CallString, SymbolicAddressMap> join(ContextMap<CallString, SymbolicAddressMap> s1, ContextMap<CallString, SymbolicAddressMap> s2) {
    if (s1 == null) {
        return new ContextMap<CallString, SymbolicAddressMap>(s2);
    }
    if (s2 == null) {
        return new ContextMap<CallString, SymbolicAddressMap>(s1);
    }
    // create empty context map, with s1's context
    ContextMap<CallString, SymbolicAddressMap> result = new ContextMap<CallString, SymbolicAddressMap>(new Context(s1.getContext()), new HashMap<CallString, SymbolicAddressMap>());
    // add both context maps. Note that entries from s2 overwrite those from the s1
    result.putAll(s1);
    result.putAll(s2);
    // a and b are the DF results for the respectively active contexts
    SymbolicAddressMap a = s1.get(s1.getContext().callString);
    SymbolicAddressMap b = s2.get(s2.getContext().callString);
    SymbolicAddressMap merged = a.clone();
    merged.join(b);
    result.put(s2.getContext().callString, merged);
    if (result.getContext().stackPtr < 0) {
        result.getContext().stackPtr = s2.getContext().stackPtr;
    }
    if (result.getContext().syncLevel < 0) {
        result.getContext().syncLevel = s2.getContext().syncLevel;
    }
    result.getContext().threaded = Context.isThreaded();
    return result;
}
Also used : Context(com.jopdesign.dfa.framework.Context) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString)

Aggregations

CallString (com.jopdesign.common.code.CallString)39 ContextMap (com.jopdesign.dfa.framework.ContextMap)18 Context (com.jopdesign.dfa.framework.Context)17 InstructionHandle (org.apache.bcel.generic.InstructionHandle)17 LinkedHashSet (java.util.LinkedHashSet)15 Set (java.util.Set)13 MethodInfo (com.jopdesign.common.MethodInfo)12 LinkedHashMap (java.util.LinkedHashMap)10 DFATool (com.jopdesign.dfa.DFATool)8 Map (java.util.Map)7 AppInfoError (com.jopdesign.common.misc.AppInfoError)5 GETFIELD (org.apache.bcel.generic.GETFIELD)4 ReferenceType (org.apache.bcel.generic.ReferenceType)4 Type (org.apache.bcel.generic.Type)4 InvokeSite (com.jopdesign.common.code.InvokeSite)3 Pair (com.jopdesign.common.graphutils.Pair)3 BoundedSet (com.jopdesign.dfa.framework.BoundedSetFactory.BoundedSet)3 GETSTATIC (org.apache.bcel.generic.GETSTATIC)3 Instruction (org.apache.bcel.generic.Instruction)3 LDC (org.apache.bcel.generic.LDC)3