Search in sources :

Example 16 with CallString

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

the class LoopBounds method printSizeResult.

public void printSizeResult(DFATool program) {
    for (InstructionHandle instr : sizes.keySet()) {
        ContextMap<CallString, Interval[]> r = sizes.get(instr);
        Context c = r.getContext();
        LineNumberTable lines = c.getMethodInfo().getCode().getLineNumberTable();
        int sourceLine = lines.getSourceLine(instr.getPosition());
        for (CallString callString : r.keySet()) {
            Interval[] bounds = r.get(callString);
            System.out.println(c.method() + ":" + sourceLine + ":\t" + callString.toStringList() + ": ");
            System.out.println(Arrays.asList(bounds));
        }
    }
}
Also used : Context(com.jopdesign.dfa.framework.Context) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LineNumberTable(org.apache.bcel.classfile.LineNumberTable) CallString(com.jopdesign.common.code.CallString)

Example 17 with CallString

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

Example 18 with CallString

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

the class LoopBounds method getArrayIndices.

public Interval getArrayIndices(InstructionHandle stmt, CallString cs) {
    ContextMap<CallString, Interval> map = arrayIndices.get(stmt);
    Interval retval = null;
    if (map == null) {
        return retval;
    }
    for (CallString c : map.keySet()) {
        if (c.hasSuffix(cs)) {
            if (retval == null) {
                retval = new Interval(map.get(c));
            } else {
                retval.join(map.get(c));
            }
        }
    }
    return retval;
}
Also used : CallString(com.jopdesign.common.code.CallString)

Example 19 with CallString

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

the class SimpleInliner method optimizeMethod.

@Override
public void optimizeMethod(MethodInfo method) {
    InlineData inlineData = new InlineData();
    List<InvokeSite> invokes = new ArrayList<InvokeSite>(method.getCode().getInvokeSites());
    // we iterate over the invoke sites in a sorted order for the single reason that the DFA cache hack works
    // (else the order of the entries in the constantpool can differ)
    Collections.sort(invokes, new Comparator<InvokeSite>() {

        @Override
        public int compare(InvokeSite o1, InvokeSite o2) {
            return o1.getInstructionHandle().getPosition() - o2.getInstructionHandle().getPosition();
        }
    });
    for (InvokeSite invoke : invokes) {
        // The callstring contains 'original' invokesites from the unmodified callgraph,
        // 'invoke' refers to the new invokesite in the modified code
        CallString cs = new CallString(invoke);
        while (invoke != null) {
            countInvokeSites++;
            MethodInfo invokee = helper.devirtualize(cs);
            if (invokee == null)
                break;
            countDevirtualized++;
            // Preliminary checks
            if (checkInvoke(invoke, cs, invokee, inlineData)) {
                invoke = performSimpleInline(invoke, invokee, inlineData);
                inlineCounter++;
                if (inlineData.getInvokeSite() != null) {
                    cs.push(inlineData.getInvokeSite());
                } else {
                    break;
                }
            } else {
                break;
            }
        }
    }
// update callgraph (?) If we update the callgraph, the callstrings become invalid!
// -> update callgraph only after we finished inlining of a toplevel invokesite;
//    collect all invokesites to collapse into toplevel invokesite;
//    replace old invokesite with invokesites from inlined code, add edges to not inlined methods
// We could collect all nodes to merge and call callgraph.merge(), but this is not yet implemented.
// Instead we simply rebuild the whole callgraph and all results which use callstrings.
}
Also used : ArrayList(java.util.ArrayList) MethodInfo(com.jopdesign.common.MethodInfo) InvokeSite(com.jopdesign.common.code.InvokeSite) CallString(com.jopdesign.common.code.CallString)

Example 20 with CallString

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

the class ExecFrequencyProvider method getExecCount.

public long getExecCount(ExecutionContext context) {
    CallString cs = context.getCallString();
    if (cs.isEmpty()) {
        return getExecCount(context.getMethodInfo());
    }
    // if we have a callstring, we need to start at the beginning of the callstring, then multiply the
    // frequencies up to the invoked method along the callstring
    long count = getExecCount(cs.first().getInvoker());
    for (int i = 0; i < cs.length(); i++) {
        InvokeSite is = cs.get(i);
        MethodInfo invokee = i + 1 < cs.length() ? cs.get(i + 1).getInvoker() : context.getMethodInfo();
        count *= getExecFrequency(is, invokee);
    }
    return count;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) InvokeSite(com.jopdesign.common.code.InvokeSite) 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