Search in sources :

Example 6 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class CallStringReceiverTypes 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;
        ContextMap<CallString, Set<String>> value = targets.get(oldHandle);
        // TODO this does NOT update stackPtr,.. in the new context!
        if (value != null)
            targets.put(newHandle, value.copy(newContainer));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ContextMap(com.jopdesign.dfa.framework.ContextMap) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CallString(com.jopdesign.common.code.CallString)

Example 7 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class CallStringReceiverTypes method updateThreads.

private void updateThreads(Map<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state) {
    DFATool p = interpreter.getDFATool();
    boolean modified = true;
    while (modified) {
        modified = false;
        Map<String, ContextMap<CallString, Set<TypeMapping>>> tmpThreads = new LinkedHashMap<String, ContextMap<CallString, Set<TypeMapping>>>();
        for (String methodName : threads.keySet()) {
            MethodInfo method = p.getMethod(methodName);
            InstructionHandle entry = p.getEntryHandle(method);
            Context c = state.get(entry).getContext();
            int varPtr = c.stackPtr - MethodHelper.getArgSize(method);
            // prepare input information
            ContextMap<CallString, Set<TypeMapping>> threadInput = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
            for (CallString cs : input.keySet()) {
                Set<TypeMapping> s = input.get(cs);
                Set<TypeMapping> o = new LinkedHashSet<TypeMapping>();
                filterSet(s, o, 0);
                threadInput.put(cs, o);
            }
            state.put(entry, join(threadInput, state.get(entry)));
            // save information
            ContextMap<CallString, Set<TypeMapping>> savedResult = threads.get(methodName);
            // interpret thread
            Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
            // pull out relevant information from thread
            InstructionHandle exit = p.getExitHandle(method);
            ContextMap<CallString, Set<TypeMapping>> threadResult;
            if (r.get(exit) != null) {
                threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
                threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
                Set<TypeMapping> returned = r.get(exit).get(c.callString);
                filterReturnSet(returned, threadResult.get(c.callString), varPtr);
            } else {
                threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
                threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
            }
            if (!threadResult.equals(savedResult)) {
                modified = true;
            }
            tmpThreads.put(methodName, threadResult);
        }
        threads = tmpThreads;
    }
}
Also used : Context(com.jopdesign.dfa.framework.Context) LinkedHashSet(java.util.LinkedHashSet) DFATool(com.jopdesign.dfa.DFATool) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) CallString(com.jopdesign.common.code.CallString) ContextMap(com.jopdesign.dfa.framework.ContextMap) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedHashMap(java.util.LinkedHashMap) CallString(com.jopdesign.common.code.CallString) MethodInfo(com.jopdesign.common.MethodInfo)

Example 8 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class LoopBounds method initial.

public ContextMap<CallString, Map<Location, ValueMapping>> initial(InstructionHandle stmt) {
    ContextMap<CallString, Map<Location, ValueMapping>> retval = new ContextMap<CallString, Map<Location, ValueMapping>>(new Context(), new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
    CallString l = CallString.EMPTY;
    Map<Location, ValueMapping> init = new LinkedHashMap<Location, ValueMapping>();
    ValueMapping value;
    value = new ValueMapping();
    value.assigned.setLb(0);
    value.assigned.setUb(16);
    init.put(new Location("com.jopdesign.io.SysDevice.nrCpu"), value);
    retval.put(l, init);
    return retval;
}
Also used : Context(com.jopdesign.dfa.framework.Context) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class LoopBounds method join.

public ContextMap<CallString, Map<Location, ValueMapping>> join(ContextMap<CallString, Map<Location, ValueMapping>> s1, ContextMap<CallString, Map<Location, ValueMapping>> s2) {
    if (s1 == null) {
        return new ContextMap<CallString, Map<Location, ValueMapping>>(s2);
    }
    if (s2 == null) {
        return new ContextMap<CallString, Map<Location, ValueMapping>>(s1);
    }
    ContextMap<CallString, Map<Location, ValueMapping>> result = new ContextMap<CallString, Map<Location, ValueMapping>>(new Context(s1.getContext()), new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
    result.putAll(s1);
    result.putAll(s2);
    Map<Location, ValueMapping> a = s1.get(s2.getContext().callString);
    Map<Location, ValueMapping> b = s2.get(s2.getContext().callString);
    if (a != null || b != null) {
        if (a == null) {
            a = new LinkedHashMap<Location, ValueMapping>();
        }
        if (b == null) {
            b = new LinkedHashMap<Location, ValueMapping>();
        }
        Map<Location, ValueMapping> merged = new LinkedHashMap<Location, ValueMapping>(a);
        for (Location l : b.keySet()) {
            ValueMapping x = a.get(l);
            ValueMapping y = b.get(l);
            if (x != null) {
                if (!x.equals(y)) {
                    ValueMapping r = new ValueMapping(x, true);
                    r.join(y);
                    merged.put(l, r);
                } else {
                    merged.put(l, x);
                }
            } else {
                merged.put(l, y);
            }
        }
        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) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class LoopBounds method doInvoke.

private void doInvoke(String methodName, InstructionHandle stmt, Context context, Map<CallString, Map<Location, ValueMapping>> input, Interpreter<CallString, Map<Location, ValueMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> state, Map<CallString, Map<Location, ValueMapping>> result) {
    DFATool p = interpreter.getDFATool();
    MethodInfo method = p.getMethod(methodName);
    if (method.isNative()) {
        handleNative(method, context, input, result);
    } else {
        // set up new context
        int varPtr = context.stackPtr - MethodHelper.getArgSize(method);
        Context c = new Context(context);
        c.stackPtr = method.getCode().getMaxLocals();
        if (method.isSynchronized()) {
            c.syncLevel = context.syncLevel + 1;
        }
        c.setMethodInfo(method);
        c.callString = c.callString.push(method, stmt, callStringLength);
        // carry only minimal information with call
        Map<Location, ValueMapping> in = input.get(context.callString);
        Map<Location, ValueMapping> out = new LinkedHashMap<Location, ValueMapping>();
        for (Location l : in.keySet()) {
            if (l.stackLoc < 0) {
                out.put(l, in.get(l));
            }
            if (l.stackLoc >= varPtr) {
                out.put(new Location(l.stackLoc - varPtr), new ValueMapping(in.get(l), false));
            }
        }
        ContextMap<CallString, Map<Location, ValueMapping>> tmpresult = new ContextMap<CallString, Map<Location, ValueMapping>>(c, new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
        tmpresult.put(c.callString, out);
        InstructionHandle entry = p.getEntryHandle(method);
        state.put(entry, join(state.get(entry), tmpresult));
        // interpret method
        Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> r = interpreter.interpret(c, entry, state, false);
        //System.out.println(">>>>>>>>");
        // pull out relevant information from call
        InstructionHandle exit = p.getExitHandle(method);
        if (r.get(exit) != null) {
            Map<Location, ValueMapping> returned = r.get(exit).get(c.callString);
            if (returned != null) {
                for (Location l : returned.keySet()) {
                    if (l.stackLoc < 0) {
                        ValueMapping m = new ValueMapping(returned.get(l), true);
                        m.join(result.get(context.callString).get(l));
                        result.get(context.callString).put(l, m);
                    }
                    if (l.stackLoc >= 0) {
                        ValueMapping m = new ValueMapping(returned.get(l), false);
                        Location loc = new Location(l.stackLoc + varPtr);
                        m.join(result.get(context.callString).get(loc));
                        result.get(context.callString).put(loc, m);
                    }
                }
            }
        }
        // add relevant information to result
        for (Location l : in.keySet()) {
            if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - MethodHelper.getArgSize(method)) {
                result.get(context.callString).put(l, new ValueMapping(in.get(l), true));
            }
        }
    }
}
Also used : Context(com.jopdesign.dfa.framework.Context) DFATool(com.jopdesign.dfa.DFATool) ContextMap(com.jopdesign.dfa.framework.ContextMap) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedHashMap(java.util.LinkedHashMap) CallString(com.jopdesign.common.code.CallString) MethodInfo(com.jopdesign.common.MethodInfo) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ContextMap(com.jopdesign.dfa.framework.ContextMap)

Aggregations

ContextMap (com.jopdesign.dfa.framework.ContextMap)19 CallString (com.jopdesign.common.code.CallString)18 Context (com.jopdesign.dfa.framework.Context)16 Set (java.util.Set)10 InstructionHandle (org.apache.bcel.generic.InstructionHandle)10 LinkedHashSet (java.util.LinkedHashSet)9 DFATool (com.jopdesign.dfa.DFATool)8 LinkedHashMap (java.util.LinkedHashMap)7 MethodInfo (com.jopdesign.common.MethodInfo)6 Map (java.util.Map)6 ReferenceType (org.apache.bcel.generic.ReferenceType)4 Type (org.apache.bcel.generic.Type)4 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 GETFIELD (org.apache.bcel.generic.GETFIELD)3 GETSTATIC (org.apache.bcel.generic.GETSTATIC)3 Instruction (org.apache.bcel.generic.Instruction)3 LDC (org.apache.bcel.generic.LDC)3 LoadInstruction (org.apache.bcel.generic.LoadInstruction)3 PUTFIELD (org.apache.bcel.generic.PUTFIELD)3 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)3