Search in sources :

Example 26 with CallString

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

the class DFATool method dumpDFA.

public String dumpDFA(MethodInfo method) {
    if (getLoopBounds() == null)
        return "n/a";
    if (method.isAbstract()) {
        return "n/a";
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream os = new PrintStream(baos);
    Map<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> results = getLoopBounds().getResult();
    if (results == null)
        return "n/a";
    AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>> printer = new AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>>();
    for (Entry<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> ihEntry : results.entrySet()) {
        for (Entry<CallString, Pair<ValueMapping, ValueMapping>> csEntry : ihEntry.getValue().entrySet()) {
            if (ihEntry.getValue().getContext().getMethodInfo().equals(method)) {
                printer.addResult(method, ihEntry.getKey().getPosition(), csEntry.getKey(), csEntry.getValue());
            }
        }
    }
    printer.dump(os);
    try {
        return baos.toString("UTF-8");
    } catch (UnsupportedEncodingException e) {
        return baos.toString();
    }
}
Also used : PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap) ValueMapping(com.jopdesign.dfa.analyses.ValueMapping) CallString(com.jopdesign.common.code.CallString) AnalysisResultSerialization(com.jopdesign.dfa.framework.AnalysisResultSerialization) Pair(com.jopdesign.common.graphutils.Pair)

Example 27 with CallString

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

the class DFATool method getReceiverMethods.

public Set<MethodInfo> getReceiverMethods(InstructionHandle stmt, CallString cs) {
    Set<String> receivers = getReceivers(stmt, cs);
    Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>(receivers.size());
    for (String rcv : receivers) {
        MemberID mID = MemberID.parse(rcv);
        methods.add(appInfo.getMethodInfoInherited(mID));
    }
    return methods;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberID(com.jopdesign.common.type.MemberID) MethodInfo(com.jopdesign.common.MethodInfo) CallString(com.jopdesign.common.code.CallString)

Example 28 with CallString

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

the class CallStringReceiverTypes method doInvokeVirtual.

private void doInvokeVirtual(String receiver, MethodInfo method, InstructionHandle stmt, Context context, ContextMap<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state, ContextMap<CallString, Set<TypeMapping>> result) {
    String methodImplName = method.getClassName() + "." + method.getMethodSignature();
    recordReceiver(stmt, context, methodImplName);
    //		LineNumberTable lines = p.getMethods().get(context.method).getLineNumberTable(context.constPool);
    //		int sourceLine = lines.getSourceLine(stmt.getPosition());
    //		String invokeId = context.method+"\t"+":"+sourceLine+"."+stmt.getPosition();
    // 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(context.getMethodInfo(), stmt, callStringLength);
    boolean threaded = false;
    DFATool p = interpreter.getDFATool();
    if (p.getAppInfo().getClassInfo(receiver).isSubclassOf(p.getAppInfo().getClassInfo("joprt.RtThread")) && "run()V".equals(method.getMethodSignature())) {
        c.createThread();
        threaded = true;
    }
    // carry only minimal information with call
    Set<TypeMapping> in = input.get(context.callString);
    Set<TypeMapping> out = new LinkedHashSet<TypeMapping>();
    ContextMap<CallString, Set<TypeMapping>> tmpresult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
    tmpresult.put(c.callString, out);
    for (TypeMapping m : in) {
        if (m.stackLoc < 0) {
            out.add(m);
        }
        if (m.stackLoc > varPtr) {
            out.add(new TypeMapping(m.stackLoc - varPtr, m.type));
        }
        if (m.stackLoc == varPtr) {
            // add "this"
            ClassInfo staticClass = p.getAppInfo().getClassInfo(receiver);
            ClassInfo dynamicClass = null;
            try {
                dynamicClass = p.getAppInfo().getClassInfo(m.type.split("@")[0]);
            } catch (MissingClassError ex) {
                logger.error("doInvokeVirtual - trying to improve type of " + staticClass + ": " + ex);
            // TODO: maybe we should throw an exception/error instead?
            }
            if (dynamicClass != null && dynamicClass.isSubclassOf(staticClass)) {
                out.add(new TypeMapping(0, m.type));
            }
        }
    }
    InstructionHandle entry = p.getEntryHandle(method);
    state.put(entry, join(state.get(entry), tmpresult));
    // interpret method
    Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
    // pull out relevant information from call
    InstructionHandle exit = p.getExitHandle(method);
    if (r.get(exit) != null) {
        Set<TypeMapping> returned = r.get(exit).get(c.callString);
        if (returned != null) {
            filterReturnSet(returned, result.get(context.callString), varPtr);
        }
    }
    // update all threads
    if (threaded) {
        threads.put(methodImplName, new ContextMap<CallString, Set<TypeMapping>>(c, result));
        updateThreads(result, interpreter, state);
    }
}
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) CallString(com.jopdesign.common.code.CallString) ClassInfo(com.jopdesign.common.ClassInfo) MissingClassError(com.jopdesign.common.misc.MissingClassError)

Example 29 with CallString

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

the class CallStringReceiverTypes method join.

public ContextMap<CallString, Set<TypeMapping>> join(ContextMap<CallString, Set<TypeMapping>> s1, ContextMap<CallString, Set<TypeMapping>> s2) {
    if (s1 == null) {
        return new ContextMap<CallString, Set<TypeMapping>>(s2);
    }
    if (s2 == null) {
        return new ContextMap<CallString, Set<TypeMapping>>(s1);
    }
    ContextMap<CallString, Set<TypeMapping>> result = new ContextMap<CallString, Set<TypeMapping>>(new Context(s2.getContext()), new LinkedHashMap<CallString, Set<TypeMapping>>());
    result.putAll(s1);
    result.putAll(s2);
    Set<TypeMapping> a = s1.get(s2.getContext().callString);
    Set<TypeMapping> b = s2.get(s2.getContext().callString);
    Set<TypeMapping> merged = new LinkedHashSet<TypeMapping>();
    if (a != null) {
        merged.addAll(a);
    }
    if (b == null) {
        logger.error("RT join: failed to find DF information for " + s2.getContext().callString.toStringVerbose(false));
    }
    merged.addAll(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) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString)

Example 30 with CallString

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

the class CallStringReceiverTypes method initial.

public ContextMap<CallString, Set<TypeMapping>> initial(InstructionHandle stmt) {
    ContextMap<CallString, Set<TypeMapping>> init = new ContextMap<CallString, Set<TypeMapping>>(new Context(), new LinkedHashMap<CallString, Set<TypeMapping>>());
    Set<TypeMapping> s = new LinkedHashSet<TypeMapping>();
    s.add(new TypeMapping("com.jopdesign.io.IOFactory.sp", "com.jopdesign.io.SerialPort"));
    s.add(new TypeMapping("com.jopdesign.io.IOFactory.sys", "com.jopdesign.io.SysDevice"));
    init.put(CallString.EMPTY, s);
    return init;
}
Also used : Context(com.jopdesign.dfa.framework.Context) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) 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