Search in sources :

Example 36 with CallString

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

the class SymbolicPointsTo method handleNative.

@SuppressWarnings({ "LiteralAsArgToStringEquals" })
private Map<CallString, SymbolicAddressMap> handleNative(MethodInfo method, Context context, ContextMap<CallString, SymbolicAddressMap> input, ContextMap<CallString, SymbolicAddressMap> retval) {
    String methodId = method.getMemberID().toString(false);
    SymbolicAddressMap in = input.get(context.callString);
    SymbolicAddressMap out;
    int nextStackPtr = context.stackPtr - 1;
    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")) {
        out = in.cloneFilterStack(nextStackPtr);
    } 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")) {
        out = in.cloneFilterStack(nextStackPtr - 2);
    } else if (methodId.equals("com.jopdesign.sys.Native.toInt(Ljava/lang/Object;)I")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toInt(F)I")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toInt(Ljava/lang/Object;)I")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toInt(Ljava/lang/Object;)I")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toLong(D)J")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toDouble(J)D")) {
        out = in.cloneFilterStack(nextStackPtr);
    } else if (methodId.equals("com.jopdesign.sys.Native.toObject(I)Ljava/lang/Object;") || methodId.equals("com.jopdesign.sys.Native.toIntArray(I)[I")) {
        out = in.cloneFilterStack(nextStackPtr);
        out.putStack(context.stackPtr - 1, bsFactory.top());
    } else if (methodId.equals("com.jopdesign.sys.Native.getSP()I")) {
        out = in.cloneFilterStack(nextStackPtr + 1);
    } else if (methodId.equals("com.jopdesign.sys.Native.getField(II)I")) {
        out = in.cloneFilterStack(nextStackPtr - 1);
    } else if (methodId.equals("com.jopdesign.sys.Native.putField(III)V")) {
        out = in.cloneFilterStack(nextStackPtr - 3);
    } else if (methodId.equals("com.jopdesign.sys.Native.condMove(IIZ)I")) {
        out = in.cloneFilterStack(nextStackPtr - 2);
    } else if (methodId.equals("com.jopdesign.sys.Native.arrayLoad(II)I")) {
        out = in.cloneFilterStack(nextStackPtr - 1);
    } else if (methodId.equals("com.jopdesign.sys.Native.arrayStore(III)V")) {
        out = in.cloneFilterStack(nextStackPtr - 3);
    } else if (methodId.equals("com.jopdesign.sys.Native.condMoveRef(Ljava/lang/Object;Ljava/lang/Object;Z)Ljava/lang/Object;")) {
        out = in.cloneFilterStack(nextStackPtr - 2);
        BoundedSet<SymbolicAddress> joined = in.getStack(context.stackPtr - 3).join(in.getStack(context.stackPtr - 2));
        out.putStack(context.stackPtr - 3, joined);
    } else {
        out = null;
        RuntimeException ex = new RuntimeException("Unknown native method: " + methodId);
        Logger.getLogger(this.getClass()).error(ex);
        throw ex;
    }
    retval.put(context.callString, out);
    return retval;
}
Also used : BoundedSet(com.jopdesign.dfa.framework.BoundedSetFactory.BoundedSet) CallString(com.jopdesign.common.code.CallString)

Example 37 with CallString

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

the class AnalysisResultSerialization method toContextMapResult.

public <T> Map<InstructionHandle, ContextMap<CallString, T>> toContextMapResult(AppInfo appInfo, Serializer<T, R> serializer) throws MethodNotFoundException, IOException, ClassNotFoundException {
    /* `context' is a really bad hack in the DFA. In the deserialization,
		 * we guarantee that context.getMethodInfo() and context.callstring are correct,
		 * but the rest of context is undefined.
		 */
    Context currentContext;
    Map<InstructionHandle, ContextMap<CallString, T>> resultMap = new LinkedHashMap<InstructionHandle, ContextMap<CallString, T>>();
    for (Entry<String, Map<CallStringSerialization, Map<Integer, R>>> miEntry : serializedResults.entrySet()) {
        MethodInfo mi = appInfo.getMethodInfo(MemberID.parse(miEntry.getKey()));
        for (Entry<CallStringSerialization, Map<Integer, R>> csEntry : miEntry.getValue().entrySet()) {
            CallString cs = csEntry.getKey().getCallString(appInfo);
            currentContext = new Context();
            currentContext.setMethodInfo(mi);
            currentContext.callString = cs;
            for (Entry<Integer, R> posEntry : csEntry.getValue().entrySet()) {
                int pos = posEntry.getKey();
                R value = posEntry.getValue();
                InstructionHandle instr = mi.getCode().getInstructionList(false, false).findHandle(pos);
                ContextMap<CallString, T> ctxMap = resultMap.get(instr);
                if (ctxMap == null) {
                    ctxMap = new ContextMap<CallString, T>(currentContext, new LinkedHashMap<CallString, T>());
                    resultMap.put(instr, ctxMap);
                }
                if (serializer == null) {
                    ctxMap.put(cs, (T) value);
                } else {
                    T origValue = serializer.fromSerializedRepresentation(value, appInfo);
                    ctxMap.put(cs, origValue);
                }
            }
        }
    }
    return resultMap;
}
Also used : CallStringSerialization(com.jopdesign.common.code.CallString.CallStringSerialization) CallString(com.jopdesign.common.code.CallString) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedHashMap(java.util.LinkedHashMap) CallString(com.jopdesign.common.code.CallString) MethodInfo(com.jopdesign.common.MethodInfo) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 38 with CallString

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

the class InlineOptimizer method findCandidates.

@Override
public Collection<Candidate> findCandidates(MethodInfo method, AnalysisManager analyses, StacksizeAnalysis stacksize, int maxLocals, InstructionHandle start, InstructionHandle end) {
    List<Candidate> candidates = new LinkedList<Candidate>();
    MethodCode code = method.getCode();
    InstructionHandle next = end.getNext();
    for (InstructionHandle ih = start; ih != next; ih = ih.getNext()) {
        if (code.isInvokeSite(ih)) {
            InvokeSite site = code.getInvokeSite(ih);
            // since we update the appInfo callgraph, the callstring only contains the invokesite and no
            // inlined methods
            CallString cs = new CallString(site);
            countInvokeSites++;
            MethodInfo invokee = helper.devirtualize(cs);
            if (invokee == null)
                continue;
            countDevirtualized++;
            // for the initial check and the DFA lookup we need the old callstring
            cs = getInlineCallString(code, ih).push(site);
            Candidate candidate = checkInvoke(code, cs, site, invokee, maxLocals);
            if (candidate == null) {
                continue;
            }
            // initial check for locals and stack, calculate gain and codesize
            if (!candidate.recalculate(analyses, stacksize)) {
                continue;
            }
            candidates.add(candidate);
        }
    }
    return candidates;
}
Also used : Candidate(com.jopdesign.jcopter.greedy.Candidate) MethodInfo(com.jopdesign.common.MethodInfo) InvokeSite(com.jopdesign.common.code.InvokeSite) MethodCode(com.jopdesign.common.MethodCode) LinkedList(java.util.LinkedList) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CallString(com.jopdesign.common.code.CallString)

Example 39 with CallString

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

the class ObjectCacheAnalysis method extractAccessesAndCosts.

/** Traverse vertex set.
	 * <p>Add vertex to access set of referenced addresses
	 * For references whose type cannot be fully resolved, add a
	 * cost of 1.</p>
	 * <p>FIXME: We should deal with subtyping (or better use storage based alias-analysis)</p>
	 *
	 * @param nodes
	 * @param usedRefs the results of the local points-to analysis, or {@code null} for always miss costs
	 * @param costModel
	 */
private AccessCostInfo extractAccessesAndCosts(Iterable<SuperGraphNode> nodes, LocalPointsToResult usedRefs, ObjectCacheCostModel costModel) {
    AccessCostInfo aci = new AccessCostInfo();
    for (SuperGraphNode node : nodes) {
        /* Compute cost for basic block */
        BasicBlock bb = node.getCFGNode().getBasicBlock();
        if (bb == null)
            continue;
        long bypassCost = 0;
        long alwaysMissCost = 0;
        CallString cs = node.getContextCFG().getCallString();
        for (InstructionHandle ih : bb.getInstructions()) {
            String handleType = getHandleType(project, node.getCfg(), ih);
            if (handleType == null)
                continue;
            /* No getfield/handle access */
            int fieldIndex = getFieldIndex(project, node.getCfg(), ih);
            int blockIndex = getBlockIndex(fieldIndex);
            if (fieldIndex > this.maxCachedFieldIndex) {
                bypassCost += costModel.getFieldAccessCostBypass();
                continue;
            }
            BoundedSet<SymbolicAddress> refs = null;
            if (usedRefs != null) {
                if (!usedRefs.containsKey(ih)) {
                    usedRefs = null;
                    WCETTool.logger.error("No DFA results for: " + ih.getInstruction() + " with field " + ((FieldInstruction) ih.getInstruction()).getFieldName(bb.cpg()));
                } else {
                    refs = usedRefs.get(ih, cs);
                    if (refs.isSaturated())
                        refs = null;
                }
            }
            if (refs == null) {
                alwaysMissCost += costModel.getReplaceLineCost() + costModel.getLoadCacheBlockCost();
            } else {
                for (SymbolicAddress ref : refs.getSet()) {
                    aci.addRefAccess(ref, node);
                    aci.addBlockAccess(ref.accessArray(blockIndex), node);
                    // Handle getfield_long / getfield_double
                    if (getCachedType(project, node.getCfg(), ih) == Type.LONG || getCachedType(project, node.getCfg(), ih) == Type.DOUBLE) {
                        if (blockIndex + 1 > this.maxCachedFieldIndex) {
                            bypassCost += costModel.getFieldAccessCostBypass();
                        } else {
                            aci.addBlockAccess(ref.accessArray(blockIndex + 1), node);
                        }
                    }
                }
            }
        }
        aci.putBypassCost(node, bypassCost);
        aci.putStaticCost(node, bypassCost + alwaysMissCost);
    }
    return aci;
}
Also used : AccessCostInfo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo) BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) FieldInstruction(org.apache.bcel.generic.FieldInstruction) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) InstructionHandle(org.apache.bcel.generic.InstructionHandle) 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