Search in sources :

Example 11 with CallString

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

the class CallStringReceiverTypes method initialize.

public void initialize(MethodInfo mi, Context context) {
    String sig = mi.getFQMethodName();
    threads.put(sig, new ContextMap<CallString, Set<TypeMapping>>(context, new LinkedHashMap<CallString, Set<TypeMapping>>()));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) CallString(com.jopdesign.common.code.CallString) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with CallString

use of com.jopdesign.common.code.CallString 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 13 with CallString

use of com.jopdesign.common.code.CallString 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 14 with CallString

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

the class LoopBounds method getBound.

public int getBound(InstructionHandle instr, CallString csSuffix) {
    ContextMap<CallString, Pair<ValueMapping, ValueMapping>> r = bounds.get(instr);
    if (r == null) {
        // no bound at this point
        return -1;
    }
    // merge bound for all contexts
    int maxValue = -1;
    for (CallString callString : r.keySet()) {
        if (!callString.hasSuffix(csSuffix))
            continue;
        Pair<ValueMapping, ValueMapping> bounds = r.get(callString);
        ValueMapping first = bounds.first();
        ValueMapping second = bounds.second();
        if (first == null || second == null) {
            return -1;
        }
        InstructionHandle target = ((BranchInstruction) instr.getInstruction()).getTarget();
        if (scopes.get(target) != null) {
            if (scopes.get(target).get(callString) <= first.defscope || scopes.get(target).get(callString) <= second.defscope) {
                return -1;
            }
        }
        if (scopes.get(instr).get(callString) <= first.defscope || scopes.get(instr).get(callString) <= second.defscope) {
            return -1;
        }
        //			if (first.softinc || second.softinc) {
        //				return -1;
        //			}
        int val = ValueMapping.computeBound(first, second);
        if (val < 0) {
            // no bound for some context
            return -1;
        } else {
            // compute the maximum
            maxValue = Math.max(maxValue, val);
        }
    }
    return maxValue;
}
Also used : BranchInstruction(org.apache.bcel.generic.BranchInstruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CallString(com.jopdesign.common.code.CallString) Pair(com.jopdesign.common.graphutils.Pair)

Example 15 with CallString

use of com.jopdesign.common.code.CallString 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)

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