Search in sources :

Example 6 with DFATool

use of com.jopdesign.dfa.DFATool 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 7 with DFATool

use of com.jopdesign.dfa.DFATool 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 8 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class JCopter method main.

public static void main(String[] args) {
    // setup some defaults
    AppSetup setup = new AppSetup();
    setup.setUsageInfo("jcopter", "A WCET driven Java bytecode optimizer.");
    setup.setVersionInfo(VERSION);
    // We do not load a config file automatically, user has to specify it explicitly to avoid
    // unintentional misconfiguration
    //setup.setConfigFilename(CONFIG_FILE_NAME);
    DFATool dfaTool = new DFATool();
    WCETTool wcetTool = new WCETTool();
    JCopter jcopter = new JCopter();
    wcetTool.setAvailableOptions(false, true, false, false);
    setup.registerTool("dfa", dfaTool, true, false);
    setup.registerTool("wca", wcetTool);
    setup.registerTool("jcopter", jcopter);
    setup.addSourceLineOptions(true);
    setup.initAndLoad(args, true, true, true);
    if (setup.useTool("dfa")) {
        wcetTool.setDfaTool(dfaTool);
        jcopter.setDfaTool(dfaTool);
    }
    jcopter.setWcetTool(wcetTool);
    wcetTool.getEventHandler().setIgnoreMissingLoopBounds(!jcopter.useWCA());
    // run optimizations
    jcopter.optimize();
    // write results
    setup.writeClasses();
}
Also used : DFATool(com.jopdesign.dfa.DFATool) AppSetup(com.jopdesign.common.AppSetup) WCETTool(com.jopdesign.wcet.WCETTool)

Example 9 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class ObjectCacheAnalysis method getUsedRefs.

/**
	 * Get DFA results on symbolic reference names for the given scope
	 * XXX: proper segment support
	 * @param scope
	 * @return
	 */
public LocalPointsToResult getUsedRefs(ExecutionContext scope) {
    ExecuteOnceAnalysis eoAna = new ExecuteOnceAnalysis(project);
    DFATool dfa = project.getDfaTool();
    SymbolicPointsTo spt = new SymbolicPointsTo(maxSetSize, project.getCallstringLength(), new ExecOnceQuery(eoAna, scope));
    dfa.runLocalAnalysis(spt, scope);
    LocalPointsToResult lpt = new LocalPointsToResult(spt.getResult());
    return lpt;
}
Also used : DFATool(com.jopdesign.dfa.DFATool) SymbolicPointsTo(com.jopdesign.dfa.analyses.SymbolicPointsTo)

Example 10 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class WCETAnalysis method main.

public static void main(String[] args) {
    // We set a different output path for this tool if invoked by cmdline
    // Note that WCETTool could also override defaults, but we do not want to change the
    // default value of outdir if WCETTool is invoked from another tool
    Properties defaultProps = new Properties();
    defaultProps.put("outdir", "java/target/wcet/${projectname}");
    AppSetup setup = new AppSetup(defaultProps, false);
    setup.setVersionInfo("1.0.1");
    // We do not load a config file automatically, user has to specify it explicitly to avoid
    // unintentional misconfiguration
    //setup.setConfigFilename(CONFIG_FILE_NAME);
    setup.setUsageInfo("WCETAnalysis", "WCET Analysis tool");
    WCETTool wcetTool = new WCETTool();
    DFATool dfaTool = new DFATool();
    setup.registerTool("dfa", dfaTool, true, false);
    setup.registerTool("wcet", wcetTool);
    setup.addSourceLineOptions(false);
    setup.initAndLoad(args, true, false, false);
    if (setup.useTool("dfa")) {
        wcetTool.setDfaTool(dfaTool);
    }
    ExecHelper exec = new ExecHelper(setup.getConfig(), Logger.getLogger(WCETTool.LOG_WCET + ".WCETAnalysis"));
    exec.dumpConfig();
    /* Load config */
    exec.checkLibs();
    /* check environment */
    WCETAnalysis inst = new WCETAnalysis(wcetTool, exec);
    try {
        inst.run();
        exec.info("Worst Case Analysis finished");
        exec.info("Cumulative LP/ILP solver time: " + LpSolveWrapper.getTotalSolverTime());
        exec.info("Cumulative WCET Calculation time: " + inst.totalWCETCalculationTime);
    } catch (Exception e) {
        exec.bail("Worst Case Analysis failed: " + e);
    }
}
Also used : DFATool(com.jopdesign.dfa.DFATool) AppSetup(com.jopdesign.common.AppSetup) Properties(java.util.Properties) XmlSerializationException(com.jopdesign.wcet.uppaal.model.XmlSerializationException) DuplicateKeyException(com.jopdesign.wcet.uppaal.model.DuplicateKeyException) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) InvalidFlowFactException(com.jopdesign.wcet.analysis.InvalidFlowFactException) LpSolveException(lpsolve.LpSolveException) IOException(java.io.IOException) UnsupportedCacheModelException(com.jopdesign.wcet.analysis.cache.CacheAnalysis.UnsupportedCacheModelException)

Aggregations

DFATool (com.jopdesign.dfa.DFATool)13 CallString (com.jopdesign.common.code.CallString)8 Context (com.jopdesign.dfa.framework.Context)8 ContextMap (com.jopdesign.dfa.framework.ContextMap)8 MethodInfo (com.jopdesign.common.MethodInfo)6 Set (java.util.Set)6 LinkedHashSet (java.util.LinkedHashSet)5 InstructionHandle (org.apache.bcel.generic.InstructionHandle)5 AppSetup (com.jopdesign.common.AppSetup)3 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 LinkedHashMap (java.util.LinkedHashMap)3 GETFIELD (org.apache.bcel.generic.GETFIELD)3 GETSTATIC (org.apache.bcel.generic.GETSTATIC)3 Instruction (org.apache.bcel.generic.Instruction)3 LDC (org.apache.bcel.generic.LDC)3 LoadInstruction (org.apache.bcel.generic.LoadInstruction)3 PUTFIELD (org.apache.bcel.generic.PUTFIELD)3 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)3 ReferenceType (org.apache.bcel.generic.ReferenceType)3 StoreInstruction (org.apache.bcel.generic.StoreInstruction)3