Search in sources :

Example 21 with CallString

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

the class DFATool method getReceivers.

public Set<String> getReceivers(InstructionHandle stmt, CallString cs) {
    ContextMap<CallString, Set<String>> map = receivers.getResult().get(stmt);
    if (map == null) {
        return null;
    }
    Set<String> retval = new LinkedHashSet<String>();
    for (CallString c : map.keySet()) {
        if (c.hasSuffix(cs)) {
            retval.addAll(map.get(c));
        }
    }
    return retval;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) CallString(com.jopdesign.common.code.CallString) CallString(com.jopdesign.common.code.CallString)

Example 22 with CallString

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

the class DFATool method runReceiverAnalysis.

public Map<InstructionHandle, ContextMap<CallString, Set<String>>> runReceiverAnalysis(int callstringLength) {
    CallStringReceiverTypes recTys = new CallStringReceiverTypes(callstringLength);
    @SuppressWarnings({ "unchecked" }) Map<InstructionHandle, ContextMap<CallString, Set<String>>> receiverResults = runAnalysis(recTys);
    setReceivers(recTys);
    return receiverResults;
}
Also used : CallString(com.jopdesign.common.code.CallString) CallStringReceiverTypes(com.jopdesign.dfa.analyses.CallStringReceiverTypes) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap)

Example 23 with CallString

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

the class ObjectCacheAnalysis method getSaturatedTypes.

/** Traverse vertex set. Collect those types where we could not resolve
	 * the symbolic object names. (Not too useful in the analysis, but useful
	 * for debugging)
	 */
public HashSet<String> getSaturatedTypes(Segment segment, LocalPointsToResult usedRefs) {
    HashSet<String> topTypes = new HashSet<String>();
    for (SuperGraphNode n : segment.getNodes()) {
        BasicBlock bb = n.getCFGNode().getBasicBlock();
        if (bb == null)
            continue;
        CallString cs = n.getContextCFG().getCallString();
        for (InstructionHandle ih : bb.getInstructions()) {
            BoundedSet<SymbolicAddress> refs;
            if (usedRefs.containsKey(ih)) {
                refs = usedRefs.get(ih, cs);
                String handleType = getHandleType(project, n.getCfg(), ih);
                if (handleType == null)
                    continue;
                if (refs.isSaturated()) {
                    topTypes.add(handleType);
                }
            }
        }
    }
    return topTypes;
}
Also used : BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) InstructionHandle(org.apache.bcel.generic.InstructionHandle) HashSet(java.util.HashSet) CallString(com.jopdesign.common.code.CallString)

Example 24 with CallString

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

the class IPETUtils method buildLocalILPModel.

/**
     * Create a max-cost maxflow problem for the given flow graph graph, based on a
     * given node to cost mapping.
     *
     * @param wcetTool    A reference to the WCETTool
     * @param problemName a unique identifier for the problem (for reporting)
     * @param cs          context of the method invocation
     * @param cfg         the graph
     * @param nodeWCET    cost of nodes
     * @return The max-cost maxflow problem
     */
public static IPETSolver buildLocalILPModel(WCETTool wcetTool, String problemName, CallString cs, ControlFlowGraph cfg, CostProvider<CFGNode> nodeWCET, IPETConfig ipetConfig) {
    IPETSolver ipetSolver = new IPETSolver(problemName, ipetConfig);
    IPETBuilder<CallString> builder = new IPETBuilder<CallString>(wcetTool, cs);
    ipetSolver.addConstraints(IPETUtils.structuralFlowConstraintsRoot(cfg.getGraph(), builder));
    ipetSolver.addConstraints(IPETUtils.loopBoundConstraints(cfg, builder));
    ipetSolver.addConstraints(IPETUtils.infeasibleEdgeConstraints(cfg, builder));
    for (CFGNode n : cfg.vertexSet()) {
        long nodeCost = nodeWCET.getCost(n);
        for (ControlFlowGraph.CFGEdge e : cfg.outgoingEdgesOf(n)) {
            ipetSolver.addEdgeCost(builder.newEdge(e), nodeCost);
        }
    }
    return ipetSolver;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) CallString(com.jopdesign.common.code.CallString)

Example 25 with CallString

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

the class AppInfo method findImplementations.

/**
     * Find all methods which might get invoked for a given methodRef.
     * This does not use the callgraph to eliminate methods. If you want a more precise result,
     * use {@link #findImplementations(InvokeSite, CallString)} and use callgraph thinning first.
     * <p>
     * Note that this method is slightly different from {@link MethodInfo#getImplementations(boolean)}, since
     * it returns only methods for subclasses of the invokee class, not of the implementing class.
     * </p>
     * <p>To handle invocations of super-methods correctly, use {@link #findImplementations(InvokeSite)}
     * instead.</p>
     *
     * @see #findImplementations(InvokeSite)
     * @see MethodInfo#overrides(MethodRef, boolean)
     * @param invokee the method to resolve.
     * @return all possible implementations, including native methods.
     */
public Set<MethodInfo> findImplementations(final MethodRef invokee) {
    final Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>();
    // 'method' may refer to an inherited MethodInfo or to an interface method if there is no implementation
    final MethodInfo method = invokee.getMethodInfo();
    if (method != null && (method.isStatic() || method.isPrivate())) {
        methods.add(method);
        return methods;
    }
    final String methodSig = invokee.getMethodSignature();
    final ClassInfo invokeeClass = invokee.getClassRef().getClassInfo();
    if (invokeeClass == null) {
        // ok, now, if the target class is unknown, there is not much we can do, so return an empty set
        logger.debug("Trying to find implementations of a method in an unknown class " + invokee.toString());
        return methods;
    }
    // Constructors are only called by invokespecial
    if ("<init>".equals(invokee.getName())) {
        MethodInfo init = invokee.getMethodInfo();
        if (init == null) {
            throw new JavaClassFormatError("Constructor not found: " + invokee);
        }
        if (init.isAbstract()) {
            throw new JavaClassFormatError("Found abstract constructor, this isn't right..: " + invokee);
        }
        methods.add(init);
        return methods;
    }
    boolean undefinedBaseMethod = false;
    // check if method is defined in the referenced class or in a superclass
    if (invokeeClass.getMethodInfo(methodSig) == null) {
        // method is inherited, add to implementations
        if (method != null && !method.isAbstract()) {
            methods.add(method);
        } else if (method == null) {
            // hm, invoke to an unknown method (maybe excluded or native), what should we do?
            if (invokeeClass.isFullyKnown(true)) {
                // .. or maybe the method has not been loaded somehow when the MethodRef was created (check!)
                throw new JavaClassFormatError("Method implementation not found in superclass: " + invokee.toString());
            } else {
                // maybe defined in excluded superclass, but we do not know for sure..
                // We *must* return an empty set, but lets try to continue for now and
                // handle it like an excluded class, and abort only if we find overriding methods
                logger.debug("Method implementation not found in incomplete superclass: " + invokee.toString());
                undefinedBaseMethod = true;
            }
        }
    }
    // now, we have a virtual call on our hands ..
    ClassVisitor visitor = new ClassVisitor() {

        public boolean visitClass(ClassInfo classInfo) {
            // Note: we also handle interface classes here, because they can contain <clinit> methods
            MethodInfo m;
            if (invokeeClass.isInterface() && !classInfo.isInterface()) {
                // If we invoke an interface method, we also need to find inherited methods in implementing
                // classes
                m = classInfo.getMethodInfoInherited(methodSig, true);
            } else {
                // If we do not invoke an interface method, 'method' is already the only possible inherited 
                // method; If the visited class is an interface, it does not inherit implementations.
                m = classInfo.getMethodInfo(methodSig);
            }
            if (m != null) {
                if (m.isPrivate() && !classInfo.equals(invokeeClass)) {
                    // found an overriding method which is private .. this is interesting..
                    logger.error("Found private method " + m.getMethodSignature() + " in " + classInfo.getClassName() + " overriding non-private method in " + invokee.getClassName());
                }
                if (!m.isAbstract() && (method == null || m.overrides(method, false))) {
                    methods.add(m);
                }
            }
            return true;
        }

        public void finishClass(ClassInfo classInfo) {
        }
    };
    ClassHierarchyTraverser traverser = new ClassHierarchyTraverser(visitor);
    traverser.setVisitSubclasses(true, true);
    traverser.traverseDown(invokeeClass);
    if (undefinedBaseMethod && methods.size() > 0) {
        // overriding methods, this we cannot handle for now
        throw new JavaClassFormatError("Found overriding methods for " + invokee + " but superclasses are undefined!");
    }
    return methods;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) ClassHierarchyTraverser(com.jopdesign.common.graphutils.ClassHierarchyTraverser) CallString(com.jopdesign.common.code.CallString) ClassVisitor(com.jopdesign.common.graphutils.ClassVisitor)

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